:root {
  --bg: #f1f6f5;
  --surface: #ffffff;
  --ink: #0f172a;
  --muted: #475569;
  --line: #dbe4e2;
  --primary: #0d7a68;
  --primary-dark: #085c4e;
  --primary-soft: #e6f5f2;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --info: #2563eb;
  --info-soft: #eff6ff;
  --sidebar-bg: #0b2228;
  --sidebar-ink: #e2e8f0;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

/* Touch-friendly ergonomics >= 42px */
button, .btn, select, input, textarea, .nav-item, .tab-btn {
  font-family: inherit;
}

button, .btn {
  min-height: 42px;
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all .15s ease;
}
button:hover, .btn:hover { border-color: var(--primary); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-soft { background: var(--primary-soft); color: var(--primary-dark); border-color: #b5e0d8; }
.btn-sm { min-height: 38px; padding: 6px 12px; font-size: 13px; }

input, select, textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-size: 16px; /* Prevent iOS Safari auto-zoom on mobile */
}
textarea { min-height: 88px; resize: vertical; }
label { display: block; font-size: 13px; font-weight: 600; color: #334155; margin-bottom: 4px; }

/* Sticky Top Bar (56px) */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  gap: 8px;
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.menu-btn { min-width: 42px; min-height: 42px; padding: 0; font-size: 20px; }
.brand-title { font-weight: 800; font-size: 15.5px; color: var(--primary-dark); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 11.5px; color: var(--muted); display: none; }
.topbar-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

/* Slide-over Drawer (Mobile default < 960px) */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.52);
  z-index: 49;
  display: none;
}
.backdrop.open { display: block; }

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 272px;
  background: var(--sidebar-bg);
  color: var(--sidebar-ink);
  z-index: 50;
  transform: translateX(-100%);
  transition: transform 0.22s cubic-bezier(.4, 0, .2, 1);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.sidebar.open { transform: translateX(0); }

.sb-header {
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sb-logo { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 15px; color: #fff; }
.sb-badge { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, #14b8a6, #0d7a68); display: flex; align-items: center; justify-content: center; font-weight: 900; color: #fff; }

.user-box {
  margin: 12px;
  padding: 12px;
  border-radius: 12px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
}
.user-box-name { font-weight: 700; font-size: 14px; color: #fff; }
.user-box-role { font-size: 12px; color: #5eead4; margin-top: 2px; }

.nav-group { padding: 6px 10px; }
.nav-group-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #94a3b8;
  padding: 6px 10px 4px;
  font-weight: 700;
}
.nav-item {
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: #cbd5e1;
  justify-content: flex-start;
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  margin-bottom: 2px;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; font-weight: 700; }

/* Main Content */
.app-shell {
  padding: 14px 12px calc(76px + env(safe-area-inset-bottom));
  max-width: 1200px;
  margin: 0 auto;
}

/* Fixed Bottom Tab Bar on Mobile (< 960px) */
.bottom-tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 42;
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab-btn {
  min-height: 56px;
  border: none;
  border-radius: 0;
  background: transparent;
  flex-direction: column;
  gap: 2px;
  padding: 6px 2px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
}
.tab-btn .ico { font-size: 18px; line-height: 1.1; }
.tab-btn.active { color: var(--primary); font-weight: 800; }

/* Desktop Enhancement (>= 960px) */
@media (min-width: 960px) {
  body { padding-left: 260px; }
  .sidebar { width: 260px; transform: translateX(0); }
  .menu-btn, .mobile-close-btn, .bottom-tabs, .backdrop { display: none !important; }
  .brand-sub { display: inline; margin-left: 8px; }
  .topbar { padding: 0 24px; }
  .app-shell { padding: 22px 24px 48px; max-width: 1200px; }
  input, select, textarea { font-size: 14px; }
}

/* Cards, Grids, Tables, Badges */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 2px 8px rgba(15,23,42,0.03);
}
.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.card-title { margin: 0; font-size: 17px; font-weight: 800; color: var(--ink); }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
}
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi-val { font-size: 24px; font-weight: 800; color: var(--primary-dark); margin-top: 4px; }
.kpi-sub { font-size: 11.5px; color: #64748b; margin-top: 2px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.full-col { grid-column: 1 / -1; }

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 12px;
}
table { width: 100%; border-collapse: collapse; min-width: 640px; font-size: 13.5px; }
th, td { padding: 10px 12px; border-bottom: 1px solid #edf2f1; text-align: left; vertical-align: top; }
th { background: #f8fafc; font-weight: 700; color: #334155; white-space: nowrap; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
}
.b-ok { background: #dcfce7; color: #166534; }
.b-warn { background: #fef3c7; color: #92400e; }
.b-err { background: #fee2e2; color: #991b1b; }
.b-info { background: #dbeafe; color: #1e40af; }

/* 1,000-Bed Matrix */
.bed-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  gap: 8px;
}
.bed-cell {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12px;
  cursor: pointer;
}
.bed-cell.available { background: #ecfdf5; border-color: #6ee7b7; }
.bed-cell.occupied { background: #fff1f2; border-color: #fda4af; }
.bed-cell.cleaning { background: #fffbeb; border-color: #fcd34d; }
.bed-cell.reserved { background: #eff6ff; border-color: #93c5fd; }

/* Login Gate */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at top right, #d1fae5, #f1f6f5 55%);
}
.auth-card {
  width: 100%;
  max-width: 520px;
  background: #fff;
  border-radius: 20px;
  padding: 28px 24px;
  border: 1px solid var(--line);
  box-shadow: 0 20px 50px rgba(15,23,42,0.08);
}

.template-bar {
  background: var(--primary-soft);
  border: 1px dashed var(--primary);
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

pre.code-box {
  background: #0f172a;
  color: #e2e8f0;
  padding: 14px;
  border-radius: 12px;
  overflow-x: auto;
  font-size: 12.5px;
  max-height: 420px;
}

/* A4 Print Preservation (.noprint) */
@media print {
  body { padding-left: 0 !important; background: #fff !important; }
  .noprint, .topbar, .sidebar, .bottom-tabs, .backdrop, .template-bar { display: none !important; }
  .app-shell { padding: 0 !important; max-width: 100% !important; }
  .card { border: none !important; box-shadow: none !important; padding: 0 !important; }
  .print-a4-header { display: block !important; border-bottom: 2px solid #000; margin-bottom: 14px; padding-bottom: 8px; }
}
.print-a4-header { display: none; }
