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

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

:root {
  --bg: #f8fafc;
  --bg-subtle: #f1f5f9;
  --card: #ffffff;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #ede9fe;
  --primary-ring: rgba(79,70,229,0.15);
  --danger: #dc2626;
  --success: #059669;
  --text: #0f172a;
  --text-secondary: #475569;
  --muted: #94a3b8;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --radius: 8px;
  --radius-sm: 5px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 4px 16px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 8px rgba(0,0,0,0.06), 0 12px 32px rgba(0,0,0,0.07);
  --shadow-lg: 0 20px 60px rgba(0,0,0,0.12), 0 8px 24px rgba(0,0,0,0.08);
  --transition: 0.15s ease;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

::placeholder { color: var(--muted); }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── Nav ──────────────────────────────────────────────── */

header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.logo {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  letter-spacing: -0.025em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
}

.logo-icon {
  width: 30px;
  height: 30px;
  background: var(--primary);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(79,70,229,0.3);
}

nav { display: flex; gap: 0.2rem; align-items: center; }
nav a {
  text-decoration: none;
  color: var(--text-secondary);
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  transition: all var(--transition);
}
nav a:hover { color: var(--primary); background: var(--primary-light); }
nav a.active {
  color: var(--primary);
  background: var(--primary-light);
  font-weight: 600;
}

.nav-divider {
  display: inline-block;
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 0.4rem;
}

#user-email {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
  padding: 0 0.25rem;
}

#btn-logout {
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 500;
  text-decoration: none;
  border: 1px solid var(--border);
  padding: 0.3rem 0.8rem;
  border-radius: var(--radius);
  transition: all var(--transition);
}
#btn-logout:hover {
  background: var(--bg-subtle);
  border-color: var(--border-strong);
  color: var(--text);
}

/* ── Layout ───────────────────────────────────────────── */

.container { max-width: 1200px; margin: 2rem auto; padding: 0 1.5rem; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
  transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow-md); }
.card h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1.25rem;
  color: var(--text);
  letter-spacing: -0.015em;
}

.hidden { display: none !important; }

/* ── Auth ─────────────────────────────────────────────── */

#auth-section {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, #eef2ff 0%, #f8fafc 55%, #ecfdf5 100%);
}

.auth-container {
  max-width: 400px;
  width: 100%;
  padding: 0 1.5rem;
}

.auth-logo {
  text-align: center;
  margin-bottom: 1.75rem;
}

.auth-logo-icon {
  width: 52px;
  height: 52px;
  background: var(--primary);
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.875rem;
  box-shadow: 0 8px 24px rgba(79,70,229,0.28);
}

.auth-container h1 {
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.035em;
  margin-bottom: 0.25rem;
}

.auth-container .subtitle {
  color: var(--muted);
  font-size: 0.875rem;
}

.auth-container .card {
  padding: 2rem;
  box-shadow: var(--shadow-lg);
  border-radius: var(--radius-lg);
  border-color: transparent;
}

/* ── Forms ────────────────────────────────────────────── */

label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--text);
  letter-spacing: 0.005em;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="time"],
textarea,
select {
  width: 100%;
  padding: 0.55rem 0.875rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-family: inherit;
  margin-bottom: 1rem;
  background: var(--card);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

input:hover:not(:focus), textarea:hover:not(:focus), select:hover:not(:focus) {
  border-color: var(--border-strong);
}

textarea { resize: vertical; min-height: 100px; line-height: 1.6; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1rem;
  padding: 0.6rem 0.875rem;
  background: var(--bg-subtle);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color var(--transition);
}
.checkbox-row:hover { border-color: var(--border-strong); }
.checkbox-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  cursor: pointer;
  accent-color: var(--primary);
  flex-shrink: 0;
}
.checkbox-row label { margin: 0; cursor: pointer; font-weight: 500; font-size: 0.875rem; }

.hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: -0.65rem;
  margin-bottom: 1rem;
  line-height: 1.5;
}

/* ── Buttons ──────────────────────────────────────────── */

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.575rem 1.25rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: 0.005em;
  transition: all var(--transition);
  box-shadow: 0 1px 3px rgba(79,70,229,0.25), 0 1px 1px rgba(0,0,0,0.06);
}
button:hover:not(:disabled) {
  background: var(--primary-hover);
  box-shadow: 0 4px 14px rgba(79,70,229,0.32);
  transform: translateY(-1px);
}
button:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 1px 3px rgba(79,70,229,0.2);
}
button:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; transform: none; }

