/* Цвета светлой и тёмной темы. Тема — атрибут data-theme на <html>. */
:root {
  color-scheme: light;
  --bg: #f2f2f5;
  --surface: #fff;
  --surface-2: #f6f6f9;
  --active: #e8efff;
  --border: #e3e3e8;
  --border-soft: #eee;
  --input-border: #d0d0d7;
  --text: #1c1c1e;
  --text-2: #777;
  --text-3: #888;
  --accent: #2f6fed;
  --bubble: #fff;
  --bubble-mine: #dbe7ff;
  --bubble-mine-text: var(--text);
  --bubble-mine-time: #888;
  --tick-read: #2f6fed;
  --seg-active: #fff;
  --day-bg: #e6e6ec;
  --placeholder: #ccd;
  --secondary-btn: #e9e9ef;
  --secondary-btn-text: #333;
  --danger: #c62828;
  --shadow: rgba(0,0,0,.06);
  --drop-bg: rgba(232, 239, 255, .9);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000;
  --surface: #1c1c1e;
  --surface-2: #2c2c2e;
  --active: #2c2c2e;
  --border: #38383a;
  --border-soft: #2c2c2e;
  --input-border: #3a3a3c;
  --text: #f2f2f7;
  --text-2: #98989f;
  --text-3: #8e8e93;
  --accent: #0a84ff;
  --bubble: #262628;
  --bubble-mine: #0a84ff;
  --bubble-mine-text: #fff;
  --bubble-mine-time: rgba(255,255,255,.7);
  --tick-read: #fff;
  --seg-active: #636366;
  --day-bg: #1c1c1e;
  --placeholder: #3a3a3c;
  --secondary-btn: #3a3a3c;
  --secondary-btn-text: #f2f2f7;
  --danger: #ff453a;
  --shadow: rgba(0,0,0,.4);
  --drop-bg: rgba(10, 32, 64, .9);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text); background: var(--bg);
  transition: background-color .3s, color .3s;
}
button, input { font: inherit; }
button {
  border: 0; border-radius: 8px; padding: 8px 14px; cursor: pointer;
  background: var(--accent); color: #fff;
}
button:disabled { opacity: .5; cursor: default; }
input {
  border: 1px solid var(--input-border); border-radius: 8px; padding: 8px 10px; width: 100%;
  background: var(--surface); color: var(--text);
}
input::placeholder { color: var(--text-3); }
.hidden { display: none !important; }
.error { color: var(--danger); min-height: 1.2em; margin: 8px 0 0; }
.avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; background: var(--placeholder); flex: none; }
.avatar.big { width: 96px; height: 96px; }

