/* Malek land dashboard — a quiet, modern surface for a dense dataset.
   Surfaces, ink and the status trio come from the fleet's validated data-viz
   palette; status colours are only ever used with a word beside them, never as
   the sole signal. The look is hairlines and whitespace: one weight of border,
   one radius scale, no shadows except where something genuinely floats. */
:root {
  color-scheme: light;
  --plane:     #f9f9f7;   /* page behind everything */
  --surface-1: #fcfcfb;   /* cards, table, controls */
  --surface-2: #f2f1ed;   /* hover / recessed */
  --line:      rgba(11, 11, 11, .11);
  --line-soft: rgba(11, 11, 11, .06);
  --ink:       #0b0b0b;
  --ink-2:     #52514e;
  --ink-3:     #898781;
  --accent:    #2a78d6;
  --accent-wash: rgba(42, 120, 214, .10);
  --good:      #0ca30c;
  --warning:   #fab219;
  --critical:  #d03b3b;

  --r-xs: 6px;
  --r-sm: 9px;
  --r:    13px;
  --r-lg: 18px;
  --bar:  56px;           /* height of the sticky top bar */
  --ease: cubic-bezier(.2, .6, .3, 1);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --plane:     #0d0d0d;
    --surface-1: #1a1a19;
    --surface-2: #262623;
    --line:      rgba(255, 255, 255, .12);
    --line-soft: rgba(255, 255, 255, .07);
    --ink:       #ffffff;
    --ink-2:     #c3c2b7;
    --ink-3:     #898781;
    --accent:    #3987e5;
    --accent-wash: rgba(57, 135, 229, .16);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-feature-settings: "cv05", "ss01";
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--accent-wash); }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }

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

main { padding: 1.75rem clamp(1rem, 3vw, 2.5rem) 5rem; max-width: 1920px; margin: 0 auto; }

h1 { font-size: clamp(1.5rem, 1.1rem + 1.1vw, 2rem); font-weight: 600; margin: 0 0 .3rem; letter-spacing: -.025em; line-height: 1.15; }
h2 {
  font-size: .7rem; font-weight: 600; margin: 0 0 .9rem;
  letter-spacing: .09em; text-transform: uppercase; color: var(--ink-3);
}
p.sub { margin: 0; color: var(--ink-2); font-size: .875rem; max-width: 72ch; }
p.crumb { margin: 0 0 .55rem; font-size: .8rem; }
p.crumb a { color: var(--ink-3); text-decoration: none; }
p.crumb a:hover { color: var(--ink); }

