/* EchoShield dashboard — operator console styling
 *
 * Hand-rolled CSS. Dark, dense, monospace. Designed for 1280px+ viewports
 * first; reflows gracefully down to ~720px.
 */

:root {
  --bg: #0f1115;
  --bg-elev: #161922;
  --bg-elev-2: #1d2130;
  --border: #2a3042;
  --text: #e6e9f0;
  --text-muted: #8c93a8;
  --accent: #4f8cff;
  --accent-hover: #6ba0ff;
  --good: #4ade80;
  --warn: #f5b942;
  --bad: #f87171;
  --crit: #ef4444;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
               Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

code, .mono, pre, .num, input[type="number"], input[type="text"], input[type="password"] {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco, Consolas,
               "Liberation Mono", "Courier New", monospace;
}

/* ── topbar ─────────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  gap: 32px;
  padding: 12px 24px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}

.brand {
  display: flex; align-items: center; gap: 10px;
}
.brand-logo {
  /* The horizontal logo is 485×138 native; we display it at a height
     that matches the topbar (≈ 26-28px). Width auto-scales. */
  height: 28px;
  width: auto;
  display: block;
}
.brand-version {
  color: var(--text-muted); font-size: 12px;
  background: var(--bg-elev-2); padding: 2px 8px; border-radius: 4px;
}

.topnav {
  display: flex; gap: 4px; flex: 1;
}
.topnav a {
  padding: 6px 14px; color: var(--text-muted); text-decoration: none;
  border-radius: 6px; font-weight: 500;
}
.topnav a:hover { color: var(--text); background: var(--bg-elev-2); }
.topnav a.active { color: var(--text); background: var(--bg-elev-2); }

.userbar {
  display: flex; align-items: center; gap: 12px;
  color: var(--text-muted);
}

/* ── main ───────────────────────────────────────────────────────────────── */

main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

.pane {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 16px;
}

h1, h2, h3 { margin: 0 0 12px 0; font-weight: 600; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }

.muted { color: var(--text-muted); }
.error { color: var(--bad); padding: 8px 0; font-size: 13px; }
.test-result {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.5;
  border: 1px solid var(--border);
  background: var(--bg-elev);
}
.test-result.ok    { border-color: var(--good); color: var(--good); }
.test-result.fail  { border-color: var(--bad);  color: var(--bad); }
.test-result.running {
  border-color: var(--text-muted); color: var(--text-muted);
}
.test-result .test-meta {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-weight: normal;
}
.test-result .spinner {
  display: inline-block;
  width: 10px; height: 10px;
  border: 2px solid var(--text-muted);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 6px;
  vertical-align: -1px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.hidden { display: none !important; }

/* ── tables ─────────────────────────────────────────────────────────────── */

table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.scans-table { table-layout: fixed; }
.scans-table td {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
th {
  text-align: left; padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted); font-weight: 600;
  background: var(--bg-elev-2);
}
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
tr:hover td { background: var(--bg-elev-2); }
tr:last-child td { border-bottom: none; }

/* ── badges ─────────────────────────────────────────────────────────────── */

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.5px;
}
.badge.good   { background: rgba(74, 222, 128, 0.15); color: var(--good); }
.badge.warn   { background: rgba(245, 185, 66, 0.15); color: var(--warn); }
.badge.bad    { background: rgba(248, 113, 113, 0.15); color: var(--bad); }
.badge.crit   { background: rgba(239, 68, 68, 0.20); color: var(--crit); }
.badge.muted  { background: var(--bg-elev-2); color: var(--text-muted); }
.badge.accent { background: rgba(79, 140, 255, 0.15); color: var(--accent); }

/* ── buttons ────────────────────────────────────────────────────────────── */

button, .btn {
  font-family: inherit; font-size: 13px; font-weight: 500;
  padding: 8px 14px; border-radius: 6px;
  border: 1px solid transparent; cursor: pointer;
  transition: all 0.15s ease;
}
.btn-primary {
  background: var(--accent); color: white; border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost {
  background: transparent; color: var(--text-muted); border-color: var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-muted); }
.btn-secondary {
  background: transparent; color: var(--accent); border-color: var(--accent);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--accent); color: white;
}
.btn-secondary:disabled { opacity: 0.6; cursor: wait; }
.btn-tiny { padding: 2px 8px; font-size: 11px; line-height: 1.4; border-radius: 3px; }
.btn-danger {
  background: transparent; color: var(--bad); border-color: rgba(248, 113, 113, 0.4);
}
.btn-danger:hover { background: rgba(248, 113, 113, 0.1); }

