/* ── Tokens ──────────────────────────────────────────────────────────────
   Strictly monochrome: hierarchy comes from weight, spacing and one filet,
   never from hue. Urgency reads as a rule in the margin, not a red pill. */
:root {
  --bg: #ffffff;
  --surface: #fafafa;
  --surface-2: #f4f4f5;
  --border: #e6e6e8;
  --border-strong: #d1d1d6;
  --text: #09090b;
  --text-2: #5c5c66;
  --text-3: #9c9ca6;
  --accent: #09090b;
  --accent-fg: #ffffff;
  --focus: #09090b;

  --radius: 10px;
  --radius-sm: 7px;
  --nav-w: 232px;
  --sheet-w: 520px;
  --ease: cubic-bezier(0.32, 0.72, 0, 1);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0a0a;
    --surface: #101011;
    --surface-2: #17171a;
    --border: #262629;
    --border-strong: #3a3a3f;
    --text: #fafafa;
    --text-2: #a0a0aa;
    --text-3: #6c6c76;
    --accent: #fafafa;
    --accent-fg: #0a0a0a;
    --focus: #fafafa;
  }
}

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

/* `display` on a class beats the user-agent rule for [hidden], so screens
   declared with grid/flex would stay visible when hidden. Make it explicit. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}

button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 34px;
  padding: 0 13px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 120ms var(--ease), border-color 120ms var(--ease);
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn--primary:hover { opacity: 0.86; background: var(--accent); }

.btn--ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn--ghost:hover { background: var(--surface-2); color: var(--text); }

.btn--danger { border-color: var(--border-strong); color: var(--text-2); }
.btn--danger:hover { background: var(--surface-2); color: var(--text); border-color: var(--text-3); }

.btn--sm { height: 29px; padding: 0 10px; font-size: 13px; }
.btn--full { width: 100%; }
.btn--icon { width: 32px; height: 32px; padding: 0; }

/* ── Sign in ─────────────────────────────────────────────────────────── */
.signin {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--surface);
}
.signin__card {
  width: 100%;
  max-width: 352px;
  padding: 32px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.signin__title { margin: 0; font-size: 21px; font-weight: 600; letter-spacing: -0.015em; }
.signin__sub { margin: 4px 0 26px; color: var(--text-2); font-size: 13.5px; }

/* ── Fields ──────────────────────────────────────────────────────────── */
.field { display: block; margin-bottom: 16px; }
.field__label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 500; color: var(--text-2); }
.field__hint { display: block; margin-top: 5px; font-size: 12.5px; color: var(--text-3); line-height: 1.45; }

input[type="text"], input[type="email"], input[type="password"], input[type="tel"],
input[type="number"], select, textarea {
  width: 100%;
  padding: 8px 11px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color 120ms var(--ease);
}
input:focus, select:focus, textarea:focus { border-color: var(--text); outline: none; }
textarea { resize: vertical; min-height: 96px; line-height: 1.6; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%); background-position: right 14px center, right 9px center; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }

.checkbox { display: flex; align-items: flex-start; gap: 9px; margin-bottom: 14px; cursor: pointer; }
.checkbox input { margin: 3px 0 0; accent-color: var(--accent); flex: none; }
.checkbox span { font-size: 13.5px; }

.alert {
  margin: 0 0 16px;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--text);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 13px;
}

/* ── Shell ───────────────────────────────────────────────────────────── */
.app { display: flex; min-height: 100dvh; }

.nav {
  width: var(--nav-w);
  flex: none;
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  /* Anchored to the viewport: only the content column scrolls, so navigation
     stays reachable however long the inbox gets. */
  position: sticky;
  top: 0;
  height: 100dvh;
  overflow-y: auto;
}
.nav__head { display: flex; align-items: center; gap: 9px; padding: 0 8px 20px; }
.nav__mark { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); flex: none; }
.nav__name { font-weight: 600; letter-spacing: -0.01em; }

.nav__links { display: flex; flex-direction: column; gap: 1px; }
.nav__link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 7px 9px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 120ms var(--ease), color 120ms var(--ease);
}
.nav__link:hover { background: var(--surface-2); color: var(--text); }
.nav__link.is-active { background: var(--surface-2); color: var(--text); }

.badge {
  min-width: 19px;
  height: 19px;
  padding: 0 6px;
  display: inline-grid;
  place-items: center;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 11.5px;
  font-weight: 600;
}

.nav__foot { margin-top: auto; padding-top: 18px; border-top: 1px solid var(--border); }
.nav__user { padding: 0 9px 10px; display: flex; flex-direction: column; }
.nav__user-name { font-size: 13.5px; font-weight: 500; }
.nav__user-role { font-size: 12.5px; color: var(--text-3); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 58px;
  padding: 0 24px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar__title { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: -0.012em; }
.topbar__actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.topbar__menu { display: none; width: 32px; height: 32px; align-items: center; justify-content: center; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-2); cursor: pointer; }

.view { flex: 1; padding: 24px; max-width: 900px; width: 100%; }
.view--wide { max-width: 1100px; }

/* ── Inbox ───────────────────────────────────────────────────────────── */
.search {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  min-width: 200px;
}
.search input { border: 0; padding: 0; background: transparent; width: 100%; }
.search input:focus { outline: none; }
.search svg { color: var(--text-3); flex: none; }

