:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #2d3a4f;
  --text: #e8edf4;
  --text-muted: #8b9cb3;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #22c55e;
  --warning: #f59e0b;
  --error: #ef4444;
  --info: #06b6d4;
  --radius: 8px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "Cascadia Code", "Consolas", monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--surface2);
  padding: 0.1em 0.4em;
  border-radius: 4px;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-brand { display: flex; align-items: center; gap: 1rem; }

.logo {
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: white;
  font-weight: 700;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.app-header h1 { font-size: 1.1rem; font-weight: 600; }
.subtitle { font-size: 0.8rem; color: var(--text-muted); }

.header-actions { display: flex; gap: 0.5rem; align-items: center; }

.auth-user {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-right: 0.25rem;
}

.btn {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:not(:disabled):hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:not(:disabled):hover { background: var(--border); }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.8rem; width: 100%; }

.sidebar-actions {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

/* Layout */
.app-layout {
  display: grid;
  grid-template-columns: 260px 1fr 220px;
  min-height: calc(100vh - 60px);
}

.sidebar, .stats-panel {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1rem;
  overflow-y: auto;
}

.stats-panel { border-right: none; border-left: 1px solid var(--border); }

.sidebar-section { margin-bottom: 1.5rem; }
.sidebar-section h2, .stats-panel h2 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.hint { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 0.75rem; }

.file-list, .doc-list { list-style: none; }

.file-list li, .doc-list li {
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: background 0.15s;
}

.file-list li:hover { background: var(--surface2); }
.file-list li.active { background: var(--primary); color: white; }
.file-list li.reviewed::after {
  content: "✓";
  margin-left: auto;
  color: var(--success);
  font-size: 0.75rem;
}
.file-list li.active.reviewed::after { color: rgba(255,255,255,0.8); }

.doc-list li {
  cursor: default;
  color: var(--text-muted);
  font-size: 0.75rem;
  padding: 0.35rem 0.5rem;
}

.doc-list .doc-type {
  font-size: 0.65rem;
  background: var(--surface2);
  padding: 0.1em 0.4em;
  border-radius: 3px;
  text-transform: uppercase;
}

/* Main */
.main-content { padding: 1rem; overflow-y: auto; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  color: var(--text-muted);
  text-align: center;
}

.empty-icon { font-size: 3rem; margin-bottom: 1rem; opacity: 0.5; }
.empty-state h2 { color: var(--text); margin-bottom: 0.5rem; }

.hidden { display: none !important; }

.doc-summary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
}

.summary-item label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}

.summary-item span { font-size: 0.875rem; font-weight: 500; }

.valid-badge {
  display: inline-block;
  padding: 0.2em 0.6em;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.valid-badge.ok { background: rgba(34,197,94,0.15); color: var(--success); }
.valid-badge.fail { background: rgba(239,68,68,0.15); color: var(--error); }

/* Tabs */
.tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}

.tab {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-size: 0.875rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s;
}

.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.filters label { display: flex; align-items: center; gap: 0.35rem; cursor: pointer; }

/* Findings */
.findings-list { display: flex; flex-direction: column; gap: 0.5rem; }

.finding-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.875rem;
  border-left: 3px solid var(--border);
  transition: border-color 0.15s;
}

.finding-card.passed { opacity: 0.55; border-left-color: var(--success); }
.finding-card.failed.error { border-left-color: var(--error); }
.finding-card.failed.warning { border-left-color: var(--warning); }
.finding-card.failed.info { border-left-color: var(--info); }

