:root {
  /* Brand tokens (mirror DesignTokens.axaml) */
  --brand-50:  #FFF7ED;
  --brand-100: #FFEDD5;
  --brand-200: #FED7AA;
  --brand-300: #FDBA74;
  --brand-400: #FB923C;
  --brand-500: #F97316;
  --brand-600: #EA580C;
  --brand-700: #C2410C;

  --accent-500: #EC4899;

  --neutral-50:  #FAFAF9;
  --neutral-100: #F5F5F4;
  --neutral-200: #E7E5E4;
  --neutral-300: #D6D3D1;
  --neutral-500: #78716C;
  --neutral-600: #57534E;
  --neutral-800: #292524;
  --neutral-900: #1C1917;

  --success-500: #10B981;
  --warning-500: #F59E0B;
  --danger-500:  #EF4444;
  --info-500:    #3B82F6;

  /* Surfaces */
  --bg:          var(--neutral-50);
  --surface:     #ffffff;
  --border:      var(--neutral-200);
  --text:        var(--neutral-900);
  --text-muted:  var(--neutral-600);

  /* Radius / shadow */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px -2px rgba(0,0,0,0.08), 0 2px 4px -2px rgba(0,0,0,0.04);
  --shadow-lg: 0 12px 24px -8px rgba(0,0,0,0.12), 0 4px 8px -4px rgba(0,0,0,0.06);

  --gradient-brand: linear-gradient(135deg, var(--brand-400) 0%, var(--accent-500) 100%);

  /* Type */
  --font-display: 'Be Vietnam Pro','Inter',-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;
  --font-body:    var(--font-display);
}

/* POS giữ light theme cố định — auto-dark gây loạn vì nhiều element hardcode
   white/dark color (drawer, kpi-card, .nav-dd-menu, …). Force light bằng color-scheme. */
:root { color-scheme: light; }
html { background: var(--bg); }

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Header — sticky, opaque (no backdrop-filter to avoid scroll repaint cost) */
header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 16px 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
header h1 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  color: var(--brand-600);
  letter-spacing: -0.5px;
}
header nav {
  display: flex;
  gap: 8px;
}
header nav button {
  padding: 10px 18px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.12s ease, color 0.12s ease;
}
header nav button:hover {
  background: var(--brand-50);
  color: var(--brand-600);
}

/* Main */
main {
  padding: 32px;
  max-width: 1400px;
  margin: 0 auto;
}
h2 { font-family: var(--font-display); font-size: 28px; font-weight: 700; margin-bottom: 24px; }
h3 { font-family: var(--font-display); font-size: 20px; font-weight: 600; margin: 24px 0 12px; }

/* KPI grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}
/* Light-DOM fallback so kpi-card boxes still have padding before Lit upgrades
   the custom element (or if the CDN module fails). Shadow-DOM styles override
   these once the component is defined. */
kpi-card {
  display: block;
  box-sizing: border-box;
  padding: 22px 26px 24px;
  border-radius: 16px;
  background: var(--surface, #ffffff);
  box-shadow: var(--shadow-sm, 0 1px 2px rgba(0,0,0,0.06));
  min-height: 120px;
  position: relative;
  overflow: hidden;
}

/* Tables — modern card style */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  font-size: 14px;
}
thead {
  background: var(--neutral-100);
  border-bottom: 2px solid var(--border);
}
/* dark-mode override removed — see top of file. */
th {
  padding: 14px 20px;
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}
td {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:hover {
  background: var(--brand-50);
}
/* dark-mode override removed — see top of file. */

/* Filter form */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
  margin-bottom: 20px;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.filters label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.filters input, .filters select {
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  transition: border-color 0.12s ease;
}
.filters input:focus, .filters select:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px var(--brand-100);
}
.filters button[type="submit"] {
  padding: 10px 24px;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--brand-500);
  color: white;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.12s ease;
}
.filters button[type="submit"]:hover { background: var(--brand-600); }

/* Status badges */
.status-paid     { color: var(--success-500); font-weight: 600; }
.status-pending  { color: var(--warning-500); font-weight: 600; }
.status-cancelled{ color: var(--danger-500);  font-weight: 600; }

/* Empty state */
.empty {
  text-align: center;
  padding: 64px 24px;
  color: var(--text-muted);
}
.empty .emoji { font-size: 48px; margin-bottom: 12px; }