select.select--sm { width: auto; height: 34px; padding-top: 0; padding-bottom: 0; font-size: 13px; }

.inbox { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }

.call {
  position: relative;
  display: grid;
  grid-template-columns: 18px 1fr auto;
  gap: 12px;
  width: 100%;
  padding: 13px 16px 13px 13px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  text-align: left;
  cursor: pointer;
  transition: background 100ms var(--ease);
}
.call:last-child { border-bottom: 0; }
.call:hover { background: var(--surface); }

/* Urgency is a rule in the margin — the only structural emphasis in the list. */
.call--urgent::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: var(--text);
  border-radius: 0 2px 2px 0;
}

.call__dot { width: 7px; height: 7px; margin: 7px auto 0; border-radius: 50%; background: var(--accent); }
.call--read .call__dot { background: transparent; }

.call__main { min-width: 0; }
.call__who { font-weight: 500; letter-spacing: -0.006em; }
.call--read .call__who { font-weight: 400; color: var(--text-2); }
.call__org { color: var(--text-3); font-weight: 400; }
.call__line {
  margin-top: 2px;
  color: var(--text-2);
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.call__type {
  display: inline-block;
  margin-right: 8px;
  padding: 0 6px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  color: var(--text-2);
  font-size: 11.5px;
  line-height: 17px;
  vertical-align: 1px;
}

.call__meta { text-align: right; color: var(--text-3); font-size: 12.5px; line-height: 1.5; flex: none; }

.empty { padding: 56px 24px; text-align: center; border: 1px dashed var(--border-strong); border-radius: var(--radius); }
.empty__title { font-weight: 500; margin-bottom: 4px; }
.empty__text { color: var(--text-2); font-size: 13.5px; margin: 0 auto; max-width: 40ch; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 20px; }
.stat { padding: 13px 16px; background: var(--bg); }
.stat__value { font-size: 21px; font-weight: 600; letter-spacing: -0.02em; }
.stat__label { color: var(--text-2); font-size: 12.5px; }

.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; color: var(--text-2); font-size: 13px; }

/* ── Sheet ───────────────────────────────────────────────────────────── */
.sheet { position: fixed; inset: 0; z-index: 40; }
.sheet__scrim { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.28); animation: fade 160ms var(--ease); }
.sheet__panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(var(--sheet-w), 100%);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-left: 1px solid var(--border);
  animation: slide 220ms var(--ease);
}
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(16px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .sheet__scrim, .sheet__panel { animation: none; }
}

.sheet__head { display: flex; align-items: center; gap: 12px; padding: 14px 16px 14px 20px; border-bottom: 1px solid var(--border); }
.sheet__title { margin: 0; font-size: 15px; font-weight: 600; flex: 1; }
.sheet__body { flex: 1; overflow-y: auto; padding: 20px; }

.detail__who { font-size: 19px; font-weight: 600; letter-spacing: -0.018em; }
.detail__org { color: var(--text-2); margin-top: 1px; }
.detail__actions { display: flex; gap: 8px; margin: 18px 0 22px; flex-wrap: wrap; }

.block { margin-bottom: 22px; }
.block__title { font-size: 13px; font-weight: 600; margin-bottom: 7px; }
.block__text { color: var(--text-2); white-space: pre-wrap; margin: 0; }

.facts { display: grid; grid-template-columns: auto 1fr; gap: 7px 18px; font-size: 13.5px; }
.facts dt { color: var(--text-3); }
.facts dd { margin: 0; }

.turn { padding: 9px 0; border-bottom: 1px solid var(--border); }
.turn:last-child { border-bottom: 0; }
.turn__role { font-size: 12.5px; color: var(--text-3); margin-bottom: 1px; }
.turn__text { margin: 0; }
.turn--assistant .turn__text { color: var(--text-2); }

/* ── Cards & forms ───────────────────────────────────────────────────── */
.card { border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.card__head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 4px; }
.card__title { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.card__tag { color: var(--text-3); font-size: 13px; }
.card__intro { color: var(--text-2); font-size: 13.5px; margin: 0 0 18px; }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0 16px; }

.section { border-top: 1px solid var(--border); margin-top: 20px; padding-top: 18px; }
.section__title { font-size: 13px; font-weight: 600; margin-bottom: 12px; }

.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; font-weight: 500; color: var(--text-3); padding: 0 12px 9px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.table td { padding: 11px 12px 11px 0; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }

.formbar { display: flex; align-items: center; gap: 12px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.formbar__note { color: var(--text-3); font-size: 13px; }

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  padding: 9px 15px;
  background: var(--accent);
  color: var(--accent-fg);
  border-radius: 20px;
  font-size: 13.5px;
  font-weight: 500;
  animation: rise 200ms var(--ease);
}
@keyframes rise { from { transform: translate(-50%, 8px); opacity: 0; } }

.spinner { padding: 40px; text-align: center; color: var(--text-3); font-size: 13.5px; }

/* ── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 760px) {
  .nav {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 220ms var(--ease);
  }
  .nav.is-open { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.3); }
  .topbar__menu { display: inline-flex; }
  .view { padding: 16px; }
  .call { grid-template-columns: 16px 1fr; padding-right: 13px; }
  .call__meta { grid-column: 2; text-align: left; display: flex; gap: 10px; }
  .sheet__panel { border-left: 0; }
}
