@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600;700&display=swap');

:root {
  --primary: #0d4f8a;
  --primary-light: #1976d2;
  --primary-dark: #073867;
  --accent: #00bcd4;
  --accent-light: #4dd0e1;
  --bg: #eef3f8;
  --sidebar-w: 240px;
  --sidebar-collapsed: 60px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Sarabun', sans-serif; background: var(--bg); min-height: 100vh; color: #2d3436; }

/* ========== LOGIN ========== */
.login-overlay {
  position: fixed; inset: 0; z-index: 9000;
  background: linear-gradient(135deg, #073867 0%, #0d4f8a 50%, #00bcd4 100%);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-card {
  background: #fff; border-radius: 20px; padding: 32px;
  width: 100%; max-width: 440px; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-logo { text-align: center; margin-bottom: 24px; }
.login-logo .logo-circle {
  width: 80px; height: 80px; border-radius: 50%; background: var(--primary);
  margin: 0 auto 12px; display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 2rem; box-shadow: 0 8px 24px rgba(13,79,138,.3);
}
.login-logo h2 { font-weight: 700; color: var(--primary); margin: 0; }
#login-tabs .nav-link { color: #555; font-weight: 600; border-radius: 10px; }
#login-tabs .nav-link.active { background: var(--primary); color: #fff; }

/* ========== SIDEBAR ========== */
#app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); background: linear-gradient(180deg, var(--primary-dark) 0%, var(--primary) 100%);
  color: #fff; position: fixed; top: 0; left: 0; height: 100vh; z-index: 100;
  transition: width 0.3s, transform 0.3s; overflow-y: auto; display: flex; flex-direction: column;
}
.sidebar.collapsed { width: var(--sidebar-collapsed); }
.sidebar.collapsed .sidebar-header span,
.sidebar.collapsed .sidebar-header small,
.sidebar.collapsed .sidebar-menu li span,
.sidebar.collapsed .sidebar-footer .user-meta,
.sidebar.collapsed .sidebar-footer .btn span { display: none; }

.sidebar-header {
  padding: 18px 16px; font-size: 1.4rem; font-weight: 700;
  display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.15);
}
.sidebar-header i { font-size: 1.6rem; color: var(--accent-light); }
.sidebar-brand { font-size: 1.2rem; font-weight: 700; line-height: 1.1; }
.sidebar-sub { font-size: .7rem; color: rgba(255,255,255,.5); font-weight: 400; }

.sidebar-menu { list-style: none; padding: 8px 0; flex: 1; }
.sidebar-menu li {
  padding: 11px 20px; cursor: pointer; display: flex; align-items: center; gap: 12px;
  transition: all 0.2s; font-size: 0.92rem; border-left: 3px solid transparent;
  user-select: none;
}
.sidebar-menu li:hover { background: rgba(255,255,255,0.1); }
.sidebar-menu li.active { background: rgba(255,255,255,0.18); border-left-color: var(--accent-light); font-weight: 600; }
.sidebar-menu li i { width: 20px; text-align: center; font-size: 0.95rem; }
.sidebar-menu .menu-section {
  font-size: .65rem; color: rgba(255,255,255,.4); text-transform: uppercase;
  padding: 12px 20px 4px; letter-spacing: 1px; cursor: default;
}
.sidebar-menu .menu-section:hover { background: transparent; }

.sidebar-footer { padding: 12px 14px; border-top: 1px solid rgba(255,255,255,0.15); }
.user-card {
  display: flex; align-items: center; gap: 10px; padding: 6px;
  background: rgba(255,255,255,.08); border-radius: 10px;
}
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--accent);
  display: flex; align-items: center; justify-content: center; font-weight: 700;
  font-size: .95rem; flex-shrink: 0;
}
.user-meta { overflow: hidden; }
.user-name { font-size: .85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: .65rem; color: rgba(255,255,255,.6); }

/* ========== MAIN ========== */
.main-content { margin-left: var(--sidebar-w); flex: 1; transition: margin-left 0.3s; padding: 0; min-width: 0; }
.sidebar.collapsed ~ .main-content { margin-left: var(--sidebar-collapsed); }

.top-bar {
  background: #fff; padding: 10px 20px; display: flex; align-items: center;
  gap: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); position: sticky; top: 0; z-index: 50;
}
.top-bar .btn-link { color: var(--primary); font-size: 1.2rem; text-decoration: none; padding: 4px 8px; }
.page-title { font-weight: 700; color: var(--primary); }

