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

:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --border: #e0e0e0;
  --text: #333;
  --text-muted: #777;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  padding: 0;
  margin: 0;
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
}

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

.logo {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--primary);
  text-decoration: none;
}

.header-nav { display: flex; gap: 0.25rem; }
.header-nav a {
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  font-size: 0.85rem;
  transition: background 0.15s;
}
.header-nav a:hover { background: var(--bg); }

.nav-group { display: flex; align-items: center; gap: 0.15rem; }
.nav-label { font-size: 0.65rem; font-weight: 700; text-transform: uppercase; color: var(--text-muted); padding: 0 0.4rem; letter-spacing: 0.04em; }
.nav-sep { color: var(--border); font-size: 0.85rem; margin: 0 0.15rem; }

/* ─── Role Switcher (admin) ─── */
.role-switcher { display: flex; gap: 0.2rem; }
.role-switch-btn {
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  text-decoration: none;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
  transition: all 0.15s;
}
.role-switch-btn:hover { background: var(--bg); color: var(--text); }
.role-switch-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.role-switch-btn.active:hover { background: var(--primary-hover); }

.header-right { display: flex; align-items: center; gap: 0.5rem; }
.user-name { font-size: 0.85rem; color: var(--text-muted); }

/* ─── Role Badges ─── */
.user-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.role-admin { background: #fef3c7; color: #92400e; }
.role-reviewer { background: #dbeafe; color: #1e40af; }
.role-author { background: #d1fae5; color: #065f46; }

/* ─── Page Title ─── */
.page-title { font-size: 1.5rem; margin: 1rem 0; }

/* ─── Login ─── */
.login-container {
  max-width: 400px;
  margin: 5rem auto;
  padding: 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
}
.login-container h1 { font-size: 1.5rem; color: var(--primary); }
.login-container .subtitle { color: var(--text-muted); margin: 0.25rem 0 1.5rem; }
.login-form { text-align: left; }
.login-form input { width: 100%; padding: 0.6rem; border: 1px solid var(--border); border-radius: var(--radius); font-size: 0.9rem; }

.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 0.65rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, box-shadow 0.15s;
}
.btn-google:hover { background: #f9fafb; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }

.divider {
  display: flex;
  align-items: center;
  margin: 1.25rem 0;
  color: var(--text-muted);
  font-size: 0.8rem;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.divider span { padding: 0 0.75rem; }

/* ─── Stats Grid ─── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
}
.stat-number { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.15rem; }
.stat-detail { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.35rem; }

/* ─── Panel ─── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.panel h2 { font-size: 1.1rem; margin-bottom: 0.75rem; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 768px) { .form-grid { grid-template-columns: 1fr; } }

/* ─── Data Table ─── */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.data-table th, .data-table td { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border); text-align: left; }
.data-table th { font-weight: 600; color: var(--text-muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
.data-table tbody tr:hover { background: #f9fafb; }

/* ─── Status Badges ─── */
.status-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
}
.status-pending { background: #fef3c7; color: #92400e; }
.status-in_review { background: #dbeafe; color: #1e40af; }
.status-reviewed { background: #d1fae5; color: #065f46; }
.status-ok { background: #d1fae5; color: #065f46; }
.provider-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 600;
  background: #ede9fe;
  color: #5b21b6;
}

/* ─── Quick Actions ─── */
.quick-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.quick-actions .btn { flex: 1; min-width: 140px; text-align: center; text-decoration: none; }

/* ─── Empty State ─── */
.empty-state { text-align: center; color: var(--text-muted); padding: 2rem; }

/* ─── Tabs ─── */
.tab-bar { display: flex; gap: 0; margin-bottom: 0.75rem; }
.tab {
  padding: 0.4rem 1rem;
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  font-size: 0.85rem;
}
.tab:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.tab:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ─── File drop zones ─── */
.file-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  text-align: center;
  margin-bottom: 0.75rem;
}
.file-drop:hover, .file-drop.dragover { border-color: var(--primary); background: #eef2ff; }
.file-drop input[type="file"] { display: none; }
.drop-text { color: var(--text-muted); font-size: 0.9rem; }
.file-name { color: var(--primary); font-weight: 600; font-size: 0.9rem; margin-top: 0.25rem; }

/* ─── Form elements ─── */
textarea {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.8rem;
  resize: vertical;
}
select, input[type="text"], input[type="email"], input[type="password"] {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  background: var(--surface);
}
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 600; margin-bottom: 0.25rem; font-size: 0.9rem; }
.hint { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.25rem; }

/* ─── Buttons ─── */
.btn {
  display: inline-block;
  padding: 0.5rem 1.25rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.2s;
  text-decoration: none;
  text-align: center;
}
.btn-primary { background: var(--primary); color: #fff; width: 100%; padding: 0.75rem; font-size: 1rem; font-weight: 600; margin-top: 0.5rem; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-small { padding: 0.35rem 0.75rem; font-size: 0.8rem; background: var(--bg); border: 1px solid var(--border); color: var(--text); }
.btn-small:hover { background: var(--border); }
.btn-danger { background: #fef2f2; color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fecaca; }

/* ─── Progress bar ─── */
.progress-bar { width: 100%; height: 4px; background: var(--bg); border-radius: 2px; margin-bottom: 1rem; overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); width: 0%; border-radius: 2px; animation: progress-pulse 2s ease-in-out infinite; }
@keyframes progress-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

/* ─── Results ─── */
.results-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; flex-wrap: wrap; gap: 0.5rem; }
.results-actions { display: flex; gap: 0.5rem; align-items: center; }

.review-output { font-size: 0.9rem; line-height: 1.7; }
.review-output h1 { font-size: 1.4rem; margin: 1rem 0 0.5rem; }
.review-output h2 { font-size: 1.15rem; margin: 1rem 0 0.5rem; border-bottom: 1px solid var(--border); padding-bottom: 0.3rem; }
.review-output h3 { font-size: 1rem; margin: 0.75rem 0 0.35rem; }
.review-output p { margin-bottom: 0.5rem; }
.review-output ul, .review-output ol { margin: 0.35rem 0 0.5rem 1.5rem; }
.review-output li { margin-bottom: 0.2rem; }
.review-output table { width: 100%; border-collapse: collapse; margin: 0.75rem 0; }
.review-output th, .review-output td { padding: 0.4rem 0.75rem; border: 1px solid var(--border); text-align: left; }
.review-output th { background: var(--bg); font-weight: 600; }
.review-output strong { color: var(--text); }
.review-output hr { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }

/* ─── Messages ─── */
.error-msg { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.9rem; }
.success-msg { background: #f0fdf4; color: var(--success); border: 1px solid #bbf7d0; padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.9rem; }

/* ─── Criteria Editor ─── */
.criteria-toolbar { display: flex; gap: 0.5rem; margin-bottom: 0.75rem; align-items: center; }
.template-select { flex: 1; }
.editor-section { margin-bottom: 0.75rem; }
.form-row { display: flex; gap: 0.5rem; }
.form-row .form-group { flex: 1; }
.form-row .form-group label { font-size: 0.8rem; }
.form-row .form-group input { padding: 0.35rem 0.5rem; font-size: 0.85rem; }

.criteria-list { display: flex; flex-direction: column; gap: 0.75rem; max-height: 55vh; overflow-y: auto; padding-right: 0.25rem; }
.criterion-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  background: #fafafa;
}
.criterion-header { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
.criterion-num { font-weight: 700; color: var(--primary); font-size: 0.9rem; min-width: 1.2rem; }
.criterion-name { flex: 1; font-weight: 600; padding: 0.3rem 0.5rem; border: 1px solid var(--border); border-radius: 4px; font-size: 0.85rem; }
.criterion-weight-group { display: flex; align-items: center; gap: 0.2rem; font-size: 0.8rem; white-space: nowrap; }
.criterion-weight-group label { font-size: 0.75rem; color: var(--text-muted); }
.criterion-weight { width: 50px; padding: 0.25rem; text-align: center; border: 1px solid var(--border); border-radius: 4px; font-size: 0.8rem; }
.criterion-desc { width: 100%; padding: 0.35rem 0.5rem; border: 1px solid var(--border); border-radius: 4px; font-size: 0.8rem; font-family: inherit; resize: vertical; margin-bottom: 0.5rem; }

.sub-criteria { margin-left: 1.5rem; }
.sub-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.35rem; }
.sub-header strong { font-size: 0.8rem; color: var(--text-muted); }
.sub-weight-total { font-size: 0.75rem; font-weight: 600; }
.sub-criterion-row { display: flex; align-items: center; gap: 0.35rem; margin-bottom: 0.3rem; }
.sub-question { flex: 1; padding: 0.25rem 0.4rem; border: 1px solid var(--border); border-radius: 4px; font-size: 0.8rem; }
.sub-weight { width: 45px; padding: 0.25rem; text-align: center; border: 1px solid var(--border); border-radius: 4px; font-size: 0.8rem; }
.sub-pct { font-size: 0.75rem; color: var(--text-muted); }
.sub-delete { padding: 0.1rem 0.4rem; font-size: 0.8rem; line-height: 1; }
.add-sub-btn { margin-top: 0.35rem; margin-left: 1.5rem; font-size: 0.75rem; }

.criteria-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 0.75rem; }
.weight-total { font-size: 0.85rem; font-weight: 700; }
