/* ==========================================================================
   TicketHappy design system
   Blue and white, with a dark theme. One set of tokens, two palettes: every
   colour is a variable so the dark theme is a token swap, not a second
   stylesheet. No external fonts or CDNs -- the CSP forbids them.
   ========================================================================== */

:root {
  /* brand */
  --blue-50:  #eff6ff;
  --blue-100: #dbeafe;
  --blue-200: #bfdbfe;
  --blue-300: #93c5fd;
  --blue-500: #3b82f6;
  --blue-600: #2563eb;
  --blue-700: #1d4ed8;
  --blue-800: #1e40af;
  --blue-900: #1e3a8a;

  /* surfaces */
  --bg:            #f6f8fc;
  --surface:       #ffffff;
  --surface-2:     #f9fbfe;
  --surface-hover: var(--blue-50);
  --border:        #e2e8f0;
  --border-strong: #cbd5e1;

  /* text */
  --text:          #0f172a;
  --text-muted:    #5b6b84;
  --text-inverse:  #ffffff;
  --link:          var(--blue-700);

  /* feedback */
  --ok:     #15803d;  --ok-bg:     #dcfce7;
  --warn:   #b45309;  --warn-bg:   #fef3c7;
  --danger: #b91c1c;  --danger-bg: #fee2e2;
  --info:   var(--blue-700); --info-bg: var(--blue-100);
  --accent: #6d28d9;  --accent-bg: #ede9fe;
  --muted-bg: #eef2f7;
  /* chart series, validated for colorblind separation on --surface */
  --series-1: #2a78d6;
  --series-2: #eb6834;

  /* shape + motion */
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow:    0 4px 16px rgba(15, 23, 42, .08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, .12);
  --ring: 0 0 0 3px var(--blue-200);
  --sidebar-w: 232px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Dark theme: honour the OS unless the user has chosen explicitly. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            #0b1220;
    --surface:       #131c2e;
    --surface-2:     #18233a;
    --surface-hover: #1c2942;
    --border:        #26334d;
    --border-strong: #35456b;
    --text:          #e8eefb;
    --text-muted:    #9bacc9;
    --link:          var(--blue-300);
    --ok:     #4ade80;  --ok-bg:     #10331f;
    --warn:   #fbbf24;  --warn-bg:   #3a2c09;
    --danger: #f87171;  --danger-bg: #3d1616;
    --info:   var(--blue-300); --info-bg: #17284a;
    --accent: #c4b5fd;  --accent-bg: #2a2150;
    --muted-bg: #1b2539;
  --series-1: #3987e5;
  --series-2: #d95926;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow:    0 4px 16px rgba(0, 0, 0, .45);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
    --ring: 0 0 0 3px rgba(59, 130, 246, .45);
  }
}

:root[data-theme="dark"] {
  --bg:            #0b1220;
  --surface:       #131c2e;
  --surface-2:     #18233a;
  --surface-hover: #1c2942;
  --border:        #26334d;
  --border-strong: #35456b;
  --text:          #e8eefb;
  --text-muted:    #9bacc9;
  --link:          var(--blue-300);
  --ok:     #4ade80;  --ok-bg:     #10331f;
  --warn:   #fbbf24;  --warn-bg:   #3a2c09;
  --danger: #f87171;  --danger-bg: #3d1616;
  --info:   var(--blue-300); --info-bg: #17284a;
  --accent: #c4b5fd;  --accent-bg: #2a2150;
  --muted-bg: #1b2539;
  --series-1: #3987e5;
  --series-2: #d95926;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow:    0 4px 16px rgba(0, 0, 0, .45);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
  --ring: 0 0 0 3px rgba(59, 130, 246, .45);
}

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

html { -webkit-text-size-adjust: 100%; }

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

h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p  { margin: 0 0 .75rem; }

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

code, kbd, pre { font-family: var(--mono); font-size: .875em; }
pre {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .75rem; overflow-x: auto;
}

