:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --text: #111317;
  --muted: #6b6f76;
  --sidebar: #e6e6e6;
  --sidebar-border: #cfcfcf;
  --icon: #7a7a7a;
  --icon-hover-bg: #d9d9d9;
  --icon-active-bg: #c8c8c8;
  --icon-active: #5c5c5c;
  --page: #f4f5f7;
  --card: #ffffff;
  --border: #d5d9e0;
  --accent: #2457d6;
  --accent-text: #ffffff;
  --error: #c62828;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17191d;
    --text: #e6e8eb;
    --muted: #9aa3b0;
    --sidebar: #22252a;
    --sidebar-border: #33373e;
    --icon: #8d939c;
    --icon-hover-bg: #2c3036;
    --icon-active-bg: #383d44;
    --icon-active: #d4d8de;
    --page: #14161a;
    --card: #1e2127;
    --border: #343a44;
    --accent: #6b93ff;
    --accent-text: #0b1020;
    --error: #ff7b72;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
a { color: var(--accent); }

/* Signed-in layout: narrow sidebar + content */
.app { display: flex; min-height: 100vh; }

.sidebar {
  position: sticky; top: 0;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  flex: 0 0 58px; height: 100vh; padding: 14px 0 6px;
  background: var(--sidebar);
  border-right: 1px solid var(--sidebar-border);
}
.sidebar .brand { margin-bottom: 6px; }
.sidebar-bottom {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  margin-top: auto; width: 100%;
}

.nav-item {
  display: grid; place-items: center;
  width: 48px; height: 48px; border-radius: 10px;
  color: var(--icon);
}
.nav-item:hover { background: var(--icon-hover-bg); }
.nav-item[aria-current="page"] { background: var(--icon-active-bg); color: var(--icon-active); }
.nav-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.nav-item svg {
  width: 32px; height: 32px;
  fill: none; stroke: currentColor; stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round;
}

.version {
  max-width: 100%; padding: 0 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--muted); font-size: 11px;
}

.content { flex: 1; min-width: 0; padding: 14px 16px; }
.content h1 { margin: 0 0 16px; font-size: 1.6rem; line-height: 1.2; }

.brand {
  margin: 0; color: var(--muted);
  font-size: 13px; letter-spacing: .06em;
}

/* Login and error pages */
.login {
  display: grid; place-items: center;
  min-height: 100vh; padding: 16px;
  background: var(--page);
}
.card {
  width: min(380px, 100%); padding: 32px;
  background: var(--card);
  border: 1px solid var(--border); border-radius: 12px;
}
.card h1 { margin: 4px 0 24px; font-size: 1.4rem; }

