/* UK Drop-Catcher dashboard styles.
 * Mobile-first, dark-on-light, no frameworks. Layout uses CSS grid for
 * desktop and stacks on narrow screens.
 */

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

:root {
  --bg: #f7f7f4;
  --card: #ffffff;
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --line: #d8d8d2;
  --primary: #1d4ed8;
  --primary-ink: #ffffff;
  --ok: #1f8a3f;
  --warn: #b8860b;
  --err: #b32424;
  --code-bg: #f0f0eb;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

code, pre, .t-cltrid {
  font-family: ui-monospace, Menlo, Consolas, "Courier New", monospace;
  background: var(--code-bg);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 0.92em;
}

/* ------------------- Login --------------------------------------------- */
.login-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #eaeae3 0%, #f7f7f4 100%);
}
.login-card {
  background: var(--card);
  padding: 32px;
  border-radius: 12px;
  max-width: 380px;
  width: 92%;
  box-shadow: 0 8px 24px rgba(0,0,0,0.06);
}
.login-card h1 { margin: 0 0 6px; font-size: 22px; }
.login-card form { display: grid; gap: 14px; margin-top: 16px; }
.login-card label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
.login-card input[type="text"], .login-card input[type="password"] {
  font-size: 16px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px;
}

/* ------------------- App shell ----------------------------------------- */
.app {
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: 56px 1fr;
  grid-template-areas:
    "top top"
    "side main";
  min-height: 100vh;
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--ink);
  color: #fff;
  padding: 0 16px;
}
.topbar .brand a { color: #fff; font-weight: 600; }
.topbar .acct-switcher { display: flex; gap: 4px; }
.topbar .acct {
  color: #ddd;
  padding: 6px 12px;
  border-radius: 6px;
  background: #2a2a2a;
  font-size: 13px;
}
.topbar .acct.active { background: var(--primary); color: #fff; }
.topbar .quota-summary { flex: 1; min-width: 0; padding: 0 12px; max-width: 460px; }
.topbar .logout { margin-left: auto; }
.topbar .ghost { background: transparent; color: #ddd; border: 1px solid #444; }

.sidenav {
  grid-area: side;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--line);
  background: #fafaf6;
  padding: 12px 0;
}
.sidenav a {
  padding: 10px 18px;
  color: var(--ink);
  font-size: 14px;
  border-left: 3px solid transparent;
}
.sidenav a.active {
  background: #fff;
  border-left-color: var(--primary);
  font-weight: 600;
}
.sidenav a:hover { background: #f0f0eb; text-decoration: none; }

.content {
  grid-area: main;
  padding: 24px;
  max-width: 1200px;
}
.page-head h1 { margin: 0 0 4px; font-size: 22px; }
.page-head .muted { color: var(--muted); font-size: 13px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px 20px;
  margin: 16px 0;
}
.card h2 { margin: 0 0 12px; font-size: 17px; }
.card h3 { margin: 18px 0 8px; font-size: 15px; }

/* ------------------- Forms ---------------------------------------------- */
input[type="text"], input[type="password"], input[type="number"],
input[type="date"], input[type="search"], select, textarea {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}
textarea { font-family: ui-monospace, Menlo, monospace; }

button, .primary, .ghost, .danger {
  font: inherit;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid transparent;
}
button[type="submit"], .primary {
  background: var(--primary); color: var(--primary-ink); border-color: var(--primary);
}
.ghost {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}
.ghost.danger { color: var(--err); }
button:hover { filter: brightness(0.95); }

.grid-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 16px;
}
.grid-form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.grid-form .full { grid-column: 1 / -1; }
.grid-form label.cb {
  flex-direction: row; gap: 8px;
  align-items: center; display: flex;
  font-size: 14px; color: var(--ink);
}
.grid-form button { grid-column: 1 / -1; justify-self: start; }
.grid-form .hint { color: var(--muted); font-size: 11px; }

form.inline { display: inline; }
form.search, form.filter-form { display: flex; gap: 8px; align-items: end; }
form.search input[type="search"] { flex: 1; min-width: 200px; }

/* ------------------- Tables -------------------------------------------- */
.t {
  width: 100%; border-collapse: collapse; font-size: 14px;
}
.t th, .t td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); }
.t th { background: #fafaf6; font-weight: 600; }
.t td.num { text-align: right; font-variant-numeric: tabular-nums; }
.t .actions { white-space: nowrap; }

.kv { width: 100%; }
.kv th, .kv td { padding: 6px 8px; text-align: left; vertical-align: top; }
.kv th { color: var(--muted); font-weight: 500; width: 200px; }

.row-ok    { background: #f1fbf3; }
.row-warn  { background: #fff8e9; }
.row-err   { background: #fdecec; }
.red-flag  { background: #fff5f5; }

/* ------------------- Quota meter --------------------------------------- */
.qm-wrap { color: #fff; font-size: 12px; }
.qm-label { display: flex; justify-content: space-between; }
.qm-level { font-weight: 600; }
.qm-bar { height: 6px; border-radius: 3px; background: #444; margin: 4px 0; overflow: hidden; }
.qm-fill { height: 100%; background: #2ecc71; transition: width 0.3s ease; }
.qm-wrap.level-warn .qm-fill { background: #f39c12; }
.qm-wrap.level-stop .qm-fill { background: #e74c3c; }
.qm-wrap.level-normal .qm-fill { background: #2ecc71; }
.qm-numbers { font-size: 11px; opacity: 0.85; }

/* On the Quota & Health page (not on dark bar) */
.backend-row .qm-wrap { color: var(--ink); }
.backend-row .qm-bar { background: #ddd; }

/* ------------------- Badges + flashes ---------------------------------- */
.badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--code-bg);
  color: var(--muted);
}
.badge.ok   { background: #d6f5dc; color: var(--ok); }
.badge.warn { background: #fff1cc; color: var(--warn); }
.badge.err  { background: #f8d4d4; color: var(--err); }
.badge.mute { background: #eee; color: var(--muted); }

.flash {
  padding: 10px 14px; border-radius: 8px; margin: 12px 0; font-size: 14px;
}
.flash.ok   { background: #e8f7ec; color: var(--ok); }
.flash.warn { background: #fdf3d4; color: var(--warn); }
.flash.err  { background: #fbe8e8; color: var(--err); }

.bulk-result, .sim-result { margin-top: 12px; font-size: 13px; }

/* ------------------- Histogram (calibration) --------------------------- */
.cal-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px 16px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 14px;
}
.cal-summary strong { color: var(--ink); }
.histogram { display: grid; gap: 4px; font-size: 12px; }
.bar-row { display: grid; grid-template-columns: 140px 1fr 40px; gap: 8px; align-items: center; }
.bar-label { color: var(--muted); font-variant-numeric: tabular-nums; }
.bar-track { height: 14px; background: #eee; border-radius: 3px; overflow: hidden; }
.bar { height: 100%; background: var(--primary); }
.bar-count { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

.muted { color: var(--muted); }
.result-block { background: #fafaf6; }

/* ------------------- Mobile -------------------------------------------- */
@media (max-width: 760px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
    grid-template-areas: "top" "side" "main";
  }
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; }
  .topbar .quota-summary { order: 4; width: 100%; padding: 6px 0; }
  .sidenav { flex-direction: row; flex-wrap: wrap; padding: 8px; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--line); }
  .sidenav a { padding: 8px 12px; border-left: none; border-bottom: 2px solid transparent; }
  .sidenav a.active { border-bottom-color: var(--primary); }
  .content { padding: 12px; }
  .grid-form { grid-template-columns: 1fr; }
  .cal-summary { grid-template-columns: repeat(2, 1fr); }
  .bar-row { grid-template-columns: 100px 1fr 36px; font-size: 11px; }
}
