/* ==========================================================================
   ShiftFlow TH — Modern Monthly Work Schedule UI
   ========================================================================== */

:root {
  --bg-app: #f4f6fb;
  --bg-surface: #ffffff;
  --bg-subtle: #f8fafc;
  --bg-hover: #f1f5f9;
  --bg-sticky: #ffffff;
  --bg-weekend: #f8fafc;
  --bg-holiday: #fff1f2;
  --bg-today: #eef2ff;

  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-soft: #94a3b8;

  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: rgba(79, 70, 229, 0.1);
  --danger: #e11d48;
  --danger-soft: rgba(225, 29, 72, 0.1);
  --warning: #d97706;
  --warning-soft: rgba(217, 119, 6, 0.12);
  --success: #059669;
  --success-soft: rgba(5, 150, 105, 0.12);

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 6px 20px -4px rgba(15, 23, 42, 0.08), 0 2px 6px -1px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 20px 45px -10px rgba(15, 23, 42, 0.18);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --font-sans: 'Noto Sans Thai', 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

[data-theme="dark"] {
  --bg-app: #0b1120;
  --bg-surface: #111827;
  --bg-subtle: #1e293b;
  --bg-hover: #243045;
  --bg-sticky: #111827;
  --bg-weekend: #162033;
  --bg-holiday: rgba(225, 29, 72, 0.12);
  --bg-today: rgba(99, 102, 241, 0.16);

  --border: #1f2937;
  --border-strong: #334155;

  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-soft: #64748b;

  --primary: #6366f1;
  --primary-hover: #818cf8;
  --primary-soft: rgba(99, 102, 241, 0.18);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 24px 48px rgba(0, 0, 0, 0.55);
}

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

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  background: var(--bg-app);
  color: var(--text-main);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* App Shell */
.app-shell {
  max-width: 1840px;
  margin: 0 auto;
  padding: 16px 20px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 100vh;
}

/* Topbar */
.topbar {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  box-shadow: var(--shadow-sm);
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding-right: 14px;
  border-right: 1px solid var(--border);
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #4f46e5, #06b6d4);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 6px 14px rgba(79, 70, 229, 0.28);
  flex-shrink: 0;
}

.brand-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 6px;
}

.brand-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
}

.brand-subtitle {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

/* Month Switcher */
.month-switcher {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 4px 6px;
}

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

.month-select, .year-select {
  border: none;
  background: transparent;
  font-weight: 600;
  font-size: 14px;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
  outline: none;
}

.month-select:hover, .year-select:hover {
  background: var(--bg-hover);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 13px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.16s ease;
  white-space: nowrap;
}

.btn-sm {
  padding: 6px 11px;
  font-size: 12px;
  border-radius: 8px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}
.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-subtle);
  border-color: var(--border);
  color: var(--text-main);
}
.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--primary);
}
.btn-ghost:hover {
  background: var(--primary-soft);
}

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
}
.btn-danger-ghost:hover {
  background: var(--danger-soft);
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-main);
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.icon-btn:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

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

.action-cluster {
  display: flex;
  align-items: center;
  gap: 4px;
}

.sync-cluster {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-soft);
  flex-shrink: 0;
}

.sync-pill.is-synced {
  border-color: rgba(5, 150, 105, 0.28);
  background: var(--success-soft);
  color: var(--success);
}
.sync-pill.is-synced .sync-dot {
  background: var(--success);
}

.sync-pill.is-saving,
.sync-pill.is-loading {
  border-color: rgba(79, 70, 229, 0.25);
  background: var(--primary-soft);
  color: var(--primary);
}
.sync-pill.is-saving .sync-dot,
.sync-pill.is-loading .sync-dot {
  background: var(--primary);
  animation: syncPulse 1.1s infinite ease-in-out;
}

