:root {
  --bg: #f2f4f8;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --border: #e4e7ee;
  --text: #1b1e28;
  --text-dim: #6b7080;
  --text-faint: #9599a8;
  --primary: #5b5bf6;
  --primary-dark: #4747d6;
  --primary-tint: #eeeeff;
  --danger: #e35b6a;
  --danger-tint: #fdeced;
  --success: #23a86a;
  --shadow-sm: 0 1px 2px rgba(20, 22, 40, 0.06);
  --shadow-md: 0 6px 20px -4px rgba(30, 34, 60, 0.12);
  --shadow-lg: 0 20px 48px -12px rgba(30, 34, 60, 0.28);
  --radius: 14px;
  --radius-sm: 10px;

  --shift-early: #3aa0ff;
  --shift-late: #f5a623;
  --shift-night: #6c5ce7;
  --shift-custom: #23a86a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

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

/* ===== Topbar ===== */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: linear-gradient(135deg, #0f9d58 0%, #1fb670 55%, #4fd88f 100%);
  color: #fff;
  box-shadow: var(--shadow-md);
  z-index: 20;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: rgba(255,255,255,0.18);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
}
.brand h1 { font-size: 17px; margin: 0; font-weight: 700; letter-spacing: -0.2px; }
.brand-sub { font-size: 11.5px; opacity: 0.82; }

.week-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 8px;
  background: rgba(255,255,255,0.14);
  padding: 5px 8px;
  border-radius: 999px;
}
.week-label {
  font-size: 13.5px;
  font-weight: 600;
  min-width: 190px;
  text-align: center;
  padding: 0 4px;
}

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 14px;
}

.stat-pill {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(255,255,255,0.14);
  border-radius: 12px;
  padding: 6px 16px;
  line-height: 1.15;
}
.stat-num { font-size: 17px; font-weight: 800; }
.stat-txt { font-size: 10px; opacity: 0.85; white-space: nowrap; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease, opacity .12s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px) scale(0.98); }

.btn-primary {
  background: #fff;
  color: #0f8a4b;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { box-shadow: var(--shadow-md); }

.topbar .btn-ghost {
  background: rgba(255,255,255,0.16);
  color: #fff;
}
.topbar .btn-ghost:hover { background: rgba(255,255,255,0.26); }

.modal .btn-primary {
  background: var(--primary);
  color: #fff;
}
.modal .btn-primary:hover { background: var(--primary-dark); }

.modal .btn-ghost {
  background: var(--surface-2);
  color: var(--text-dim);
}
.modal .btn-ghost:hover { background: #eceef4; }

.btn-danger {
  background: var(--danger-tint);
  color: var(--danger);
}
.btn-danger:hover { background: #fbdadd; }

.icon-btn {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  transition: background .12s ease;
}
.topbar .icon-btn:hover { background: rgba(255,255,255,0.2); }

/* ===== Layout ===== */
.body-layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

.sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 16px;
  overflow-y: auto;
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.sidebar-head h2 { font-size: 15px; margin: 0; font-weight: 700; }
.badge {
  background: var(--primary-tint);
  color: var(--primary-dark);
  font-size: 11.5px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  color: var(--text-faint);
  margin-bottom: 10px;
}
.search-box input {
  border: none;
  background: transparent;
  outline: none;
  font-size: 13px;
  width: 100%;
  color: var(--text);
}

.sidebar-hint {
  font-size: 11.5px;
  color: var(--text-faint);
  line-height: 1.4;
  margin: 2px 2px 14px;
}

.employee-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}

.employee-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  cursor: grab;
  transition: box-shadow .15s ease, transform .15s ease, border-color .15s ease;
}
.employee-card:hover {
  box-shadow: var(--shadow-sm);
  border-color: #d7dbe6;
  transform: translateY(-1px);
}
.employee-card.dragging { opacity: 0.35; }
.employee-card.no-match { display: none; }

.avatar {
  width: 34px; height: 34px;
  min-width: 34px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 12.5px;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.35);
}

.employee-meta { display: flex; flex-direction: column; min-width: 0; }
.employee-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.employee-role { font-size: 11px; color: var(--text-faint); }

.employee-shift-count {
  margin-left: auto;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-faint);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 7px;
  min-width: 22px;
  text-align: center;
}

