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

:root {
  --primary: #3B82F6;
  --primary-dark: #2563EB;
  --primary-light: #DBEAFE;
  --success: #10B981;
  --success-light: #D1FAE5;
  --danger: #EF4444;
  --danger-light: #FEE2E2;
  --warning: #F59E0B;
  --warning-light: #FEF3C7;
  --gray-50: #F8FAFC;
  --gray-100: #F1F5F9;
  --gray-200: #E2E8F0;
  --gray-300: #CBD5E1;
  --gray-400: #94A3B8;
  --gray-500: #64748B;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1E293B;
  --gray-900: #0F172A;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Yu Gothic UI', sans-serif;
  font-size: 14px;
  color: var(--gray-800);
  background: var(--gray-50);
  line-height: 1.5;
}

/* ─── Loading ───────────────────────────────────────────────────────────────── */
.loading-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Layout ────────────────────────────────────────────────────────────────── */
.page-center {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.app-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ─── Header ────────────────────────────────────────────────────────────────── */
.app-header {
  background: white;
  border-bottom: 1px solid var(--gray-200);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.app-header__title {
  font-size: 17px;
  font-weight: 700;
  color: var(--gray-900);
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-header__title span { color: var(--primary); }

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

.user-name {
  font-size: 13px;
  color: var(--gray-600);
}

/* ─── Nav Tabs ──────────────────────────────────────────────────────────────── */
.nav-tabs {
  display: flex;
  background: white;
  border-bottom: 1px solid var(--gray-200);
  padding: 0 24px;
  gap: 4px;
}

.nav-tab {
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--gray-500);
  border: none;
  background: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color .15s, border-color .15s;
}

.nav-tab:hover { color: var(--gray-800); }
.nav-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ─── Main Content ──────────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  padding: 24px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

/* ─── Card ──────────────────────────────────────────────────────────────────── */
.card {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--gray-900);
}

.card-body { padding: 20px; }

/* ─── Auth / Setup Card ─────────────────────────────────────────────────────── */
.auth-card {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 400px;
  padding: 36px 32px;
}

.auth-card__logo {
  text-align: center;
  margin-bottom: 28px;
}

.auth-card__logo h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--gray-900);
}

.auth-card__logo p {
  font-size: 13px;
  color: var(--gray-500);
  margin-top: 4px;
}

/* ─── Form ──────────────────────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  font-size: 14px;
  color: var(--gray-800);
  background: white;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
}

.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}

.form-hint {
  font-size: 12px;
  color: var(--gray-400);
  margin-top: 4px;
}

/* ─── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 16px;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
  font-family: inherit;
}

.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); border-color: var(--primary-dark); }

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

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

.btn-ghost {
  background: transparent;
  color: var(--gray-600);
  border-color: var(--gray-300);
}
.btn-ghost:hover:not(:disabled) { background: var(--gray-100); color: var(--gray-800); }

.btn-sm { height: 30px; padding: 0 12px; font-size: 12px; }
.btn-lg { height: 44px; padding: 0 24px; font-size: 15px; width: 100%; }

/* ─── Alert ─────────────────────────────────────────────────────────────────── */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
}

.alert-error {
  background: #FEF2F2;
  color: #991B1B;
  border: 1px solid #FECACA;
}

.alert-success {
  background: #F0FDF4;
  color: #166534;
  border: 1px solid #BBF7D0;
}

.alert-info {
  background: var(--primary-light);
  color: #1E40AF;
  border: 1px solid #BFDBFE;
}

.alert-warning {
  background: var(--warning-light);
  color: #92400E;
  border: 1px solid #FDE68A;
}

/* ─── Toast ─────────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  top: 70px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: slideIn .2s ease;
  max-width: 300px;
}

.toast-success { background: #166534; color: white; }
.toast-error { background: #991B1B; color: white; }

@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ─── Month Nav ─────────────────────────────────────────────────────────────── */
.month-nav {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.month-nav h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--gray-900);
  min-width: 140px;
  text-align: center;
}

.month-status-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.status-open { background: #D1FAE5; color: #065F46; }
.status-published { background: var(--primary-light); color: #1E40AF; }

/* ─── Member Calendar ───────────────────────────────────────────────────────── */
.calendar-legend {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--gray-600);
}

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

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.calendar-day-header {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-500);
  padding: 6px 0;
  text-transform: uppercase;
}

