:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --border-2: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-faint: #94a3b8;
  --primary: #0f172a;
  --primary-hover: #1e293b;
  --accent: #3b82f6;
  --success: #10b981;
  --success-soft: #d1fae5;
  --warn: #f59e0b;
  --warn-soft: #fef3c7;
  --danger: #ef4444;
  --danger-soft: #fee2e2;
  --info: #6366f1;
  --info-soft: #e0e7ff;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 4px 6px rgba(15, 23, 42, 0.05), 0 2px 4px rgba(15, 23, 42, 0.04);
  --radius: 8px;
  --radius-lg: 12px;
  --sidebar-w: 240px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ===== APP LAYOUT ===== */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ===== SIDEBAR ===== */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
}

.sidebar-header {
  padding: 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-logo {
  width: 36px;
  height: 36px;
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: -0.02em;
  flex-shrink: 0;
}
.sidebar-title {
  flex: 1;
  min-width: 0;
}
.sidebar-title .name {
  font-weight: 700;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-title .role {
  font-size: 11px;
  color: var(--text-muted);
}

.sidebar-nav {
  padding: 16px 12px;
  flex: 1;
}
.sidebar-section {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 12px 12px 8px;
  margin-top: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  transition: background 0.1s;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active {
  background: var(--primary);
  color: #fff;
}
.nav-item .icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}
.nav-item .label {
  flex: 1;
  font-weight: 500;
}
.nav-item .badge {
  font-size: 9px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 99px;
  background: var(--info-soft);
  color: var(--info);
  letter-spacing: 0.04em;
}
.nav-item.active .badge { background: rgba(255,255,255,0.2); color: #fff; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-footer .avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
}
.sidebar-footer .who {
  flex: 1;
  min-width: 0;
}
.sidebar-footer .who .email {
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-footer .who .role {
  font-size: 11px;
  color: var(--text-muted);
}

/* ===== MAIN ===== */
.main {
  background: var(--bg);
  min-height: 100vh;
  overflow-x: hidden;
}
.main-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.main-header h1 {
  font-size: 16px;
  font-weight: 600;
}
.main-content {
  padding: 32px;
  max-width: 1400px;
}
.page-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}
.page-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

/* ===== TAB PANEL ===== */
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; } }

/* ===== CARDS ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card h2 { font-size: 18px; font-weight: 700; margin-bottom: 16px; }
.card h3 { font-size: 14px; font-weight: 700; margin: 16px 0 8px; }
.card h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 8px;
}
.card p { font-size: 14px; line-height: 1.6; }

/* ===== STAT CARDS ===== */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
}
.stat-card:hover { border-color: var(--text-muted); transform: translateY(-1px); }
.stat-card.active { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(15,23,42,0.08); }
.stat-card .stat-num {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
}
.stat-card .stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 6px;
  font-weight: 600;
}
.stat-card.stat-pass .stat-num { color: var(--success); }
.stat-card.stat-partial .stat-num { color: var(--warn); }
.stat-card.stat-fail .stat-num { color: var(--danger); }
.stat-card.stat-error .stat-num { color: var(--text-muted); }
.stat-card.stat-score .stat-num { color: var(--accent); }

/* ===== BUTTONS ===== */
.primary-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.1s;
}
.primary-btn:hover { background: var(--primary-hover); }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== FORMS ===== */
.input-group { margin-bottom: 14px; }
.input-group label {
  display: block;
  margin-bottom: 5px;
  font-weight: 600;
  font-size: 13px;
}
.input-group small {
  display: block;
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 4px;
}
input[type="text"], input[type="number"], textarea, select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
}
textarea {
  min-height: 120px;
  font-family: 'SFMono-Regular', Menlo, monospace;
  font-size: 13px;
  resize: vertical;
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ===== SCAN MODES ===== */
.scan-modes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.radio-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  display: flex;
  gap: 10px;
  transition: all 0.15s;
}
.radio-card:hover { border-color: var(--text-muted); }
.radio-card input { margin-top: 3px; }
.radio-card:has(input:checked) { border-color: var(--accent); background: var(--info-soft); }
.radio-card strong { display: block; font-size: 14px; margin-bottom: 2px; }
.radio-card span { font-size: 12px; color: var(--text-muted); }

