:root {
  color-scheme: dark;
  --bg: #0b1015;
  --bg-elevated: #121922;
  --panel: #171d25;
  --line: #2a3441;
  --text: #e8edf2;
  --muted: #93a1b3;
  --mint: #7fe7c4;
  --violet: #b6a0ff;
  --danger: #ff7f9d;
  --warn: #ffc466;
  --medium: #8eb8ff;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
body {
  margin: 0;
  font-family: "Pretendard", ui-sans-serif, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, #101820 0%, #0b1015 100%);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  color: var(--mint);
}
.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.tabs {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tab {
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
}
.tab:hover { background: rgba(255,255,255,0.04); }
.tab:focus-visible,
.btn:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.table-scroll:focus-visible {
  outline: 3px solid var(--mint);
  outline-offset: 2px;
}
.tab.active {
  background: rgba(127, 231, 196, 0.12);
  border-color: rgba(127, 231, 196, 0.35);
  color: var(--mint);
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
}
.live-indicator { color: var(--mint); }
.live-indicator.paused { color: var(--muted); }

.main-area {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(18, 25, 34, 0.8);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.stat-pill {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
}
.stat-pill strong { color: var(--violet); margin-left: 4px; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-block { display: inline; }
.wide-input { min-width: 220px; }

.worker-banner {
  margin: 12px 20px 0;
  padding: 10px 14px;
  border: 1px solid var(--warn);
  border-radius: 10px;
  background: rgba(255, 196, 102, 0.12);
  color: var(--warn);
  font-size: 13px;
}
.worker-banner[hidden] { display: none !important; }
.warn-text { color: var(--warn); font-size: 13px; margin: 6px 0 0; }

.tab-panel {
  display: none;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}
.tab-panel.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 16px;
  min-width: 0;
}
.panel h2, .panel h3 {
  margin: 0 0 12px;
  font-size: 16px;
}
.panel h2 { color: var(--mint); }

.login-watch {
  border-color: color-mix(in srgb, var(--mint) 45%, var(--line));
}
.login-watch .actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.error-text { color: #ff8f8f; font-size: 13px; }
.success-text { color: var(--mint); font-size: 13px; }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.card-stat {
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}
.card-stat span { color: var(--muted); font-size: 12px; }
.card-stat strong { display: block; font-size: 26px; color: var(--violet); margin-top: 4px; }

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.user-password-reset-form[hidden] { display: none; }

input, select, button, textarea {
  background: #0d1218;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
}
textarea { width: 100%; resize: vertical; min-height: 88px; }

.btn {
  cursor: pointer;
  background: #1d2733;
}
.btn:hover { border-color: var(--mint); }
.btn.primary {
  background: rgba(127, 231, 196, 0.15);
  border-color: rgba(127, 231, 196, 0.45);
  color: var(--mint);
}
.btn.danger { border-color: rgba(255,127,157,0.5); color: var(--danger); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.table-scroll {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  scrollbar-gutter: stable;
}
.table-scroll table {
  min-width: 640px;
}
th, td {
  border-top: 1px solid var(--line);
  padding: 10px 8px;
  vertical-align: top;
  text-align: left;
}
th { color: var(--muted); font-weight: 500; }

.mono { font-family: ui-monospace, monospace; font-size: 12px; word-break: break-all; }
.muted { color: var(--muted); font-size: 12px; }
.small { font-size: 12px; color: var(--muted); }
.comment-source-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
}
.source-link {
  color: var(--mint);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.source-link:hover { color: var(--violet); }
.fallback-warning {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  padding: 8px 10px;
  border: 1px solid var(--warn);
  border-radius: 8px;
  color: var(--warn);
  background: rgba(255, 196, 102, 0.08);
  font-size: 12px;
}
.post-attempt-ledger {
  display: grid;
  color: var(--text);
}
.reconcile-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
  margin-top: 6px;
}
.reconcile-controls label {
  display: grid;
  gap: 4px;
  color: var(--muted);
}
.reconcile-controls .btn {
  justify-self: start;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: #243041;
  font-size: 12px;
  line-height: 1.4;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge.threat-low { background: rgba(127,231,196,0.15); color: var(--mint); }
.badge.threat-medium { background: rgba(142,184,255,0.15); color: var(--medium); }
.badge.threat-high, .badge.threat-critical { background: rgba(255,127,157,0.18); color: var(--danger); }
.badge.status-approved { color: var(--mint); }
.badge.maturity-stable { color: var(--mint); }
.badge.maturity-beta { color: var(--violet); }
.badge.maturity-experimental { color: var(--danger); }
.badge.cf { color: var(--warn); }

.comment-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 14px;
}

.comment-card {
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow);
}
.comment-card.threat-low { border-left-color: var(--mint); }
.comment-card.threat-medium { border-left-color: var(--medium); }
.comment-card.threat-high { border-left-color: var(--danger); }
.comment-card.threat-critical { border-left-color: #ff4d6d; box-shadow: 0 0 0 1px rgba(255,77,109,0.2); }

.comment-card-header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
}
.comment-card-meta { font-size: 12px; color: var(--muted); }

.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.compare-box {
  background: #0d1218;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}
.compare-box h4 {
  margin: 0 0 6px;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.compare-box p {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.evidence-block {
  margin-top: 10px;
  display: grid;
  gap: 8px;
  justify-items: start;
}
.evidence-shot {
  max-width: 100%;
  max-height: 220px;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: contain;
  background: #0a0e12;
}

.comment-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.settings-form {
  display: grid;
  gap: 14px;
  max-width: 720px;
}
.settings-group {
  display: grid;
  gap: 8px;
}
.settings-group label {
  display: grid;
  gap: 4px;
  font-size: 13px;
}
.settings-group label span { color: var(--muted); font-size: 12px; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.checkbox-row input { width: auto; }

.toast-root {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}
.toast {
  min-width: 260px;
  max-width: 420px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #1a2330;
  box-shadow: var(--shadow);
  animation: slideIn 0.2s ease;
}
.toast.success { border-color: rgba(127,231,196,0.5); }
.toast.error { border-color: rgba(255,127,157,0.5); }
.toast.info { border-color: rgba(182,160,255,0.5); }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(12px); }
  to { opacity: 1; transform: translateX(0); }
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 32px 16px;
}

.filter-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.pagination-bar {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at top, #1a2433, #0b1015 60%);
}
.login-card {
  width: min(420px, 92vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.login-card h1 {
  margin: 0;
  color: var(--mint);
}
.login-form {
  display: grid;
  gap: 12px;
  margin: 18px 0;
}
.login-form label {
  display: grid;
  gap: 6px;
  font-size: 13px;
}
.login-form label span { color: var(--muted); }
.login-error {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255,127,157,0.45);
  color: var(--danger);
  background: rgba(255,127,157,0.08);
  font-size: 13px;
}
.login-form .btn { width: 100%; }

@media (max-width: 960px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--line); }
  .tabs { flex-direction: row; flex-wrap: wrap; }
  .grid-2, .grid-3, .compare-grid { grid-template-columns: 1fr; }
  .reconcile-controls { grid-template-columns: 1fr; }
  .comment-cards { grid-template-columns: 1fr; }
}