.btn-secondary {
  background: white;
  color: var(--text);
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--bg-subtle);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.btn-sm {
  padding: 0.275rem 0.65rem;
  font-size: 0.775rem;
  border-radius: var(--radius-sm);
  letter-spacing: 0;
}
.btn-apply {
  background: var(--success);
  color: white;
  border: none;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(5,150,105,0.2);
}
.btn-apply:hover:not(:disabled) {
  background: #047857;
  box-shadow: 0 4px 10px rgba(5,150,105,0.3);
}
.btn-reject {
  background: var(--danger);
  color: white;
  border: none;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(220,38,38,0.2);
}
.btn-reject:hover:not(:disabled) {
  background: #b91c1c;
  box-shadow: 0 4px 10px rgba(220,38,38,0.3);
}
.btn-undo {
  background: white;
  color: var(--text-secondary);
  border: 1.5px solid var(--border);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.btn-undo:hover:not(:disabled) {
  background: var(--bg-subtle);
  color: var(--text);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.link { color: var(--primary); text-decoration: none; font-size: 0.875rem; font-weight: 500; }
.link:hover { text-decoration: underline; }
.text-center { text-align: center; margin-top: 1rem; }

/* ── Status ───────────────────────────────────────────── */

.status {
  font-size: 0.825rem;
  font-weight: 500;
  margin-top: 0.6rem;
  min-height: 1.2rem;
}
.status.error { color: var(--danger); }
.status.success { color: var(--success); }

/* ── Table ────────────────────────────────────────────── */

.table-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

#sort-select {
  width: auto;
  min-width: 145px;
  padding: 0.35rem 0.7rem;
  font-size: 0.825rem;
  margin-bottom: 0;
  cursor: pointer;
  background: var(--bg-subtle);
  border-color: var(--border);
  font-weight: 500;
}

table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }

thead { position: sticky; }

th {
  text-align: left;
  padding: 0.625rem 0.875rem;
  background: var(--bg-subtle);
  border-bottom: 2px solid var(--border);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}
th:first-child { border-radius: var(--radius-sm) 0 0 0; }
th:last-child { border-radius: 0 var(--radius-sm) 0 0; }

