:root {
  color-scheme: dark;
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #182235;
  --border: #29364d;
  --text: #f3f4f6;
  --muted: #9ca3af;
  --brand: #37d67a;
  --brand-dark: #16a34a;
  --blue: #60a5fa;
  --amber: #fbbf24;
  --red: #f87171;
  --radius: 16px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; color: var(--text); background: radial-gradient(circle at top left, #14223d 0, var(--bg) 38rem); }
a { color: #9dc5ff; text-decoration: none; }
a:hover { color: white; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: .4rem; font-size: clamp(2rem, 5vw, 3rem); letter-spacing: -.04em; }
h2 { margin-bottom: .25rem; font-size: 1.2rem; }
code { overflow-wrap: anywhere; color: #bcf7d0; }
footer { padding: 2.5rem 1rem; color: var(--muted); text-align: center; font-size: .85rem; }

.topbar { position: sticky; z-index: 10; top: 0; display: flex; align-items: center; justify-content: space-between; gap: 2rem; min-height: 76px; padding: .8rem max(1rem, calc((100vw - 1180px) / 2)); border-bottom: 1px solid rgba(255,255,255,.08); background: rgba(11,17,32,.88); backdrop-filter: blur(16px); }
.brand { display: flex; align-items: center; gap: .7rem; color: white; font-weight: 750; font-size: 1.15rem; }
.brand-mark { display: grid; place-items: center; width: 40px; height: 40px; color: #082615; border-radius: 12px; background: var(--brand); font-weight: 900; }
nav { display: flex; align-items: center; gap: 1.3rem; }
.container { width: min(1180px, calc(100% - 2rem)); min-height: calc(100vh - 160px); margin: 0 auto; padding: 3rem 0; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 2rem; margin-bottom: 2rem; }
.detail-heading { align-items: center; }
.heading-actions { display: flex; align-items: center; gap: .8rem; }
.eyebrow { margin-bottom: .45rem; color: var(--brand); font-size: .75rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.muted { color: var(--muted); }
.lead { color: #cbd5e1; font-size: 1.15rem; }
.back-link { display: inline-block; margin-bottom: 1.2rem; color: var(--muted); }

.button { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; padding: .65rem 1rem; border: 1px solid transparent; border-radius: 10px; cursor: pointer; font: inherit; font-weight: 700; transition: .15s ease; }
.button:hover { transform: translateY(-1px); }
.button-primary { color: #07180f; background: var(--brand); }
.button-primary:hover { color: #07180f; background: #57e18e; }
.button-secondary { color: white; border-color: var(--border); background: var(--surface-2); }
.button-ghost { color: #d1d5db; background: transparent; }
.button-danger { color: white; background: #b91c1c; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { min-height: 130px; padding: 1.25rem; border: 1px solid var(--border); border-radius: var(--radius); background: linear-gradient(145deg, rgba(255,255,255,.04), rgba(255,255,255,.01)); box-shadow: 0 16px 40px rgba(0,0,0,.13); }
.stat-card span { color: var(--muted); font-size: .85rem; }
.stat-card strong { display: block; margin-top: .8rem; font-size: 2.25rem; }
.stat-total strong { color: var(--brand); }
.stat-opened strong { color: var(--blue); }
.stat-warning strong { color: var(--amber); }
.stat-followup strong { color: #c084fc; }
.stat-email-opened strong { color: var(--brand); }
.stat-email-unopened strong { color: #94a3b8; }

.panel, .form-panel { margin-bottom: 1.5rem; border: 1px solid var(--border); border-radius: var(--radius); background: rgba(17,24,39,.88); box-shadow: 0 20px 50px rgba(0,0,0,.14); }
.panel { padding: 1.35rem; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.15rem; }
.panel-heading h2 { margin: 0; }
.filters { display: grid; grid-template-columns: minmax(240px, 1fr) minmax(180px, .4fr) auto auto; gap: .7rem; margin-bottom: 1.2rem; }
input, select, textarea { width: 100%; color: var(--text); border: 1px solid #34435c; border-radius: 10px; outline: none; background: #0d1626; font: inherit; }
input, select { min-height: 44px; padding: .65rem .8rem; }
textarea { padding: .75rem .8rem; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(55,214,122,.12); }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: .8rem; color: var(--muted); border-bottom: 1px solid var(--border); text-align: left; font-size: .75rem; letter-spacing: .08em; text-transform: uppercase; }
td { padding: 1rem .8rem; border-bottom: 1px solid rgba(41,54,77,.65); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(255,255,255,.025); }
td small { display: block; margin-top: .2rem; color: var(--muted); }
.table-title { color: white; font-weight: 750; }
.table-action { text-align: right; }
.status { display: inline-flex; align-items: center; padding: .35rem .65rem; color: #dbeafe; border: 1px solid #244678; border-radius: 999px; background: #132b4c; white-space: nowrap; font-size: .78rem; font-weight: 750; }
.status-large { padding: .55rem .85rem; font-size: .85rem; }
.status-accepted, .status-opened { color: #bbf7d0; border-color: #176038; background: #103822; }
.status-rejected, .status-no_response { color: #fecaca; border-color: #7f1d1d; background: #3c161b; }
.status-follow_up, .status-interview { color: #fde68a; border-color: #715814; background: #3d3214; }

.empty-state { padding: 4rem 1rem; text-align: center; }
.empty-state p { color: var(--muted); }
.empty-icon { display: grid; place-items: center; width: 52px; height: 52px; margin: 0 auto 1rem; color: #082615; border-radius: 50%; background: var(--brand); font-size: 1.4rem; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.5rem; }
.detail-list { margin: 0; }
.detail-list div { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 1rem; padding: .75rem 0; border-bottom: 1px solid rgba(41,54,77,.6); }
.detail-list div:last-child { border: 0; }
.detail-list dt { color: var(--muted); }
.detail-list dd { margin: 0; overflow-wrap: anywhere; }
.pre-line { white-space: pre-line; }

.form-panel fieldset { margin: 0; padding: 1.5rem; border: 0; border-bottom: 1px solid var(--border); }
.form-panel legend { padding: 0; font-size: 1.1rem; font-weight: 800; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem 1.25rem; margin-top: 1.2rem; }
.field { display: grid; gap: .45rem; }
.field > span { color: #d1d5db; font-size: .88rem; font-weight: 650; }
.field b { color: var(--brand); }
.field-wide { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: .7rem; padding: 1.4rem; }
.alert { margin-bottom: 1rem; padding: 1rem 1.2rem; border-radius: 12px; }
.alert p { margin: .2rem 0 0; }
.alert-error { color: #fecaca; border: 1px solid #7f1d1d; background: #3c161b; }
.alert-warning { color: #fde68a; border: 1px solid #715814; background: #3d3214; }
.tracking-state { padding: .4rem .7rem; color: #cbd5e1; border: 1px solid var(--border); border-radius: 999px; font-size: .8rem; font-weight: 750; }
.tracking-state.tracking-opened { color: #bbf7d0; border-color: #176038; background: #103822; }
.tracking-url { display: grid; gap: .45rem; }
.tracking-url > span { color: var(--muted); font-size: .85rem; }
.tracking-actions { display: flex; align-items: center; gap: .7rem; margin: .8rem 0 1.1rem; }
.tracking-stats { max-width: 720px; }
.privacy-note { margin: 1rem 0 0; color: var(--muted); font-size: .8rem; }
.interest-level, .interest-stars { color: var(--amber); white-space: nowrap; letter-spacing: .05em; }
.interest-score { display: inline-flex; padding: .3rem .55rem; color: #dbeafe; border: 1px solid #31527e; border-radius: 999px; background: #132b4c; white-space: nowrap; font-size: .78rem; font-weight: 800; }
.analysis-heading { align-items: flex-start; }
.interest-summary { display: grid; min-width: 130px; gap: .2rem; text-align: right; }
.interest-summary strong { font-size: 1rem; }
.interest-summary > span:last-child { color: var(--muted); font-size: .85rem; }
.analysis-callout { margin-bottom: 1.4rem; padding: 1rem 1.1rem; border: 1px solid #31527e; border-radius: 12px; background: rgba(19,43,76,.62); }
.analysis-callout p { margin: 0; }
.analysis-callout p + p { margin-top: .65rem; color: #dbeafe; }
.analysis-layout { display: grid; grid-template-columns: minmax(280px, .8fr) minmax(360px, 1.2fr); gap: 1.5rem; }
.analysis-layout h3, .opening-chart h3 { font-size: 1rem; }
.opening-timeline { position: relative; margin: 0; padding: 0; list-style: none; }
.opening-timeline::before { position: absolute; top: 1rem; bottom: 1rem; left: 1rem; width: 2px; content: ""; background: var(--border); }
.opening-timeline li { position: relative; display: grid; grid-template-columns: 70px 38px minmax(0, 1fr); align-items: center; min-height: 56px; gap: .65rem; }
.opening-timeline time { color: var(--muted); text-align: right; font-size: .75rem; }
.timeline-icon { position: relative; z-index: 1; display: grid; place-items: center; min-width: 34px; min-height: 34px; padding: .2rem; border: 1px solid var(--border); border-radius: 50%; background: var(--surface-2); font-size: .9rem; }
.opening-timeline strong { font-size: .88rem; }
.analysis-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 1rem; }
.analysis-stats div { grid-template-columns: minmax(0, 1fr) auto; }
.opening-chart { margin-top: 1.5rem; padding-top: 1.25rem; border-top: 1px solid var(--border); }
.chart-legend { display: flex; gap: 1rem; margin-bottom: .8rem; color: var(--muted); font-size: .75rem; }
.chart-legend span::before { display: inline-block; width: .65rem; height: .65rem; margin-right: .35rem; border-radius: 3px; content: ""; }
.legend-human::before { background: var(--brand); }
.legend-automated::before { background: #52627b; }
.chart-bars { display: flex; align-items: flex-end; gap: .75rem; min-height: 190px; padding: 1rem 1rem 0; overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; background: #0d1626; }
.chart-column { display: grid; grid-template-rows: 20px 125px 28px; flex: 1 0 58px; align-items: end; max-width: 90px; text-align: center; }
.chart-count { color: #cbd5e1; font-size: .75rem; }
.chart-bar { position: relative; width: 32px; height: var(--bar-height); max-height: 125px; min-height: 8px; margin: 0 auto; overflow: hidden; border-radius: 6px 6px 0 0; background: #52627b; }
.chart-human { position: absolute; right: 0; bottom: 0; left: 0; height: var(--human-share); background: var(--brand); }
.chart-column time { align-self: center; color: var(--muted); font-size: .7rem; }
.analysis-icon { font-size: 1.15rem; }
.analysis-summary { display: block; min-width: 220px; color: #dbeafe; font-weight: 650; }
.confidence { display: inline-flex; padding: .3rem .55rem; border: 1px solid var(--border); border-radius: 999px; white-space: nowrap; font-size: .78rem; font-weight: 800; }
.confidence-large { padding: .6rem .85rem; font-size: .9rem; }
.confidence-human { color: #bbf7d0; border-color: #176038; background: #103822; }
.confidence-proxy, .confidence-robot { color: #fecaca; border-color: #7f1d1d; background: #3c161b; }
.confidence-scanner { color: #fde68a; border-color: #715814; background: #3d3214; }
.confidence-unknown { color: #cbd5e1; background: #1e293b; }
.tracking-events { margin-top: 1.5rem; padding-top: 1.25rem; border-top: 1px solid var(--border); }
.tracking-events h3 { font-size: 1rem; }
.activity-summary { display: grid; gap: .2rem; text-align: right; }
.activity-summary span { color: var(--muted); font-size: .8rem; }
.activity-filters { display: grid; grid-template-columns: 1fr minmax(190px, .35fr) auto; gap: .7rem; margin: 1rem 0 1.4rem; }
.activity-timeline { position: relative; margin: 0; padding: 0; list-style: none; }
.activity-timeline::before { position: absolute; top: 1rem; bottom: 1rem; left: 92px; width: 2px; content: ""; background: var(--border); }
.activity-timeline li { position: relative; display: grid; grid-template-columns: 72px 40px minmax(0, 1fr); gap: .7rem; align-items: start; min-height: 72px; }
.activity-timeline time { padding-top: .45rem; color: var(--muted); text-align: right; font-size: .75rem; }
.activity-icon { position: relative; z-index: 1; display: grid; place-items: center; width: 36px; height: 36px; border: 1px solid var(--border); border-radius: 50%; background: var(--surface-2); }
.activity-timeline strong { margin-right: .5rem; }
.activity-timeline p { margin: .3rem 0; color: #cbd5e1; white-space: pre-line; }
.activity-timeline small { display: block; margin-top: .25rem; color: var(--muted); }
.activity-kind { padding: .15rem .4rem; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; font-size: .68rem; }
.compact-timeline li { min-height: 58px; }
.compact-timeline a, .compact-timeline .muted { display: block; margin-top: .15rem; font-size: .82rem; }
.activity-add { margin-top: 1.2rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.activity-add summary { cursor: pointer; color: #dbeafe; font-weight: 700; }
.activity-add form { display: grid; grid-template-columns: minmax(180px, .35fr) 1fr; gap: .8rem; margin-top: 1rem; }
.activity-add button { justify-self: start; }
.raw-user-agent { margin: 0; padding: 1rem; overflow-x: auto; color: #cbd5e1; border: 1px solid var(--border); border-radius: 10px; background: #0d1626; white-space: pre-wrap; overflow-wrap: anywhere; }
.danger-zone { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.3rem; border: 1px solid #63252c; border-radius: var(--radius); background: rgba(60,22,27,.6); }
.danger-zone h2 { font-size: 1rem; }
.danger-zone p { margin: 0; color: #fca5a5; font-size: .85rem; }
.opening-counts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.opening-counts div { padding: 1rem; border: 1px solid var(--border); border-radius: 12px; background: #0d1626; }
.opening-counts strong { display: block; color: var(--brand); font-size: 1.8rem; }
.opening-counts span { color: var(--muted); }
.ignored-row { opacity: .72; background: rgba(148,163,184,.05); }
.settings-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.settings-form > .button { justify-self: start; }
.settings-list { display: grid; gap: 1rem; }
.settings-card, .candidate-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 1rem; padding: 1rem; border: 1px solid var(--border); border-radius: 12px; background: #0d1626; }
.settings-card form:first-child { min-width: 0; }
.settings-card .form-grid { margin: 0; }
.settings-search { grid-template-columns: 1fr auto; }
.inline-actions, .candidate-actions { display: flex; align-items: center; gap: .7rem; margin-top: .8rem; }
.candidate-card { grid-template-columns: minmax(180px, .45fr) minmax(320px, 1fr) auto; }
.candidate-card p, .device-card p { margin: .3rem 0; color: #cbd5e1; }
.candidate-card small, .device-card small { color: var(--muted); }
.check-list { display: grid; gap: .8rem; }
.check-field { display: flex; align-items: center; gap: .65rem; }
.check-field input { width: 18px; min-height: 18px; }
.check-list .button { justify-self: start; margin-top: .5rem; }
.device-card { grid-template-columns: minmax(220px, 1fr) minmax(280px, .7fr) auto; }
.device-card form { display: flex; align-items: center; gap: .7rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 880px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-grid { grid-template-columns: 1fr; gap: 0; }
  .analysis-layout { grid-template-columns: 1fr; }
  .candidate-card, .device-card { grid-template-columns: 1fr; }
  .activity-filters { grid-template-columns: 1fr; }
  nav > a:not(.button) { display: none; }
}

@media (max-width: 640px) {
  .topbar { min-height: 66px; }
  .brand > span:last-child { display: none; }
  .container { width: min(100% - 1.2rem, 1180px); padding-top: 2rem; }
  .page-heading, .detail-heading { align-items: stretch; flex-direction: column; }
  .heading-actions { justify-content: space-between; }
  .stats-grid { gap: .6rem; }
  .stat-card { min-height: 108px; padding: 1rem; }
  .stat-card strong { font-size: 1.8rem; }
  .filters, .form-grid { grid-template-columns: 1fr; }
  .settings-form, .opening-counts { grid-template-columns: 1fr; }
  .candidate-actions, .device-card form { align-items: stretch; flex-direction: column; }
  .field-wide { grid-column: auto; }
  .detail-list div { grid-template-columns: 1fr; gap: .25rem; }
  .analysis-heading { align-items: stretch; }
  .interest-summary { text-align: left; }
  .analysis-stats { grid-template-columns: 1fr; }
  .activity-summary { text-align: left; }
  .activity-add form { grid-template-columns: 1fr; }
  .activity-timeline::before { left: 76px; }
  .activity-timeline li { grid-template-columns: 58px 34px minmax(0, 1fr); }
  .analysis-stats div { grid-template-columns: minmax(0, 1fr) auto; }
  .opening-timeline li { grid-template-columns: 62px 36px minmax(0, 1fr); }
  .danger-zone { align-items: stretch; flex-direction: column; }
  .tracking-actions { align-items: stretch; flex-direction: column; }
  .tracking-actions form, .tracking-actions .button { width: 100%; }
  .form-actions { flex-direction: column-reverse; }
  .form-actions .button { width: 100%; }
}
