/* ==========================================================================
   Inbox assistant — admin UI
   --------------------------------------------------------------------------
   Hand-written, no build step, no framework, and NO JavaScript anywhere: the
   Content-Security-Policy on every response is script-src 'none'. Anything
   that looks interactive here is CSS only (:target, :focus-within, :checked).

   Brand orange #FF6200 is sampled from the AirGo wordmark. It is used for
   identity and for the single primary action on a page — never for status.
   Status has its own colours, because "the thing you click" and "the thing
   that is wrong" must never look the same.
   ========================================================================== */

/* --- palette ------------------------------------------------------------ */
:root {
  --brand:        #FF6200;
  --brand-ink:    #C74B00;
  --brand-soft:   #FFF1E8;
  --brand-line:   #FFD3B8;

  --bg:           #F6F7F9;
  --surface:      #FFFFFF;
  --surface-2:    #FBFCFD;
  --line:         #E3E7EC;
  --line-strong:  #CBD2DA;

  --ink:          #12171D;
  --ink-2:        #4A5560;
  --ink-3:        #79838F;

  --good:         #0F7B4F;
  --good-soft:    #E7F6EE;
  --warn:         #9A6400;
  --warn-soft:    #FDF3DF;
  --bad:          #B3261E;
  --bad-soft:     #FDECEA;
  --info:         #1B5FA8;
  --info-soft:    #E9F2FB;

  --radius:       12px;
  --radius-sm:    8px;
  --shadow:       0 1px 2px rgba(16,24,32,.06), 0 4px 16px rgba(16,24,32,.05);
  --shadow-lift:  0 2px 6px rgba(16,24,32,.08), 0 12px 32px rgba(16,24,32,.10);

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand-soft:  #2A1608;
    --brand-line:  #5A2E0E;

    --bg:          #0E1116;
    --surface:     #161B22;
    --surface-2:   #1B212A;
    --line:        #262D37;
    --line-strong: #38414D;

    --ink:         #E8EDF3;
    --ink-2:       #AFBAC6;
    --ink-3:       #7C8794;

    --good:        #4ED88F;  --good-soft: #0E2A1D;
    --warn:        #E8B33E;  --warn-soft: #2B2210;
    --bad:         #FF7B72;  --bad-soft:  #2C1512;
    --info:        #6FB4F5;  --info-soft: #101F2E;

    --shadow:      0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
    --shadow-lift: 0 2px 6px rgba(0,0,0,.5), 0 12px 32px rgba(0,0,0,.4);
  }
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; letter-spacing: -.01em; font-weight: 650; }
h1 { font-size: 26px; }
h2 { font-size: 18px; margin-top: 2rem; }
h3 { font-size: 15px; }

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

p { margin: 0 0 1rem; }
code, pre, .mono { font-family: var(--mono); font-size: .92em; }

/* Visible focus everywhere. Without JS this is the only affordance a
   keyboard user gets, so it is deliberately loud. */
:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 4px;
}

.muted    { color: var(--ink-3); }
.err-text { color: var(--bad); }

/* --- app shell ---------------------------------------------------------- */
.bar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}

.bar-inner {
  max-width: 1120px; margin: 0 auto;
  padding: 0 24px;
  display: flex; align-items: center; gap: 28px;
  min-height: 62px;
}

.brand { display: flex; align-items: center; gap: 12px; flex: none; }
.brand img { height: 26px; width: auto; display: block; }
.brand .brand-sub {
  font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink-3); border-left: 1px solid var(--line-strong); padding-left: 12px;
}

.bar nav { display: flex; gap: 2px; flex: 1 1 auto; flex-wrap: wrap; }
.bar nav a {
  padding: 8px 14px; border-radius: var(--radius-sm);
  color: var(--ink-2); font-weight: 550; font-size: 14px;
  display: inline-flex; align-items: center; gap: 7px;
}
.bar nav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.bar nav a.on { background: var(--brand-soft); color: var(--brand-ink); }

/* The count of things waiting rides in the nav, so it is visible from every
   page rather than only the dashboard. */
.navcount {
  min-width: 20px; padding: 0 6px; height: 20px;
  border-radius: 10px; background: var(--bad); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 20px; text-align: center;
}
.bar nav a.on .navcount { background: var(--bad); }

.bar-right { display: flex; align-items: center; gap: 10px; flex: none; }

main { max-width: 1120px; margin: 0 auto; padding: 28px 24px 72px; }

