/* Buttons, chips, cards, tables, forms, modal, toast, command palette. */

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  --btn-bg: var(--surface-1);
  --btn-fg: var(--fg);
  --btn-bd: var(--border-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 13px;
  background: var(--btn-bg); color: var(--btn-fg);
  border: 1px solid var(--btn-bd); border-radius: var(--r-sm);
  font-size: var(--t-md); font-weight: 500; cursor: pointer;
  box-shadow: var(--e1);
  transition: transform var(--d-fast) var(--ease), box-shadow var(--d-fast) var(--ease),
              background var(--d-fast) var(--ease), border-color var(--d-fast) var(--ease);
}
.btn svg { width: 15px; height: 15px; flex: none; }
.btn:hover { box-shadow: var(--e2); transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(.975); box-shadow: var(--e1); }
.btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-primary { --btn-bg: var(--brand); --btn-fg: var(--brand-on); --btn-bd: var(--brand); }
.btn-primary:hover { --btn-bg: var(--brand-hover); --btn-bd: var(--brand-hover); }
.btn-wa { --btn-bg: var(--wa); --btn-fg: var(--wa-on); --btn-bd: var(--wa); }
.btn-ghost { --btn-bg: transparent; --btn-bd: transparent; --btn-fg: var(--fg-2); box-shadow: none; }
.btn-ghost:hover { --btn-bg: var(--surface-3); --btn-fg: var(--fg); box-shadow: none; transform: none; }
.btn-block { width: 100%; }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: var(--t-sm); border-radius: var(--r-xs); }
.btn-sm svg { width: 13px; height: 13px; }

/* Shared primitives — used by both the doctor screen and the full CRM. */
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center;
  border: 1px solid transparent; background: transparent; color: var(--fg-2);
  border-radius: var(--r-sm); cursor: pointer;
  transition: background var(--d-fast) var(--ease), color var(--d-fast) var(--ease), border-color var(--d-fast) var(--ease);
}
.icon-btn:hover { background: var(--surface-3); color: var(--fg); border-color: var(--border); }
.icon-btn svg { width: 18px; height: 18px; }
/* Theme toggle: only the glyph for the *other* theme is shown */
.icon-btn .ico-moon { display: none; }
.icon-btn .ico-sun, .icon-btn .ico-moon { display: flex; }
:root[data-theme="dark"] .icon-btn .ico-sun  { display: none; }
:root[data-theme="light"] .icon-btn .ico-moon { display: none; }

.avatar {
  width: 30px; height: 30px; border-radius: 99px; flex: none;
  background: var(--c, var(--brand)); color: #fff;
  display: grid; place-items: center;
  font-size: 10.5px; font-weight: 650; letter-spacing: .02em;
  box-shadow: var(--hairline);
}
.avatar.sm { width: 25px; height: 25px; font-size: 9.5px; }
.avatar.lg {
  width: 56px; height: 56px; border-radius: var(--r);
  font-family: var(--display); font-size: 21px; font-weight: 400;
}

.dot-live {
  width: 7px; height: 7px; border-radius: 99px; background: var(--wa); flex: none;
  box-shadow: 0 0 0 3px var(--wa-soft);
}

/* Touch devices get the 44px minimum; pointer devices stay dense. */
@media (pointer: coarse) {
  .btn, .icon-btn, .seg button, .tabs button,
  select.mini, input.mini, .fld input, .fld select { min-height: 44px; }
  .btn-sm { min-height: 40px; padding: 0 14px; }
  .icon-btn { width: 44px; }
  .switch { width: 52px; height: 30px; }
  .switch::after { width: 24px; height: 24px; }
  .switch.on::after { transform: translateX(22px); }
  .list-clean li { padding-top: 14px; padding-bottom: 14px; }
  .nav a { min-height: 44px; }
}