td {
  padding: 0.75rem 0.875rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  transition: background var(--transition);
}
tr:last-child td { border-bottom: none; }
tr:not(:first-child):hover td { background: #f8fafc; }
tbody tr:hover td:first-child { border-left: 2px solid var(--primary-light); padding-left: calc(0.875rem - 2px); }

td.center, th.center { text-align: center; }
td a { color: var(--primary); text-decoration: none; font-weight: 500; }
td a:hover { text-decoration: underline; }

.loading {
  text-align: center;
  color: var(--muted);
  padding: 3.5rem 0;
  font-size: 0.875rem;
  animation: pulse 1.8s ease-in-out infinite;
}

/* ── Badges ───────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.badge::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.badge-new     { background: #ede9fe; color: #5b21b6; }
.badge-applied { background: #d1fae5; color: #065f46; }
.badge-rejected { background: #fee2e2; color: #991b1b; }

/* ── Score pills ──────────────────────────────────────── */

.score-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 700;
  min-width: 2.75rem;
  letter-spacing: -0.02em;
}
.score-perfect  { background: #d1fae5; color: #064e3b; }
.score-strong   { background: #dcfce7; color: #166534; }
.score-moderate { background: #fef3c7; color: #92400e; }
.score-partial  { background: #ffedd5; color: #9a3412; }
.score-poor     { background: #fee2e2; color: #991b1b; }
.score-none     { background: var(--bg-subtle); color: var(--muted); }

/* ── Rationale toggle & expanded row ─────────────────── */

.btn-rationale {
  background: var(--bg-subtle);
  color: var(--text-secondary);
  border: 1.5px solid var(--border);
  box-shadow: none;
}
.btn-rationale svg { transition: transform var(--transition); }
.btn-rationale.open svg { transform: rotate(180deg); }
.btn-rationale:hover:not(:disabled) {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary-light);
  box-shadow: none;
  transform: none;
}

.rationale-row td { border-bottom: none; }

.rationale-expanded-cell {
  padding: 0.75rem 1.25rem 1rem;
  font-size: 0.825rem;
  color: var(--text-secondary);
  line-height: 1.65;
  background: var(--bg-subtle);
  border-top: 1px solid var(--border);
}

/* ── Pay column ───────────────────────────────────────── */

.pay-cell {
  font-size: 0.825rem;
  font-weight: 500;
  white-space: nowrap;
  color: var(--text-secondary);
}
.pay-cell .muted { color: var(--muted); font-weight: 400; }

/* ── Progress bar ─────────────────────────────────────── */

.progress-track {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary) 0%, #818cf8 100%);
  border-radius: 3px;
  transition: width 0.7s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Animations ───────────────────────────────────────── */

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.45; }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.page { animation: fadeIn 0.2s ease both; }

.spinner {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  opacity: 0.7;
}

/* ── Dark mode ────────────────────────────────────────── */

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --bg-subtle: #1e293b;
    --card: #1e293b;
    --primary: #818cf8;
    --primary-hover: #6366f1;
    --primary-light: rgba(129,140,248,0.12);
    --primary-ring: rgba(129,140,248,0.2);
    --danger: #f87171;
    --success: #34d399;
    --text: #f1f5f9;
    --text-secondary: #94a3b8;
    --muted: #64748b;
    --border: #334155;
    --border-strong: #475569;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
    --shadow: 0 1px 3px rgba(0,0,0,0.35), 0 4px 16px rgba(0,0,0,0.25);
    --shadow-md: 0 4px 8px rgba(0,0,0,0.35), 0 12px 32px rgba(0,0,0,0.3);
    --shadow-lg: 0 20px 60px rgba(0,0,0,0.5), 0 8px 24px rgba(0,0,0,0.3);
  }

  #auth-section {
    background: linear-gradient(145deg, #1e1b4b 0%, #0f172a 55%, #042f2e 100%);
  }

  .auth-container .card { border-color: var(--border); }

  .auth-logo-icon { box-shadow: 0 8px 24px rgba(129,140,248,0.25); }

  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="time"],
  textarea,
  select {
    background: #162032;
    color: var(--text);
  }

  .checkbox-row { background: #162032; }

  tr:not(:first-child):hover td { background: #263348; }
  tbody tr:hover td:first-child { border-left-color: rgba(129,140,248,0.2); }

  .btn-secondary, .btn-undo {
    background: #162032;
    border-color: var(--border);
    color: var(--text-secondary);
    box-shadow: none;
  }
  .btn-secondary:hover:not(:disabled), .btn-undo:hover:not(:disabled) {
    background: var(--bg-subtle);
    color: var(--text);
    border-color: var(--border-strong);
  }

  button:not(.btn-secondary):not(.btn-undo):not(.btn-apply):not(.btn-reject) {
    box-shadow: 0 1px 3px rgba(129,140,248,0.15);
  }
  button:not(.btn-secondary):not(.btn-undo):not(.btn-apply):not(.btn-reject):hover:not(:disabled) {
    box-shadow: 0 4px 14px rgba(129,140,248,0.28);
  }

  .badge-new      { background: rgba(99,102,241,0.22);  color: #c7d2fe; }
  .badge-applied  { background: rgba(16,185,129,0.22);  color: #a7f3d0; }
  .badge-rejected { background: rgba(239,68,68,0.22);   color: #fecaca; }

  .score-perfect  { background: rgba(16,185,129,0.22);  color: #a7f3d0; }
  .score-strong   { background: rgba(34,197,94,0.22);   color: #bbf7d0; }
  .score-moderate { background: rgba(245,158,11,0.22);  color: #fde68a; }
  .score-partial  { background: rgba(249,115,22,0.22);  color: #fed7aa; }
  .score-poor     { background: rgba(239,68,68,0.22);   color: #fecaca; }

  #sort-select { background: #162032; }

  #btn-logout {
    background: transparent;
    border-color: var(--border);
  }
  #btn-logout:hover {
    background: var(--bg-subtle);
    border-color: var(--border-strong);
  }
}

/* ── Responsive ───────────────────────────────────────── */

@media (max-width: 768px) {
  .form-row { grid-template-columns: 1fr; }
  header { padding: 0 1rem; height: 54px; }
  .container { padding: 0 0.75rem; margin: 1.25rem auto; }
  table { font-size: 0.82rem; }
  th, td { padding: 0.5rem 0.5rem; }
}

@media (max-width: 640px) {
  header { padding: 0 0.75rem; }
  .container { padding: 0 0.5rem; margin: 1rem auto; }
  table { font-size: 0.78rem; }
  th, td { padding: 0.4rem 0.35rem; }
  .auth-container { padding: 0 1rem; }
  .card { padding: 1.25rem; }
}
