@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ==================== CSS Variables ==================== */
:root {
  --primary: #7C3AED;
  --primary-dark: #5B21B6;
  --primary-light: #EDE9FE;
  --primary-mid: #A78BFA;

  --success: #16A34A;
  --success-light: #DCFCE7;

  --danger: #DC2626;
  --danger-light: #FEE2E2;

  --warning: #D97706;
  --warning-light: #FEF3C7;

  --info: #2563EB;
  --info-light: #DBEAFE;

  --bg: #F1F5F9;
  --surface: #FFFFFF;
  --surface-2: #F8FAFC;
  --border: #E2E8F0;
  --border-dark: #CBD5E1;

  --text-primary: #0F172A;
  --text-secondary: #475569;
  --text-muted: #94A3B8;
  --text-inverse: #FFFFFF;

  --shadow-xs: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -1px rgba(0,0,0,0.04);
  --shadow-md: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
  --shadow-lg: 0 20px 25px -5px rgba(0,0,0,0.08), 0 10px 10px -5px rgba(0,0,0,0.03);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --nav-height: 68px;
  --transition: all 0.2s ease;
}

/* ==================== Base Reset ==================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', 'Poppins', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: var(--transition);
}
a:hover { color: var(--primary-dark); }

/* ==================== Navbar ==================== */
.navbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  background: var(--primary);
  min-height: var(--nav-height);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  padding: 0 24px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.18);
  gap: 0;
}

.navbar-brand {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-inverse);
  letter-spacing: -0.3px;
  white-space: nowrap;
  flex-shrink: 0;
  padding: 16px 0;
}
.navbar-brand:hover { color: rgba(255,255,255,0.92); }

.navbar-spacer { flex: 1; }

.navbar-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 10px;
  margin-left: auto;
  color: white;
  flex-shrink: 0;
}
.navbar-toggle .bar {
  display: block;
  width: 22px;
  height: 2px;
  background: white;
  margin: 4px 0;
  transition: var(--transition);
  border-radius: 2px;
}

.navbar-menu {
  display: flex;
  align-items: center;
  gap: 4px;
}

.navbar-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  list-style: none;
}

.navbar-nav .nav-link {
  color: rgba(255,255,255,0.82);
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  transition: var(--transition);
  white-space: nowrap;
  display: block;
}
.navbar-nav .nav-link:hover,
.navbar-nav .nav-link.active {
  color: var(--text-inverse);
  background: rgba(255,255,255,0.16);
}
.navbar-nav .nav-link.logout {
  background: rgba(255,255,255,0.13);
  border: 1px solid rgba(255,255,255,0.22);
  margin-left: 4px;
}
.navbar-nav .nav-link.logout:hover {
  background: rgba(255,255,255,0.24);
}

.nav-user {
  color: rgba(255,255,255,0.7);
  font-size: 12.5px;
  padding: 5px 12px;
  background: rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  margin-left: 8px;
  white-space: nowrap;
}
.nav-user strong { color: rgba(255,255,255,0.95); }

/* ==================== Page Layout ==================== */
.page-wrapper {
  padding-top: calc(var(--nav-height) + 28px);
  padding-bottom: 56px;
  min-height: 100vh;
}

.container {
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 24px;
}
.container-sm { max-width: 520px; }
.container-md { max-width: 860px; }

/* ==================== Cards ==================== */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 32px;
  border: 1px solid var(--border);
}
.card-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
  text-align: center;
}
.card-subtitle {
  font-size: 13.5px;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 28px;
}

/* ==================== Buttons ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.4;
  font-family: inherit;
}
.btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(124,58,237,0.35);
  color: white;
}
.btn-primary:active:not(:disabled) { transform: translateY(0); box-shadow: none; }

.btn-secondary {
  background: var(--surface);
  color: var(--text-primary);
  border: 1.5px solid var(--border-dark);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--bg);
  border-color: var(--primary);
  color: var(--primary);
}

.btn-success { background: var(--success); color: white; }
.btn-success:hover:not(:disabled) { background: #15803D; color: white; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover:not(:disabled) { background: #B91C1C; color: white; }

.btn-lg { padding: 13px 28px; font-size: 15px; border-radius: var(--radius); }
.btn-sm { padding: 6px 13px; font-size: 12.5px; }
.btn-full { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

@keyframes spin { to { transform: rotate(360deg); } }
.btn-loading { pointer-events: none; }
.btn-loading::after {
  content: '';
  display: inline-block;
  width: 13px; height: 13px;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-left: 6px;
}

/* ==================== Forms ==================== */
.form-group { margin-bottom: 20px; }

.form-label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.form-control {
  width: 100%;
  padding: 11px 14px;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  transition: var(--transition);
  font-family: inherit;
  resize: vertical;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(124,58,237,0.12);
}
.form-control::placeholder { color: var(--text-muted); }
.form-control.is-invalid { border-color: var(--danger); }
.form-control.is-invalid:focus { box-shadow: 0 0 0 3px rgba(220,38,38,0.12); }
.form-error { font-size: 12px; color: var(--danger); margin-top: 4px; }
textarea.form-control { min-height: 120px; line-height: 1.65; }