/* --- sticky top bar ------------------------------------------------------- */
.bar {
  position: sticky; top: 0; z-index: 40; height: var(--bar);
  display: flex; align-items: center; gap: .75rem;
  padding: 0 clamp(1rem, 3vw, 2.5rem);
  border-bottom: 1px solid var(--line-soft);
  background: color-mix(in srgb, var(--plane) 82%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
}
.brand { display: flex; align-items: center; gap: .6rem; text-decoration: none; color: inherit; margin-right: auto; }
.mark {
  width: 26px; height: 26px; border-radius: 8px; flex: none;
  background: var(--ink); color: var(--plane);
  display: grid; place-items: center;
  font-size: .8rem; font-weight: 700; letter-spacing: -.02em;
}
.brand b { font-weight: 600; font-size: .95rem; letter-spacing: -.015em; }
.brand em { font-style: normal; color: var(--ink-3); font-size: .95rem; }
@media (max-width: 620px) { .brand em { display: none; } }
.baract { display: flex; align-items: center; gap: .4rem; }
.baract form { display: contents; }

/* --- buttons -------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .42rem .8rem; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface-1); color: var(--ink);
  font: inherit; font-size: .82rem; font-weight: 500; cursor: pointer; text-decoration: none;
  white-space: nowrap;
  transition: background .15s var(--ease), border-color .15s var(--ease), color .15s var(--ease);
}
.btn:hover { background: var(--surface-2); border-color: var(--line); }
.btn:active { transform: translateY(.5px); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.on { background: var(--accent-wash); border-color: transparent; color: var(--accent); }

/* --- page header ---------------------------------------------------------- */
.top {
  display: flex; gap: 1.5rem; align-items: flex-end; justify-content: space-between;
  flex-wrap: wrap; margin-bottom: 1.75rem;
}
.topact { display: flex; gap: .4rem; align-items: center; }

/* --- stat strip ----------------------------------------------------------- */
.tiles {
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface-1); border: 1px solid var(--line-soft);
  border-radius: var(--r); overflow: hidden; margin-bottom: 1.5rem;
}
.tile { padding: 1rem 1.15rem; border-left: 1px solid var(--line-soft); }
.tile:first-child { border-left: 0; }
.tlab {
  display: flex; align-items: center; gap: .4rem;
  font-size: .72rem; font-weight: 500; letter-spacing: .05em; text-transform: uppercase;
  color: var(--ink-3); margin-bottom: .45rem;
}
.tlab::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; flex: none;
  background: var(--ink-3);
}
.tile.good .tlab::before { background: var(--good); }
.tile.warn .tlab::before { background: var(--warning); }
.tile.crit .tlab::before { background: var(--critical); }
.tile.live .tlab::before { background: var(--accent); }
.tnum { display: block; font-size: 1.85rem; font-weight: 600; letter-spacing: -.03em; line-height: 1; }
@media (max-width: 1000px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .tile { border-top: 1px solid var(--line-soft); }
  .tile:nth-child(-n+2) { border-top: 0; }
  .tile:nth-child(odd) { border-left: 0; }
}
/* Two across even on a phone — five stacked tiles push the table off-screen. */
@media (max-width: 520px) {
  .tile { padding: .8rem .9rem; }
  .tlab { font-size: .66rem; margin-bottom: .35rem; }
  .tnum { font-size: 1.5rem; }
}

/* --- controls ------------------------------------------------------------- */
.controls { display: flex; gap: .45rem; align-items: center; flex-wrap: wrap; margin-bottom: .9rem; }
.field {
  display: flex; align-items: center; gap: .5rem; flex: 1 1 300px; max-width: 380px;
  padding: 0 .8rem; height: 34px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface-1);
  transition: border-color .15s var(--ease), background .15s var(--ease);
}
.field:focus-within { border-color: var(--accent); background: var(--surface-1); }
.field svg { flex: none; color: var(--ink-3); }
.field input {
  flex: 1; min-width: 0; border: 0; background: none; color: var(--ink);
  font: inherit; font-size: .85rem; padding: 0;
}
.field input:focus { outline: none; }
.field input::-webkit-search-cancel-button { filter: grayscale(1) opacity(.5); }
.hint { color: var(--ink-3); font-size: .78rem; margin-left: auto; }
@media (max-width: 900px) { .hint { display: none; } }

.colpicker {
  background: var(--surface-1); border: 1px solid var(--line-soft); border-radius: var(--r);
  padding: 1.1rem 1.25rem; margin-bottom: 1rem;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem 1.5rem;
}
/* An author `display` beats the UA stylesheet's [hidden] rule, so restore it. */
.colpicker[hidden] { display: none; }
.colpicker fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.colpicker legend {
  font-size: .68rem; font-weight: 600; text-transform: uppercase; letter-spacing: .09em;
  color: var(--ink-3); padding: 0 0 .5rem;
}
.colpicker label {
  display: flex; align-items: center; gap: .5rem; font-size: .82rem;
  padding: .18rem 0; color: var(--ink-2); cursor: pointer;
}
.colpicker label:hover { color: var(--ink); }
.colpicker input[type=checkbox] { accent-color: var(--accent); width: 14px; height: 14px; margin: 0; }
.pickacts {
  grid-column: 1 / -1; display: flex; gap: .4rem;
  border-top: 1px solid var(--line-soft); padding-top: .9rem;
}

