:root {
  color-scheme: light;
  --ink: #171a20;
  --muted: #68717d;
  --line: #dfe3e8;
  --surface: #ffffff;
  --canvas: #f3f5f7;
  --accent: #08766d;
  --accent-dark: #055a54;
  --danger: #a33d51;
  --warning-bg: #f8ecef;
  --agent: #e9f3f2;
  --shadow: 0 20px 60px rgb(20 28 38 / 14%);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
*[hidden] { display: none !important; }

html { min-width: 320px; background: var(--canvas); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--canvas);
  font-size: 14px;
  letter-spacing: 0;
}

button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, tr:focus-visible {
  outline: 3px solid rgb(8 118 109 / 22%);
  outline-offset: 2px;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 22px; line-height: 1.1; font-weight: 710; }
h2 { font-size: 20px; line-height: 1.2; }
h3 { font-size: 15px; }

.eyebrow {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 76px;
  padding: 12px clamp(20px, 4vw, 64px);
  border-bottom: 1px solid var(--line);
  background: rgb(255 255 255 / 96%);
  backdrop-filter: blur(12px);
}

.brand-lockup, .topbar-actions, .filters, .section-heading, .drawer-header, .turn-head {
  display: flex;
  align-items: center;
}

.brand-lockup { gap: 14px; }
.brand-mark {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  background: var(--ink);
  color: #fff;
  font-size: 17px;
  font-weight: 800;
}
.brand-mark.small { width: 46px; height: 46px; font-size: 14px; }

.topbar-actions { gap: 18px; }
.topbar-actions form { margin: 0; }
.live-status { display: flex; align-items: center; gap: 8px; color: #3c4652; font-size: 13px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #1d9b6c; box-shadow: 0 0 0 4px #e4f4ed; }

.text-button, .icon-button {
  border: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 650;
}
.text-button { padding: 8px 0; }
.text-button:hover { color: var(--accent); }
.text-button.muted { color: var(--muted); }

.workspace { padding: 0 clamp(20px, 4vw, 64px) 64px; }

.view-tabs { display: flex; gap: 24px; border-bottom: 1px solid var(--line); }
.view-tab { padding: 18px 2px 14px; border: 0; border-bottom: 3px solid transparent; background: transparent; color: var(--muted); font-weight: 750; }
.view-tab.active { border-bottom-color: var(--accent); color: var(--ink); }

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  max-width: 920px;
  padding: 28px 0;
}
.metrics > div { padding: 0 28px; border-left: 1px solid var(--line); }
.metrics > div:first-child { padding-left: 0; border-left: 0; }
.metrics span { display: block; font-size: 29px; line-height: 1; font-weight: 740; }
.metrics small { display: block; margin-top: 7px; color: var(--muted); font-size: 12px; }

