:root {
  /* ── Brand ─────────────────────────────────────────────────────────── */
  --brand: #e03131;
  --brand-dark: #b02525;
  --bg: #f7f5f2;
  --card: #ffffff;
  --text: #262220;
  --muted: #7a7068;
  --border: #e7e0d8;
  --danger: #c92a2a;
  --danger-bg: #fbeaea;
  --ok: #2b8a3e;
  --ok-bg: #ebf5ec;
  --brand-tint-soft: #fdf4f4;

  /* ── Spacing (4px step) ────────────────────────────────────────────── */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 28px;
  --space-8: 32px;

  /* ── Radius ────────────────────────────────────────────────────────── */
  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 16px;
  --radius-pill: 999px;

  /* ── Shadow ────────────────────────────────────────────────────────── */
  --shadow-card: 0 1px 4px rgba(0, 0, 0, 0.06);
  --shadow-modal: 0 8px 24px rgba(0, 0, 0, 0.08);

  /* ── Motion ────────────────────────────────────────────────────────── */
  --dur-fast: 120ms;
  --dur-base: 200ms;
  --ease-standard: cubic-bezier(0.4, 0, 0.2, 1);

  /* ── Typography ────────────────────────────────────────────────────── */
  --fs-title: 1.3rem;
  --fs-header: 1.05rem;
  --fs-stat: 1.6rem;
  --fs-body: 0.92rem;
  --fs-small: 0.85em;
  --fs-caption: 0.8rem;
  --fs-badge: 0.75em;

  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Sarabun", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

h1, h2, h3 { margin: 0 0 var(--space-2); }

button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: var(--radius-md);
  padding: 0.7em 1.2em;
  background: var(--brand);
  color: #fff;
  transition: background var(--dur-fast) var(--ease-standard);
}
button:hover { background: var(--brand-dark); }
button.secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
button.danger { background: var(--danger); }

input, select {
  font: inherit;
  padding: 0.6em 0.8em;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 100%;
}

label { display: block; margin-bottom: 0.9em; font-size: var(--fs-small); color: var(--muted); }
label input, label select { margin-top: var(--space-1); color: var(--text); }

.error { color: var(--danger); min-height: 1.2em; font-size: var(--fs-small); }
.success { color: var(--ok); font-size: var(--fs-small); }

/* Screen-reader-only (visually hidden but accessible) */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Login page — white card with a dark-red accent edge; a light-red tinted
   brand header band, white body below. Deliberately not a saturated full-red
   panel (too harsh) — just an accent + a soft tint. */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--space-4);
  background: linear-gradient(180deg, #fff 0%, var(--bg) 100%);
}
.login-card {
  background: var(--card);
  border-radius: var(--radius-xl);
  border-left: 6px solid var(--brand-dark);
  width: 100%;
  max-width: 380px;
  overflow: hidden;
  box-shadow: var(--shadow-modal);
}
.login-brand {
  background: var(--danger-bg);
  padding: var(--space-6) var(--space-6) var(--space-5);
  text-align: center;
}
.login-brand img { width: 56px; height: 56px; border-radius: var(--radius-lg); margin-bottom: var(--space-2); }
.login-brand h1 { font-size: var(--fs-title); color: var(--brand-dark); margin: 0; }
.login-brand p { font-size: var(--fs-caption); color: var(--muted); margin: 0.3em 0 0; }
.login-body { padding: var(--space-6); }
.login-body button[type="submit"] { width: 100%; margin-top: var(--space-2); }

