/* AppSystem design system — plain CSS, no build step.

   Tokens first (colours, radius, spacing, type), then components. Pages use the component
   classes (btn, field, select, card, toolbar, data table); they never hard-code colours.
   A theme = another set of tokens: add `:root[data-theme="<name>"] { ... }` below and set
   data-theme on <html>. Loaded after utilities.css (frozen layout utilities); see docs/ai/UI.md. */

:root {
  /* surfaces */
  --bg: #f4f3f0;
  --surface: #ffffff;
  --surface-2: #f8f7f5;          /* table header, hover, subtle fills */
  --border: #e4e0da;
  --border-strong: #cfc9c2;

  /* text */
  --text: #2a241d;
  --text-muted: #746b5f;
  --text-on-color: #ffffff;

  /* actions — the call view's colours */
  --primary: #375059;
  --primary-hover: #26393f;
  --green: #3c6142;
  --green-hover: #2e4b33;
  --red: #835042;
  --red-hover: #664033;
  --yellow: #bb8742;
  --yellow-hover: #976c33;
  --gray: #746b5f;
  --gray-hover: #5b5247;

  --selected: #e6edf0;           /* selected row */
  /* soft fills for status pills */
  --green-soft: #e6f0e8;
  --red-soft: #f6e6e3;
  --yellow-soft: #fdf6e6;
  --blue-soft: #e6edf0;
  --focus-ring: 0 0 0 3px rgba(55, 80, 89, 0.25);

  /* shape and type */
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 2px rgba(42, 36, 29, 0.06), 0 1px 3px rgba(42, 36, 29, 0.08);
  --shadow-lg: 0 10px 40px rgba(42, 36, 29, 0.18);
  --control-h: 2rem;             /* buttons, inputs, selects share one height */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ---------- base ---------- */

body.app {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  height: var(--control-h);
  padding: 0 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font: 500 0.875rem/1 var(--font);
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, box-shadow 0.15s;
  /* default look = secondary: white with a border */
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn:hover { background: var(--surface-2); }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary, .btn-green, .btn-red, .btn-yellow, .btn-gray {
  color: var(--text-on-color);
  border-color: transparent;
}
.btn-primary { background: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-green { background: var(--green); }
.btn-green:hover:not(:disabled) { background: var(--green-hover); }
.btn-red { background: var(--red); }
.btn-red:hover:not(:disabled) { background: var(--red-hover); }
.btn-yellow { background: var(--yellow); }
.btn-yellow:hover:not(:disabled) { background: var(--yellow-hover); }
.btn-gray { background: var(--gray); }
.btn-gray:hover:not(:disabled) { background: var(--gray-hover); }

/* icon-only / in-row actions: no frame until hovered */
.btn-ghost {
  background: transparent;
  border-color: transparent;
  padding: 0 0.5rem;
}
.btn-ghost:hover { background: var(--surface-2); }

.btn-sm { height: 1.625rem; padding: 0 0.5rem; font-size: 0.8125rem; }

/* ---------- form controls ---------- */

.field,
.select {
  height: var(--control-h);
  padding: 0 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background-color: var(--surface);
  color: var(--text);
  font: 400 0.875rem var(--font);
  transition: border-color 0.15s, box-shadow 0.15s;
}

textarea.field { height: auto; padding: 0.5rem 0.75rem; line-height: 1.4; }

.field::placeholder { color: var(--text-muted); opacity: 0.8; }

.field:focus,
.select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}

/* native dropdown arrow replaced by one chevron that matches everywhere */
.select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 2.25rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%23746b5f'%3E%3Cpath fill-rule='evenodd' d='M5.23 7.21a.75.75 0 011.06.02L10 11.17l3.71-3.94a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z' clip-rule='evenodd'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.625rem center;
  background-size: 1.125rem;
  cursor: pointer;
}

/* a multi-select and a Tagify box (it copies the input's classes) grow with their content */
.select[multiple] { height: auto; padding: 0.375rem; background-image: none; }
.tagify.field { height: auto; min-height: var(--control-h); padding: 0.125rem 0.25rem; }

/* compact controls for dense admin tables */
.field-sm, .select-sm { height: 1.625rem; font-size: 0.8125rem; padding: 0 0.5rem; }
.select-sm { padding-right: 1.75rem; background-position: right 0.375rem center; background-size: 1rem; }

/* text link */
.link { color: var(--primary); text-decoration: none; background: none; border: 0; padding: 0; cursor: pointer; font: inherit; }
.link:hover { text-decoration: underline; }
.link-danger { color: var(--red); }

/* search field with a magnifier inside */
.field-search {
  width: 100%;
  max-width: 22rem;
  padding-left: 2.25rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%23746b5f'%3E%3Cpath fill-rule='evenodd' d='M9 3.5a5.5 5.5 0 100 11 5.5 5.5 0 000-11zM2 9a7 7 0 1112.45 4.39l3.33 3.33a.75.75 0 11-1.06 1.06l-3.33-3.33A7 7 0 012 9z' clip-rule='evenodd'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 0.75rem center;
  background-size: 1rem;
}

/* Inside .form-scope (the modal body) plain inputs, textareas and selects get the
   field/select look without classes, so the existing edit forms match. New markup
   still uses .field / .select. */
.form-scope :is(input:not([type="checkbox"], [type="radio"], [type="file"], [type="hidden"],
                          [type="submit"], [type="button"], [type="range"], [type="color"]),
                select) {
  height: var(--control-h);
  padding: 0 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background-color: var(--surface);
  color: var(--text);
  font: 400 0.875rem var(--font);
}

.form-scope textarea {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background-color: var(--surface);
  font: 400 0.875rem/1.4 var(--font);
}

.form-scope select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 2.25rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%23746b5f'%3E%3Cpath fill-rule='evenodd' d='M5.23 7.21a.75.75 0 011.06.02L10 11.17l3.71-3.94a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z' clip-rule='evenodd'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.625rem center;
  background-size: 1.125rem;
}