/* HTMX loading indicator */
.htmx-request {
  opacity: 0.6;
  transition: opacity 0.12s ease;
}
.htmx-indicator {
  display: none;
  position: fixed;
  top: 16px;
  right: 16px;
  padding: 12px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  font-size: 14px;
  color: var(--text-muted);
}
.htmx-request .htmx-indicator { display: block; }

/* Responsive */
@media (max-width: 768px) {
  header { padding: 10px 14px; gap: 10px; flex-wrap: wrap; }
  header h1 { font-size: 18px; }
  main { padding: 16px 12px; }
  h2 { font-size: 20px; margin-bottom: 14px; line-height: 1.25; }
  h3 { font-size: 16px; margin: 16px 0 8px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
  kpi-card { padding: 14px 14px 16px; min-height: 96px; }
  th, td { padding: 10px 12px; font-size: 13px; }
  /* Table wrapper — let wide tables scroll horizontally instead of breaking layout. */
  table.orders, table { display: block; max-width: 100%; overflow-x: auto; }
  /* Allow long page titles to wrap without going huge. */
  main h1 { font-size: 20px; line-height: 1.3; word-break: break-word; }
}

@media (max-width: 480px) {
  header { padding: 8px 12px; gap: 8px; }
  header h1 { font-size: 16px; letter-spacing: 0; }
  main { padding: 12px 10px; }
  h2 { font-size: 18px; margin-bottom: 12px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  kpi-card { padding: 12px 12px 14px; min-height: 88px; border-radius: 12px; }
  .ham-drawer { width: min(260px, 78vw); left: -78vw; }
  .ham-drawer.open { left: 0; }
}

/* Inside the kpi-card shadow DOM Lit applies its own styles, but the light-DOM
   fallback affects mobile flow when the component hasn't upgraded yet. */
@media (max-width: 480px) {
  kpi-card::part(label), kpi-card::part(value) { /* harmless if not parts */ }
}

/* ────────────────────────────────────────────────────────────────────────────
   Unified buttons + form controls + status badges. Used across global dashboard
   AND admin pages so visual language stays in sync.
   ──────────────────────────────────────────────────────────────────────────── */

/* Base button (sets shape + transitions). Default = secondary (white/outline). */
button:not(header nav button),
.btn,
input[type="submit"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s, color 0.12s, box-shadow 0.12s;
  line-height: 1.2;
  text-decoration: none;
}
button:not(header nav button):hover:not(:disabled),
.btn:hover:not(:disabled),
input[type="submit"]:hover:not(:disabled) {
  background: var(--neutral-100);
  border-color: var(--neutral-300);
}
button:disabled, .btn:disabled, input[type="submit"]:disabled {
  opacity: 0.5; cursor: not-allowed;
}

/* Sizes */
.btn-small {
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-sm);
}
.btn-large {
  padding: 14px 22px;
  font-size: 15px;
  font-weight: 700;
}

/* Variants */
.btn-primary,
button.btn-primary,
input[type="submit"].btn-primary {
  background: var(--brand-500);
  color: #fff;
  border-color: var(--brand-500);
}
.btn-primary:hover:not(:disabled) {
  background: var(--brand-600);
  border-color: var(--brand-600);
}
.btn-secondary,
button.btn-secondary {
  background: var(--surface);
  color: var(--brand-600);
  border-color: var(--brand-500);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--brand-50);
}
.btn-danger,
button.btn-danger {
  background: var(--surface);
  color: var(--danger-500);
  border-color: var(--danger-500);
}
.btn-danger:hover:not(:disabled) {
  background: #FEF2F2;
}
.btn-danger-solid,
button.btn-danger-solid {
  background: var(--danger-500);
  color: #fff;
  border-color: var(--danger-500);
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--neutral-100);
  color: var(--text);
}

/* Form controls — applies wherever they appear (admin, dashboard, popups). */
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
input[type="password"],
input[type="date"],
input[type="search"],
input[type="url"],
input:not([type]),
select,
textarea,
.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.4;
  transition: border-color 0.12s, box-shadow 0.12s;
}
input:focus, select:focus, textarea:focus, .form-control:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px var(--brand-50);
}
input::placeholder, textarea::placeholder {
  color: var(--neutral-500);
}
textarea {
  min-height: 64px;
  resize: vertical;
}
.form-group {
  margin-bottom: 12px;
}
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* File input */
input[type="file"] {
  padding: 6px;
  font-size: 13px;
  background: var(--surface);
}