.page { padding: 22px; animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* ========== CARDS ========== */
.stat-card {
  background: #fff; border-radius: 12px; padding: 18px; display: flex;
  align-items: center; gap: 14px; box-shadow: 0 2px 12px rgba(0,0,0,0.06);
  transition: transform 0.2s, box-shadow 0.2s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 4px 20px rgba(0,0,0,0.1); }
.stat-icon {
  width: 48px; height: 48px; border-radius: 12px; display: flex;
  align-items: center; justify-content: center; font-size: 1.2rem; color: #fff;
}
.stat-icon.bg-blue { background: linear-gradient(135deg, #1976d2, #00bcd4); }
.stat-icon.bg-green { background: linear-gradient(135deg, #2e7d32, #66bb6a); }
.stat-icon.bg-orange { background: linear-gradient(135deg, #f57c00, #ffb74d); }
.stat-icon.bg-red { background: linear-gradient(135deg, #c62828, #ef5350); }
.stat-icon.bg-purple { background: linear-gradient(135deg, #7b2cbf, #c77dff); }
.stat-icon.bg-teal { background: linear-gradient(135deg, #0097a7, #4dd0e1); }
.stat-value { font-size: 1.7rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: 0.8rem; color: #636e72; margin-top: 2px; }

.card { border: none; border-radius: 12px; box-shadow: 0 2px 12px rgba(0,0,0,0.05); }
.card-title { font-weight: 600; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; color: var(--primary-dark); }

.table th { font-weight: 600; font-size: 0.78rem; text-transform: uppercase; color: #636e72; border-bottom: 2px solid #dee2e6; }
.table td { vertical-align: middle; font-size: 0.88rem; }

.badge-status { padding: 4px 10px; border-radius: 20px; font-size: 0.72rem; font-weight: 500; }
.badge-pending { background: #fff3cd; color: #856404; }
.badge-completed { background: #d4edda; color: #155724; }
.badge-fail { background: #f8d7da; color: #721c24; }
.badge-pass { background: #d4edda; color: #155724; }

/* ========== HOUSE CARDS ========== */
.house-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.house-card {
  background: #fff; border-radius: 12px; padding: 14px;
  border-left: 4px solid var(--accent);
  box-shadow: 0 2px 8px rgba(0,0,0,.05);
}
.house-card-name { font-weight: 700; color: var(--primary); font-size: .95rem; }
.house-card-phase { font-size: .7rem; color: #888; }
.house-card-stat { font-size: 1.5rem; font-weight: 700; color: var(--primary-dark); margin-top: 4px; }
.house-card-stat-lbl { font-size: .7rem; color: #888; }

/* ========== STAIN GRID ========== */
.stain-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 8px; }
.stain-card {
  background: #fff; border-radius: 10px; padding: 10px 14px;
  border-left: 4px solid #ccc;
  display: flex; justify-content: space-between; align-items: center;
}
.stain-card.severity-high { border-left-color: #c62828; }
.stain-card.severity-normal { border-left-color: #1976d2; }
.stain-card-name { font-size: .82rem; font-weight: 500; }
.stain-card-count { font-size: 1.4rem; font-weight: 700; color: var(--primary); }
.stain-card-days { font-size: .7rem; color: #888; }

/* ========== LINEN MATRIX ========== */
.linen-matrix { width: 100%; border-collapse: collapse; }
.linen-matrix th, .linen-matrix td {
  border: 1px solid #dee2e6; padding: 6px; font-size: .82rem; text-align: center;
}
.linen-matrix th { background: var(--primary); color: #fff; font-weight: 600; position: sticky; top: 0; z-index: 5; }
.linen-matrix th.linen-name-col { text-align: left; min-width: 200px; background: var(--primary-dark); }
.linen-matrix td.linen-name-col { text-align: left; font-weight: 500; background: #f5f9fc; }
.linen-matrix input[type="number"] { width: 60px; text-align: center; border: 1px solid #ccc; border-radius: 4px; padding: 2px 4px; font-size: .82rem; }
.linen-matrix tr:nth-child(even) td:not(.linen-name-col) { background: #fafbfd; }

/* ========== STAIN DAILY MATRIX ========== */
.daily-matrix-wrap { overflow-x: auto; max-width: 100%; }
.daily-matrix {
  border-collapse: collapse;
  font-size: .8rem;
}
.daily-matrix th, .daily-matrix td {
  border: 1px solid #dee2e6; padding: 4px 6px;
  text-align: center; min-width: 36px;
}
.daily-matrix th.stain-name-col { text-align: left; min-width: 220px; max-width: 240px; position: sticky; left: 0; z-index: 6; background: var(--primary-dark); color: #fff; }
.daily-matrix td.stain-name-col { text-align: left; position: sticky; left: 0; z-index: 5; background: #f5f9fc; font-weight: 500; }
.daily-matrix th { background: var(--primary); color: #fff; font-weight: 600; position: sticky; top: 0; z-index: 4; }
.daily-matrix th.stain-name-col { z-index: 7; }
.daily-matrix input { width: 36px; text-align: center; border: none; background: transparent; font-size: .82rem; }
.daily-matrix input:focus { outline: 2px solid var(--accent); background: #fff; }
.daily-matrix tr:nth-child(even) td:not(.stain-name-col) { background: #fafbfd; }
.daily-matrix td.has-value { background: #fff3cd !important; font-weight: 600; }

/* ========== EQUIPMENT GRID ========== */
.equip-grid { width: 100%; border-collapse: collapse; }
.equip-grid th, .equip-grid td { border: 1px solid #dee2e6; padding: 6px; font-size: .85rem; text-align: center; }
.equip-grid th { background: var(--primary); color: #fff; font-weight: 600; }
.equip-grid td.staff-name { text-align: left; font-weight: 600; background: #f5f9fc; min-width: 140px; }
.equip-status-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 50%; cursor: pointer;
  border: 2px solid #ddd; background: #fff; font-size: 1rem;
  transition: all .2s;
}
.equip-status-btn.pass { background: #d4edda; border-color: #28a745; color: #28a745; }
.equip-status-btn.fail { background: #f8d7da; border-color: #dc3545; color: #dc3545; }
.equip-status-btn.shared { background: #cce5ff; border-color: #007bff; color: #007bff; font-size: .7rem; }
.equip-status-btn.unchecked { background: #fff; border-color: #ddd; color: #ccc; }

/* ========== PM WEEK MATRIX ========== */
.pm-week-matrix { width: 100%; border-collapse: collapse; }
.pm-week-matrix th, .pm-week-matrix td { border: 1px solid #dee2e6; padding: 8px; font-size: .85rem; text-align: center; }
.pm-week-matrix th { background: var(--primary); color: #fff; }
.pm-week-matrix td.task-name { text-align: left; font-weight: 500; background: #f5f9fc; min-width: 280px; }
.pm-checkbox { width: 24px; height: 24px; cursor: pointer; }

/* ========== UTILITIES ========== */
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-outline-primary { color: var(--primary); border-color: var(--primary); }
.btn-outline-primary:hover { background: var(--primary); }
.text-primary { color: var(--primary) !important; }
.bg-primary { background-color: var(--primary) !important; }

.severity-high-text { color: #c62828; font-weight: 600; }
.severity-normal-text { color: #1976d2; }

.lang-switch { display: inline-flex; gap: 4px; }
.lang-sw-btn {
  background: transparent; border: 1px solid #dee2e6; border-radius: 8px;
  padding: 2px 8px; cursor: pointer; font-size: 1rem; line-height: 1;
  transition: all .15s;
}
.lang-sw-btn:hover { background: #f1f3f5; }
.lang-sw-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; border-radius: 14px; font-size: .72rem;
  background: #e3f2fd; color: #0d47a1;
}
.chip.warn { background: #fff3cd; color: #856404; }
.chip.danger { background: #f8d7da; color: #721c24; }
.chip.success { background: #d4edda; color: #155724; }

/* ========== STATUS COLORS (traffic light) ========== */
.st-done { background: #d4edda !important; border-left-color: #28a745 !important; }
.st-pending { background: #fff3cd !important; border-left-color: #ffc107 !important; }
.st-overdue { background: #f8d7da !important; border-left-color: #dc3545 !important; }
.st-today, .st-current { background: #cce5ff !important; border-left-color: #0d6efd !important; }
.st-future { background: #f8f9fa !important; border-left-color: #adb5bd !important; }

.status-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 14px; font-size: .72rem; font-weight: 500;
}
.status-success { background: #d4edda; color: #155724; }
.status-warning { background: #fff3cd; color: #856404; }
.status-danger { background: #f8d7da; color: #721c24; }
.status-primary { background: #cce5ff; color: #004085; }
.status-secondary { background: #e9ecef; color: #495057; }

/* ========== PERIOD VIEWS (Shopee-style cards) ========== */
.period-strip {
  display: flex; gap: 8px; overflow-x: auto; padding: 8px 0;
  scroll-snap-type: x mandatory;
}
.day-cell {
  flex: 0 0 auto; min-width: 60px; padding: 10px 6px; border-radius: 12px;
  background: #fff; border-left: 4px solid #adb5bd; text-align: center; cursor: pointer;
  scroll-snap-align: start; transition: transform .15s, box-shadow .15s;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.day-cell:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,.1); }
.day-num { font-size: 1.2rem; font-weight: 700; line-height: 1; }
.day-mn { font-size: .65rem; color: #888; }
.day-tag { font-size: .7rem; margin-top: 4px; background: var(--primary); color: #fff; border-radius: 8px; padding: 1px 6px; display: inline-block; }

.period-grid {
  display: grid; gap: 12px;
}
.period-grid.daily-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.period-grid.weekly-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.period-grid.monthly-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.period-grid.quarterly-grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

.period-card {
  background: #fff; border-radius: 14px; padding: 14px;
  border-left: 5px solid #adb5bd;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
  transition: transform .15s, box-shadow .15s;
  cursor: pointer;
}
.period-card:hover { transform: translateY(-3px); box-shadow: 0 6px 18px rgba(0,0,0,.12); }
.period-card .pc-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.period-card .pc-date { font-size: 1.3rem; font-weight: 700; color: var(--primary-dark); }
.period-card .pc-weekday { font-size: .8rem; color: #888; }
.period-card .pc-status { margin-bottom: 8px; }
.period-card .pc-metrics {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px; font-size: .85rem;
}
.period-card .pc-metrics.big { grid-template-columns: 1fr 1fr; gap: 10px; }
.period-card .pc-metrics.big > div { text-align: center; padding: 6px; background: #f8f9fa; border-radius: 8px; }
.period-card .pc-metrics.big strong { font-size: 1.25rem; display: block; color: var(--primary); }
.period-card .pc-metrics.big small { color: #888; font-size: .7rem; }
.period-card .pc-metrics > div { display: flex; align-items: center; gap: 4px; color: #555; }
.period-card .pc-progress {
  height: 6px; background: rgba(0,0,0,.06); border-radius: 3px; margin-top: 8px; overflow: hidden;
}
.period-card .pc-progress-bar {
  height: 100%; background: linear-gradient(90deg, #28a745, #4dd0e1); transition: width .3s;
}

/* ========== Clickable hover ========== */
.clickable { cursor: pointer; transition: transform .12s, box-shadow .12s; }
.clickable:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(0,0,0,.1); }
.stat-card.clickable:hover { box-shadow: 0 4px 20px rgba(0,0,0,.12); }

/* Highlight for filtered/jumped items */
.highlight, .highlight-row td { background: #fff3cd !important; }
.highlight-row { animation: pulse-highlight 1.5s ease-out; }
@keyframes pulse-highlight {
  0% { background: #ffc107 !important; }
  100% { background: #fff3cd !important; }
}

/* Big checkbox label (Shopee-style touch target) */
.big-check {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; background: #f8f9fa; border-radius: 10px;
  cursor: pointer; transition: background .15s;
  font-size: .9rem;
}
.big-check:hover { background: #e9ecef; }
.big-check input { width: 18px; height: 18px; cursor: pointer; }

/* User chip avatar */
.user-chip {
  width: 36px; height: 36px; border-radius: 50%; color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .9rem;
}

/* Export cards */
.export-card {
  transition: transform .15s, box-shadow .15s;
  border: none; box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
.export-card:hover { transform: translateY(-4px); box-shadow: 0 8px 24px rgba(0,0,0,.15); }

/* ========== TOAST ========== */
.toast-pop {
  position: fixed; bottom: 20px; right: 20px; z-index: 9999;
  background: #fff; border-radius: 12px; padding: 12px 18px;
  box-shadow: 0 8px 28px rgba(0,0,0,.2);
  display: flex; align-items: center; gap: 10px;
  font-size: .95rem; font-weight: 500;
  transform: translateX(120%); transition: transform .3s;
}
.toast-pop.show { transform: translateX(0); }
.toast-pop.toast-success { border-left: 4px solid #28a745; }
.toast-pop.toast-success i { color: #28a745; }
.toast-pop.toast-warning { border-left: 4px solid #ffc107; }
.toast-pop.toast-warning i { color: #ffc107; }
.toast-pop.toast-info { border-left: 4px solid #0d6efd; }
.toast-pop.toast-info i { color: #0d6efd; }

@media (max-width: 768px) {
  :root { --sidebar-w: 220px; }
  .sidebar { transform: translateX(-100%); }
  .sidebar.show { transform: translateX(0); }
  .main-content { margin-left: 0 !important; }
  .stat-card { padding: 12px; }
  .stat-value { font-size: 1.3rem; }
  .page { padding: 12px; }
}
