:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #059669;
  --warning: #d97706;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.08);
  --sidebar-width: 240px;
  --bottom-nav-height: 64px;
  --topbar-height: 56px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-tap-highlight-color: transparent; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  padding-bottom: var(--bottom-nav-height);
}

/* ========== SIDEBAR (desktop) ========== */
.sidebar {
  display: none;
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-width);
  background: #0f172a;
  color: #fff;
  flex-direction: column;
  padding: 0;
  z-index: 60;
}
.sidebar.open { display: flex; }
.sidebar .logo {
  padding: 24px 24px 20px;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  border-bottom: 1px solid #1e293b;
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar .logo i { color: var(--primary); font-size: 1.2rem; }
.sidebar ul { list-style: none; padding: 12px 0; flex: 1; overflow-y: auto; }
.sidebar li {
  padding: 14px 24px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  color: #94a3b8;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: all 0.15s;
  border-left: 3px solid transparent;
}
.sidebar li i { width: 20px; text-align: center; font-size: 1rem; }
.sidebar li:hover { background: #1e293b; color: #e2e8f0; }
.sidebar li.active { background: #1e293b; color: #fff; font-weight: 600; border-left-color: var(--primary); }
.sidebar-footer {
  padding: 16px 24px;
  border-top: 1px solid #1e293b;
  font-size: 0.75rem;
  color: #475569;
}
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 55;
}
.sidebar-overlay.open { display: block; }

/* ========== TOPBAR (mobile) ========== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-height);
  padding: 0 16px;
  background: #0f172a;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 70;
}
.topbar .logo { font-weight: 800; font-size: 1.15rem; display: flex; align-items: center; gap: 8px; }
.topbar .logo i { color: var(--primary); }
.topbar .menu-btn {
  background: none; border: none; color: #94a3b8;
  font-size: 1.3rem; padding: 8px; cursor: pointer;
}

/* ========== MAIN ========== */
main {
  padding: 16px;
  max-width: 1200px;
  margin: 0 auto;
}
@media (min-width: 768px) {
  body { padding-bottom: 0; }
  .topbar { display: none; }
  .sidebar { display: flex; }
  main { margin-left: var(--sidebar-width); padding: 32px 40px; }
}

/* ========== NAV STRIP ========== */
.nav-strip {
  display: flex;
  gap: 4px;
  padding: 8px 16px;
  background: #0f172a;
  border-bottom: 1px solid #1e293b;
  position: sticky;
  top: var(--topbar-height);
  z-index: 65;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.nav-strip::-webkit-scrollbar { display: none; }
.nav-pill {
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  color: #94a3b8;
  background: transparent;
  border: 1px solid #1e293b;
  white-space: nowrap;
  transition: 0.15s;
}
.nav-pill:hover { background: #1e293b; color: #e2e8f0; }
.nav-pill.active { background: #3b82f6; color: #fff; border-color: #3b82f6; }

/* ========== TABS ========== */
.tab-content { display: none; animation: fadeIn 0.2s ease; }
.tab-content.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ========== BOTTOM NAV (mobile) ========== */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bottom-nav-height);
  background: #0f172a;
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 50;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottom-nav .nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  color: #475569;
  font-size: 0.65rem;
  font-weight: 500;
  padding: 4px 12px;
  cursor: pointer;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.bottom-nav .nav-item i { font-size: 1.2rem; }
.bottom-nav .nav-item.active { color: var(--primary); }
.bottom-nav .nav-item.active i { color: var(--primary); }
@media (min-width: 768px) { .bottom-nav { display: none; } }

/* ========== SECTION HEADERS ========== */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.section-header h1, .section-header h2 {
  font-size: 1.3rem;
  font-weight: 700;
}
.page-title {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 20px;
  letter-spacing: -0.3px;
}

/* ========== STATS GRID ========== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}
@media (min-width: 768px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr); gap: 16px; }
}
.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  transition: transform 0.15s;
}
.stat-card:active { transform: scale(0.97); }
.stat-card .label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  margin-bottom: 4px;
}
.stat-card .value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
}

/* ========== CARDS ========== */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  transition: box-shadow 0.2s;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.card h3 { font-size: 1rem; font-weight: 600; }

/* ========== MATCH BAR ========== */
.match-scroll {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 4px 0 8px;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x mandatory;
}
.match-scroll::-webkit-scrollbar { height: 4px; }
.match-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.match-item {
  min-width: 200px;
  max-width: 260px;
  flex-shrink: 0;
  scroll-snap-align: start;
}
.match-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  border-left: 4px solid var(--primary);
}
.match-card:active { transform: scale(0.97); }
.match-card .title { font-weight: 600; font-size: 0.9rem; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.match-card .company { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 8px; }
.match-card .score-row { display: flex; align-items: center; gap: 8px; }
.match-card .score-bar { flex: 1; height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.match-card .score-bar-fill { height: 100%; border-radius: 3px; transition: width 0.3s; }
.match-card .score-label { font-weight: 700; font-size: 0.85rem; min-width: 32px; text-align: right; }
.match-card .letter-badge { color: var(--success); font-size: 0.75rem; }

/* ========== JOBS LIST ========== */
.jobs-list { display: flex; flex-direction: column; gap: 10px; }
.job-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  display: flex;
  align-items: center;
  gap: 12px;
}
.job-card:active { transform: scale(0.98); }
.job-card .job-info { flex: 1; min-width: 0; }
.job-card .job-title {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.job-card .job-meta {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 2px;
  display: flex; gap: 8px; flex-wrap: wrap;
}
.job-card .job-score {
  font-weight: 700;
  font-size: 1rem;
  text-align: right;
  flex-shrink: 0;
  min-width: 36px;
}
.job-card .job-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.job-card .job-spinner { display: none; }
@media (max-width: 480px) {
  .job-card .job-actions { display: none; }
}

/* ========== BUTTONS ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #cbd5e1; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-ghost { background: transparent; color: var(--text-secondary); padding: 8px; }
.btn-ghost:hover { background: var(--border); }
.btn-icon {
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.15s;
}
.btn-icon:hover { background: var(--border); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-xs { padding: 4px 8px; font-size: 0.7rem; border-radius: 6px; }

/* ========== BADGES ========== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-discovered { background: #f1f5f9; color: #475569; }
.badge-saved { background: #dbeafe; color: #1e40af; }
.badge-applied { background: #fef3c7; color: #92400e; }
.badge-interviewing { background: #d1fae5; color: #065f46; }
.badge-offered { background: #bbf7d0; color: #166534; }
.badge-rejected { background: #fee2e2; color: #991b1b; }

/* ========== FILTERS ========== */
.filter-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 12px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.filter-bar select, .filter-bar input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  background: var(--surface);
  color: var(--text);
  outline: none;
  flex: 1;
  min-width: 100px;
}
.filter-bar select:focus, .filter-bar input:focus { border-color: var(--primary); }
.status-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.status-tabs .tab {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--border);
  color: var(--text-secondary);
  transition: all 0.15s;
  border: none;
  -webkit-tap-highlight-color: transparent;
}
.status-tabs .tab:active { transform: scale(0.96); }
.status-tabs .tab.active { background: var(--primary); color: #fff; }

/* ========== FORM ========== */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.form-group input, .form-group textarea, .form-group select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  background: var(--surface);
  color: var(--text);
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s;
}
.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.form-group textarea { font-family: 'SFMono-Regular', Consolas, monospace; font-size: 0.85rem; resize: vertical; }
.form-row { margin-bottom: 12px; }
.form-row.checkbox { display: flex; align-items: center; gap: 8px; }
.form-row.checkbox label { margin: 0; }

/* ========== MODAL ========== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  align-items: flex-end;
  justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal-content {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  max-height: 85vh;
  width: 100%;
  overflow-y: auto;
  padding: 24px 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0));
  animation: slideUp 0.25s ease;
}
.modal-content .modal-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 16px;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}
.modal-title { font-size: 1.2rem; font-weight: 700; margin-bottom: 4px; padding-right: 32px; }
.modal-subtitle { font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 16px; }
.modal-body { margin-bottom: 16px; }
.mood-row { display:flex; gap:5px; padding:0 0 8px 0; flex-wrap:wrap; align-items:center; }
.mood-row label { font-size:0.7rem; color:var(--text-muted,#94a3b8); text-transform:uppercase; letter-spacing:0.5px; }
.mood-row select {
  font-size:0.75rem; padding:3px 5px; border:1px solid var(--border,#e2e8f0);
  border-radius:4px; background:var(--surface,#fff); color:var(--text,#1e293b);
  cursor:pointer; outline:none;
}
.mood-row select:focus { border-color:var(--primary,#4f46e5); }
.modal-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.modal-section {
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 12px;
}
.modal-section-title { font-size: 0.8rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
@media (min-width: 768px) {
  .modal-overlay { align-items: center; }
  .modal-content {
    border-radius: var(--radius);
    max-width: 640px;
    max-height: 80vh;
    animation: fadeIn 0.2s ease;
    padding: 32px;
  }
  .modal-content .modal-handle { display: none; }
}

/* ========== PAGINATION ========== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.page-btn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.15s;
}
.page-btn:hover:not(:disabled) { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-btn:disabled { opacity: 0.4; cursor: default; }

/* ========== FLOATING PROGRESS ========== */
#floating-progress {
  position: fixed;
  bottom: calc(var(--bottom-nav-height) + 12px);
  left: 12px;
  right: 12px;
  background: #0f172a;
  color: #fff;
  padding: 12px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 60;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 360px;
}
@media (min-width: 768px) { #floating-progress { bottom: 20px; left: calc(var(--sidebar-width) + 20px); right: auto; } }
#floating-progress-icon { font-size: 0.6rem; flex-shrink: 0; }
#floating-progress-label { font-weight: 600; }
#floating-progress-detail { color: #94a3b8; font-size: 0.75rem; }

/* ========== ANALYSIS CARD ========== */
.analysis-card {
  background: #0f172a;
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 8px;
}
.analysis-card .score-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.analysis-card .score-box {
  text-align: center;
  background: #1e293b;
  border-radius: var(--radius-sm);
  padding: 10px;
}
.analysis-card .score-box .num { font-size: 1.3rem; font-weight: 700; display: block; }
.analysis-card .score-box .lbl { font-size: 0.65rem; color: #64748b; }
.analysis-card .tag-row { margin-bottom: 6px; font-size: 0.85rem; }
.analysis-card .tag-row .tag-label { font-weight: 600; }
.analysis-card .reasoning-box {
  background: #1e293b;
  border-radius: var(--radius-sm);
  padding: 10px;
  margin-top: 8px;
  border-left: 3px solid var(--primary);
  font-size: 0.85rem;
  color: #cbd5e1;
  line-height: 1.5;
}
.analysis-card .reasoning-box .reasoning-label {
  font-size: 0.7rem;
  color: #64748b;
  margin-bottom: 4px;
}

/* ========== SEARCH RESULTS ========== */
#search-results { margin-top: 16px; }

/* ========== GLOBAL BUSY BAR ========== */
#global-busy-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, #4f46e5, #8b5cf6, #4f46e5);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  z-index: 200;
}
@keyframes shimmer { from { background-position:200% 0; } to { background-position:-200% 0; } }

/* ========== DASHBOARD PANELS ========== */
.dashboard-grid {
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.section-panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.section-panel h2 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ========== PROFILE ========== */
.profile-form { max-width: 720px; }
.profile-form .form-group textarea { min-height: 80px; }
.profile-form .form-group textarea[name="summary"] { min-height: 100px; }
.profile-form .form-group textarea[name="personal_letter"] { min-height: 160px; }

/* ========== CV IMPORT ========== */
.cv-import { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.cv-import input[type="file"] { font-size: 0.85rem; padding: 6px 0; }
#parse-cv-status { font-size: 0.8rem; color: var(--text-secondary); }

/* ========== RESPONSIVE HELPERS ========== */
.hide-mobile { display: none !important; }
@media (min-width: 768px) { .hide-mobile { display: initial !important; } .hide-desktop { display: none !important; } }

/* ========== DANGER ZONE ========== */
.danger-zone { margin-top: 32px; padding-top: 24px; border-top: 2px solid #fee2e2; }
.danger-zone h2 { color: var(--danger); font-size: 1rem; margin-bottom: 8px; }
.danger-zone p { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 12px; }

/* ========== WELCOME ========== */
.welcome-card {
  text-align: center;
  padding: 32px 16px;
}
.welcome-card h3 { font-size: 1.2rem; margin-bottom: 8px; }
.welcome-card p { color: var(--text-secondary); font-size: 0.9rem; }