.finding-header {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.finding-id {
  font-family: var(--mono);
  font-size: 0.7rem;
  background: var(--surface2);
  padding: 0.15em 0.5em;
  border-radius: 4px;
  flex-shrink: 0;
}

.severity-badge {
  font-size: 0.65rem;
  text-transform: uppercase;
  font-weight: 600;
  padding: 0.15em 0.5em;
  border-radius: 4px;
  flex-shrink: 0;
}

.severity-badge.error { background: rgba(239,68,68,0.15); color: var(--error); }
.severity-badge.warning { background: rgba(245,158,11,0.15); color: var(--warning); }
.severity-badge.info { background: rgba(6,182,212,0.15); color: var(--info); }

.finding-desc { font-size: 0.875rem; flex: 1; }

.finding-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.finding-meta .ref { font-style: italic; }

.finding-location {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.btn-goto-xml {
  background: rgba(59, 130, 246, 0.12);
  color: var(--primary);
  border: 1px solid rgba(59, 130, 246, 0.35);
  border-radius: var(--radius);
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn-goto-xml:hover {
  background: rgba(59, 130, 246, 0.22);
  border-color: var(--primary);
}

.finding-xpath {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  background: var(--surface2);
  padding: 0.15em 0.45em;
  border-radius: 4px;
}

.finding-fragment {
  font-family: var(--mono);
  font-size: 0.72rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--warning);
  padding: 0.5rem 0.65rem;
  border-radius: 4px;
  margin-bottom: 0.5rem;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.finding-card.failed.error .finding-fragment { border-left-color: var(--error); }
.finding-card.failed.warning .finding-fragment { border-left-color: var(--warning); }
.finding-card.failed.info .finding-fragment { border-left-color: var(--info); }

.finding-card.failed {
  cursor: pointer;
}

.finding-card.failed:hover {
  border-color: var(--primary);
}

.finding-card.finding-active {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.finding-detail {
  font-family: var(--mono);
  font-size: 0.75rem;
  background: var(--bg);
  padding: 0.5rem;
  border-radius: 4px;
  margin-bottom: 0.5rem;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.correction-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.correction-controls select,
.correction-controls input {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.35rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8rem;
}

.correction-controls input { flex: 1; min-width: 180px; }

/* XML view */
.xml-view-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.xml-view-hint strong {
  color: var(--text);
  font-weight: 500;
}

.xml-view {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.6;
  overflow: auto;
  max-height: calc(100vh - 280px);
  white-space: pre-wrap;
  word-break: break-word;
}

.xml-view-lines {
  padding: 0.5rem 0;
}

.xml-line {
  display: flex;
  gap: 0.75rem;
  padding: 0 1rem;
  min-height: 1.6em;
}

.xml-ln {
  color: var(--text-muted);
  user-select: none;
  min-width: 3.5rem;
  text-align: right;
  flex-shrink: 0;
  opacity: 0.65;
}

.xml-line-content {
  flex: 1;
  min-width: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.xml-line-highlight {
  background: rgba(245, 158, 11, 0.14);
  box-shadow: inset 3px 0 0 var(--warning);
}

.xml-line-highlight.error {
  background: rgba(239, 68, 68, 0.14);
  box-shadow: inset 3px 0 0 var(--error);
}

.xml-line-highlight.warning {
  background: rgba(245, 158, 11, 0.14);
  box-shadow: inset 3px 0 0 var(--warning);
}

.xml-line-highlight.info {
  background: rgba(6, 182, 212, 0.14);
  box-shadow: inset 3px 0 0 var(--info);
}

.xml-view .tag { color: #7dd3fc; }
.xml-view .attr { color: #fcd34d; }
.xml-view .val { color: #86efac; }
.xml-view .xml-comment { color: #8b9cb3; font-style: italic; }

/* Rules */
.rules-view { display: flex; flex-direction: column; gap: 0.35rem; }

.rule-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  display: grid;
  grid-template-columns: 70px 90px 1fr;
  gap: 0.5rem;
  align-items: center;
}

/* Stats */
.stats { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1.5rem; }

.stat {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 0.75rem;
  text-align: center;
}

.stat-num { display: block; font-size: 1.5rem; font-weight: 700; }
.stat-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; }
.stat-ok .stat-num { color: var(--success); }
.stat-error .stat-num { color: var(--error); }
.stat-warning .stat-num { color: var(--warning); }

.review-progress h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.progress-bar {
  height: 6px;
  background: var(--surface2);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 0.35rem;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width 0.3s;
  width: 0%;
}

.progress-text { font-size: 0.75rem; color: var(--text-muted); }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 1rem;
}

.modal-backdrop.hidden { display: none; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 { font-size: 1rem; font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.25rem;
}

.modal-close:hover { color: var(--text); }

.modal-body {
  padding: 1.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
}

.field-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.field-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.875rem;
}

.field-textarea {
  width: 100%;
  min-height: 280px;
  padding: 0.75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.45;
  resize: vertical;
}

.field-input:focus,
.field-textarea:focus {
  outline: none;
  border-color: var(--primary);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 200;
  transition: opacity 0.3s;
}

.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--error); }

@media (max-width: 1100px) {
  .app-layout { grid-template-columns: 220px 1fr; }
  .stats-panel { display: none; }
}

@media (max-width: 768px) {
  .app-layout { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); }
}
