:root {
  color-scheme: dark;
  --bg: #070b12;
  --bg-start: #0c121e;
  --glow: rgba(53, 162, 235, 0.15);
  --topbar: #0f1622;
  --panel: #121a26;
  --panel-rgb: 18, 26, 38;
  --panel-soft: #1a2433;
  --surface: #0a101a;
  --surface-2: #0d1421;
  --surface-3: #111a2b;
  --line: #222f42;
  --line-strong: #31435c;
  --text: #dbede6;
  --text-strong: #ffffff;
  --muted: #8295ad;
  --table-head: #0a111c;
  --table-text: #e1eaf5;
  --chip-bg: #152030;
  --green: #2ecc71;
  --green-dark: #27ae60;
  --blue: #3498db;
  --cyan: #1abc9c;
  --yellow: #f1c40f;
  --red: #962d31;
  --red-bright: #e74c3c;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
}

body[data-theme="light"] {
  color-scheme: light;
  --bg: #f0f4f8;
  --bg-start: #ffffff;
  --glow: rgba(52, 152, 219, 0.12);
  --topbar: #ffffff;
  --panel: #ffffff;
  --panel-rgb: 255, 255, 255;
  --panel-soft: #f4f7fa;
  --surface: #fafbfc;
  --surface-2: #f0f3f7;
  --surface-3: #e6ebf2;
  --line: #d2dae2;
  --line-strong: #bcccda;
  --text: #2c3e50;
  --text-strong: #1a252f;
  --muted: #7f8c8d;
  --table-head: #ebf0f5;
  --table-text: #2c3e50;
  --chip-bg: #ffffff;
  --green: #27ae60;
  --green-dark: #1e8449;
  --blue: #2980b9;
  --cyan: #16a085;
  --yellow: #d35400;
  --red: #c0392b;
  --red-bright: #e74c3c;
  --shadow: 0 15px 35px rgba(142, 153, 165, 0.15);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at left 35%, var(--glow), transparent 25rem),
    linear-gradient(180deg, var(--bg-start) 0%, var(--bg) 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  position: sticky; top: 0; z-index: 100; display: flex; align-items: center; gap: 20px;
  height: 54px; padding: 0 24px; background: rgba(var(--panel-rgb), 0.85);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; color: var(--text-strong); text-decoration: none; }
