/* Jhatpat Ops console. One stylesheet, no framework, light and dark. */

:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #fafaf8;
  --ink: #16150f;
  --ink-2: #5b5a52;
  --ink-3: #8b897e;
  --line: #e3e2dc;
  --line-2: #cfcec6;
  --accent: #1f5c3d;
  --accent-ink: #ffffff;
  --ok-bg: #e4f0e6; --ok-ink: #1b5132;
  --wait-bg: #fdf0d9; --wait-ink: #7a5310;
  --warn-bg: #fce7d4; --warn-ink: #8a4415;
  --bad-bg: #fbe1de; --bad-ink: #8c231c;
  --neutral-bg: #ecebe6; --neutral-ink: #55534b;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20,18,10,.06), 0 6px 20px rgba(20,18,10,.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121210; --surface: #1b1b18; --surface-2: #201f1c;
    --ink: #f2f1ec; --ink-2: #b3b1a8; --ink-3: #85837a;
    --line: #2d2c28; --line-2: #3c3b35;
    --accent: #6fc496; --accent-ink: #10130f;
    --ok-bg: #1d3327; --ok-ink: #8fd9ab;
    --wait-bg: #3a2f16; --wait-ink: #e7c473;
    --warn-bg: #3d2a19; --warn-ink: #eab183;
    --bad-bg: #3d1f1c; --bad-ink: #f0a49c;
    --neutral-bg: #2a2925; --neutral-ink: #b6b4ab;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 1.6rem; margin: 0 0 .2rem; letter-spacing: -.02em; }
h2 { font-size: 1.05rem; margin: 0; letter-spacing: -.01em; }
h3 { font-size: .98rem; margin: 0 0 .15rem; }
p { margin: .3rem 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82em; }

/* ── Shell ───────────────────────────────────────────────────────────────── */

.topbar {
  display: flex; align-items: center; gap: 1.5rem;
  padding: .7rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: .55rem; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink); font-weight: 700;
}
.brand-sub { color: var(--ink-3); margin-left: .35rem; font-size: .85rem; }
.nav { display: flex; flex-wrap: wrap; gap: .3rem; flex: 1; min-width: 0; }
.nav-link {
  padding: .35rem .7rem; border-radius: 7px; color: var(--ink-2); font-weight: 500;
}
.nav-link:hover { background: var(--surface-2); text-decoration: none; }
.nav-link-on { background: var(--neutral-bg); color: var(--ink); }
.topbar-right { display: flex; gap: .4rem; }

.main { max-width: 1080px; margin: 0 auto; padding: 1.6rem 1.5rem 5rem; }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem;
  margin-bottom: 1.2rem;
}
.head-status { padding-top: .3rem; }
.back { margin: 0 0 .8rem; font-size: .9rem; }

/* ── Text ────────────────────────────────────────────────────────────────── */

.help { color: var(--ink-2); font-size: .85rem; margin: .15rem 0; }
.help-quiet { color: var(--ink-3); }
.help-warn { color: var(--warn-ink); }
.muted { color: var(--ink-3); }
.strong { font-weight: 600; }
.eyebrow { text-transform: uppercase; letter-spacing: .1em; font-size: .7rem; color: var(--ink-3); margin: 0; }
.lede { color: var(--ink-2); margin: .2rem 0 1.2rem; }
.ok-line { color: var(--ok-ink); font-weight: 500; }
.reason-line {
  background: var(--surface-2); border-left: 3px solid var(--line-2);
  padding: .4rem .6rem; margin: .4rem 0; font-size: .85rem; color: var(--ink-2);
}
.note {
  margin: .6rem 0; padding: .6rem .8rem; border-left: 3px solid var(--accent);
  background: var(--surface-2); border-radius: 0 var(--radius) var(--radius) 0;
  white-space: pre-wrap;
}
.loading { padding: 2.5rem 0; color: var(--ink-3); text-align: center; }
.row-center { display: flex; justify-content: center; padding: 1rem 0; }
.right { text-align: right; align-items: flex-end; }

/* ── Cards ───────────────────────────────────────────────────────────────── */

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem 1.2rem; margin-bottom: 1.1rem; box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem;
  margin-bottom: .6rem;
}
.stack > * + * { margin-top: 1rem; }
.stack-tight > * + * { margin-top: .2rem; }
.stack-tight { display: flex; flex-direction: column; align-items: flex-start; }
.stack-tight.right { align-items: flex-end; }