.filters {
  gap: 12px;
  padding: 18px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.search-field { flex: 1 1 400px; }
.date-field { flex: 0 1 170px; }
.filters label, .field-stack label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}
.filters input, .filters select, .login-form input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid #cdd3da;
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
}
.filters select { min-width: 150px; }
.filters input:hover, .login-form input:hover { border-color: #9ba5b1; }
.secondary-button, .primary-button, .load-more {
  min-height: 42px;
  border-radius: 4px;
  font-weight: 700;
}
.secondary-button {
  align-self: end;
  padding: 0 18px;
  border: 1px solid #cdd3da;
  background: var(--surface);
  color: var(--ink);
}
.secondary-button:hover { border-color: var(--accent); color: var(--accent); }

.calls-section { padding-top: 28px; }
.appeals-section { padding-top: 0; }
.appeals-section > .section-heading { margin-top: 28px; }
.appeals-table th:nth-child(1) { width: 190px; }
.appeals-table th:nth-child(2) { width: 190px; }
.appeals-table th:nth-child(3) { width: 220px; }
.appeals-table th:nth-child(4) { width: auto; }
.appeals-table th:nth-child(5) { width: 170px; }
.urgent-number { color: var(--danger); font-weight: 800; }
.section-heading { justify-content: space-between; margin-bottom: 14px; }
.section-heading span { color: var(--muted); }
.table-wrap { overflow-x: auto; border-top: 2px solid var(--ink); background: var(--surface); }
table { width: 100%; min-width: 980px; border-collapse: collapse; table-layout: fixed; }
th {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  text-align: left;
  text-transform: uppercase;
}
th:nth-child(1) { width: 190px; }
th:nth-child(2) { width: 190px; }
th:nth-child(3) { width: auto; }
th:nth-child(4) { width: 90px; }
th:nth-child(5) { width: 120px; }
th:nth-child(6) { width: 150px; }
td { padding: 15px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr { transition: background-color 140ms ease, transform 140ms ease; }
tbody tr:hover { background: #f0f7f6; }
tbody tr:active { transform: translateY(1px); }
.cell-primary, .phone-value, .transcript-preview { display: block; line-height: 1.35; }
.cell-secondary { display: block; margin-top: 5px; color: var(--muted); font-size: 12px; line-height: 1.35; }
.mono { font-family: "SFMono-Regular", Consolas, monospace; font-size: 11px; }
.transcript-preview { max-width: 560px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.route-number { display: inline-grid; min-width: 38px; height: 30px; place-items: center; border: 1px solid #b7c0ca; font-weight: 800; }
.duration { color: #3c4652; white-space: nowrap; }
.call-status { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 750; }
.call-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #71808e; }
.call-status.completed::before { background: var(--accent); }
.call-status.registered::before { background: #4169a1; }
.call-status.active::before, .call-status.no_dialog::before { background: var(--danger); }
.attention-mark { display: inline-grid; width: 18px; height: 18px; place-items: center; border-radius: 50%; background: var(--warning-bg); color: var(--danger); }

.empty-state { padding: 70px 24px; text-align: center; }
.empty-state strong, .empty-state span { display: block; }
.empty-state strong { font-size: 17px; }
.empty-state span { margin-top: 7px; color: var(--muted); }
.load-more { display: block; margin: 22px auto 0; padding: 0 24px; border: 1px solid var(--ink); background: transparent; }
.load-more:hover { background: var(--ink); color: #fff; }

.drawer-backdrop { position: fixed; inset: 0; z-index: 39; background: rgb(14 18 23 / 34%); }
.call-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 40;
  width: min(720px, 94vw);
  height: 100vh;
  overflow-y: auto;
  background: var(--surface);
  box-shadow: var(--shadow);
  transform: translateX(102%);
  transition: transform 180ms ease;
}
.call-drawer.open { transform: translateX(0); }
.drawer-header {
  position: sticky;
  top: 0;
  z-index: 2;
  justify-content: space-between;
  min-height: 86px;
  padding: 20px 28px;
  border-bottom: 1px solid var(--line);
  background: rgb(255 255 255 / 96%);
  backdrop-filter: blur(10px);
}
.icon-button { width: 40px; height: 40px; font-size: 29px; line-height: 1; }
.drawer-content { padding: 24px 28px 50px; }
.call-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border-top: 2px solid var(--ink); }
.meta-item { min-width: 0; padding: 14px 12px 14px 0; border-bottom: 1px solid var(--line); }
.meta-item:nth-child(even) { padding-left: 12px; }
.meta-item small { display: block; margin-bottom: 5px; color: var(--muted); font-size: 11px; text-transform: uppercase; }
.meta-item strong { display: block; overflow-wrap: anywhere; line-height: 1.35; }
.attention-box { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 20px 0; padding: 14px 16px; border-left: 3px solid var(--danger); background: var(--warning-bg); color: #732c3b; }
.dialogue-heading { display: flex; align-items: baseline; justify-content: space-between; margin: 30px 0 12px; }
.dialogue-heading span { color: var(--muted); font-size: 12px; }
.turn-block { padding: 18px 0 22px; border-top: 1px solid var(--line); }
.turn-head { justify-content: space-between; margin-bottom: 11px; color: var(--muted); font-size: 11px; }
.turn-number { font-weight: 750; text-transform: uppercase; }
.message { margin-top: 9px; padding: 12px 14px; border-radius: 4px; }
.message.caller { margin-right: 60px; background: #f0f2f5; }
.message.agent { margin-left: 60px; background: var(--agent); }
.message-label { display: block; margin-bottom: 5px; color: var(--muted); font-size: 11px; font-weight: 750; }
.message p { line-height: 1.5; white-space: pre-wrap; }
.turn-tech { margin-top: 9px; color: #89919b; font-family: "SFMono-Regular", Consolas, monospace; font-size: 10px; overflow-wrap: anywhere; }
.empty-dialogue { padding: 30px 0; color: var(--muted); }
.appeal-description, .status-form, .appeal-history { padding: 24px 0; border-top: 1px solid var(--line); }
.appeal-description { margin-top: 24px; }
.appeal-description p, .appeal-history p { margin-top: 10px; line-height: 1.55; }
.status-form { display: grid; gap: 12px; }
.status-form select, .status-form textarea { width: 100%; padding: 10px 12px; border: 1px solid #cdd3da; border-radius: 4px; background: var(--surface); }
.status-form textarea { min-height: 88px; resize: vertical; }
.status-form .primary-button { width: auto; margin: 0; padding: 0 20px; justify-self: start; }
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 80; padding: 12px 18px; border-radius: 4px; background: var(--ink); color: #fff; box-shadow: var(--shadow); transform: translateX(-50%); }

.login-page { display: grid; min-height: 100vh; place-items: center; background: #e9edf1; }
.login-shell { display: grid; grid-template-columns: 1.1fr .9fr; width: min(900px, calc(100vw - 40px)); min-height: 500px; background: var(--surface); box-shadow: var(--shadow); }
.login-brand { display: flex; flex-direction: column; justify-content: flex-end; padding: 48px; background: #182027; color: #fff; }
.login-brand .brand-mark { margin-bottom: auto; background: #fff; color: var(--ink); }
.login-brand .eyebrow { color: #aeb8c2; }
.login-brand h1 { max-width: 340px; font-size: 48px; line-height: 1.02; }
.login-note { margin-top: 20px; color: #aeb8c2; }
.login-form-wrap { display: grid; padding: 48px; place-items: center; }
.login-form { width: 100%; max-width: 320px; }
.field-stack + .field-stack { margin-top: 18px; }
.primary-button { width: 100%; margin-top: 24px; border: 0; background: var(--accent); color: #fff; }
.primary-button:hover { background: var(--accent-dark); }
.form-error { margin-top: 14px; color: var(--danger); font-size: 12px; line-height: 1.4; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}

@media (max-width: 760px) {
  .topbar { align-items: flex-start; min-height: auto; padding: 14px 16px; }
  .brand-mark.small { display: none; }
  .topbar h1 { font-size: 18px; }
  .topbar-actions { gap: 12px; }
  .live-status { display: none; }
  .workspace { padding: 0 16px 40px; }
  .metrics { grid-template-columns: repeat(2, 1fr); padding: 16px 0; }
  .metrics > div { padding: 12px 14px; border-left: 1px solid var(--line); }
  .metrics > div:nth-child(odd) { padding-left: 0; border-left: 0; }
  .metrics span { font-size: 25px; }
  .filters { align-items: stretch; flex-wrap: wrap; }
  .search-field { flex-basis: 100%; }
  .date-field { flex: 1 1 130px; }
  .secondary-button { flex: 1 1 100%; }
  .table-wrap { overflow: visible; border-top: 2px solid var(--ink); background: transparent; }
  table, tbody { display: block; min-width: 0; }
  thead { display: none; }
  tbody tr { display: grid; grid-template-columns: 1fr auto; padding: 16px 0; border-bottom: 1px solid var(--line); }
  td { display: block; padding: 3px 0; border: 0; }
  td:nth-child(1), td:nth-child(2), td:nth-child(3) { grid-column: 1 / -1; }
  td:nth-child(4), td:nth-child(5) { margin-top: 8px; }
  td:nth-child(6) { grid-column: 2; grid-row: 4; align-self: center; margin-top: 8px; }
  .transcript-preview { white-space: normal; }
  .cell-secondary.mono { display: none; }
  .call-drawer { width: 100vw; }
  .drawer-header, .drawer-content { padding-left: 18px; padding-right: 18px; }
  .call-meta { grid-template-columns: 1fr; }
  .meta-item:nth-child(even) { padding-left: 0; }
  .message.caller { margin-right: 20px; }
  .message.agent { margin-left: 20px; }
  .login-shell { grid-template-columns: 1fr; width: min(520px, calc(100vw - 24px)); }
  .login-brand { min-height: 250px; padding: 28px; }
  .login-brand h1 { font-size: 38px; }
  .login-form-wrap { padding: 34px 28px; }
}
