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

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --font: "Sarabun", "TH Sarabun New", "Noto Sans Thai", sans-serif;

  --shift-day-bg: #eff6ff;
  --shift-eve-bg: #fef3c7;
  --shift-night-bg: #f0fdf4;
  --shift-we-day-bg: #fdf4ff;
  --shift-we-mid-bg: #fff1f2;
  --shift-we-night-bg: #f0f9ff;
}

html { font-size: 20px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ─── Topbar ───────────────────────────────────────────────── */
.topbar {
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 3.25rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.brand-icon { font-size: 1.4rem; }
.brand-name {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: .5px;
}
.brand-sub {
  font-size: 0.75rem;
  opacity: 0.8;
  display: none;
}
@media (min-width: 900px) { .brand-sub { display: inline; } }
.topbar-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}
.nav-link {
  color: rgba(255,255,255,.85);
  text-decoration: none;
  padding: 0.375rem 0.75rem;
  border-radius: 4px;
  font-size: 0.875rem;
  transition: background .15s;
}
.nav-link:hover, .nav-link.active {
  background: rgba(255,255,255,.2);
  color: white;
}
.nav-logout {
  background: none;
  border: 1px solid rgba(255,255,255,.4);
  color: rgba(255,255,255,.85);
  padding: 0.3rem 0.75rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.875rem;
  font-family: var(--font);
  transition: background .15s;
}
.nav-logout:hover { background: rgba(255,255,255,.15); }

/* ─── Main ─────────────────────────────────────────────────── */
.main-content {
  max-width: 1600px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}

/* ─── Login ────────────────────────────────────────────────── */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
}
.login-container {
  background: white;
  border-radius: 12px;
  padding: 2.5rem 2rem;
  width: 360px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  text-align: center;
}
.login-logo { font-size: 3rem; margin-bottom: 0.5rem; }
.login-title { font-size: 1.75rem; font-weight: 700; color: var(--primary); }
.login-sub { color: var(--text-muted); font-size: 0.8rem; margin: 0.5rem 0 1.5rem; line-height: 1.5; }
.login-form { text-align: left; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.875rem; font-weight: 600; margin-bottom: 0.3rem; }
.form-group input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-family: var(--font);
  font-size: 0.95rem;
  transition: border-color .15s;
}
.form-group input:focus { outline: none; border-color: var(--primary); }

/* ─── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 1rem;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  transition: background .15s, opacity .15s;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { opacity: .9; }
.btn-outline {
  background: white;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}
.btn-outline:hover { background: #eff6ff; }
.btn-full { width: 100%; justify-content: center; }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.8rem; }

/* ─── Page header ──────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.page-title { font-size: 1.4rem; font-weight: 700; color: var(--text); }
.page-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.month-label {
  font-size: 1rem;
  font-weight: 600;
  color: var(--primary);
  min-width: 6rem;
  text-align: center;
}

/* ─── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.card-title { font-size: 1rem; font-weight: 700; margin-bottom: 1rem; color: var(--text); }

/* ─── Alerts ────────────────────────────────────────────────── */
.alert {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 0.875rem;
}
.alert-error { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.alert-warn { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
.compact-list { margin: 0.5rem 0 0 1.25rem; }
.compact-list li { margin: 0.15rem 0; }

/* ─── Schedule ──────────────────────────────────────────────── */
.schedule-wrapper { display: flex; flex-direction: column; gap: 0.5rem; }

.day-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.day-block.day-weekend { border-left: 3px solid var(--warn); }

.day-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  background: #f8fafc;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid var(--border);
}
.day-header:hover { background: #f1f5f9; }
.day-num { font-size: 1.25rem; font-weight: 700; color: var(--primary); min-width: 2rem; }
.day-name { font-weight: 600; color: var(--text-muted); }
.day-badge {
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-weight: 600;
}
.day-badge.weekend { background: #fef3c7; color: #92400e; }
.day-toggle { margin-left: auto; color: var(--text-muted); font-size: 0.75rem; }

.day-shifts { display: none; }
.day-shifts.open { display: block; }

.shift-block { border-bottom: 1px solid var(--border); padding: 0.75rem 1rem; }
.shift-block:last-child { border-bottom: none; }
.shift-day { background: var(--shift-day-bg); }
.shift-eve { background: var(--shift-eve-bg); }
.shift-night { background: var(--shift-night-bg); }
.shift-we-day { background: var(--shift-we-day-bg); }
.shift-we-mid { background: var(--shift-we-mid-bg); }
.shift-we-night { background: var(--shift-we-night-bg); }

.shift-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.premium-badge {
  background: #fef3c7;
  color: #92400e;
  font-size: 0.65rem;
  padding: 0.1rem 0.35rem;
  border-radius: 999px;
  font-weight: 700;
}

.slot-table { width: 100%; border-collapse: collapse; }
.slot-table th {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: left;
  padding: 0.2rem 0.3rem;
  border-bottom: 1px solid var(--border);
}
.slot-row td { padding: 0.2rem 0.3rem; }
.col-num { width: 1.5rem; color: var(--text-muted); font-size: 0.75rem; text-align: center; }
.col-name { width: 45%; }
.col-status { width: 5rem; }
.col-repl { width: auto; }

.input-name, .input-repl {
  width: 100%;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--font);
  font-size: 0.875rem;
  background: white;
  transition: border-color .15s;
}
.input-name:focus, .input-repl:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37,99,235,.15);
}
.input-status {
  width: 100%;
  padding: 0.3rem 0.25rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--font);
  font-size: 0.875rem;
  background: white;
  cursor: pointer;
}