:focus-visible { outline: 2px solid var(--blue-600); outline-offset: 2px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* --------------------------------------------------------------------------
   App shell
   -------------------------------------------------------------------------- */
.app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 1rem;
  height: 58px; padding: 0 1rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex; align-items: center; gap: .5rem;
  font-weight: 700; font-size: 1.05rem; color: var(--text); letter-spacing: -.02em;
}
.brand:hover { text-decoration: none; }
.brand-sub { font-weight: 400; }
.brand-mark {
  /* The SVG supplies its own rounded blue tile, so no background or radius
     here -- styling one on would frame the artwork twice. */
  display: block; width: 30px; height: 30px; object-fit: contain;
  flex: 0 0 auto;
}

.topbar-spacer { flex: 1; }

/* The account controls. Inline here; a dropdown on phones (see Responsive).
   The toggle's selector outranks .btn, which is declared further down. */
.topbar-menu { display: flex; align-items: center; gap: 1rem; }
.topbar .topbar-menu-toggle { display: none; }

.shell { flex: 1; display: flex; align-items: flex-start; }

.sidebar {
  position: sticky; top: 58px;
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  height: calc(100vh - 58px); overflow-y: auto;
  padding: 1rem .75rem;
  background: var(--surface); border-right: 1px solid var(--border);
}

.nav-group { margin-bottom: 1.25rem; }
.nav-label {
  padding: 0 .6rem; margin-bottom: .35rem;
  font-size: .68rem; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-muted);
}
.nav-link {
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem .6rem; margin-bottom: 2px;
  border-radius: var(--radius-sm);
  color: var(--text); font-weight: 500;
}
.nav-link:hover { background: var(--surface-hover); text-decoration: none; }
.nav-link[aria-current="page"] {
  background: var(--blue-600); color: #fff; font-weight: 600;
}
.nav-link[aria-current="page"] .nav-count { background: rgba(255,255,255,.22); color: #fff; }
.nav-count {
  margin-left: auto; padding: 0 .4rem; border-radius: 999px;
  background: var(--muted-bg); color: var(--text-muted);
  font-size: .72rem; font-weight: 700;
}

.content { flex: 1; min-width: 0; padding: 1.5rem; max-width: 1280px; }

.page-head {
  display: flex; flex-wrap: wrap; align-items: center; gap: .75rem;
  margin-bottom: 1.25rem;
}
.page-head h1 { margin: 0; }
.page-head .spacer { flex: 1; }
.page-sub { color: var(--text-muted); margin: .15rem 0 0; font-size: .9rem; }

/* --------------------------------------------------------------------------
   Cards, panels, grids
   -------------------------------------------------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 1rem; }
.card-head {
  display: flex; align-items: center; gap: .75rem;
  padding: .85rem 1.1rem; border-bottom: 1px solid var(--border);
}
.card-head h2, .card-head h3 { margin: 0; font-size: 1rem; }
.card-head .spacer { flex: 1; }
.card-body { padding: 1.1rem; }
.card-body.tight { padding: .6rem; }

.grid { display: grid; gap: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.grid.detail { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }

.stat {
  padding: 1rem 1.1rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.stat-label {
  font-size: .72rem; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-muted);
}
.stat-value { font-size: 1.85rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.stat-note { font-size: .8rem; color: var(--text-muted); }
.stat.is-warn .stat-value { color: var(--warn); }
.stat.is-danger .stat-value { color: var(--danger); }

/* --------------------------------------------------------------------------
   Charts (server-drawn SVG; see reports/templatetags/charts.py)
   -------------------------------------------------------------------------- */
.filter-row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; margin-bottom: 1rem; }
.filter-row select { width: auto; }
.report.htmx-request { opacity: .55; transition: opacity .15s; }
.report > * + * { margin-top: 1rem; }

