:root {
  --bg: #fbf7f0;
  --surface: #ffffff;
  --surface-2: #f4eee3;
  --text: #1d1b2e;
  --muted: #6b6578;
  --border: #e8e0d2;
  --navy: #1f2a5c;
  --accent: #f5b301;
  --accent-text: #1d1b2e;
  --danger: #c62835;
  --ok: #1b7f4b;
  --shadow: 0 6px 24px rgba(31, 42, 92, .08);
  --c1: #d62839; --c2: #17703f; --c3: #e0531f; --c4: #3b2f9a; --c5: #b0233a;
  --chart: #3b4fb8;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12131a; --surface: #1b1d27; --surface-2: #232633; --text: #f1ede4; --muted: #a39fae;
    --border: #2d3040; --navy: #0d1230; --shadow: 0 6px 24px rgba(0, 0, 0, .35);
    --c1: #ff5c6b; --c2: #3cc47a; --c3: #ff8a4c; --c4: #8c80ff; --c5: #ff6f86;
    --chart: #7385f0;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12131a; --surface: #1b1d27; --surface-2: #232633; --text: #f1ede4; --muted: #a39fae;
  --border: #2d3040; --navy: #0d1230; --shadow: 0 6px 24px rgba(0, 0, 0, .35);
  --c1: #ff5c6b; --c2: #3cc47a; --c3: #ff8a4c; --c4: #8c80ff; --c5: #ff6f86;
  --chart: #7385f0;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 120px; }
body {
  margin: 0;
  font-family: "Mukta", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.display { font-family: "Rozha One", "Mukta", serif; font-weight: 400; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: var(--navy); color: var(--accent); font-size: 20px;
}
.brand-name { font-size: 1.25rem; line-height: 1; }
.controls { display: flex; gap: 8px; }
.btn-icon, .btn-pill {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  height: 40px; display: inline-flex; align-items: center; justify-content: center;
}
.btn-icon { width: 40px; }
.btn-pill { padding: 0 14px; font-weight: 600; }
.btn-icon:hover, .btn-pill:hover { border-color: var(--accent); }

/* Hero */
.hero {
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(245, 179, 1, .18), transparent 60%),
    var(--navy);
  color: #fff; text-align: center;
}
.hero-inner { max-width: 960px; margin: 0 auto; padding: 40px 16px 36px; }
.hero-logo {
  display: block; width: min(100%, 560px); height: auto; margin: 0 auto 18px;
  border-radius: 14px; box-shadow: 0 12px 40px rgba(0, 0, 0, .35);
}
.hero p { font-size: clamp(1.05rem, 3.5vw, 1.35rem); margin: 0 0 22px; opacity: .95; }
.btn-primary {
  display: inline-flex; align-items: center; gap: 8px; border: 0; border-radius: 12px;
  background: var(--accent); color: var(--accent-text); font-weight: 700;
  padding: 12px 20px; text-decoration: none;
}
.btn-primary:hover { filter: brightness(1.05); }

/* Category nav + search */
.toolbar {
  position: sticky; top: 61px; z-index: 15; background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.toolbar-inner { max-width: 960px; margin: 0 auto; padding: 10px 16px; display: grid; gap: 10px; }
.cats { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.cats::-webkit-scrollbar { display: none; }
.cat-chip {
  flex: none; border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: 8px 16px; text-decoration: none; color: var(--text); font-weight: 600; white-space: nowrap;
}
.cat-chip:hover { border-color: var(--accent); }
.search {
  width: 100%; border: 1px solid var(--border); background: var(--surface); border-radius: 12px;
  padding: 10px 14px;
}
.search:focus, .field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

/* Menu */
main { max-width: 960px; margin: 0 auto; padding: 20px 16px 40px; }
.category { margin: 8px 0 28px; --cat: var(--c1); }
.category:nth-of-type(5n+2) { --cat: var(--c2); }
.category:nth-of-type(5n+3) { --cat: var(--c3); }
.category:nth-of-type(5n+4) { --cat: var(--c4); }
.category:nth-of-type(5n+5) { --cat: var(--c5); }
.category h2 {
  display: flex; align-items: center; gap: 10px; font-size: 1.6rem; margin: 0 0 10px;
}
.category h2::before {
  content: ""; width: 6px; height: 1.4em; border-radius: 3px; background: var(--cat);
}
.items {
  list-style: none; margin: 0; padding: 0; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden;
}
.item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-top: 1px solid var(--border);
}
.item:first-child { border-top: 0; }
.item-name { font-weight: 600; font-size: 1.05rem; }
.item-unit { color: var(--muted); font-size: .9rem; }
.item-right { display: flex; align-items: center; gap: 12px; flex: none; }
.price {
  font-family: "Mukta", system-ui, sans-serif; font-weight: 700; color: #fff; background: var(--cat);
  padding: 2px 10px; border-radius: 999px; min-width: 58px; text-align: center;
}
.item.off .item-name { text-decoration: line-through; color: var(--muted); }
.item.off .price { background: var(--muted); }
.off-label { color: var(--muted); font-size: .85rem; }
.empty-state { text-align: center; color: var(--muted); padding: 40px 0; }

.footer { text-align: center; color: var(--muted); padding: 16px; font-size: .95rem; }
.footer a { color: var(--muted); }

/* Forms */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 0; }
.form-grid .wide { grid-column: 1 / -1; }
.field { display: grid; gap: 4px; font-size: .9rem; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--border); background: var(--bg); color: var(--text);
  border-radius: 10px; padding: 9px 12px; font-size: 1rem;
}
.btn-ghost {
  border: 1px solid var(--border); background: transparent; border-radius: 10px; padding: 8px 14px; font-weight: 600;
}
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }

