/* ===========================================================
   Autoclinic — editorial-clinical
   Warm paper bg · Instrument Serif display · IBM Plex body/mono
   One clay accent. Generous letter-spacing. Tactile chips.
   =========================================================== */

:root {
  --paper:        #F2EFE8;
  --paper-deep:   #ECE7DC;
  --surface:      #FAF7F0;
  --surface-2:    #F6F1E5;
  --ink:          #13140E;
  --ink-soft:     #2A2C24;
  --muted:        #6E6A5E;
  --muted-soft:   #9A9483;
  --line:         #D5CCB8;
  --line-soft:    #E3DCC9;
  --clay:         #A24A2B;
  --clay-deep:    #7B361F;
  --clay-soft:    #E8C8B8;
  --forest:       #3F6B3F;
  --amber:        #A0701A;
  --olive:        #5F5F2F;
  --indigo:       #2F3A6B;

  --radius-sm: 4px;
  --radius:    10px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 0 rgba(19, 20, 14, 0.04);
  --shadow:    0 2px 0 rgba(19, 20, 14, 0.05), 0 12px 32px -16px rgba(19, 20, 14, 0.10);
  --shadow-lg: 0 24px 60px -20px rgba(19, 20, 14, 0.25);

  --serif: "Instrument Serif", "Iowan Old Style", Georgia, serif;
  --sans:  "IBM Plex Sans", -apple-system, "Segoe UI", sans-serif;
  --mono:  "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  font-feature-settings: "ss01", "cv11";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Faint paper grain — pure inline SVG, no asset request */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.5;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='1.05' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.07 0 0 0 0 0.07 0 0 0 0 0.05 0 0 0 0.06 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

body > * { position: relative; z-index: 1; }

/* ==========================================================
   TOPBAR — masthead style
   ========================================================== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 32px 14px;
  background: transparent;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  background: rgba(242, 239, 232, 0.86);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
}

.brand-mark {
  font-family: var(--serif);
  font-size: 30px;
  line-height: 1;
  color: var(--clay);
  transform: translateY(2px);
}

.brand-word {
  font-family: var(--serif);
  font-size: 26px;
  line-height: 1;
  letter-spacing: -0.01em;
}
.brand-word em { font-style: italic; }

.brand-tag {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  border-left: 1px solid var(--line);
  padding-left: 10px;
  margin-left: 4px;
  transform: translateY(-2px);
}

.tabs {
  display: flex;
  gap: 4px;
  align-items: stretch;
}

.tab {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  background: transparent;
  border: none;
  padding: 10px 16px 10px 14px;
  border-radius: var(--radius);
  font: inherit;
  cursor: pointer;
  color: var(--muted);
  position: relative;
  transition: color 160ms ease, background 160ms ease;
}

.tab-num {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--muted-soft);
}

.tab-label {
  font-family: var(--serif);
  font-style: italic;
  font-size: 19px;
  letter-spacing: -0.005em;
}

.tab:hover { color: var(--ink); }
.tab:hover .tab-num { color: var(--muted); }

.tab.active {
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.tab.active .tab-num { color: var(--clay); }
.tab.active::after {
  content: "";
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 6px;
  height: 1px;
  background: var(--ink);
  transform-origin: left;
  animation: underline 240ms ease;
}

@keyframes underline {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

/* Live indicator dot on the Live tab */
.tab[data-view="live"] .tab-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--clay);
  transform: translateY(-7px);
  margin-left: -4px;
  box-shadow: 0 0 0 0 rgba(162, 74, 43, 0.45);
}
.tab[data-view="live"][data-pulse="on"] .tab-dot {
  animation: livepulse 1.6s ease-out infinite;
}

@keyframes livepulse {
  0%   { box-shadow: 0 0 0 0 rgba(162, 74, 43, 0.45); }
  70%  { box-shadow: 0 0 0 8px rgba(162, 74, 43, 0); }
  100% { box-shadow: 0 0 0 0 rgba(162, 74, 43, 0); }
}

/* ==========================================================
   MAIN LAYOUT
   ========================================================== */
main {
  max-width: 860px;
  margin: 0 auto;
  padding: 48px 32px 120px;
}