.brand strong { font-size: 16px; font-weight: 800; letter-spacing: -0.5px; }
.brand-mark { position: relative; display: inline-grid; place-items: center; width: 24px; height: 24px; background: var(--blue); border-radius: 6px; }
.signal-dot { width: 6px; height: 6px; border-radius: 50%; background: #fff; box-shadow: 0 0 8px #fff; }
.version { padding: 2px 6px; border-radius: 4px; background: var(--line-strong); color: var(--text-strong); font-size: 11px; font-weight: bold; }

.nav-tabs { display: flex; align-items: center; gap: 6px; height: 100%; }
.nav-tab {
  height: 38px; border: 0; padding: 0 16px; color: var(--muted); background: transparent;
  border-radius: 6px; cursor: pointer; font-weight: 500; font-size: 15px; transition: all 0.2s;
}
.nav-tab:hover { color: var(--text-strong); background: rgba(var(--panel-rgb), 0.5); }
.nav-tab.active { color: #fff; background: var(--blue); box-shadow: 0 4px 12px rgba(52, 152, 219, 0.3); }

.theme-toggle { margin-left: auto; height: 32px; border: 1px solid var(--line); border-radius: 20px; padding: 0 16px; background: var(--panel-soft); color: var(--text); font-size: 13px; cursor: pointer; font-weight: 600; transition: all 0.2s; }

.workspace { max-width: 1440px; margin: 0 auto; padding: 24px; }
.view { display: none; }
.view.active { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; }

.panel { border: 1px solid var(--line); border-radius: 12px; background: rgba(var(--panel-rgb), 0.7); backdrop-filter: blur(16px); box-shadow: var(--shadow); padding: 24px; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; border-bottom: 1px solid var(--line); padding-bottom: 16px; }
.status-group { display: flex; align-items: center; gap: 10px; }
.eyebrow { margin: 0 0 4px; color: var(--cyan); font-size: 12px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; }
h1 { margin: 0; font-size: 24px; font-weight: 700; color: var(--text-strong); }

.scan-form { display: grid; gap: 20px; }
.field-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.field-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field { display: grid; gap: 6px; }
.field span { font-size: 14px; font-weight: 500; color: var(--muted); margin-bottom: 6px; }

select, input {
  height: 46px; padding: 0 16px; font-size: 15px; color: var(--text-strong);
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  outline: none; box-shadow: inset 0 2px 4px rgba(0,0,0,0.05); transition: all 0.2s ease;
}
textarea {
  padding: 16px; font-size: 15px; line-height: 1.5; font-family: monospace; background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; outline: none; color: var(--text-strong); resize: vertical;
}
input::placeholder, textarea::placeholder { font-size: 14px; color: #4a5d78; }
select:focus, input:focus, textarea:focus { border-color: var(--blue); background: var(--surface-2); box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2), inset 0 2px 4px rgba(0,0,0,0.05); }

.input-group { display: flex; gap: 8px; }
.input-group input { flex: 1; }

.dynamic-tag-list { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.ip-asn-tag {
  display: flex; align-items: center; justify-content: space-between; height: 38px;
  padding: 0 14px; border: 1px solid rgba(52, 152, 219, 0.35); background: rgba(52, 152, 219, 0.06);
  border-radius: 6px; font-size: 14px; color: #a4bcd6;
}
.tag-close-btn { background: transparent; border: 0; color: #526882; cursor: pointer; font-size: 16px; padding: 0; transition: color 0.2s; }
.tag-close-btn:hover { color: var(--red-bright); }

.actions { display: flex; gap: 12px; margin-top: 12px; }
.primary-btn, .secondary-btn, .danger-btn, .ghost-btn, .add-btn { display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 8px; font-size: 14.5px; font-weight: 600; cursor: pointer; transition: all 0.2s ease; }
.primary-btn { height: 46px; padding: 0 24px; background: var(--blue); color: #fff; }
.primary-btn:hover { background: #2980b9; transform: translateY(-1px); }
.secondary-btn { height: 46px; padding: 0 24px; border: 1px solid var(--line); background: var(--panel-soft); color: var(--text); }
.secondary-btn:hover { background: var(--line); color: var(--text-strong); }
.add-btn { height: 46px; padding: 0 20px; }
.danger-btn { height: 46px; padding: 0 24px; background: var(--red); color: #fff; }
.danger-btn:hover:not(:disabled) { background: var(--red-bright); }
.ghost-btn { height: 30px; padding: 0 12px; background: transparent; border: 1px solid var(--line); color: var(--muted); font-size: 12px; }
button:disabled { opacity: 0.4; cursor: not-allowed; transform: none !important; }

.live-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.live-dot.active { background: var(--green); box-shadow: 0 0 12px var(--green); animation: pulse-glow 2s infinite; }
@keyframes pulse-glow { 0% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.7); } 70% { box-shadow: 0 0 0 8px rgba(46, 204, 113, 0); } 100% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0); } }

.status-pill { padding: 6px 12px; border-radius: 6px; background: var(--surface-3); color: var(--muted); font-size: 12px; font-weight: 700; }
.status-pill.running { background: rgba(46, 204, 113, 0.15); color: var(--green); }
.status-pill.ok { background: rgba(52, 152, 219, 0.15); color: var(--blue); }

.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin: 24px 0; }
.validation-metrics { grid-template-columns: repeat(4, 1fr); }
.metrics article { padding: 20px 24px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); min-height: 110px; display: flex; flex-direction: column; justify-content: space-between; }
.metrics span { display: block; font-size: 14px; color: var(--muted); font-weight: 500; }
.metrics strong { display: block; font-size: 34px; line-height: 1.1; color: var(--text-strong); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.progress-wrap { margin: 16px 0; }
.progress-label { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); margin-bottom: 10px; }
.progress-bar { height: 8px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.progress-bar span { display: block; width: 0%; height: 100%; background: linear-gradient(90deg, var(--blue), var(--cyan)); transition: width 0.3s ease; }

.log-list { display: flex; flex-direction: column; gap: 8px; max-height: 200px; overflow-y: auto; padding: 16px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; list-style: none; margin: 0; font-family: monospace; }
.log-list li { font-size: 14px; line-height: 1.6; color: var(--text); word-break: break-all; }

.tool-row { display: grid; grid-template-columns: minmax(0, 1fr) 180px; gap: 16px; margin-bottom: 20px; }
.tool-actions { display: flex; flex-direction: column; gap: 10px; }
.tool-actions button { width: 100%; }

.table-wrap { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
table { width: 100%; border-collapse: collapse; text-align: left; font-size: 14px; }
th, td { padding: 14px 16px; border-bottom: 1px solid var(--line); }
th { background: var(--table-head); color: var(--muted); font-weight: 600; font-size: 13px; }
td { color: var(--table-text); }
tr:last-child td { border-bottom: 0; }

.tag { padding: 4px 8px; border-radius: 4px; font-size: 12px; font-weight: bold; }
.tag.pending { background: rgba(241, 196, 15, 0.15); color: var(--yellow); }
.tag.checking { background: rgba(52, 152, 219, 0.15); color: var(--blue); }
.tag.valid { background: rgba(46, 204, 113, 0.15); color: var(--green); }
.tag.invalid { background: rgba(231, 76, 60, 0.15); color: var(--red-bright); }

.row-btn { height: 28px; padding: 0 12px; background: var(--panel-soft); border: 1px solid var(--line); border-radius: 4px; color: var(--text-strong); font-size: 12px; cursor: pointer; float: right; }
.row-btn:hover { background: var(--line); }

.export-filter-panel { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 16px; display: grid; gap: 12px; margin-bottom: 20px; }
.filter-summary { font-size: 14px; font-weight: 700; color: var(--blue); padding-bottom: 10px; border-bottom: 1px dashed var(--line); }
.filter-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.filter-label { font-size: 13px; color: var(--muted); font-weight: bold; width: 44px; }
.export-chip { height: 30px; padding: 0 14px; border-radius: 15px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-size: 13px; cursor: pointer; transition: all 0.2s; }
.export-chip.active { background: rgba(52, 152, 219, 0.15); border-color: var(--blue); color: var(--blue); }
.export-chip.warm { border-color: var(--line-strong); background: var(--panel-soft); }
.export-chip.warm:hover { background: var(--blue); color: #fff; }

.export-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.export-card { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); padding: 16px; display: flex; flex-direction: column; justify-content: space-between; gap: 12px; }
.export-card strong { font-size: 16px; color: var(--text-strong); word-break: break-all; }
.export-card p { margin: 0; font-size: 13px; color: var(--muted); }
.export-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.info-chip { padding: 4px 8px; background: var(--surface-3); border: 1px solid var(--line); font-size: 12px; border-radius: 4px; color: var(--text); }
.info-chip.risk-pure { color: var(--green); }
.info-chip.risk-low { color: var(--blue); }
.info-chip.risk-high { color: var(--yellow); }
.info-chip.risk-critical { color: var(--red-bright); }
.landing-ip { display: flex; align-items: center; justify-content: space-between; font-size: 13px; background: var(--surface-2); padding: 8px 12px; border-radius: 6px; }
.latency-badge { font-size: 12px; font-weight: bold; color: var(--green); align-self: flex-start; }
.export-empty { grid-column: 1 / -1; text-align: center; padding: 40px; color: var(--muted); border: 1px dashed var(--line); border-radius: 8px; font-size: 14px; }

@media (max-width: 768px) {
  .topbar { flex-direction: column; height: auto; padding: 12px; gap: 10px; }
  .theme-toggle { margin-left: 0; width: 100%; }
  .nav-tabs { width: 100%; overflow-x: auto; padding-bottom: 4px; }
  .field-grid { grid-template-columns: 1fr; }
  .tool-row { grid-template-columns: 1fr; }
  .metrics, .validation-metrics { grid-template-columns: repeat(2, 1fr); }
}