/* Status badges already exist higher up (.status-paid etc) — extend with neutral pill. */
.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--neutral-100);
  color: var(--text-muted);
}
.pill-success { background: var(--brand-50); color: var(--brand-600); }
.pill-warn    { background: #FEF3C7; color: #92400E; }
.pill-danger  { background: #FEE2E2; color: #B91C1C; }
.pill-info    { background: #DBEAFE; color: #1E40AF; }

/* ───────────────────────────────────────────────────────────────────────────
   Mobile responsive fix — 2026-05-19
   Adds: horizontal scroll hint on overflowing tables, empty-state placeholder,
   extra padding-bottom so iOS Safari URL bar doesn't cover the last row.
   Scopes: both admin (.adm-scope) and dashboard pages.
   ─────────────────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Extra bottom padding so iOS Safari address bar / nav bar doesn't cover content */
  main,
  body.adm-scope main {
    padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Force horizontal scroll on wide tables in both scopes */
  main table,
  main table.orders,
  main table.cashflow,
  main table.inventory,
  body.adm-scope main table,
  body.adm-scope main table.orders,
  body.adm-scope main .adm-table {
    display: block !important;
    max-width: 100% !important;
    width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    /* visual scroll-hint: subtle inner shadow on left/right when content overflows */
    background:
      linear-gradient(to right, #ffffff 30%, rgba(255,255,255,0)) left center / 24px 100% no-repeat local,
      linear-gradient(to left,  #ffffff 30%, rgba(255,255,255,0)) right center / 24px 100% no-repeat local,
      radial-gradient(farthest-side at 0 50%, rgba(0,0,0,.12), rgba(0,0,0,0)) left center / 12px 100% no-repeat scroll,
      radial-gradient(farthest-side at 100% 50%, rgba(0,0,0,.12), rgba(0,0,0,0)) right center / 12px 100% no-repeat scroll;
    background-color: #fff;
  }

  /* Keep header cells on one line so columns stay legible while scrolling */
  main table thead th,
  body.adm-scope main table thead th {
    white-space: nowrap;
  }

  /* Empty-state placeholder when tbody has no rows */
  main table:has(tbody:empty)::after,
  body.adm-scope main table:has(tbody:empty)::after,
  main table:has(tbody:not(:has(tr)))::after,
  body.adm-scope main table:has(tbody:not(:has(tr)))::after {
    content: "Chưa có dữ liệu";
    display: block;
    padding: 28px 12px;
    text-align: center;
    color: #9ca3af;
    font-size: 13px;
    font-style: italic;
    border-top: 1px dashed #e5e7eb;
  }
}

/* Dark mode adjustments for the additions above */
@media (max-width: 768px) and (prefers-color-scheme: dark) {
  main table,
  main table.orders,
  main table.cashflow,
  body.adm-scope main table,
  body.adm-scope main table.orders {
    background-color: var(--surface, #1c1917) !important;
    background-image:
      linear-gradient(to right, var(--surface, #1c1917) 30%, rgba(28,25,23,0)) left center / 24px 100% no-repeat local,
      linear-gradient(to left,  var(--surface, #1c1917) 30%, rgba(28,25,23,0)) right center / 24px 100% no-repeat local,
      radial-gradient(farthest-side at 0 50%, rgba(0,0,0,.4), rgba(0,0,0,0)) left center / 12px 100% no-repeat scroll,
      radial-gradient(farthest-side at 100% 50%, rgba(0,0,0,.4), rgba(0,0,0,0)) right center / 12px 100% no-repeat scroll;
  }
  main table:has(tbody:empty)::after,
  body.adm-scope main table:has(tbody:empty)::after {
    color: var(--text-muted, #78716c);
    border-top-color: var(--border, #292524);
  }
}


/* ───────────────────────────────────────────────────────────────────────────
   Filter form responsive fix — 2026-05-19b
   `.filters` is flex-row by default. On narrow mobile the two date inputs
   + select + button all try to share one row → overlap / overflow.
   Force each label onto its own row below 600px; inputs fill the width.
   ─────────────────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .filters,
  body.adm-scope .filters,
  body.adm-scope form.filters {
    padding: 14px 14px !important;
    gap: 10px !important;
  }
  .filters > label,
  body.adm-scope .filters > label {
    flex: 1 1 100% !important;
    min-width: 0 !important;
    width: 100% !important;
  }
  .filters input,
  .filters select,
  .filters input[type="date"],
  .filters input[type="text"],
  .filters input[type="search"],
  body.adm-scope .filters input,
  body.adm-scope .filters select {
    width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
    max-width: 100% !important;
  }
  .filters button[type="submit"],
  body.adm-scope .filters button[type="submit"] {
    width: 100% !important;
    margin-top: 4px;
  }
}

/* Two columns at tablet width — date pair fits, type/button stack below */
@media (min-width: 601px) and (max-width: 900px) {
  .filters > label,
  body.adm-scope .filters > label {
    flex: 1 1 calc(50% - 6px);
    min-width: 0;
  }
  .filters input,
  .filters select,
  body.adm-scope .filters input,
  body.adm-scope .filters select {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }
}


/* ───────────────────────────────────────────────────────────────────────────
   Inline-styled admin forms + alignment fix — 2026-05-19c
   Reason: Đơn hàng page uses <form style="display:grid; grid-template-columns:
   repeat(auto-fit,minmax(140px,1fr))"> with inline styles. Plus on Cashflow
   the .filters card content was indented by 14px while sibling .kpi-grid had
   no padding → left edges of inner content visually misaligned.
   ─────────────────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  /* Collapse any inline-style grid form to a single column on mobile */
  main form[style*="display:grid"],
  main form[style*="grid-template-columns"],
  body.adm-scope main form[style*="display:grid"],
  body.adm-scope main form[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
    padding: 14px !important;
    box-sizing: border-box !important;
    width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
  /* Children labels: full row, stretchable, no min that pushes overflow */
  main form[style*="grid"] > label,
  main form[style*="grid"] > div,
  body.adm-scope main form[style*="grid"] > label,
  body.adm-scope main form[style*="grid"] > div {
    grid-column: 1 / -1 !important;
    width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
  }
  /* All inputs/selects inside these forms fill their cell */
  main form[style*="grid"] input,
  main form[style*="grid"] select,
  main form[style*="grid"] textarea,
  body.adm-scope main form[style*="grid"] input,
  body.adm-scope main form[style*="grid"] select,
  body.adm-scope main form[style*="grid"] textarea {
    width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
    padding: 10px 12px !important;
    font-size: 14px !important;
  }
  main form[style*="grid"] button,
  body.adm-scope main form[style*="grid"] button {
    width: 100% !important;
    padding: 12px !important;
  }

  /* Alignment: every direct child of <main> uses same outer gutter so cards
     line up visually (filter card / kpi-grid / tables / sections). */
  main > .filters,
  main > .kpi-grid,
  main > form,
  main > section,
  main > div,
  main > table,
  main > h2,
  main > h3,
  body.adm-scope main > .filters,
  body.adm-scope main > .kpi-grid,
  body.adm-scope main > form,
  body.adm-scope main > section,
  body.adm-scope main > div,
  body.adm-scope main > table,
  body.adm-scope main > h2,
  body.adm-scope main > h3 {
    margin-left: 0 !important;
    margin-right: 0 !important;
    box-sizing: border-box !important;
    max-width: 100% !important;
  }

  /* Native iOS date input clamp — Safari adds an internal min-width that
     can push the input outside its cell. -webkit-min-content tells it to
     respect parent constraints. */
  main input[type="date"],
  body.adm-scope main input[type="date"] {
    min-width: 0 !important;
    -webkit-appearance: none;
    appearance: none;
    line-height: 1.2;
  }
}

/* Tablet width: 2-column for the inline grid (Đơn hàng form) */
@media (min-width: 601px) and (max-width: 900px) {
  main form[style*="display:grid"],
  main form[style*="grid-template-columns"],
  body.adm-scope main form[style*="display:grid"] {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
  }
  main form[style*="grid"] input,
  main form[style*="grid"] select,
  body.adm-scope main form[style*="grid"] input,
  body.adm-scope main form[style*="grid"] select {
    width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
  }
}
