/*
 * App styles, "F · Tail" dark theme: the client dashboard and the allauth
 * account pages (sign in/up, reset, email, password).
 *
 * Loaded via templates/ui/_head.html by clients/client_detail.html and
 * allauth/layouts/{entrance,manage}.html. Those pages are standalone (no
 * Bootstrap). Selected rows and tabs get a lighter surface, never a side
 * accent bar.
 *
 * Real vs safe must stay distinguishable without hue: real is a light blue,
 * safe a mid orange, so they also differ in lightness. Sized for a 13-14"
 * laptop (~1280x800 viewport).
 */

:root {
  --bg: #0b0d0c;
  --surface: #111412;
  --surface-side: #0e110f;
  --raised: #171b19;
  --line: #1f2421;
  --line-strong: #2a302c;
  --text: #d7ded9;
  --text-strong: #eef3ef;
  --muted: #8c978f;
  --real: #8ccbff;
  --safe: #e8743b;
  --ok: #7bd88f;
  --display: "Red Hat Display", system-ui, sans-serif;
  --sans: "Red Hat Text", system-ui, sans-serif;
  --mono: "Red Hat Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.4;
}

a { color: var(--real); }
a:hover { color: #b8deff; }
:focus-visible { outline: 2px solid var(--real); outline-offset: 2px; }

.mono { font-family: var(--mono); }
.small { font-size: 12px; color: var(--muted); }
.dim { color: var(--muted); }
.right { text-align: right; }
.real { color: var(--real); }
.safe { color: var(--safe); }
.warn { color: var(--safe); }
.muted, .muted a { color: var(--muted); }
.empty { color: var(--muted); padding: 12px 0; margin: 0; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.eyebrow {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
}

.logo {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.2px;
  color: var(--text-strong);
  text-decoration: none;
}

.logo span { color: var(--real); }

/* Controls */

.btn {
  min-height: 34px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--text);
  font: 500 13px var(--sans);
  text-decoration: none;
  cursor: pointer;
}

.btn:hover { background: var(--raised); color: var(--text-strong); }
.btn-primary { background: var(--text); border-color: var(--text); color: var(--bg); }
.btn-primary:hover { background: var(--text-strong); color: var(--bg); }
.btn-block { width: 100%; min-height: 42px; }
.btn-small { min-height: 28px; padding: 0 10px; font-size: 12px; }
.btn-danger { border-color: #5a3222; color: var(--safe); }
.btn-danger:hover { background: #24160f; color: var(--safe); }
.btn-text { background: none; border: none; padding: 0; color: var(--real); font: 500 13px var(--sans); text-decoration: underline; cursor: pointer; }

input[type="search"], input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="url"], textarea {
  height: 36px;
  padding: 0 10px;
  border-radius: 6px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  font: 13px var(--sans);
}

textarea { height: auto; min-height: 80px; padding: 8px 10px; }
input::placeholder, textarea::placeholder { color: #66716a; }
input[type="checkbox"], input[type="radio"] { width: 16px; height: 16px; accent-color: var(--real); margin: 0; }

.segmented { display: flex; border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; }
.segmented a {
  min-width: 40px;
  height: 32px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: 12px var(--mono);
  color: var(--muted);
  text-decoration: none;
}

.segmented a[aria-current="true"] { background: var(--text); color: var(--bg); font-weight: 600; }

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: var(--raised);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  font-size: 11px;
  font-weight: 500;
  text-decoration: none;
}

.messages { list-style: none; margin: 0; padding: 10px 20px 0; }
.message { padding: 10px 14px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--raised); overflow-wrap: anywhere; }

.live { display: inline-flex; align-items: center; gap: 6px; color: var(--ok); }
.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.live[data-state="offline"] { color: var(--safe); }
body:has(#stream-pause:checked) .live { color: var(--muted); }
body:has(#stream-pause:checked) .live::after { content: " (paused)"; }

/* Dashboard shell */

.tail { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

.tail-top {
  height: 52px;
  flex-shrink: 0;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 24px;
  border-bottom: 1px solid var(--line);
}

.tabs { display: flex; align-self: stretch; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.tab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  white-space: nowrap;
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
}

.tab:hover { color: var(--text-strong); background: var(--surface); }
.tab[aria-current="page"] { background: var(--raised); color: var(--text-strong); font-weight: 500; }
.tab-rate { font: 11px var(--mono); }
.tab-add { font-size: 18px; padding: 0 14px; }
.single-client { font-weight: 500; color: var(--text-strong); }

.top-right { margin-left: auto; display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
.top-link { color: var(--muted); font-size: 13px; text-decoration: none; }
.top-link:hover { color: var(--text-strong); }

.statusline {
  height: 30px;
  flex-shrink: 0;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  font: 11px var(--mono);
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
}

.statusline-right { margin-left: auto; }

.tail-body { flex-grow: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 380px; }

/* Stream */

.stream { display: flex; flex-direction: column; min-width: 0; min-height: 0; border-right: 1px solid var(--line); }

.stream-bar {
  min-height: 52px;
  flex-shrink: 0;
  padding: 8px 20px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  border-bottom: 1px solid var(--line);
}

.stream-bar h1 { margin: 0 12px 0 0; font: 700 18px var(--display); letter-spacing: -0.2px; color: var(--text-strong); }

.chips { display: flex; gap: 6px; margin: 0; padding: 0; border: none; }
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips label {
  height: 30px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  border-radius: 15px;
  border: 1px solid var(--line-strong);
  font-size: 12px;
  cursor: pointer;
}

.chips .chip-real { color: var(--real); }
.chips .chip-safe { color: var(--safe); }
.chips input:checked + label { background: var(--text); border-color: var(--text); color: var(--bg); font-weight: 500; }
.chips input:focus-visible + label { outline: 2px solid var(--real); outline-offset: 2px; }

.stream-q-label { margin-left: auto; font-size: 12px; color: var(--muted); }
#stream-q { width: 250px; font-family: var(--mono); font-size: 12px; }
.pause-toggle { position: absolute; opacity: 0; pointer-events: none; }
.pause-toggle:checked + .pause-label { background: var(--safe); border-color: var(--safe); color: var(--bg); }
.pause-toggle:focus-visible + .pause-label { outline: 2px solid var(--real); outline-offset: 2px; }

.stream-scroll { flex-grow: 1; min-height: 0; overflow-y: auto; }
.stream-table { width: 100%; border-collapse: collapse; font: 12px var(--mono); }
.stream-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  height: 32px;
  padding: 0 12px 0 0;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-weight: 400;
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
}

.stream-table th:first-child, .stream-table td:first-child { padding-left: 20px; }
.stream-table td {
  height: 31px;
  padding: 0 12px 0 0;
  border-bottom: 1px solid var(--raised);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

.stream-table tbody tr:first-child { background: #151a17; }
.stream-table tbody tr:hover { background: var(--surface); }
.verdict { font-weight: 600; }
.verdict.real { color: var(--real); }
.verdict.safe { color: var(--safe); }
.stream-table .empty { padding: 20px; font-family: var(--sans); }

/* Sidebar */

.side { min-height: 0; overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 22px; background: var(--surface-side); }
.side-block { display: flex; flex-direction: column; gap: 8px; }
.side-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.side-title { margin: 0; font: 700 15px var(--display); color: var(--text-strong); }
.side-subtitle { margin: 0; font: 700 13px var(--display); color: #b9c3bc; }
.small-link { font-size: 12px; }

.split-bar { display: flex; height: 10px; border-radius: 2px; overflow: hidden; background: var(--safe); }
.split-bar.thin { height: 6px; width: 70px; flex-shrink: 0; }
.bar-real { background: var(--real); }
.bar-empty { flex-grow: 1; background: var(--line); }

.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.tile { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; display: flex; flex-direction: column; gap: 2px; }
.tile-label { font-size: 11px; color: var(--muted); }
.tile-value { font: 500 20px var(--mono); color: var(--text-strong); }
.tile-value.real { color: var(--real); }
.tile-value.safe { color: var(--safe); }

.reasons { display: grid; grid-template-columns: minmax(0, 1fr) 100px 34px; gap: 7px 10px; align-items: center; font-size: 12px; }
.reason-track { height: 6px; background: var(--line); }
.reason-fill { display: block; height: 6px; background: var(--safe); }

.side-list { list-style: none; margin: 0; padding: 0; }
.campaign-row, .key-row {
  min-height: 32px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}

.campaign-row a { flex-grow: 1; min-width: 0; color: var(--text); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.campaign-row a:hover { color: var(--text-strong); text-decoration: underline; }
.key-row { padding: 4px 0; }
.key-name { flex-grow: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.key-form { display: flex; gap: 8px; padding-top: 4px; }
.key-form input { flex-grow: 1; min-width: 0; height: 30px; font-size: 12px; }
.new-key { margin: 0; padding: 10px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--raised); font-size: 12px; }
.new-key code { display: block; margin-top: 6px; color: var(--text-strong); overflow-wrap: anywhere; }

@media (max-width: 1100px) {
  .tail-body { grid-template-columns: minmax(0, 1fr) 320px; }
  .top-link { display: none; }
  .stream-table th:nth-child(5), .stream-table td:nth-child(5) { display: none; }
}

@media (max-width: 820px) {
  .tail { height: auto; overflow: visible; }
  .tail-body { grid-template-columns: minmax(0, 1fr); }
  .stream { border-right: none; }
  .stream-scroll { max-height: 60vh; }
  .stream-q-label { margin-left: 0; }
  #stream-q { width: 100%; }
  .stream-table th:nth-child(2), .stream-table td:nth-child(2),
  .stream-table th:nth-child(4), .stream-table td:nth-child(4) { display: none; }
}

/* Auth pages: allauth entrance layout (sign in, sign up, reset, verify) */

.auth-page { min-height: 100vh; display: flex; flex-direction: column; }

.auth-top {
  height: 52px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.auth-top-nav { display: flex; gap: 20px; font-size: 13px; }
.auth-top-nav a { color: var(--muted); text-decoration: none; }
.auth-top-nav a:hover { color: var(--text-strong); }

.auth-main { flex-grow: 1; display: flex; justify-content: center; padding: 64px 16px; }
.auth-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; }
.auth-card h1 { margin: 0; font: 700 28px var(--display); letter-spacing: -0.4px; color: var(--text-strong); }
.auth-card h2 { margin: 6px 0 0; font: 700 16px var(--display); color: var(--text-strong); }
.auth-card p { margin: 0; color: var(--muted); }
.auth-card form { display: flex; flex-direction: column; gap: 14px; padding: 20px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.auth-card hr, .manage-main hr { width: 100%; border: none; border-top: 1px solid var(--line); margin: 4px 0; }
.auth-messages, .manage-messages { padding: 0; }

/* Form rows: Django's as_div (<div><label><input><helptext><errorlist>) and the field element */

.auth-card form > div:not(.field-check),
.manage-main form > div:not(.field-check),
.field { display: flex; flex-direction: column; gap: 6px; }

.auth-card form > div:not(.field-check) > label,
.manage-main form > div:not(.field-check) > label,
.field > label { font-size: 12px; font-weight: 500; color: #b9c3bc; }

/* Django as_div puts the checkbox after its label; the field element puts it before. */
.auth-card form > div:has(> input[type="checkbox"]),
.manage-main form > div:has(> input[type="checkbox"]) { flex-direction: row-reverse; justify-content: flex-end; align-items: center; gap: 8px; }

div.field-check { display: flex; flex-direction: row; align-items: center; gap: 10px; }
div.field-check > label { font-size: 13px; font-weight: 400; color: var(--text); }

.auth-card input:not([type="checkbox"]):not([type="radio"]),
.manage-main form input:not([type="checkbox"]):not([type="radio"]) { width: 100%; height: 38px; }

.helptext, .helptext ul { font-size: 12px; color: var(--muted); }
.helptext ul { margin: 0; padding-left: 16px; }
.errorlist { list-style: none; margin: 0; padding: 0; color: var(--safe); font-size: 13px; }
.errorlist.nonfield { padding: 10px 12px; border: 1px solid #5a3222; border-radius: 6px; background: #1a120d; }

.alert { padding: 10px 14px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--raised); }
.badge { font: 500 10px var(--mono); letter-spacing: 1px; text-transform: uppercase; padding: 2px 6px; border: 1px solid var(--line-strong); border-radius: 4px; color: var(--muted); }
.badge-ok { border-color: #2f5a3a; color: var(--ok); }
.badge-warn { border-color: #5a3222; color: var(--safe); }

/* Account pages: allauth manage layout */

.topbar { height: 52px; padding: 0 20px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.topnav { display: flex; align-items: center; gap: 22px; font-size: 13px; }
.topnav a:not(.logo) { color: var(--muted); text-decoration: none; }
.topnav a:not(.logo):hover { color: var(--text-strong); }

.manage-shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: calc(100vh - 52px); }
.manage-nav { padding: 24px 20px; border-right: 1px solid var(--line); background: var(--surface-side); display: flex; flex-direction: column; gap: 10px; }
.manage-nav ul { list-style: none; margin: 0; padding: 0; }
.manage-nav a { display: block; padding: 8px 10px; border-radius: 6px; color: var(--text); text-decoration: none; }
.manage-nav a:hover { background: var(--surface); }
.manage-nav a[aria-current="page"] { background: var(--raised); color: var(--text-strong); }
.manage-main { padding: 24px 32px 40px; max-width: 700px; display: flex; flex-direction: column; gap: 14px; }
.manage-main h1 { margin: 0; font: 700 24px var(--display); color: var(--text-strong); }
.manage-main h2 { margin: 10px 0 0; font: 700 16px var(--display); color: var(--text-strong); }
.manage-main p { margin: 0; color: var(--muted); }

/* Account pages are settings, not a single call to action: fields take full
   lines and the submit buttons (direct form children in allauth's templates)
   size to their label and share one row. */
.manage-main form { display: flex; flex-flow: row wrap; align-items: center; gap: 14px 8px; }
.manage-main form > :not(.btn):not(.btn-text) { flex-basis: 100%; }
.manage-main .btn-block { width: auto; }

.panel { display: flex; flex-direction: column; gap: 10px; padding-top: 12px; border-top: 1px solid var(--line); }
.section-title { margin: 0; font: 700 16px var(--display); color: var(--text-strong); }
.panel-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { padding: 0 12px 8px 0; border-bottom: 1px solid var(--line-strong); text-align: left; font: 400 10px var(--mono); letter-spacing: 1px; text-transform: uppercase; color: var(--muted); }
.data-table td { height: 38px; padding: 0 12px 0 0; border-bottom: 1px solid var(--line); }

@media (max-width: 800px) {
  .manage-shell { grid-template-columns: minmax(0, 1fr); }
  .manage-nav { border-right: none; border-bottom: 1px solid var(--line); }
  .manage-main { padding: 20px 16px; }
}