@media (max-width: 420px) {
  .item { padding: 12px; }
  .item-right { gap: 8px; }
  .price { min-width: 50px; padding: 2px 8px; }
  .brand-name { font-size: 1.1rem; }
}

/* ---------- Admin ---------- */
.admin-wrap { max-width: 1040px; margin: 0 auto; padding: 20px 16px 60px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px;
}
.card h2 { margin: 0 0 4px; font-size: 1.3rem; }
.card > p.sub { margin: 0 0 14px; color: var(--muted); }
.login-card { max-width: 380px; margin: 10vh auto; }
.login-card .btn-primary { width: 100%; justify-content: center; margin-top: 12px; }
.error { color: var(--danger); min-height: 1.4em; margin: 8px 0 0; font-size: .95rem; }
.grid-2 { display: grid; gap: 18px; grid-template-columns: 1fr; }
@media (min-width: 820px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.row .field { flex: 1 1 160px; }
.qr-preview { display: flex; justify-content: center; margin: 14px 0; }
.qr-preview canvas { width: 100%; max-width: 280px; height: auto; border-radius: 12px; border: 1px solid var(--border); }
.warn { background: color-mix(in srgb, var(--accent) 18%, transparent); border-radius: 10px; padding: 8px 12px; font-size: .9rem; margin: 10px 0 0; }

.admin-cat { margin-top: 18px; }
.admin-cat-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.admin-cat-head input { font-weight: 700; }
.table-scroll { overflow-x: auto; }
table.items-table { width: 100%; border-collapse: collapse; min-width: 640px; }
.items-table th { text-align: left; font-size: .85rem; color: var(--muted); font-weight: 600; padding: 6px; }
.items-table td { padding: 4px 6px; border-top: 1px solid var(--border); }
.items-table input, .items-table select, .admin-cat-head input {
  width: 100%; border: 1px solid transparent; background: transparent; border-radius: 8px; padding: 6px 8px;
}
.items-table input:hover, .items-table select:hover, .admin-cat-head input:hover { border-color: var(--border); }
.items-table input:focus, .items-table select:focus, .admin-cat-head input:focus { outline: 2px solid var(--accent); background: var(--bg); }
.items-table input[type="number"] { max-width: 100px; font-weight: 700; }
.items-table input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--ok); }
.del { border: 0; background: transparent; color: var(--danger); font-size: 1.1rem; padding: 4px 8px; border-radius: 8px; }
.del:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 10px; opacity: 0;
  transition: opacity .2s, transform .2s; pointer-events: none; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

[hidden] { display: none !important; }

/* ---------- Phones ---------- */
.btn-pill { white-space: nowrap; }
.form-grid { align-items: end; }
.del { min-width: 40px; min-height: 40px; }
.items-table input[type="number"] { font-variant-numeric: tabular-nums; }

@media (max-width: 640px) {
  .hide-sm { display: none; }
  .topbar { padding: 10px 12px; }
  .controls { gap: 6px; }
  .btn-pill { padding: 0 12px; }
  .card { padding: 16px 14px; border-radius: 14px; }
  .admin-wrap { padding: 14px 12px 40px; }
  .card .btn-primary { width: 100%; justify-content: center; }
  .qr-preview canvas { max-width: 240px; }

  /* Items table becomes one card per dish */
  .table-scroll { overflow: visible; }
  table.items-table { min-width: 0; }
  .items-table thead { display: none; }
  .items-table, .items-table tbody, .items-table td { display: block; }
  .items-table tr {
    display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; align-items: end;
    padding: 12px; margin-bottom: 10px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg);
  }
  .items-table td { border: 0; padding: 0; }
  .items-table td[data-label]::before {
    content: attr(data-label); display: block; font-size: .78rem; color: var(--muted); margin-bottom: 2px;
  }
  .items-table input, .items-table select { border-color: var(--border); background: var(--surface); min-height: 42px; }
  .items-table input[type="number"] { max-width: none; }
  .items-table td[data-label="On menu"] { display: flex; align-items: center; gap: 8px; min-height: 42px; }
  .items-table td[data-label="On menu"]::before { margin: 0; font-size: .9rem; }
  .items-table input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; }
  .items-table .del-cell { text-align: right; }
  .admin-cat-head input { border-color: var(--border); background: var(--surface); }
}
@media (max-width: 360px) {
  .brand-mark { width: 32px; height: 32px; font-size: 18px; }
  .brand-name { font-size: 1rem; }
  .btn-icon { width: 38px; height: 38px; }
  .btn-pill { height: 38px; padding: 0 10px; font-size: .95rem; }
}
.brand { min-width: 0; }
.brand-mark { flex: none; }
.brand-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.controls { flex: none; }

