:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e3e6eb;
  --text: #16181d;
  --muted: #5f6673;
  --accent: #0f766e;
  --accent-soft: #ccfbf1;
  --accent-text: #ffffff;
  --danger: #b42318;
  --danger-soft: #fee4e2;
  --warn: #b54708;
  --warn-soft: #fef0c7;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1013;
    --surface: #171a1f;
    --surface-2: #1f232a;
    --border: #2a2f37;
    --text: #eceef1;
    --muted: #9aa3b2;
    --accent: #2dd4bf;
    --accent-soft: #123b37;
    --accent-text: #04201d;
    --danger: #f97066;
    --danger-soft: #3d1715;
    --warn: #fdb022;
    --warn-soft: #3a2a0b;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* Layout */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 20px 12px; display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; padding: 0 10px 18px; }
.brand img { width: 30px; height: 30px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 10px;
  color: var(--text); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 20px; height: 20px; flex: none; }
.nav .badge { margin-left: auto; }
.sidebar .spacer { flex: 1; }
main { padding: 28px 32px 48px; max-width: 1100px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; z-index: 10;
    flex-direction: row; padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--border);
  }
  .brand, .sidebar .spacer, .sidebar .logout { display: none; }
  .nav { display: contents; }
  .nav a { flex: 1; flex-direction: column; gap: 2px; font-size: .7rem; padding: 6px 2px; justify-content: center; position: relative; }
  .nav .badge { position: absolute; top: 2px; right: calc(50% - 22px); margin: 0; }
  main { padding: 18px 16px 96px; }
  h1 { font-size: 1.3rem; }
}

/* Components */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 14px; }
.stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 20px; }
.stat .value { font-size: 1.8rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .label { color: var(--muted); font-size: .85rem; }
.two-col { grid-template-columns: 1fr 1fr; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 9px 16px; border-radius: 10px; font: inherit; font-weight: 550; cursor: pointer;
  text-decoration: none; min-height: 40px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .55; cursor: default; }
.btn svg { width: 18px; height: 18px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.badge { display: inline-block; font-size: .72rem; font-weight: 650; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.high { background: var(--danger-soft); color: var(--danger); }
.badge.new { background: var(--accent); color: var(--accent-text); }
.badge.owner { background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

.banner { border-radius: var(--radius); padding: 12px 16px; margin-bottom: 18px; background: var(--warn-soft); color: var(--warn); font-weight: 500; }

/* Call list */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input { flex: 1; min-width: 200px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 99px; padding: 6px 12px; font: inherit; font-size: .85rem; cursor: pointer; }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.list { list-style: none; margin: 0; padding: 0; }
.list li + li { border-top: 1px solid var(--border); }
.call-item { display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; align-items: center; padding: 12px 6px; color: inherit; text-decoration: none; border-radius: 10px; }
.call-item:hover { background: var(--surface-2); }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.call-item .title { font-weight: 600; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.call-item.unread .title::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.call-item .sub { color: var(--muted); font-size: .88rem; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.call-item .when { color: var(--muted); font-size: .8rem; text-align: right; white-space: nowrap; }
.empty { text-align: center; padding: 36px 12px; color: var(--muted); }

/* Transcript & simulator */
.transcript { display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 80%; padding: 10px 14px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word; }
.bubble.assistant { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 4px; }
.bubble.caller { align-self: flex-end; background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 4px; }
.bubble .who { display: block; font-size: .72rem; opacity: .75; font-weight: 600; margin-bottom: 2px; }
.bubble.typing { color: var(--muted); font-style: italic; }
.sim-box { display: flex; flex-direction: column; height: min(70vh, 640px); }
.sim-box .transcript { flex: 1; overflow-y: auto; padding: 4px 2px 12px; }
.composer { display: flex; gap: 8px; border-top: 1px solid var(--border); padding-top: 12px; }
.composer input { flex: 1; }
.mic.listening { background: var(--danger); border-color: var(--danger); color: #fff; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }

/* Forms */
label { display: block; font-weight: 550; margin-bottom: 6px; }
.field { margin-bottom: 16px; }
.field .hint { color: var(--muted); font-size: .82rem; margin-top: 4px; font-weight: 400; }
input[type=text], input[type=tel], input[type=password], input[type=number], input[type=search], input[type=time], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; min-height: 40px;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .chip:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.switch { display: flex; align-items: center; gap: 10px; font-weight: 500; cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }
.hours { display: grid; grid-template-columns: 110px auto 1fr 1fr; gap: 8px 10px; align-items: center; }
.hours .day { font-weight: 550; }
@media (max-width: 520px) { .hours { grid-template-columns: 80px auto 1fr 1fr; } }
.form-actions { position: sticky; bottom: 0; padding: 12px 0; background: linear-gradient(transparent, var(--bg) 30%); display: flex; justify-content: flex-end; }
@media (max-width: 760px) { .form-actions { bottom: 64px; } }
code.url { display: block; padding: 8px 10px; background: var(--surface-2); border-radius: 8px; font-size: .85rem; word-break: break-all; margin: 4px 0 10px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login img { width: 48px; height: 48px; margin-bottom: 12px; }
.error { color: var(--danger); font-size: .9rem; min-height: 1.4em; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 20; font-weight: 500;
}
#toast.show { opacity: 1; transform: translateX(-50%); }
@media (max-width: 760px) { #toast { bottom: 84px; } }
