/* Switchboard — refined dark lounge aesthetic */

:root {
  --bg: #0f0e12;
  --bg-elevated: #141318;
  --panel: rgba(22, 21, 27, 0.88);
  --panel-solid: #16151b;
  --panel-2: #1c1b22;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.12);
  --ink: #f2ebe1;
  --ink-soft: rgba(242, 235, 225, 0.82);
  --muted: #8a8494;
  --brass: #c9a24b;
  --brass-light: #e2c078;
  --brass-soft: rgba(201, 162, 75, 0.14);
  --brass-glow: rgba(201, 162, 75, 0.35);
  --success: #7cb888;
  --success-glow: rgba(124, 184, 136, 0.45);
  --danger: #d9705f;
  --danger-soft: rgba(217, 112, 95, 0.18);
  --warn: #d4a853;
  /* Density: ~40% larger type (via html rem), ~30% tighter chrome */
  --type-scale: 1.4;
  --space-scale: 0.7;
  --radius: 8px;
  --radius-sm: 6px;
  --radius-pill: 999px;
  --shadow: 0 12px 34px rgba(0, 0, 0, 0.42);
  --shadow-soft: 0 6px 17px rgba(0, 0, 0, 0.28);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --font-ui: "SF Pro Text", "Segoe UI", ui-sans-serif, system-ui, sans-serif;
  --font-display: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  /* Browser default 16px × 1.4 → rem-based UI text ~40% larger */
  font-size: calc(16px * var(--type-scale));
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 0.875rem; /* ≈19.6px — was 14px absolute */
  font-weight: 500;
  line-height: 1.3;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  background:
    radial-gradient(ellipse 80% 55% at 50% -10%, rgba(201, 162, 75, 0.07), transparent 55%),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(90, 70, 120, 0.06), transparent 50%),
    linear-gradient(180deg, #121116 0%, var(--bg) 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  z-index: 0;
}

::selection {
  background: var(--brass-soft);
  color: var(--ink);
}

/* ---- controls ---- */

button {
  font: inherit;
  color: #1a1508;
  background: linear-gradient(180deg, var(--brass-light) 0%, var(--brass) 100%);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-sm);
  padding: 6px 11px;
  cursor: pointer;
  font-weight: 650;
  letter-spacing: 0.01em;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.12) inset, 0 3px 10px rgba(0, 0, 0, 0.22);
  transition: transform 0.12s var(--ease), box-shadow 0.2s var(--ease), filter 0.2s ease;
}
button:hover {
  filter: brightness(1.06);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.16) inset, 0 6px 20px rgba(201, 162, 75, 0.22);
}
button:active { transform: scale(0.98); }
button:focus-visible {
  outline: 2px solid var(--brass-glow);
  outline-offset: 2px;
}

button.ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--line-strong);
  box-shadow: none;
  font-weight: 600;
}
button.ghost:hover {
  color: var(--ink);
  border-color: rgba(201, 162, 75, 0.45);
  background: rgba(255, 255, 255, 0.03);
  filter: none;
}

input, select, textarea {
  font: inherit;
  font-weight: 500;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 7px 9px;
  width: 100%;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}
input::placeholder, textarea::placeholder { color: rgba(138, 132, 148, 0.75); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: rgba(201, 162, 75, 0.55);
  box-shadow: 0 0 0 3px var(--brass-soft);
  background: rgba(0, 0, 0, 0.32);
}

.muted { color: var(--muted); }

/* ---- lock screen ---- */

.lock-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  position: relative;
  z-index: 1;
}

.lock-card {
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: calc(var(--radius) + 4px);
  padding: 48px 40px;
  max-width: 380px;
  text-align: center;
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  animation: riseIn 0.7s var(--ease) both;
}

.lock-mark {
  font-size: 36px;
  color: var(--brass);
  margin-bottom: 12px;
  filter: drop-shadow(0 0 12px var(--brass-glow));
}

.lock-card h1 {
  margin: 0 0 14px;
  font: 600 1.65rem/1.2 var(--font-display);
  letter-spacing: 0.04em;
}