/* Autocomplete dropdown */
.autocomplete-list {
  position: absolute;
  z-index: 999;
  background: white;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 20px rgba(0,0,0,.12);
  max-height: 200px;
  overflow-y: auto;
  min-width: 220px;
}
.autocomplete-item {
  padding: 0.45rem 0.75rem;
  cursor: pointer;
  font-size: 0.875rem;
  font-family: var(--font);
}
.autocomplete-item:hover, .autocomplete-item.active { background: #eff6ff; }

/* Save indicator */
.save-indicator {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--success);
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
  z-index: 1000;
  animation: fadeout 2s forwards;
}
@keyframes fadeout {
  0%,70% { opacity: 1; }
  100% { opacity: 0; }
}

/* ─── Tables ────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.data-table th, .data-table td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.data-table th {
  background: #f8fafc;
  font-weight: 700;
  color: var(--text-muted);
  font-size: 0.8rem;
}
.data-table tr:hover td { background: #f8fafc; }
.row-warn td { background: #fffbeb !important; }
.total-row td { font-weight: 700; background: #f8fafc; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.font-bold { font-weight: 700; }
.small-text { font-size: 0.8rem; color: var(--text-muted); }

/* ─── Badges ────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}
.badge-ok { background: #d1fae5; color: #065f46; }
.badge-warn { background: #fef3c7; color: #92400e; }
.badge-rate1 { background: #dbeafe; color: #1e40af; }
.badge-rate15 { background: #d1fae5; color: #065f46; }
.badge-rate3 { background: #fee2e2; color: #991b1b; }

/* ─── Summary Table ─────────────────────────────────────────── */
.table-scroll-x { overflow-x: auto; }
.summary-table {
  border-collapse: collapse;
  font-size: 0.8rem;
  white-space: nowrap;
}
.summary-table th, .summary-table td {
  border: 1px solid var(--border);
  padding: 0.25rem 0.35rem;
  text-align: center;
}
.col-emp-name {
  text-align: left !important;
  min-width: 160px;
  background: #f8fafc;
  position: sticky;
  left: 0;
  z-index: 10;
}
.emp-name-cell {
  text-align: left !important;
  min-width: 160px;
  background: white;
  position: sticky;
  left: 0;
  z-index: 5;
  font-weight: 600;
}
.day-header-cell { background: #f1f5f9; font-weight: 700; }
.shift-header-cell { background: #f8fafc; font-size: 0.72rem; color: var(--text-muted); }
.premium-col { background: #fffbeb !important; }
.status-cell { font-size: 0.75rem; min-width: 2rem; }
.status-ท { background: #d1fae5; color: #065f46; }
.status-ป { background: #fef9c3; color: #713f12; }
.status-พ { background: #dbeafe; color: #1e40af; }
.status-ก { background: #ede9fe; color: #5b21b6; }
.status-น { background: #fee2e2; color: #991b1b; }
.status-ส { background: #e0f2fe; color: #0c4a6e; }
.status-อ { background: #f1f5f9; color: #475569; }
.status-ย { background: #fce7f3; color: #831843; }
.status-ล { background: #fef3c7; color: #92400e; }
.status-empty { color: transparent; }

/* ─── Misc ──────────────────────────────────────────────────── */
.info-bar {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  padding: 0.6rem 1rem;
  font-size: 0.875rem;
  margin-bottom: 1rem;
  color: #1e40af;
}
.result-actions { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.table-scroll { overflow-x: auto; }
.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
  font-size: 1rem;
}
.upload-form { display: flex; flex-direction: column; gap: 1rem; }
.form-row { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; }
.input-file {
  display: block;
  padding: 0.4rem;
  border: 1.5px dashed var(--border);
  border-radius: 6px;
  width: 100%;
  cursor: pointer;
}
.input-sm {
  width: 7rem;
  padding: 0.4rem 0.5rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-family: var(--font);
  font-size: 0.875rem;
}
.col-mapping { margin-top: 0.5rem; }
.col-mapping summary { cursor: pointer; color: var(--primary); font-size: 0.875rem; }
.inline-form { display: flex; gap: 0.5rem; align-items: center; }
.input-text {
  padding: 0.4rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-family: var(--font);
  font-size: 0.875rem;
  flex: 1;
}
.inactive-row td { color: var(--text-muted); text-decoration: line-through; }
.legend {
  margin-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.8rem;
}
.legend-item {
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  border: 1px solid rgba(0,0,0,.08);
}
