/* MailTrace — instrument-panel styling.
   Mono carries the identity: every measured value, token and timestamp is set
   in the mono face; prose is set in the UI face. Amber marks anything the
   system guessed rather than observed. */

:root {
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-2: #f6f8fa;
  --line: #dbe1e8;
  --line-strong: #c3ccd6;
  --ink: #131a22;
  --ink-2: #4a5866;
  --ink-3: #77848f;

  --signal: #16706b;
  --signal-soft: #d7ecea;
  --estimate: #9a6300;
  --estimate-soft: #fbeed6;
  --click: #5647c9;
  --click-soft: #e3e0fa;
  --danger: #b03a30;
  --danger-soft: #fadedb;

  --radius: 10px;
  --rail: 236px;
}

html[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #151b23;
  --surface-2: #1b232d;
  --line: #262f3b;
  --line-strong: #38434f;
  --ink: #e4ebf2;
  --ink-2: #a4b1bf;
  --ink-3: #7a8796;

  --signal: #57cbc2;
  --signal-soft: #123634;
  --estimate: #e0a955;
  --estimate-soft: #3a2c12;
  --click: #a79bfb;
  --click-soft: #251f4d;
  --danger: #f08a80;
  --danger-soft: #3d1c19;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--signal); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; border-radius: 4px; }

h1, h2, h3 { margin: 0 0 .4rem; line-height: 1.25; letter-spacing: -0.015em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; }
p { margin: 0 0 .8rem; color: var(--ink-2); }

/* ---- Eyebrow: the mono label that heads every block ---- */
.eyebrow {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin: 0 0 .5rem;
  display: block;
}

/* ---- Shell ---- */
.shell { display: flex; min-height: 100vh; }

.rail {
  width: var(--rail);
  flex: 0 0 var(--rail);
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 18px 14px 24px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 9px; padding: 0 6px 16px; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 6px;
  background: var(--signal); position: relative; flex: none;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 9px 6px auto 6px; height: 2px;
  background: var(--surface); box-shadow: 0 5px 0 var(--surface);
}
.brand-name { font-family: var(--font-mono); font-size: 13.5px; font-weight: 600; letter-spacing: -.01em; }

.nav-group { margin-bottom: 14px; }
.nav-group > .eyebrow { padding-left: 8px; }
.nav a {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 9px; border-radius: 7px;
  color: var(--ink-2); font-size: 14px; text-decoration: none;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.on { background: var(--signal-soft); color: var(--signal); font-weight: 550; }
.nav svg { width: 15px; height: 15px; flex: none; }

.main { flex: 1; min-width: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 14px 26px; border-bottom: 1px solid var(--line);
  background: var(--surface); position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-family: var(--font-mono); font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.page { padding: 22px 26px 60px; max-width: 1180px; }

/* ---- Cards ---- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px;
}
.card-tight { padding: 13px 15px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }

.grid { display: grid; gap: 14px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }

/* ---- Stat ---- */
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat-value {
  font-family: var(--font-mono); font-size: 1.85rem; font-weight: 600;
  font-variant-numeric: tabular-nums; letter-spacing: -.02em; line-height: 1.1;
}
.stat-label { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; }
.stat-foot { font-size: 11.5px; color: var(--ink-3); margin-top: 7px; font-family: var(--font-mono); }

/* ---- The signature: uncertainty made visible ---- */
.est {
  border-bottom: 1px dashed var(--estimate);
  color: inherit; cursor: help; white-space: nowrap;
}
.est-tag {
  font-family: var(--font-mono); font-size: 8.5px; letter-spacing: .06em;
  text-transform: uppercase; color: var(--estimate);
  vertical-align: super; margin-left: 3px;
}
.unknown { color: var(--ink-3); font-style: italic; }

.caveat {
  border-left: 2px solid var(--estimate);
  background: var(--estimate-soft);
  padding: 10px 13px; border-radius: 0 8px 8px 0;
  font-size: 13px; color: var(--ink-2); margin: 0 0 14px;
}
.caveat strong { color: var(--ink); }

/* ---- Badges ---- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .05em;
  text-transform: uppercase; padding: 3px 7px; border-radius: 5px;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line);
}
.badge-on   { background: var(--signal-soft); color: var(--signal); border-color: transparent; }
.badge-warn { background: var(--estimate-soft); color: var(--estimate); border-color: transparent; }
.badge-bad  { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge-click{ background: var(--click-soft); color: var(--click); border-color: transparent; }

/* ---- Forms ---- */
label { display: block; font-size: 13px; font-weight: 550; margin-bottom: 5px; color: var(--ink); }
.hint { font-size: 12px; color: var(--ink-3); margin: 4px 0 0; }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=url], select, textarea {
  width: 100%; padding: 8px 11px; font-size: 14px; font-family: inherit;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 7px;
}
textarea { resize: vertical; min-height: 90px; }
textarea.code, input.mono { font-family: var(--font-mono); font-size: 13px; }
input:focus, select:focus, textarea:focus { border-color: var(--signal); outline: none; box-shadow: 0 0 0 3px var(--signal-soft); }

.field { margin-bottom: 13px; }
.row { display: grid; gap: 13px; grid-template-columns: 1fr 1fr; }
.row-3 { display: grid; gap: 13px; grid-template-columns: repeat(3, 1fr); }

.check { display: flex; gap: 9px; align-items: flex-start; margin-bottom: 10px; }
.check input { margin-top: 3px; flex: none; }
.check label { margin: 0; font-weight: 500; }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px; border-radius: 7px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); font-size: 13.5px; font-weight: 550;
  font-family: inherit; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--signal); border-color: var(--signal); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); background: var(--signal); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.actions { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left; font-family: var(--font-mono); font-size: 10.5px;
  letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3);
  padding: 10px 13px; border-bottom: 1px solid var(--line); font-weight: 500; white-space: nowrap;
}
td { padding: 11px 13px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); font-size: 12.5px; }
.truncate { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Signal rail: the event timeline ---- */
.rail-events { list-style: none; margin: 0; padding: 0 0 0 22px; position: relative; }
.rail-events::before {
  content: ""; position: absolute; left: 5px; top: 6px; bottom: 6px;
  width: 1px; background: var(--line-strong);
}
.rail-events li { position: relative; padding: 0 0 16px; }
.rail-events li::before {
  content: ""; position: absolute; left: -21px; top: 5px;
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--line-strong);
}
/* Solid tick: this system observed it. Hollow amber tick: inferred from a request. */
.rail-events li.reported::before { background: var(--signal); border-color: var(--signal); }
.rail-events li.estimated::before { border-color: var(--estimate); border-style: dashed; }
.rail-events li.flagged::before { border-color: var(--estimate); background: var(--estimate-soft); }
.rail-events li.bad::before { border-color: var(--danger); background: var(--danger); }
.rail-events li.click::before { border-color: var(--click); background: var(--click); }