/* ── Chips ─────────────────────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 99px;
  font-size: var(--t-xs); font-weight: 600; line-height: 1.5;
  background: var(--surface-3); color: var(--fg-2);
  border: 1px solid transparent; white-space: nowrap;
}
.chip .bullet { width: 6px; height: 6px; border-radius: 99px; background: currentColor; flex: none; }
.chip svg { width: 12px; height: 12px; }
.chip-green { background: var(--brand-soft); color: var(--brand-text); }
.chip-ochre { background: var(--ochre-soft); color: var(--ochre-text); }
.chip-clay  { background: var(--clay-soft);  color: var(--clay-text); }
.chip-info  { background: var(--info-soft);  color: var(--info-text); }
.chip-wa    { background: var(--wa-soft);    color: var(--wa-text); }
.chip-grey  { background: var(--surface-3);  color: var(--fg-2); }
.chip-outline { background: transparent; border-color: var(--border-strong); color: var(--fg-2); font-weight: 500; }

/* Stage chip: the raw stage hue is tuned for bars and dots, not for text.
   Keep the hue on the bullet, and darken/lighten it for the label so both
   themes clear 4.5:1. */
.chip-stage {
  background: color-mix(in srgb, var(--stage) 13%, transparent);
  color: color-mix(in srgb, var(--stage) 60%, #000);
}
.chip-stage .bullet { background: var(--stage); opacity: 1; }
:root[data-theme="dark"] .chip-stage {
  background: color-mix(in srgb, var(--stage) 20%, transparent);
  color: color-mix(in srgb, var(--stage) 38%, #FFF);
}

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--e1);
  transition: box-shadow var(--d-base) var(--ease), border-color var(--d-base) var(--ease);
}
.card-pad { padding: var(--s4) var(--s5); }
.card-head {
  padding: var(--s3) var(--s5);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
}
.card-head h3 { font-size: var(--t-md); font-weight: 600; letter-spacing: -.005em; }
.card-head .hint { font-size: var(--t-xs); color: var(--fg-3); }
.card-head a.hint:hover { color: var(--brand-text); }

/* KPI — layered: tinted wash, value, delta, sparkline behind */
.kpi {
  position: relative; overflow: hidden;
  padding: var(--s4) var(--s5) var(--s3);
  display: flex; flex-direction: column; gap: 2px;
  animation: kpiIn var(--d-slow) var(--ease) both;
  animation-delay: var(--i, 0ms);
}
@keyframes kpiIn { from { opacity: 0; transform: translateY(10px) } }
.kpi::before {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(120% 100% at 0% 0%, var(--k-soft, transparent), transparent 62%);
  opacity: .85; pointer-events: none;
}
.kpi::after {
  content: ''; position: absolute; left: 0; top: var(--s4); bottom: var(--s4);
  width: 3px; border-radius: 0 3px 3px 0; background: var(--k, var(--brand));
}
.kpi > * { position: relative; }
.kpi .k-label {
  font-size: var(--t-xs); color: var(--fg-3);
  text-transform: uppercase; letter-spacing: .07em; font-weight: 650;
}
.kpi .k-value {
  font-family: var(--display); font-size: var(--t-3xl); font-weight: 400;
  line-height: 1.1; letter-spacing: -.02em; font-variant-numeric: tabular-nums;
}
.kpi .k-sub { font-size: var(--t-xs); color: var(--fg-2); }
.kpi .k-spark { position: absolute; right: 0; bottom: 0; left: auto; opacity: .5; pointer-events: none; }
.k-up   { color: var(--brand-text); font-weight: 650; }
.k-down { color: var(--clay-text);  font-weight: 650; }

/* ── Tables ────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--r); }
table.tbl { width: 100%; border-collapse: collapse; font-size: var(--t-md); }
table.tbl th {
  position: sticky; top: 0; z-index: 1;
  text-align: left; padding: 10px var(--s4);
  font-size: 10.5px; letter-spacing: .07em; text-transform: uppercase;
  color: var(--fg-3); font-weight: 650; white-space: nowrap;
  background: var(--surface-glass);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
table.tbl td { padding: 11px var(--s4); border-bottom: 1px solid var(--border); vertical-align: middle; }
table.tbl tbody tr { position: relative; transition: background var(--d-fast) var(--ease); }
table.tbl tbody tr:hover { background: var(--surface-2); }
table.tbl tbody tr.clickable { cursor: pointer; }
/* Left accent bar on hover instead of a heavy background */
table.tbl tbody tr.clickable:hover td:first-child { box-shadow: inset 3px 0 0 var(--brand); }
table.tbl tbody tr:last-child td { border-bottom: 0; }

.cell-name { display: flex; align-items: center; gap: var(--s2); }
.cell-name strong { font-weight: 600; }
.cell-sub { font-size: var(--t-xs); color: var(--fg-3); }
.mono { font-variant-numeric: tabular-nums; letter-spacing: -.01em; }

