/* Sidework look: charcoal frame, warm work area, white panels, blue only for
   the primary action, selection and focus. Tokens live here; templates use
   the classes below and never write a color. */
:root {
  --sidebar: #1a1f25;
  --sidebar-foreground: #e9ecef;
  --sidebar-muted: #b9c1c9;
  --sidebar-faint: #8f99a3;
  --sidebar-hover: #1f2530;
  --sidebar-active: #242c38;
  --sidebar-active-border: #313945;
  --sidebar-rule: #262d36;
  --background: #f5f4f0;
  --card: #ffffff;
  --panel-2: #f3f1ec;
  --panel-3: #e9e5dc;
  --foreground: #1b1e22;
  --muted-foreground: #4d5761;
  --faint: #5f6a75;
  --border: #e3ded2;
  --rule-strong: #d4cdbd;
  --input: #6b7480;
  --input-hover: #4d5761;
  --primary: #2251ff;
  --primary-hover: #1b3fd1;
  --primary-foreground: #ffffff;
  --accent-text: #1e40d6;
  --accent-on-dark: #9db1ff;
  --focus-ring: 0 0 0 3px rgba(34, 81, 255, .28);
  --warning-bg: #fef3c7;
  --warning-border: #b45309;
  --warning-text: #92400e;
  --success-bg: #d1fae5;
  --success-border: #047857;
  --success-text: #065f46;
  --reply-bubble: #e3e9ff;
  --reply-bubble-border: #b9c3f5;
  --scrim: rgba(20, 22, 25, .5);
  --lift: 0 18px 48px rgba(20, 22, 25, .22);
  --radius: 12px;
  --sidebar-width: 224px;
  --page-pad: 20px;
  --control-height: 44px;
  --header-height: 65px;
  --font: 'Inter Tight', system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--background);
  color: var(--foreground);
  font: 14px/1.5 var(--font);
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent-text); }
h1, h2, h3, p { margin: 0; }
h2 { font-size: 18px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 600; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.icon { flex: none; display: block; }
.muted { color: var(--muted-foreground); }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

/* Shell */
.shell { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px;
  padding: 14px 10px;
  background: var(--sidebar); color: var(--sidebar-foreground);
}
.wordmark {
  width: 180px; max-width: 100%; padding: 6px 8px 14px;
  border-bottom: 1px solid var(--sidebar-rule);
  font-size: 22px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.2;
  overflow-wrap: anywhere;
}
.switcher-row {
  display: flex; align-items: center; gap: 10px; width: 100%;
  min-height: var(--control-height); padding: 8px;
  border: 1px solid transparent; border-radius: 8px;
  background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.switcher-row:hover { background: var(--sidebar-hover); }
.switcher-text { display: grid; min-width: 0; flex: 1; }
.switcher-name { font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
.switcher-sub { font-size: 12px; color: var(--sidebar-muted); }
.nav { display: grid; gap: 2px; }
.nav-bottom { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--sidebar-rule); }
.nav-row {
  display: flex; align-items: center; gap: 10px;
  min-height: var(--control-height); padding: 0 10px;
  border: 1px solid transparent; border-radius: 8px;
  color: var(--sidebar-muted); font-size: 14px; font-weight: 500; text-decoration: none;
}
.nav-row:hover { background: var(--sidebar-hover); color: var(--sidebar-foreground); }
.nav-row[aria-current="page"] {
  background: var(--sidebar-active); border-color: var(--sidebar-active-border);
  color: var(--sidebar-foreground);
}
.profile {
  display: flex; align-items: center; gap: 10px;
  margin-top: auto; padding: 12px 6px 2px; border-top: 1px solid var(--sidebar-rule);
}
.nav-bottom + .profile { margin-top: 0; border-top: 0; padding-top: 0; }
.avatar {
  flex: none; display: grid; place-items: center; width: 30px; height: 30px;
  border-radius: 50%; background: var(--sidebar-active); border: 1px solid var(--sidebar-active-border);
  font-size: 12px; font-weight: 700;
}
.profile-text { display: grid; min-width: 0; flex: 1; }
.profile-name { font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
.profile-role { font-size: 12px; color: var(--sidebar-muted); }
.profile form { margin: 0; }
.signout {
  display: grid; place-items: center; width: 36px; height: 36px; padding: 0;
  border: 1px solid transparent; border-radius: 8px;
  background: transparent; color: var(--sidebar-muted); cursor: pointer;
}
.signout:hover { background: var(--sidebar-hover); color: var(--sidebar-foreground); }

.main { min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }
.page-header {
  display: flex; align-items: center; gap: 8px;
  min-height: var(--header-height); padding: 14px var(--page-pad);
  background: var(--card); border-bottom: 1px solid var(--border);
}
.page-header h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.018em; line-height: 1.25; }
.page-header .sub { font-size: 22px; font-weight: 500; color: var(--muted-foreground); }
.page-body { flex: 1; min-width: 0; padding: var(--page-pad); display: grid; gap: 16px; align-content: start; }

/* Dialog (venue switcher) */
.dialog {
  width: min(560px, calc(100vw - 32px)); max-width: 560px; padding: 0;
  border: 0; border-radius: 14px; background: var(--card); color: var(--foreground);
  box-shadow: var(--lift);
}
.dialog::backdrop { background: var(--scrim); }
.dialog-inner { padding: 18px 20px 20px; display: grid; gap: 16px; }
.dialog-head { display: flex; align-items: flex-start; gap: 12px; }
.dialog-head div { flex: 1; }
.dialog-head h2 { font-size: 17px; font-weight: 700; }
.dialog-head p { font-size: 13px; color: var(--muted-foreground); }
.dialog-close {
  display: grid; place-items: center; width: 36px; height: 36px; padding: 0;
  border: 1px solid var(--rule-strong); border-radius: 8px; background: var(--card);
  color: var(--foreground); cursor: pointer;
}
.choices { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.choice {
  display: flex; align-items: center; gap: 10px; min-height: var(--control-height); padding: 0 14px;
  border: 1px solid var(--rule-strong); border-radius: var(--radius);
  color: var(--foreground); font-weight: 600; text-decoration: none;
}
.choice:hover { background: var(--panel-2); }
.choice .check { color: var(--accent-text); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--control-height); padding: 0 16px;
  border: 1px solid var(--rule-strong); border-radius: var(--radius);
  background: var(--card); color: var(--foreground);
  font: 600 14px/1.2 var(--font); text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--panel-2); border-color: var(--input); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-foreground); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-quiet { background: transparent; border-color: transparent; color: var(--muted-foreground); }
.btn-quiet:hover { background: var(--panel-2); border-color: transparent; color: var(--foreground); }
.btn-warn { color: var(--warning-text); }
.btn-warn:hover { border-color: var(--warning-border); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: default; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; min-height: 28px; padding: 3px 10px;
  border: 1px solid var(--rule-strong); border-radius: 8px;
  background: var(--panel-2); color: var(--muted-foreground);
  font-size: 12px; font-weight: 600; line-height: 1.2; white-space: nowrap;
}
.badge-success { background: var(--success-bg); border-color: var(--success-border); color: var(--success-text); }
.badge-warning { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning-text); }

