/* ═══════════════════════════════════════════════════════
   SHIFT SCHEDULER — Premium Design System
   ═══════════════════════════════════════════════════════ */

/* ── Theme Tokens ── */
:root {
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* Surfaces */
  --bg-base: #0b1120;
  --bg-raised: #111827;
  --bg-card: rgba(17, 24, 39, 0.75);
  --bg-overlay: rgba(255, 255, 255, 0.03);
  --bg-hover: rgba(255, 255, 255, 0.06);
  --bg-active: rgba(99, 130, 255, 0.12);

  /* Text */
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-tertiary: #64748b;
  --text-inverse: #0f172a;

  /* Borders */
  --border: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.1);

  /* Accent */
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.35);
  --accent-subtle: rgba(99, 102, 241, 0.1);

  /* Semantic */
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;

  /* Shift Colors — refined palette */
  --shift-night: #475569;
  --shift-7: #3b82f6;
  --shift-2: #8b5cf6;
  --shift-9: #10b981;
  --shift-930: #06b6d4;
  --shift-1030: #f59e0b;
  --shift-730: #0ea5e9;
  --shift-800: #f97316;
  --shift-1130: #ef4444;
  --shift-off-bg: rgba(248, 113, 113, 0.08);
  --shift-off-border: rgba(248, 113, 113, 0.3);
  --shift-off-text: #fca5a5;

  /* Layout */
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 999px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.25);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.35);
  --shadow-glow: 0 0 24px var(--accent-glow);
  --transition: 0.2s ease;
}

/* ── Light Theme ── */
[data-theme="light"] {
  --bg-base: #f8fafc;
  --bg-raised: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-overlay: rgba(0, 0, 0, 0.02);
  --bg-hover: rgba(0, 0, 0, 0.04);
  --bg-active: rgba(99, 102, 241, 0.08);
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-tertiary: #94a3b8;
  --text-inverse: #f8fafc;
  --border: rgba(0, 0, 0, 0.06);
  --border-strong: rgba(0, 0, 0, 0.1);
  --accent-glow: rgba(99, 102, 241, 0.15);
  --accent-subtle: rgba(99, 102, 241, 0.06);
  --shift-off-bg: rgba(248, 113, 113, 0.06);
  --shift-off-border: rgba(239, 68, 68, 0.25);
  --shift-off-text: #dc2626;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.1);
  --shadow-glow: 0 0 24px rgba(99,102,241,0.12);
}

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

html {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

body {
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background var(--transition), color var(--transition);
  line-height: 1.5;
}

/* Subtle top gradient wash */
body::before {
  content: "";
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 500px;
  background: radial-gradient(ellipse 80% 50% at 50% -20%, var(--accent-subtle) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ═══════════════ TOP BAR ═══════════════ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px) saturate(180%);
}

[data-theme="dark"] .topbar {
  background: rgba(17, 24, 39, 0.8);
}

.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  flex-shrink: 0;
}

.brand h1 {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: -0.3px;
  color: var(--text-primary);
  line-height: 1.2;
}

.brand-sub {
  font-size: 0.72rem;
  color: var(--text-tertiary);
  font-weight: 400;
  letter-spacing: 0.1px;
}

.topbar-actions {
  display: flex;
  gap: 4px;
}

/* Icon buttons (theme, fullscreen) */
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  padding: 0;
  box-shadow: none;
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-strong);
  transform: none;
  box-shadow: none;
}

/* Theme icon visibility */
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: block; }

/* ═══════════════ MAIN ═══════════════ */
.main {
  flex: 1;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 24px 32px;
}

/* ═══════════════ MONTH STRIP ═══════════════ */
.month-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 16px;
}

.nav-arrow {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  padding: 0;
  box-shadow: var(--shadow-sm);
}

.nav-arrow:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  transform: scale(1.05);
  box-shadow: var(--shadow-glow);
}

.month-center {
  display: flex;
  align-items: center;
  gap: 10px;
}

.month-label {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
  min-width: 160px;
  text-align: center;
}

.pill-btn {
  font-size: 0.7rem;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font);
  letter-spacing: 0.2px;
  text-transform: uppercase;
  box-shadow: none;
}

.pill-btn:hover {
  background: var(--accent);
  color: white;
  box-shadow: var(--shadow-glow);
  transform: none;
}

/* ═══════════════ ACTION BAR ═══════════════ */
.action-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.action-group {
  display: flex;
  gap: 6px;
}