/* ===== PROGRESS ===== */
.progress-area { margin-top: 20px; }
.progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}
.progress-bar-inner {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s;
}
.progress-log {
  font-family: 'SFMono-Regular', Menlo, monospace;
  font-size: 12px;
  color: var(--text-muted);
  max-height: 240px;
  overflow-y: auto;
  background: var(--bg);
  padding: 12px;
  border-radius: 6px;
  margin-top: 12px;
  line-height: 1.6;
}
.progress-log .log-line { padding: 2px 0; }
.progress-log .ok { color: var(--success); }
.progress-log .err { color: var(--danger); }

/* ===== FILTER BAR ===== */
.findings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}
.summary-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill { padding: 4px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.pill-pass { background: var(--success-soft); color: var(--success); }
.pill-partial { background: var(--warn-soft); color: var(--warn); }
.pill-fail { background: var(--danger-soft); color: var(--danger); }
.pill-error { background: var(--surface-2); color: var(--text-muted); }

.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}
.filter-search {
  flex: 1;
  min-width: 220px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}
.filter-select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
  min-width: 160px;
}
.filter-active { font-size: 12px; color: var(--text-muted); }

/* ===== DATA TABLES ===== */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left;
  padding: 10px 12px;
  background: var(--bg);
  border-bottom: 2px solid var(--border);
  font-weight: 600;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  position: sticky;
  top: 0;
}
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.data-table tr:hover td { background: var(--bg); }
.data-table .empty { text-align: center; color: var(--text-muted); padding: 40px; }
.data-table a { color: var(--accent); text-decoration: none; }
.data-table a:hover { text-decoration: underline; }
.data-table .url-cell { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== GRADES & PATTERNS ===== */
.grade-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.02em;
}
.grade-PASS { background: var(--success-soft); color: var(--success); }
.grade-PARTIAL { background: var(--warn-soft); color: var(--warn); }
.grade-FAIL { background: var(--danger-soft); color: var(--danger); }
.grade-ERROR { background: var(--surface-2); color: var(--text-muted); }

.len-good { color: var(--success); font-weight: 600; }
.len-bad { color: var(--danger); font-weight: 600; }

