/* ==========================================================================
   เมืองกาญย่าง — Design System
   Shared design tokens & base components used by index.html and backoffice.html
   ========================================================================== */

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

:root {
  /* Brand palette — charcoal grill / ember fire */
  --color-primary: #D62839;
  --color-primary-dark: #A81F2D;
  --color-primary-light: #FF6B5A;
  --color-accent: #F4A300;
  --color-accent-dark: #C97F00;
  --color-accent-light: #FFD166;

  --color-dark: #201B1A;
  --color-dark-2: #2E2725;
  --color-bg: #FFF8F0;
  --color-surface: #FFFFFF;
  --color-text: #2B2320;
  --color-text-muted: #8A7C74;
  --color-border: #EFE3D8;

  --color-success: #2E9E5B;
  --color-success-bg: #E7F6EC;
  --color-warning: #F4A300;
  --color-warning-bg: #FFF4DC;
  --color-danger: #D62839;
  --color-danger-bg: #FCE8E9;
  --color-info: #3B82C4;
  --color-info-bg: #E8F2FA;

  --font-display: 'Kanit', 'Noto Sans Thai', sans-serif;
  --font-body: 'Mitr', 'Noto Sans Thai', sans-serif;

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-pill: 999px;

  --shadow-sm: 0 2px 8px rgba(32, 27, 26, 0.06);
  --shadow-md: 0 6px 20px rgba(32, 27, 26, 0.10);
  --shadow-lg: 0 12px 36px rgba(32, 27, 26, 0.16);
  --shadow-glow: 0 0 0 4px rgba(214, 40, 57, 0.12);

  --header-h: 64px;
  --transition: 180ms cubic-bezier(.4,0,.2,1);
}

* , *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5 {
  font-family: var(--font-display);
  margin: 0;
  line-height: 1.25;
  font-weight: 600;
}

p { margin: 0; }

a { color: inherit; text-decoration: none; }

img { max-width: 100%; display: block; }

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

button { cursor: pointer; }

ul { list-style: none; margin: 0; padding: 0; }

/* The [hidden] attribute must always win over a component's own `display`
   declaration (e.g. `.app-shell{display:flex}`) — author rules otherwise
   override the UA default `[hidden]{display:none}` at equal specificity. */
[hidden] { display: none !important; }

/* Custom scrollbar (webkit) — subtle, on-brand */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(32,27,26,0.18); border-radius: var(--radius-pill); border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(32,27,26,0.3); background-clip: content-box; }

/* ==========================================================================
   Layout utilities
   ========================================================================== */

.container {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 20px;
}

.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-4 { gap: 4px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.gap-24 { gap: 24px; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-pill);
  padding: 13px 24px;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 15px;
  letter-spacing: 0.2px;
  transition: transform var(--transition), box-shadow var(--transition), background var(--transition), opacity var(--transition);
  white-space: nowrap;
  user-select: none;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  color: #fff;
  box-shadow: 0 6px 16px rgba(214, 40, 57, 0.32);
}
.btn-primary:not(:disabled):hover { box-shadow: 0 8px 22px rgba(214, 40, 57, 0.42); }

.btn-accent {
  background: linear-gradient(135deg, var(--color-accent), var(--color-accent-dark));
  color: #2B1A00;
  box-shadow: 0 6px 16px rgba(244, 163, 0, 0.32);
}

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

.btn-outline {
  background: transparent;
  color: var(--color-primary);
  border: 1.5px solid var(--color-primary);
}

.btn-ghost {
  background: rgba(32, 27, 26, 0.05);
  color: var(--color-text);
}
.btn-ghost:hover { background: rgba(32, 27, 26, 0.09); }

.btn-danger {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

.btn-success {
  background: var(--color-success-bg);
  color: var(--color-success);
}

.btn-sm { padding: 8px 16px; font-size: 13px; }
.btn-lg { padding: 16px 32px; font-size: 17px; }
.btn-block { width: 100%; }
.btn-icon { padding: 10px; border-radius: 50%; }

.btn-fab {
  border-radius: 50%;
  width: 56px;
  height: 56px;
  padding: 0;
  flex-shrink: 0;
}

/* ==========================================================================
   Form controls
   ========================================================================== */

.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-muted);
}