.legend {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.legend-title { font-size: 11px; font-weight: 700; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 8px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

/* ===== Calendar ===== */
.calendar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 18px 20px 8px;
  overflow: hidden;
}

.calendar-scroll {
  flex: 1;
  overflow: auto;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

.calendar {
  display: grid;
  grid-template-columns: 130px repeat(7, minmax(150px, 1fr));
  min-width: 1180px;
  background: var(--surface);
}

.cal-cell {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 10px 8px;
  background: var(--surface);
}

.cal-corner {
  position: sticky;
  top: 0; left: 0;
  z-index: 5;
  background: var(--surface-2);
}

.day-head {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--surface-2);
  text-align: center;
  padding: 10px 6px;
}
.day-head .dow { font-size: 10.5px; font-weight: 700; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.4px; }
.day-head .dnum { font-size: 16px; font-weight: 700; margin-top: 2px; }
.day-head.is-today { background: var(--primary-tint); }
.day-head.is-today .dnum { color: var(--primary-dark); }
.day-head.is-weekend .dnum { color: var(--text-faint); }

.row-head {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}
.row-head .shift-name {
  font-size: 12.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}
.row-head .shift-time { font-size: 10.5px; color: var(--text-faint); }

.shift-cell {
  min-height: 92px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
  position: relative;
  transition: background .12s ease;
}
.shift-cell.is-today { background: #fbfbff; }
.shift-cell.drag-over {
  background: var(--primary-tint) !important;
  box-shadow: inset 0 0 0 2px var(--primary);
}
.shift-cell .drop-hint {
  position: absolute;
  inset: 6px;
  border: 1.5px dashed transparent;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--primary-dark);
  pointer-events: none;
  opacity: 0;
  transition: opacity .12s ease;
}
.shift-cell.drag-over .drop-hint {
  opacity: 1;
  border-color: var(--primary);
}

/* Shift chip */
.shift-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--chip-color, var(--primary));
  border-radius: 8px;
  padding: 5px 7px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform .1s ease, box-shadow .1s ease;
}
.shift-chip:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.shift-chip .avatar { width: 24px; height: 24px; font-size: 10px; min-width: 24px; }
.chip-info { min-width: 0; }
.chip-name { font-size: 11.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip-time { font-size: 10px; color: var(--text-faint); }
.chip-pos {
  margin-left: auto;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-faint);
  background: var(--surface-2);
  padding: 2px 5px;
  border-radius: 5px;
  white-space: nowrap;
}

.empty-tip {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 2px;
}
.empty-tip svg { color: var(--primary); flex-shrink: 0; }

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 22, 40, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
}
.modal-backdrop.open { display: flex; animation: fadeIn .15s ease; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }

.modal {
  background: var(--surface);
  border-radius: 18px;
  width: 440px;
  max-width: 92vw;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: popIn .18s ease;
}
.modal-sm { width: 380px; }

.modal-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 15.5px; font-weight: 700; }
.modal-sub { font-size: 11.5px; color: var(--text-faint); }
.modal-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 14px;
}
.modal-close { margin-left: auto; color: var(--text-faint); }
.modal-close:hover { background: var(--surface-2); }

#shiftForm, #employeeForm { padding: 18px 20px 20px; display: flex; flex-direction: column; gap: 14px; }

.form-row { display: flex; flex-direction: column; gap: 6px; }
.form-row label { font-size: 12px; font-weight: 700; color: var(--text-dim); }
.form-row .optional { font-weight: 400; color: var(--text-faint); }
.form-row-split { flex-direction: row; gap: 12px; }
.form-row-split > div { flex: 1; display: flex; flex-direction: column; gap: 6px; }

input[type="date"], input[type="time"], input[type="text"], input[type="number"], select, textarea {
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 10px;
  font-size: 13.5px;
  background: var(--surface-2);
  color: var(--text);
  outline: none;
  transition: border-color .12s ease, background .12s ease;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  background: #fff;
}
textarea { resize: vertical; font-family: inherit; }

.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}
.seg {
  border: none;
  background: transparent;
  padding: 7px 4px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 7px;
  cursor: pointer;
  color: var(--text-dim);
  transition: background .12s ease, color .12s ease;
}
.seg.active {
  background: #fff;
  color: var(--primary-dark);
  box-shadow: var(--shadow-sm);
}

.color-swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch {
  width: 28px; height: 28px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform .1s ease;
}
.swatch:hover { transform: scale(1.1); }
.swatch.selected { border-color: var(--text); box-shadow: 0 0 0 2px #fff inset; }

.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}
.spacer { flex: 1; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translate(-50%, 20px);
  background: #1b1e28;
  color: #fff;
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 8px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); }
.toast.toast-danger .dot { background: var(--danger); }

/* Scrollbars */
.calendar-scroll::-webkit-scrollbar, .employee-list::-webkit-scrollbar, .sidebar::-webkit-scrollbar, .modal::-webkit-scrollbar {
  width: 9px; height: 9px;
}
.calendar-scroll::-webkit-scrollbar-thumb, .employee-list::-webkit-scrollbar-thumb {
  background: #d8dbe6;
  border-radius: 6px;
}

@media (max-width: 900px) {
  .sidebar { width: 220px; min-width: 220px; }
  .week-label { min-width: 140px; font-size: 12px; }
  .stat-pill { display: none; }
}