/* Panels and tables */
.panel {
  min-width: 0; padding: 18px 20px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
}
.panel:has(> .table) { padding: 0; overflow-x: auto; }
.panel > h2, .panel > h3 { margin-bottom: 12px; }
.table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden;
}
.panel > .table { border: 0; border-radius: 0; }
.table th {
  padding: 10px 12px; background: var(--panel-2); border-bottom: 1px solid var(--border);
  color: var(--muted-foreground); font-size: 12px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase; text-align: left; white-space: nowrap;
}
.table td { padding: 10px 12px; height: 56px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tfoot td { font-weight: 700; background: var(--panel-2); border-top: 1px solid var(--border); border-bottom: 0; }
.table td:first-child { font-weight: 600; }
.table th.num, .table td.num { text-align: right; }
.table .sub { display: block; font-size: 12px; font-weight: 400; color: var(--muted-foreground); }
.table form { display: inline-flex; flex-wrap: wrap; align-items: end; gap: 8px; margin: 4px 8px 4px 0; }
.table .field { font-size: 12px; }
.table .field input, .table .field select { min-height: 36px; }
.table .btn { min-height: 36px; padding: 0 12px; }
.row-link { position: relative; }
.row-link a { color: var(--foreground); text-decoration: none; }
.row-link a::after { content: ""; position: absolute; inset: 0; }
.row-link:hover td { background: var(--panel-2); }
.row-link .chevron { width: 44px; color: var(--muted-foreground); }

/* Forms */
.form-section { display: grid; gap: 14px; padding-bottom: 20px; border-bottom: 1px solid var(--border); }
.form-section > h2, .form-section > h3 { font-size: 18px; font-weight: 700; }
.form-section > p { color: var(--muted-foreground); }
.form-section form { display: grid; gap: 14px; max-width: 640px; }
.field { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--foreground); }
.field input:not([type="checkbox"]):not([type="radio"]), .field select, .field textarea {
  width: 100%; min-height: var(--control-height); padding: 0 12px;
  border: 1px solid var(--input); border-radius: 10px;
  background: var(--card); color: var(--foreground); font: 400 14px/1.5 var(--font);
}
.field textarea { min-height: 88px; padding: 10px 12px; resize: vertical; }
.field input:hover, .field select:hover, .field textarea:hover { border-color: var(--input-hover); }
.field input[type="checkbox"], .field input[type="radio"] { width: 20px; height: 20px; margin: 0; accent-color: var(--primary); }
.field:has(> input[type="checkbox"]) { display: flex; align-items: center; gap: 10px; }
.hint { font-size: 12px; font-weight: 400; color: var(--muted-foreground); }
.save-bar {
  display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap;
  padding-top: 14px; border-top: 1px solid var(--border);
}
.save-bar > :first-child:not(.btn):not(button) { margin-right: auto; color: var(--muted-foreground); }
[role="alert"] {
  padding: 10px 12px; border: 1px solid var(--warning-border); border-radius: 10px;
  background: var(--warning-bg); color: var(--warning-text); font-weight: 600;
}