.chart { position: relative; margin: 0; overflow-x: auto; }
.chart-svg { display: block; width: 100%; min-width: 520px; height: auto; font-family: var(--font); }
.chart-svg text { fill: var(--text-muted); font-size: 11px; }
.chart-svg .chart-value { fill: var(--text); font-weight: 600; }
.chart-svg .chart-label { fill: var(--text); font-size: 12px; }
.chart-grid line, .chart-baseline { stroke: var(--border); stroke-width: 1; }
.chart-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-line.series-1 { stroke: var(--series-1); }
.chart-line.series-2 { stroke: var(--series-2); }
.chart-dot { stroke: var(--surface); stroke-width: 2; }
.chart-dot.series-1, .chart-bar { fill: var(--series-1); }
.chart-dot.series-2 { fill: var(--series-2); }
.chart-hit { fill: transparent; cursor: default; }
.chart-hit:focus { outline: none; }
.chart-hit:focus-visible { fill: var(--surface-hover); fill-opacity: .6; }
.chart-row:hover .chart-bar, .chart-row:focus-within .chart-bar { fill-opacity: .8; }
.chart-crosshair { stroke: var(--border-strong); stroke-width: 1; visibility: hidden; }
.chart-crosshair.is-visible { visibility: visible; }

.chart-legend { display: flex; gap: 1rem; font-size: .8rem; color: var(--text-muted); margin-bottom: .5rem; }
.chart-legend span { display: inline-flex; align-items: center; gap: .4rem; }
.chart-key { display: inline-block; width: 14px; height: 2px; border-radius: 1px; background: var(--text-muted); }
.chart-key.series-1 { background: var(--series-1); }
.chart-key.series-2 { background: var(--series-2); }

.chart-tip {
  position: absolute; z-index: 5; pointer-events: none; min-width: 9rem;
  padding: .45rem .6rem; font-size: .8rem; line-height: 1.4;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow);
  opacity: 0; transition: opacity .08s;
}
.chart-tip.is-visible { opacity: 1; }
.chart-tip-title { color: var(--text-muted); margin-bottom: .15rem; }
.chart-tip-row { display: flex; align-items: center; gap: .45rem; }
.chart-tip-row strong { font-variant-numeric: tabular-nums; }
.chart-tip-row span:last-child { color: var(--text-muted); }

.chart-table { margin-top: .5rem; font-size: .85rem; }
.chart-table summary { cursor: pointer; color: var(--text-muted); font-size: .8rem; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .48rem .9rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font: inherit; font-weight: 600; font-size: .875rem;
  cursor: pointer; transition: background .12s ease, border-color .12s ease, transform .06s ease;
  text-decoration: none;
}
.btn:hover { background: var(--surface-hover); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }

.btn-primary {
  background: var(--blue-600); border-color: var(--blue-600); color: #fff;
}
.btn-primary:hover { background: var(--blue-700); border-color: var(--blue-700); }

.btn-danger { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-hover); }
.btn-sm { padding: .3rem .6rem; font-size: .8rem; }
.btn-icon { padding: .4rem; width: 34px; height: 34px; }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */
.field { margin-bottom: 1rem; }
.field > label, .label {
  display: block; margin-bottom: .3rem;
  font-size: .82rem; font-weight: 600; color: var(--text);
}
.hint { font-size: .78rem; color: var(--text-muted); margin-top: .25rem; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="datetime-local"], input[type="search"], input[type="url"],
input[type="time"], select, textarea {
  width: 100%; padding: .5rem .65rem;
  font: inherit; font-size: .9rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}
textarea { min-height: 108px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  border-color: var(--blue-500); box-shadow: var(--ring); outline: none;
}
input[type="file"] {
  width: 100%; padding: .45rem; font-size: .85rem;
  border: 1px dashed var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text-muted);
}
.check { display: flex; align-items: flex-start; gap: .5rem; margin-bottom: .6rem; }
.check input { margin-top: .2rem; }
.check label { font-weight: 500; font-size: .88rem; }

.form-row { display: flex; gap: .75rem; flex-wrap: wrap; }
.form-row > * { flex: 1 1 180px; min-width: 0; }