/* ── Toolbars & controls ───────────────────────────────────── */
.toolbar { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; margin-bottom: var(--s3); }
.seg {
  display: inline-flex; background: var(--surface-3);
  border: 1px solid var(--border); border-radius: 99px; padding: 3px;
}
.seg button {
  border: 0; background: transparent; color: var(--fg-2);
  min-height: 30px; padding: 0 14px; border-radius: 99px;
  cursor: pointer; font-size: var(--t-sm);
  transition: background var(--d-base) var(--ease), color var(--d-base) var(--ease), box-shadow var(--d-base) var(--ease);
}
.seg button:hover { color: var(--fg); }
.seg button.on { background: var(--surface-1); color: var(--brand-text); font-weight: 600; box-shadow: var(--e1); }

select.mini, input.mini {
  min-height: 34px; padding: 0 10px;
  border: 1px solid var(--border-strong); border-radius: var(--r-xs);
  background: var(--surface-1); font-size: var(--t-sm); outline: none;
  transition: border-color var(--d-fast) var(--ease), box-shadow var(--d-fast) var(--ease);
}
select.mini:focus-visible, input.mini:focus-visible { border-color: var(--brand); box-shadow: var(--ring); outline: none; }

.switch {
  width: 40px; height: 23px; border-radius: 99px; flex: none;
  background: var(--border-strong); position: relative; cursor: pointer; border: 0;
  transition: background var(--d-base) var(--ease);
}
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 17px; height: 17px; border-radius: 99px; background: #fff;
  box-shadow: var(--e1);
  transition: transform var(--d-base) var(--ease);
}
.switch.on { background: var(--brand); }
.switch.on::after { transform: translateX(17px); }

/* ── Progress & bars ───────────────────────────────────────── */
.progress { height: 7px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.progress > span {
  display: block; height: 100%; border-radius: 99px;
  background: linear-gradient(90deg, var(--brand), var(--brand-hover));
  transition: width var(--d-slow) var(--ease);
}
.bar-row { display: grid; grid-template-columns: minmax(90px,150px) minmax(0,1fr) 58px; gap: var(--s3); align-items: center; padding: 6px 0; font-size: var(--t-sm); }
.bar-track { height: 9px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; background: var(--b, var(--brand)); transition: width var(--d-slow) var(--ease); }

/* ── Lists ─────────────────────────────────────────────────── */
.list-clean { list-style: none; margin: 0; padding: 0; }
.list-clean li {
  padding: 11px var(--s5); border-bottom: 1px solid var(--border);
  display: flex; gap: var(--s3); align-items: center;
  transition: background var(--d-fast) var(--ease);
}
.list-clean li:last-child { border-bottom: 0; }
.list-clean li:hover { background: var(--surface-2); }
.list-clean li[data-action] { cursor: pointer; }

.callout {
  border: 1px solid var(--border); border-left: 3px solid var(--ochre);
  background: var(--ochre-soft); color: var(--ochre-text);
  padding: 12px var(--s4); border-radius: var(--r-xs);
  font-size: var(--t-sm);
}
.callout b { color: inherit; }
.empty { padding: var(--s10) var(--s5); text-align: center; color: var(--fg-3); font-size: var(--t-md); }

.due-over  { color: var(--clay-text);  font-weight: 650; }
.due-today { color: var(--ochre-text); font-weight: 650; }

/* ── Modal ─────────────────────────────────────────────────── */
#modal-root:empty { display: none; }
.modal-back {
  position: fixed; inset: 0; z-index: var(--z-modal);
  background: var(--scrim);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: var(--s5);
  animation: fadeIn var(--d-base) var(--ease);
}
.modal {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--e4);
  width: min(580px, 100%); max-height: 88vh; overflow: auto;
  animation: modalIn var(--d-slow) var(--ease);
}
@keyframes fadeIn { from { opacity: 0 } }
@keyframes modalIn { from { opacity: 0; transform: translateY(14px) scale(.97) } }
.modal-head {
  padding: var(--s4) var(--s5); border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; gap: var(--s3);
}
.modal-head h3 { font-family: var(--display); font-size: var(--t-xl); font-weight: 400; }
.modal-body { padding: var(--s5); display: flex; flex-direction: column; gap: var(--s4); }
.modal-foot {
  padding: var(--s3) var(--s5); border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: var(--s2); background: var(--surface-2);
}

