:root {
  --bg: #f9fafc;
  --card: #ffffff;
  --text: #1a2032;
  --text-muted: #5c6478;
  --accent: #2563eb;
  --accent-light: #eef4ff;
  --btn-bg: #1a2032;
  --success: #16a34a;
  --success-bg: #eafaf0;
  --warn: #d97706;
  --warn-bg: #fef6ea;
  --danger: #dc2626;
  --danger-bg: #fdecec;
  --border: #e7e9ef;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Anuphan', sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, .heading, .stat-number, .logo-text {
  font-family: 'Bai Jamjuree', sans-serif;
  margin: 0;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 24px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 2px 16px rgba(26, 32, 50, 0.06);
  border: 1px solid var(--border);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 10px;
  padding: 13px 22px;
  font-family: 'Anuphan', sans-serif;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease, opacity .15s ease, transform .05s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary { background: var(--btn-bg); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent); }

.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }

.btn-block { width: 100%; }

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.field input, .field select {
  width: 100%;
  padding: 12px 14px;
  font-size: 15px;
  font-family: 'Anuphan', sans-serif;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color .15s ease;
}
.field input:focus, .field select:focus { border-color: var(--accent); }

.banner {
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 14px;
  margin-bottom: 16px;
  line-height: 1.5;
}
.banner-error { background: var(--danger-bg); color: var(--danger); }
.banner-success { background: var(--success-bg); color: var(--success); }
.banner-info { background: var(--accent-light); color: var(--accent); }

.chip {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
}
.chip-blue { background: var(--accent-light); color: var(--accent); }
.chip-green { background: var(--success-bg); color: var(--success); }
.chip-amber { background: var(--warn-bg); color: var(--warn); }

.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.text-muted { color: var(--text-muted); }

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

/* ===== App shell: sidebar + topbar (app.* / dashboard.html / sales.html ฯลฯ) ===== */
.app-sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 230px;
  background: #fff;
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  z-index: 30;
  overflow-y: auto;
  transition: transform .2s ease;
}
.sidebar-brand {
  font-family: 'Bai Jamjuree', sans-serif;
  font-weight: 700;
  font-size: 20px;
  padding: 6px 10px 22px;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar-link {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px; border-radius: 10px;
  color: var(--text); font-size: 14.5px; font-weight: 500;
}
.sidebar-link:hover { background: #f1f4fa; text-decoration: none; }
.sidebar-link.active { background: var(--accent-light); color: var(--accent); font-weight: 600; }
.sidebar-icon { font-size: 17px; width: 20px; text-align: center; }

.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(26, 32, 50, .4);
  z-index: 25;
}

.app-body { margin-left: 230px; min-height: 100vh; }
.app-topbar {
  height: 60px; background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 24px; gap: 16px;
  position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-size: 17px; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-user { font-size: 13.5px; font-weight: 600; }
.hamburger-btn { display: none; background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text); }
.btn-small { padding: 8px 14px; font-size: 13px; }
.app-main { padding: 24px; max-width: 1120px; }

.pending-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.pending-card { max-width: 420px; text-align: center; padding: 36px 28px; }

.module-placeholder {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-muted);
}
.module-placeholder .icon { font-size: 34px; margin-bottom: 12px; display: block; }
.module-placeholder h2 { color: var(--text); margin-bottom: 8px; font-size: 18px; }

@media (max-width: 860px) {
  .app-sidebar { transform: translateX(-100%); }
  .app-sidebar.open { transform: translateX(0); }
  .app-body { margin-left: 0; }
  .hamburger-btn { display: block; }
  .sidebar-backdrop.open { display: block; }
  .topbar-user { display: none; }
}

/* ===== Data tables & CRUD widgets (ใช้ร่วมกันทุกโมดูล) ===== */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 12px; flex-wrap: wrap; }
.section-header h2 { font-size: 17px; }

.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th {
  text-align: left; font-size: 12px; color: var(--text-muted); font-weight: 700;
  padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
  text-transform: uppercase; letter-spacing: .02em;
}
.data-table td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--bg); }
.money { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.icon-btn {
  background: none; border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 11px; cursor: pointer; font-size: 12.5px; font-family: 'Anuphan', sans-serif;
  color: var(--text); transition: border-color .15s, color .15s;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.icon-btn.danger:hover { border-color: var(--danger); color: var(--danger); }

.empty-state { text-align: center; padding: 32px 16px; color: var(--text-muted); font-size: 14px; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(26, 32, 50, .45);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal-box { background: #fff; border-radius: 16px; max-width: 460px; width: 100%; padding: 26px; max-height: 90vh; overflow-y: auto; }
.modal-box h3 { margin-bottom: 18px; }
.modal-actions { display: flex; gap: 10px; margin-top: 22px; }
.modal-actions .btn { flex: 1; }

.tabs-row { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tab-link {
  padding: 10px 14px; margin-bottom: -1px; border-bottom: 2px solid transparent;
  color: var(--text-muted); font-weight: 600; font-size: 13.5px; cursor: pointer;
  background: none; border-left: none; border-top: none; border-right: none; font-family: 'Anuphan', sans-serif;
}
.tab-link.active { color: var(--accent); border-bottom-color: var(--accent); }

.cost-panel { margin-top: 12px; padding: 20px; background: var(--bg); border-radius: 12px; }
.cost-summary-row { display: flex; justify-content: space-between; padding: 8px 0; font-size: 13.5px; border-bottom: 1px dashed var(--border); }
.cost-summary-row:last-child { border-bottom: none; font-weight: 700; padding-top: 10px; }
.form-row-inline { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.form-row-inline .field { margin-bottom: 0; flex: 1; min-width: 110px; }

/* ===== Toast (แจ้งเตือนแทน alert()) ===== */
.toast-container {
  position: fixed; bottom: 20px; right: 20px; z-index: 100;
  display: flex; flex-direction: column; gap: 10px; max-width: 320px;
}
.toast {
  padding: 13px 16px; border-radius: 10px; font-size: 13.5px; color: #fff;
  box-shadow: 0 6px 20px rgba(26, 32, 50, .18);
  animation: toast-in .18s ease;
}
.toast-error { background: var(--danger); }
.toast-success { background: var(--success); }
.toast-info { background: var(--accent); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@media (max-width: 480px) {
  .toast-container { left: 16px; right: 16px; max-width: none; }
}