.login-field { position: relative; margin-bottom: var(--space-3); }
.login-field svg.field-icon {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.login-field input { padding-left: 2.6em; background: var(--brand-tint-soft); }
.login-field input:focus { border-color: var(--brand); background: #fff; }
.login-field .eye-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  padding: 4px;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
}
.login-field .eye-btn:hover { color: var(--brand); background: none; }

.login-error {
  display: none;
  background: var(--danger-bg);
  border: 1px solid #f3c9c9;
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 0.6em 0.8em;
  font-size: var(--fs-small);
  margin-bottom: var(--space-3);
  line-height: 1.5;
}
.login-error.show { display: block; }

@media (max-width: 420px) {
  .login-brand { padding: var(--space-5) var(--space-4) var(--space-4); }
  .login-body { padding: var(--space-5) var(--space-4); }
}

/* App shell — left sidebar (brand + nav + who/logout) + main content column,
   matching the original prototype's layout concept (แอป-...QuickService.html:
   <aside class="side">). Sidebar is fixed-width on desktop, collapses to a
   horizontal scrollable bar above the content on narrow screens. */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.side {
  width: 250px;
  flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  padding: var(--space-5) var(--space-5) var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.brand .mk {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.05rem;
  flex-shrink: 0;
}
.brand .nm { font-weight: 800; font-size: var(--fs-body); line-height: 1.2; }
.brand .nm small { display: block; font-weight: 500; font-size: var(--fs-caption); color: var(--muted); }

.side .tabs {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-2) var(--space-3);
  background: transparent;
  border-bottom: none;
}
.side .tabs button {
  background: transparent;
  color: var(--text);
  text-align: left;
  white-space: normal;
  padding: 0.65em 0.9em;
  border-radius: var(--radius-md);
}
.side .tabs button:hover { background: var(--brand-tint-soft); }
.side .tabs button.active { background: var(--brand); color: #fff; }

.side-foot {
  padding: var(--space-4);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.side-foot .who { font-size: var(--fs-caption); color: var(--muted); }
.side-foot button { width: 100%; }

.content { flex: 1; min-width: 0; }

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: var(--space-3) var(--space-5);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .ttl { font-size: var(--fs-title); font-weight: 700; }

main { padding: var(--space-4); max-width: 720px; margin: 0 auto; }

@media (max-width: 760px) {
  .app-shell { flex-direction: column; }
  .side {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .brand { padding: var(--space-3); }
  .side .tabs {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: visible;
    padding: var(--space-2);
  }
  .side .tabs button { white-space: nowrap; }
  .side-foot { flex-direction: row; align-items: center; border-top: none; padding: var(--space-2) var(--space-3); }
  .side-foot button { width: auto; }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
  box-shadow: var(--shadow-card);
}

.stat-row { display: flex; gap: var(--space-3); flex-wrap: wrap; }
.stat {
  flex: 1 1 120px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  text-align: center;
  box-shadow: var(--shadow-card);
}
.stat .value { font-size: var(--fs-stat); font-weight: 700; color: var(--brand); }
.stat .label { font-size: var(--fs-caption); color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: var(--fs-body); }
th, td { text-align: left; padding: 0.5em 0.4em; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; }

/* Wide tables (many columns) scroll horizontally within their own card on
   narrow screens instead of blowing out the page layout. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 calc(var(--space-4) * -1); padding: 0 var(--space-4); }
.table-scroll table { min-width: 480px; }
.table-scroll th, .table-scroll td { white-space: nowrap; }

.row-actions { display: flex; gap: var(--space-1); }
.row-actions button { padding: 0.35em 0.7em; font-size: var(--fs-small); }

.badge {
  display: inline-block;
  padding: 0.15em 0.6em;
  border-radius: var(--radius-pill);
  font-size: var(--fs-badge);
  background: var(--ok-bg);
  color: var(--ok);
}
.badge.off { background: var(--danger-bg); color: var(--danger); }
.badge.green { background: var(--ok-bg); color: var(--ok); }
.badge.yellow { background: #fdf3e6; color: #b45309; }
.badge.red { background: var(--danger-bg); color: var(--danger); }
.badge.gray { background: #f0f1f4; color: #8a8f98; }

.progress-bar {
  background: #f0f1f4;
  border-radius: var(--radius-pill);
  height: 10px;
  overflow: hidden;
  margin: 0.4em 0;
}
.progress-bar .fill {
  background: var(--ok);
  height: 100%;
  transition: width 0.2s;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--space-3);
}
.menu-tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  text-align: left;
}
.menu-tile .name { font-weight: 600; margin-bottom: 0.2em; }
.menu-tile .price { color: var(--brand); font-weight: 700; }

/* Sub-tabs (secondary nav nested inside a top-level tab section) */
.subtabs {
  display: flex;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
}
.subtabs button {
  background: transparent;
  color: var(--muted);
  white-space: nowrap;
  padding: 0.5em 0.2em;
  border-radius: 0;
  font-size: var(--fs-small);
  border-bottom: 2px solid transparent;
}
.subtabs button:hover { color: var(--text); }
.subtabs button.active { background: transparent; color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

/* Home quick-links */
.quick-links {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: var(--space-3);
}
.quick-link {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-3);
  text-align: center;
  box-shadow: var(--shadow-card);
  font-size: var(--fs-small);
}
.quick-link:hover { background: var(--bg); }
.quick-link .icon { display: block; font-size: 1.5rem; margin-bottom: 0.3em; }