/* A group of checkboxes under one label, e.g. the working days. */
fieldset.field { border: 0; padding: 0; min-width: 0; }
fieldset.field > legend {
  padding: 0; margin-bottom: .3rem;
  font-size: .82rem; font-weight: 600; color: var(--text);
}
.check-row { display: flex; flex-wrap: wrap; gap: .25rem 1rem; }
.check-row > .check { margin-bottom: 0; }
input[type="number"].hours { width: 5.5rem; }

.errorlist, .form-errors {
  margin: 0 0 .75rem; padding: .6rem .8rem; list-style: none;
  background: var(--danger-bg); color: var(--danger);
  border: 1px solid var(--danger); border-radius: var(--radius-sm); font-size: .85rem;
}

/* --------------------------------------------------------------------------
   Tables and lists
   -------------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td {
  padding: .6rem .75rem; text-align: left; border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.data th {
  font-size: .72rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--text-muted); background: var(--surface-2); white-space: nowrap;
}
table.data tbody tr:hover { background: var(--surface-hover); }
table.data td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-link { font-weight: 600; }
.ticket-key { font-family: var(--mono); font-size: .8rem; color: var(--text-muted); }

/* A field the organization has marked required on intake. */
.req { color: var(--danger); font-weight: 700; }
/* Lets an HTMX-loaded group of filters sit in the toolbar's flex flow rather
   than becoming one flex item. */
.contents { display: contents; }

/* ---- Knowledge base ------------------------------------------------------ */
.kb-grid {
  display: grid; gap: .85rem;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
}
.kb-card {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); padding: .9rem 1rem;
  display: flex; flex-direction: column; gap: .35rem;
}
.kb-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.kb-card-title { font-weight: 650; color: var(--text); line-height: 1.3; }
.kb-card-title:hover { color: var(--link); }
.kb-card-lead { color: var(--text-muted); font-size: .85rem; margin: 0; }
.kb-card-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem;
  margin-top: auto; padding-top: .35rem; font-size: .78rem; }

.kb-summary {
  font-size: 1.02rem; color: var(--text-muted);
  border-left: 3px solid var(--blue-500); padding-left: .85rem; margin-bottom: 1.25rem;
}

/* Rendered article body. The sanitiser fixes the tag set, so these rules can
   safely assume what may appear. */
.kb-body { line-height: 1.65; }
.kb-body > *:first-child { margin-top: 0; }
.kb-body h1, .kb-body h2, .kb-body h3, .kb-body h4 {
  margin: 1.6rem 0 .6rem; line-height: 1.25; letter-spacing: -.01em;
}
.kb-body h1 { font-size: 1.45rem; }
.kb-body h2 { font-size: 1.2rem; }
.kb-body h3 { font-size: 1.05rem; }
.kb-body p { margin: 0 0 .9rem; }
.kb-body ul, .kb-body ol { margin: 0 0 .9rem; padding-left: 1.4rem; }
.kb-body li { margin-bottom: .3rem; }
.kb-body a { color: var(--link); }
.kb-body code {
  background: var(--muted-bg); padding: .1rem .3rem; border-radius: var(--radius-sm);
  font-size: .87em;
}
.kb-body pre {
  background: var(--muted-bg); padding: .8rem 1rem; border-radius: var(--radius);
  overflow-x: auto; margin: 0 0 .9rem;
}
.kb-body pre code { background: none; padding: 0; }
.kb-body blockquote {
  margin: 0 0 .9rem; padding: .1rem 0 .1rem 1rem;
  border-left: 3px solid var(--border-strong); color: var(--text-muted);
}
.kb-body table { width: 100%; border-collapse: collapse; margin: 0 0 .9rem; }
.kb-body th, .kb-body td {
  border: 1px solid var(--border); padding: .45rem .6rem; text-align: left;
}
.kb-body th { background: var(--surface-2); font-weight: 650; }
.kb-body hr { border: 0; border-top: 1px solid var(--border); margin: 1.5rem 0; }

/* ---- Public help centre -------------------------------------------------- */
.public-main {
  max-width: 62rem; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; width: 100%;
}
.public-footer {
  border-top: 1px solid var(--border); padding: 1.25rem;
  text-align: center; background: var(--surface);
}
.help-search { max-width: 34rem; margin: 1.25rem auto 0; position: relative; }
.help-search input[type="search"] { font-size: 1rem; padding: .7rem .9rem; }