label { display: block; margin: 0 0 6px; font-weight: 600; font-size: .9rem; }
input, select {
  width: 100%; margin-bottom: 16px; padding: 10px 12px;
  font: inherit; color: inherit; background: transparent;
  border: 1px solid var(--border); border-radius: 8px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
  padding: 10px 16px;
  font: inherit; font-weight: 600;
  color: var(--accent-text); background: var(--accent);
  border: 0; border-radius: 8px; cursor: pointer;
}
.card button { width: 100%; }
button.secondary { color: var(--text); background: transparent; border: 1px solid var(--border); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.error { margin: 12px 0 0; color: var(--error); font-size: .9rem; }
.error:empty { display: none; }

/* Settings */
.tabs {
  display: flex; gap: 4px;
  margin: 0 0 20px; border-bottom: 1px solid var(--border);
}
.tabs a {
  padding: 8px 12px; margin-bottom: -1px;
  color: var(--muted); text-decoration: none;
  border-bottom: 2px solid transparent;
}
.tabs a:hover { color: var(--text); }
.tabs a[aria-current="page"] { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }
.tabs button { padding: 8px 12px; margin: 0 0 -1px; color: var(--muted); background: none; border: 0; border-bottom: 2px solid transparent; border-radius: 0; font: inherit; font-weight: 400; cursor: pointer; }
.tabs button:hover { color: var(--text); background: none; }
.tabs button.active { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }

.panel { max-width: 640px; margin: 0 0 28px; }
.panel h2 { margin: 0 0 6px; font-size: 1.1rem; }
.help { margin: 0 0 14px; color: var(--muted); font-size: .9rem; }
.stack { max-width: 420px; }
.stack input { margin-bottom: 6px; }
.stack label { margin-top: 10px; }
.stack .help { margin-bottom: 14px; }
button:disabled { opacity: .5; cursor: default; }

.notice {
  margin: 14px 0; padding: 10px 12px;
  border: 1px solid var(--border); border-left-width: 4px; border-radius: 6px;
}
.notice p { margin: 0; }
.notice-ok { border-left-color: #2e7d32; }
.notice-error { border-left-color: var(--error); }

table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data caption { text-align: left; font-weight: 600; margin-bottom: 6px; }
table.data th, table.data td { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--border); }
table.data th { color: var(--muted); font-weight: 600; }
.optional { color: var(--muted); font-weight: 400; }
code { font-size: .9em; }

/* Audio: recordings list + details */
.sync-status { display: flex; align-items: center; gap: 6px; margin: 0; color: var(--muted); font-size: .85rem; white-space: nowrap; }
.sync-status .sync-text { overflow: hidden; text-overflow: ellipsis; }
.sync-status a { flex: none; }
.sync-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.sync-ok .dot { background: #2e7d32; }
.sync-error .dot { background: var(--error); }
.sync-error { color: var(--text); }
.sync-skipped .dot { background: #b26a00; }

.split {
  display: grid; grid-template-columns: minmax(260px, 340px) 1fr; gap: 0;
  height: calc(100vh - 136px); min-height: 360px;
  border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
}
.recording-list { overflow-y: auto; border-right: 1px solid var(--border); }
.recording-details { overflow-y: auto; padding: 16px 20px; }
.list-summary { margin: 0; padding: 8px 12px; color: var(--muted); font-size: .8rem; border-bottom: 1px solid var(--border); }

.recording-item {
  display: block; padding: 10px 12px; color: inherit; text-decoration: none;
  border-bottom: 1px solid var(--border); border-left: 3px solid transparent;
}
.recording-item:hover { background: var(--icon-hover-bg); }
.recording-item[aria-current="page"] { background: var(--icon-hover-bg); border-left-color: var(--accent); }
.recording-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.ri-row { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.ri-caller { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ri-company { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .85rem; }
.ri-none { color: var(--muted); font-style: italic; }
.ri-length { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.ri-meta { margin-top: 2px; color: var(--muted); font-size: .8rem; }

.badge {
  display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: .75rem; font-weight: 600;
  background: var(--icon-hover-bg); color: var(--muted); white-space: nowrap;
}
.badge-stored { background: #e3f1e4; color: #1e5e22; }
.badge-failed { background: #fbe4e4; color: #9b1c1c; }
.badge-pending { background: #e6edfb; color: #1d47ad; }
@media (prefers-color-scheme: dark) {
  .badge-stored { background: #1f3a22; color: #9fd8a3; }
  .badge-failed { background: #47201f; color: #ffb4ad; }
  .badge-pending { background: #1e2c4d; color: #a9c0ff; }
}

.pager { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; font-size: .85rem; color: var(--muted); }
.pager .disabled { visibility: hidden; }

.details-header h2 { margin: 0; font-size: 1.3rem; }
.details-header p { margin: 2px 0 0; color: var(--muted); }
.recording-details h3 { margin: 22px 0 8px; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
dl.details { display: grid; grid-template-columns: minmax(140px, 200px) 1fr; gap: 6px 16px; margin: 0; font-size: .9rem; }
dl.details dt { color: var(--muted); }
dl.details dd { margin: 0; overflow-wrap: anywhere; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .85em; }
.empty { padding: 24px 16px; color: var(--muted); }
.empty p { margin: 0 0 6px; }

@media (max-width: 760px) {
  .split { grid-template-columns: 1fr; height: auto; }
  .recording-list { max-height: 45vh; border-right: 0; border-bottom: 1px solid var(--border); }
}

/* Transcription */
label.check { display: flex; align-items: center; gap: 8px; margin: 10px 0 0; font-weight: 400; }
label.check input { width: auto; margin: 0; }

.transcript-meta { margin: 0 0 8px; color: var(--muted); font-size: .85rem; }
.transcript {
  max-height: 45vh; overflow-y: auto; padding: 4px 12px;
  border: 1px solid var(--border); border-radius: 8px; font-size: .92rem;
}
.turn { display: grid; grid-template-columns: 3.2em 1fr; gap: 8px; margin: 8px 0; line-height: 1.45; }
.turn-time { color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; padding-top: .15em; }
.turn-speaker { margin-right: 4px; }
.list-showing { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: .85rem; background: var(--icon-hover-bg); }
button.small { padding: 5px 10px; font-size: .85rem; }
.badge-transcribed { background: #e3f1e4; color: #1e5e22; }
@media (prefers-color-scheme: dark) { .badge-transcribed { background: #1f3a22; color: #9fd8a3; } }

/* Settings tabs: switched in the page by Datastar */
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.notice table.data { margin-top: 10px; }

/* Sync status: a pulsing dot while the sync loop is working */
.sync-busy .dot { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }

/* Dashboard */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; max-width: 900px; }
.tile {
  display: flex; flex-direction: column; gap: 2px; padding: 14px 16px;
  color: inherit; text-decoration: none;
  border: 1px solid var(--border); border-radius: 10px;
}
.tile:hover { background: var(--icon-hover-bg); }
.tile-value { font-size: 1.6rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.tile-label { color: var(--muted); font-size: .85rem; }

/* Call processing: people on a call */
.people { list-style: none; margin: 0 0 8px; padding: 0; }
.people li { display: grid; grid-template-columns: 6.5em 1fr; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: .92rem; }
.people li:last-child { border-bottom: 0; }
.people q { display: block; margin-top: 2px; color: var(--muted); font-style: italic; }
.hint { color: var(--muted); font-size: .8rem; margin-left: 4px; }
.role { align-self: start; justify-self: start; padding: 1px 7px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--icon-hover-bg); color: var(--muted); }
.role-employee { background: #e6edfb; color: #1d47ad; }
.role-customer { background: #fdf0dc; color: #8a4b00; }
.turn-speaker.role-employee { color: #1d47ad; }
.turn-speaker.role-customer { color: #8a4b00; }
@media (prefers-color-scheme: dark) {
  .role-employee { background: #1e2c4d; color: #a9c0ff; }
  .role-customer { background: #3d2c12; color: #ffcf8a; }
  .turn-speaker.role-employee { color: #a9c0ff; }
  .turn-speaker.role-customer { color: #ffcf8a; }
}

/* Settings: employees */
.name-list { list-style: none; margin: 0 0 14px; padding: 0; max-width: 640px; }
.name-list li { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.name-actions { display: flex; gap: 6px; align-items: center; }
.alias { margin-left: 6px; color: var(--muted); font-size: .85rem; }
button.link { padding: 0 4px; color: var(--muted); background: none; border: 0; font-weight: 400; }
button.link:hover { color: var(--error); }
select.small { width: auto; margin: 0; padding: 4px 8px; font-size: .85rem; }
.inline-form { display: flex; gap: 8px; max-width: 420px; }
.inline-form input { margin: 0; }
.inline-form button { white-space: nowrap; }
details.panel summary { cursor: pointer; color: var(--muted); }

/* Page header: title on the left, sync status tucked in the top right */
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 0 0 14px; }
.page-header h1 { margin: 0; }
#sync-status { min-width: 0; max-width: 60%; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
#sync-status .sync-status { max-width: 100%; }

/* Audio filters */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 12px; }
.filters input, .filters select { width: auto; margin: 0; padding: 6px 10px; font-size: .9rem; }
.filters .filter-search { flex: 1 1 240px; min-width: 180px; }
.filter-date { display: flex; align-items: center; gap: 6px; margin: 0; color: var(--muted); font-size: .85rem; font-weight: 400; }
@media (max-width: 700px) { .page-header { flex-wrap: wrap; } #sync-status { max-width: 100%; align-items: flex-start; } }

/* Recording details tabs */
.details-tabs { margin: 12px 0 14px; }
.details-header p:empty { display: none; }
.muted { color: var(--muted); }
.person-name[title]:not([title=""]) { text-decoration: underline dotted var(--border); text-underline-offset: 3px; cursor: help; }
.status-text { margin-left: 4px; }
.status-action { margin-top: 6px; }
.recording-details .tab-panel > h3:first-child { margin-top: 0; }
.recording-details .transcript { max-height: none; }
.call-summary { margin: 0 0 14px; padding: 10px 12px; border-left: 3px solid var(--accent); background: var(--icon-hover-bg); border-radius: 0 6px 6px 0; line-height: 1.45; }

/* Signing in and setting up an account */
.card.wide { width: min(460px, 100%); }
.card .help { margin: -8px 0 16px; }
.card button + .help { margin: 14px 0 0; }
.card button.link { width: auto; margin-top: 12px; padding: 0; color: var(--muted); }
.login > .error { width: min(380px, 100%); text-align: center; }
.steps { margin: 0 0 16px; padding-left: 20px; font-size: .92rem; }
.steps li { margin-bottom: 6px; }
.qr { display: block; width: 200px; height: 200px; margin: 0 auto 12px; border-radius: 6px; }
#totp-setup details { margin: 0 0 16px; font-size: .9rem; }
#totp-setup summary { cursor: pointer; color: var(--muted); text-align: center; }
.secret-key { margin: 6px 0 0; font-size: 1rem; letter-spacing: .05em; text-align: center; user-select: all; }
.recovery-codes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 24px; margin: 0 0 12px; padding: 12px 12px 12px 36px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 1rem; }
.card .recovery-codes + p button { width: auto; }
#welcome-notice .notice { margin: 16px 0 0; }
.invite-link { display: flex; gap: 8px; margin-top: 8px; }
.invite-link input { margin: 0; padding: 6px 8px; font-size: .85rem; }
#users .inline-form { max-width: 640px; }
.name-list .name-main { flex: 1 1 260px; min-width: 0; }

/* Dashboard: usage */
.usage { margin-top: 24px; max-width: 960px; }
.usage h2 { margin: 0 0 10px; font-size: 1.1rem; }
.usage-table { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums;
  background: var(--card); border: 1px solid var(--border); border-radius: 8px; }
.usage-table th, .usage-table td { padding: 7px 12px; text-align: right; border-bottom: 1px solid var(--border); }
.usage-table th[scope="row"] { text-align: left; font-weight: 400; color: var(--muted); }
.usage-table th[scope="row"] .hint { display: block; margin: 0; }
.usage-table thead th { font-weight: 600; }
.usage-table .usage-group th { text-align: left; font-weight: 600; background: var(--icon-hover-bg); }
.usage .help { margin: 8px 0 0; }

/* The call's audio, above the tabs, with a download link styled as a button. */
.player { display: flex; align-items: center; gap: 10px; margin: 8px 0 12px; }
.player audio { flex: 1; min-width: 0; height: 36px; }
a.button { display: inline-block; text-decoration: none; border-radius: 8px; font-weight: 600; white-space: nowrap; }
a.button.secondary { color: var(--text); border: 1px solid var(--border); }
a.button.small { padding: 5px 10px; font-size: .85rem; }
a.button:hover { background: var(--icon-hover-bg); }
/* Transcript times jump the player to that point. */
button.turn-time { padding: .15em 0 0; margin: 0; background: none; border: 0; border-radius: 0; font-weight: 400; text-align: left; align-self: start; cursor: pointer; }
button.turn-time:hover { color: var(--accent); text-decoration: underline; }