/* ---------- Table ordering ---------- */
.table-badge {
  display: inline-flex; align-items: center; height: 40px; padding: 0 12px; border-radius: 999px;
  background: var(--accent); color: #1d1b2e; font-weight: 700; white-space: nowrap;
}
.scan-note { color: var(--text); font-weight: 600; }
.made-by { font-size: .9rem; }
body.has-orderbar main { padding-bottom: 110px; }
.qty { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.qty button { width: 38px; height: 38px; border: 0; background: var(--surface-2); font-size: 1.15rem; font-weight: 700; }
.qty span { min-width: 28px; text-align: center; font-weight: 700; }
.add-btn {
  height: 38px; padding: 0 14px; border-radius: 10px; border: 1.5px solid var(--cat, var(--c1));
  background: transparent; color: var(--cat, var(--c1)); font-weight: 700;
}
.add-btn:hover { background: var(--cat, var(--c1)); color: #fff; }
.line .qty button { width: 34px; height: 34px; }
.line .add-btn { display: none; }

.orderbar {
  position: fixed; left: 16px; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 30;
  max-width: 560px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border: 0; border-radius: 14px; padding: 15px 18px;
  background: var(--navy); color: #fff; box-shadow: 0 10px 30px rgba(0, 0, 0, .3); font-weight: 600;
}
.orderbar strong { color: var(--accent); }
dialog.sheet {
  width: min(560px, calc(100% - 24px)); max-height: 90vh; padding: 0; border: 1px solid var(--border);
  border-radius: 18px; background: var(--surface); color: var(--text);
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, .55); }
.sheet-head, .sheet-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; }
.sheet-head { border-bottom: 1px solid var(--border); }
.sheet-head h3 { margin: 0; font-size: 1.2rem; }
.sheet-body { padding: 8px 16px 4px; overflow-y: auto; max-height: 58vh; }
.sheet-foot { border-top: 1px solid var(--border); flex-direction: column; align-items: stretch; }
.sheet-foot .btn-primary { justify-content: center; }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.line { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px dashed var(--border); }
.line small { color: var(--muted); display: block; }
.total-row { display: flex; justify-content: space-between; font-size: 1.15rem; font-weight: 700; padding: 12px 0; }
.order-done { text-align: center; padding: 28px 20px 24px; }
.order-done h3 { margin: 10px 0 6px; font-size: 1.5rem; }
.order-done p { color: var(--muted); margin: 0 0 18px; }
.done-icon {
  width: 64px; height: 64px; margin: 0 auto; border-radius: 50%; display: grid; place-items: center;
  background: var(--ok); color: #fff; font-size: 2rem; font-weight: 700;
}