/* Sign in: the only page whose main is a bare panel */
body > main.panel {
  display: grid; gap: 18px; width: calc(100% - 24px); max-width: 520px;
  margin: 12vh auto 24px; padding: 28px;
}
body > main.panel h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.018em; }
body > main.panel form { display: grid; gap: 14px; }
body > main.panel form .btn-primary { width: 100%; margin-top: 4px; }

/* Pills */
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pills a, .pills button {
  display: inline-flex; align-items: center; min-height: 36px; padding: 0 12px;
  border: 1px solid transparent; border-radius: 8px; background: transparent;
  color: var(--muted-foreground); font: 600 13px/1.2 var(--font); text-decoration: none; cursor: pointer;
}
.pills a:hover, .pills button:hover { background: var(--panel-2); color: var(--foreground); }
.pills [aria-current], .pills .active {
  background: var(--panel-3); border-color: var(--rule-strong); color: var(--foreground);
}

/* Split: list and thread in one panel */
.split {
  display: grid; grid-template-columns: 300px minmax(0, 1fr);
  height: calc(100vh - var(--header-height) - 2 * var(--page-pad)); min-height: 480px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.list { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border); }
.list-head { display: grid; gap: 10px; padding: 12px; border-bottom: 1px solid var(--border); }
.list-rows { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.list-row {
  display: flex; align-items: flex-start; gap: 10px; min-height: 72px; padding: 12px;
  border-bottom: 1px solid var(--border); border-left: 2px solid transparent;
  color: var(--foreground); text-decoration: none;
}
.list-row-main { display: grid; gap: 2px; flex: 1; min-width: 0; }
.avatar-sm {
  flex: none; display: grid; place-items: center; width: 30px; height: 30px;
  border-radius: 50%; background: var(--panel-3); border: 1px solid var(--rule-strong);
  color: var(--foreground); font-size: 12px; font-weight: 700;
}
.list-row:hover { background: var(--panel-2); }
.list-row[aria-current] { background: var(--panel-2); border-left-color: var(--primary); }
.list-row-top { display: flex; align-items: baseline; gap: 8px; }
.list-row-title { flex: 1; min-width: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row-time { flex: none; font-size: 12px; color: var(--muted-foreground); }
.list-row-meta { font-size: 12px; color: var(--muted-foreground); }
.list-row-preview { font-size: 13px; color: var(--muted-foreground); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .badge { justify-self: start; margin-top: 4px; }
.list > .empty { flex: 1; }

.thread { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.thread-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  min-height: 72px; padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.thread-head > div { flex: 1; min-width: 0; }
.thread-head h2 { font-size: 16px; font-weight: 700; }
.thread-head p { font-size: 12px; color: var(--muted-foreground); }
.thread-body { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; padding: 16px; }
.thread-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.bubble-review, .bubble-reply {
  max-width: 72%; padding: 10px 12px; border-radius: var(--radius);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.bubble-review { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--rule-strong); }
.bubble-reply { align-self: flex-end; background: var(--reply-bubble); border: 1px solid var(--reply-bubble-border); }
.bubble-time { margin-top: -8px; font-size: 12px; color: var(--muted-foreground); }
.bubble-review + .bubble-time { align-self: flex-start; }
.bubble-reply + .bubble-time { align-self: flex-end; }
.bubble-note { align-self: flex-end; font-size: 13px; color: var(--muted-foreground); }
.removed { font-style: italic; color: var(--muted-foreground); }
.composer {
  margin: 0 16px 16px; border: 1px solid var(--input); border-radius: var(--radius); background: var(--card);
}
.composer textarea {
  display: block; width: 100%; min-height: 120px; padding: 12px; border: 0; border-radius: var(--radius) var(--radius) 0 0;
  background: transparent; color: var(--foreground); font: 400 14px/1.5 var(--font); resize: vertical;
}
.composer textarea:focus-visible { box-shadow: none; }
.composer:focus-within { box-shadow: var(--focus-ring); }
.composer-text { padding: 12px; color: var(--muted-foreground); white-space: pre-wrap; }
.composer-bar { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; padding: 10px 12px; }
.composer-bar .status { margin-right: auto; font-size: 12px; color: var(--muted-foreground); }
.composer-bar form { margin: 0; }

/* Sales board */
.board { display: flex; gap: 12px; align-items: flex-start; overflow-x: auto; padding-bottom: 4px; }
.lane {
  flex: 0 0 19rem; display: grid; gap: 10px; align-content: start; padding: 12px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius);
}
.lane > h2, .lane > h3, .lane > header {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 15px; font-weight: 600;
}
.card {
  display: grid; gap: 6px; padding: 14px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
}
.card h3, .card h4, .card strong { font-size: 14px; font-weight: 700; }
.card p, .card small { font-size: 13px; color: var(--muted-foreground); }
.card form { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.card .btn { min-height: 36px; padding: 0 12px; }
.card .field input, .card .field select { min-height: 36px; }

/* Empty state */
.empty {
  display: grid; justify-items: center; align-content: center; gap: 8px; padding: 48px 20px; text-align: center;
  color: var(--muted-foreground);
}
.empty-icon {
  display: grid; place-items: center; width: 48px; height: 48px;
  border-radius: var(--radius); background: var(--panel-2); border: 1px solid var(--border); color: var(--muted-foreground);
}
.empty h2, .empty h3 { font-size: 18px; font-weight: 700; color: var(--foreground); }
.thread > .empty { flex: 1; }

.menu-button, .thread-back { display: none; }

/* Phones: stack, never scroll sideways. The menu folds away, and one side shows at a time:
   the opened review, or the list. */
@media (max-width: 760px) {
  :root { --page-pad: 12px; }
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .sidebar {
    position: static; height: auto; display: grid; grid-template-columns: minmax(0, 1fr) auto;
    align-items: center; gap: 6px; padding: 8px 10px;
  }
  .wordmark { width: auto; padding: 0 8px; border-bottom: 0; font-size: 18px; }
  .menu-button {
    display: inline-flex; align-items: center; min-height: var(--control-height); padding: 0 14px;
    border: 1px solid var(--sidebar-active-border); border-radius: 8px;
    font-size: 14px; font-weight: 600; cursor: pointer;
  }
  .menu-toggle:focus-visible + .menu-button { box-shadow: var(--focus-ring); }
  .switcher-row, .nav, .profile { grid-column: 1 / -1; }
  .menu-toggle:not(:checked) ~ .nav, .menu-toggle:not(:checked) ~ .profile { display: none; }
  .nav-bottom, .profile { margin-top: 0; }
  .main { min-height: 0; }
  .split { grid-template-columns: minmax(0, 1fr); height: auto; min-height: 0; }
  .list { border-right: 0; }
  .list-rows, .thread-body { overflow-y: visible; }
  .split[data-view="thread"] .list, .split[data-view="list"] .thread { display: none; }
  .thread-back {
    display: flex; align-items: center; min-height: var(--control-height); padding: 0 16px;
    border-bottom: 1px solid var(--border); font-weight: 600; text-decoration: none;
  }
  .bubble-review, .bubble-reply { max-width: 100%; }
}