.sync-pill.is-conflict {
  border-color: rgba(217, 119, 6, 0.35);
  background: var(--warning-soft);
  color: var(--warning);
  cursor: pointer;
}
.sync-pill.is-conflict .sync-dot {
  background: var(--warning);
}

.sync-pill.is-offline {
  border-color: rgba(225, 29, 72, 0.25);
  background: var(--danger-soft);
  color: var(--danger);
}
.sync-pill.is-offline .sync-dot {
  background: var(--danger);
}

#syncNowBtn.is-spinning svg {
  animation: syncSpin 0.8s linear infinite;
}

@keyframes syncPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.8); }
}

@keyframes syncSpin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

[data-theme="light"] .sun-icon { display: none; }
[data-theme="dark"] .moon-icon { display: none; }

/* Dropdown */
.dropdown {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 245px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 60;
}

.dropdown-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 11px;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  color: var(--text-main);
}

.dropdown-item:hover {
  background: var(--bg-hover);
}

.dropdown-item.danger {
  color: var(--danger);
}
.dropdown-item.danger:hover {
  background: var(--danger-soft);
}

.dropdown-divider {
  height: 1px;
  background: var(--border);
  margin: 5px 4px;
}

/* KPI Strip */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 13px 16px;
  display: flex;
  align-items: center;
  gap: 13px;
  box-shadow: var(--shadow-sm);
}