/* ==================== Alerts ==================== */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.alert-success { background: var(--success-light); color: #14532D; border: 1px solid #86EFAC; }
.alert-error   { background: var(--danger-light);  color: #7F1D1D; border: 1px solid #FCA5A5; }
.alert-warning { background: var(--warning-light); color: #78350F; border: 1px solid #FCD34D; }
.alert-info    { background: var(--info-light);    color: #1E3A5F; border: 1px solid #93C5FD; }

/* ==================== Tables ==================== */
.table-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  min-width: 580px;
}
.table thead tr { background: var(--primary); color: white; }
.table th {
  padding: 13px 16px;
  font-weight: 600;
  font-size: 12.5px;
  text-align: left;
  white-space: nowrap;
  letter-spacing: 0.3px;
}
.table td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #F7F8FF; }
.table tbody tr:nth-child(even) { background: #FAFBFF; }
.table tbody tr:nth-child(even):hover { background: #F4F5FF; }

/* Confidence coloring */
.score-high, .kp-high { color: var(--success); font-weight: 600; }
.score-medium, .kp-medium { color: var(--info); font-weight: 600; }
.score-low, .kp-low { color: var(--danger); font-weight: 600; }

/* Highlight spans (for review page text) */
.color-green { background: #DCFCE7; color: #14532D; border-radius: 3px; padding: 1px 4px; }
.color-blue  { background: #DBEAFE; color: #1E3A5F; border-radius: 3px; padding: 1px 4px; }
.color-red   { background: #FEE2E2; color: #7F1D1D; border-radius: 3px; padding: 1px 4px; }

/* ==================== Toggle Buttons ==================== */
.tri-state-toggle {
  display: inline-flex;
  background: rgba(165,170,174,0.18);
  box-shadow: inset 0 1px 4px rgba(0,0,0,0.08);
  border-radius: 20px;
  padding: 3px;
  gap: 2px;
}
.toggle-btn {
  padding: 5px 11px;
  border-radius: 16px;
  border: none;
  background: transparent;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  font-family: inherit;
}
.toggle-btn:hover { background: rgba(124,58,237,0.08); color: var(--primary); }
.toggle-btn.active          { background: var(--primary); color: white; box-shadow: 0 2px 6px rgba(124,58,237,0.28); }
.toggle-btn.active.active-yes { background: var(--success); box-shadow: 0 2px 6px rgba(22,163,74,0.28); }
.toggle-btn.active.active-no  { background: var(--danger);  box-shadow: 0 2px 6px rgba(220,38,38,0.28); }

/* ==================== Legend ==================== */
.legend-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 20px;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
  box-shadow: var(--shadow-xs);
}
.legend-item { display: flex; align-items: center; gap: 7px; }
.legend-dot { width: 11px; height: 11px; border-radius: 50%; flex-shrink: 0; }
.dot-green { background: var(--success); }
.dot-blue  { background: var(--info); }
.dot-red   { background: var(--danger); }

/* ==================== Pagination ==================== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 20px 0 4px;
  flex-wrap: wrap;
}
.pagination-btn {
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
}
.pagination-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.pagination-btn.active { background: var(--primary); border-color: var(--primary); color: white; box-shadow: 0 2px 6px rgba(124,58,237,0.3); }

/* ==================== Toast Notifications ==================== */
.toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 380px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  border-left: 4px solid var(--primary);
  animation: toastIn 0.28s ease;
  pointer-events: all;
}
.toast.toast-success { border-color: var(--success); }
.toast.toast-error   { border-color: var(--danger); }
.toast.toast-warning { border-color: var(--warning); }
.toast-icon { font-size: 17px; flex-shrink: 0; margin-top: 2px; }
.toast-body { flex: 1; }
.toast-title { font-weight: 600; font-size: 14px; color: var(--text-primary); }
.toast-message { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.toast-close {
  background: none; border: none;
  color: var(--text-muted); cursor: pointer;
  font-size: 18px; padding: 0; line-height: 1; flex-shrink: 0;
}
.toast-close:hover { color: var(--text-primary); }
@keyframes toastIn {
  from { transform: translateX(110%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ==================== Loading Overlay ==================== */
.loading-overlay {
  position: fixed; inset: 0;
  background: rgba(255,255,255,0.75);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9000;
  backdrop-filter: blur(2px);
}
.loading-overlay.active { display: flex; }
.spinner {
  width: 44px; height: 44px;
  border: 4px solid var(--primary-light);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ==================== Admin Switch ==================== */
.switch-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
}
.switch {
  position: relative;
  display: inline-block;
  width: 46px; height: 26px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  cursor: pointer; inset: 0;
  background: #CBD5E1;
  border-radius: 26px;
  transition: 0.3s;
}
.slider:before {
  position: absolute; content: '';
  height: 20px; width: 20px;
  left: 3px; bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.3s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
input:checked + .slider { background: var(--success); }
input:checked + .slider:before { transform: translateX(20px); }

/* ==================== Review Page ==================== */
.review-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}
.review-left {
  position: sticky;
  top: calc(var(--nav-height) + 20px);
}
.review-text-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  max-height: calc(100vh - 130px);
  overflow-y: auto;
  box-shadow: var(--shadow-sm);
  line-height: 1;
}
.review-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
  display: block;
}
.review-text {
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.8;
}
.meta-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  background: var(--primary-light);
  color: var(--primary-dark);
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 12px;
}

/* ==================== Selection Page ==================== */
.selection-options { display: flex; flex-direction: column; gap: 12px; }
.selection-btn {
  width: 100%;
  padding: 16px 24px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-family: inherit;
  text-decoration: none;
}
.selection-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.selection-btn:active { transform: translateY(0); }

.selection-divider {
  text-align: center;
  color: var(--text-muted);
  font-size: 12.5px;
  position: relative;
  padding: 4px 0;
}
.selection-divider::before,
.selection-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 38%;
  height: 1px;
  background: var(--border);
}
.selection-divider::before { left: 0; }
.selection-divider::after  { right: 0; }

/* ==================== File Upload ==================== */
.file-upload-area {
  border: 2px dashed var(--border-dark);
  border-radius: var(--radius);
  padding: 24px 16px;
  text-align: center;
  transition: var(--transition);
  cursor: pointer;
}
.file-upload-area:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}
.file-upload-area input[type="file"] { display: none; }
.file-upload-label { font-size: 13.5px; color: var(--text-secondary); cursor: pointer; }
.file-upload-label strong { color: var(--primary); }

/* ==================== Consensus / Charts ==================== */
.chart-cell { display: flex; align-items: center; gap: 8px; }
.eye-btn {
  background: none; border: none;
  color: var(--text-muted); cursor: pointer;
  font-size: 15px; padding: 6px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  flex-shrink: 0;
}
.eye-btn:hover { color: var(--primary); background: var(--primary-light); }

/* ==================== Page Headers / Toolbars ==================== */
.page-header { margin-bottom: 20px; }
.page-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}
.page-meta { font-size: 13px; color: var(--text-secondary); margin-top: 3px; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

/* ==================== Home Page ==================== */
.home-hero {
  text-align: center;
  padding: 56px 24px 36px;
}
.home-hero h1 {
  font-size: 38px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.6px;
  margin-bottom: 16px;
  line-height: 1.25;
}
.home-hero p {
  font-size: 17px;
  color: var(--text-secondary);
  max-width: 540px;
  margin: 0 auto 32px;
  line-height: 1.7;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-top: 36px;
}
.feature-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 22px;
  text-align: center;
  transition: var(--transition);
  text-decoration: none;
  display: block;
}
.feature-card:hover {
  border-color: var(--primary-mid);
  box-shadow: var(--shadow-md);
  transform: translateY(-4px);
  color: inherit;
}
.feature-icon {
  width: 56px; height: 56px;
  background: var(--primary-light);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 14px;
  font-size: 22px;
  color: var(--primary);
}
.feature-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}
.feature-desc { font-size: 13px; color: var(--text-secondary); line-height: 1.6; }

/* ==================== Responsive ==================== */
@media (max-width: 1024px) {
  .review-layout { grid-template-columns: 1fr; }
  .review-left { position: static; }
  .review-text-box { max-height: none; }
}

@media (max-width: 768px) {
  :root { --nav-height: 60px; }

  .navbar { padding: 0 16px; }
  .navbar-toggle { display: flex; flex-direction: column; justify-content: center; }

  .navbar-menu {
    display: none;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    padding: 8px 0 14px;
    gap: 2px;
    border-top: 1px solid rgba(255,255,255,0.15);
    margin-top: 4px;
  }
  .navbar-menu.open { display: flex; }

  .navbar-nav { flex-direction: column; align-items: stretch; width: 100%; }
  .navbar-nav .nav-link { padding: 10px 12px; }
  .navbar-nav .nav-link.logout { margin-left: 0; margin-top: 4px; }
  .nav-user { margin: 6px 0 0; text-align: center; }

  .page-wrapper { padding-top: calc(var(--nav-height) + 16px); padding-bottom: 32px; }
  .container { padding: 0 16px; }

  .card { padding: 20px; border-radius: var(--radius); }
  .card-title { font-size: 19px; }

  .home-hero h1 { font-size: 26px; }
  .home-hero p { font-size: 15px; }
  .feature-grid { grid-template-columns: 1fr 1fr; }

  .toolbar { flex-direction: column; align-items: flex-start; }
  .legend-bar { flex-direction: column; align-items: flex-start; gap: 6px; }

  .toast-container { bottom: 16px; right: 16px; max-width: calc(100vw - 32px); }
}

@media (max-width: 480px) {
  .card { padding: 16px; }
  .btn-lg { padding: 12px 20px; font-size: 14px; }
  .table th, .table td { padding: 9px 12px; }
  .feature-grid { grid-template-columns: 1fr; }
  .home-hero { padding: 36px 12px 24px; }
  .home-hero h1 { font-size: 22px; }
}