/* --- the grid ------------------------------------------------------------- */
.tablewrap {
  overflow: auto; max-height: calc(100vh - var(--bar) - 300px);
  border: 1px solid var(--line-soft); border-radius: var(--r); background: var(--surface-1);
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
}
.tablewrap::-webkit-scrollbar { width: 10px; height: 10px; }
.tablewrap::-webkit-scrollbar-thumb { background: var(--line); border-radius: 99px; border: 3px solid var(--surface-1); }
.tablewrap::-webkit-scrollbar-track { background: transparent; }

table#grid { border-collapse: separate; border-spacing: 0; width: 100%; font-size: .82rem; }
#grid thead th {
  position: sticky; background: var(--surface-1); text-align: left; z-index: 3; padding: 0;
}
#grid tr.hrow th { top: 0; }
#grid tr.frow th { top: 34px; padding: 0 .3rem .35rem; box-shadow: 0 1px 0 var(--line); }
#grid tr.hrow th:first-child, #grid tr.frow th:first-child { left: 0; z-index: 5; }
#grid tbody td:first-child {
  position: sticky; left: 0; z-index: 1; background: var(--surface-1);
}
#grid tr.frow th:first-child, #grid tbody td:first-child { box-shadow: inset -1px 0 0 var(--line-soft); }
#grid tr.frow th:first-child { box-shadow: inset -1px 0 0 var(--line-soft), 0 1px 0 var(--line); }

.sortbtn {
  display: block; width: 100%; height: 34px; text-align: left; background: none; border: 0;
  color: var(--ink-3); font: inherit; font-weight: 600; font-size: .68rem;
  letter-spacing: .07em; text-transform: uppercase;
  padding: 0 .55rem; cursor: pointer; white-space: nowrap;
  transition: color .15s var(--ease);
}
.sortbtn:hover { color: var(--ink); }
.sortbtn[data-active] { color: var(--ink); }
.sortbtn .arrow { color: var(--accent); font-size: .7em; margin-left: .25em; }

.fcell input, .fcell select {
  width: 100%; padding: .25rem .45rem; font: inherit; font-size: .76rem;
  border: 1px solid transparent; border-radius: var(--r-xs);
  background: var(--surface-2); color: var(--ink);
  transition: border-color .15s var(--ease);
}
.fcell input::placeholder { color: var(--ink-3); }
.fcell input:focus, .fcell select:focus { outline: none; border-color: var(--accent); }
/* A multi-select column filter: a button in the header, its checkbox list
   pinned to the viewport so the grid's scroll box cannot clip it. */
.fcell button.multi {
  display: flex; align-items: center; justify-content: space-between; gap: .25rem;
  width: 100%; padding: .25rem .45rem; font: inherit; font-size: .76rem; cursor: pointer;
  border: 1px solid transparent; border-radius: var(--r-xs);
  background: var(--surface-2); color: var(--ink); text-align: left;
  white-space: nowrap; overflow: hidden;
  transition: border-color .15s var(--ease), color .15s var(--ease);
}
.fcell button.multi:hover { border-color: var(--line); }
.fcell button.multi.on { background: var(--accent-wash); color: var(--accent); font-weight: 600; }
.fcell button.multi .mlab { overflow: hidden; text-overflow: ellipsis; }
.fcell button.multi .caret { color: var(--ink-3); font-size: .7em; }
.fcell button.multi.on .caret { color: var(--accent); }