/* ---------- Admin: ordering + orders ---------- */
.switch { display: flex; align-items: center; gap: 10px; font-weight: 600; cursor: pointer; }
.switch input { width: 22px; height: 22px; accent-color: var(--ok); }
.status-pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .85rem; font-weight: 700; }
.status-on { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.status-off { background: var(--surface-2); color: var(--muted); }
.table-qr-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; margin: 12px 0; }
.table-qr-list button {
  border: 1px solid var(--border); background: var(--bg); border-radius: 10px; padding: 10px 6px; font-weight: 600;
}
.table-qr-list button.active { border-color: var(--accent); outline: 2px solid var(--accent); }
.tabs { display: flex; gap: 8px; margin: 10px 0; flex-wrap: wrap; }
.tabs button { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 6px 14px; font-weight: 600; }
.tabs button.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.order-cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.order-card { border: 1px solid var(--border); border-radius: 14px; padding: 14px; background: var(--bg); }
.order-card.new { border-left: 5px solid var(--accent); }
.order-card header { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.order-card .tbl { font-size: 1.3rem; font-weight: 700; }
.order-card .meta { color: var(--muted); font-size: .85rem; }
.order-card ul { list-style: none; margin: 6px 0; padding: 0; }
.order-card li { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; }
.order-card .note { background: var(--surface-2); border-radius: 8px; padding: 6px 10px; font-size: .9rem; margin: 6px 0; }
.order-card footer { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 8px; font-weight: 700; }
.badge-count { background: var(--danger); color: #fff; border-radius: 999px; padding: 0 8px; font-size: .8rem; margin-left: 4px; }
@media (max-width: 640px) {
  .table-badge { height: 38px; padding: 0 10px; }
  .order-cards { grid-template-columns: 1fr; }
}
@media (max-width: 360px) {
  .table-badge { font-size: .9rem; }
}
.order-card footer span { white-space: nowrap; }
.card .order-card .btn-primary, .card .order-card .btn-ghost { width: auto; flex: none; padding: 8px 16px; }

/* ---------- Admin v2: tabs, tiles, reports, customers ---------- */
.admin-tabs {
  position: sticky; top: 61px; z-index: 15; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  padding: 10px 16px; background: var(--bg); border-bottom: 1px solid var(--border);
}
.admin-tabs::-webkit-scrollbar { display: none; }
.admin-tabs button {
  flex: none; border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: 8px 16px; font-weight: 600; white-space: nowrap;
}
.admin-tabs button.active { background: var(--navy); border-color: var(--navy); color: #fff; }
@media (min-width: 1072px) { .admin-tabs { padding-left: calc((100% - 1040px) / 2 + 16px); } }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); }
.tile-label { color: var(--muted); font-size: .9rem; }
.tile-value { font-size: 1.6rem; font-weight: 700; line-height: 1.2; margin-top: 2px; }
.tile-sub { color: var(--muted); font-size: .82rem; margin-top: 2px; }
.tiles-modes .tile-value { font-size: 1.25rem; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.filters .field { flex: 1 1 140px; }
.filters .btn-ghost { height: 42px; }
.filter-chip { margin: 12px 0 0; font-weight: 600; }

.chart-grid { display: grid; gap: 18px; grid-template-columns: 1fr; margin-bottom: 18px; }
.chart-grid .card { margin-bottom: 0; }
@media (min-width: 820px) { .chart-grid { grid-template-columns: 1fr 1fr; } .chart-wide { grid-column: 1 / -1; } }
.chart-card h3 { margin: 0 0 10px; font-size: 1.05rem; }
.chart-box { position: relative; height: 240px; }
.chart-box-tall { height: 320px; }

.order-sub { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 4px; }
.status-new { background: color-mix(in srgb, var(--accent) 25%, transparent); color: var(--text); }
.status-served { background: color-mix(in srgb, var(--chart) 18%, transparent); color: var(--text); }
.status-paid { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.order-card.served { border-left: 5px solid var(--chart); }
.order-card.paid { border-left: 5px solid var(--ok); }
.order-total { display: flex; justify-content: space-between; border-top: 1px dashed var(--border); padding-top: 8px; margin-top: 6px; }
.order-card footer { flex-wrap: wrap; font-weight: 400; }
.card-actions { display: flex; gap: 8px; align-items: center; margin-left: auto; }
.pay-modes { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; width: 100%; }
.pay-modes .btn-ghost { padding: 8px 12px; }
.paid-label { color: var(--ok); font-weight: 700; }
.btn-link { border: 0; background: none; color: var(--chart); font-weight: 600; padding: 6px 4px; text-decoration: underline; }
.btn-whatsapp { border-color: #1fa855; color: #13863f; }
:root[data-theme="dark"] .btn-whatsapp { color: #3fd07a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-whatsapp { color: #3fd07a; } }
.settings-grid { align-items: end; }

.data-table { width: 100%; border-collapse: collapse; }
.data-table th { text-align: left; font-size: .85rem; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--border); }
.data-table td { padding: 10px 8px; border-bottom: 1px solid var(--border); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table a { color: inherit; }
.meta { color: var(--muted); font-size: .85rem; font-weight: 400; }

@media (max-width: 640px) {
  .admin-tabs { top: 59px; padding: 8px 12px; }
  .tiles { grid-template-columns: 1fr 1fr; gap: 10px; }
  .tile { padding: 12px; }
  .tile-value { font-size: 1.3rem; }
  .filters .field { flex: 1 1 calc(50% - 10px); }
  .filters .btn-ghost { flex: 1 1 100%; }
  .chart-box { height: 220px; }
  .card .card-actions .btn-primary { width: auto; }
  /* Customer table becomes stacked rows */
  .data-table thead { display: none; }
  .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; }
  .data-table tr { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; background: var(--bg); }
  .data-table td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; gap: 10px; text-align: right; }
  .data-table td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .85rem; text-align: left; }
  .data-table td.num { text-align: right; }
}
.admin-tabs button.active, .tabs button.active { background: var(--accent); border-color: var(--accent); color: #1d1b2e; }
