/**
 * The design system: tokens and components every page shares.
 *
 * WHY THIS EXISTS
 *
 * Each page used to carry its own copy of the colour tokens and its own idea
 * of what a card, a table or a status pill looked like. Nine pages meant nine
 * slightly different apps, and the whole thing read as flat and lifeless:
 * grey text on white, no colour carrying meaning, numbers that did not stand
 * out from prose.
 *
 * Loaded BEFORE a page's own <style>, so a page can still override — but a
 * page that overrides a token is now a page that has drifted, and the fix is
 * to delete the override, not to add another.
 *
 * COLOUR MEANS SOMETHING
 *
 * Green is good or neutral-positive, amber needs attention, red is a problem,
 * blue is money, navy is chrome. Nothing is coloured for decoration alone:
 * on a screen where everything is vivid, nothing is.
 */

:root {
  /* ---- chrome ---- */
  --navy:        #0d2137;
  --navy-2:      #16324f;
  --navy-3:      #1e4066;

  /* ---- brand: the tenant's own colour lands on --brand at runtime ---- */
  --brand:       #1c5a2b;
  --brand-2:     #2e7d32;
  --brand-light: #4caf50;
  --brand-accent:#76c442;
  --brand-pale:  #e8f5e9;
  --brand-pale2: #f1f8e9;
  --on-brand:    #ffffff;

  /* ---- meaning ---- */
  --ok:        #15803d;  --ok-bg:     #e8f5e9;  --ok-line:   #bbe7c4;
  --warn:      #b45309;  --warn-bg:   #fef3c7;  --warn-line: #f5dba0;
  --bad:       #b91c1c;  --bad-bg:    #fee2e2;  --bad-line:  #f5c2c2;
  --info:      #1565c0;  --info-bg:   #e3f0ff;  --info-line: #c3ddfa;
  --money:     #1565c0;  --money-bg:  #eff6ff;
  --gold:      #f59e0b;
  --orange:    #f97316;

  /* ---- neutrals ---- */
  --canvas:    #f5f7f6;
  --panel:     #ffffff;
  --panel-2:   #f1f5f4;
  --ink:       #16201a;
  --ink-2:     #475569;
  --ink-3:     #64748b;
  --ink-4:     #94a3b8;
  --rule:      #e2e8f0;
  --rule-2:    #eef2f1;

  /* ---- shape ---- */
  --radius:    12px;
  --radius-sm: 9px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(13, 33, 55, .07);
  --shadow:    0 4px 16px rgba(13, 33, 55, .09);
  --shadow-lg: 0 10px 34px rgba(13, 33, 55, .14);

  /* ---- type ---- */
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  /* Figures are read, compared and added up, so they get a face where every
     digit is the same width and a 1 cannot be mistaken for a 7. */
  --mono: ui-monospace, "SF Mono", SFMono-Regular, "JetBrains Mono", "Roboto Mono", Menlo, Consolas, monospace;

  --rail: 244px;

  /* ---- compatibility with pages not yet migrated ---- */
  --surface: var(--canvas);
  --brand-d: #12401e;
}

* { box-sizing: border-box; }

/* `hidden` has to mean hidden.
   The attribute is display:none in the browser's own stylesheet, which ANY
   author rule outranks — so `.field { display: flex }` quietly un-hid every
   `<label class="field" hidden>` on every page, and a form showed the field
   for the option you had not chosen. Found on the asset form, true everywhere. */
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--canvas); color: var(--ink);
  font: 15px/1.55 var(--sans);
  -webkit-text-size-adjust: 100%;
}
a { color: var(--brand-2); }

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

.ui-wrap { max-width: 1320px; margin: 0 auto; padding: 20px 20px 72px; }
.ui-wrap.narrow { max-width: 820px; }

/* Page heading: what this is, one line on why, and the page's own controls. */
.ui-head { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; margin: 2px 0 18px; }
.ui-head h1 { font-size: 1.5rem; letter-spacing: -.02em; margin: 0; color: var(--navy); }
.ui-head p { margin: 3px 0 0; color: var(--ink-3); font-size: 13.5px; max-width: 72ch; }
.ui-head .ui-head-tools { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.grid    { display: grid; gap: 14px; margin-bottom: 14px; }
.grid-2  { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3  { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2-1{ grid-template-columns: 2fr minmax(0, 1fr); }
.grid-1-2{ grid-template-columns: minmax(0, 1fr) 2fr; }
@media (max-width: 900px) {
  .grid-2, .grid-3, .grid-2-1, .grid-1-2 { grid-template-columns: minmax(0, 1fr); }
}

/* --------------------------------------------------------------- card -- */

.card {
  background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); padding: 16px 18px; min-width: 0;
}
.card.pad-0 { padding: 0; }
.card-head { display: flex; align-items: center; gap: 10px; margin: -2px 0 12px; }
.card-head h2, .card-head h3 { margin: 0; font-size: .98rem; font-weight: 700; color: var(--navy); }
.card-head .sub { font-size: 12px; color: var(--ink-3); font-weight: 500; }
.card-tools { margin-left: auto; display: flex; gap: 6px; align-items: center; }

/* ---------------------------------------------------------------- KPI -- */

.kpi-grid { display: grid; gap: 12px; margin-bottom: 16px;
            grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.kpi {
  position: relative; overflow: hidden; background: var(--panel);
  border: 1px solid var(--rule); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); padding: 15px 16px; transition: box-shadow .18s, transform .18s;
}
.kpi:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
/* The stripe carries the meaning; the icon repeats it for anyone who cannot
   see the difference between green and amber. */
.kpi::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--ink-4); }
.kpi.is-ok::before    { background: var(--brand-light); }
.kpi.is-money::before { background: var(--money); }
.kpi.is-warn::before  { background: var(--gold); }
.kpi.is-bad::before   { background: var(--bad); }
.kpi.is-info::before  { background: var(--brand-accent); }
.kpi-icon { width: 34px; height: 34px; border-radius: var(--radius-sm); display: flex;
            align-items: center; justify-content: center; margin-bottom: 9px; color: var(--ink-2); }