/* --- pills -------------------------------------------------------------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 650; letter-spacing: .01em;
  border: 1px solid transparent; white-space: nowrap;
}
.pill::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; flex: none;
}
.pill-plain::before { display: none; }

.mode-observe  { background: var(--info-soft); color: var(--info); border-color: var(--info); }
.mode-assisted { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
.mode-auto     { background: var(--good-soft); color: var(--good); border-color: var(--good); }
.paused        { background: var(--bad-soft);  color: var(--bad);  border-color: var(--bad); }

.st-queued     { background: var(--surface-2); color: var(--ink-2); border-color: var(--line-strong); }
.st-replied    { background: var(--good-soft); color: var(--good); border-color: var(--good); }
.st-escalated  { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
.st-error      { background: var(--bad-soft);  color: var(--bad);  border-color: var(--bad); }
.st-dismissed  { background: var(--surface-2); color: var(--ink-3); border-color: var(--line); }

/* --- status banner ------------------------------------------------------ */
/* The one thing a new operator must understand: is it sending or not. */
/* A block, not a flex row: this is a <details>, and its summary and body must
   stack. The flex row lives on the summary itself, further down. Left as flex
   here, the explanatory paragraph rendered as a narrow column beside the
   heading. */
.status {
  display: block;
  border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface);
  box-shadow: var(--shadow); margin-bottom: 24px;
  overflow: hidden;
}
.status-icon {
  flex: none; width: 40px; height: 40px; border-radius: 10px;
  display: grid; place-items: center; font-size: 19px; font-weight: 700;
}
.status-title { font-weight: 650; font-size: 16px; margin: 0 0 2px; }
.status-body  { margin: 0; color: var(--ink-2); font-size: 14px; }
.status-body strong { color: var(--ink); }

.status-observe  { border-left: 4px solid var(--info); }
.status-observe  .status-icon { background: var(--info-soft); color: var(--info); }
.status-assisted { border-left: 4px solid var(--warn); }
.status-assisted .status-icon { background: var(--warn-soft); color: var(--warn); }
.status-auto     { border-left: 4px solid var(--good); }
.status-auto     .status-icon { background: var(--good-soft); color: var(--good); }
.status-paused   { border-left: 4px solid var(--bad); }
.status-paused   .status-icon { background: var(--bad-soft); color: var(--bad); }

/* --- stat cards --------------------------------------------------------- */
.cards {
  display: grid; gap: 14px; margin: 0 0 26px;
  grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
}
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 18px 16px;
  display: flex; flex-direction: column; gap: 2px;
  box-shadow: var(--shadow); color: inherit;
}
a.card { transition: transform .12s ease, box-shadow .12s ease; }
a.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); text-decoration: none; }

.card .n { font-size: 32px; font-weight: 680; line-height: 1.1; letter-spacing: -.02em; }
.card .l { font-size: 13px; color: var(--ink-3); font-weight: 550; }
.card .sub { font-size: 12px; color: var(--ink-3); margin-top: 6px; }

/* "Needs you" is the only card that is ever an action, so it is the only one
   that carries brand colour. */
.card.need { border-color: var(--brand-line); background: var(--brand-soft); }
.card.need .n { color: var(--brand-ink); }
.card.need .l { color: var(--brand-ink); font-weight: 650; }
.card.bad  { border-color: var(--bad); }
.card.bad .n { color: var(--bad); }

/* --- panels and tables -------------------------------------------------- */
.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 20px; margin: 0 0 20px;
  box-shadow: var(--shadow);
}
.panel-pause { border-left: 4px solid var(--warn); }

.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }

table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 11px 14px; text-align: left; vertical-align: top; }
thead th {
  background: var(--surface-2); color: var(--ink-3);
  font-size: 11px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
tbody tr + tr td { border-top: 1px solid var(--line); }
tbody tr:hover td { background: var(--surface-2); }
td .subj { font-weight: 550; color: var(--ink); }
td .from { color: var(--ink-3); font-size: 13px; }
td.nowrap, th.nowrap { white-space: nowrap; }

.empty {
  text-align: center; padding: 44px 20px; color: var(--ink-3);
  background: var(--surface); border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
}
.empty .big { font-size: 30px; display: block; margin-bottom: 8px; }

/* --- forms -------------------------------------------------------------- */
.field { margin: 0 0 20px; }
.field > label {
  display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; color: var(--ink);
}

input[type=text], input[type=password], input[type=email], input[type=number],
input[type=search], select, textarea {
  width: 100%; padding: 9px 12px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  font: inherit; font-size: 14px;
}
textarea { resize: vertical; min-height: 96px; font-family: var(--mono); font-size: 13px; line-height: 1.55; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(255,98,0,.16);
}
input::placeholder, textarea::placeholder { color: var(--ink-3); }

.help { font-size: 13px; color: var(--ink-3); margin: 6px 0 0; line-height: 1.5; }

.check { display: flex; align-items: flex-start; gap: 9px; font-size: 14px; margin: 0 0 6px; cursor: pointer; }
.check input { margin-top: 3px; accent-color: var(--brand); flex: none; }
.checks { display: grid; gap: 4px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

.group-heading {
  margin: 34px 0 14px; padding-bottom: 8px;
  border-bottom: 2px solid var(--line);
  font-size: 12px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--ink-3);
}

/* --- buttons ------------------------------------------------------------ */
button, .btn {
  font: inherit; font-size: 14px; font-weight: 600;
  padding: 9px 18px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  cursor: pointer; display: inline-flex; align-items: center; gap: 7px;
  transition: background .12s ease, border-color .12s ease;
}
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }

button.primary, .btn.primary {
  background: var(--brand); border-color: var(--brand); color: #fff;
  box-shadow: 0 1px 2px rgba(199,75,0,.28);
}
button.primary:hover, .btn.primary:hover { background: var(--brand-ink); border-color: var(--brand-ink); }

button.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
button.danger:hover { background: var(--bad-soft); }

button.link {
  background: none; border: none; padding: 4px 8px;
  color: var(--ink-2); font-weight: 550; text-decoration: none;
}
button.link:hover { color: var(--ink); background: var(--surface-2); }

.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 22px; }
form.inline { display: inline; }

/* --- flash -------------------------------------------------------------- */
.flash {
  padding: 12px 16px; border-radius: var(--radius-sm); margin: 0 0 16px;
  background: var(--info-soft); color: var(--info);
  border: 1px solid currentColor; font-size: 14px;
}
.flash a { color: inherit; text-decoration: underline; font-weight: 600; }
.flash-err { background: var(--bad-soft); color: var(--bad); }
.flash-ok  { background: var(--good-soft); color: var(--good); }

/* --- message detail ----------------------------------------------------- */
.meta { display: grid; gap: 10px 26px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin: 0 0 18px; }
.meta div { min-width: 0; }
.meta dt { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); font-weight: 650; }
.meta dd { margin: 2px 0 0; font-size: 14px; word-break: break-word; }

.emailbody {
  white-space: pre-wrap; word-wrap: break-word;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 15px 17px;
  font-family: var(--mono); font-size: 13px; line-height: 1.6;
  max-height: 460px; overflow: auto;
}

/* A confidence number means nothing to a non-technical reader on its own, so
   it is always drawn as a bar against the threshold that governs it. */
.conf { display: flex; align-items: center; gap: 10px; }
.conf-track { flex: 1 1 auto; height: 7px; border-radius: 4px; background: var(--line); position: relative; overflow: hidden; max-width: 220px; }
.conf-fill { position: absolute; inset: 0 auto 0 0; border-radius: 4px; background: var(--good); }
.conf-fill.low { background: var(--warn); }
.conf-num { font-variant-numeric: tabular-nums; font-weight: 650; font-size: 13px; }

.logbox {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; font-family: var(--mono); font-size: 12.5px; line-height: 1.65;
  max-height: 560px; overflow: auto; white-space: pre-wrap; word-break: break-word;
}

/* --- login -------------------------------------------------------------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 372px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 16px; padding: 34px 30px;
  box-shadow: var(--shadow-lift);
}
.login-card .brand { justify-content: center; margin-bottom: 6px; }
.login-card .brand img { height: 30px; }
.login-card h1 { font-size: 17px; text-align: center; margin-bottom: 22px; color: var(--ink-2); font-weight: 550; }
.login-card button { width: 100%; justify-content: center; margin-top: 4px; }
.login-foot { text-align: center; margin-top: 18px; font-size: 12px; color: var(--ink-3); }

@media print {
  .bar, .actions, form { display: none; }
  body { background: #fff; }
}

/* Confidence bar widths. Classes rather than inline styles because the CSP
   is style-src 'self' - an inline style attribute would be blocked. */
.conf-fill.w0 { width: 0%; }
.conf-fill.w5 { width: 5%; }
.conf-fill.w10 { width: 10%; }
.conf-fill.w15 { width: 15%; }
.conf-fill.w20 { width: 20%; }
.conf-fill.w25 { width: 25%; }
.conf-fill.w30 { width: 30%; }
.conf-fill.w35 { width: 35%; }
.conf-fill.w40 { width: 40%; }
.conf-fill.w45 { width: 45%; }
.conf-fill.w50 { width: 50%; }
.conf-fill.w55 { width: 55%; }
.conf-fill.w60 { width: 60%; }
.conf-fill.w65 { width: 65%; }
.conf-fill.w70 { width: 70%; }
.conf-fill.w75 { width: 75%; }
.conf-fill.w80 { width: 80%; }
.conf-fill.w85 { width: 85%; }
.conf-fill.w90 { width: 90%; }
.conf-fill.w95 { width: 95%; }
.conf-fill.w100 { width: 100%; }

/* --- branding controls -------------------------------------------------- */
.swatch { align-items: center; }
.swatch-dot { width: 16px; height: 16px; border-radius: 50%; display: inline-block;
  border: 1px solid rgba(0,0,0,.15); flex: none; }
