/* RAautoPause tokens and components. Single source of truth for the whole app. */

:root {
  /* Neutrals tinted toward the RAcube blue (OKLCH hue 262, chroma 0.004-0.030). */
  --canvas:      #f2f4f9;
  --surface:     #ffffff;
  --raised:      #f9fafd;
  --line:        #e3e6ed;
  --line-strong: #cfd4dd;

  /* Text. All three tiers clear 4.5:1 on canvas, surface and raised. */
  --ink:        #19202f;
  --ink-muted:  #5d6574;
  --ink-soft:   #69707f;

  /* Accent, sampled from the RAcube mark. Actions and current state only. */
  --accent:       #214cb6;
  --accent-hover: #143ba1;
  --accent-soft:  #e8f0ff;
  --accent-line:  #c2d5f9;

  /* Status. Reserved for status. Never decoration. */
  --pos-ink:  #006f38;  --pos-bg:  #e5faeb;  --pos-line:  #b5e7c5;
  --neg-ink:  #b72121;  --neg-bg:  #ffeeeb;  --neg-line:  #ffc9c2;
  --warn-ink: #935b00;  --warn-bg: #fff1da;  --warn-line: #f7d3a2;

  /* Dense 4/8 spacing scale. */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 24px; --s6: 32px; --s7: 48px;

  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;

  --shadow-sm: 0 1px 2px rgba(25, 32, 47, .06);
  --shadow-md: 0 1px 3px rgba(25, 32, 47, .09), 0 1px 2px rgba(25, 32, 47, .05);

  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --t-fast: 120ms;
  --t-base: 180ms;

  /* Semantic stacking order. No arbitrary 999. */
  --z-sticky: 100;
  --z-overlay: 200;
  --z-dialog: 300;
}

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

/* The hidden attribute must beat component display rules like .field's flex. */
[hidden] { display: none !important; }

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

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background: var(--canvas);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

/* Numerals line up in columns and stop jittering as live values tick. */
.num, td, .kpi__value, .figures td { font-variant-numeric: tabular-nums; }

a { color: var(--accent); }
a:hover { color: var(--accent-hover); }

:where(a, button, input, select, textarea, summary):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

.skip-link {
  position: absolute; left: var(--s3); top: calc(var(--s3) * -4);
  z-index: var(--z-dialog);
  background: var(--surface); color: var(--ink);
  padding: var(--s2) var(--s3);
  border: 1px solid var(--line-strong); border-radius: var(--r-md);
  text-decoration: none; font-weight: 600;
  transition: top var(--t-fast) var(--ease-out);
}
.skip-link:focus { top: var(--s3); }

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

/* ---- Masthead ---- */

.masthead {
  position: sticky; top: 0; z-index: var(--z-sticky);
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s4);
  padding: var(--s3) var(--s5);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.masthead__brand {
  display: flex; align-items: center; gap: var(--s3);
  min-width: 0; flex: none;
}
.masthead__brand img { height: 26px; width: auto; border-radius: var(--r-sm); }
.masthead__name { font-size: 14px; font-weight: 600; letter-spacing: .1px; }
.masthead__tenant { font-size: 12px; color: var(--ink-muted); }

.masthead__nav { display: flex; align-items: center; gap: var(--s1); flex-wrap: wrap; }
.masthead__nav a {
  font-size: 13px; font-weight: 500;
  color: var(--ink-muted); text-decoration: none;
  padding: 7px 11px; border-radius: var(--r-md);
  border: 1px solid transparent;
  transition: color var(--t-fast) var(--ease-out),
              background var(--t-fast) var(--ease-out);
}
.masthead__nav a:hover { color: var(--ink); background: var(--raised); }
.masthead__nav a[aria-current="page"] {
  color: var(--accent); background: var(--accent-soft); border-color: var(--accent-line);
}

.shell { max-width: 1180px; margin: var(--s5) auto var(--s7); padding: 0 var(--s5); }

.page-head { margin: 0 0 var(--s4); }
.page-head h1 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -.01em; }
.page-head p { margin: var(--s1) 0 0; font-size: 13px; color: var(--ink-muted); }

/* ---- Panels ---- */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--s4);
}
.panel__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s3); flex-wrap: wrap;
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--line);
}
.panel__head h2 { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: .1px; }
.panel__head p { margin: 2px 0 0; font-size: 12px; color: var(--ink-muted); }
.panel__body { padding: var(--s4); }
.panel__body > :first-child { margin-top: 0; }
.panel__body > :last-child { margin-bottom: 0; }
.panel--flush .panel__body { padding: 0; }