.fields {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: .7rem 1.2rem; margin-top: .4rem;
}
.field { display: flex; flex-direction: column; gap: .1rem; }
.field-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3); }
.field-value { font-size: .92rem; }

/* ── Queues ──────────────────────────────────────────────────────────────── */

.queue-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: .9rem; }
.queue-card {
  display: flex; gap: .9rem; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; color: var(--ink); box-shadow: var(--shadow);
}
.queue-card:hover { text-decoration: none; border-color: var(--line-2); }
.queue-card-inert { opacity: .68; }
.queue-count { font-size: 1.9rem; font-weight: 600; line-height: 1.1; color: var(--ink-3); min-width: 1.6ch; }
.queue-count-live { color: var(--accent); }
.queue-body { flex: 1; }

.alarms { margin-bottom: 1.1rem; }
.alarm {
  background: var(--bad-bg); color: var(--bad-ink); border-radius: var(--radius);
  padding: .8rem 1rem; margin-bottom: .6rem;
}
.alarm p { margin: .2rem 0 0; font-size: .87rem; }

/* ── Tables ──────────────────────────────────────────────────────────────── */

.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th {
  text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--ink-3); font-weight: 600; padding: .45rem .6rem; border-bottom: 1px solid var(--line);
}
.table td { padding: .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.row-link { cursor: pointer; }
.row-link:hover td { background: var(--surface-2); }
.cell-actions { white-space: nowrap; text-align: right; }
.cell-actions .btn + .btn { margin-left: .3rem; }

/* Outside a card the table needs its own surface. */
.table-scroll {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.table-scroll > .table th, .table-scroll > .table td { padding-left: 1rem; padding-right: 1rem; }

/* ── Badges & pills ──────────────────────────────────────────────────────── */

.badge {
  display: inline-block; padding: .16rem .5rem; border-radius: 99px;
  font-size: .76rem; font-weight: 600; white-space: nowrap;
  background: var(--neutral-bg); color: var(--neutral-ink);
}
.badge-ok { background: var(--ok-bg); color: var(--ok-ink); }
.badge-wait { background: var(--wait-bg); color: var(--wait-ink); }
.badge-warn { background: var(--warn-bg); color: var(--warn-ink); }
.badge-bad { background: var(--bad-bg); color: var(--bad-ink); }

.pills { display: flex; flex-wrap: wrap; gap: .35rem; margin: .5rem 0; }
.pill {
  display: inline-block; padding: .1rem .45rem; border-radius: 5px;
  font-size: .76rem; background: var(--neutral-bg); color: var(--neutral-ink);
}
.pill-wait { background: var(--wait-bg); color: var(--wait-ink); }
.pill-warn { background: var(--warn-bg); color: var(--warn-ink); }
.pill-bad { background: var(--bad-bg); color: var(--bad-ink); }

.blockers { margin: .4rem 0 0; padding: 0; list-style: none; }
.blockers li {
  display: flex; gap: .6rem; align-items: baseline;
  padding: .4rem 0; border-top: 1px solid var(--line);
}
.blocker-code {
  background: var(--warn-bg); color: var(--warn-ink);
  padding: .08rem .4rem; border-radius: 5px; white-space: nowrap;
}

/* ── Forms & buttons ─────────────────────────────────────────────────────── */

.filters { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .6rem; }
.label { display: block; font-weight: 600; font-size: .86rem; margin: .8rem 0 .3rem; }

.input {
  width: 100%; padding: .5rem .65rem; font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 8px;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.input-inline { width: auto; min-width: 180px; }
.filters input[type="search"] { min-width: 280px; flex: 1; max-width: 420px; }
select.input { cursor: pointer; }
textarea.input { resize: vertical; }

.btn {
  display: inline-block; padding: .5rem .9rem; font: inherit; font-weight: 600;
  border-radius: 8px; border: 1px solid transparent; cursor: pointer;
  background: var(--neutral-bg); color: var(--ink);
}
.btn:hover:not(:disabled) { filter: brightness(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-danger { background: var(--bad-bg); color: var(--bad-ink); border-color: var(--bad-ink); }
.btn-ghost { background: transparent; border-color: var(--line-2); color: var(--ink-2); }
.btn-small { padding: .28rem .6rem; font-size: .82rem; }

.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .7rem; }
.actions .help { width: 100%; margin: 0; }

/* ── Empty & error states ────────────────────────────────────────────────── */

.empty {
  background: var(--surface); border: 1px dashed var(--line-2); border-radius: var(--radius);
  padding: 2.2rem 1.5rem; text-align: center;
}
.empty-mark { font-size: 2rem; color: var(--line-2); line-height: 1; }
.empty h3 { margin: .4rem 0 .2rem; font-size: 1.02rem; }
.empty p { color: var(--ink-2); max-width: 46ch; margin: 0 auto .8rem; font-size: .9rem; }

.alert {
  background: var(--bad-bg); color: var(--bad-ink); border-radius: var(--radius);
  padding: .75rem .9rem; margin: .6rem 0;
}
.alert p { margin: 0; font-weight: 500; }
.alert ul { margin: .4rem 0 0; padding-left: 1.1rem; font-size: .88rem; }
.alert-code { display: block; margin-top: .4rem; opacity: .65; font-size: .72rem; }
.alert-inline { color: var(--bad-ink); font-size: .85rem; margin: .4rem 0 0; }

/* ── Sign in ─────────────────────────────────────────────────────────────── */

.signin { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.signin-card {
  width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 2rem; box-shadow: var(--shadow);
}
.signin-card .btn { width: 100%; }
.signin-card .stack > * + * { margin-top: .6rem; }

/* ── Modal ───────────────────────────────────────────────────────────────── */

#modal { display: none; }
#modal.open { display: block; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(12,12,10,.5); z-index: 40; }
.modal-card {
  position: fixed; z-index: 41; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(480px, calc(100vw - 2rem)); max-height: 86vh; overflow: auto;
  background: var(--surface); border-radius: 14px; padding: 1.4rem;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.modal-subject { font-weight: 600; margin: .5rem 0 .2rem; }
.modal-consequence { color: var(--ink-2); font-size: .9rem; }
.modal-human {
  background: var(--wait-bg); color: var(--wait-ink); border-radius: 7px;
  padding: .45rem .6rem; font-size: .83rem; margin: .7rem 0 0;
}
.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.1rem; }

/* ── Toasts ──────────────────────────────────────────────────────────────── */

#toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 50; display: flex; flex-direction: column; gap: .5rem; }
.toast {
  background: var(--ink); color: var(--bg); padding: .65rem .9rem; border-radius: 9px;
  max-width: 380px; font-size: .88rem; box-shadow: var(--shadow);
  animation: toast-in .16s ease-out;
}
.toast-bad { background: var(--bad-ink); color: #fff; }
.toast-out { opacity: 0; transition: opacity .55s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: .6rem; padding: .6rem 1rem; }
  .main { padding: 1.2rem 1rem 4rem; }
  .table { font-size: .84rem; }
  .cell-actions { text-align: left; white-space: normal; }
  .fields { grid-template-columns: 1fr 1fr; }
  .filters .input-inline, .filters input[type="search"] { min-width: 0; width: 100%; max-width: none; }
  .fields .input-inline { max-width: 100%; }

  /*
   * A six-column review table does not fit a phone, and the honest fix is to let the table
   * scroll inside its card rather than to let it push the whole page sideways — a page that
   * scrolls horizontally hides the nav and the action buttons at the same time.
   */
  .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .card { overflow-x: auto; }
  .page-head { flex-wrap: wrap; }
  .help-quiet { overflow-wrap: anywhere; }
}

/*
 * A phone: the nav is one horizontally scrollable row, not one link per line — a stacked nav
 * made the sticky header 565 px of an 844 px viewport. Brand and Sign out stay in view.
 */
@media (max-width: 600px) {
  .topbar { gap: .4rem .6rem; }
  .nav {
    flex-wrap: nowrap; overflow-x: auto; white-space: nowrap; order: 3; flex-basis: 100%;
    -webkit-overflow-scrolling: touch; scrollbar-width: none; margin: 0 -1rem; padding: 0 1rem;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav-link { flex: 0 0 auto; }
  .brand { flex: 1; min-width: 0; }
  .topbar-right { flex: 0 0 auto; }
}