.lock-card p {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.65;
}

/* ---- app shell ---- */

.app-shell {
  position: relative;
  z-index: 1;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
  grid-template-columns: min(340px, 36vw) 1fr;
  grid-template-areas: "rail rail" "sidebar chat";
  isolation: isolate;
}

/* ---- header rail ---- */

.rail {
  grid-area: rail;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 7px 13px 8px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset;
  /* Hard guarantee: however many Android lines get auto-provisioned, the
     header never grows past this — the line bank below scrolls sideways
     instead of wrapping to a second row. */
  max-height: 165px;
  flex-shrink: 0;
  overflow: hidden;
}

.rail-top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 7px;
}

.brand-mark {
  color: var(--brass);
  font-size: 1.15rem;
  font-weight: 600;
  filter: drop-shadow(0 0 8px var(--brass-glow));
}

.brand-text { display: flex; flex-direction: column; gap: 0; }

.brand-name {
  font: 650 1rem/1.15 var(--font-display);
  letter-spacing: 0.05em;
  text-transform: lowercase;
  font-variant: small-caps;
}

.brand-tag {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.rail-right {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.nav-menu {
  position: relative;
}
.nav-menu > summary {
  list-style: none;
  cursor: pointer;
}
.nav-menu > summary::-webkit-details-marker { display: none; }
.nav-menu > summary::after {
  content: " ▾";
  font-size: 0.65em;
}
.nav-menu-popover {
  position: absolute;
  z-index: 20;
  top: calc(100% + 7px);
  right: 0;
  min-width: 10rem;
  padding: 5px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel-solid);
  box-shadow: var(--shadow);
}
.nav-menu-popover a {
  display: block;
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 0.76rem;
}
.nav-menu-popover a:hover {
  color: var(--ink);
  background: var(--brass-soft);
}

.gateway-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 7px 3px 6px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.18);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.ami-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--danger);
  flex-shrink: 0;
  transition: background 0.35s ease, box-shadow 0.35s ease;
}
.ami-dot.up {
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(124, 184, 136, 0.15), 0 0 10px var(--success-glow);
  animation: pulseSoft 2.4s ease-in-out infinite;
}

.line-picker-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
}
.line-picker-label {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.65rem;
  font-weight: 650;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.line-picker {
  width: min(260px, 100%);
  min-height: 32px;
  padding: 4px 28px 4px 9px;
  border-radius: var(--radius-pill);
  font-size: 0.76rem;
  font-weight: 650;
  background-color: rgba(0, 0, 0, 0.25);
}

/* ---- sidebar ---- */

.sidebar {
  grid-area: sidebar;
  background: var(--panel-solid);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.search-row {
  padding: 10px 10px 8px;
  border-bottom: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.12);
}
.search-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.search-wrap { flex: 1; }
.archive-toggle {
  flex: 0 0 auto;
  padding: 5px 8px;
  font-size: 0.62rem;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted);
  border-color: var(--line-strong);
  box-shadow: none;
}
.archive-toggle.active {
  color: var(--brass-light);
  border-color: rgba(201, 162, 75, 0.45);
  background: var(--brass-soft);
}

.search-wrap { position: relative; }

.search-wrap::before {
  content: "⌕";
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-52%);
  color: var(--muted);
  font-size: 0.95rem;
  pointer-events: none;
  opacity: 0.7;
}

#search {
  padding-left: 34px;
  border-radius: var(--radius-pill);
  background: rgba(0, 0, 0, 0.28);
}

.thread-list {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.12) transparent;
}
.thread-list::-webkit-scrollbar { width: 6px; }
.thread-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 99px;
}

.thread-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 9px 11px 9px 13px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  position: relative;
  transition: background 0.2s ease;
  animation: fadeUp 0.35s var(--ease) both;
}
.thread-item::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: transparent;
  transition: background 0.25s var(--ease);
}
.thread-item:hover { background: rgba(255, 255, 255, 0.03); }
.thread-item.active {
  background: linear-gradient(90deg, var(--brass-soft) 0%, transparent 100%);
}
.thread-item.active::before {
  background: linear-gradient(180deg, var(--brass-light), var(--brass));
}