.kpi-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.kpi-blue { background: rgba(59, 130, 246, 0.12); color: #2563eb; }
.kpi-emerald { background: rgba(16, 185, 129, 0.13); color: #059669; }
.kpi-indigo { background: rgba(99, 102, 241, 0.13); color: #4f46e5; }
.kpi-amber { background: rgba(245, 158, 11, 0.14); color: #d97706; }

[data-theme="dark"] .kpi-blue { color: #60a5fa; }
[data-theme="dark"] .kpi-emerald { color: #34d399; }
[data-theme="dark"] .kpi-indigo { color: #818cf8; }
[data-theme="dark"] .kpi-amber { color: #fbbf24; }

.kpi-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.kpi-label {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi-value {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* Toolbar */
.toolbar {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  box-shadow: var(--shadow-sm);
}

.toolbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.mode-switch {
  display: inline-flex;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  padding: 3px;
  border-radius: 10px;
  gap: 3px;
}

.mode-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: transparent;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.mode-btn.active {
  background: var(--bg-surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.brush-palette {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  flex: 1;
}

.brush-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--bg-surface);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.brush-pill:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.brush-pill.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.16);
}

.brush-code {
  width: 21px;
  height: 21px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
}

.brush-time {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
}

.toolbar-filters {
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  justify-content: flex-start;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
  width: 250px;
}

.search-box svg {
  position: absolute;
  left: 11px;
  color: var(--text-soft);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: 7px 12px 7px 34px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  font-size: 13px;
  outline: none;
}

.search-box input:focus {
  border-color: var(--primary);
  background: var(--bg-surface);
}

.filter-select {
  padding: 7px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  font-size: 13px;
  outline: none;
  cursor: pointer;
}

.min-staff-control {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--text-muted);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 9px;
}

.min-staff-control input {
  width: 46px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  border-radius: 6px;
  padding: 2px 6px;
  text-align: center;
  font-weight: 600;
}

.legend-hint {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: var(--text-muted);
}

.hint-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.dot-note {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f59e0b;
  display: inline-block;
}

.ring-regoff {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  border: 2px dashed #94a3b8;
  display: inline-block;
}

/* Matrix Table Card */
.matrix-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.matrix-scroll {
  overflow: auto;
  max-height: calc(100vh - 305px);
  min-height: 360px;
}

.schedule-table {
  border-collapse: separate;
  border-spacing: 0;
  width: max-content;
  min-width: 100%;
  user-select: none;
}

.schedule-table th,
.schedule-table td {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 0;
  vertical-align: middle;
}

/* Sticky Top Header */
.schedule-table thead th {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg-sticky);
  border-bottom: 2px solid var(--border-strong);
}

/* Sticky Left Staff Column */
.col-staff {
  position: sticky;
  left: 0;
  z-index: 15;
  background: var(--bg-sticky);
  min-width: 245px;
  max-width: 270px;
  border-right: 2px solid var(--border-strong) !important;
}

.schedule-table thead th.col-staff {
  z-index: 30;
}

.schedule-table tfoot td.col-staff {
  z-index: 25;
}

.staff-header-inner {
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-muted);
}

/* Day Header Cells */
.day-th {
  width: 104px;
  min-width: 104px;
  text-align: center;
  cursor: pointer;
  transition: background 0.12s ease;
}

.day-th:hover {
  background: var(--bg-hover) !important;
}

.day-th-inner {
  padding: 6px 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  position: relative;
}

.day-name {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.day-num {
  font-size: 13.5px;
  font-weight: 700;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  display: grid;
  place-items: center;
}

.day-th.is-weekend {
  background: var(--bg-weekend) !important;
}

.day-th.is-sunday .day-name,
.day-th.is-sunday .day-num {
  color: #e11d48;
}

.day-th.is-saturday .day-name {
  color: #7c3aed;
}

.day-th.is-holiday {
  background: var(--bg-holiday) !important;
}

.day-th.is-today .day-num {
  background: var(--primary);
  color: #fff;
}

.holiday-star {
  position: absolute;
  top: 2px;
  right: 3px;
  font-size: 9px;
  color: #e11d48;
}

/* Summary Right Columns */
.col-summary {
  min-width: 64px;
  padding: 6px 8px !important;
  text-align: center;
  font-size: 12px;
  background: var(--bg-subtle);
}

.schedule-table thead th.col-summary {
  background: var(--bg-subtle);
  font-weight: 700;
  color: var(--text-muted);
}

/* Staff Row */
.staff-row:hover td:not(.shift-cell) {
  background: var(--bg-hover);
}

.staff-cell-inner {
  padding: 7px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.staff-meta {
  min-width: 0;
  flex: 1;
}

.staff-name-row {
  display: flex;
  align-items: center;
  gap: 5px;
}

.staff-name {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.staff-nick {
  font-size: 11px;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 1px 6px;
  border-radius: 999px;
  font-weight: 600;
  flex-shrink: 0;
}

.staff-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}

.staff-off-badge {
  font-size: 10px;
  padding: 0 5px;
  border-radius: 4px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  color: var(--text-muted);
  white-space: nowrap;
}

.staff-edit-btn {
  opacity: 0;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all 0.14s ease;
}

.staff-row:hover .staff-edit-btn,
.staff-edit-btn:focus {
  opacity: 1;
}

.staff-edit-btn:hover {
  background: var(--bg-surface);
  border-color: var(--border);
  color: var(--primary);
}

/* Shift Cells */
.schedule-table td.shift-cell {
  height: 54px;
  padding: 4px 5px;
  text-align: center;
  cursor: pointer;
  position: relative;
  transition: background 0.1s ease;
}

body.paint-mode .shift-cell {
  cursor: crosshair;
}

.shift-cell.is-weekend {
  background: var(--bg-weekend);
}

.shift-cell.is-holiday {
  background: var(--bg-holiday);
}

.shift-cell.is-today {
  background: var(--bg-today);
}

.shift-cell.is-reg-off {
  background-image: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 5px,
    rgba(148, 163, 184, 0.08) 5px,
    rgba(148, 163, 184, 0.08) 10px
  );
}

.shift-cell:hover {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
  z-index: 5;
}

.shift-badge {
  width: 100%;
  min-height: 36px;
  padding: 4px 5px;
  margin: 0 auto;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  font-weight: 600;
  font-size: 11.5px;
  line-height: 1.2;
  text-align: center;
  word-break: break-word;
  position: relative;
  transition: transform 0.12s ease;
}

.shift-cell:hover .shift-badge {
  transform: scale(1.03);
}

.shift-badge-ot {
  font-size: 9.5px;
  font-weight: 700;
  opacity: 0.94;
}

.cell-empty-off {
  width: 100%;
  min-height: 32px;
  padding: 3px 5px;
  margin: 0 auto;
  border-radius: 7px;
  border: 1.5px dashed var(--border-strong);
  display: grid;
  place-items: center;
  font-size: 11px;
  line-height: 1.2;
  color: var(--text-soft);
  font-weight: 600;
}

.cell-note-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #f59e0b;
  box-shadow: 0 0 0 1.5px var(--bg-surface);
}

.cell-custom-time-bar {
  position: absolute;
  bottom: 3px;
  left: 50%;
  transform: translateX(-50%);
  width: 16px;
  height: 2.5px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.85);
}

.cell-warn-regoff {
  position: absolute;
  bottom: 3px;
  left: 4px;
  font-size: 9px;
  line-height: 1;
}

/* Summary cells */
.sum-num {
  font-weight: 700;
  font-size: 13px;
}

.sum-sub {
  font-size: 10.5px;
  color: var(--text-muted);
}

/* Sticky Table Footer */
.schedule-table tfoot td {
  position: sticky;
  bottom: 0;
  z-index: 18;
  background: var(--bg-subtle);
  border-top: 2px solid var(--border-strong);
  font-weight: 700;
  text-align: center;
  padding: 7px 2px;
  font-size: 12px;
}

.foot-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 22px;
  border-radius: 6px;
  padding: 0 4px;
}

.foot-count.is-low {
  background: var(--danger-soft);
  color: var(--danger);
}

.foot-count.is-ok {
  background: var(--success-soft);
  color: var(--success);
}

/* Empty State */
.empty-state {
  padding: 56px 24px;
  text-align: center;
  color: var(--text-muted);
}
.empty-state h3 {
  margin: 12px 0 4px;
  color: var(--text-main);
}
.empty-state p {
  margin: 0;
  font-size: 13px;
}

/* Tooltip */
.cell-tooltip {
  position: fixed;
  z-index: 120;
  pointer-events: none;
  background: #0f172a;
  color: #f8fafc;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 12px;
  max-width: 270px;
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.tt-head {
  font-weight: 700;
  margin-bottom: 3px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tt-meta {
  color: #cbd5e1;
  font-size: 11.5px;
}

.tt-note {
  margin-top: 6px;
  padding-top: 5px;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  color: #fde68a;
  word-break: break-word;
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
}

.modal-dialog {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  animation: popIn 0.16s ease-out;
}

.modal-dialog.modal-lg {
  max-width: 720px;
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.96) translateY(6px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.modal-eyebrow {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--primary);
  display: block;
}

.modal-header h2 {
  margin: 2px 0 0;
  font-size: 17px;
  font-weight: 700;
}

.modal-body {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 6px;
}

.modal-footer-right {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

/* Forms */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-group label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-main);
}

.form-group input[type="text"],
.form-group input[type="time"],
.form-group input[type="number"],
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 9px 11px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  outline: none;
  transition: border-color 0.15s ease;
}

.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--primary);
  background: var(--bg-surface);
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.field-hint {
  font-size: 11.5px;
  color: var(--text-muted);
}

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}

.info-banner {
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--warning-soft);
  color: var(--warning);
  font-size: 12.5px;
  font-weight: 600;
}

/* Shift Choice Grid inside Cell Modal */
.shift-choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
  gap: 8px;
}