.input, .select, .textarea {
  border: 1.5px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  caret-color: var(--color-text);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 15px;
  width: 100%;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input::placeholder, .textarea::placeholder {
  color: var(--color-text-muted);
  opacity: 1;
}
.select option {
  background: var(--color-surface);
  color: var(--color-text);
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: var(--shadow-glow);
}
.textarea { resize: vertical; min-height: 80px; font-family: var(--font-body); }

.checkbox-row { display: flex; align-items: center; gap: 8px; }

/* ==========================================================================
   Cards, badges, pills
   ========================================================================== */

.card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-success { background: var(--color-success-bg); color: var(--color-success); }
.badge-warning { background: var(--color-warning-bg); color: #8A5A00; }
.badge-danger { background: var(--color-danger-bg); color: var(--color-danger); }
.badge-info { background: var(--color-info-bg); color: var(--color-info); }
.badge-neutral { background: rgba(32,27,26,0.07); color: var(--color-text-muted); }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 14px;
  transition: all var(--transition);
  white-space: nowrap;
}
.pill.active {
  background: var(--color-dark);
  border-color: var(--color-dark);
  color: #fff;
}

/* ==========================================================================
   Toasts
   ========================================================================== */

.toast-stack {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 900;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(92vw, 380px);
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--color-dark);
  color: #fff;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toast-in 220ms cubic-bezier(.2,.8,.2,1);
}
.toast.success { background: linear-gradient(135deg, #2E9E5B, #1F7A44); }
.toast.error { background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark)); }
.toast.info { background: linear-gradient(135deg, #3B82C4, #2A628F); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-14px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(-10px) scale(0.96); }
}

/* ==========================================================================
   Modal
   ========================================================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 15, 14, 0.55);
  backdrop-filter: blur(2px);
  z-index: 950;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade-in 180ms ease;
}
@media (min-width: 720px) {
  .modal-overlay { align-items: center; }
}

.modal-sheet {
  background: var(--color-surface);
  color: var(--color-text);
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: 24px 24px 0 0;
  padding: 24px;
  animation: sheet-up 240ms cubic-bezier(.2,.8,.2,1);
}
.no-enter-animation { animation: none !important; }
@media (min-width: 720px) {
  .modal-sheet { border-radius: var(--radius-lg); margin: 20px; }
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheet-up { from { opacity: 0; transform: translateY(40px); } to { opacity: 1; transform: translateY(0); } }

/* ==========================================================================
   Loading & empty states
   ========================================================================== */

.spinner {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 3px solid rgba(0,0,0,0.1);
  border-top-color: var(--color-primary);
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--color-text-muted);
}
.empty-state .emoji { font-size: 48px; display: block; margin-bottom: 12px; }

.skeleton {
  background: linear-gradient(90deg, rgba(32,27,26,.06) 25%, rgba(32,27,26,.11) 37%, rgba(32,27,26,.06) 63%);
  background-size: 400% 100%;
  animation: skeleton-loading 1.4s ease infinite;
  border-radius: var(--radius-sm);
}
@keyframes skeleton-loading {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

/* ==========================================================================
   Setup notice (shown when Firebase isn't configured yet)
   ========================================================================== */

.setup-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--color-dark);
}
.setup-card {
  max-width: 560px;
  width: 100%;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 36px;
  box-shadow: var(--shadow-lg);
}
.setup-card h1 { font-size: 22px; margin-bottom: 12px; }
.setup-card ol { list-style: decimal; padding-left: 20px; display: flex; flex-direction: column; gap: 10px; margin: 16px 0; }
.setup-card code {
  background: var(--color-bg);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--color-primary-dark);
}

@media (max-width: 480px) {
  .container { padding: 0 14px; }
}