.view { display: none; animation: fadeUp 360ms cubic-bezier(.2,.7,.2,1); }
.view.active { display: block; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.view-header {
  margin-bottom: 32px;
}

.eyebrow {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--clay);
  margin: 0 0 10px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.display {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 46px;
  line-height: 1.05;
  letter-spacing: -0.012em;
  margin: 0 0 12px;
  color: var(--ink);
}
.display em { font-style: italic; color: var(--clay); }

.subtitle {
  color: var(--muted);
  margin: 0;
  max-width: 60ch;
  font-size: 15px;
}

/* ==========================================================
   SETUP HEADER — title left, quick-demo presets right
   ========================================================== */
.setup-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 40px;
  align-items: start;
}
.setup-header .header-text { min-width: 0; }

@media (max-width: 820px) {
  .setup-header { grid-template-columns: 1fr; }
}

/* ==========================================================
   PRESETS — quick-fill bubbles (sidebar on Setup)
   ========================================================== */
.presets {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 6px;
}

.presets-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 4px;
}

.preset-bubbles {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bubble {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 14px 9px 10px;
  font: inherit;
  cursor: pointer;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-align: left;
  width: 100%;
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease;
}

.bubble:hover {
  border-color: var(--ink);
  background: var(--surface);
}
.bubble:active { background: var(--surface-2); }

.bubble-num {
  font-family: var(--serif);
  font-style: italic;
  font-size: 15px;
  color: var(--muted);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: color 160ms ease, border-color 160ms ease, background 160ms ease;
}

.bubble:hover .bubble-num {
  color: var(--ink);
  border-color: var(--ink);
}

.bubble-body {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.bubble-title {
  font-size: 13.5px;
  font-weight: 500;
  letter-spacing: -0.005em;
  line-height: 1.2;
}

.bubble-sub {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.01em;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bubble.applied {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--surface);
}
.bubble.applied .bubble-num {
  border-color: var(--surface);
  color: var(--surface);
  background: transparent;
}
.bubble.applied .bubble-sub { color: rgba(250, 247, 240, 0.65); }

.bubble-clear {
  border-style: dashed;
  color: var(--muted);
  grid-template-columns: auto 1fr;
}
.bubble-clear:hover { color: var(--ink); border-color: var(--ink); border-style: solid; }
.bubble-clear-icon {
  font-size: 16px;
  line-height: 0.6;
  width: 22px;
  text-align: center;
  color: var(--muted);
}
.bubble-clear:hover .bubble-clear-icon { color: var(--ink); }

/* ==========================================================
   FORM CARDS — heading sits ABOVE the box (no cut-through)
   ========================================================== */
.card {
  margin: 0 0 24px;
}

.card-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 0 4px 10px;
  margin: 0;
}

.card-num {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  color: var(--muted-soft);
  text-transform: uppercase;
}

.card-title {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: 22px;
  line-height: 1.1;
  color: var(--ink);
  margin: 0;
  letter-spacing: -0.005em;
}

.card-badge {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  background: var(--surface-2);
  color: var(--muted);
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  margin-left: 4px;
}

.card-body {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px 22px 18px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.help {
  color: var(--muted);
  font-size: 13px;
  margin: 2px 0 14px;
  max-width: 64ch;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  align-items: end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 10px 0;
  font-size: 14px;
}

.field-label {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  display: inline-flex;
  gap: 8px;
  align-items: baseline;
}

.field-hint {
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--muted-soft);
  font-weight: 400;
  letter-spacing: 0.06em;
}

input[type=text],
input[type=tel],
input[type=url],
input[type=datetime-local],
textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: inherit;
  font-size: 15px;
  background: var(--paper);
  color: var(--ink);
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

input:hover, textarea:hover { border-color: var(--muted-soft); }

input:focus, textarea:focus {
  outline: none;
  border-color: var(--clay);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(162, 74, 43, 0.14);
}

textarea {
  resize: vertical;
  min-height: 110px;
  font-family: var(--sans);
  line-height: 1.55;
}

/* Inline chip row for "use my saved phone" etc */
.field-chip-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 4px;
  min-height: 0;
}

.field-chip {
  background: var(--surface-2);
  border: 1px dashed var(--line);
  border-radius: 999px;
  font: inherit;
  font-size: 11.5px;
  font-family: var(--mono);
  color: var(--muted);
  padding: 3px 10px;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: color 140ms ease, border-color 140ms ease, background 140ms ease;
}
.field-chip:hover {
  color: var(--clay);
  border-color: var(--clay);
  border-style: solid;
  background: var(--clay-soft);
}

/* ==========================================================
   SCHEDULE LIST (setup)
   ========================================================== */