.kpi.is-ok    .kpi-icon { background: var(--ok-bg);    color: var(--ok); }
.kpi.is-money .kpi-icon { background: var(--money-bg); color: var(--money); }
.kpi.is-warn  .kpi-icon { background: var(--warn-bg);  color: var(--warn); }
.kpi.is-bad   .kpi-icon { background: var(--bad-bg);   color: var(--bad); }
.kpi.is-info  .kpi-icon { background: var(--brand-pale2); color: var(--brand-2); }
.kpi-icon svg { width: 18px; height: 18px; }
.kpi-label { font-size: 10.5px; font-weight: 700; color: var(--ink-4);
             text-transform: uppercase; letter-spacing: .07em; margin-bottom: 3px; }
.kpi-value { font-family: var(--mono); font-size: 1.42rem; font-weight: 700; color: var(--navy);
             line-height: 1.1; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi-value .unit { font-size: .72em; color: var(--ink-3); font-weight: 600; margin-left: 3px; }
.kpi-sub { font-size: 12px; margin-top: 5px; color: var(--ink-3); display: flex; align-items: center; gap: 4px; }
.kpi-sub.up   { color: var(--ok); }
.kpi-sub.down { color: var(--bad); }
.kpi-sub.warn { color: var(--warn); }
.kpi a.kpi-link { position: absolute; inset: 0; }

/* --------------------------------------------------------------- pill -- */

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px;
        font-size: 11.5px; font-weight: 700; background: var(--panel-2); color: var(--ink-2);
        white-space: nowrap; }
.pill.ok   { background: var(--ok-bg);   color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad  { background: var(--bad-bg);  color: var(--bad); }
.pill.info { background: var(--info-bg); color: var(--info); }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* -------------------------------------------------------------- table -- */

.tbl-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.tbl th {
  text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-4); font-weight: 700; padding: 8px 10px; white-space: nowrap;
  border-bottom: 1.5px solid var(--rule); position: sticky; top: 0; background: var(--panel);
}
table.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--rule-2); vertical-align: top; }
table.tbl tr:last-child td { border-bottom: 0; }
table.tbl tbody tr:hover { background: var(--panel-2); }
table.tbl .num, table.tbl th.num { text-align: right; font-family: var(--mono);
                                   font-variant-numeric: tabular-nums; white-space: nowrap; }
table.tbl th.num { font-family: var(--sans); }
table.tbl .muted { color: var(--ink-3); font-size: 12.5px; }
table.tbl tr.total td { font-weight: 700; border-top: 1.5px solid var(--rule); background: var(--panel-2); }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 42px; padding: 0 15px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--rule); background: var(--panel); color: var(--ink);
  font: inherit; font-size: 14px; font-weight: 650; cursor: pointer; text-decoration: none;
  transition: .16s;
}
.btn:hover { border-color: var(--ink-4); }
.btn:focus-visible { outline: 2px solid var(--brand-2); outline-offset: 2px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: linear-gradient(135deg, var(--brand), var(--brand-2));
               border-color: transparent; color: #fff; }
.btn.primary:hover { box-shadow: 0 6px 18px rgba(28, 90, 43, .28); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--brand-2); }
.btn.small { min-height: 34px; padding: 0 11px; font-size: 13px; }
.btn.block { width: 100%; }

.chip { min-height: 34px; padding: 5px 11px; border: 1.5px solid var(--rule); border-radius: 99px;
        background: var(--panel); font: inherit; font-size: 13px; font-weight: 600;
        color: var(--ink-2); cursor: pointer; }
