/* ===========================================================================
   Roost — operator console
   ---------------------------------------------------------------------------
   Dark by default, light as an equal peer. The design goal is not decoration:
   it is that one glance answers "is anything wrong?", and that a screen you
   stare at for an hour stays comfortable. Hence one hero number per view,
   tabular numerals everywhere, and colour used only to carry meaning.
   =========================================================================== */

/* ---------------------------------------------------------------- fonts --- */

@font-face {
  font-family: 'Geist';
  src: url('/static/fonts/geist-latin.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: 'Geist Mono';
  src: url('/static/fonts/geist-mono-latin.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}

/* --------------------------------------------------------------- tokens --- */

:root {
  --bg:          #0A0C0E;
  --surface:     #111417;
  --surface-2:   #171B1F;
  --surface-3:   #1E2429;
  --border:      #252B31;
  --border-strong: #333B43;

  /* Text is set deliberately bright. Muted grey on black reads as unfinished. */
  --text:        #F2F5F7;
  --text-dim:    #A8B3BC;
  --text-faint:  #828F99;

  --accent:        #3E8FA3;
  --accent-strong: #52A9BE;
  --accent-quiet:  #14303A;
  --on-accent:     #04191F;

  --ok:      #4ABE8A;
  --ok-bg:   rgba(74, 190, 138, .11);
  --warn:    #D9A441;
  --warn-bg: rgba(217, 164, 65, .11);
  --danger:  #E8615C;
  --danger-bg: rgba(232, 97, 92, .11);
  --info:    #8E86E0;

  --shadow: 0 10px 34px rgba(0, 0, 0, .5);

  --sans: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, sans-serif;
  --mono: 'Geist Mono', ui-monospace, 'SF Mono', SFMono-Regular, Menlo, monospace;

  --radius:    10px;
  --radius-sm: 6px;

  --row-y: 11px;      /* overridden by density */
  --row-font: 13px;

  --ease: cubic-bezier(.22, .61, .36, 1);
}

:root[data-theme="light"] {
  --bg:          #FAFAF8;
  --surface:     #FFFFFF;
  --surface-2:   #F4F5F3;
  --surface-3:   #ECEEEB;
  --border:      #E2E5E1;
  --border-strong: #CBD0CA;

  --text:        #14181B;
  --text-dim:    #4E585F;
  --text-faint:  #606B71;

  --accent:        #2E6F7E;
  --accent-strong: #235863;
  --accent-quiet:  #E2EFF2;
  --on-accent:     #FFFFFF;

  --ok:      #23724E;
  --ok-bg:   rgba(35, 114, 78, .10);
  --warn:    #8A5D14;
  --warn-bg: rgba(138, 93, 20, .12);
  --danger:  #B23834;
  --danger-bg: rgba(178, 56, 52, .10);
  --info:    #5B51B8;

  --shadow: 0 10px 30px rgba(20, 24, 27, .12);
}

:root[data-density="compact"] { --row-y: 6px; --row-font: 12px; }

* { box-sizing: border-box; }

html { color-scheme: dark; }
:root[data-theme="light"] { color-scheme: light; }

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

/* Numbers are the point of this product; they must line up. */
.tabular, table, .stat .value, .mono, code, input, .pill { font-variant-numeric: tabular-nums; }

a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.015em; }
h1 { font-size: 19px; }
h2 { font-size: 14px; }
h3 {
  font-size: 11px; font-weight: 600; color: var(--text-faint);
  text-transform: uppercase; letter-spacing: .08em;
}

code, .mono { font-family: var(--mono); font-size: 12px; }

svg.ico { width: 16px; height: 16px; flex-shrink: 0; }
svg.ico-lg { width: 22px; height: 22px; }

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

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 216px; flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 0 14px;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}

/* ------ wordmark ------ */

.brand { display: flex; align-items: center; gap: 10px; padding: 0 16px 20px; }

.brand .mark {
  width: 26px; height: 26px; border-radius: 7px;
  background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center; flex-shrink: 0;
}

.wordmark {
  font-family: var(--mono);
  font-size: 13px; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--text);
  display: flex; align-items: center; gap: 4px; white-space: nowrap;
}
/* The hyphen is a drawn rule, so the join reads as deliberate. */
.wordmark i {
  display: block; width: 9px; height: 2px; border-radius: 1px;
  background: var(--accent); font-style: normal;
}