.help-list { list-style: none; margin: 0; padding: 0; }
.help-list li { margin-bottom: .6rem; }
.help-item {
  display: block; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); padding: .85rem 1rem; color: var(--text);
}
.help-item:hover {
  border-color: var(--blue-500); box-shadow: var(--shadow-sm); text-decoration: none;
}
.help-title { display: block; font-weight: 650; margin-bottom: .2rem; }
.help-lead { display: block; color: var(--text-muted); font-size: .87rem; }

/* ---- Canned responses --------------------------------------------------- */
.canned-picker { margin: 0 0 1rem; }
.canned-picker > summary {
  cursor: pointer; font-size: .85rem; font-weight: 600; color: var(--link);
  padding: .35rem 0; list-style: none;
}
.canned-picker > summary::-webkit-details-marker { display: none; }
.canned-picker > summary::before { content: "+ "; font-weight: 700; }
.canned-picker[open] > summary::before { content: "− "; }
.canned-picker > summary:hover { text-decoration: underline; }

.canned-panel {
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); overflow: hidden; margin-top: .4rem;
}
.canned-panel input[type="search"] {
  border: 0; border-bottom: 1px solid var(--border); border-radius: 0;
  background: transparent;
}
.canned-list { list-style: none; margin: 0; padding: 0; max-height: 15rem; overflow-y: auto; }
.canned-list li { border-bottom: 1px solid var(--border); }
.canned-list li:last-child { border-bottom: 0; }
.canned-item {
  display: block; width: 100%; text-align: left; cursor: pointer;
  border: 0; background: none; padding: .55rem .75rem; font: inherit;
  color: var(--text);
}
.canned-item:hover, .canned-item:focus-visible { background: var(--surface-hover); }
.canned-title { display: flex; align-items: center; gap: .4rem; font-weight: 600; font-size: .88rem; }
.canned-title code { font-size: .72rem; }
.canned-preview {
  display: block; color: var(--text-muted); font-size: .8rem;
  margin-top: .15rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Condensed queue used in narrow panels. */
.compact-list { list-style: none; margin: 0; padding: 0; }
.compact-list li {
  padding: .65rem 1.1rem; border-bottom: 1px solid var(--border);
}
.compact-list li:last-child { border-bottom: 0; }
.compact-list li:hover { background: var(--surface-hover); }
.compact-meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: .35rem;
  margin-top: .25rem; font-size: .8rem;
}

.empty {
  padding: 2.5rem 1rem; text-align: center; color: var(--text-muted);
}
.empty strong { display: block; color: var(--text); margin-bottom: .25rem; }

/* --------------------------------------------------------------------------
   Badges
   -------------------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .15rem .5rem; border-radius: 999px;
  font-size: .74rem; font-weight: 700; letter-spacing: .01em; white-space: nowrap;
  background: var(--muted-bg); color: var(--text-muted);
}
.badge.tone-ok     { background: var(--ok-bg);     color: var(--ok); }
.badge.tone-warn   { background: var(--warn-bg);   color: var(--warn); }
.badge.tone-danger { background: var(--danger-bg); color: var(--danger); }
.badge.tone-info   { background: var(--info-bg);   color: var(--info); }
.badge.tone-accent { background: var(--accent-bg); color: var(--accent); }
.badge.tone-muted  { background: var(--muted-bg);  color: var(--text-muted); }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* --------------------------------------------------------------------------
   Conversation
   -------------------------------------------------------------------------- */
.thread { display: flex; flex-direction: column; gap: .85rem; }
.message {
  padding: .85rem 1rem; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface);
}
.message.is-internal {
  background: var(--warn-bg); border-color: var(--warn);
}
.message.is-internal .message-meta { color: var(--warn); }
.message-meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem;
  margin-bottom: .4rem; font-size: .8rem; color: var(--text-muted);
}
.message-author { font-weight: 650; color: var(--text); }
.message-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.message-body p:last-child { margin-bottom: 0; }