/* ---- Buttons ---- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 34px; padding: 7px 14px;
  font: inherit; font-size: 13px; font-weight: 500;
  border-radius: var(--r-md);
  border: 1px solid var(--accent);
  background: var(--accent); color: #fff;
  cursor: pointer; text-decoration: none;
  box-shadow: var(--shadow-sm);
  transition: background var(--t-fast) var(--ease-out),
              border-color var(--t-fast) var(--ease-out),
              transform var(--t-fast) var(--ease-out);
}
.btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn:active { transform: scale(.98); }
.btn[disabled], .btn[aria-busy="true"] {
  opacity: .55; cursor: not-allowed; transform: none; box-shadow: none;
}

.btn--quiet {
  background: var(--surface); color: var(--ink); border-color: var(--line-strong);
}
.btn--quiet:hover { background: var(--raised); border-color: var(--line-strong); color: var(--ink); }

.btn--danger { background: var(--neg-ink); border-color: var(--neg-ink); }
.btn--danger:hover { background: #9c1a1a; border-color: #9c1a1a; }

.btn--sm { min-height: 30px; padding: 5px 10px; font-size: 12px; }

.btn-row { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; }

/* ---- Forms ---- */

.field { display: flex; flex-direction: column; gap: var(--s1); min-width: 0; }
.field > label, .field-label {
  font-size: 12px; font-weight: 500; color: var(--ink-muted);
}
.field__hint { font-size: 12px; color: var(--ink-soft); }
.field__error { font-size: 12px; color: var(--neg-ink); font-weight: 500; }
.field__error:empty { display: none; }

input[type="text"], input[type="password"], input[type="number"],
input:not([type]), select, textarea {
  width: 100%;
  min-height: 34px;
  padding: 7px 10px;
  font: inherit; font-size: 13px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  transition: border-color var(--t-fast) var(--ease-out),
              box-shadow var(--t-fast) var(--ease-out);
}
input::placeholder { color: var(--ink-soft); }
input:hover, select:hover, textarea:hover { border-color: var(--ink-soft); }
input[aria-invalid="true"] { border-color: var(--neg-ink); }
input[type="checkbox"] { width: auto; min-height: 0; accent-color: var(--accent); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--s3) var(--s4);
  /* Top-aligned. Bottom alignment let a hint under one input shove that
     field's label above its neighbours, so labels sat at three heights. */
  align-items: start;
}
.form-grid--full { grid-column: 1 / -1; }

/* Buttons sit beside inputs, so offset them by one label row (12px x 1.5
   line-height + the field's 4px gap) to land on the same baseline. */
.form-grid > .btn-row { padding-top: 22px; }

.checkbox-row {
  display: flex; align-items: flex-start; gap: var(--s2);
  font-size: 13px; color: var(--ink); font-weight: 500;
}

/* ---- Tables ---- */

.table-scroll { overflow-x: auto; }
.panel--flush .table-scroll { border-radius: 0 0 var(--r-lg) var(--r-lg); }

table { width: 100%; border-collapse: collapse; background: var(--surface); }
caption {
  text-align: left; padding: var(--s3) var(--s4);
  font-size: 12px; color: var(--ink-muted);
}
th, td { padding: 9px 12px; font-size: 13px; text-align: left; vertical-align: middle; }
thead th {
  position: sticky; top: 0;
  background: var(--raised);
  color: var(--ink-muted);
  font-weight: 600; font-size: 11px;
  letter-spacing: .04em; text-transform: uppercase;
  white-space: nowrap;
  border-bottom: 1px solid var(--line-strong);
}
tbody td { border-bottom: 1px solid var(--line); }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; }

.mono {
  font-family: ui-monospace, "SF Mono", "Cascadia Code", Consolas, Menlo, monospace;
  font-size: 12px; color: var(--ink-muted);
}
.trunc {
  display: inline-block; max-width: 220px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  vertical-align: bottom;
}
.trunc--wide { max-width: 320px; }

.row-actions { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; }
.row-actions form { display: contents; }

/* Person names read as one unit. Breaking "Aisha Okonkwo" across two lines
   makes a dense table look ragged and costs a row of height for nothing. */
td.name, th.name { white-space: nowrap; min-width: 11ch; }
@media (max-width: 640px) { td.name, th.name { white-space: normal; min-width: 0; } }

