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

:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --green: #16a34a;
  --red: #dc2626;
  --sidebar-w: 220px;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  padding: 1.5rem 1rem;
}

.sidebar-header { margin-bottom: 2rem; }
.logo { font-size: 1.25rem; font-weight: 700; color: var(--accent); }
.logo-sub { font-size: 0.75rem; color: var(--text-muted); margin-left: 4px; }

.nav-links { list-style: none; flex: 1; }
.nav-links li { margin-bottom: 4px; }
.nav-links a {
  display: block;
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
}
.nav-links a:hover { background: var(--bg); color: var(--text); }
.nav-links a.active { background: #eff6ff; color: var(--accent); }

.sidebar-footer { border-top: 1px solid var(--border); padding-top: 1rem; }
.user-name { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logout { font-size: 12px; color: var(--text-muted); text-decoration: none; }
.logout:hover { color: var(--red); }

/* Main content */
.content {
  margin-left: var(--sidebar-w);
  padding: 2rem;
  flex: 1;
  max-width: 1100px;
}

.page-header {
  display: flex;
  align-items: baseline;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.page-header h1 { font-size: 1.4rem; font-weight: 700; }

/* Tabs */
.tab-bar { display: flex; gap: 4px; }
.tab {
  padding: 5px 14px;
  border-radius: 6px;
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 13px;
}
.tab:hover { background: var(--border); color: var(--text); }
.tab.active { background: var(--accent); color: white; }

/* Badge */
.badge {
  background: var(--red);
  color: white;
  border-radius: 99px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 600;
  margin-left: 4px;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
}
.card h2 { font-size: 1rem; margin-bottom: 1rem; }

section { margin-bottom: 2rem; }
section h2 { font-size: 1rem; font-weight: 600; margin-bottom: 0.75rem; }

/* Queue cards */
.tier-high { background: #dcfce7; color: #15803d; }
.tier-medium { background: #fef9c3; color: #854d0e; }
.tier-low { background: #fee2e2; color: var(--red); }

.item-meta { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }
.item-meta span strong { color: var(--text); }

.item-list { display: flex; flex-direction: column; gap: 1rem; }
.queue-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
}
.card-header { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.item-title { font-weight: 600; flex: 1; }
.item-date { font-size: 12px; color: var(--text-muted); }
.item-desc { color: var(--text-muted); margin-bottom: 10px; line-height: 1.5; }
.doc-link { font-size: 13px; color: var(--accent); text-decoration: none; display: inline-block; margin-bottom: 10px; }
.doc-link:hover { text-decoration: underline; }

/* Decide form */
.decide-form { margin-top: 10px; }
.decide-form textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  font-size: 13px;
  resize: vertical;
  margin-bottom: 8px;
  font-family: inherit;
}
.decide-buttons { display: flex; gap: 8px; }

.review-info { font-size: 12px; color: var(--text-muted); margin-top: 8px; }
.review-notes { font-style: italic; margin-top: 4px; }

/* Tags */
.tag {
  background: #f1f5f9;
  color: #475569;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Buttons */
.btn {
  padding: 7px 16px;
  border-radius: 6px;
  border: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-approve { background: var(--green); color: white; }
.btn-approve:hover { background: #15803d; }
.btn-reject { background: var(--red); color: white; }
.btn-reject:hover { background: #b91c1c; }
.btn-danger { background: #fee2e2; color: var(--red); }
.btn-danger:hover { background: #fecaca; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* Upload form */
.upload-form { display: flex; flex-direction: column; gap: 10px; }
.form-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.form-row label, .upload-form label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; flex: 1; min-width: 200px; }
input[type="text"], input[type="file"] {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
}

/* Table */
.data-table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.data-table th { background: var(--bg); text-align: left; padding: 10px 14px; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px solid var(--border); }
.data-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table tr:last-child td { border-bottom: none; }
.data-table a { color: var(--accent); text-decoration: none; }
.data-table a:hover { text-decoration: underline; }

/* Misc */
.empty-state { color: var(--text-muted); padding: 2rem 0; }
.hint { color: var(--text-muted); font-size: 12px; }
.mono { font-family: ui-monospace, monospace; }
.small { font-size: 12px; }
.file-list { list-style: none; display: flex; flex-direction: column; gap: 4px; }
.file-list li { font-family: ui-monospace, monospace; font-size: 13px; color: var(--text-muted); }

.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 1rem; font-size: 13px; }
.flash-error { background: #fee2e2; color: var(--red); }
.flash-success { background: #dcfce7; color: var(--green); }

/* Documents page */
.doc-table-header { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 1rem; }
.doc-table-header h2 { margin: 0; }
.filter-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.filter-label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.filter-chip { font-size: 12px; padding: 3px 10px; border-radius: 99px; text-decoration: none; color: var(--text-muted); border: 1px solid var(--border); }
.filter-chip:hover { border-color: var(--accent); color: var(--accent); }
.filter-chip.active { background: var(--accent); color: white; border-color: var(--accent); }
.view-link { color: var(--accent); text-decoration: none; font-size: 13px; font-weight: 500; white-space: nowrap; }
.view-link:hover { text-decoration: underline; }
.pagination { display: flex; align-items: center; gap: 12px; justify-content: center; padding: 1rem 0 0.25rem; border-top: 1px solid var(--border); margin-top: 0.5rem; }
.page-btn { font-size: 13px; font-weight: 500; color: var(--accent); text-decoration: none; padding: 5px 12px; border-radius: 6px; border: 1px solid var(--border); }
.page-btn:hover { background: var(--bg); }
.page-btn.disabled { color: var(--text-muted); pointer-events: none; }
.page-info { font-size: 13px; color: var(--text-muted); }

/* Status badges */
.status-badge { padding: 2px 10px; border-radius: 99px; font-size: 11px; font-weight: 600; }
.status-complete { background: #dcfce7; color: var(--green); }
.status-running { background: #fef9c3; color: #854d0e; }
.status-pending { background: #f1f5f9; color: #64748b; }
.status-failed { background: #fee2e2; color: var(--red); cursor: help; }
.status-untracked { background: #f1f5f9; color: #94a3b8; }
.tag.processing { background: #fef9c3; color: #854d0e; }
.error-row td { padding: 4px 14px 10px; }
.error-detail { color: var(--red); background: #fff5f5; padding: 8px 12px; border-radius: 4px; display: block; }

/* Card actions row */
.card-actions { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.inline-form { display: flex; gap: 8px; }
.btn-secondary { background: #f1f5f9; color: #475569; }
.btn-secondary:hover { background: var(--border); }

/* Edit rule form */
.back-link { font-size: 13px; color: var(--text-muted); text-decoration: none; }
.back-link:hover { color: var(--text); }
.source-box { background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; padding: 1rem 1.25rem; margin-bottom: 1.5rem; }
.source-box .label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); display: block; margin-bottom: 6px; }
.source-box p { font-style: italic; color: var(--text); line-height: 1.5; margin-bottom: 8px; }
.edit-form { display: flex; flex-direction: column; gap: 1.5rem; }
.form-section { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 1.25rem 1.5rem; }
.form-section h2 { font-size: 0.9rem; font-weight: 600; margin-bottom: 1rem; }
.field-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.field-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 500; }
.field-grid input, .field-grid select, .field-grid textarea { border: 1px solid var(--border); border-radius: 6px; padding: 7px 10px; font-size: 13px; font-family: inherit; }
.full-width { grid-column: 1 / -1; }
details summary { cursor: pointer; font-weight: 600; font-size: 13px; color: var(--text-muted); }
details summary:hover { color: var(--text); }
.readonly-section { background: var(--bg); }
.readonly-grid { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; font-size: 13px; align-items: center; }
.readonly-grid span:first-child { color: var(--text-muted); }
.decide-section textarea { width: 100%; border: 1px solid var(--border); border-radius: 6px; padding: 8px; font-size: 13px; font-family: inherit; resize: vertical; margin-bottom: 10px; }
.decide-section .decide-buttons { display: flex; gap: 8px; flex-wrap: wrap; }

/* Review issues — queue card and edit page */
.review-issues { margin: 8px 0 0 0; padding: 10px 10px 10px 28px; background: #fffbeb; border: 1px solid #f59e0b; border-radius: 6px; font-size: 13px; line-height: 1.6; color: #92400e; list-style: disc; }
.review-issues li + li { margin-top: 4px; }
.review-issues-box { background: #fffbeb; border: 1px solid #f59e0b; border-radius: 8px; padding: 1rem 1.25rem; margin-bottom: 1.5rem; }
.review-issues-box .label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: #92400e; display: block; margin-bottom: 6px; }
.review-issues-box .review-issues { margin: 0; padding-left: 20px; background: none; border: none; color: #92400e; }

/* Corrections dashboard */
.stats-grid { display: flex; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 1.25rem 1.5rem; min-width: 160px; }
.stat-number { display: block; font-size: 2rem; font-weight: 700; color: var(--text); }
.stat-label { display: block; font-size: 0.8rem; color: var(--muted); margin-top: 0.25rem; }
.stat-ready .stat-number { color: #22c55e; }
.stat-close .stat-number { color: #f59e0b; }
.stat-not-ready .stat-number { color: var(--muted); }
.info-box { background: #eff6ff; border-left: 3px solid #3b82f6; padding: 0.75rem 1rem; border-radius: 4px; margin-bottom: 1.5rem; font-size: 0.875rem; color: var(--text); }
.info-box-amber { background: #fffbeb; border-left-color: #f59e0b; }
.info-box-green { background: #f0fdf4; border-left-color: #22c55e; }
.info-box code { background: #e2e8f0; color: #1a1d23; padding: 0.1rem 0.4rem; border-radius: 3px; font-size: 0.8rem; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; margin-bottom: 2rem; }
.simple-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; margin-bottom: 1.5rem; }
.simple-table th { text-align: left; padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border); color: var(--muted); font-weight: 600; }
.simple-table td { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border); }
.small { font-size: 0.8rem; }
.eval-form { margin-top: 1.5rem; }
.eval-form-inner { padding: 0.75rem 0; }
.tag.tier-approved { background: #14532d; color: #86efac; }
.tag.tier-rejected { background: #450a0a; color: #fca5a5; }
.tag.tier-saved { background: #1e293b; color: var(--muted); }

/* Document actions */
.actions-cell { white-space: nowrap; }
.actions-group { display: flex; align-items: center; gap: 12px; }
.btn-link-danger { background: none; border: none; color: var(--red); font-size: 13px; font-weight: 500; cursor: pointer; padding: 0; font-family: inherit; }
.btn-link-danger:hover { text-decoration: underline; }
.replace-row td { border-bottom: 1px solid var(--border); }
.replace-cell { padding: 0 14px !important; }
.replace-details { padding: 6px 0; }
.replace-details > summary { font-size: 12px; color: var(--accent); cursor: pointer; font-weight: 500; list-style: none; display: inline; }
.replace-details > summary::-webkit-details-marker { display: none; }
.replace-details > summary::before { content: '+ '; }
.replace-details[open] > summary::before { content: '− '; }
.replace-details > summary:hover { text-decoration: underline; }
.replace-upload-form { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 0 6px; }
.replace-upload-form .hint { flex-basis: 100%; margin-top: 2px; }

/* Carrier tier badges */
.tier-badge { padding: 2px 10px; border-radius: 99px; font-size: 11px; font-weight: 600; display: inline-block; }
.tier-badge.tier-1 { background: #dcfce7; color: #15803d; }
.tier-badge.tier-2 { background: #dbeafe; color: #1d4ed8; }
.tier-badge.tier-3 { background: #fef9c3; color: #854d0e; }
.tier-badge.tier-null { background: var(--bg); color: var(--text-muted); }
.tier-form { display: flex; gap: 6px; align-items: center; }
.tier-select { font-size: 13px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); }
.page-desc { color: var(--text-muted); font-size: 13px; margin: 4px 0 16px; }