.chip[aria-pressed="true"] { border-color: var(--brand-2); background: var(--brand-pale); color: var(--brand); }

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

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 12.5px; font-weight: 650; color: var(--ink-2); }
input, select, textarea { font: inherit; }
.field input, .field select, .field textarea, input.ui, select.ui, textarea.ui {
  min-height: 44px; padding: 9px 11px; border: 1.5px solid var(--rule);
  border-radius: var(--radius-sm); background: var(--panel); color: var(--ink); width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus,
input.ui:focus, select.ui:focus, textarea.ui:focus {
  outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(46, 125, 50, .13);
}

/* The shared form renderer (assets/form.js) draws this markup, so its styles
   live here rather than in any one page: the console, the getting-started
   deck and the buying screen all show the same inputs. */
.ag-fields label, form.qa-form label { display: block; margin-bottom: 12px; }
label span.l { display: block; font-size: 12.5px; font-weight: 700; color: var(--ink-2); margin-bottom: 5px; }
label span.h { display: block; font-size: 12px; color: var(--ink-3); margin-top: 4px; font-weight: 400; }
.req { color: var(--bad); }
.ag-fields input[type=text], .ag-fields input[type=number], .ag-fields input[type=date],
.ag-fields select, .ag-fields textarea,
form.qa-form input[type=text], form.qa-form input[type=number], form.qa-form input[type=date],
form.qa-form select, form.qa-form textarea {
  min-height: 44px; padding: 9px 11px; border: 1.5px solid var(--rule);
  border-radius: var(--radius-sm); background: var(--panel); color: var(--ink); width: 100%;
}
.ag-fields textarea, form.qa-form textarea { min-height: 76px; }
label.bool { display: flex; gap: 10px; align-items: flex-start; }
label.bool input { width: 20px; height: 20px; margin-top: 2px; flex: none; }
label.bool span.l { margin-bottom: 0; }

/* A reference and the way to add one, side by side — because the thing you
   need is missing exactly when you need it, and leaving the page to add it is
   how people lose what they were doing. */
.withadd { display: flex; gap: 8px; align-items: stretch; }
.withadd select { flex: 1 1 auto; min-width: 0; }
button.qa { flex: 0 0 auto; background: var(--panel); border: 1.5px dashed var(--rule);
  border-radius: var(--radius-sm); color: var(--brand); font: inherit; font-size: 12.5px;
  font-weight: 700; padding: 0 11px; min-height: 44px; cursor: pointer; white-space: nowrap; }
button.qa:hover { border-color: var(--brand-2); background: var(--brand-pale); }

/* A code the app makes for you: present, but not a question. */
details.gen { margin-bottom: 12px; }
details.gen > summary { cursor: pointer; font-size: 12.5px; font-weight: 650; color: var(--ink-3);
  /* A thumb has to be able to hit it: 44px, like every other control here. */
  min-height: 44px; display: flex; align-items: center; padding: 4px 0; list-style: none; }
details.gen > summary::-webkit-details-marker { display: none; }
details.gen > summary::before { content: "+ "; font-weight: 800; }
details.gen[open] > summary::before { content: "\2212 "; }
details.gen[open] > summary { color: var(--ink-2); }

/* The inline "add one here" form, wherever it opens. */
.qa-host:not(:empty) { margin: 10px 0 14px; padding: 14px; border: 1.5px solid var(--brand-2);
  border-radius: var(--radius); background: var(--brand-pale); }
.qa-hd { font-weight: 700; color: var(--navy); margin-bottom: 10px; }
.qa-err { background: var(--bad-bg); color: var(--bad); border-radius: var(--radius-sm);
  padding: 9px 11px; margin-bottom: 10px; font-size: 13px; font-weight: 600; }
.qa-ft { display: flex; gap: 8px; flex-wrap: wrap; }

/* -------------------------------------------------------- empty state -- */

/* An empty panel must say why it is empty and what to do, or it reads as a
   bug. Every dashboard on a new tenant is empty on day one. */
.empty { text-align: center; padding: 26px 18px; color: var(--ink-3); }
.empty .icon { width: 42px; height: 42px; border-radius: 12px; background: var(--panel-2);
               display: inline-flex; align-items: center; justify-content: center;
               color: var(--ink-4); margin-bottom: 9px; }
.empty .icon svg { width: 21px; height: 21px; }
.empty b { display: block; color: var(--ink-2); font-size: 14px; margin-bottom: 3px; }
.empty p { margin: 0 auto 10px; font-size: 13px; max-width: 46ch; }

/* ------------------------------------------------------------- notice -- */

.notice { border-radius: var(--radius-sm); padding: 11px 13px; font-size: 13.5px; margin-bottom: 12px;
          border: 1px solid transparent; }
.notice.ok   { background: var(--ok-bg);   color: var(--ok);   border-color: var(--ok-line); }
.notice.warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-line); }
.notice.bad  { background: var(--bad-bg);  color: var(--bad);  border-color: var(--bad-line); }
.notice.info { background: var(--info-bg); color: var(--info); border-color: var(--info-line); }

/* -------------------------------------------------------------- misc --- */

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.small { font-size: 12.5px; }
.stack > * + * { margin-top: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* A loading placeholder that looks intentional rather than broken. */
.skel { background: linear-gradient(90deg, var(--panel-2) 25%, var(--rule-2) 37%, var(--panel-2) 63%);
        background-size: 400% 100%; animation: skel 1.3s ease infinite; border-radius: 7px;
        color: transparent !important; }
@keyframes skel { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
@media (prefers-reduced-motion: reduce) { .skel { animation: none; } }

@media print {
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
  .noprint { display: none !important; }
}