/* Button System */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition);
  white-space: nowrap;
  box-shadow: none;
  line-height: 1;
}

.btn svg { flex-shrink: 0; }

.btn-primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: var(--shadow-glow);
  transform: translateY(-1px);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}

.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-strong);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.btn-outline {
  background: transparent;
  color: var(--accent);
  border-color: var(--accent);
}

.btn-outline:hover {
  background: var(--accent-subtle);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.btn-outline.active {
  background: var(--accent);
  color: white;
}

/* Loading state */
.btn.loading {
  opacity: 0.8;
  pointer-events: none;
}

.btn.loading .spinner-spin {
  display: inline-block;
  animation: spin 0.7s linear infinite;
}

.btn.loading .spinner-bounce {
  display: inline-block;
  animation: bounce 0.5s ease-in-out infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
}

/* ═══════════════ TAB BAR ═══════════════ */
.tab-bar {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-bottom: 16px;
  padding: 4px;
  background: var(--bg-overlay);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  width: fit-content;
  margin-left: auto;
  margin-right: auto;
}

.tab {
  padding: 7px 18px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  font-weight: 600;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font);
  box-shadow: none;
}

.tab:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  transform: none;
  box-shadow: none;
}

.tab.active {
  background: var(--accent);
  color: white;
  box-shadow: 0 2px 8px var(--accent-glow);
}

.tab.active:hover {
  box-shadow: 0 2px 12px var(--accent-glow);
}

/* ═══════════════ WEEK CARD ═══════════════ */
.week-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(12px);
  animation: cardEnter 0.35s ease-out both;
  transition: box-shadow var(--transition);
}

.week-card:hover {
  box-shadow: var(--shadow-lg), var(--shadow-glow);
}

.week-card.hidden {
  display: none !important;
  animation: none;
}

@keyframes cardEnter {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Week header inside card */
.week-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.week-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: white;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.week-range {
  font-size: 0.82rem;
  color: var(--text-tertiary);
  font-weight: 400;
}

/* ═══════════════ TABLE ═══════════════ */
.table-scroll {
  overflow-x: auto;
  border-radius: var(--radius-md);
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.table-scroll::-webkit-scrollbar { height: 6px; }
.table-scroll::-webkit-scrollbar-track { background: transparent; }
.table-scroll::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 3px;
}

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

/* Header */
thead th {
  padding: 10px 10px;
  text-align: center;
  font-weight: 600;
  font-size: 0.78rem;
  letter-spacing: 0.3px;
  white-space: nowrap;
  color: var(--text-secondary);
  background: var(--bg-overlay);
  border-bottom: 2px solid var(--border-strong);
}

thead tr:first-child th {
  color: var(--text-primary);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.8px;
  background: var(--accent-subtle);
}

thead tr:nth-child(2) th {
  font-size: 0.74rem;
  font-weight: 500;
  color: var(--text-tertiary);
  background: var(--bg-overlay);
  border-bottom: 1px solid var(--border);
}

/* Body */
tbody th, tbody td {
  padding: 10px 8px;
  text-align: center;
  vertical-align: middle;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

tbody tr:last-child th, tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: var(--bg-hover);
}

tbody th {
  color: var(--text-secondary);
  font-weight: 600;
  white-space: nowrap;
  font-size: 0.82rem;
}

/* Department label */
.dept {
  font-weight: 700;
  color: var(--accent-hover);
  font-size: 0.78rem;
  letter-spacing: 0.1px;
  text-align: left !important;
  padding-left: 14px !important;
}

/* Sunday column */
.col-sun {
  background: var(--accent-subtle);
}

/* Today column */
.col-today {
  position: relative;
}

thead .col-today {
  color: var(--accent) !important;
  font-weight: 800 !important;
}

thead .col-today::after {
  content: "●";
  display: block;
  font-size: 6px;
  color: var(--accent);
  margin-top: 2px;
}

/* ═══════════════ SHIFT BADGES ═══════════════ */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  padding: 4px 10px;
  border-radius: var(--radius-xs);
  font-weight: 700;
  font-size: 0.76rem;
  color: white;
  letter-spacing: 0.2px;
  transition: transform var(--transition);
}

.badge:hover { transform: scale(1.08); }