.mpanel {
  position: fixed; z-index: 60; display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface-1); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: 0 10px 28px rgba(0, 0, 0, .18);
  font-size: .78rem;
}
.mpanel .mpacts {
  display: flex; gap: .75rem; padding: .4rem .6rem;
  border-bottom: 1px solid var(--line-soft);
}
.mpanel .lnk {
  background: none; border: 0; padding: 0; font: inherit; font-size: .74rem;
  color: var(--accent); cursor: pointer;
}
.mpanel .lnk:hover { text-decoration: underline; }
.mpanel .mopts { overflow: auto; min-height: 0; padding: .2rem 0; scrollbar-width: thin; }
.mpanel label {
  display: flex; align-items: center; gap: .45rem; padding: .22rem .6rem; cursor: pointer;
}
.mpanel label:hover { background: var(--surface-2); }
.mpanel input[type=checkbox] { accent-color: var(--accent); width: 14px; height: 14px; margin: 0; }
.mpanel .mval { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.mpanel .mct { color: var(--ink-3); font-variant-numeric: tabular-nums; }

.fcell .range { display: flex; gap: .25rem; }
.fcell .range input { width: 50%; min-width: 0; }
/* The spinners eat the width the min/max placeholders need. */
.fcell input[type=number] { -moz-appearance: textfield; appearance: textfield; }
.fcell input[type=number]::-webkit-outer-spin-button,
.fcell input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* One line per row. A dense grid is only readable if the rows are the same
   height, so long values truncate and carry the whole string in `title`. */
#grid tbody td {
  padding: .5rem .55rem; border-bottom: 1px solid var(--line-soft);
  max-width: 320px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#grid tbody tr { cursor: pointer; }
#grid tbody tr:hover td { background: var(--surface-2); }
#grid tbody tr:last-child td { border-bottom: 0; }
#grid td.t-num { text-align: right; font-variant-numeric: tabular-nums; }
#grid td.addr a { font-weight: 500; text-decoration: none; color: var(--ink); }
#grid tbody tr:hover td.addr a { color: var(--accent); }
.nil { color: var(--ink-3); }
.yes { color: var(--ink); font-weight: 500; }
.no  { color: var(--ink-3); }

/* Status is a word first; the dot is only its echo. */
.pill {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .1rem .5rem .1rem .4rem; border-radius: 999px;
  font-size: .72rem; font-weight: 500; white-space: nowrap;
  background: var(--surface-2); color: var(--ink-2);
}
.pill::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--ink-3); flex: none; }
.pill.presented::before, .pill.act-keep::before   { background: var(--good); }
.pill.held_back::before, .pill.act-verify::before { background: var(--warning); }
.pill.removed::before,  .pill.act-drop::before    { background: var(--critical); }

.empty { color: var(--ink-3); padding: 2.5rem 0; text-align: center; font-size: .9rem; }

/* --- detail page ---------------------------------------------------------- */
.badges { display: flex; flex-wrap: wrap; gap: .35rem; margin: .9rem 0 0; }
.badge {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .2rem .65rem; border-radius: 999px; border: 1px solid var(--line);
  font-size: .78rem; color: var(--ink-2); background: var(--surface-1);
}
.badge b { font-weight: 600; color: var(--ink); }
.badge.good, .badge.warn, .badge.crit { border-color: transparent; background: var(--surface-2); color: var(--ink); font-weight: 500; }
.badge.good::before, .badge.warn::before, .badge.crit::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; flex: none;
}
.badge.good::before { background: var(--good); }
.badge.warn::before { background: var(--warning); }
.badge.crit::before { background: var(--critical); }

.headline {
  font-size: 1.05rem; line-height: 1.45; color: var(--ink); letter-spacing: -.01em;
  border-left: 2px solid var(--accent); padding: .15rem 0 .15rem 1rem;
  margin: 0 0 1.5rem; max-width: 80ch;
}
.shots { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; margin-bottom: .75rem; }
.shots figure {
  margin: 0; background: var(--surface-1); border: 1px solid var(--line-soft);
  border-radius: var(--r); overflow: hidden;
}
.shots a { display: block; overflow: hidden; }
.shots img {
  width: 100%; height: auto; display: block; background: var(--surface-2);
  transition: transform .4s var(--ease);
}
.shots a:hover img { transform: scale(1.02); }
.shots figcaption { font-size: .76rem; color: var(--ink-3); padding: .6rem .8rem; line-height: 1.4; }
.links { font-size: .82rem; margin: 0 0 1.75rem; display: flex; gap: .4rem; flex-wrap: wrap; }

