:root {
  --bg:#0e1116;
  --panel:#0b0e14;
  --text:#e8eefc;
  --muted:#9aa6b2;
  --accent:#5ea0ff;
  --pos:#3ddc84;
  --neg:#ff4d4d;
  --border:#1a2230;
  --focus:rgba(94,160,255,0.35);
}

html { font-size: clamp(15px,1.2vw + 0.5rem,20px); }

body {
  margin:0;
  background:var(--bg);
  color:var(--text);
  font-family:system-ui,-apple-system,Segoe UI,Roboto,Inter,sans-serif;
}

body.modal-open {
  overflow:hidden;
}

.top-bar {
  position:sticky;
  top:0;
  z-index:1000;
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:8px 16px;
  background:var(--panel);
  border-bottom:1px solid var(--border);
}

.brand { font-weight:600; }

.nav-links { display:flex; gap:12px; overflow-x:auto; }

.nav-link {
  color:var(--text);
  text-decoration:none;
  padding:8px 12px;
  border-bottom:2px solid transparent;
}

.nav-link:hover,
.nav-link:focus {
  border-bottom-color:var(--accent);
  box-shadow:0 0 6px var(--accent);
}

.nav-link.active {
  border-bottom-color:var(--accent);
  box-shadow:0 0 6px var(--accent);
}

.wrap {
  max-width:1200px;
  margin:0 auto;
  padding:16px;
}

.card {
  background:var(--panel);
  border:1px solid var(--border);
  border-radius:12px;
  padding:16px;
  box-shadow:0 20px 60px rgba(0,0,0,.35);
}

.grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(220px,1fr)); gap:16px; }

label { display:block; color:var(--muted); margin-bottom:4px; }

input, select {
  width:100%;
  padding:8px 12px;
  border-radius:10px;
  border:1px solid var(--border);
  background:var(--panel);
  color:var(--text);
  font-size:1rem;
}

.row {
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(220px,1fr));
  gap:16px;
  margin-top:8px;
}

.actions {
  display:flex;
  gap:12px;
  flex-wrap:wrap;
  margin-top:16px;
  align-items:center;
}

button, .btn {
  cursor:pointer;
  background:var(--accent);
  border:none;
  color:#07101e;
  font-weight:600;
  padding:8px 12px;
  border-radius:10px;
  transition:box-shadow .2s;
}

button:hover, .btn:hover { box-shadow:0 0 8px var(--accent); }
button:disabled { opacity:.5; cursor:default; box-shadow:none; }

.btn {
  display:inline-block;
  background:#161616;
  border:1px solid #2b2b2b;
  color:var(--text);
  padding:6px 10px;
  font-weight:400;
}

.btn.btn-secondary,
button.btn-secondary {
  background:#1f2a3c;
  border:1px solid #2f3b52;
  color:var(--text);
}

.btn.btn-secondary:hover,
button.btn-secondary:hover {
  background:#25354b;
}

.btn.btn-danger,
button.btn-danger {
  background:#2b0f0f;
  border:1px solid #8b0000;
  color:#ffd7d7;
}

.btn.btn-danger:hover,
button.btn-danger:hover {
  background:#3a1212;
}

.btn-sm {
  padding:4px 8px;
  font-size:.85rem;
}

.btn.toggle-active {
  background:#0f3311;
  border-color:#1f6d3b;
  color:#daf7e3;
}