.timeline { list-style: none; margin: 0; padding: 0; font-size: .85rem; }
.timeline li {
  display: flex; gap: .6rem; padding: .45rem 0;
  border-bottom: 1px dashed var(--border); color: var(--text-muted);
}
.timeline li:last-child { border-bottom: 0; }
.timeline time { flex: 0 0 auto; font-variant-numeric: tabular-nums; }

.attachments { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .6rem; }
.attachment {
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .35rem .6rem; font-size: .82rem;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
}
.attachment:hover { background: var(--surface-hover); text-decoration: none; }
.attachment .size { color: var(--text-muted); font-size: .76rem; }

.meta-list { margin: 0; font-size: .875rem; }
.meta-list dt {
  font-size: .72rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--text-muted); margin-top: .8rem;
}
.meta-list dt:first-child { margin-top: 0; }
.meta-list dd { margin: .15rem 0 0; }

/* --------------------------------------------------------------------------
   Filters, toolbar, pagination
   -------------------------------------------------------------------------- */
.toolbar {
  display: flex; flex-wrap: wrap; gap: .5rem; align-items: center;
  padding: .75rem 1.1rem; border-bottom: 1px solid var(--border);
  background: var(--surface-2); border-radius: var(--radius) var(--radius) 0 0;
}
.toolbar input[type="search"], .toolbar select { width: auto; min-width: 140px; }
.toolbar .spacer { flex: 1; }

.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip {
  padding: .3rem .7rem; border-radius: 999px; font-size: .8rem; font-weight: 600;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  cursor: pointer;
}
.chip:hover { background: var(--surface-hover); text-decoration: none; }
.chip.is-active { background: var(--blue-600); border-color: var(--blue-600); color: #fff; }

.pager {
  display: flex; align-items: center; gap: .6rem; justify-content: flex-end;
  padding: .75rem 1.1rem; border-top: 1px solid var(--border);
  font-size: .85rem; color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   Toasts + messages
   -------------------------------------------------------------------------- */
#toasts {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 90;
  display: flex; flex-direction: column; gap: .5rem; max-width: 22rem;
}
.toast {
  display: flex; gap: .6rem; align-items: flex-start;
  padding: .7rem .85rem; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-lg); font-size: .88rem;
  animation: toast-in .16s ease-out;
}
.toast.level-success { border-left: 3px solid var(--ok); }
.toast.level-error   { border-left: 3px solid var(--danger); }
.toast.level-info    { border-left: 3px solid var(--info); }
.toast button {
  margin-left: auto; border: 0; background: none; cursor: pointer;
  color: var(--text-muted); font-size: 1rem; line-height: 1; padding: 0 .15rem;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }

.notice {
  padding: .7rem .9rem; border-radius: var(--radius); font-size: .88rem;
  border: 1px solid var(--border); background: var(--surface-2); margin-bottom: 1rem;
}
.notice.warn   { background: var(--warn-bg);   border-color: var(--warn);   color: var(--warn); }
.notice.danger { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }
.notice.info   { background: var(--info-bg);   border-color: var(--info);   color: var(--info); }
.notice.ok     { background: var(--ok-bg);     border-color: var(--ok);     color: var(--ok); }

/* --------------------------------------------------------------------------
   Public pages
   -------------------------------------------------------------------------- */
