/* ============================================================================
   Yama Admin — "Signal" console
   An instrument panel for a realtime chat backend. Identity is carried by the
   IBM Plex Mono / Plex Sans pairing and a single signal-orange accent, not by a
   loud background. Self-contained, no build step (propshaft).
   ========================================================================== */

:root {
  --ink: #0f141a;
  --bg: #eef1f4;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --line: #dfe4ea;
  --line-strong: #cbd3dc;

  --signal: #f97316;
  --signal-ink: #c2540b;
  --signal-soft: #fdebd9;

  --amber: #b5710f;
  --amber-soft: #fbf0de;
  --alert: #d64550;
  --alert-soft: #fbe7e8;

  --muted: #687078;
  --faint: #97a0a9;

  --sidebar: #11161f;
  --sidebar-line: rgba(255, 255, 255, .08);

  --radius: 10px;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body.admin {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Eyebrow / overline label, the recurring mono utility voice */
.eyebrow {
  font-family: var(--mono);
  font-size: .68rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--faint);
}

/* ---- Shell: fixed sidebar + content ------------------------------------- */
.admin-shell { display: flex; min-height: 100vh; }

.admin-sidebar {
  width: 232px;
  background: var(--sidebar);
  color: #c2cad6;
  display: flex;
  flex-direction: column;
  padding: 1.5rem 0 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
}
.admin-brand {
  padding: 0 1.4rem 1.5rem;
  font-family: var(--mono);
  font-weight: 600;
  font-size: 1.05rem;
  color: #fff;
  letter-spacing: .02em;
}
.admin-brand .mark { color: var(--signal); }
.admin-brand small {
  display: block;
  margin-top: .35rem;
  font-family: var(--sans);
  font-weight: 400;
  font-size: .7rem;
  letter-spacing: .01em;
  color: #6c7790;
}
.admin-nav { display: flex; flex-direction: column; gap: 1px; padding: 0 .7rem; }
.admin-nav a {
  display: flex; align-items: center; gap: .55rem;
  padding: .55rem .75rem;
  border-radius: 8px;
  color: #aeb7c5;
  text-decoration: none;
  font-weight: 500;
  font-size: .9rem;
}
.admin-nav a::before {
  content: ""; width: 5px; height: 5px; border-radius: 50%;
  background: currentColor; opacity: .35;
}
.admin-nav a:hover { background: rgba(255, 255, 255, .05); color: #fff; }
.admin-nav a.active { background: rgba(249, 115, 22, .16); color: #fff; }
.admin-nav a.active::before { background: var(--signal); opacity: 1; box-shadow: 0 0 8px var(--signal); }

.admin-sidebar-footer { margin-top: auto; padding: 1rem 1.4rem 0; border-top: 1px solid var(--sidebar-line); }
.admin-sidebar-footer .who {
  font-family: var(--mono); font-size: .72rem; color: #8a93a6;
  margin-bottom: .65rem; word-break: break-all;
}

.admin-content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.admin-topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 1.1rem 2rem;
}
.admin-topbar .eyebrow { display: block; margin-bottom: .15rem; }
.admin-topbar h1 { font-size: 1.3rem; margin: 0; font-weight: 600; letter-spacing: -.01em; }
.admin-main { padding: 2rem; width: 100%; flex: 1; min-height: 0; }

/* Sidekiq UI embedded full-bleed inside the admin shell: drop the padding and
   the topbar so the iframe fills the entire right-hand content area. */
.admin-content:has(.jobs-frame) .admin-topbar { display: none; }
.admin-main:has(.jobs-frame) { padding: 0; }
.jobs-frame {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 70vh;
  border: 0;
  background: var(--surface);
}

/* ---- Flash -------------------------------------------------------------- */
.flash {
  padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1.25rem;
  font-size: .9rem; border: 1px solid transparent;
}
.flash.notice { background: var(--signal-soft); color: var(--signal-ink); border-color: #f6d4b3; }
.flash.alert  { background: var(--alert-soft); color: #9b2c33; border-color: #f3c7ca; }

/* ---- Status strip (signature: live pulse) ------------------------------- */
.status-strip {
  display: flex; align-items: center; gap: .7rem;
  padding: .85rem 1.15rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
}
.pulse { position: relative; width: 9px; height: 9px; flex: none; }
.pulse i {
  position: absolute; inset: 0; border-radius: 50%; background: var(--signal);
}
.pulse i::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  background: var(--signal); animation: pulse-ring 2s ease-out infinite;
}
@keyframes pulse-ring {
  0%   { transform: scale(1);   opacity: .55; }
  100% { transform: scale(3.4); opacity: 0; }
}
.status-strip .label { font-weight: 600; }
.status-strip .detail { color: var(--muted); font-size: .85rem; }
.status-strip .clock {
  margin-left: auto; font-family: var(--mono); font-size: .8rem; color: var(--faint);
  letter-spacing: .02em;
}

/* ---- Readout (instrument) metric cards ---------------------------------- */
.readouts { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; margin-bottom: 1.75rem; }
.readout {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem 1.25rem;
}
.readout::before {
  content: ""; position: absolute; left: 0; top: 1.15rem; bottom: 1.15rem;
  width: 3px; border-radius: 3px; background: var(--line-strong);
}
.readout.is-signal::before { background: var(--signal); }
.readout.is-muted::before  { background: var(--line-strong); }
.readout.is-alert::before  { background: var(--alert); }
.readout .eyebrow { display: block; margin-bottom: .7rem; }
.readout .value {
  font-family: var(--mono); font-size: 2.5rem; font-weight: 500;
  line-height: 1; letter-spacing: -.02em; font-variant-numeric: tabular-nums;
}
.readout .value .unit { font-size: .8rem; color: var(--faint); margin-left: .4rem; letter-spacing: .02em; }
.readout .hint { margin-top: .6rem; font-size: .8rem; color: var(--muted); }

/* Occupancy bar: honest active/total ratio */
.ratio { margin-top: .85rem; height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; }
.ratio > span { display: block; height: 100%; background: var(--signal); border-radius: 4px; }

/* ---- Panel (card) ------------------------------------------------------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel-header {
  display: flex; align-items: center; gap: .75rem;
  padding: .95rem 1.25rem; border-bottom: 1px solid var(--line);
}
.panel-header h2 { margin: 0; font-size: .95rem; font-weight: 600; }
.panel-header .spacer { margin-left: auto; }
.panel-body { padding: 1.25rem; }
/* legacy aliases so every admin view stays coherent */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.card-header { display: flex; align-items: center; padding: .95rem 1.25rem; border-bottom: 1px solid var(--line); }
.card-header h2 { margin: 0; font-size: .95rem; font-weight: 600; }
.card-body { padding: 1.25rem; }

/* ---- Ledger / data tables ----------------------------------------------- */
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { text-align: left; padding: .7rem 1.25rem; }
table.data thead th {
  font-family: var(--mono); color: var(--faint); font-weight: 500;
  font-size: .68rem; text-transform: uppercase; letter-spacing: .12em;
  border-bottom: 1px solid var(--line);
}
table.data tbody tr { border-bottom: 1px solid var(--line); }
table.data tbody tr:last-child { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td .name { font-weight: 600; color: var(--ink); text-decoration: none; }
table.data td .name:hover { color: var(--signal-ink); }
table.data .mono, table.data .id { font-family: var(--mono); font-size: .82rem; color: var(--muted); }

/* ---- JSON payload viewer (request logs) --------------------------------- */
pre.json {
  margin: 0; padding: .9rem 1rem;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px;
  font-family: var(--mono); font-size: .8rem; line-height: 1.55; color: var(--ink);
  overflow-x: auto; white-space: pre-wrap; word-break: break-word;
}
pre.json .j-key  { color: var(--signal-ink); }
pre.json .j-str  { color: #2e7d57; }
pre.json .j-num  { color: #b5710f; }
pre.json .j-bool { color: #7048e8; }
pre.json .j-null { color: var(--faint); }

/* Relation links render as pill/tags (everything but the primary .name link
   and action buttons). */
table.data td a:not(.name):not(.btn) {
  display: inline-flex; align-items: center;
  padding: .12rem .5rem;
  border: 1px solid var(--line-strong); border-radius: 999px;
  font-size: .8rem; color: var(--muted); text-decoration: none;
}
table.data td a:not(.name):not(.btn):hover { border-color: var(--signal); color: var(--signal-ink); }

table.kv th { width: 170px; color: var(--muted); font-weight: 500; vertical-align: top; }
table.kv td { color: var(--ink); }

/* ---- Badges ------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .2rem .55rem; border-radius: 999px;
  font-family: var(--mono); font-size: .7rem; letter-spacing: .04em; text-transform: uppercase;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.on { background: var(--signal-soft); color: var(--signal-ink); }
.badge.off { background: #eef1f4; color: var(--muted); }

/* ---- Buttons ------------------------------------------------------------ */
.btn, button.btn, input[type="submit"] {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .55rem .9rem;
  border-radius: 9px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font: inherit; font-weight: 600; font-size: .88rem;
  cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--surface-2); border-color: var(--muted); }
.btn.primary, input[type="submit"] { background: var(--signal); border-color: var(--signal); color: #fff; }
.btn.primary:hover, input[type="submit"]:hover { background: var(--signal-ink); border-color: var(--signal-ink); }
.btn.danger { color: #9b2c33; border-color: #f0c4c7; background: var(--alert-soft); }
.btn.danger:hover { background: #f7d6d8; }
.btn-row { display: flex; gap: .6rem; flex-wrap: wrap; }

/* ---- Forms -------------------------------------------------------------- */
.form-field { margin-bottom: 1.1rem; max-width: 520px; }
.form-field label { display: block; font-weight: 600; margin-bottom: .35rem; font-size: .88rem; }
.form-field input[type="text"],
.form-field input[type="email"],
.form-field input[type="password"],
.form-field textarea {
  width: 100%; padding: .6rem .7rem;
  border: 1px solid var(--line-strong); border-radius: 9px;
  font: inherit; background: var(--surface); color: var(--ink);
}
.form-field input:focus, .form-field textarea:focus {
  outline: none; border-color: var(--signal); box-shadow: 0 0 0 3px var(--signal-soft);
}
.form-check { display: flex; align-items: center; gap: .5rem; margin-bottom: 1.1rem; font-size: .9rem; }

/* ---- Filter bar (clickable badges) ------------------------------------- */
.filter-bar { display: flex; flex-direction: column; gap: .55rem; margin-bottom: 1.25rem; }
.filter-group { display: flex; align-items: center; flex-wrap: wrap; gap: .4rem; }
.filter-label {
  font-family: var(--mono); font-size: .68rem; text-transform: uppercase; letter-spacing: .12em;
  color: var(--faint); min-width: 54px;
}
.chip {
  display: inline-flex; align-items: center;
  padding: .25rem .6rem; border-radius: 999px;
  font-family: var(--mono); font-size: .72rem; letter-spacing: .04em;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--muted);
  text-decoration: none; cursor: pointer;
}
.chip:hover { border-color: var(--muted); color: var(--ink); }
.chip.active { background: var(--signal); border-color: var(--signal); color: #fff; }

/* ---- Search form -------------------------------------------------------- */
.search-form { display: flex; gap: .6rem; margin-bottom: 1.25rem; }
.search-input {
  flex: 1; min-width: 0; max-width: 420px;
  padding: .6rem .7rem;
  border: 1px solid var(--line-strong); border-radius: 9px;
  font: inherit; background: var(--surface); color: var(--ink);
}
.search-input:focus {
  outline: none; border-color: var(--signal); box-shadow: 0 0 0 3px var(--signal-soft);
}

/* ---- Helpers ------------------------------------------------------------ */
.page-head { display: flex; align-items: center; gap: .6rem; margin-bottom: 1.5rem; }
.page-head .spacer { margin-left: auto; }
.page-head .search-form { margin-bottom: 0; }
.muted { color: var(--muted); }
.section-label { margin: 0 0 .85rem; }
code { font-family: var(--mono); background: var(--surface-2); border: 1px solid var(--line); padding: .12rem .4rem; border-radius: 6px; font-size: .82em; }

/* ---- Centered auth (login) ---------------------------------------------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; background: var(--bg); padding: 1.5rem; }
.auth-card {
  width: 370px; max-width: 100%;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 2.25rem;
}
.auth-card h1 { margin: 0 0 .25rem; font-family: var(--mono); font-size: 1.35rem; letter-spacing: .01em; }
.auth-card h1 .mark { color: var(--signal); }
.auth-card .auth-sub { margin: 0 0 1.75rem; color: var(--muted); font-size: .88rem; }

/* ---- Quality floor ------------------------------------------------------ */
:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .pulse i::after { animation: none; }
}

@media (max-width: 720px) {
  .admin-shell { flex-direction: column; }
  .admin-sidebar { width: auto; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; padding: .85rem 1rem; }
  .admin-brand { padding: 0 1rem 0 0; }
  .admin-brand small { display: none; }
  .admin-nav { flex-direction: row; padding: 0; }
  .admin-sidebar-footer { margin: 0 0 0 auto; padding: 0; border: 0; }
  .admin-sidebar-footer .who { display: none; }
  .admin-main { padding: 1.25rem; }
}

/* Pagination (Pagy) */
.pagy.nav { display: flex; flex-wrap: wrap; gap: .25rem; margin-top: 1rem; align-items: center; }
.pagy.nav a {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 2rem; height: 2rem; padding: 0 .5rem;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--ink);
  font: 500 .85rem/1 var(--sans); text-decoration: none;
}
.pagy.nav a:hover { border-color: var(--line-strong); background: var(--surface-2); }
.pagy.nav a.current { background: var(--signal-soft); border-color: var(--signal); color: var(--signal-ink); }
.pagy.nav a[aria-disabled="true"] { color: var(--faint); background: var(--surface); cursor: default; }
.pagy.nav a.gap { border: 0; background: none; min-width: auto; }