/* Multi-column rather than a grid: the field groups are wildly uneven in
   length, and a grid leaves half of every row empty. */
.cards { columns: 370px; column-gap: 1rem; }
.card {
  background: var(--surface-1); border: 1px solid var(--line-soft);
  border-radius: var(--r); padding: 1.1rem 1.25rem;
  break-inside: avoid; margin-bottom: 1rem;
}
.card p { margin: 0 0 .5rem; color: var(--ink-2); max-width: 80ch; }
.card p:last-child { margin-bottom: 0; }
.caveat { font-size: .875rem; color: var(--ink-3) !important; }

table.kv { width: 100%; border-collapse: collapse; font-size: .84rem; }
table.kv th {
  text-align: left; font-weight: 400; color: var(--ink-3);
  padding: .4rem 1rem .4rem 0; vertical-align: top; width: 44%;
}
table.kv td { padding: .4rem 0; vertical-align: top; word-break: break-word; }
table.kv tr + tr th, table.kv tr + tr td { border-top: 1px solid var(--line-soft); }
.q {
  display: inline-grid; place-items: center; margin-left: .35rem;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--surface-2); color: var(--ink-3); font-size: .62rem; cursor: help;
}
ul.vlist { margin: 0; padding-left: 1.05rem; }
ul.vlist li { padding: .05rem 0; }
pre.json {
  margin: 0; font-size: .76rem; white-space: pre-wrap; word-break: break-word;
  color: var(--ink-2); background: var(--surface-2); padding: .5rem .6rem; border-radius: var(--r-xs);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* --- login ---------------------------------------------------------------- */
body.bare { background: var(--plane); }
body.bare main { display: grid; place-items: center; min-height: 100vh; padding: 1.5rem; }
body.bare::before {
  content: ""; position: fixed; inset: 0; pointer-events: none;
  background: radial-gradient(60rem 40rem at 50% -10%, var(--accent-wash), transparent 70%);
}
.login {
  position: relative; background: var(--surface-1); border: 1px solid var(--line-soft);
  border-radius: var(--r-lg); padding: 2rem; width: min(24rem, 100%);
}
.login .mark { width: 32px; height: 32px; border-radius: 10px; font-size: .95rem; margin-bottom: 1.2rem; }
.login h1 { font-size: 1.25rem; letter-spacing: -.02em; }
.login label {
  display: block; font-size: .72rem; font-weight: 500; letter-spacing: .05em;
  text-transform: uppercase; color: var(--ink-3); margin: 1.5rem 0 .4rem;
}
.login input {
  width: 100%; padding: .6rem .8rem; border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--plane); color: var(--ink); font: inherit;
  transition: border-color .15s var(--ease);
}
.login input:focus { outline: none; border-color: var(--accent); }
.login button {
  width: 100%; margin-top: 1.1rem; padding: .62rem; border-radius: 999px;
  border: 1px solid transparent; background: var(--ink); color: var(--plane);
  font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer;
  transition: opacity .15s var(--ease);
}
.login button:hover { opacity: .88; }
.login .err {
  color: var(--critical); font-size: .82rem; margin: 1rem 0 0;
  display: flex; align-items: center; gap: .4rem;
}
.login .err::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--critical); flex: none; }

@media (max-width: 720px) {
  main { padding-top: 1.25rem; }
  .tablewrap { max-height: calc(100vh - var(--bar) - 340px); }
  .cards { columns: 1; }
  .top { align-items: flex-start; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  .shots a:hover img { transform: none; }
}