.schedule-card .help { display: flex; align-items: center; gap: 10px; }
.hidden { display: none !important; }

.dot-spinner {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 1.5px solid var(--clay-soft);
  border-top-color: var(--clay);
  border-radius: 50%;
  animation: spin 720ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.schedule-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.schedule-row {
  display: grid;
  grid-template-columns: 220px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  background: var(--paper);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  position: relative;
  animation: rowIn 320ms ease;
}

@keyframes rowIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.schedule-row input[type=datetime-local] {
  font-family: var(--mono);
  font-size: 13px;
  padding: 8px 10px;
  background: var(--surface);
}
.schedule-row input[type=text] {
  padding: 8px 10px;
  font-size: 14px;
  background: var(--surface);
}

.schedule-row .remove {
  background: transparent;
  border: none;
  color: var(--muted-soft);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  transition: color 140ms ease, background 140ms ease;
}
.schedule-row .remove:hover { color: var(--clay); background: var(--clay-soft); }

.schedule-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ==========================================================
   BUTTONS
   ========================================================== */
button.primary, button.ghost, button.danger {
  font: inherit;
  font-weight: 500;
  border-radius: var(--radius);
  padding: 12px 22px;
  cursor: pointer;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  transition: transform 140ms ease, background 160ms ease, color 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

button.primary {
  background: var(--ink);
  color: var(--surface);
  border-color: var(--ink);
  box-shadow: var(--shadow-sm);
}
button.primary:hover {
  background: var(--clay);
  border-color: var(--clay);
  transform: translateY(-1px);
  box-shadow: 0 8px 22px -10px rgba(162, 74, 43, 0.55);
}
button.primary:active { transform: translateY(0); }
.primary-arrow {
  font-family: var(--serif);
  font-style: italic;
  font-size: 18px;
  line-height: 1;
}

button.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
  padding: 10px 16px;
}
button.ghost:hover {
  background: var(--surface);
  border-color: var(--muted-soft);
}
button.ghost.icon {
  width: 40px;
  height: 40px;
  padding: 0;
  justify-content: center;
  font-size: 18px;
  font-family: var(--serif);
  color: var(--muted);
}
.ghost-icon {
  font-family: var(--mono);
  color: var(--clay);
  font-size: 13px;
}

button.danger {
  background: transparent;
  border-color: var(--clay);
  color: var(--clay-deep);
}
button.danger:hover { background: var(--clay); color: var(--surface); }

button:disabled { opacity: 0.45; cursor: not-allowed; transform: none !important; }

.status {
  font-size: 13px;
  color: var(--muted);
  font-family: var(--mono);
  letter-spacing: 0.01em;
}
.status.ok  { color: var(--forest); }
.status.err { color: var(--clay-deep); }

.actions {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-top: 12px;
}

.sticky-actions {
  position: sticky;
  bottom: 16px;
  background: var(--paper);
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  background: rgba(242, 239, 232, 0.92);
}

/* ==========================================================
   LIVE VIEW — agent state
   ========================================================== */
.live-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 28px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.live-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.live-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--clay);
  box-shadow: 0 0 0 0 rgba(162, 74, 43, 0.4);
  animation: livepulse 1.6s ease-out infinite;
}

.msg-pip {
  background: var(--clay);
  color: var(--surface);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 999px;
  letter-spacing: 0.03em;
  display: inline-block;
  min-width: 18px;
  text-align: center;
}
.msg-pip[data-count="0"] {
  background: var(--line);
  color: var(--muted);
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 64px 28px;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius-lg);
  display: none;
  font-family: var(--serif);
  font-style: italic;
  font-size: 18px;
}
.empty strong {
  font-family: var(--mono);
  font-style: normal;
  font-size: 13px;
  letter-spacing: 0.08em;
  color: var(--clay);
  background: var(--clay-soft);
  padding: 2px 8px;
  border-radius: 4px;
  margin: 0 2px;
}
.empty.visible { display: block; }
.empty-tight { padding: 28px 18px; font-size: 15px; }
.live-body.hidden { display: none; }

/* "Next scheduled" strip — runs across the top of the live view */
.next-strip {
  display: flex;
  align-items: baseline;
  gap: 14px;
  background: var(--ink);
  color: var(--surface);
  padding: 14px 22px;
  border-radius: var(--radius);
  margin-bottom: 22px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.next-strip::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--clay);
}
.next-k {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted-soft);
}
.next-v {
  font-family: var(--serif);
  font-style: italic;
  font-size: 22px;
  color: var(--surface);
}
.next-hint {
  flex: 1;
  font-size: 14px;
  color: rgba(250, 247, 240, 0.7);
}