.sw-current { background: var(--brand); }
.sw-current-ink { background: var(--brand-ink); }
.sw-orange   { background: #FF6200; }
.sw-blue     { background: #2563EB; }
.sw-teal     { background: #0D9488; }
.sw-green    { background: #16A34A; }
.sw-purple   { background: #7C3AED; }
.sw-red      { background: #DC2626; }
.sw-slate    { background: #475569; }
.sw-custom   { background: #FF6200; }
.asset-preview { display: flex; align-items: center; gap: 16px; margin: 0 0 8px;
  background: var(--surface-2); }
.asset-logo { max-height: 42px; max-width: 260px; width: auto; display: block; }
.asset-favicon { width: 32px; height: 32px; object-fit: contain; display: block; }
input[type=file] { width: 100%; padding: 9px 12px; font: inherit; font-size: 14px;
  background: var(--surface); color: var(--ink);
  border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); }

.asset-preview.on-brand { background: var(--brand); border-color: var(--brand); }
.on-brand-text { color: #fff; opacity: .85; font-size: 13px; }

/* --- icons --------------------------------------------------------------- */
.ico { width: 18px; height: 18px; flex: none; vertical-align: -3px; }
.bar nav .ico { width: 17px; height: 17px; }
.check .ico, .help .ico { width: 15px; height: 15px; }

/* --- tabs ---------------------------------------------------------------- */
/* Radio inputs and sibling selectors. There is no JavaScript on this site. */
.tabradio { position: absolute; opacity: 0; pointer-events: none; }
.tabs {
  display: flex; gap: 4px; flex-wrap: wrap;
  border-bottom: 1px solid var(--line); margin: 0 0 22px; padding-bottom: 0;
}
.tab {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  padding: 10px 15px; font-size: 14px; font-weight: 550; color: var(--ink-3);
  border: 1px solid transparent; border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  margin-bottom: -1px; white-space: nowrap;
}
.tab:hover { color: var(--ink); background: var(--surface-2); }
.tabpanel { display: none; }

/* One rule per tab: highlight its label and reveal its panel. */
#tab-behaviour:checked ~ .tabs .tab[for="tab-behaviour"] { color: var(--brand-ink); background: var(--surface); border-color: var(--line); border-bottom: 1px solid var(--surface); }
#tab-behaviour:checked ~ #panel-behaviour { display: block; }
#tab-filtering:checked ~ .tabs .tab[for="tab-filtering"] { color: var(--brand-ink); background: var(--surface); border-color: var(--line); border-bottom: 1px solid var(--surface); }
#tab-filtering:checked ~ #panel-filtering { display: block; }
#tab-branding:checked ~ .tabs .tab[for="tab-branding"] { color: var(--brand-ink); background: var(--surface); border-color: var(--line); border-bottom: 1px solid var(--surface); }
#tab-branding:checked ~ #panel-branding { display: block; }
#tab-alert-email:checked ~ .tabs .tab[for="tab-alert-email"] { color: var(--brand-ink); background: var(--surface); border-color: var(--line); border-bottom: 1px solid var(--surface); }
#tab-alert-email:checked ~ #panel-alert-email { display: block; }
#tab-api-keys:checked ~ .tabs .tab[for="tab-api-keys"] { color: var(--brand-ink); background: var(--surface); border-color: var(--line); border-bottom: 1px solid var(--surface); }
#tab-api-keys:checked ~ #panel-api-keys { display: block; }
#tab-identity:checked ~ .tabs .tab[for="tab-identity"] { color: var(--brand-ink); background: var(--surface); border-color: var(--line); border-bottom: 1px solid var(--surface); }
#tab-identity:checked ~ #panel-identity { display: block; }
#tab-outgoing-mail:checked ~ .tabs .tab[for="tab-outgoing-mail"] { color: var(--brand-ink); background: var(--surface); border-color: var(--line); border-bottom: 1px solid var(--surface); }
#tab-outgoing-mail:checked ~ #panel-outgoing-mail { display: block; }

/* Keyboard focus must be visible even though the radio itself is hidden. */
.tabradio:focus-visible ~ .tabs .tab { outline: none; }
.tabradio#tab-behaviour:focus-visible ~ .tabs .tab[for="tab-behaviour"] { outline: 2px solid var(--brand); outline-offset: -2px; }
.tabradio#tab-filtering:focus-visible ~ .tabs .tab[for="tab-filtering"] { outline: 2px solid var(--brand); outline-offset: -2px; }
.tabradio#tab-branding:focus-visible ~ .tabs .tab[for="tab-branding"] { outline: 2px solid var(--brand); outline-offset: -2px; }
.tabradio#tab-alert-email:focus-visible ~ .tabs .tab[for="tab-alert-email"] { outline: 2px solid var(--brand); outline-offset: -2px; }
.tabradio#tab-api-keys:focus-visible ~ .tabs .tab[for="tab-api-keys"] { outline: 2px solid var(--brand); outline-offset: -2px; }
.tabradio#tab-identity:focus-visible ~ .tabs .tab[for="tab-identity"] { outline: 2px solid var(--brand); outline-offset: -2px; }
.tabradio#tab-outgoing-mail:focus-visible ~ .tabs .tab[for="tab-outgoing-mail"] { outline: 2px solid var(--brand); outline-offset: -2px; }

/* --- inputs with a leading icon ------------------------------------------ */
.input-icon { position: relative; display: block; }
.input-icon .ico {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--ink-3); pointer-events: none;
}
.input-icon input, .input-icon select { padding-left: 40px; }
.input-icon input:focus ~ .ico { color: var(--brand); }

/* --- sticky save --------------------------------------------------------- */
/* The settings form is long; the save button should not require scrolling. */

button .ico, .btn .ico { margin-right: -2px; }


.ico-lg { width: 22px; height: 22px; }
.ico-xl { width: 34px; height: 34px; opacity: .55; }
.empty .big { display: block; margin-bottom: 10px; }
.bar nav a span, .tab span { display: inline-block; }
button.link { gap: 6px; }

/* --- layout corrections -------------------------------------------------- */
/* Six nav items plus the brand and the mode pill wrapped onto a second row
   at common laptop widths. Tightening the nav keeps it on one line without
   shrinking the text below a comfortable size. */
.bar-inner { gap: 18px; }
.bar nav { gap: 0; }
.bar nav a { padding: 8px 11px; gap: 6px; }
.brand .brand-sub { padding-left: 10px; }
/* The account button added width to the right-hand group, which pushed the
   last nav item under the overflow and clipped it. The wordmark subtitle is
   the least useful thing in the bar, so it yields first. */
@media (max-width: 1400px) { .brand .brand-sub { display: none; } }

/* The sticky save bar floats over the form, so the form needs room beneath
   its last field or that field sits permanently behind the button. */

/* The nav must never wrap: a second row pushes the page content down and
   makes the header look broken. It scrolls horizontally instead on the
   rare width where it genuinely cannot fit. */
.bar nav { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.bar nav::-webkit-scrollbar { display: none; }

/* A translucent sticky bar lets text show through from behind, which reads
   as a rendering fault. Solid, with a top edge, so it is clearly a layer. */
.tabpanel { padding-bottom: 24px; }

/* nowrap on the container stops the row breaking, but each item must also
   refuse to break internally or "Needs you" becomes two lines. */
.bar nav a { white-space: nowrap; }
.tab { white-space: nowrap; }

/* Match the content column rather than bleeding past it. */
/* One save bar, pinned to the bottom of the viewport. Solid rather than
   translucent: text showing through from behind reads as a rendering fault. */
.sticky-save {
  position: sticky; bottom: 0; z-index: 5;
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -4px 16px rgba(16,24,32,.06);
  margin: 0; padding: 14px 20px;
}

#tab-account:checked ~ .tabs .tab[for="tab-account"] { color: var(--brand-ink); background: var(--surface); border-color: var(--line); border-bottom: 1px solid var(--surface); }
#tab-account:checked ~ #panel-account { display: block; }
.tabpanel h2 { margin-top: 0; display: flex; align-items: center; gap: 9px; }

/* --- account button in the bar ------------------------------------------- */
.iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  color: var(--ink-2); border: 1px solid transparent; flex: none;
}
.iconbtn:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
/* Visible label for screen readers only - the icon alone is not a name. */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden;
      clip: rect(0 0 0 0); white-space: nowrap; }

/* The save bar belongs to the settings form. On the Account tab the only
   action is Change password, and a second primary button there implies
   the password is saved by the wrong one. */
#tab-account:checked ~ .sticky-save { display: none; }

/* --- per-row quick actions ----------------------------------------------- */
.rowactions { text-align: right; white-space: nowrap; }
.rowactions button { padding: 4px 9px; font-size: 13px; }
/* Delete is destructive, so it reads as such - but quietly, since it sits
   on every row and a wall of red would drown the actual warnings. */
.danger-link { color: var(--ink-3); }
.danger-link:hover { color: var(--bad); background: var(--bad-soft); }
tbody tr:hover .rowactions button { opacity: 1; }
.rowactions button { opacity: .65; transition: opacity .12s ease; }

/* --- row actions: icons with a hover label -------------------------------- */
/* The label is a CSS pseudo-element, not a title attribute: native tooltips
   take about a second to appear and cannot be styled. It sits to the LEFT
   of the icon because the table lives in an overflow container, and a
   tooltip drawn above or to the right would be clipped by it. */
.iconaction {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; padding: 0; margin-left: 2px;
  background: none; border: 1px solid transparent; border-radius: var(--radius-sm);
  color: var(--ink-3); cursor: pointer; opacity: .7;
  transition: opacity .12s ease, color .12s ease, background .12s ease;
}
tbody tr:hover .iconaction { opacity: 1; }
.iconaction .ico { width: 17px; height: 17px; }

.iconaction::after {
  content: attr(data-label);
  position: absolute; right: calc(100% + 6px); top: 50%; transform: translateY(-50%);
  background: var(--ink); color: var(--surface);
  font-size: 12px; font-weight: 600; line-height: 1; white-space: nowrap;
  padding: 6px 9px; border-radius: 6px;
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .12s ease;
}
.iconaction:hover::after, .iconaction:focus-visible::after { opacity: 1; visibility: visible; }

/* Colour carries the meaning: dismiss is a filing action, delete destroys. */
.act-dismiss:hover { color: var(--info); background: var(--info-soft); border-color: var(--info); }
.act-delete:hover  { color: var(--bad);  background: var(--bad-soft);  border-color: var(--bad); }
.act-dismiss:hover::after { background: var(--info); }
.act-delete:hover::after  { background: var(--bad); }

#tab-housekeeping:checked ~ .tabs .tab[for="tab-housekeeping"] { color: var(--brand-ink); background: var(--surface); border-color: var(--line); border-bottom: 1px solid var(--surface); }
#tab-housekeeping:checked ~ #panel-housekeeping { display: block; }

#tab-costs:checked ~ .tabs .tab[for="tab-costs"] { color: var(--brand-ink); background: var(--surface); border-color: var(--line); border-bottom: 1px solid var(--surface); }
#tab-costs:checked ~ #panel-costs { display: block; }

/* The costs page filters with links rather than radios, so its tabs need the
   selected state applied directly. */
a.tab { text-decoration: none; }
a.tab:hover { text-decoration: none; }
a.tab.tab-on {
  color: var(--brand-ink); background: var(--surface);
  border-color: var(--line); border-bottom: 1px solid var(--surface);
}
.card .n { word-break: break-word; }

/* =========================================================================
   RESPONSIVE
   =========================================================================
   Three widths, defined once here rather than scattered through the file:

     >= 1151px   everything inline, nav labels shown
     901-1150px  nav goes icon-only; nine items no longer fit with labels
     <= 900px    the nav collapses behind a menu button
     <= 560px    tables stop being tables

   The menu is a checkbox and a sibling selector - the same mechanism the
   settings tabs use, and for the same reason: the CSP on every response is
   script-src 'none', so there is no JavaScript to open anything with. A
   <details> element was the obvious alternative and was not used, because
   forcing its content to stay visible above the breakpoint means overriding
   UA-stylesheet behaviour that engines do not implement identically.
   ========================================================================= */

/* The toggle itself is never seen; only its label is. */
.navtoggle { position: absolute; opacity: 0; pointer-events: none; }
.navtoggle-btn { display: none; }

@media (max-width: 1150px) {
  .bar nav a span { display: none; }
  .bar nav a { padding: 8px 10px; }
  .bar nav a.on span { display: inline-block; }
}

@media (max-width: 900px) {
  .bar-inner { flex-wrap: wrap; gap: 12px; padding: 8px 16px; min-height: 56px; }
  /* Menu button last, hard against the right edge - where a thumb reaches it
     without crossing the screen. The auto margin sits on the group before it
     so the two are pushed across together; the button itself never shrinks and
     never wraps, because it is the only way back to the rest of the site. */
  .brand { order: 1; }
  .bar-right { order: 2; margin-left: auto; min-width: 0; }
  .navtoggle-btn { order: 3; flex: none; }
  .bar nav { order: 4; }

  /* The word beside the logout icon is the least useful thing in the bar and
     the easiest 60px to find. Hidden from here down, not just on a phone, so
     the menu button always has room. The button keeps its aria-label. */
  .bar-right .link span { display: none; }
  .bar-right { gap: 6px; }

  /* A hamburger drawn in CSS: no icon file, no extra request, and it inherits
     currentColor so it works in both themes. */
  .navtoggle-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 42px; height: 42px; flex: none; cursor: pointer;
    border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
    color: var(--ink-2);
  }
  .navtoggle-btn:hover { background: var(--surface-2); color: var(--ink); }
  .navtoggle-bars, .navtoggle-bars::before, .navtoggle-bars::after {
    display: block; width: 18px; height: 2px; border-radius: 2px;
    background: currentColor; content: "";
  }
  .navtoggle-bars { position: relative; }
  .navtoggle-bars::before { position: absolute; top: -6px; }
  .navtoggle-bars::after  { position: absolute; top: 6px; }
  /* Focus has to be visible on the label, because the input it controls is
     the thing that actually receives focus and it is invisible. */
  .navtoggle:focus-visible ~ .navtoggle-btn { outline: 2px solid var(--brand); outline-offset: 2px; }

  .bar nav {
    display: none;
    width: 100%; flex-direction: column; gap: 2px;
    padding: 6px 0 4px; margin-top: 4px;
    border-top: 1px solid var(--line);
    overflow: visible;                 /* it is a column here, nothing to scroll */
  }
  .navtoggle:checked ~ nav { display: flex; }

  /* Labels come back the moment there is a full row for each item. Hiding
     them was only ever a way to fit nine things across one bar. */
  .bar nav a { padding: 11px 12px; min-height: 44px; }
  .bar nav a span, .bar nav a.on span { display: inline-block; }
  .bar nav .navcount { margin-left: auto; }

  main { padding: 20px 16px 56px; }
  h1 { font-size: 22px; }
  .card .n { font-size: 27px; }

  /* The tab strips scroll rather than wrapping onto a second row, which would
     push the panel down and read as a broken header. */
  .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
          scroll-snap-type: x proximity; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { scroll-snap-align: start; }
}

@media (max-width: 900px) {
  /* Touch targets. 44px is the smallest a finger reliably hits, and a tablet
     is as much a touch device as a phone. */
  button, .btn { min-height: 44px; padding: 11px 18px; }
  .iconaction { width: 40px; height: 40px; opacity: 1; }
  tbody tr .iconaction { opacity: 1; }
  /* There is no hover on a touch screen, so the label would never appear.
     Each button carries an aria-label, which is what actually names it here. */
  .iconaction::after { display: none; }

  /* --- tables become cards ---------------------------------------------
     Below this width a table can only be scrolled sideways, which hides the
     column that matters behind the edge of the screen. 900 rather than a
     phone-sized figure because the message list carries nine columns: at 768,
     an iPad held upright, the last three fall off. Each row becomes a card and
     each cell carries its own heading, taken from the data-label attribute the
     views set. Nothing is hidden and nothing needs panning. */
  .tablewrap {
    overflow-x: visible; border: 0; background: none; box-shadow: none;
    border-radius: 0;
  }
  table, tbody, tr, td { display: block; width: 100%; }
  thead { display: none; }

  tbody tr {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow);
    margin: 0 0 10px; padding: 4px 0; overflow: hidden;
  }
  tbody tr:hover td { background: transparent; }
  tbody tr + tr td { border-top: 0; }

  td {
    display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap;
    padding: 8px 14px; border: 0; text-align: right;
  }
  td + td { border-top: 1px solid var(--line); }
  /* The label pushes everything else to the right with an auto margin rather
     than the cell using space-between. A cell often holds more than one thing
     - an address and a "asked for a person" pill, two action buttons - and
     space-between would spread those apart across the row instead of keeping
     them together as one value. */
  td[data-label]::before {
    content: attr(data-label);
    flex: none; text-align: left; margin-right: auto;
    color: var(--ink-3); font-size: 11px; font-weight: 650;
    letter-spacing: .06em; text-transform: uppercase;
  }
  /* nowrap exists to keep columns from breaking. There are no columns here,
     and keeping it truncates long values against the right edge instead. */
  td.nowrap, td.muted { white-space: normal; }
  td .subj, td .from { text-align: right; word-break: break-word; }
  .rowactions { text-align: right; }
  /* The bar is a flex child of .conf, which is itself a flex child of the
     cell. Without a basis of its own it collapses to nothing and the row shows
     a bare percentage - which is the one thing the bar exists to give context
     to. */
  td .conf { flex: 1 1 auto; min-width: 0; }
  .conf-track { max-width: none; }

  td.rowactions { gap: 8px; }
}

@media (max-width: 560px) {
  main { padding: 16px 12px 56px; }

  /* ⚠ 16px, not 14px. iOS Safari zooms the whole page in when a focused field
     has text smaller than 16px, and it does not zoom back out afterwards -
     which leaves the operator on a page they now have to pan sideways. This is
     the one place where the type scale gives way to the platform. */
  input[type=text], input[type=password], input[type=email], input[type=number],
  input[type=search], select, textarea { font-size: 16px; padding: 11px 12px; }
  textarea { font-size: 14px; }

  .actions { gap: 8px; }
  .actions button, .actions .btn { flex: 1 1 auto; justify-content: center; }

  .meta { grid-template-columns: 1fr; gap: 12px; }
  .group-heading { margin-top: 26px; }
  .sticky-save { padding: 12px 14px; margin: 0 -12px; border-radius: 0; }
}

/* =========================================================================
   DISCLOSURES
   =========================================================================
   <details> where it is valid, which is everywhere except inside a table row -
   a <tr> may contain only <td> and <th>, so the message list uses a checkbox
   instead (see .rowmore below). No JavaScript is involved in either.
   ========================================================================= */

summary { cursor: pointer; list-style: none; }
summary::-webkit-details-marker { display: none; }
summary:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: var(--radius-sm); }

/* One marker, drawn in CSS and rotated when open, so both engines' native
   markers can be turned off and the result looks the same in each. */
summary::after {
  content: ""; flex: none; margin-left: auto;
  width: 8px; height: 8px; border-right: 2px solid var(--ink-3); border-bottom: 2px solid var(--ink-3);
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform .15s ease;
}
details[open] > summary::after { transform: rotate(-135deg) translate(-2px, -2px); }

/* --- the mode banner on the dashboard ------------------------------------ */
.status > summary {
  display: flex; align-items: center; gap: 16px;
  padding: 16px 20px;
}
.status > summary:hover { background: var(--surface-2); }
.status .status-title { font-weight: 650; font-size: 16px; margin: 0; }
.status .status-body { margin: 0; padding: 0 20px 16px 60px; }
.status .status-icon { margin: 0; }

/* --- section headings that open and close -------------------------------- */
.disclose { margin: 0 0 4px; }
.disclose > summary { display: flex; align-items: center; gap: 10px; }
/* The heading keeps its own semantics; the summary is only the control. */
.disclose > summary h2 { margin: 0; }
.disclose > summary:hover h2 { color: var(--brand-ink); }
.disclose > summary::after { margin-left: 8px; }

/* =========================================================================
   COLLAPSIBLE MESSAGE ROWS  (card layout only)
   =========================================================================
   Five messages stacked as cards ran to several screens. Collapsed, a card
   shows what you scan by - sender, subject, status, when - and the rest opens
   on demand.
   ========================================================================= */
.rowmore { position: absolute; opacity: 0; pointer-events: none; }
.rowmore-btn { display: none; }

@media (max-width: 900px) {
  .rowmore-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; flex: none; margin-left: 8px; cursor: pointer;
    border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
    color: var(--ink-3);
  }
  .rowmore-btn:hover { background: var(--surface-2); color: var(--ink); }
  .rowmore-btn .ico { transition: transform .15s ease; }
  .rowmore:focus-visible ~ .rowmore-btn { outline: 2px solid var(--brand); outline-offset: 2px; }

  /* :has() reaches the cells that are siblings of the one holding the
     checkbox, which a sibling combinator alone cannot do. */
  tbody tr td.more { display: none; }
  tbody tr:has(.rowmore:checked) td.more { display: flex; }
  tbody tr:has(.rowmore:checked) .rowmore-btn .ico { transform: rotate(180deg); }

  /* The subject cell now holds the toggle as well. It must not wrap: with
     wrapping on, a long subject pushed the chevron onto a line of its own,
     left-aligned under the text, where it reads as a stray control rather than
     this row's. The subject shrinks instead and wraps within itself. */
  td[data-label="Subject"] { flex-wrap: nowrap; align-items: center; }
  td[data-label="Subject"] .subj { min-width: 0; }
}

/* =========================================================================
   RESPONSIVE SWEEP
   =========================================================================
   The things that only misbehave once the viewport is narrow enough, or once
   the content is real rather than tidy: a customer's 90-character URL, a
   forwarded booking confirmation, a log line with no spaces in it.
   ========================================================================= */

/* Nothing may push the page sideways. An image with intrinsic width larger
   than its column is the classic way that happens. */
img { max-width: 100%; height: auto; }

/* Inline code carries file paths and pipe commands - "|/home/USER/mailai/
   pipe.php contact@airgo.mk" is wider than a phone and has no space in it to
   break at. */
code, .mono { overflow-wrap: anywhere; }

/* Long unbroken URLs a customer pasted, and quoted-printable soup. */
.emailbody { overflow-wrap: anywhere; }

@media (max-width: 900px) {
  /* Half a phone screen of log is enough to scroll through; the box scrolls
     inside itself, so a taller one just buries whatever follows it. */
  .logbox { max-height: 320px; font-size: 12px; }

  /* The mode banner indents its body to clear the icon. At this width that
     indent costs more than the alignment is worth. */
  .status .status-body { padding-left: 20px; }
}

@media (max-width: 560px) {
  .login-wrap { padding: 16px; }
  .login-card { padding: 26px 20px; }

  /* Two counts across rather than one: five cards in a single column is a
     screen and a half before the recent messages start. */
  .cards { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .card { padding: 14px 12px; }
  .card .sub { font-size: 11px; }

  /* Section headings sit closer to their content when there is less of it. */
  h2 { font-size: 17px; }
  .panel { padding: 14px 14px; }

  /* A wide select with a long model id was widening the page on the settings
     and mailbox forms. */
  select { max-width: 100%; }
}
