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

:root {
  --bg:           #f5f6f8;
  --surface:      #eef0f3;
  --card:         #ffffff;
  --border:       #e2e5ea;
  --border-focus: #3b6ff5;
  --accent:       #3b6ff5;
  --accent-hover: #2f5ce0;
  --accent-muted: rgba(59, 111, 245, 0.1);
  --text:         #1a1d23;
  --text-sub:     #4b5563;
  --text-muted:   #8a93a2;

  --status-applied-bg:    #eff6ff; --status-applied-text:    #1d4ed8; --status-applied-dot:    #3b82f6;
  --status-screening-bg:  #fffbeb; --status-screening-text:  #b45309; --status-screening-dot:  #f59e0b;
  --status-interview-bg:  #f5f3ff; --status-interview-text:  #6d28d9; --status-interview-dot:  #8b5cf6;
  --status-offer-bg:      #f0fdf4; --status-offer-text:      #15803d; --status-offer-dot:      #22c55e;
  --status-accepted-bg:   #ecfdf5; --status-accepted-text:   #047857; --status-accepted-dot:   #10b981;
  --status-rejected-bg:   #fef2f2; --status-rejected-text:   #b91c1c; --status-rejected-dot:   #ef4444;
  --status-ghosted-bg:    #f3f4f6; --status-ghosted-text:    #4b5563; --status-ghosted-dot:    #9ca3af;

  --priority-high:   #dc2626;
  --priority-medium: #d97706;
  --priority-low:    #6b7280;

  --radius:    10px;
  --radius-sm: 7px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow:    0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
}

html.dark {
  --bg:           #1c1c1e;
  --surface:      #2c2c2e;
  --card:         #242426;
  --border:       #3a3a3c;
  --border-focus: #5e8af4;
  --accent:       #5e8af4;
  --accent-hover: #4d79e8;
  --accent-muted: rgba(94, 138, 244, 0.12);
  --text:         #e5e5e7;
  --text-sub:     #aeaeb2;
  --text-muted:   #6c6c70;

  --status-applied-bg:    rgba(59,130,246,0.12);  --status-applied-text:    #60a5fa;
  --status-screening-bg:  rgba(245,158,11,0.12);  --status-screening-text:  #fbbf24;
  --status-interview-bg:  rgba(139,92,246,0.12);  --status-interview-text:  #c084fc;
  --status-offer-bg:      rgba(34,197,94,0.12);   --status-offer-text:      #4ade80;
  --status-accepted-bg:   rgba(16,185,129,0.12);  --status-accepted-text:   #34d399;
  --status-rejected-bg:   rgba(239,68,68,0.12);   --status-rejected-text:   #f87171;
  --status-ghosted-bg:    rgba(156,163,175,0.12); --status-ghosted-text:    #9ca3af;

  --priority-high:   #f87171;
  --priority-medium: #fbbf24;
  --priority-low:    #6b7280;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow:    0 2px 8px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
  transition: background-color 0.2s, color 0.2s;
}

/* ── HEADER ── */
header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 16px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.header-left h1 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.2px;
}
.header-left p {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ── BUTTONS ── */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-outline {
  background: transparent;
  color: var(--text-sub);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.btn-outline:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-muted);
}

.btn-theme {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-sub);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: all 0.15s;
  flex-shrink: 0;
}
.btn-theme:hover { border-color: var(--accent); color: var(--accent); }

/* ── STATS ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  padding: 20px 32px 0;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: var(--shadow-sm);
}
.stat-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  margin-top: 4px;
  line-height: 1;
}
.stat-progress {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 10px;
  overflow: hidden;
}
.stat-progress-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.5s ease;
}
.stat-card.total     .stat-progress-fill { background: var(--accent); }
.stat-card.active    .stat-progress-fill { background: var(--status-applied-dot); }
.stat-card.interview .stat-progress-fill { background: var(--status-interview-dot); }
.stat-card.offer     .stat-progress-fill { background: var(--status-offer-dot); }
.stat-card.rejected  .stat-progress-fill { background: var(--status-rejected-dot); }
.stat-card.total     { border-top: 3px solid var(--accent); }
.stat-card.active    { border-top: 3px solid var(--status-applied-dot); }
.stat-card.interview { border-top: 3px solid var(--status-interview-dot); }
.stat-card.offer     { border-top: 3px solid var(--status-offer-dot); }
.stat-card.rejected  { border-top: 3px solid var(--status-rejected-dot); }

/* ── WEEKLY SUMMARY ── */
.weekly-summary {
  padding: 12px 32px 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--text-sub);
  flex-wrap: wrap;
  min-height: 32px;
}
.ws-sep { color: var(--border); margin: 0 4px; }
.ws-num { font-weight: 700; color: var(--text); }
.ws-followup { color: var(--priority-medium); font-weight: 600; }

/* ── TOOLBAR ── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 32px;
  flex-wrap: wrap;
}
.toolbar input[type="text"] {
  flex: 1;
  min-width: 200px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.toolbar input[type="text"]:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-muted);
}
.toolbar input::placeholder { color: var(--text-muted); }

.filter-select {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-family: inherit;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
}
.filter-select:focus { border-color: var(--border-focus); }

/* ── TABLE ── */
.table-wrap {
  padding: 0 32px 40px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  font-size: 0.85rem;
}
thead th {
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
thead th:hover { color: var(--text); }
thead th.sorted { color: var(--accent); }
.sort-icon { opacity: 0.4; margin-left: 3px; }
thead th.sorted .sort-icon { opacity: 1; }

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background-color 0.1s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface); }

tbody td {
  padding: 12px 14px;
  vertical-align: middle;
  color: var(--text);
}
tbody td.muted { color: var(--text-muted); font-size: 0.8rem; }

/* ── STATUS BADGE ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
}
.badge-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  flex-shrink: 0;
}
.badge.applied    { background: var(--status-applied-bg);    color: var(--status-applied-text); }
.badge.applied    .badge-dot { background: var(--status-applied-dot); }
.badge.screening  { background: var(--status-screening-bg);  color: var(--status-screening-text); }
.badge.screening  .badge-dot { background: var(--status-screening-dot); }
.badge.interview  { background: var(--status-interview-bg);  color: var(--status-interview-text); }
.badge.interview  .badge-dot { background: var(--status-interview-dot); }
.badge.offer      { background: var(--status-offer-bg);      color: var(--status-offer-text); }
.badge.offer      .badge-dot { background: var(--status-offer-dot); }
.badge.accepted   { background: var(--status-accepted-bg);   color: var(--status-accepted-text); }
.badge.accepted   .badge-dot { background: var(--status-accepted-dot); }
.badge.rejected   { background: var(--status-rejected-bg);   color: var(--status-rejected-text); }
.badge.rejected   .badge-dot { background: var(--status-rejected-dot); }
.badge.ghosted    { background: var(--status-ghosted-bg);    color: var(--status-ghosted-text); }
.badge.ghosted    .badge-dot { background: var(--status-ghosted-dot); }

/* ── PRIORITY ── */
.priority-high   { color: var(--priority-high);   font-weight: 600; }
.priority-medium { color: var(--priority-medium); font-weight: 600; }
.priority-low    { color: var(--priority-low);    font-weight: 500; }

/* ── ROW STATUS TINTS ── */
tbody tr.row-status-accepted  { background: rgba(16, 185, 129, 0.05); }
tbody tr.row-status-offer     { background: rgba(34, 197, 94,  0.06); }
tbody tr.row-status-rejected  { background: rgba(239, 68,  68,  0.05); }
tbody tr.row-status-interview { background: rgba(139, 92,  246, 0.04); }
tbody tr.row-status-accepted:hover  { background: rgba(16, 185, 129, 0.09); }
tbody tr.row-status-offer:hover     { background: rgba(34, 197, 94,  0.10); }
tbody tr.row-status-rejected:hover  { background: rgba(239, 68,  68,  0.08); }
tbody tr.row-status-interview:hover { background: rgba(139, 92,  246, 0.07); }

/* ── STALE ROW ── */
tbody tr.row-stale { border-left: 3px solid #f59e0b !important; }
.stale-days { color: #d97706 !important; font-weight: 600; }

/* ── STATUS HISTORY ── */
.history-list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 8px 0 4px;
}
.history-arrow { color: var(--text-muted); font-size: 0.8rem; }

/* ── COL OPTIONAL ── */
.col-optional { transition: opacity 0.15s; }

/* ── CLICKABLE BADGE ── */
.badge-clickable {
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  user-select: none;
}
.badge-clickable:hover { opacity: 0.78; transform: scale(1.05); }

/* ── DAYS AGO CELL ── */
.days-ago {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ── ROW ACTIONS ── */
.row-actions { display: flex; gap: 6px; }
.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  transition: all 0.15s;
}
.btn-icon:hover { background: var(--surface); color: var(--text); border-color: var(--text-muted); }
.btn-icon.edit:hover   { border-color: var(--accent); color: var(--accent); }
.btn-icon.delete:hover { border-color: var(--priority-high); color: var(--priority-high); }

/* ── EMPTY STATE ── */
.empty {
  text-align: center;
  padding: 56px 24px;
  color: var(--text-muted);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 12px;
}
.empty-title { font-size: 0.95rem; font-weight: 600; color: var(--text-sub); margin-bottom: 6px; }
.empty p { font-size: 0.85rem; }

/* ── MODAL ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 20, 0.45);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  padding: 16px;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 600px;
  max-height: 92vh;
  overflow-y: auto;
  padding: 28px;
  box-shadow: var(--shadow-lg);
  transform: translateY(10px);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.modal-overlay.open .modal { transform: translateY(0); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}
.modal-title { font-size: 1rem; font-weight: 700; color: var(--text); }
.btn-close {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: all 0.15s;
}
.btn-close:hover { color: var(--text); border-color: var(--text-muted); }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full { grid-column: 1 / -1; }

label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.form-group input,
.form-group select,
.form-group textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-muted);
}
.form-group textarea { resize: vertical; min-height: 72px; }
.form-group select option { background: var(--card); color: var(--text); }

.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 24px;
}

/* ── TOAST ── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  z-index: 1001;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow-lg);
  transform: translateY(80px);
  opacity: 0;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { border-left: 3px solid var(--status-offer-dot); }
.toast.success .toast-icon { color: var(--status-offer-dot); }
.toast.error   { border-left: 3px solid var(--status-rejected-dot); }
.toast.error   .toast-icon { color: var(--status-rejected-dot); }

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── MOBILE ── */
@media (max-width: 768px) {
  header, .toolbar, .table-wrap { padding-left: 16px; padding-right: 16px; }
  .weekly-summary { padding-left: 16px; padding-right: 16px; }
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    padding-left: 16px;
    padding-right: 16px;
  }
  .stat-card.rejected { grid-column: 1 / -1; }
  .form-grid { grid-template-columns: 1fr; }
  .form-group.full { grid-column: auto; }
  .modal { padding: 20px; }
  .header-left p { display: none; }
  /* Hide optional columns by default on mobile */
  .col-optional { display: none; }
  table.show-all-cols .col-optional { display: table-cell; }
  #btn-toggle-cols { display: inline-flex; }
}

@media (min-width: 769px) {
  #btn-toggle-cols { display: none; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .toolbar { gap: 8px; }
  .filter-select { flex: 1; min-width: 0; }
  #btn-export-csv { width: 100%; }
}