/* Agent grid: goals + flags */
.agent-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 18px;
  margin-bottom: 18px;
}
@media (max-width: 760px) {
  .agent-grid { grid-template-columns: 1fr; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px 22px 14px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 18px;
}
.panel:last-child { margin-bottom: 0; }

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line-soft);
}
.panel-head h2 {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: 22px;
  margin: 0;
  color: var(--ink);
}
.panel-count {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--muted);
  background: var(--surface-2);
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line-soft);
}
.panel-legend {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  color: var(--muted);
  display: inline-flex;
  gap: 12px;
  align-items: center;
}
.dot-clinician, .dot-agent {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 4px;
}
.dot-clinician { background: var(--indigo); }
.dot-agent     { background: var(--clay); }

/* Goals */
ul.goals, ul.flags { list-style: none; padding: 0; margin: 0; }

.goal, .flag {
  padding: 10px 0;
  border-bottom: 1px solid var(--line-soft);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px 14px;
  font-size: 14px;
  align-items: baseline;
}
.goal:last-child, .flag:last-child { border-bottom: none; }

.goal-status, .flag-severity {
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  align-self: start;
  white-space: nowrap;
}

.goal-pending     .goal-status { background: var(--surface-2); color: var(--muted); }
.goal-in_progress .goal-status { background: rgba(47,58,107,0.10); color: var(--indigo); }
.goal-complete    .goal-status { background: rgba(63,107,63,0.14); color: var(--forest); }
.goal-blocked     .goal-status { background: var(--clay-soft); color: var(--clay-deep); }

.goal-desc { color: var(--ink); }
.goal-note {
  grid-column: 2;
  color: var(--muted);
  font-style: italic;
  font-size: 13px;
  font-family: var(--serif);
}

.flag-info .flag-severity     { background: rgba(47,58,107,0.10); color: var(--indigo); }
.flag-note .flag-severity     { background: rgba(160,112,26,0.14); color: var(--amber); }
.flag-concern .flag-severity  { background: var(--clay-soft); color: var(--clay-deep); }

.empty-inline {
  color: var(--muted);
  font-style: italic;
  font-family: var(--serif);
  font-size: 16px;
  padding: 14px 0;
}

/* ==========================================================
   TIMELINE — schedule on Live tab
   ========================================================== */
.timeline {
  list-style: none;
  padding: 4px 0 4px 0;
  margin: 0;
  position: relative;
}
.timeline::before {
  content: "";
  position: absolute;
  left: 9px;
  top: 6px;
  bottom: 6px;
  width: 1px;
  background: var(--line);
}

.timeline-item {
  position: relative;
  padding: 8px 0 10px 32px;
  border-bottom: 1px dashed var(--line-soft);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 14px;
  align-items: baseline;
}
.timeline-item:last-child { border-bottom: none; }

.timeline-item::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 16px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--surface);
  border: 1.5px solid var(--indigo);
}
.timeline-item.sched-by-agent::before { border-color: var(--clay); }
.timeline-item.sched-done::before { background: var(--ink); border-color: var(--ink); }

.t-when {
  font-family: var(--serif);
  font-style: italic;
  font-size: 17px;
  color: var(--ink);
  line-height: 1.2;
}
.t-when small {
  display: block;
  font-family: var(--mono);
  font-style: normal;
  font-size: 10.5px;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-transform: uppercase;
  margin-top: 2px;
}
.t-hint {
  font-size: 14px;
  color: var(--ink-soft);
  grid-column: 1 / -1;
  margin-top: -2px;
}
.t-meta {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--muted-soft);
  text-transform: uppercase;
  align-self: center;
  text-align: right;
}
.t-meta .by-agent { color: var(--clay); }
.t-meta .by-clinician { color: var(--indigo); }
.timeline-item.sched-done .t-when,
.timeline-item.sched-done .t-hint {
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-color: var(--line);
  text-decoration-thickness: 1px;
}

/* ==========================================================
   COUNTERS
   ========================================================== */
.counters {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
@media (max-width: 760px) { .counters { grid-template-columns: repeat(2, 1fr); } }
.counters > div {
  background: var(--paper);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.counters label {
  display: block;
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: 6px;
}
.counters span {
  font-family: var(--serif);
  font-style: italic;
  font-size: 24px;
  color: var(--ink);
  line-height: 1;
}

/* ==========================================================
   TICK LOG
   ========================================================== */
.ticks { display: flex; flex-direction: column; gap: 12px; }

.tick {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px 12px;
  border-left: 3px solid var(--muted);
  animation: rowIn 320ms ease;
}

.tick-send_sms          { border-left-color: var(--clay); }
.tick-stay_silent       { border-left-color: var(--muted-soft); }
.tick-close_conversation{ border-left-color: var(--ink); }
.tick-no_terminal_tool  { border-left-color: var(--amber); }

.tick-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  font-size: 12px;
  margin-bottom: 8px;
}
.tick-trigger {
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 10.5px;
  color: var(--clay);
  font-weight: 600;
}
.tick-final {
  font-family: var(--serif);
  font-style: italic;
  font-size: 14px;
  color: var(--ink);
}
.tick-time {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.tick-plan {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-left: 2px solid var(--clay);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 10px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink-soft);
  white-space: pre-wrap;
}
.tick-plan .label {
  display: block;
  font-family: var(--mono);
  font-style: normal;
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  margin-bottom: 4px;
}
.tick-plan div { white-space: pre-wrap; }

.tick-actions {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.action {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 12.5px;
  border-left: 2px solid var(--line);
}

.action-send_sms          { border-left-color: var(--clay); }
.action-stay_silent       { border-left-color: var(--muted-soft); }
.action-update_goal       { border-left-color: var(--indigo); }
.action-schedule_followup { border-left-color: var(--olive); }
.action-flag_for_clinician{ border-left-color: var(--amber); }
.action-close_conversation{ border-left-color: var(--ink); }
.action-error             { border-left-color: var(--clay-deep); background: rgba(162, 74, 43, 0.07); }

.action-tool {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 11.5px;
  letter-spacing: 0.04em;
  color: var(--ink);
}
.action-input {
  margin: 6px 0;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.5;
  white-space: pre-wrap;
  color: var(--muted);
}
.action-result {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--forest);
  letter-spacing: 0.02em;
}

/* ==========================================================
   DRAWER — conversation
   ========================================================== */
.drawer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
}
.drawer[aria-hidden="false"] { pointer-events: auto; }

.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(19, 20, 14, 0.32);
  opacity: 0;
  transition: opacity 280ms ease;
}
.drawer[aria-hidden="false"] .drawer-backdrop { opacity: 1; }

.drawer-panel {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: min(440px, 92vw);
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform 320ms cubic-bezier(.22,.7,.2,1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.drawer[aria-hidden="false"] .drawer-panel { transform: translateX(0); }

.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 22px 24px 16px;
  border-bottom: 1px solid var(--line-soft);
}
.drawer-title { font-size: 28px; margin: 0; }
.drawer-meta { margin: 6px 0 0; font-family: var(--mono); font-size: 12px; }

.conversation {
  flex: 1;
  overflow-y: auto;
  padding: 18px 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background:
    linear-gradient(var(--surface), var(--surface)) 0 0 / 100% 100% no-repeat,
    repeating-linear-gradient(180deg, transparent 0 26px, var(--line-soft) 26px 27px);
}

.msg {
  max-width: 84%;
  padding: 10px 14px 8px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 14px;
  line-height: 1.5;
  animation: rowIn 240ms ease;
  position: relative;
}

.msg.agent {
  background: var(--paper);
  border: 1px solid var(--line);
  color: var(--ink);
  border-bottom-left-radius: 4px;
  margin-right: auto;
}
.msg.patient {
  background: var(--ink);
  color: var(--surface);
  border-bottom-right-radius: 4px;
  margin-left: auto;
}

.msg-meta {
  display: block;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 4px;
}
.msg.patient .msg-meta { color: var(--muted-soft); }

/* ==========================================================
   SETTINGS
   ========================================================== */
.danger-card .card-body { border-color: var(--clay-soft); }
.danger-card .card-num { color: var(--clay); }

/* ==========================================================
   Misc small-screen
   ========================================================== */
@media (max-width: 720px) {
  main { padding: 32px 18px 100px; }
  .topbar { padding: 16px 18px 12px; flex-wrap: wrap; gap: 10px; }
  .display { font-size: 36px; }
  .field-row { grid-template-columns: 1fr; }
  .schedule-row { grid-template-columns: 1fr auto; }
  .schedule-row input[type=datetime-local] { grid-column: 1 / -1; }
}