.form-scope .tagify {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background-color: var(--surface);
  font-size: 0.875rem;
}

.form-scope select[multiple] { height: auto; padding: 0.375rem; background-image: none; }

.form-scope :is(input, select, textarea):focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}

.form-scope :is(input, select, textarea):disabled { background-color: var(--surface-2); }

input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--primary);
  width: 1rem;
  height: 1rem;
  cursor: pointer;
}

/* ---------- layout helpers ---------- */

/* a row of buttons and controls that wraps on narrow screens */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

/* control + its button kept together when the toolbar wraps */
.toolbar-group {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  max-width: 100%;
}

/* a long option (e.g. an email) must not stretch the toolbar */
.toolbar .select { max-width: 16rem; min-width: 0; text-overflow: ellipsis; }

@media (max-width: 767px) {
  .toolbar-group { width: 100%; flex-wrap: wrap; }
  .toolbar-group :is(.select, .field) { flex: 1; min-width: 0; max-width: none; }
  .toolbar-group .field[type="date"] { min-width: 9rem; }
  /* alone on a wrapped line it would only add an empty row */
  .toolbar-spacer { display: none; }
}

/* pushes what follows to the right end of the toolbar */
.toolbar-spacer { flex: 1; }

.toolbar-divider {
  width: 1px;
  align-self: stretch;
  margin: 0 0.25rem;
  background: var(--border);
}

/* small counter / status pill */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  min-height: 1.5rem;
  padding: 0.125rem 0.625rem;
  border-radius: 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font: 500 0.8125rem var(--font);
}
/* a badge that opens something (a channel in the Social tab) */
button.badge { cursor: pointer; }
button.badge:hover { border-color: var(--border-strong); color: var(--text); }

.stack > * + * { margin-top: 0.75rem; }

/* status pill in a table cell: Unpaid, Overdue, OK … */
.status {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  font: 600 0.75rem/1.4 var(--font);
  white-space: nowrap;
}
.status-green { background: var(--green-soft); color: var(--green); }
.status-red { background: var(--red-soft); color: var(--red); }
.status-yellow { background: var(--yellow-soft); color: var(--yellow-hover); }
.status-blue { background: var(--blue-soft); color: var(--primary); }
.status-gray { background: var(--surface-2); color: var(--text-muted); }

/* ---------- data tables ----------
   Lists sit in <div class="full-table">: a 55vh scroll box. Cells cut long text with "…"
   and base.js adds the full text as a tooltip. The <thead> is sticky WITHOUT a z-index on
   purpose, so menus and dialogs always paint above it; do not add one. */