.nav { display: flex; flex-direction: column; gap: 2px; padding: 0 10px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-dim); font-size: 13px; font-weight: 500;
  transition: background .14s var(--ease), color .14s var(--ease);
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-quiet); color: var(--text); }
.nav a.active svg { color: var(--accent-strong); }
.nav .count {
  margin-left: auto; font-family: var(--mono); font-size: 11px;
  color: var(--text-faint); background: var(--bg);
  padding: 1px 6px; border-radius: 9px;
}

.sidebar-foot {
  margin-top: auto; padding: 14px 16px 0;
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 10px;
}
.who { font-size: 12px; color: var(--text-dim); }
.prefs { display: flex; gap: 6px; }
.prefs button {
  flex: 1; display: grid; place-items: center;
  padding: 6px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-dim); cursor: pointer;
  transition: color .14s var(--ease), border-color .14s var(--ease);
}
.prefs button:hover { color: var(--text); border-color: var(--border-strong); }

.btn.signout { width: 100%; justify-content: center; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 15px 26px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}

/* ------ status strip: answers "is anything wrong?" on every screen ------ */

.statusbar {
  display: flex; align-items: center; gap: 22px; flex-wrap: wrap;
  padding: 9px 26px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  position: sticky; top: 57px; z-index: 19;
}
.statusbar .unit { display: flex; align-items: center; gap: 7px; color: var(--text-dim); }
.statusbar .unit b { color: var(--text); font-weight: 600; font-family: var(--mono); }
.statusbar .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); flex-shrink: 0; }
.statusbar .dot.warn { background: var(--warn); }
.statusbar .dot.bad  { background: var(--danger); }
.statusbar .spacer { margin-left: auto; }

.content { padding: 24px 26px 60px; max-width: 1240px; width: 100%; }

.stack { display: flex; flex-direction: column; gap: 18px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

/* ---------------------------------------------------------------- cards --- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-head {
  padding: 13px 16px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.card-body { padding: 16px; }
.card-body.tight { padding: 0; }

.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* ------------------------------------------------------------ hero stat --- */

/* One number leads each screen. Everything else is support. */
.hero { display: flex; gap: 28px; align-items: flex-start; flex-wrap: wrap; padding: 22px 24px; }
.hero .figure { min-width: 250px; }
.hero .label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-faint); margin-bottom: 8px;
}
.hero .value {
  font-size: 48px; line-height: 1; font-weight: 600; letter-spacing: -0.035em;
  font-family: var(--mono);
}
.hero .value small {
  font-size: 20px; color: var(--text-faint); font-weight: 400; letter-spacing: -0.02em;
}
.hero .sub { font-size: 13px; color: var(--text-dim); margin-top: 10px; }
.hero .aside { flex: 1; min-width: 240px; display: flex; flex-direction: column; gap: 9px; }

.stat { padding: 15px 16px; }
.stat .label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-faint); margin-bottom: 7px;
}
.stat .value {
  font-size: 25px; font-weight: 600; letter-spacing: -0.03em;
  line-height: 1.1; font-family: var(--mono);
}
.stat .value small { font-size: 14px; color: var(--text-faint); font-weight: 400; }
.stat .sub { font-size: 12px; color: var(--text-dim); margin-top: 6px; }

.meter {
  height: 6px; background: var(--surface-3);
  border-radius: 3px; overflow: hidden; margin-top: 11px;
}
.meter > i {
  display: block; height: 100%; background: var(--accent); border-radius: 3px;
  transition: width .4s var(--ease);
}
.meter.warn > i   { background: var(--warn); }
.meter.danger > i { background: var(--danger); }