/* ---- Status ---- */

.status {
  display: inline-flex; align-items: center; gap: var(--s2);
  padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 500;
  border: 1px solid var(--line);
  background: var(--raised); color: var(--ink-muted);
  white-space: nowrap;
}
.status::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; flex: none;
}
.status--on   { background: var(--pos-bg);  border-color: var(--pos-line);  color: var(--pos-ink); }
.status--off  { background: var(--neg-bg);  border-color: var(--neg-line);  color: var(--neg-ink); }
.status--warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn-ink); }

/* ---- Notices ---- */

.notice {
  display: flex; gap: var(--s2);
  padding: 10px 14px; margin-bottom: var(--s3);
  font-size: 13px;
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--surface);
}
.notice--ok  { background: var(--pos-bg); border-color: var(--pos-line); color: var(--pos-ink); }
.notice--err { background: var(--neg-bg); border-color: var(--neg-line); color: var(--neg-ink); }

/* ---- Metrics ---- */

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--s3);
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s3) var(--s4) var(--s4);
  box-shadow: var(--shadow-sm);
}
.kpi__label { font-size: 12px; font-weight: 500; color: var(--ink-muted); }
.kpi__value {
  font-size: 30px; line-height: 1.15; font-weight: 600;
  letter-spacing: -.02em; margin-top: var(--s2); color: var(--ink);
}
.kpi__value--attention { color: var(--neg-ink); }
.kpi__sub { margin-top: var(--s1); font-size: 12px; color: var(--ink-soft); }

/* ---- Figures list (money, counts) ---- */

.figures { width: 100%; border-collapse: collapse; }
.figures th, .figures td { padding: 6px 0; font-size: 13px; border: none; }
.figures th {
  position: static; background: none; text-transform: none; letter-spacing: 0;
  font-size: 13px; font-weight: 400; color: var(--ink-muted); text-align: left;
}
.figures td { text-align: right; font-weight: 500; white-space: nowrap; }
.figures tr.figures__rule th, .figures tr.figures__rule td {
  border-top: 1px solid var(--line); padding-top: var(--s3);
}
.figures tr.figures__total th { font-weight: 600; color: var(--ink); }
.figures tr.figures__total td { font-weight: 600; font-size: 15px; }

/* ---- Loading and empty states ---- */

.skeleton {
  display: block; height: 10px; border-radius: 4px;
  background: linear-gradient(90deg, var(--line) 25%, var(--raised) 37%, var(--line) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.2s ease-in-out infinite;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

.empty { padding: var(--s6) var(--s4); text-align: center; }
.empty__title { font-size: 14px; font-weight: 600; color: var(--ink); }
.empty__body { margin-top: var(--s1); font-size: 13px; color: var(--ink-muted); }

.freshness {
  display: flex; gap: var(--s4); flex-wrap: wrap;
  font-size: 12px; color: var(--ink-muted);
}

@media (max-width: 760px) {
  /* Stack the masthead. Side by side, the wrapping nav rides over the brand. */
  .masthead {
    flex-direction: column; align-items: stretch;
    gap: var(--s2); padding: var(--s3) var(--s4);
  }
  .masthead__nav { justify-content: flex-start; }
  .masthead__nav a { padding: 8px 10px; }
}

@media (max-width: 640px) {
  .shell { padding: 0 var(--s4); margin-top: var(--s4); }
  .trunc { max-width: 140px; }
  .kpi__value { font-size: 26px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .skeleton { background: var(--line); }
}

@media print {
  .masthead, .btn, .btn-row, .skip-link { display: none !important; }
  .panel { border: none; box-shadow: none; }
  body { background: #fff; }
}

/* ---- Confirm dialog ---- */

dialog.confirm {
  width: min(420px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  box-shadow: 0 12px 32px rgba(25, 32, 47, .18);
  color: var(--ink);
  background: var(--surface);
}
dialog.confirm::backdrop { background: rgba(25, 32, 47, .45); }
dialog.confirm .confirm__body { padding: var(--s5) var(--s5) var(--s4); }
dialog.confirm h2 { margin: 0 0 var(--s2); font-size: 15px; font-weight: 600; }
dialog.confirm p { margin: 0; font-size: 13px; color: var(--ink-muted); }
dialog.confirm .confirm__actions {
  display: flex; justify-content: flex-end; gap: var(--s2);
  padding: var(--s3) var(--s5) var(--s5);
}