.full-table {
  max-height: 55vh;
  overflow: auto;
  display: block;
  isolation: isolate;              /* keep z-indexed cell content inside this box */
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.full-table table { border-collapse: separate; border-spacing: 0; border: 0; }

.full-table thead {
  position: sticky;
  top: 0;
  background: var(--surface-2);
}

.full-table th,
.full-table td {
  border: 0;
  border-bottom: 1px solid var(--border);
  padding: 0.625rem 0.75rem;
  text-align: left;
  font-size: 0.875rem;
}

.full-table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.full-table tbody tr:last-child td { border-bottom: 0; }
/* on the row, not the cells, so a cell's own colour (e.g. last-call heat) stays */
.full-table tbody tr:hover { background: var(--surface-2); }
.full-table tbody tr.is-selected { background: var(--selected); font-weight: 600; }
.full-table tbody tr.day-row td { background: var(--surface-2); }  /* a group heading inside a list (Time: one per day) */
.full-table tbody tr.day-row td .btn { margin-left: 0.25rem; }

/* fixed-width columns: never let text spill into the neighbouring cell */
.full-table table.table-fixed th,
.full-table table.table-fixed td {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* keep one line and cut long values with "…" (full text in tooltip) */
.full-table table.table-fixed td { white-space: nowrap; }

/* cells with controls wrap instead, so buttons are never cut off */
.full-table table.table-fixed td:has(button, input, select) {
  overflow: visible;
  white-space: normal;
}

/* amounts: right-aligned, digits line up */
.full-table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* action and checkbox columns: centred, as narrow as their content */
.full-table .cell-action { text-align: center; white-space: nowrap; }

/* Column priority (components/table.html): narrow screens show only the main
   columns; a row click still opens the full record. */
@media (max-width: 1023px) {
  .full-table .col-p3 { display: none; }
}

@media (max-width: 767px) {
  .full-table .col-p2 { display: none; }

  /* natural column widths and wrapped text instead of percentage slivers cut with "…" */
  .full-table table.table-fixed { table-layout: auto; }
  .full-table table.table-fixed th { width: auto; }
  .full-table table.table-fixed td { white-space: normal; }

  .full-table th,
  .full-table td { padding: 0.5rem; }
}

/* ---------- call view (calls/dashboard.html) ----------
   Seven panes in two Split.js rows; on phones they stack (CSS in the template). */

.calls-layout {
  height: 85vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.pane {
  padding: 0.875rem;
  overflow: auto;
  background: var(--surface);
}

.pane-title {
  margin-bottom: 0.5rem;
  color: var(--text-muted);
  font: 600 0.75rem var(--font);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* info box filled by htmx (customer, product, call) */
.pane-box {
  min-height: 2.5rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  font-size: 0.875rem;
  overflow: auto;
}

.pane .field-search { max-width: none; }

/* group of chips / choices with a light frame */
.choice-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* checkbox or radio with its label as one pill */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  min-height: 1.75rem;
  padding: 0.25rem 0.625rem;
  border: 1px solid var(--border-strong);
  border-radius: 0.875rem;
  background: var(--surface);
  font-size: 0.8125rem;
  cursor: pointer;
  user-select: none;
}
.chip:has(input:checked) { background: var(--blue-soft); border-color: var(--primary); color: var(--primary); }
.chip:has(input:disabled) { opacity: 0.5; cursor: not-allowed; }
.chip input { width: 0.875rem; height: 0.875rem; }

/* the chosen call outcome (verticals/calls/static/dashboard.js highlightButton) */
.btn.highlight {
  outline: none !important;
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text);
}

/* ---------- header, navigation, user menu (base.html) ---------- */

.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.app-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 1rem;
}

.app-name { font: 700 1.125rem var(--font); letter-spacing: -0.01em; }

.nav-links { display: flex; align-items: center; gap: 0.25rem; }
.nav-links-col { flex-direction: column; align-items: stretch; }

.nav-link {
  height: 2.25rem;
  padding: 0 0.875rem;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  font: 500 0.875rem var(--font);
  text-align: left;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.is-active { background: var(--blue-soft); color: var(--primary); font-weight: 600; }

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: 999px;
  background: var(--primary);
  color: var(--text-on-color);
  font: 600 0.875rem var(--font);
  cursor: pointer;
}
.avatar-lg { width: 2.5rem; height: 2.5rem; }

/* dropdown under a button; its wrapper needs position: relative */
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 0.5rem);
  z-index: 70;
  min-width: 12rem;
  width: max-content;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.menu-head { padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); }