.shift-choice-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--bg-subtle);
  cursor: pointer;
  text-align: left;
  transition: all 0.14s ease;
}

.shift-choice-btn:hover {
  border-color: var(--border-strong);
}

.shift-choice-btn.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.shift-choice-code {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.shift-choice-text strong {
  display: block;
  font-size: 12.5px;
}

.shift-choice-text span {
  font-size: 11px;
  color: var(--text-muted);
}

/* Color swatches & Weekday pills */
.color-swatch-row {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  padding-top: 4px;
}

.color-swatch {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.12s ease;
}

.color-swatch.selected {
  border-color: var(--text-main);
  transform: scale(1.12);
}

.weekday-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.weekday-pill {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--bg-subtle);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.weekday-pill.selected {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* Shifts Manager */
.shifts-manager-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 280px;
  overflow-y: auto;
}

.shift-mgr-item {
  display: grid;
  grid-template-columns: 52px 1fr 90px 90px 70px auto auto;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-subtle);
}

.shift-mgr-item input[type="text"],
.shift-mgr-item input[type="time"],
.shift-mgr-item input[type="number"] {
  padding: 5px 7px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  font-size: 12.5px;
}

.color-input {
  width: 36px;
  height: 32px;
  padding: 2px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  cursor: pointer;
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

.add-shift-box h3 {
  margin: 0 0 10px;
  font-size: 14px;
}

.add-shift-grid {
  display: grid;
  grid-template-columns: 90px 1.4fr 1fr 1fr 90px 60px;
  gap: 8px;
}

.add-shift-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
}