.thread-top { display: flex; justify-content: space-between; gap: 7px; align-items: baseline; }
.thread-peer {
  font-weight: 650;
  font-size: 0.92rem;
  letter-spacing: 0.01em;
}
.thread-time {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.thread-preview {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.3;
}
.thread-line-chip {
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--brass);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.thread-item-actions {
  display: flex;
  gap: 4px;
  margin-top: 3px;
  opacity: 0;
  transition: opacity 0.16s ease;
}
.thread-item:hover .thread-item-actions,
.thread-item:focus-within .thread-item-actions {
  opacity: 1;
}
.thread-action {
  padding: 3px 7px;
  min-height: 24px;
  font-size: 0.58rem;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted);
  border-color: var(--line-strong);
  box-shadow: none;
}
.thread-action:hover {
  color: var(--ink);
  border-color: rgba(201, 162, 75, 0.45);
  background: rgba(255, 255, 255, 0.04);
  filter: none;
}
.thread-action.delete:hover {
  color: var(--danger);
  border-color: rgba(217, 112, 95, 0.5);
}
.thread-list-empty {
  padding: 28px 14px;
  color: var(--muted);
  text-align: center;
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1.4;
}

/* ---- chat pane ---- */

.chat-pane {
  grid-area: chat;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  background:
    radial-gradient(ellipse 70% 50% at 50% 0%, rgba(201, 162, 75, 0.04), transparent 60%),
    linear-gradient(180deg, rgba(255,255,255,0.015) 0%, transparent 120px);
}

.chat-active {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: fadeIn 0.35s ease both;
}
/* An unconditional `display: flex` here would otherwise always beat the
   UA stylesheet's `[hidden] { display: none }` (author rules win over UA
   rules regardless of specificity), so the `hidden` attribute toggled by
   showChat() needs this explicit, higher-specificity override to work. */
.chat-active[hidden] { display: none; }

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
  animation: fadeIn 0.35s ease both;
}
.chat-empty[hidden] { display: none; }
.chat-empty-mark {
  font-size: 2.4rem;
  color: var(--brass);
  opacity: 0.5;
  filter: drop-shadow(0 0 16px var(--brass-glow));
  margin-bottom: 4px;
}
.chat-empty h2 {
  margin: 0;
  font: 600 1.15rem/1.2 var(--font-display);
  letter-spacing: 0.02em;
  color: var(--ink-soft);
}
.chat-empty p { margin: 0; font-size: 0.85rem; }
.chat-empty-cta {
  margin-top: 10px;
  border-radius: var(--radius-pill);
  padding: 9px 20px;
  font-size: 0.8rem;
}

.chat-header {
  padding: 11px 15px;
  border-bottom: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.14);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.chat-peer {
  font: 650 1.05rem/1.2 var(--font-display);
  letter-spacing: 0.02em;
}

.chat-line {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 1px;
}

.chat-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 15px 17px 20px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}
.chat-scroll::-webkit-scrollbar { width: 6px; }
.chat-scroll::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 99px;
}

/* ---- message bubbles ---- */

.bubble {
  max-width: min(420px, 72%);
  padding: 7px 10px 6px;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.32;
  word-wrap: break-word;
  animation: bubbleIn 0.32s var(--ease) both;
  transition: opacity 0.2s ease;
}

.bubble.in {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line-strong);
  border-bottom-left-radius: 5px;
  box-shadow: var(--shadow-soft);
}