/* Senders view — a lighter-weight search input + filter chips. */
.input-ghost {
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 13px;
  width: auto;
}
.input-ghost:focus { outline: none; border-color: var(--accent); }
.chip {
  background: var(--bg-elev-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 3px 10px;
  font-size: 12px;
  cursor: pointer;
}
.chip:hover { color: var(--text); border-color: var(--text-muted); }
.chip.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* ── inputs ─────────────────────────────────────────────────────────────── */

input[type="text"], input[type="password"], input[type="number"], select {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
}
input:focus { outline: none; border-color: var(--accent); }

label {
  display: block; margin-bottom: 10px;
}
label > span {
  display: block; font-size: 12px; color: var(--text-muted);
  margin-bottom: 4px;
}

label.checkbox {
  display: flex; align-items: center; gap: 8px;
}
label.checkbox > span { display: inline; margin: 0; }
label.checkbox input { width: auto; }

/* ── layout helpers ─────────────────────────────────────────────────────── */

.grid-2 {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
.grid-2 .span-2 { grid-column: 1 / -1; }

.toolbar {
  display: flex; gap: 8px; align-items: center;
  padding: 12px 0;
  flex-wrap: wrap;
}
.toolbar .grow { flex: 1; }

/* ── login overlay ──────────────────────────────────────────────────────── */

/* When the login overlay is showing, hide the topbar and footer
   so the user can't see the internal nav or footer through the
   semi-transparent backdrop. Toggled by app.js via
   `document.body.classList.add('is-logged-out')`. */
body.is-logged-out .topbar,
body.is-logged-out .site-footer {
  display: none;
}

.overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.login-card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 12px; padding: 32px; min-width: 360px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center;
}
.login-logo {
  /* The horizontal logo is 485×138 native; on the login card we
     display it larger than in the topbar to make the brand identity
     the focal point. */
  height: 64px;
  width: auto;
  display: block;
  margin-bottom: 16px;
}
.login-card h1 { margin-bottom: 4px; }
.login-card p.muted { margin-bottom: 20px; }
.login-card label { width: 100%; }
.login-card input[type="text"],
.login-card input[type="password"],
.login-card button[type="submit"] { width: 100%; }
.login-card #login-error { width: 100%; }

/* ── modals ─────────────────────────────────────────────────────────────── */

.modal-card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 12px; padding: 24px; min-width: 500px;
  max-width: 90vw; max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal-card.wide { min-width: 700px; }
.modal-card h2 { margin-bottom: 16px; }
.modal-card.wide { min-width: 800px; max-width: 95vw; }
.modal-actions {
  display: flex; gap: 8px; justify-content: flex-end;
  margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border);
}

/* ── email view (inside scan modal) ─────────────────────────────────── */

.email-headers {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  margin: 8px 0;
  font-size: 12px;
  max-height: 180px;
  overflow-y: auto;
}
.email-headers div { padding: 2px 0; }
.email-headers .h-k { color: var(--text-muted); display: inline-block; min-width: 120px; }

.email-body {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 400px;
  overflow-y: auto;
  margin: 8px 0;
}

.email-html {
  width: 100%;
  height: 400px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
}

.feedback-actions {
  display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px;
}
.feedback-actions button {
  flex: 1; min-width: 140px;
}

/* ── scan detail view ───────────────────────────────────────────────────── */

.scan-field {
  display: grid; grid-template-columns: 160px 1fr; gap: 8px;
  padding: 6px 0; border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.scan-field:last-child { border-bottom: none; }
.scan-field .k { color: var(--text-muted); }
.scan-field .v { word-break: break-all; }
.scan-field pre {
  margin: 0; padding: 8px; background: var(--bg); border-radius: 4px;
  overflow-x: auto; font-size: 12px;
}

/* ── stat tiles ─────────────────────────────────────────────────────────── */

.stat-tiles {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.stat-tile {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}
.stat-tile .num {
  font-size: 28px; font-weight: 600;
  font-family: ui-monospace, monospace;
}
.stat-tile .lbl {
  font-size: 12px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.5px;
  margin-top: 4px;
}

/* ── site footer ──────────────────────────────────────────────────────────── */

.site-footer {
  margin-top: 32px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
}
.site-footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}
.site-footer a {
  color: var(--accent);
  text-decoration: none;
}
.site-footer a:hover { text-decoration: underline; }

/* ── responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 720px) {
  .topbar { padding: 10px 14px; gap: 14px; flex-wrap: wrap; }
  .topnav { order: 3; width: 100%; }
  main { padding: 14px; }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-2 .span-2 { grid-column: auto; }
  .modal-card, .modal-card.wide { min-width: 90vw; padding: 16px; }
  th, td { padding: 8px 6px; font-size: 12px; }
  .login-logo { height: 48px; }
  .site-footer { padding: 12px 14px; font-size: 11px; }
}