.pattern-tag {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.pattern-sev-0 { background: var(--success-soft); color: var(--success); }
.pattern-sev-1 { background: var(--info-soft); color: var(--info); }
.pattern-sev-3 { background: var(--warn-soft); color: var(--warn); }
.pattern-sev-4 { background: #ffe4d3; color: #c2410c; }
.pattern-sev-5 { background: var(--danger-soft); color: var(--danger); }

.tier-tag {
  display: inline-block;
  padding: 1px 6px;
  background: var(--primary);
  color: #fff;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  margin-right: 6px;
  vertical-align: middle;
}

/* ===== STATUS BADGES ===== */
.status-pending { padding: 3px 8px; border-radius: 4px; background: var(--warn-soft); color: var(--warn); font-weight: 600; font-size: 11px; }
.status-processing { padding: 3px 8px; border-radius: 4px; background: var(--info-soft); color: var(--info); font-weight: 600; font-size: 11px; }
.status-done { padding: 3px 8px; border-radius: 4px; background: var(--success-soft); color: var(--success); font-weight: 600; font-size: 11px; }
.status-failed { padding: 3px 8px; border-radius: 4px; background: var(--danger-soft); color: var(--danger); font-weight: 600; font-size: 11px; }

.detail-link {
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
  background: none;
  border: none;
  font-family: inherit;
}
.detail-link:hover { text-decoration: underline; }

/* ===== STRATEGY MEMO ===== */
#strategy-content .card h2 { font-size: 20px; margin-bottom: 12px; }
#strategy-content .card h3 { margin-top: 18px; margin-bottom: 8px; font-size: 15px; font-weight: 700; }

/* ===== PER-PAGE DETAILS ===== */
.page-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 16px;
}
.page-detail-header select { flex: 1; max-width: 600px; }
.page-detail h3 { font-size: 16px; margin: 20px 0 10px; font-weight: 700; }
.page-detail .meta-block {
  background: var(--bg);
  padding: 14px;
  border-radius: 6px;
  margin-bottom: 12px;
  font-size: 13px;
}
.page-detail .meta-row { margin-bottom: 8px; }
.page-detail .meta-row strong {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}
.page-detail .findings-list { list-style: none; }
.page-detail .finding-item {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 8px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.page-detail .finding-item.pass { border-left: 3px solid var(--success); }
.page-detail .finding-item.fail { border-left: 3px solid var(--danger); }
.page-detail .finding-icon { font-size: 18px; line-height: 1; }
.page-detail .finding-body { flex: 1; font-size: 13px; }
.page-detail .finding-body strong { display: block; margin-bottom: 2px; font-size: 14px; }
.page-detail .finding-body .evidence {
  color: var(--text-muted);
  font-family: 'SFMono-Regular', Menlo, monospace;
  font-size: 12px;
  margin: 4px 0;
}
.page-detail .finding-body .fix {
  margin-top: 6px;
  padding: 8px 10px;
  background: var(--info-soft);
  border-radius: 4px;
  font-size: 13px;
}

/* ===== EXPORT ===== */
.export-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.export-btn {
  text-align: left;
  padding: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  transition: all 0.15s;
}
.export-btn:hover { border-color: var(--text-muted); background: var(--surface-2); }
.export-btn.primary { border-color: var(--accent); background: var(--info-soft); }
.export-btn strong { display: block; font-size: 14px; margin-bottom: 4px; }
.export-btn span { display: block; font-size: 12px; color: var(--text-muted); }
.export-actions { display: flex; gap: 8px; margin-top: 12px; }
.export-actions button {
  padding: 9px 18px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
}
.export-actions button:hover { background: var(--surface-2); }

/* ===== MODAL ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: 40px 20px;
}
.modal-content {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 28px;
  max-width: 720px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(15, 23, 42, 0.2);
}
.modal-content h2 { margin-bottom: 8px; }
.modal-content code { background: var(--bg); padding: 2px 5px; border-radius: 3px; font-size: 12px; }

/* ===== LIVE INDICATOR ===== */
.live-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  animation: livepulse 1.6s ease-in-out infinite;
}
@keyframes livepulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

/* ===== SCHEMA JSON VIEWER ===== */
.schema-json-block {
  margin-top: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 14px;
}
.schema-json-block summary {
  cursor: pointer;
  font-size: 13px;
  padding: 4px 0;
}
.schema-json-block summary:hover { color: var(--accent); }
.schema-id-list {
  padding: 8px 0;
  font-family: 'SFMono-Regular', Menlo, monospace;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.7;
}
.schema-json {
  background: var(--primary);
  color: #e2e8f0;
  padding: 14px;
  border-radius: 6px;
  font-family: 'SFMono-Regular', Menlo, monospace;
  font-size: 11px;
  line-height: 1.5;
  overflow-x: auto;
  max-height: 400px;
  overflow-y: auto;
  margin-top: 8px;
  white-space: pre;
}

/* ===== FIX QUEUE DETAILS ===== */
.detail-expansion td {
  background: var(--bg);
  padding: 0 !important;
  border-bottom: 2px solid var(--accent);
}
.fix-details { padding: 18px 24px; font-size: 13px; }
.fix-details h4 {
  font-size: 11px;
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
}
.fix-details-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  margin-bottom: 18px;
}
.fix-details-grid > div {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
}
.fix-details-grid p {
  font-size: 12px;
  line-height: 1.5;
  margin-bottom: 6px;
  word-break: break-word;
}
.fix-details-grid p strong {
  display: block;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.fix-list { list-style: none; padding: 0; font-size: 12px; line-height: 1.6; }
.fix-list li { padding: 3px 0; color: var(--text); }
.fix-list em {
  color: var(--text-muted);
  font-style: normal;
  display: block;
  margin-top: 2px;
  font-size: 11px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1100px) {
  .stat-cards { grid-template-columns: repeat(3, 1fr); }
  .fix-details-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -100%; transition: left 0.2s; z-index: 100; width: 280px; box-shadow: 0 0 24px rgba(0,0,0,0.1); }
  .sidebar.open { left: 0; }
  .main-header { position: sticky; top: 0; z-index: 10; }
  .main-content { padding: 20px; }
  .scan-modes, .export-grid { grid-template-columns: 1fr; }
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
}

/* mobile menu toggle */
.menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  font-size: 22px;
}
@media (max-width: 900px) {
  .menu-toggle { display: block; }
}