.bubble.out {
  align-self: flex-end;
  background: linear-gradient(145deg, #e2c078 0%, #c9a24b 55%, #b8923f 100%);
  color: #1a1508;
  border-bottom-right-radius: 5px;
  box-shadow: 0 6px 20px rgba(201, 162, 75, 0.22);
}

.bubble.status-queued {
  opacity: 0.72;
  filter: saturate(0.85);
}
.bubble.status-failed {
  background: linear-gradient(145deg, #e8a090 0%, var(--danger) 100%);
  box-shadow: 0 6px 20px rgba(217, 112, 95, 0.25);
}

.bubble-meta {
  font-size: 0.62rem;
  margin-top: 5px;
  opacity: 0.7;
  display: flex;
  gap: 6px;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}
.bubble.out .bubble-meta { justify-content: flex-end; }

.status-tag {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}
.status-tag.queued { color: rgba(26, 21, 8, 0.55); }
.status-tag.failed { color: rgba(80, 20, 10, 0.75); }

/* ---- reply composer ---- */

.composer {
  display: grid;
  grid-template-columns: 1fr auto auto;
  grid-template-areas: "from when send" "body schedule send";
  gap: 6px 8px;
  padding: 10px 13px 11px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  align-items: end;
  box-shadow: 0 -6px 22px rgba(0, 0, 0, 0.18);
}

.compose-from {
  grid-area: from;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.composer textarea {
  grid-area: body;
  width: 100%;
  resize: none;
  max-height: 120px;
  border-radius: var(--radius);
  min-height: 36px;
}

.composer input[type="datetime-local"] {
  grid-area: when;
  min-height: 32px;
  max-width: 176px;
  padding: 5px 7px;
  font-size: 0.73rem;
}

.composer #reply-schedule {
  grid-area: schedule;
  min-width: 78px;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
}

.composer button[type="submit"] {
  grid-area: send;
  min-width: 72px;
  border-radius: var(--radius-pill);
}

/* ---- compose modal ---- */
/* A true centered dialog (native <dialog>.showModal()) instead of a
   floating dock: one obvious, always-in-the-same-place entry point
   (the sidebar button below) rather than a control that hangs in empty
   chat space and moves around depending on whether a thread is open. */

.compose-modal {
  border: none;
  padding: 0;
  margin: auto;
  width: min(400px, calc(100vw - 40px));
  max-width: min(400px, calc(100vw - 40px));
  background: transparent;
  overflow: visible;
}
.compose-modal::backdrop {
  background: rgba(6, 5, 8, 0.62);
  backdrop-filter: blur(2px);
}
.compose-modal[open] {
  animation: riseIn 0.3s var(--ease) both;
}

.sidebar-top-row {
  padding: 10px 10px 2px;
}

.compose-trigger {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  background: linear-gradient(180deg, var(--brass-light) 0%, var(--brass) 100%);
  color: #1a1508;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.compose-trigger-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(26, 21, 8, 0.16);
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1;
}

.compose-card {
  width: 100%;
  background: rgba(18, 17, 22, 0.94);
  border: 1px solid var(--line-strong);
  border-radius: calc(var(--radius) + 2px);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px) saturate(1.15);
  -webkit-backdrop-filter: blur(18px) saturate(1.15);
}

.compose-card-head {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.compose-close {
  position: absolute;
  right: 0;
  top: -4px;
  background: transparent;
  border: none;
  box-shadow: none;
  color: var(--muted);
  font-size: 1.2rem;
  line-height: 1;
  padding: 4px 6px;
}
.compose-close:hover { color: var(--ink); filter: none; }

.compose-title {
  font: 600 0.72rem/1 var(--font-ui);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.compose-form { display: flex; flex-direction: column; gap: 8px; }
.compose-form .field { display: flex; flex-direction: column; gap: 3px; }
.field-label {
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.compose-form textarea { min-height: 76px; resize: vertical; }
.compose-error { margin: 0 0 8px; text-align: center; font-size: 0.78rem; }
.compose-success {
  margin: 0 0 8px;
  text-align: center;
  font-size: 0.78rem;
  color: var(--success);
  letter-spacing: 0.02em;
}
.compose-when { min-height: 40px; font-size: 0.95rem; }

.compose-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 2px;
}
.send-btn {
  width: 100%;
  min-height: 34px;
  padding: 6px 10px;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: var(--radius-pill);
}
.send-later.ghost:hover {
  color: var(--brass-light);
  border-color: rgba(201, 162, 75, 0.5);
  background: rgba(201, 162, 75, 0.08);
}

.hint { color: var(--danger); margin: 0; font-size: 0.78rem; }

.send-wide {
  width: 100%;
  min-height: 34px;
  font-size: 0.78rem;
  margin-top: 4px;
  border-radius: var(--radius-pill);
}

.line-select {
  font-size: 1rem;
  min-height: 44px;
  padding: 10px 12px;
  width: 100%;
  -webkit-appearance: menulist;
  appearance: menulist;
}
.line-select:focus { border-color: var(--brass); }

.back-link, .btn-link {
  display: inline-flex;
  align-items: center;
  padding: 7px 13px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  color: var(--muted);
  text-decoration: none;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.back-link:hover, .btn-link:hover {
  color: var(--ink);
  border-color: rgba(201, 162, 75, 0.45);
  background: rgba(255, 255, 255, 0.03);
}

/* ---- motion ---- */

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes riseIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes pulseSoft {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---- responsive ---- */

/* ---- devices console ---- */

.devices-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
}

.devices-rail { flex-shrink: 0; }

.devices-main {
  flex: 1;
  overflow-y: auto;
  padding: 17px clamp(11px, 3vw, 28px) 34px;
}

.devices-banner {
  margin: 0 0 14px;
  padding: 8px 11px;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: rgba(217, 112, 95, 0.1);
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1.3;
}
.devices-banner.warn {
  background: rgba(212, 168, 83, 0.1);
  border-color: rgba(212, 168, 83, 0.35);
}

.devices-empty {
  padding: 42px 14px;
  text-align: center;
  color: var(--ink-soft);
  line-height: 1.4;
  font-weight: 500;
}

.devices-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 11px;
}

.device-card {
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: calc(var(--radius) + 2px);
  padding: 13px 14px 11px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  animation: riseIn 0.35s var(--ease) both;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.device-card.revoked { opacity: 0.55; }
.device-card.off-account {
  border-color: rgba(212, 168, 83, 0.45);
}
.device-account-warn {
  font-size: 0.72rem;
  line-height: 1.4;
  color: var(--warn);
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  background: rgba(212, 168, 83, 0.1);
  border: 1px solid rgba(212, 168, 83, 0.3);
}

.device-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.device-name {
  font: 650 1rem/1.2 var(--font-display);
  letter-spacing: 0.02em;
}

.device-id {
  font-size: 0.65rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}

.presence-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.2);
  color: var(--muted);
  white-space: nowrap;
}
.presence-pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}
.presence-pill.online { color: var(--success); }
.presence-pill.online .dot {
  background: var(--success);
  box-shadow: 0 0 8px var(--success-glow);
  animation: pulseSoft 2.4s ease-in-out infinite;
}
.presence-pill.idle { color: var(--warn); }
.presence-pill.idle .dot { background: var(--warn); }
.presence-pill.offline { color: var(--danger); }
.presence-pill.offline .dot { background: var(--danger); }
.presence-pill.revoked { color: var(--muted); }

.device-meta-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--ink-soft);
  gap: 10px;
}
.device-meta-row .label {
  color: var(--muted);
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.device-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.device-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 4px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.16);
}
.device-stat .n {
  font: 700 1.05rem/1 var(--font-display);
  font-variant-numeric: tabular-nums;
}
.device-stat .k {
  font-size: 0.58rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.device-stat.failed .n { color: var(--danger); }
.device-stat.delivered .n { color: var(--success); }

.devices-updated {
  margin-top: 24px;
  text-align: center;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}

.device-call-row {
  display: flex;
  gap: 6px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.device-call-row input {
  flex: 1;
  min-width: 0;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  color: var(--ink);
  font-size: 0.8rem;
}
.device-call-row input:focus { outline: 1px solid var(--accent); }
.device-call-row button {
  flex-shrink: 0;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--accent-soft, rgba(96, 165, 250, 0.16));
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}
.device-call-row button:disabled { opacity: 0.5; cursor: default; }
.device-call-row button:not(:disabled):hover { filter: brightness(1.15); }

.device-last-call {
  font-size: 0.72rem;
  color: var(--ink-soft);
  padding-top: 2px;
}
.device-last-call .muted { color: var(--muted); }

.conn-chip {
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.conn-chip.connected { color: var(--success); border-color: rgba(90, 200, 140, 0.4); }
.conn-chip.reconnecting { color: var(--warn); border-color: rgba(212, 168, 83, 0.4); }
.conn-chip.disconnected, .conn-chip.error { color: var(--danger); border-color: rgba(217, 112, 95, 0.4); }

.devices-log-panel {
  margin-top: 20px;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: calc(var(--radius) + 2px);
  padding: 11px 13px;
}
.devices-log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 7px;
}
.devices-log-head h2 {
  font: 650 0.9rem/1.2 var(--font-display);
  letter-spacing: 0.03em;
  margin: 0;
}
.devices-log-list {
  max-height: 280px;
  overflow-y: auto;
  display: flex;
  flex-direction: column-reverse;
  gap: 2px;
  font-size: 0.76rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.devices-log-row {
  display: flex;
  gap: 6px;
  padding: 3px 5px;
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  animation: riseIn 0.25s var(--ease) both;
}
.devices-log-row:hover { background: rgba(255, 255, 255, 0.04); }
.devices-log-row .t { color: var(--muted); flex-shrink: 0; }
.devices-log-row .k {
  flex-shrink: 0;
  text-transform: uppercase;
  font-size: 0.6rem;
  letter-spacing: 0.06em;
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  align-self: flex-start;
}
.devices-log-row .k.call { color: var(--accent, #60a5fa); }
.devices-log-row .k.connection { color: var(--warn); }
.devices-log-row .k.sms { color: var(--brass-light); }
.devices-log-row .d { flex-shrink: 0; color: var(--muted); }
.devices-log-empty { color: var(--muted); font-size: 0.78rem; padding: 8px 0; }

/* ---- lines management ---- */

.lines-intro {
  margin: 0 0 13px;
  max-width: 52rem;
  line-height: 1.35;
  font-size: 0.88rem;
  font-weight: 500;
}
.lines-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line-strong);
  border-radius: calc(var(--radius) + 2px);
  background: var(--panel);
}
.lines-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}
.lines-table th {
  text-align: left;
  padding: 7px 6px;
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.lines-table td {
  padding: 6px 4px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.lines-table input,
.lines-table select {
  width: 100%;
  min-width: 5.5rem;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--ink);
  padding: 6px 8px;
  font-size: 0.78rem;
}
.lines-table input[type="checkbox"] {
  width: auto;
  min-width: 0;
}
.lines-table .mono {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.kind-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.kind-pill.android { color: var(--accent, #60a5fa); }
.kind-pill.yeastar { color: var(--success); }
.lines-actions {
  white-space: nowrap;
  display: flex;
  gap: 4px;
}
.lines-actions .danger { color: var(--danger); }
.identity-cell { min-width: 9rem; max-width: 13rem; }
.identity-details summary {
  cursor: pointer;
  list-style: none;
  font-size: 0.74rem;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.identity-details summary::-webkit-details-marker { display: none; }
.identity-details summary::before { content: "▸ "; color: var(--muted); }
.identity-details[open] summary::before { content: "▾ "; }
.identity-history {
  margin-top: 4px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 22rem;
}
.identity-history-row {
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}
.identity-history-row.active { color: var(--success); }
.identity-history-row.superseded { color: var(--muted); text-decoration: line-through; }
.device-history-details summary {
  white-space: normal;
  overflow: visible;
  text-overflow: unset;
  margin-top: 6px;
}
.device-history-details .identity-history { max-width: none; }

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(150px, 26vh) 1fr;
    grid-template-areas: "rail" "sidebar" "chat";
  }
  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .line-picker { width: min(220px, 100%); }
  .bubble { max-width: 85%; }
  .brand-tag { display: none; }
}