.public { max-width: 1060px; margin: 0 auto; padding: 2rem 1.25rem 4rem; }
.hero { padding: 3rem 0 2rem; text-align: center; }
.hero h1 { font-size: clamp(1.9rem, 4vw, 2.75rem); }
.hero p.lede { font-size: 1.1rem; color: var(--text-muted); max-width: 40rem; margin: 0 auto 1.5rem; }
.auth-card {
  max-width: 26rem; margin: 3rem auto; padding: 1.75rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
}
.auth-card h1 { font-size: 1.35rem; }
.plan {
  display: flex; flex-direction: column;
  padding: 1.25rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.plan.is-featured { border-color: var(--blue-600); box-shadow: var(--shadow); }
.plan .price { font-size: 1.5rem; font-weight: 700; margin: .25rem 0 .75rem; }
.plan ul { margin: 0 0 1rem; padding-left: 1.1rem; font-size: .88rem; color: var(--text-muted); }
.plan li { margin-bottom: .3rem; }
.plan .btn { margin-top: auto; }

/* allauth entrance pages: the primary action owns the full width. */
.auth-card .btn-primary { width: 100%; }
.auth-card form { margin-bottom: .5rem; }
.auth-card h2 { font-size: 1rem; color: var(--text-muted); margin-top: 1.25rem; }
.auth-panel { margin-bottom: 1rem; }
.auth-panel .btn-row { margin-top: .75rem; }
.auth-back { margin-top: 1.25rem; }
hr.rule { border: 0; border-top: 1px solid var(--border); margin: 1.25rem 0; }

/* Provider buttons (allauth socialaccount) */
.socialaccount_providers, .provider-list { list-style: none; padding: 0; margin: .75rem 0; display: grid; gap: .5rem; }
.socialaccount_providers a, .provider-list a {
  display: block; text-align: center; padding: .5rem .9rem;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-weight: 600; font-size: .88rem; color: var(--text); background: var(--surface);
}
.socialaccount_providers a:hover, .provider-list a:hover { background: var(--surface-hover); text-decoration: none; }

.divider {
  display: flex; align-items: center; gap: .75rem;
  margin: 1.1rem 0; color: var(--text-muted); font-size: .78rem;
  text-transform: uppercase; letter-spacing: .08em;
}
.divider::before, .divider::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}

/* --------------------------------------------------------------------------
   HTMX feedback
   -------------------------------------------------------------------------- */
.htmx-indicator { opacity: 0; transition: opacity .15s ease; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }
.htmx-swapping { opacity: .45; }

.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--blue-200); border-top-color: var(--blue-600);
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 960px) {
  .grid.cols-5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.detail { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  /* Stretch, so the content column is the screen's width and wide tables
     and charts scroll inside their own wrappers instead of widening the page. */
  .shell { flex-direction: column; align-items: stretch; }
  /* Every topbar fits a 320px screen instead of widening the page: the logo
     loses its name and the theme toggle says just "Dark"/"Light" (both still
     read out), buttons never wrap, and long organization names truncate.
     The app's bar also folds its account controls into a menu. */
  .topbar { gap: .5rem; padding: 0 .75rem; }
  .brand-name, .topbar > .btn .theme-word {
    position: absolute; width: 1px; height: 1px; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
  .topbar > .btn { flex: none; white-space: nowrap; }
  .brand { min-width: 0; }
  .topbar .badge, .brand-org, .brand-sub {
    display: block; min-width: 0; max-width: 100%;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .help-brand { flex-direction: column; align-items: flex-start; gap: 0; line-height: 1.25; }
  .help-brand .brand-sub { margin-top: 0; }
  .org-switcher { min-width: 0; }
  .topbar .topbar-menu-toggle { display: inline-flex; }
  .topbar-menu {
    display: none; position: absolute; top: calc(100% + .35rem); right: .75rem;
    flex-direction: column; align-items: stretch; gap: 2px;
    min-width: 12rem; max-width: calc(100vw - 1.5rem); padding: .35rem;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-lg);
  }
  .topbar-menu.is-open { display: flex; }
  .topbar-menu .btn { width: 100%; justify-content: flex-start; font-size: .875rem; padding: .55rem .7rem; }
  .sidebar {
    position: static; width: 100%; flex: none; height: auto;
    border-right: 0; border-bottom: 1px solid var(--border);
    display: flex; gap: .35rem; overflow-x: auto; padding: .6rem;
  }
  .nav-group { display: flex; gap: .35rem; margin: 0; }
  .nav-label { display: none; }
  .nav-link { white-space: nowrap; }
  .content { padding: 1rem; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4, .grid.cols-5 { grid-template-columns: minmax(0, 1fr); }
}