.calendar-day-header.sun { color: #EF4444; }
.calendar-day-header.sat { color: #3B82F6; }

.calendar-cell {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform .1s, box-shadow .1s;
  min-height: 56px;
  padding: 4px;
  user-select: none;
}

.calendar-cell:hover { transform: scale(1.05); box-shadow: var(--shadow-md); }
.calendar-cell.empty { cursor: default; background: transparent; }
.calendar-cell.empty:hover { transform: none; box-shadow: none; }

.calendar-cell.today { border-color: var(--primary) !important; }

.cell-date {
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
}

.cell-label {
  font-size: 10px;
  font-weight: 600;
  margin-top: 2px;
}

/* Desired states */
.desired-none { background: var(--gray-100); color: var(--gray-400); }
.desired-work { background: #FEF08A; color: #7C2D12; }
.desired-work .cell-date { color: #7C2D12; }
.desired-off  { background: var(--primary-light); color: var(--primary-dark); }
.desired-off .cell-date { color: var(--primary-dark); }

/* Confirmed overlay (published) */
.confirmed-work { background: var(--success-light); color: #065F46; }
.confirmed-work .cell-date { color: #065F46; }
.confirmed-off  { background: var(--gray-100); color: var(--gray-400); }
.confirmed-unset { background: var(--warning-light); color: #92400E; }
.confirmed-unset .cell-date { color: #92400E; }

/* Day of week tints */
.day-sun .cell-date { color: #EF4444; }
.day-sat .cell-date { color: #3B82F6; }

/* ─── Admin Shift Grid ──────────────────────────────────────────────────────── */
.shift-grid-wrapper {
  overflow-x: auto;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.shift-grid {
  border-collapse: collapse;
  min-width: 100%;
  white-space: nowrap;
  background: white;
}

.shift-grid th, .shift-grid td {
  border: 1px solid var(--gray-200);
  padding: 0;
}

.shift-grid th {
  background: var(--gray-50);
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-500);
  text-align: center;
  padding: 6px 4px;
  position: sticky;
  top: 0;
  z-index: 2;
}

.shift-grid th.day-col-sun { color: #EF4444; }
.shift-grid th.day-col-sat { color: #3B82F6; }

.shift-grid th.name-col {
  left: 0;
  z-index: 3;
  min-width: 90px;
  text-align: left;
  padding: 6px 10px;
}

.shift-grid td.name-col {
  position: sticky;
  left: 0;
  background: white;
  z-index: 1;
  font-size: 13px;
  font-weight: 500;
  padding: 0 10px;
  min-width: 90px;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.grid-cell {
  width: 42px;
  height: 42px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: filter .1s;
  font-size: 11px;
  font-weight: 600;
}

.grid-cell:hover { filter: brightness(.93); }

.grid-cell .desired-indicator {
  font-size: 9px;
  opacity: .7;
  line-height: 1;
}

.grid-cell .confirmed-text {
  font-size: 12px;
  line-height: 1;
  margin-top: 1px;
}

/* grid cell color combos */
.gc-none-unset  { background: var(--gray-100); color: var(--gray-400); }
.gc-work-unset  { background: #EFF6FF; color: #3B82F6; }
.gc-off-unset   { background: #FFF1F2; color: #F87171; }
.gc-none-work   { background: var(--success-light); color: #065F46; }
.gc-work-work   { background: #DCFCE7; color: #166534; }
.gc-off-work    { background: #D1FAE5; color: #065F46; }
.gc-none-off    { background: var(--gray-100); color: var(--gray-400); }
.gc-work-off    { background: #FEE2E2; color: #991B1B; }
.gc-off-off     { background: #F3F4F6; color: var(--gray-400); }

/* ─── Member Table ──────────────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 10px 16px;
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--gray-100);
  font-size: 14px;
  color: var(--gray-700);
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--gray-50); }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.badge-admin { background: #EDE9FE; color: #5B21B6; }
.badge-member { background: var(--gray-100); color: var(--gray-600); }
.badge-warning { background: var(--warning-light); color: #92400E; }

/* ─── Modal ─────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn .15s ease;
}

.modal {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 440px;
  animation: slideUp .2s ease;
}

.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title { font-size: 16px; font-weight: 600; }

.modal-body { padding: 20px 24px; }

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--gray-200);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.btn-icon {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--gray-400);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover { background: var(--gray-100); color: var(--gray-600); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ─── Divider ───────────────────────────────────────────────────────────────── */
.divider { height: 1px; background: var(--gray-200); margin: 16px 0; }

/* ─── Section header ────────────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--gray-900);
}

/* ─── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .main-content { padding: 16px; }
  .app-header { padding: 0 16px; }
  .nav-tabs { padding: 0 16px; }
  .calendar-grid { gap: 3px; }
  .calendar-cell { min-height: 44px; }
  .cell-date { font-size: 13px; }
}