.off {
  background: var(--shift-off-bg);
  color: var(--shift-off-text);
  border: 1px solid var(--shift-off-border);
  padding: 3px 8px;
  border-radius: var(--radius-xs);
  font-weight: 600;
  font-size: 0.72rem;
  display: inline-block;
  letter-spacing: 0.2px;
}

.t-N    { background: var(--shift-night); }
.t-7    { background: var(--shift-7); }
.t-2    { background: var(--shift-2); }
.t-9    { background: var(--shift-9); }
.t-930  { background: var(--shift-930); }
.t-1030 { background: var(--shift-1030); color: #1c1917; }
.t-730  { background: var(--shift-730); }
.t-800  { background: var(--shift-800); color: #1c1917; }
.t-1130 { background: var(--shift-1130); }

/* ═══════════════ STATS ROW ═══════════════ */
.stats-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  justify-content: center;
}

.stat-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: var(--bg-overlay);
  border: 1px solid var(--border);
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: background var(--transition);
}

.stat-chip:hover { background: var(--bg-hover); }

.stat-name {
  font-weight: 700;
  color: var(--text-primary);
}

.stat-off {
  color: var(--danger);
  font-weight: 600;
}

/* ═══════════════ LEGEND STRIP ═══════════════ */
.legend-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 12px 0;
  margin-top: 8px;
}

.legend-label {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.74rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* ═══════════════ FOOTER ═══════════════ */
.footer {
  text-align: center;
  padding: 16px 24px;
  font-size: 0.74rem;
  color: var(--text-tertiary);
  border-top: 1px solid var(--border);
  background: var(--bg-raised);
}

.footer-sep { margin: 0 6px; opacity: 0.4; }

.footer-hint { opacity: 0.5; }

/* ═══════════════ RESPONSIVE ═══════════════ */
@media (max-width: 1024px) {
  .main { padding: 16px 16px 24px; }
  .topbar-inner { padding: 0 16px; }
}

@media (max-width: 768px) {
  .topbar-inner { height: 50px; }
  .brand h1 { font-size: 0.95rem; }
  .brand-icon { width: 32px; height: 32px; }
  .brand-icon svg { width: 18px; height: 18px; }

  .action-bar {
    flex-direction: column;
    gap: 6px;
  }

  .action-group {
    width: 100%;
    justify-content: center;
  }

  .btn { flex: 1; justify-content: center; padding: 8px 12px; font-size: 0.78rem; }

  .tab-bar { width: 100%; justify-content: center; }
  .tab { padding: 6px 14px; font-size: 0.78rem; }

  .week-card { padding: 16px; border-radius: var(--radius-lg); }

  table { font-size: 0.78rem; }
  thead th { padding: 8px 6px; font-size: 0.7rem; }
  tbody th, tbody td { padding: 8px 5px; }
  .badge { min-width: 36px; padding: 3px 7px; font-size: 0.7rem; }
  .off { font-size: 0.68rem; padding: 2px 6px; }

  .month-label { font-size: 1rem; min-width: 140px; }
  .legend-strip { gap: 8px; }
}

@media (max-width: 480px) {
  .brand-sub { display: none; }
  .brand h1 { font-size: 0.9rem; }

  .btn { padding: 7px 10px; font-size: 0.74rem; }
  .btn svg { width: 13px; height: 13px; }

  .tab { padding: 5px 10px; font-size: 0.74rem; }

  thead th { font-size: 0.65rem; padding: 6px 4px; }
  tbody th, tbody td { padding: 6px 3px; font-size: 0.72rem; }
  .badge { min-width: 30px; padding: 2px 5px; font-size: 0.65rem; }
}

/* ═══════════════ PRINT ═══════════════ */
@media print {
  body { background: #fff !important; color: #000 !important; }
  body::before { display: none; }
  .topbar, .action-bar, .tab-bar, .legend-strip, .footer, .stats-row { display: none !important; }
  .month-strip { margin-bottom: 12px; }
  .week-card { box-shadow: none; border: 1px solid #ddd; backdrop-filter: none; page-break-inside: avoid; }
  .week-card.hidden { display: block !important; }
  thead th { background: #f0f0f0 !important; color: #000 !important; }
  .badge { color: #000 !important; background: #eee !important; border: 1px solid #999; }
  .off { color: #c00 !important; background: #fff !important; }
  .dept { color: #333 !important; }
}

/* ═══════════════ Custom Scrollbar (Webkit) ═══════════════ */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }
