/* ICYou — оформление в духе классических мессенджеров, но адаптивное */

* { box-sizing: border-box; }

body {
  font-family: Tahoma, "MS Sans Serif", Segoe UI, Arial, sans-serif;
  font-size: 12px;
  background: #3a6ea5;
  margin: 0;
  padding: 20px;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

/* ---------------- окно ---------------- */
.win {
  background: #ECE9D8;
  border: 2px solid #0A246A;
  box-shadow: 2px 2px 6px rgba(0,0,0,0.5);
}
.titlebar {
  background: linear-gradient(180deg, #3169C6, #0A246A 90%);
  color: #fff;
  font-weight: bold;
  padding: 5px 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}
.titlebar .tleft { display: flex; align-items: center; gap: 6px; min-width: 0; }
.titlebar .tleft > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flower {
  width: 16px; height: 16px; flex-shrink: 0;
  background: radial-gradient(circle at 30% 30%, #fff, #ffd400 40%, #ff8c00 70%, #e60000);
  border-radius: 50%;
}
.titlebar .buttons { display: flex; flex-shrink: 0; }
.titlebar .buttons span {
  width: 18px; height: 16px;
  background: #ECE9D8; border: 1px solid #0A246A; color: #000;
  text-align: center; line-height: 15px; margin-left: 2px;
  font-size: 10px; cursor: pointer;
}
.titlebar .buttons span:active { background: #c9c5b4; }

/* ---------------- вход ---------------- */
#login-screen { width: 320px; margin: 60px auto; }
#login-screen .body { padding: 16px; }
#login-screen h2 { margin: 0 0 4px; font-size: 16px; }
.sub { margin: 0 0 12px; color: #555; }
label { display: block; margin-top: 8px; font-size: 11px; color: #333; }
input[type=text], input[type=password], textarea, select {
  width: 100%; padding: 5px 6px; font-size: 13px;
  border: 1px inset #999; margin-top: 2px;
  font-family: inherit; background: #fff;
}
textarea { resize: vertical; }
#login-error { color: #b30000; margin-top: 8px; min-height: 14px; font-size: 11px; }
.row-buttons { display: flex; gap: 8px; margin-top: 14px; }
.row-buttons.end { justify-content: flex-end; }

.win-btn {
  background: #ECE9D8; border: 1px outset #ccc;
  padding: 6px 14px; cursor: pointer; font-size: 12px; font-family: inherit;
}
.win-btn:active { border-style: inset; }
.win-btn.primary { font-weight: bold; }

/* ---------------- основное приложение ---------------- */
#app-shell { display: none; gap: 20px; align-items: flex-start; flex-wrap: wrap; }
#main-win { width: 250px; flex-shrink: 0; }

.my-profile {
  display: flex; align-items: center; gap: 8px;
  padding: 8px; border-bottom: 1px solid #999;
}
.avatar-wrap { position: relative; width: 36px; height: 36px; cursor: pointer; flex-shrink: 0; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  object-fit: cover; background: #cfd8e8; border: 1px solid #8a9ab5; display: block;
}
.avatar-overlay {
  position: absolute; inset: 0; border-radius: 50%;
  background: rgba(10,36,106,0.6); color: #fff;
  display: none; align-items: center; justify-content: center; font-size: 14px;
}
.avatar-wrap:hover .avatar-overlay { display: flex; }
.avatar.small { width: 26px; height: 26px; }

#status-select { flex: 1; min-width: 0; margin-top: 0; }

.search-box { padding: 6px; border-bottom: 1px solid #999; }
.search-box input { margin-top: 0; }

.tabs { display: flex; border-bottom: 1px solid #999; }
.tabs .tab {
  flex: 1; text-align: center; padding: 7px 0; cursor: pointer;
  background: #DCE4F2; border-right: 1px solid #999; font-size: 12px;
}
.tabs .tab:last-child { border-right: none; }
.tabs .tab.active { background: #fff; font-weight: bold; }

.list-panel {
  background: #fff; height: 320px; overflow-y: auto;
  border: 1px inset #999; margin: 6px;
}
.list-panel.hidden { display: none; }

.group-header {
  background: #D6E4F0; padding: 3px 8px; font-weight: bold;
  border-bottom: 1px solid #b8c9dd; user-select: none; font-size: 11px;
}
.contact, .group-item {
  padding: 6px 8px; cursor: pointer; display: flex; align-items: center;
  gap: 8px; border-bottom: 1px solid #f0f0f0;
}
.contact:hover, .group-item:hover { background: #E3ECF7; }
.contact-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact.unread .contact-name, .group-item.unread .contact-name { font-weight: bold; }

.status-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.dot-online { background: #3ac13a; box-shadow: 0 0 2px #1a7a1a; }
.dot-away { background: #e8b400; }
.dot-offline { background: #b0b0b0; }

.unread-badge {
  background: #d33; color: #fff; border-radius: 9px;
  padding: 1px 6px; font-size: 10px; font-weight: bold; flex-shrink: 0;
}
.member-count { font-size: 10px; color: #777; flex-shrink: 0; }

.main-toolbar {
  display: flex; gap: 6px; padding: 6px;
  border-top: 1px solid #999; flex-wrap: wrap;
}
.main-toolbar .win-btn {
  flex: 1 1 auto; min-width: 90px; padding: 6px 4px; font-size: 11px;
  white-space: nowrap;
}
.statusbar {
  font-size: 10px; padding: 4px 8px; background: #ECE9D8;
  border-top: 1px solid #999; color: #333;
}

/* ---------------- чат ---------------- */
.chats-container { display: flex; gap: 16px; flex-wrap: wrap; }
.chat-win { width: 360px; display: flex; flex-direction: column; }

.chat-history {
  background: #fff; border: 1px inset #999; margin: 6px;
  height: 300px; overflow-y: auto; padding: 8px;
}
.msg { margin-bottom: 10px; display: flex; gap: 6px; align-items: flex-start; }
.msg .bubble { flex: 1; min-width: 0; }
.msg .who { font-weight: bold; }
.msg.me .who { color: #0033cc; }
.msg.them .who { color: #b30000; }
.msg .time { color: #888; font-size: 10px; margin-left: 4px; }
.msg .edited { color: #888; font-size: 10px; font-style: italic; margin-left: 4px; }
.msg .text { white-space: pre-wrap; word-break: break-word; margin-top: 2px; }
.msg.deleted .text { color: #999; font-style: italic; }

.msg-actions { display: none; gap: 6px; margin-top: 3px; }
.msg:hover .msg-actions { display: flex; }
.msg-actions button {
  background: none; border: none; color: #0033cc; cursor: pointer;
  font-size: 10px; padding: 0; text-decoration: underline;
}
.read-mark { font-size: 10px; color: #2a7a2a; margin-left: 4px; }
.read-mark.unread { color: #999; }

.file-attach {
  display: inline-block; margin-top: 4px; padding: 5px 8px;
  background: #eef2fa; border: 1px solid #b8c9dd; border-radius: 3px;
  text-decoration: none; color: #0033cc; font-size: 11px; word-break: break-all;
}
.file-attach img { max-width: 100%; border-radius: 3px; display: block; margin-top: 4px; }

.typing-indicator {
  font-size: 10px; color: #888; padding: 0 10px;
  min-height: 13px; font-style: italic;
}

.chat-input-area { display: flex; flex-direction: column; margin: 0 6px 6px; gap: 5px; }
.chat-toolbar {
  display: flex; gap: 4px; padding: 3px; align-items: center;
  background: #ECE9D8; border: 1px outset #ccc;
}
.chat-toolbar button {
  width: 30px; height: 26px; font-size: 13px; cursor: pointer;
  border: 1px outset #ccc; background: #ECE9D8;
}
.attach-name { font-size: 10px; color: #333; flex: 1; overflow: hidden; text-overflow: ellipsis; }
.chat-input-area textarea { height: 54px; font-size: 13px; }
.chat-send-row { display: flex; justify-content: flex-end; }

/* ---------------- модалки и тост ---------------- */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  align-items: center; justify-content: center; z-index: 20; padding: 16px;
}
.modal-overlay.open { display: flex; }
.modal-box { width: 300px; max-width: 100%; }
.modal-box .body { padding: 14px; }

#toast {
  position: fixed; bottom: 70px; left: 50%; transform: translateX(-50%);
  background: #0A246A; color: #fff; padding: 10px 18px;
  border-radius: 4px; font-size: 12px; z-index: 50;
  opacity: 0; pointer-events: none; transition: opacity .25s;
  max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; }

::-webkit-scrollbar { width: 14px; }
::-webkit-scrollbar-track { background: #ECE9D8; }
::-webkit-scrollbar-thumb { background: #C0C0C0; border: 1px solid #888; }

/* ---------------- мобильная вёрстка ---------------- */
@media (max-width: 760px) {
  body { padding: 0; }

  #login-screen {
    width: 100%; margin: 0; min-height: 100vh;
    border: none; display: flex; flex-direction: column; justify-content: center;
  }

  #app-shell { display: block; }
  #main-win {
    width: 100%; border: none; min-height: 100vh;
    display: flex; flex-direction: column;
    padding-top: env(safe-area-inset-top);
  }
  #main-win .list-panel { flex: 1; height: auto; }

  /* На телефоне чат раскрывается на весь экран поверх списка */
  .chats-container { position: fixed; inset: 0; z-index: 30; display: block; }
  .chats-container:empty { display: none; }
  .chat-win {
    width: 100%; height: 100%; border: none;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .chat-history { flex: 1; height: auto; }

  .titlebar .buttons span { width: 26px; height: 24px; line-height: 23px; font-size: 13px; }
  .contact, .group-item { padding: 10px 8px; }
  .msg-actions { display: flex; }  /* на тач-экранах нет наведения */
}
