:root {
  --bg:        #060d1a;
  --bg2:       #0a1628;
  --card:      rgba(12, 26, 46, 0.82);
  --card2:     rgba(16, 38, 66, 0.68);
  --border:    rgba(80, 150, 255, 0.2);
  --text:      #eaf3ff;
  --muted:     #8faacc;
  --blue:      #2f9bff;
  --cyan:      #14d8ff;
  --green:     #3de68c;
  --red:       #ff4f4f;
  --gold:      #f6c66a;
  --purple:    #a78bfa;
  --shadow:    0 20px 60px rgba(0,0,0,.55);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* ─── Reset ────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(ellipse at 75% -5%, rgba(47,155,255,.2) 0%, transparent 38%),
    radial-gradient(ellipse at 10% 15%, rgba(20,216,255,.12) 0%, transparent 32%),
    radial-gradient(ellipse at 50% 105%, rgba(167,139,250,.08) 0%, transparent 40%),
    linear-gradient(180deg, #060d1a 0%, #020710 100%);
  min-height: 100dvh;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
button { cursor: pointer; border: 0; color: inherit; }
input {
  width: 100%;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: rgba(4, 12, 24, .75);
  color: var(--text);
  padding: 14px 16px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
input:focus { border-color: rgba(47,155,255,.7); box-shadow: 0 0 0 3px rgba(47,155,255,.12); }

/* ─── Panels & Cards ───────────────────────────────────────────── */
.panel, .client-card, .mini-card {
  background: linear-gradient(145deg, var(--card), rgba(5,14,26,.65));
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

/* ─── App Shell ────────────────────────────────────────────────── */
.app-shell {
  width: min(100%, 540px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) 14px calc(env(safe-area-inset-bottom) + 16px);
  position: relative;
  overflow: hidden;
}

/* ─── Screens ──────────────────────────────────────────────────── */
.screen {
  display: block;
  visibility: hidden;
  opacity: 0;
  position: absolute;
  top: 0; left: 0; right: 0;
  pointer-events: none;
  z-index: 0;
}
.screen.active {
  visibility: visible;
  opacity: 1;
  position: relative;
  pointer-events: auto;
  z-index: 1;
}
.screen.animate-in {
  animation: rise .25s ease both;
}
@keyframes rise { from { opacity:0; transform:translateY(10px); } to { opacity:1; transform:none; } }

/* ─── PIN Screen ───────────────────────────────────────────────── */
.pin-wrapper {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 32px;
  padding: 20px;
}
.pin-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}
.pin-brand {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -.3px;
}
.pin-brand em { font-style: normal; color: var(--cyan); }
.pin-card {
  width: min(100%, 360px);
  padding: 32px 24px;
  display: grid;
  gap: 24px;
  text-align: center;
}
.pin-label { margin: 0; color: var(--muted); font-size: 14px; letter-spacing: .4px; }
.pin-dots {
  display: flex;
  justify-content: center;
  gap: 14px;
  padding: 4px 0;
}
.pin-dots span {
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  transition: background .15s, border-color .15s;
}
.pin-dots span.filled { background: var(--cyan); border-color: var(--cyan); box-shadow: 0 0 12px rgba(20,216,255,.55); }
.pin-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.key-btn {
  height: 64px;
  border-radius: 18px;
  font-size: 24px;
  font-weight: 700;
  background: rgba(47,155,255,.1);
  border: 1px solid var(--border);
  transition: background .15s, transform .1s;
}
.key-btn:active { transform: scale(.93); background: rgba(47,155,255,.22); }
.key-btn.ghost { font-size: 20px; background: rgba(255,255,255,.06); }
.pin-error { margin: 0; color: var(--red); font-size: 13px; font-weight: 600; }
.pin-error.hidden { visibility: hidden; }

@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%,60% { transform: translateX(-8px); }
  40%,80% { transform: translateX(8px); }
}
.shake { animation: shake .4s ease; }

/* ─── Brand Mark ───────────────────────────────────────────────── */
.brand { display: flex; align-items: center; gap: 10px; font-size: 21px; font-weight: 700; }
.brand em { font-style: normal; color: var(--blue); }
.brand-mark { display: flex; align-items: flex-end; gap: 4px; height: 30px; }
.brand-mark span { display: block; width: 5px; border-radius: 9px; background: linear-gradient(var(--cyan), var(--blue)); }
.brand-mark span:nth-child(1) { height: 14px; }
.brand-mark span:nth-child(2) { height: 24px; }
.brand-mark span:nth-child(3) { height: 30px; }
.brand-mark span:nth-child(4) { height: 18px; }

/* ─── Topbar ───────────────────────────────────────────────────── */
.topbar { height: 70px; display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

/* ─── Status Pills ─────────────────────────────────────────────── */
.status-pill {
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(47,155,255,.1);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  transition: color .3s;
}
.status-pill.good { color: var(--green); border-color: rgba(61,230,140,.3); background: rgba(61,230,140,.08); }
.status-pill.bad  { color: var(--red);   border-color: rgba(255,79,79,.3);  background: rgba(255,79,79,.08); }
.status-pill.loading { color: var(--muted); }

/* ─── Search ───────────────────────────────────────────────────── */
.search-row { margin-bottom: 14px; }

/* ─── Sections ─────────────────────────────────────────────────── */
.section-heading { display: flex; justify-content: space-between; align-items: center; margin: 4px 2px 12px; }
.section-heading h2 { margin: 0; font-size: 17px; }
.section-heading span { color: var(--muted); font-size: 13px; }
.section-heading.compact { margin-top: 0; }

/* ─── Client Cards ─────────────────────────────────────────────── */
.clients-list {
  display: grid;
  gap: 6px;
  padding-bottom: 20px;
}
.client-card {
  padding: 10px 12px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  cursor: pointer;
  background: linear-gradient(145deg, var(--card), rgba(5,14,26,.65));
  border: 1px solid var(--border);
  border-radius: 18px;
  transition: background .15s, border-color .2s;
}
.client-card:hover { border-color: rgba(47,155,255,.35); }
.client-card:active { background: rgba(47,155,255,.08); border-color: rgba(47,155,255,.4); }

.avatar {
  width: 46px; height: 46px; border-radius: 14px;
  display: grid; place-items: center;
  font-weight: 800; font-size: 17px; color: white;
  border: 1px solid rgba(255,255,255,.12);
  background: linear-gradient(135deg, rgba(47,155,255,.9), rgba(20,216,255,.6));
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(0,0,0,.25);
}
.avatar.cyan   { background: linear-gradient(135deg, #14d8ff, #2f9bff); }
.avatar.gold   { background: linear-gradient(135deg, #f6a623, #f6c66a); }
.avatar.green  { background: linear-gradient(135deg, #3de68c, #1aad5e); }
.avatar.purple { background: linear-gradient(135deg, #a78bfa, #6d28d9); }
.avatar.blue   { background: linear-gradient(135deg, #2f9bff, #1750a0); }

.client-meta { min-width: 0; }
.client-meta strong { display: block; font-size: 16px; }
.did { display: block; color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.badges { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 5px; }
.badge { font-size: 10px; padding: 3px 7px; border-radius: 999px; background: rgba(47,155,255,.12); color: #83c8ff; border: 1px solid rgba(47,155,255,.22); }
.badge.voice-badge { background: rgba(20,216,255,.1); color: var(--cyan); border-color: rgba(20,216,255,.25); }

.call-btn {
  width: 44px; height: 44px; border-radius: 14px;
  background: rgba(47,155,255,.12); color: var(--blue);
  font-size: 18px; border: 1px solid rgba(47,155,255,.22);
  transition: background .15s, transform .1s;
  flex-shrink: 0;
}
.call-btn:active { transform: scale(.85); background: rgba(47,155,255,.25); }

/* ─── Empty State ──────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}
.empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { margin: 0 0 6px; font-size: 16px; color: var(--text); }
.empty-state small { font-size: 13px; }

/* ─── Call Screen ──────────────────────────────────────────────── */
.call-screen {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 100dvh;
}
.call-screen.active {
  display: flex;
}

.call-header {
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.client-mini { display: flex; align-items: center; gap: 12px; }
.client-mini strong { display: block; font-size: 16px; }
.client-mini small { display: block; color: var(--muted); font-size: 11px; }
.transport-chip {
  padding: 7px 12px; border-radius: 999px; font-size: 12px;
  background: rgba(47,155,255,.1); border: 1px solid var(--border); color: var(--muted);
}

.call-visual {
  padding: 22px 16px;
  text-align: center;
  overflow: hidden;
  flex: 1 0 auto;
}
.call-status { color: var(--blue); font-size: 14px; margin: 0 0 18px; letter-spacing: .3px; }

.main-orb {
  width: 148px; height: 148px; border-radius: 50%; margin: 0 auto 18px;
  display: grid; place-items: center;
  position: relative;
  background: radial-gradient(circle at 32% 28%, #163568, #071324 68%);
  border: 1px solid rgba(47,155,255,.38);
  box-shadow: 0 0 44px rgba(47,155,255,.28), inset 0 0 36px rgba(47,155,255,.14);
  transition: box-shadow .35s;
}
.main-orb span { color: var(--gold); font-size: 42px; font-weight: 900; z-index: 2; position: relative; }
.main-orb i {
  position: absolute; inset: -8px; border-radius: inherit;
  border: 1px solid rgba(47,155,255,.18);
  animation: pulse 2.6s infinite ease-out;
}
.main-orb i:nth-child(3) { animation-delay: .85s; }
.main-orb i:nth-child(4) { animation-delay: 1.7s; }
.main-orb.speaking {
  box-shadow: 0 0 72px rgba(20,216,255,.6), inset 0 0 50px rgba(20,216,255,.18);
  border-color: rgba(20,216,255,.55);
}
@keyframes pulse { from { transform:scale(.9); opacity:.8; } to { transform:scale(1.6); opacity:0; } }

.call-visual h1 { margin: 0 0 4px; font-size: 28px; }
.call-visual p  { margin: 0; color: var(--muted); font-size: 12px; }
.timer { font-size: 28px; margin: 10px 0; font-variant-numeric: tabular-nums; letter-spacing: .5px; }
#waveCanvas { width: 100%; height: 60px; display: block; margin: 4px 0; }

.bridge-state { font-size: 12px; color: var(--muted); }
.bridge-state.good { color: var(--green); }

/* ─── Mini Cards Row ───────────────────────────────────────────── */
.cards-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.mini-card { padding: 12px; min-width: 0; }
.mini-card span { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.mini-card strong { display: block; margin-top: 4px; color: #80caff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }

/* ─── Transcript ───────────────────────────────────────────────── */
.transcript-panel { padding: 14px; max-height: 220px; overflow-y: auto; }
.transcript { display: grid; gap: 12px; }
.line { display: grid; grid-template-columns: 70px 1fr; gap: 10px; font-size: 13px; align-items: start; }
.line b { color: #5ca8ff; line-height: 1.3; }
.line p  { margin: 0; color: #cce0f5; line-height: 1.4; }
.line.user b { color: var(--cyan); }
.line.tool b { color: var(--gold); }
.line.tool p { color: var(--muted); font-family: ui-monospace, monospace; font-size: 11px; }

.dot-blink { color: var(--green); animation: blink 1.4s infinite; }
@keyframes blink { 0%,100% { opacity:1; } 50% { opacity:.3; } }

/* ─── Call Controls ────────────────────────────────────────────── */
.call-controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding-bottom: env(safe-area-inset-bottom, 8px);
}
.control-btn {
  min-height: 72px;
  border-radius: 22px;
  background: rgba(255,255,255,.07);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  gap: 4px;
  font-size: 22px;
  transition: background .15s, transform .1s;
}
.control-btn span { font-size: 11px; color: var(--muted); }
.control-btn:active { transform: scale(.93); }
.control-btn.active { background: rgba(20,216,255,.15); border-color: rgba(20,216,255,.4); box-shadow: 0 0 20px rgba(20,216,255,.12); }
.control-btn.active span { color: var(--cyan); }
.control-btn.danger { background: linear-gradient(135deg, rgba(220,30,30,.8), rgba(140,10,10,.7)); border-color: rgba(255,90,90,.5); color: white; }
.control-btn.danger span { color: rgba(255,200,200,.8); }
.control-btn.danger:active { transform: scale(.93); }

/* ─── Toast ────────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: 24px;
  transform: translateX(-50%) translateY(16px);
  opacity: 0; pointer-events: none;
  background: rgba(8, 20, 36, .95);
  border: 1px solid var(--border);
  padding: 12px 18px; border-radius: 999px;
  color: var(--text); font-size: 14px;
  box-shadow: var(--shadow);
  transition: .22s ease;
  z-index: 100;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
  overflow: hidden; text-overflow: ellipsis;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ─── Desktop tweaks ───────────────────────────────────────────── */
@media (min-width: 720px) {
  .app-shell { padding-left: 24px; padding-right: 24px; }
  .call-screen.active {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 1fr auto auto;
    gap: 14px;
    align-items: start;
    min-height: auto;
  }
  .call-header  { grid-column: 1 / -1; }
  .call-visual  { grid-column: 1; grid-row: 2 / 4; }
  .cards-row    { grid-column: 2; grid-row: 2; }
  .transcript-panel { grid-column: 2; grid-row: 3; max-height: 300px; }
  .call-controls { grid-column: 1 / -1; }
}