.fld { display: flex; flex-direction: column; gap: 5px; }
.fld label { font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--fg-3); font-weight: 650; }
.fld input, .fld select, .fld textarea {
  min-height: 40px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: var(--r-xs);
  background: var(--surface-1); outline: none;
  transition: border-color var(--d-fast) var(--ease), box-shadow var(--d-fast) var(--ease);
}
.fld textarea { padding: 10px 12px; min-height: 80px; resize: vertical; }
.fld input:focus-visible, .fld select:focus-visible, .fld textarea:focus-visible {
  border-color: var(--brand); box-shadow: var(--ring); outline: none;
}
.fld .help { font-size: var(--t-xs); color: var(--fg-3); }
.fld-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4); }
@media (max-width: 640px) { .fld-2 { grid-template-columns: 1fr; } }

/* ── Command palette ───────────────────────────────────────── */
#cmd-root:empty { display: none; }
.cmd-back {
  position: fixed; inset: 0; z-index: var(--z-modal);
  background: var(--scrim);
  backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
  display: flex; justify-content: center; align-items: flex-start;
  padding: 12vh var(--s5) var(--s5);
  animation: fadeIn var(--d-base) var(--ease);
}
.cmd {
  width: min(620px, 100%);
  background: var(--surface-1); border: 1px solid var(--border-strong);
  border-radius: var(--r-lg); box-shadow: var(--e4);
  overflow: hidden; animation: modalIn var(--d-slow) var(--ease);
}
.cmd-input-row { display: flex; align-items: center; gap: 10px; padding: 0 var(--s4); border-bottom: 1px solid var(--border); }
.cmd-input-row svg { width: 17px; height: 17px; color: var(--fg-3); flex: none; }
.cmd-input-row input {
  flex: 1; min-height: 52px; border: 0; outline: none;
  background: transparent; font-size: var(--t-lg);
}
.cmd-input-row input::placeholder { color: var(--fg-3); }
.cmd-list { max-height: 46vh; overflow-y: auto; padding: var(--s2); }
.cmd-group { font-size: 10px; letter-spacing: .09em; text-transform: uppercase; color: var(--fg-3); font-weight: 650; padding: var(--s2) 10px 4px; }
.cmd-item {
  display: flex; align-items: center; gap: 10px;
  min-height: 40px; padding: 0 10px; border-radius: var(--r-xs);
  cursor: pointer; font-size: var(--t-md); color: var(--fg-2);
}
.cmd-item svg { width: 16px; height: 16px; opacity: .75; flex: none; }
.cmd-item .cmd-sub { font-size: var(--t-xs); color: var(--fg-3); margin-left: auto; }
.cmd-item[aria-selected="true"] { background: var(--brand-soft); color: var(--brand-text); }
.cmd-item[aria-selected="true"] svg { opacity: 1; }
.cmd-foot {
  border-top: 1px solid var(--border); padding: 8px var(--s4);
  display: flex; gap: var(--s4); font-size: var(--t-xs); color: var(--fg-3); background: var(--surface-2);
}
.cmd-foot kbd {
  font-family: var(--sans); background: var(--surface-3); border: 1px solid var(--border);
  border-radius: 4px; padding: 0 4px; font-size: 10px;
}

/* ── Toast ─────────────────────────────────────────────────── */
.toast-root {
  position: fixed; right: var(--s5); bottom: var(--s5); z-index: var(--z-toast);
  display: flex; flex-direction: column; gap: var(--s2); pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-1); color: var(--fg);
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  padding: 11px var(--s4); font-size: var(--t-md);
  box-shadow: var(--e4); max-width: 400px;
  animation: toastIn var(--d-slow) var(--ease);
}
.toast.out { animation: toastOut var(--d-fast) var(--ease-in) forwards; }
.toast svg { width: 16px; height: 16px; color: var(--brand-text); flex: none; }
@keyframes toastIn  { from { opacity: 0; transform: translateY(10px) scale(.96) } }
@keyframes toastOut { to   { opacity: 0; transform: translateY(6px) scale(.97) } }

/* ── Skeleton ──────────────────────────────────────────────── */
.sk {
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%);
  background-size: 200% 100%; border-radius: var(--r-xs);
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0 } }