.btn:hover { background:#1e1e1e; }

.error-banner {
  background:#2b0f0f;
  border:1px solid #8b0000;
  color:#ffd7d7;
  padding:0.75rem 1rem;
  border-radius:10px;
  margin-bottom:0.75rem;
  font-weight:600;
  box-shadow:0 0 12px rgba(139,0,0,0.2);
}

.inline-error {
  display:flex;
  align-items:center;
  gap:0.5rem;
  flex-wrap:wrap;
  background:#2b0f0f;
  border:1px solid #8b0000;
  color:#ffd7d7;
  padding:0.5rem 0.75rem;
  border-radius:8px;
  margin-bottom:0.75rem;
  font-size:.95rem;
}

.inline-error[hidden] { display:none; }

.inline-error .btn {
  margin-left:auto;
}

.forward-header,
.archive-header {
  display:flex;
  align-items:center;
  justify-content:space-between;
  flex-wrap:wrap;
  gap:12px;
  margin-bottom:0.75rem;
}

.forward-note { margin-bottom:0.75rem; }

#forward-loading { margin-bottom:0.75rem; }

.icon-btn {
  background:transparent;
  border:1px solid #2b2b2b;
  color:var(--muted);
  padding:4px 6px;
  border-radius:8px;
  cursor:pointer;
  line-height:1;
  font-size:1rem;
  display:inline-flex;
  align-items:center;
  justify-content:center;
}

.icon-btn:hover {
  background:#1e1e1e;
  color:var(--text);
}

.icon-btn:disabled {
  opacity:.45;
  cursor:default;
}

.note, .muted { color:var(--muted); font-size:.95rem; }

.results-card { margin-top:1.2rem; border-radius:12px; border:1px solid var(--border); box-shadow: inset 0 0 0 1px #0b1020, 0 20px 60px rgba(0,0,0,.3); padding:16px; }

.table {
  width:100%;
  border-collapse:collapse;
}

.table th, .table td {
  padding:8px 12px;
  border-bottom:1px solid var(--border);
  vertical-align:top;
}

.table-compact th,
.table-compact td {
  padding:6px 10px;
}

.table-hover tbody tr:hover {
  outline:1px solid var(--accent);
  box-shadow:0 0 6px var(--accent);
}

.table thead th {
  position:sticky;
  top:0;
  background:#070a12;
  z-index:1;
}

.table th { text-align:left; color:var(--muted); }

.table .num { text-align:right; font-variant-numeric:tabular-nums; }

.table tbody tr { background:var(--bg); }

.table tbody tr:hover { outline:1px solid var(--accent); box-shadow:0 0 6px var(--accent); }

.table-scroll {
  overflow:auto;
}

.row-hover { cursor:pointer; }

.roi.pos { color:var(--pos); }
.roi.neg { color:var(--neg); }
.hit.high { color:var(--pos); }

.col-rule,
.col-recent {
  max-width:360px;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}

.clamp1 {
  white-space:nowrap;
}

.clamp-cell {
  max-width:360px;
  vertical-align:top;
}

.timeline-td {
  max-width:300px;
}

.history-td {
  position:relative;
  max-width:280px;
}

.summary-td {
  max-width:340px;
}

.forward-empty-card {
  border:1px solid var(--border);
  background:rgba(10,15,24,0.75);
  border-radius:12px;
  padding:16px;
  margin-bottom:0.75rem;
  box-shadow:0 12px 30px rgba(0,0,0,0.35);
}

.forward-empty-card strong {
  display:block;
  font-size:0.95rem;
  margin-bottom:4px;
}

.forward-empty-card p {
  margin:0;
  font-size:0.85rem;
}

.forward-skeleton-row td {
  position:relative;
  overflow:hidden;
}

.forward-skeleton-bar {
  display:block;
  width:100%;
  height:12px;
  border-radius:6px;
  background:linear-gradient(90deg, rgba(30,36,48,0.4), rgba(60,72,96,0.55), rgba(30,36,48,0.4));
  background-size:200% 100%;
  animation:forward-skeleton-pulse 1.4s ease-in-out infinite;
}

.forward-skeleton-bar.short {
  width:55%;
}

.forward-skeleton-bar.tiny {
  width:35%;
}

@keyframes forward-skeleton-pulse {
  0% { background-position:200% 0; }
  100% { background-position:-200% 0; }
}

.summary-chips {
  display:flex;
  align-items:center;
  gap:6px;
  flex-wrap:nowrap;
}

.summary-chip {  
  display:inline-flex;
  align-items:center;
  gap:4px;
  padding:2px 8px;
  border-radius:999px;
  border:1px solid transparent;
  font-size:0.72rem;
  font-weight:600;
  line-height:1.2;
  white-space:nowrap;
  font-variant-numeric:tabular-nums;
}

.summary-recency-badge {
  display:inline-flex;
  align-items:center;
  padding:2px 6px;
  border-radius:999px;
  border:1px dashed rgba(154,166,178,0.4);
  background:rgba(154,166,178,0.12);
  color:var(--muted);
  font-size:0.62rem;
  font-weight:600;
  letter-spacing:0.05em;
  text-transform:uppercase;
  white-space:nowrap;
}

.summary-chip-success {
  border-color:rgba(61,220,132,0.45);
  background:rgba(61,220,132,0.15);
  color:var(--pos);
}

.summary-chip-warn {
  border-color:rgba(255,77,77,0.45);
  background:rgba(255,77,77,0.18);
  color:var(--neg);
}

.summary-chip-neutral {
  border-color:rgba(154,166,178,0.4);
  background:rgba(154,166,178,0.15);
  color:var(--muted);
}

.summary-chip-main {
  display:inline-flex;
  align-items:center;
  gap:4px;
}

.summary-chip-sub {
  font-size:0.65rem;
  color:var(--muted);
}

.summary-empty {
  display:inline-block;
  padding:0 4px;
}

.clamp-wrap {
  display:flex;
  align-items:flex-start;
  gap:4px;
}

.clamp-content {
  flex:1 1 auto;
  min-width:0;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.clamp-wrap[data-expanded="1"] .clamp-content {
  white-space:normal;
}

.clamp-toggle {
  border:0;
  background:transparent;
  color:var(--muted);
  cursor:pointer;
  padding:0;
  line-height:1;
  font-size:0.85rem;
}

.clamp-toggle:hover,
.clamp-wrap[data-expanded="1"] .clamp-toggle {
  color:var(--accent);
}

.rule-td {
  max-width:360px;
}

.rule-td code {
  white-space:pre-wrap;
}

.timeline-text {
  font-variant-numeric:tabular-nums;
}

.timeline-badge {
  display:inline-flex;
  align-items:center;
  justify-content:center;
  padding:0 0.35rem;
  margin:0 0.25rem;
  border-radius:999px;
  font-size:0.65rem;
  font-weight:600;
  letter-spacing:0.05em;
  border:1px solid transparent;
}

.timeline-badge-hit {
  border-color:rgba(61,220,132,0.45);
  background:rgba(61,220,132,0.15);
  color:var(--pos);
}

.timeline-badge-stop {
  border-color:rgba(255,77,77,0.45);
  background:rgba(255,77,77,0.18);
  color:var(--neg);
}

.timeline-badge-timeout,
.timeline-badge-neutral {
  border-color:rgba(154,166,178,0.4);
  background:rgba(154,166,178,0.15);
  color:var(--muted);
}

.history-chip {
  border:1px solid var(--border);
  background:#1f2a3c;
  color:var(--text);
  padding:2px 10px;
  border-radius:999px;
  font-size:0.75rem;
  cursor:pointer;
  line-height:1.4;
}

.history-chip:hover,
.history-chip:focus,
.history-chip-active {
  border-color:var(--accent);
  color:var(--accent);
}

.history-popover {
  position:absolute;
  top:calc(100% + 6px);
  right:0;
  min-width:240px;
  max-width:320px;
  max-height:220px;
  overflow-y:auto;
  background:var(--panel);
  border:1px solid var(--border);
  border-radius:10px;
  box-shadow:0 12px 40px rgba(0,0,0,0.45);
  padding:8px 0;
  z-index:40;
}

.history-popover[hidden] {
  display:none;
}

.history-list {
  list-style:none;
  margin:0;
  padding:0;
  display:flex;
  flex-direction:column;
  gap:6px;
}

.history-item {
  padding:0 12px;
}

.history-line {
  font-size:0.85rem;
  line-height:1.4;
  color:var(--text);
  display:block;
}

.history-empty {
  color:var(--muted);
}

.history-outcome {
  margin-left:0.35rem;
}

.history-badge-old {
  color:var(--muted);
  font-size:0.7rem;
}

.history-popover-actions {
  margin:8px 12px 0;
  padding-top:8px;
  border-top:1px solid var(--border);
  display:flex;
  justify-content:flex-end;
}

.history-view-all {
  background:none;
  border:none;
  color:var(--accent);
  font-size:0.75rem;
  cursor:pointer;
  padding:4px 0;
}

.history-view-all:hover,
.history-view-all:focus {
  text-decoration:underline;
  color:var(--text);
}

.history-popover::-webkit-scrollbar {
  width:6px;
}

.history-popover::-webkit-scrollbar-thumb {
  background:var(--border);
  border-radius:999px;
}

.forward-history-modal {
  position:fixed;
  inset:0;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:24px;
  background:rgba(6, 10, 18, 0.78);
  backdrop-filter:blur(4px);
  z-index:200;
}

.forward-history-modal[hidden] {
  display:none;
}

.forward-history-dialog {
  background:var(--panel);
  border:1px solid var(--border);
  border-radius:14px;
  box-shadow:0 24px 80px rgba(0,0,0,0.6);
  width:min(720px, 96%);
  max-height:90vh;
  display:flex;
  flex-direction:column;
  overflow:hidden;
}

.forward-history-header {
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:16px 20px 12px;
  border-bottom:1px solid var(--border);
}

.forward-history-header h2 {
  margin:0;
  font-size:1.1rem;
}

.forward-history-close {
  background:none;
  border:none;
  color:var(--muted);
  font-size:1.2rem;
  line-height:1;
  cursor:pointer;
  padding:4px;
}

.forward-history-close:hover,
.forward-history-close:focus {
  color:var(--text);
}

.forward-history-toolbar {
  display:flex;
  justify-content:flex-end;
  gap:12px;
  padding:10px 20px;
  border-bottom:1px solid var(--border);
  background:var(--panel);
  z-index:1;
}

.forward-history-body {
  flex:1;
  display:flex;
  flex-direction:column;
  min-height:0;
}

.forward-history-status {
  padding:12px 20px 0;
  font-size:0.85rem;
}

.forward-history-status.error {
  color:var(--neg);
}

.forward-history-scroll {
  flex:1;
  overflow-y:auto;
  padding:12px 20px 4px;
}

.forward-history-list {
  list-style:none;
  margin:0;
  padding:0;
  display:flex;
  flex-direction:column;
  gap:8px;
  position:relative;
}

.forward-history-virtual-spacer {
  height:0;
  margin:0;
  padding:0;
  border:0;
  list-style:none;
}

.forward-history-row {
  display:flex;
  align-items:center;
  gap:16px;
  padding:6px 0;
  border-bottom:1px solid rgba(26, 34, 48, 0.6);
}

.forward-history-row:last-child {
  border-bottom:none;
}

.forward-history-row-text {
  flex:1;
  min-width:0;
  font-size:0.88rem;
  line-height:1.45;
  color:var(--text);
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.forward-history-row-outcome {
  margin-left:0.35rem;
}

.forward-history-spark {
  width:120px;
  height:36px;
  flex-shrink:0;
  border-radius:6px;
  background:#0f1521;
}

.forward-history-footer {
  padding:12px 20px 16px;
  border-top:1px solid var(--border);
  display:flex;
  justify-content:flex-end;
}

.forward-history-footer .btn {
  background:#161d2c;
  border:1px solid var(--border);
  color:var(--text);
}

.forward-history-footer .btn:disabled {
  opacity:0.6;
}

@media (max-width: 640px) {
  .forward-history-modal {
    padding:0;
  }

  .forward-history-dialog {
    width:100%;
    height:100%;
    max-height:none;
    border-radius:0;
  }

  .forward-history-toolbar {
    position:sticky;
    top:0;
  }

  .forward-history-footer {
    position:sticky;
    bottom:0;
    background:var(--panel);
  }

  .forward-history-spark {
    width:96px;
  }
}

@media (max-width: 740px) {
  .clamp1 {
    white-space:normal;
    display:-webkit-box;
    -webkit-line-clamp:2;
    -webkit-box-orient:vertical;
  }
}

.del-btn {
  background:none;
  border:none;
  color:var(--muted);
  cursor:pointer;
  font-size:1.2rem;
  line-height:1;
}

.linklike {
  border:0;
  background:transparent;
  color:var(--accent);
  cursor:pointer;
}

.linklike:hover { text-decoration:underline; }

button:focus,
.btn:focus,
input:focus,
select:focus,
.nav-link:focus,
.linklike:focus {
  outline:none;
  box-shadow:0 0 0 3px var(--focus);
}

#ctx-menu {
  position:fixed;
  z-index:9999;
  background:var(--panel);
  color:var(--text);
  border:1px solid var(--border);
  border-radius:8px;
  padding:6px;
  min-width:180px;
  box-shadow:0 8px 28px rgba(0,0,0,.25);
}

#ctx-menu[hidden] { display:none; }

#ctx-menu .menu-item {
  width:100%;
  text-align:left;
  border:0;
  background:transparent;
  color:var(--text);
  padding:8px 10px;
  border-radius:6px;
  cursor:pointer;
  font-size:14px;
}

#ctx-menu .menu-item:hover { background:#1e1e1e; }

#toast {
  position:fixed;
  bottom:20px;
  right:20px;
  z-index:9999;
  background:var(--panel);
  color:var(--text);
  border:1px solid var(--border);
  border-radius:10px;
  padding:10px 14px;
  font-size:14px;
  box-shadow:0 8px 28px rgba(0,0,0,.25);
  display:flex;
  align-items:center;
  gap:12px;
}

#toast[hidden] { display:none; }

#toast .toast-action {
  background:rgba(94,160,255,0.18);
  color:var(--accent);
  border:none;
  border-radius:6px;
  padding:4px 10px;
  font-size:13px;
  cursor:pointer;
}