.menu-item {
  display: block;
  width: 100%;
  padding: 0.625rem 1rem;
  border: 0;
  background: transparent;
  color: var(--text);
  font: 400 0.875rem var(--font);
  text-align: left;
  cursor: pointer;
}
.menu-item:hover { background: var(--surface-2); }

.text-muted { color: var(--text-muted); }

/* ---------- toast (base.js showPopup) ---------- */

.toast {
  position: fixed;
  top: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  max-width: calc(100vw - 2rem);
  padding: 0.625rem 1.25rem;
  border: 1px solid;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font: 500 0.875rem var(--font);
  white-space: pre-line;
  transition: opacity 0.3s;
}
.toast-ok { background: var(--green-soft); color: var(--green); border-color: #c0d5c5; }
.toast-error { background: var(--red-soft); color: var(--red); border-color: #e7c7c1; }

/* ---------- messages and sign-in pages ---------- */

.alert {
  padding: 0.625rem 0.875rem;
  border: 1px solid;
  border-radius: var(--radius);
  font-size: 0.875rem;
}
.alert-error { background: var(--red-soft); color: var(--red); border-color: #e7c7c1; }
.alert-ok { background: var(--green-soft); color: var(--green); border-color: #c0d5c5; }

/* login, tenant picker: one centred card */
.auth-card {
  width: 100%;
  max-width: 26rem;
  margin: 3rem auto 0;
  padding: 2rem;
}
.auth-title { margin-bottom: 1.5rem; text-align: center; font: 700 1.5rem var(--font); }

/* label above a control */
.label { display: block; margin-bottom: 0.25rem; color: var(--text-muted); font: 500 0.8125rem var(--font); }

/* a big full-width choice, e.g. a workspace */
.choice {
  display: block;
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: 500 0.9375rem var(--font);
  text-align: left;
  cursor: pointer;
}
.choice:hover { border-color: var(--primary); background: var(--blue-soft); }

/* ---------- sub-tabs ----------
   A second level of navigation inside one main tab (docs/ai/UI.md "Sub-tabs"): a strip of `.subtab` buttons over a
   panel. Built by the macro in templates/components/subtabs.html; the server decides which one is active. Tabs that
   only an ADMIN may open come after a `.subtab-spacer` (pushed right). The strip scrolls sideways on a phone. */
.subtabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.subtabs::-webkit-scrollbar { display: none; }
.subtab {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  margin-bottom: -1px;
  padding: 0.5rem 0.875rem;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--text-muted);
  font: 500 0.9375rem var(--font);
  white-space: nowrap;
  cursor: pointer;
}
.subtab:hover { color: var(--text); }
.subtab:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius); }
.subtab.is-active { color: var(--primary); border-bottom-color: var(--primary); }
.subtab .badge { height: 1.25rem; padding: 0 0.5rem; font-size: 0.75rem; }
.subtab-spacer { flex: 1; }

/* cards side by side, as many as fit (panels of a sub-tab) */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr));
  gap: 1rem;
}

/* clickable pick list: about 5 rows, then a scrollbar */
.pick-list { max-height: 9.5rem; overflow-y: auto; border: 1px solid var(--border-strong); border-radius: var(--radius); background-color: var(--surface); }
.pick-list th { position: sticky; top: 0; text-align: left; background-color: var(--surface); padding: 0.25rem 0.5rem; }
.pick-list td { padding: 0.25rem 0.5rem; }
.pick-row { cursor: pointer; }
.pick-row:hover { background-color: var(--surface-2, rgba(0, 0, 0, 0.04)); }
.pick-row.is-picked { background-color: var(--primary); color: #fff; }

/* the green phone icon (customer list on a phone, customer details) */
.icon-phone { color: #16a34a; vertical-align: middle; }