.event-head { display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap; }
.event-time { font-family: var(--font-mono); font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.event-meta { font-size: 12.5px; color: var(--ink-2); margin-top: 3px; }
.event-note { font-size: 12.5px; color: var(--estimate); margin-top: 3px; }

/* ---- Charts ---- */
.chart { width: 100%; height: auto; display: block; }
.bars { list-style: none; margin: 0; padding: 0; }
.bars li { margin-bottom: 9px; }
.bar-top { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 3px; }
.bar-top .n { font-family: var(--font-mono); color: var(--ink-3); font-variant-numeric: tabular-nums; }
.bar-track { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--line); }
.bar-fill { height: 100%; background: var(--signal); }

/* ---- Flash / toast ---- */
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 60; display: flex; flex-direction: column; gap: 8px; max-width: 380px; }
.toast {
  background: var(--surface); border: 1px solid var(--line-strong); border-left-width: 3px;
  border-radius: 8px; padding: 10px 13px; font-size: 13.5px;
  box-shadow: 0 6px 20px rgba(10, 20, 30, .12);
}
.toast.success { border-left-color: var(--signal); }
.toast.error { border-left-color: var(--danger); }

/* ---- Empty states ---- */
.empty { text-align: center; padding: 42px 20px; color: var(--ink-2); }
.empty .eyebrow { color: var(--ink-3); }
.empty h3 { margin-bottom: 6px; color: var(--ink); }

/* ---- Auth / installer ---- */
.bare { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 26px 18px; }
.bare-card { width: 100%; max-width: 430px; }
.bare-wide { max-width: 720px; }

/* ---- Misc ---- */
.pill-list { display: flex; gap: 7px; flex-wrap: wrap; }
.filters { display: grid; gap: 10px; grid-template-columns: repeat(4, 1fr); align-items: end; }
.pagination { display: flex; gap: 7px; align-items: center; justify-content: center; padding: 14px 0; font-size: 13px; }
.transcript {
  font-family: var(--font-mono); font-size: 12px; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 8px; padding: 11px 13px;
  max-height: 260px; overflow: auto; white-space: pre-wrap; word-break: break-word; color: var(--ink-2);
}
.preview-frame {
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
  padding: 14px; max-height: 460px; overflow: auto; color: #111;
}
.split { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; align-items: start; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 14px; font-size: 13.5px; }
.kv dt { color: var(--ink-3); font-size: 12.5px; }
.kv dd { margin: 0; }
.spinner { display: inline-block; width: 13px; height: 13px; border: 2px solid var(--line-strong); border-top-color: var(--signal); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.is-loading { pointer-events: none; opacity: .7; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

@media (max-width: 1000px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .split { grid-template-columns: 1fr; }
  .filters { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .rail {
    width: 100%; flex: none; height: auto; position: static;
    border-right: none; border-bottom: 1px solid var(--line); padding: 12px;
  }
  .nav { display: flex; flex-wrap: wrap; gap: 5px; }
  .nav a { padding: 6px 10px; font-size: 13px; }
  .nav-group > .eyebrow { display: none; }
  .brand { padding-bottom: 10px; }
  .page, .topbar { padding-left: 15px; padding-right: 15px; }
  .grid-4, .grid-3, .grid-2, .row, .row-3, .filters { grid-template-columns: 1fr; }
  .toasts { left: 12px; right: 12px; max-width: none; }
}
