/* ==========================================================================
   Talk — цвета только через переменные, тёмная тема переопределяет их ниже.
   Нейтральная палитра (без привязки к стилю другого сайта владельца).
   ========================================================================== */

:root {
  --accent: #3657e0;
  --accent-hover: #2944b8;
  --on-accent: #ffffff;

  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #eceef5;
  --border: #dde0ea;
  --border-strong: #c3c7d6;
  --text-primary: #1c1f2b;
  --text-secondary: #5b5f71;
  --text-muted: #8c90a0;

  --danger: #b3392c;
  --danger-soft: #fbe9e5;
  --success: #2f7d4f;
  --success-soft: #e4f3ea;

  --radius: 8px;
  --radius-lg: 16px;
  --shadow-modal: 0 18px 50px rgba(28, 31, 43, 0.22);

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #15171f;
  --surface: #1c1f2b;
  --surface-2: #262a38;
  --border: #343849;
  --border-strong: #454a5e;
  --text-primary: #f2f3f7;
  --text-secondary: #a7abbd;
  --text-muted: #777c8f;

  --accent: #6f85f0;
  --accent-hover: #8a9df4;
  --on-accent: #0f1119;

  --danger: #f08a7e;
  --danger-soft: #3c201c;
  --success: #7fcf9e;
  --success-soft: #1d3327;

  --shadow-modal: 0 18px 50px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171f;
    --surface: #1c1f2b;
    --surface-2: #262a38;
    --border: #343849;
    --border-strong: #454a5e;
    --text-primary: #f2f3f7;
    --text-secondary: #a7abbd;
    --text-muted: #777c8f;

    --accent: #6f85f0;
    --accent-hover: #8a9df4;
    --on-accent: #0f1119;

    --danger: #f08a7e;
    --danger-soft: #3c201c;
    --success: #7fcf9e;
    --success-soft: #1d3327;

    --shadow-modal: 0 18px 50px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

/* Не убирать: без !important класс с display:flex/block может перебить это
   правило при равной специфичности, и скрытые экраны будут видны при загрузке. */
[hidden] { display: none !important; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font);
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

button {
  font-family: inherit;
  font-size: 15px;
  cursor: pointer;
}

input {
  font-family: inherit;
  font-size: 15px;
}

a { color: var(--accent); }

.themeBtn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  border-radius: var(--radius);
  width: 36px;
  height: 36px;
  font-size: 16px;
  line-height: 1;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.topbar h1 {
  font-size: 17px;
  margin: 0;
}

.btn {
  border: none;
  border-radius: var(--radius);
  padding: 10px 16px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}

.btn:hover { background: var(--accent-hover); }

.btn.secondary {
  background: var(--surface-2);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn.danger { background: var(--danger); color: #fff; }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field label {
  font-size: 13px;
  color: var(--text-secondary);
}

.field input, .field select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-primary);
}

.field input:focus, .field select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.error {
  color: var(--danger);
  font-size: 14px;
  min-height: 18px;
  margin-top: -4px;
  margin-bottom: 10px;
}

.center-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.center-screen .card { width: 100%; max-width: 360px; }

.muted { color: var(--text-muted); font-size: 13px; }

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

th { color: var(--text-secondary); font-weight: 600; }

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.pill.active { background: var(--success-soft); color: var(--success); }
.pill.inactive { background: var(--danger-soft); color: var(--danger); }

/* ---------------------------------------------------------------- чат */

.chatLayout {
  flex: 1;
  display: flex;
  min-height: 0;
}

.contactsPane {
  width: 280px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  background: var(--surface);
}

.contactList { list-style: none; margin: 0; padding: 0; }

.contactItem {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.contactItem:hover, .contactItem.active { background: var(--surface-2); }

.onlineDot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--border-strong);
  flex-shrink: 0;
}

.onlineDot.online { background: var(--success); }

.contactName { flex: 1; font-size: 14px; }

.unreadDot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.chatPane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chatEmpty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.chatThread {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chatHeader {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.backBtn {
  display: none;
  border: none;
  background: transparent;
  font-size: 20px;
  color: var(--text-primary);
  padding: 4px;
}

.chatHeaderName { font-weight: 600; }
.chatHeaderStatus { font-size: 12px; color: var(--text-muted); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg {
  max-width: 72%;
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.35;
  word-wrap: break-word;
}

.msg.out {
  align-self: flex-end;
  background: var(--accent);
  color: var(--on-accent);
  border-bottom-right-radius: 2px;
}

.msg.in {
  align-self: flex-start;
  background: var(--surface-2);
  color: var(--text-primary);
  border-bottom-left-radius: 2px;
}

.msg.sending { opacity: .6; }

.msgTime {
  display: block;
  font-size: 10px;
  opacity: .7;
  margin-top: 3px;
  text-align: right;
}

.composer {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.composer input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text-primary);
}

@media (max-width: 720px) {
  .backBtn { display: inline-block; }
  .chatLayout.chatOpen .contactsPane { display: none; }
  .chatLayout:not(.chatOpen) .chatPane { display: none; }
  .contactsPane { width: 100%; }
}

.chatHeaderInfo { flex: 1; min-width: 0; }

.callStartBtn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-primary);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  font-size: 17px;
  line-height: 1;
  flex-shrink: 0;
}

.callStartBtn:hover { background: var(--success-soft); }

/* ------------------------------------------------------------- звонок */

.callOverlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 25, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 24px;
}

.callCard {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  padding: 36px 28px;
  width: 100%;
  max-width: 340px;
  text-align: center;
}

.callAvatar {
  width: 88px;
  height: 88px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
}

.callName { font-size: 19px; font-weight: 600; }
.callStatus { color: var(--text-secondary); font-size: 14px; margin-top: 6px; min-height: 18px; }

.callActions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 28px;
}

.callActions .btn { flex: 1; padding: 12px; }