/* --------------------------------------------------------------- tables --- */

table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .07em; color: var(--text-faint);
  padding: 9px 14px; background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 2;
}
tbody td {
  padding: var(--row-y) 14px; font-size: var(--row-font);
  border-bottom: 1px solid var(--border); vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .14s var(--ease); }
tbody tr:hover { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }

/* A colour rail on the row edge makes state scannable peripherally, without
   having to read each pill. */
td.rail {
  border-left: 3px solid transparent; padding-left: 11px;
  font-family: var(--mono); color: var(--text-faint); font-size: 11px;
}
tr[data-state="succeeded"] td.rail,
tr[data-state="linked"]    td.rail { border-left-color: var(--ok); }
tr[data-state="dead"] td.rail,
tr[data-state="needs_relink"] td.rail,
tr[data-state="revoked"] td.rail   { border-left-color: var(--danger); }
tr[data-state="failed"] td.rail,
tr[data-state="blocked_quota"] td.rail,
tr[data-state="blocked_tier"] td.rail,
tr[data-state="disabled"] td.rail  { border-left-color: var(--warn); }
tr[data-state="queued"] td.rail,
tr[data-state="running"] td.rail   { border-left-color: var(--accent); }

/* --------------------------------------------------------- empty states --- */

.empty { padding: 44px 20px; text-align: center; }
.empty svg { width: 26px; height: 26px; color: var(--text-faint); margin-bottom: 10px; }
.empty p { margin: 0 0 4px; font-size: 14px; color: var(--text); font-weight: 500; }
.empty span { font-size: 13px; color: var(--text-dim); }

/* ----------------------------------------------------------------- pills --- */

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 550; white-space: nowrap;
  border: 1px solid transparent;
}
.pill::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.pill.plain::before { display: none; }
.pill.linked, .pill.succeeded { color: var(--ok); background: var(--ok-bg); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.pill.needs_relink, .pill.dead, .pill.revoked { color: var(--danger); background: var(--danger-bg); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.pill.queued, .pill.running { color: var(--accent-strong); background: var(--accent-quiet); border-color: color-mix(in srgb, var(--accent) 34%, transparent); }
.pill.failed, .pill.blocked_quota, .pill.blocked_tier, .pill.disabled { color: var(--warn); background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.pill.cancelled { color: var(--text-faint); background: var(--surface-3); border-color: var(--border); }

/* A running job should look like it is doing something. */
@media (prefers-reduced-motion: no-preference) {
  .pill.running::before { animation: breathe 1.7s ease-in-out infinite; }
  @keyframes breathe { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

  tr.changed { animation: flash 1.4s var(--ease); }
  @keyframes flash {
    from { background: var(--accent-quiet); }
    to   { background: transparent; }
  }
}

/* ----------------------------------------------------------------- forms --- */

label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; font-weight: 500; }

input[type=text], input[type=password], input[type=search], input[type=number],
input[type=datetime-local], input[type=file], textarea, select {
  width: 100%; background: var(--bg);
  border: 1px solid var(--border-strong); color: var(--text);
  border-radius: var(--radius-sm); padding: 9px 11px;
  font-size: 13px; font-family: inherit;
  transition: border-color .14s var(--ease), box-shadow .14s var(--ease);
}
textarea { resize: vertical; min-height: 150px; line-height: 1.65; font-size: 15px; }
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input[type=file] { padding: 7px 9px; font-size: 12px; color: var(--text-dim); }

.field { margin-bottom: 15px; }
.hint { font-size: 12px; color: var(--text-dim); margin-top: 6px; }
.hint code {
  background: var(--surface-3); padding: 1px 5px;
  border-radius: 4px; color: var(--text);
}

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface-2);
  color: var(--text); font-size: 13px; font-weight: 550;
  cursor: pointer; font-family: inherit; white-space: nowrap;
  transition: background .14s var(--ease), border-color .14s var(--ease);
}
.btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 38%, transparent); }
.btn.danger:hover { background: var(--danger-bg); }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.checkbox {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--text); cursor: pointer; margin: 0;
}
input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }

/* ------ character ring: sits beside the submit, not in a corner ------ */

.ring { display: flex; align-items: center; gap: 9px; }
.ring svg { width: 30px; height: 30px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 3; }
.ring .track { stroke: var(--surface-3); }
.ring .value {
  stroke: var(--accent); stroke-linecap: round;
  transition: stroke-dashoffset .2s var(--ease), stroke .2s var(--ease);
}
.ring.warn  .value { stroke: var(--warn); }
.ring.over  .value { stroke: var(--danger); }
.ring .readout { font-family: var(--mono); font-size: 12px; color: var(--text-dim); }
.ring.over .readout { color: var(--danger); }

/* --------------------------------------------------------------- notices --- */

.notice {
  padding: 12px 15px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2);
  font-size: 13px; display: flex; gap: 11px; align-items: flex-start;
}
.notice svg { margin-top: 1px; color: var(--text-dim); }
.notice.warn   { border-color: color-mix(in srgb, var(--warn) 38%, transparent); background: var(--warn-bg); }
.notice.warn svg { color: var(--warn); }
.notice.error  { border-color: color-mix(in srgb, var(--danger) 38%, transparent); background: var(--danger-bg); }
.notice.error svg { color: var(--danger); }
.notice.ok     { border-color: color-mix(in srgb, var(--ok) 38%, transparent); background: var(--ok-bg); }
.notice.ok svg { color: var(--ok); }

.toast-host {
  position: fixed; bottom: 22px; right: 22px; z-index: 100;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 11px 15px; border-radius: var(--radius-sm);
  background: var(--surface-3); border: 1px solid var(--border-strong);
  font-size: 13px; box-shadow: var(--shadow); max-width: 380px;
}
.toast.error { border-color: color-mix(in srgb, var(--danger) 55%, transparent); color: var(--danger); }
.toast.ok    { border-color: color-mix(in srgb, var(--ok) 55%, transparent); color: var(--ok); }
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: rise .18s var(--ease); }
  @keyframes rise { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: none; } }
}

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

.dim { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.small { font-size: 12px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.divider { height: 1px; background: var(--border); margin: 8px 0; }

.tag {
  font-family: var(--mono); font-size: 11px;
  background: var(--surface-3); border: 1px solid var(--border);
  padding: 1px 6px; border-radius: 4px; color: var(--text-dim);
}

.copy-field { display: flex; gap: 6px; }
.copy-field input { font-family: var(--mono); font-size: 11px; }

.htmx-request { opacity: .55; pointer-events: none; }
.scroll-list { max-height: 360px; overflow-y: auto; }

/* --------------------------------------------------- standalone screens --- */

.center-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.center-card { width: 100%; max-width: 380px; }

.result-card { max-width: 460px; text-align: center; }
.result-badge {
  width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center; margin: 0 auto 16px;
  background: var(--ok-bg); color: var(--ok);
}
.result-badge.bad { background: var(--danger-bg); color: var(--danger); }
.result-badge svg { width: 22px; height: 22px; }

/* ------------------------------------------------------------ responsive --- */

@media (max-width: 1000px) {
  .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sidebar { width: 60px; padding-top: 16px; }
  .sidebar .label, .brand .wordmark, .who { display: none; }
  .brand { justify-content: center; padding: 0 0 18px; }
  .nav a { justify-content: center; padding: 9px; }
  .nav .count { display: none; }
  .sidebar-foot { padding: 12px 8px 0; }
  .prefs { flex-direction: column; }
  /* Collapsed sidebar: the label would overflow 60px, so show the icon only. */
  .btn.signout { padding: 7px 0; }
  .btn.signout .label { display: none; }
}

@media (max-width: 700px) {
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
  .content { padding: 18px 15px 48px; }
  .topbar, .statusbar { padding-left: 15px; padding-right: 15px; }
  .statusbar { gap: 14px; }
  .hero { padding: 18px; gap: 18px; }
  .hero .value { font-size: 38px; }
}