/* Slide-over Drawer */
.drawer {
  position: fixed;
  inset: 0;
  z-index: 85;
  display: flex;
  justify-content: flex-end;
}

.drawer[hidden] {
  display: none;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
}

.drawer-panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 440px;
  height: 100%;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
}

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

.drawer-eyebrow {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--primary);
}

.drawer-header h2 {
  margin: 2px 0 0;
  font-size: 17px;
}

.drawer-body {
  padding: 16px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
}

.holiday-card {
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.holiday-card-row {
  display: flex;
  gap: 8px;
}

.holiday-card-row input {
  flex: 1;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
}

.day-staff-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.day-staff-item {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  transition: border-color 0.14s ease;
}

.day-staff-item:hover {
  border-color: var(--primary);
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 150;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: #0f172a;
  color: #fff;
  padding: 10px 15px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.18s ease-out;
}

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

/* Print Styles */
.print-header {
  display: none;
}

@media print {
  @page {
    size: A4 landscape;
    margin: 10mm;
  }

  body {
    background: #fff !important;
    color: #000 !important;
    font-size: 11px;
  }

  .topbar, .kpi-strip, .toolbar, .staff-edit-btn, .toast-container, .cell-tooltip, .sync-cluster {
    display: none !important;
  }

  .app-shell {
    padding: 0;
    gap: 8px;
  }

  .print-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    border-bottom: 2px solid #0f172a;
    padding-bottom: 6px;
    margin-bottom: 6px;
  }

  .print-header h2 {
    margin: 0;
    font-size: 16px;
  }

  .print-header p {
    margin: 2px 0 0;
    font-size: 11px;
    color: #475569;
  }

  .print-legend {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    font-size: 10px;
  }

  .matrix-card {
    box-shadow: none;
    border: 1px solid #cbd5e1;
  }

  .matrix-scroll {
    max-height: none;
    overflow: visible;
  }

  .schedule-table thead th,
  .schedule-table tfoot td,
  .col-staff {
    position: static !important;
  }

  .day-th {
    width: auto;
    min-width: 64px;
  }

  .schedule-table td.shift-cell {
    height: 38px;
    padding: 2px 3px;
  }

  .shift-badge {
    width: 100%;
    min-height: 24px;
    padding: 2px 3px;
    font-size: 9px;
    line-height: 1.15;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

/* Responsive adjustments */
@media (max-width: 960px) {
  .kpi-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .brand {
    border-right: none;
    padding-right: 0;
  }
  .add-shift-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .shift-mgr-item {
    grid-template-columns: 44px 1fr 80px 80px;
  }
}