#toast .toast-action:hover,
#toast .toast-action:focus {
  background:rgba(94,160,255,0.3);
  outline:none;
}

#scan-overlay {
  position:fixed;
  inset:0;
  background:rgba(0,0,0,.5);
  display:none;
  place-items:center;
  z-index:9998;
}

#scan-overlay .box {
  background:var(--panel);
  border:1px solid var(--border);
  padding:16px 18px;
  border-radius:12px;
  box-shadow:0 8px 40px rgba(0,0,0,.4);
}

#progress-bar {
  width:200px;
  height:16px;
  background:var(--border);
  border-radius:8px;
  overflow:hidden;
}

#progress-fill {
  height:100%;
  width:0%;
  background:var(--accent);
  transition:width .1s linear;
}

#progress-text {
  margin-top:8px;
  text-align:center;
}

#progress-status {
  margin-top:4px;
  text-align:center;
  font-size:.9rem;
}

#scan-overlay.htmx-request { display:grid !important; }
.htmx-request #scan-results { opacity:.4; filter:grayscale(30%); }

.site-footer {
  margin:32px auto 24px;
  max-width:1200px;
  padding:0 16px;
  text-align:center;
  color:var(--muted);
  font-size:0.9rem;
  display:flex;
  flex-direction:column;
  gap:0.4rem;
  align-items:center;
}

.site-footer .footer-links {
  display:flex;
  gap:0.75rem;
  flex-wrap:wrap;
  justify-content:center;
}

.site-footer .footer-meta {
  font-size:0.85rem;
}

.site-footer a {
  color:var(--accent);
  text-decoration:none;
  margin:0 6px;
}

.site-footer a:hover,
.site-footer a:focus {
  text-decoration:underline;
}