/* Переключатель темы в стиле iOS: солнце и луна */
.theme-toggle {
  position: relative; flex: none; width: 51px; height: 31px; padding: 0; border-radius: 16px;
  background: #e9e9eb; box-shadow: inset 0 0 0 1px rgba(0,0,0,.04);
  transition: background-color .25s;
}
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-toggle .track-icon { position: absolute; top: 8px; width: 15px; height: 15px; transition: opacity .25s; }
.theme-toggle svg { display: block; width: 100%; height: 100%; }
.theme-toggle .track-sun { left: 7px; color: #ff9f0a; opacity: 0; }
.theme-toggle .track-moon { right: 7px; color: #8e8e93; }
.theme-toggle .knob {
  position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 3px 8px rgba(0,0,0,.15), 0 1px 1px rgba(0,0,0,.16);
  transition: transform .25s cubic-bezier(.3, 1.3, .5, 1), background-color .25s;
}
.theme-toggle .knob > span { position: absolute; inset: 5px; transition: opacity .25s, transform .25s; }
.theme-toggle .knob-sun { color: #ff9f0a; }
.theme-toggle .knob-moon { color: #5e5ce6; opacity: 0; transform: rotate(-90deg); }
:root[data-theme="dark"] .theme-toggle { background: #39393d; box-shadow: none; }
:root[data-theme="dark"] .theme-toggle .knob { transform: translateX(20px); }
:root[data-theme="dark"] .theme-toggle .knob-sun { opacity: 0; transform: rotate(90deg); }
:root[data-theme="dark"] .theme-toggle .knob-moon { opacity: 1; transform: none; }
:root[data-theme="dark"] .theme-toggle .track-sun { opacity: 1; }
:root[data-theme="dark"] .theme-toggle .track-moon { opacity: 0; }
/* Вход */
.login { height: 100%; display: grid; place-items: center; padding: 16px; position: relative; }
.login > .theme-toggle { position: absolute; top: 16px; right: 16px; }
.login-card { background: var(--surface); padding: 32px; border-radius: 16px; text-align: center; box-shadow: 0 2px 12px var(--shadow); }
.login-card h1 { margin: 0 0 4px; }
.login-card p { color: var(--text-2); }
#google-btn { display: flex; justify-content: center; margin-top: 16px; min-height: 44px; }
.login-card { width: min(360px, 100%); }
.or { display: flex; align-items: center; gap: 10px; color: var(--text-3); font-size: 13px; margin: 18px 0 12px; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.tabs { display: flex; gap: 2px; padding: 2px; border-radius: 10px; background: var(--surface-2); margin-bottom: 12px; }
.tab { flex: 1; padding: 6px 10px; border-radius: 8px; background: none; color: var(--text-2); font-size: 14px; }
.tab.active { background: var(--seg-active); color: var(--text); box-shadow: 0 1px 3px var(--shadow); font-weight: 600; }
.auth-form { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.auth-form .fl { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-2); }
.auth-form .fl input { font-size: 15px; }
#login-error { text-align: left; }
.android-app { display: block; margin-top: 12px; font-size: 14px; color: var(--accent); text-decoration: none; }
.auth-form button[type="submit"] { margin-top: 4px; padding: 10px 14px; }
.auth-photo { display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; color: var(--accent); font-size: 13px; margin-bottom: 4px; }
.auth-photo .avatar.big { width: 72px; height: 72px; }
.hint { color: var(--text-3); font-size: 12px; margin: 6px 0 0; }
.link-btn { background: none; color: var(--accent); padding: 8px 0 0; }
.password-fields { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }

/* Раскладка */
.app { height: 100%; display: flex; }
.sidebar { width: 320px; flex: none; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.side-top { display: flex; align-items: center; border-bottom: 1px solid var(--border-soft); padding-right: 12px; }
.me { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; background: none; color: inherit; padding: 14px 16px; border-radius: 0; text-align: left; font-weight: 600; }
.me span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me:hover { background: var(--surface-2); }
.new-chat { display: flex; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--border-soft); }
.chats { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.chats li { display: flex; gap: 10px; align-items: center; padding: 10px 16px; cursor: pointer; }
.chats li:hover { background: var(--surface-2); }
.chats li.active { background: var(--active); }
.chats .info { min-width: 0; flex: 1; }
.chats .top { display: flex; justify-content: space-between; gap: 8px; }
.chats .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chats .time { color: var(--text-3); font-size: 12px; flex: none; }
.chats .last { color: var(--text-2); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.chat-empty { margin: auto; color: var(--text-3); padding: 16px; text-align: center; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); font-weight: 600; }
.back { display: none; background: none; color: var(--accent); padding: 4px 8px; font-size: 20px; }
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: min(70%, 480px); padding: 8px 12px; border-radius: 14px; background: var(--bubble); align-self: flex-start; box-shadow: 0 1px 1px var(--shadow); }
.msg.mine { align-self: flex-end; background: var(--bubble-mine); color: var(--bubble-mine-text); }
.msg img { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; margin-bottom: 4px; cursor: zoom-in; }
.msg .text { white-space: pre-wrap; word-wrap: break-word; }
.msg .time { font-size: 11px; color: var(--text-3); text-align: right; margin-top: 2px; }
.msg.mine .time { color: var(--bubble-mine-time); }
.day { align-self: center; font-size: 12px; color: var(--text-2); background: var(--day-bg); padding: 2px 10px; border-radius: 10px; margin: 8px 0; }

.composer { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px; background: var(--surface); border-top: 1px solid var(--border); }
.composer-main { flex: 1; min-width: 0; }
.attach { font-size: 22px; cursor: pointer; padding: 4px; line-height: 1; margin-bottom: 4px; }
.preview { position: relative; display: inline-block; margin-bottom: 6px; }
.preview img { max-height: 90px; border-radius: 8px; display: block; cursor: zoom-in; }
.preview button { position: absolute; top: 4px; right: 4px; padding: 0 6px; background: rgba(0,0,0,.6); border-radius: 50%; }

/* Поиск собеседников */
.search-results { list-style: none; margin: 0; padding: 4px 0; border-bottom: 1px solid var(--border-soft); max-height: 50vh; overflow-y: auto; }
.search-results li { display: flex; gap: 10px; align-items: center; padding: 8px 16px; cursor: pointer; }
.search-results li:hover { background: var(--surface-2); }
.search-results li.none { color: var(--text-3); cursor: default; }
.search-results li.none:hover { background: none; }
.search-results .info { min-width: 0; }
.search-results .name { font-weight: 600; }
.search-results .last { color: var(--text-2); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Перетаскивание фото */
.drop-hint {
  position: absolute; inset: 8px; z-index: 5; display: grid; place-items: center;
  border: 2px dashed var(--accent); border-radius: 16px; background: var(--drop-bg);
  color: var(--accent); font-weight: 600; pointer-events: none;
}

/* Просмотр фото */
.viewer { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.85); display: grid; place-items: center; cursor: zoom-out; padding: 16px; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }
.viewer button { position: absolute; top: 12px; right: 12px; background: rgba(255,255,255,.15); font-size: 18px; border-radius: 50%; width: 40px; height: 40px; padding: 0; }

/* Звонки */
.chat-head .spacer { flex: 1; }
.head-btn { background: none; font-size: 20px; padding: 4px 8px; }
.head-btn:hover { background: var(--surface-2); }
.call { position: fixed; inset: 0; z-index: 90; background: #15161a; color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.call video { background: #000; }
#remote-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
#local-video { position: absolute; right: 16px; top: 16px; width: min(28vw, 220px); aspect-ratio: 4 / 3; object-fit: cover; border-radius: 12px; z-index: 2; transform: scaleX(-1); }
.call.audio video, .call:not(.connected) #remote-video, .call.cam-off #local-video { visibility: hidden; }
.call-info { position: relative; z-index: 1; text-align: center; padding: 16px; }
.call.connected:not(.audio) .call-info { position: absolute; top: 16px; left: 16px; text-align: left; padding: 0; text-shadow: 0 1px 3px #000; }
.call.connected:not(.audio) .call-info img { display: none; }
.call-name { font-size: 22px; font-weight: 600; margin-top: 12px; }
.call-status { color: #c9cbd6; margin-top: 4px; font-variant-numeric: tabular-nums; }
.call-buttons { position: absolute; bottom: 32px; left: 0; right: 0; display: flex; justify-content: center; gap: 20px; z-index: 2; }
.round { width: 60px; height: 60px; border-radius: 50%; padding: 0; font-size: 24px; background: rgba(255,255,255,.18); }
.round.off { background: #fff; color: #15161a; filter: grayscale(1); }
.round.green { background: #2e9e4f; }
.round.red { background: #d93a3a; }

/* Непрочитанные и галочки */
.badge {
  flex: none; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 600;
  display: grid; place-items: center; font-variant-numeric: tabular-nums;
}
.msg .time { display: flex; justify-content: flex-end; align-items: center; gap: 3px; }
.ticks { display: inline-flex; width: 16px; height: 11px; color: var(--text-3); }
.ticks svg { width: 100%; height: 100%; }
.ticks.read { color: var(--accent); }
.msg.mine .ticks { color: var(--bubble-mine-time); }
.msg.mine .ticks.read { color: var(--tick-read); }

/* Кнопка-шестерёнка и выбор устройств */
.gear svg { width: 20px; height: 20px; display: block; }
.head-btn.gear { color: var(--text-3); }
.round.gear { display: grid; place-items: center; }
.round.gear svg { width: 26px; height: 26px; color: #fff; }
select {
  font: inherit; width: 100%; margin-top: 6px; padding: 8px 10px; border-radius: 10px;
  border: 1px solid var(--input-border); background: var(--surface-2); color: var(--text);
}
.devices { width: min(400px, calc(100% - 32px)); }
.devices .field { display: block; font-size: 13px; color: var(--text-2); margin-top: 14px; }
.devices video { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 12px; background: #000; transform: scaleX(-1); }

/* Профиль */
dialog { border: 0; border-radius: 16px; padding: 24px; width: min(360px, calc(100% - 32px)); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h2 { margin: 0 0 16px; }
.profile-photo { display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer; color: var(--accent); margin-bottom: 16px; }
.row { display: flex; gap: 8px; margin-top: 16px; }
.row span { flex: 1; }
.row #profile-cancel { background: var(--secondary-btn); color: var(--secondary-btn-text); }
.link { background: none; color: var(--danger); padding: 8px 0; }

/* Телефон: показываем либо список, либо чат */
@media (max-width: 700px) {
  .sidebar { width: 100%; border-right: 0; }
  .app.in-chat .sidebar { display: none; }
  .app:not(.in-chat) .chat { display: none; }
  .back { display: block; }
  .msg { max-width: 85%; }
}
