:root {
  --forest: #0b5430;
  --forest-dark: #083d22;
  --lime: #8bc541;
  --lime-dark: #6a9a2e;
  --teal: #015c61;
  --cream: #f4f1eb;
  --ink: #1c2b24;
  --muted: #3d5c56;
  --danger: #c44536;
  --line: rgba(11, 84, 48, 0.12);
  --shadow: 0 16px 40px rgba(11, 84, 48, 0.12);
  font-family: Inter, system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--cream);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100vh; min-height: 100dvh; background: var(--cream); }
button, a, input, select, textarea, summary { touch-action: manipulation; }
a { color: var(--teal); }
h1, h2, h3 { color: var(--forest); margin: 0 0 0.35rem; }
h1 { font-size: 1.8rem; letter-spacing: -0.02em; }
button, input, select, textarea { font: inherit; }
img { max-width: 100%; }

.topbar { background: var(--forest); color: #fff; position: sticky; top: 0; z-index: 40; }
.topbar-row, .subnav, .page, .pos-layout {
  padding-left: max(1.25rem, env(safe-area-inset-left));
  padding-right: max(1.25rem, env(safe-area-inset-right));
}
.topbar-row { min-height: 72px; display: flex; align-items: center; flex-wrap: wrap; gap: 0.65rem 0.75rem; padding-top: 0.65rem; padding-bottom: 0.65rem; }
.brand { font-weight: 700; letter-spacing: 0.04em; line-height: 1.1; }
.brand-sub { color: #d7efb4; font-size: 0.8rem; }
.grow { flex: 1 1 140px; min-width: 0; }
.top-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 0.45rem; margin-left: auto; }
.short-label { display: none; }
.menu-toggle {
  display: none; width: 42px; height: 42px; padding: 0; border-radius: 10px; cursor: pointer;
  border: 1px solid rgba(255,255,255,0.35); background: transparent; flex-direction: column;
  align-items: center; justify-content: center; gap: 5px;
}
.menu-toggle span {
  display: block; width: 18px; height: 2px; border-radius: 2px; background: #fff;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
body.menu-open .menu-toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
body.menu-open .menu-toggle span:nth-child(2) { opacity: 0; }
body.menu-open .menu-toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
.subnav {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; overflow: visible; padding-bottom: 0.85rem;
}
.nav-link, .tabs a {
  color: #fff; text-decoration: none; border: 1px solid rgba(255,255,255,0.35);
  border-radius: 10px; padding: 0.45rem 0.75rem; white-space: nowrap;
  min-height: 40px; display: inline-flex; align-items: center;
}
.nav-link.active, .tabs a.active { background: var(--lime); color: var(--forest); border-color: var(--lime); }
.nav-group { position: relative; }
.nav-parent {
  list-style: none; background: transparent; color: #fff; cursor: pointer; font-weight: inherit; gap: 0.45rem;
}
.nav-parent::-webkit-details-marker { display: none; }
.nav-parent::marker { content: ""; }
.nav-parent::after {
  content: ""; width: 0.4rem; height: 0.4rem; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
}
.nav-group[open] > .nav-parent::after { transform: rotate(225deg) translate(-1px, -1px); }
.nav-sub {
  display: none; position: absolute; z-index: 50; top: 100%; left: 0; min-width: 11.5rem;
  padding: 0.45rem 0.35rem 0.35rem; border-radius: 12px; background: #fff; box-shadow: var(--shadow);
}
.nav-sub::before {
  content: ""; position: absolute; left: 0; right: 0; bottom: 100%; height: 0.35rem;
}
.nav-sub .nav-link { color: var(--forest); border-color: transparent; width: 100%; }
.nav-sub .nav-link:hover { background: rgba(139, 197, 65, 0.28); }
.nav-sub .nav-link.active { background: var(--lime); color: var(--forest); }
@media (min-width: 768px) {
  .nav-group:hover > .nav-sub,
  .nav-group:focus-within > .nav-sub,
  .nav-group[open] > .nav-sub { display: grid; }
}
.session-pill, .who { font-size: 0.85rem; }
.session-pill { border: 1px solid rgba(139,197,65,0.55); background: rgba(139,197,65,0.18); border-radius: 999px; padding: 0.25rem 0.7rem; }
.brand-lock {
  width: 36px; height: 36px; border-radius: 10px; background: var(--lime); color: var(--forest);
  display: grid; place-items: center; font-weight: 800;
}
.session-warn {
  background: #c47b12; color: #fff; text-align: center; padding: 0.6rem 1rem;
}

.btn {
  border: 0; border-radius: 10px; padding: 0.7rem 1rem; font-weight: 700; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-forest { background: var(--forest); color: #fff; }
.btn-lime { background: var(--lime); color: var(--forest); }
.btn-outline { background: #fff; color: var(--danger); border: 1px solid var(--danger); }
.btn-ghost { background: transparent; color: #fff; border: 1px solid #fff; padding: 0.25rem 0.6rem; }
.btn:disabled { background: #d5d5d5; color: #777; cursor: not-allowed; }

.page { max-width: 1200px; margin: 0 auto; padding-top: 1.5rem; padding-bottom: max(2.5rem, env(safe-area-inset-bottom)); }
.page-head, .filters, .actions, .row, .line, .stat-grid, .split-3 { display: flex; gap: 0.75rem; }
.page-head, .line { justify-content: space-between; align-items: center; }
.page-head, .actions { flex-wrap: wrap; }
.page-head { align-items: flex-start; }
.page-head > div { min-width: 0; }
.actions .btn { flex: 1 1 8rem; }
details.card summary { cursor: pointer; display: flex; flex-wrap: wrap; gap: 0.25rem 0.75rem; align-items: baseline; }
.lede, .muted, .hint { color: var(--teal); }
.muted { color: var(--muted); font-size: 0.92rem; }
.hint { font-size: 0.78rem; font-style: italic; text-align: center; margin: 0; }
.stack { display: grid; gap: 0.85rem; }
.card, .table-wrap, .panel, .login-card {
  background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 1rem 1.1rem;
}
.table-wrap { overflow: auto; margin-top: 1rem; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.65rem 0.5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--forest); }
.stat-grid, .split-3 { display: grid; gap: 0.85rem; margin: 1rem 0; }
.stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.split-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; }
.stat { border-radius: 16px; padding: 1rem; min-height: 110px; min-width: 0; }
.stat span { display: block; opacity: 0.85; }
.stat strong { display: block; font-size: clamp(1.2rem, 2.4vw, 1.7rem); margin-top: 0.4rem; overflow-wrap: anywhere; }
.stat.forest { background: var(--forest); color: #fff; }
.stat.lime { background: var(--lime); color: var(--forest); }
.stat.teal { background: var(--teal); color: #fff; }
.stat.cream { background: #fff; color: var(--forest); border: 1px solid var(--line); }
.line { padding: 0.7rem 0; border-bottom: 1px solid var(--line); }
.line > div { min-width: 0; }
.line.block { display: block; }
.teal { color: var(--teal); }
.danger { color: var(--danger); font-weight: 700; }
.filters, .form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); gap: 0.75rem; align-items: end; margin: 1rem 0; }
label { display: grid; gap: 0.3rem; font-size: 0.92rem; color: var(--muted); }
input, select, textarea {
  width: 100%; border: 1px solid rgba(11,84,48,0.25); border-radius: 10px; padding: 0.65rem 0.75rem; background: #fff; color: var(--ink);
}
.check { display: flex; align-items: center; gap: 0.5rem; }
.check input { width: auto; }
.span-2 { grid-column: 1 / -1; }
.alert { border-radius: 12px; padding: 0.75rem 0.9rem; margin: 0.75rem 0; }
.alert-error { background: #f8e4e1; color: #8e2f24; }
.alert-success { background: #e7f3d0; color: var(--forest); }
.alert-info { background: #d7ecee; color: #013e42; }
.inline { display: inline; }
.link, button.link { background: none; border: 0; color: var(--teal); padding: 0 0 0 0.5rem; cursor: pointer; font-weight: 600; }
.nowrap { white-space: nowrap; }
.thumb { width: 72px; height: 72px; object-fit: cover; border-radius: 10px; }
.pager { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; margin: 0.75rem 0 1.2rem; }
.pager a, .pager .current {
  border: 1px solid rgba(11, 84, 48, 0.25); border-radius: 10px; padding: 0.35rem 0.7rem;
  text-decoration: none; color: var(--forest); background: #fff;
}
.pager .current { background: var(--forest); color: #fff; border-color: var(--forest); }
.pager-count, .pager-gap { color: var(--muted); }
.tabs { display: flex; gap: 0.45rem; flex-wrap: wrap; margin: 1rem 0; }
.tabs a { color: var(--forest); border-color: rgba(11,84,48,0.25); background: #fff; }
.line-grid { display: grid; grid-template-columns: minmax(0, 2fr) repeat(4, minmax(0, 1fr)) auto; gap: 0.5rem; margin-bottom: 0.6rem; align-items: end; }

.login-wrap {
  min-height: 100vh; min-height: 100dvh; display: grid; place-items: center;
  padding: max(1.5rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1.5rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  background:
    radial-gradient(circle at top left, rgba(139, 197, 65, 0.35), transparent 42%),
    radial-gradient(circle at bottom right, rgba(1, 92, 97, 0.18), transparent 36%),
    var(--cream);
}
.login-card { width: min(420px, 100%); border-top: 6px solid var(--lime); box-shadow: var(--shadow); text-align: center; }
.login-card form { text-align: left; }
.login-mark {
  width: 80px; height: 80px; margin: 0 auto 0.8rem; border-radius: 50%; background: var(--forest); color: #fff;
  display: grid; place-items: center; font-weight: 800; box-shadow: 0 8px 20px rgba(11, 84, 48, 0.25);
}

.pos-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(260px, 380px); gap: 1rem; padding-top: 1rem; padding-bottom: 1.5rem; align-items: start; }
.pos-layout > * { min-width: 0; }
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 160px), 1fr)); gap: 0.75rem; margin-top: 0.8rem; }
.category-row { display: flex; gap: 0.4rem; overflow-x: auto; margin-top: 0.8rem; padding-bottom: 0.2rem; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.category-row::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid rgba(11, 84, 48, 0.25); background: #fff; color: var(--forest);
  border-radius: 999px; padding: 0.45rem 0.8rem; font-weight: 700; white-space: nowrap; cursor: pointer;
}
.chip.active { background: var(--forest); color: #fff; border-color: var(--forest); }
.product-card { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: #fff; display: flex; flex-direction: column; }
.product-card img, .placeholder { height: 120px; width: 100%; object-fit: cover; background: var(--cream); }
.placeholder { display: grid; place-items: center; color: var(--teal); text-align: center; padding: 0.5rem; font-size: 0.8rem; }
.product-card .body { padding: 0.75rem; display: grid; gap: 0.35rem; }
.product-card .body strong { overflow-wrap: anywhere; }
.remark { color: var(--muted); font-size: 0.85rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cart-panel { position: sticky; top: 5.25rem; max-height: calc(100dvh - 6rem); overflow: auto; padding: 0; scroll-margin-top: 5rem; }
.cart-head { background: var(--forest); color: #fff; margin: 0 0 1rem; padding: 1rem 1.1rem; border-radius: 16px 16px 0 0; }
#cart-empty, #cart-body { padding: 0 1.1rem 1rem; }
.cart-head h2, .cart-sub { color: #fff; }
.cart-sub { color: #d7efb4; margin: 0; }
.cart-items { max-height: 320px; overflow: auto; }
.cart-item { display: grid; grid-template-columns: 1fr auto; gap: 0.4rem; padding: 0.7rem 0; border-bottom: 1px solid var(--line); }
.qty { display: flex; align-items: center; gap: 0.3rem; }
.qty button { width: 44px; height: 44px; border-radius: 8px; border: 1px solid var(--line); background: #fff; cursor: pointer; }
.cart-panel .actions { display: grid; grid-template-columns: 1fr 1fr; }
.cart-dock { display: none; }
.empty { text-align: center; padding: 2rem 0; display: grid; gap: 0.3rem; color: var(--muted); }
.totals { display: grid; gap: 0.55rem; }
.total-line { background: var(--lime); color: var(--forest); border-radius: 10px; padding: 0.7rem 0.8rem; display: flex; justify-content: space-between; font-size: 1.25rem; }
.discount-line, .change-line { border-radius: 10px; padding: 0.45rem 0.7rem; display: flex; justify-content: space-between; }
.discount-line { background: #d7ecee; color: #013e42; }
.change-ok { background: #e7f3d0; color: var(--forest); }
.change-bad { background: #f8e4e1; color: #8e2f24; }
dialog {
  border: 0; border-radius: 16px; padding: 1.2rem; width: min(480px, calc(100% - 2rem));
  max-height: calc(100dvh - 2rem); overflow: auto; margin: auto; box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(11, 84, 48, 0.35); }

.customer { max-width: 980px; margin: 0 auto; padding: 1.5rem; }
.customer-head, .customer-meta, .customer-total { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.customer-empty, .customer-order { background: #fff; border-radius: 20px; padding: 1.5rem; border-top: 8px solid var(--lime); min-height: 420px; }
.customer-order h1 { font-size: 2.4rem; }
.eyebrow { color: var(--teal); font-weight: 700; letter-spacing: 0.04em; }
.countdown, .live { background: var(--forest); color: #fff; border-radius: 999px; padding: 0.4rem 0.8rem; }
.customer-total { margin-top: 1rem; background: var(--lime); color: var(--forest); border-radius: 14px; padding: 1rem 1.2rem; font-size: 1.6rem; }

.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.85rem; margin: 1rem 0; }
.chart-span { grid-column: 1 / -1; }
.chart-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.75rem; flex-wrap: wrap; }
.chart-head h2, .chart-head p { margin: 0; }
.chart-legend { display: flex; gap: 1rem; margin: 0.7rem 0 0.45rem; color: var(--muted); font-size: 0.85rem; }
.chart-legend span { display: inline-flex; align-items: center; gap: 0.35rem; }
.swatch { width: 0.75rem; height: 0.75rem; border-radius: 3px; display: inline-block; }
.swatch.sales, .chart-bar.sales { background: var(--forest); }
.swatch.profit, .chart-bar.profit { background: var(--lime); }
.chart-bar.profit.down { background: var(--danger); }
.chart-columns { display: grid; grid-template-columns: 3.4rem minmax(0, 1fr); gap: 0.45rem; }
.chart-y { position: relative; height: 180px; }
.chart-y span { position: absolute; right: 0; transform: translateY(50%); font-size: 0.72rem; color: var(--muted); white-space: nowrap; }
.chart-plot { position: relative; display: flex; align-items: stretch; gap: 0.2rem; height: 180px; border-bottom: 1px solid var(--line); }
.chart-zero { position: absolute; left: 0; right: 0; border-top: 1px dashed rgba(11, 84, 48, 0.28); }
.chart-day { position: relative; flex: 1 1 0; min-width: 0; border: 0; background: transparent; padding: 0; cursor: pointer; }
.chart-day.active { background: transparent; box-shadow: inset 0 -3px 0 var(--forest); }
.chart-detail { margin: 0 0 0.55rem; color: var(--forest); font-weight: 700; }
.chart-bar { position: absolute; width: 34%; border-radius: 4px 4px 0 0; min-height: 0; }
.chart-bar.sales { left: 12%; }
.chart-bar.profit { left: 52%; }
.chart-bar.down { border-radius: 0 0 4px 4px; }
.chart-x { display: flex; gap: 0.2rem; margin-top: 0.3rem; }
.chart-x span { flex: 1 1 0; min-width: 0; text-align: center; font-size: 0.68rem; color: var(--muted); }
.meter { margin: 0.85rem 0 0; }
.meter-top { display: flex; justify-content: space-between; gap: 0.75rem; align-items: baseline; }
.meter-top span { min-width: 0; overflow-wrap: anywhere; }
.meter-track { height: 10px; border-radius: 999px; background: rgba(11, 84, 48, 0.08); margin: 0.35rem 0 0.2rem; overflow: hidden; }
.meter-fill { height: 100%; border-radius: inherit; background: var(--forest); min-width: 0; }

@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1024px) {
  .line-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .line-grid > :first-child,
  .line-grid > .remove-line { grid-column: 1 / -1; }
}
@media (max-width: 980px) {
  .split-3 { grid-template-columns: 1fr; }
}
@media (max-width: 767px) {
  .menu-toggle { display: inline-flex; }
  .subnav { display: none; flex-direction: column; align-items: stretch; gap: 0.4rem; padding-top: 0.15rem; }
  body.menu-open .subnav { display: flex; }
  .subnav > .nav-link, .nav-parent { width: 100%; justify-content: space-between; }
  .nav-group { width: 100%; }
  .nav-sub {
    position: static; min-width: 0; margin: 0.35rem 0 0.15rem 0.75rem; padding: 0; background: transparent; box-shadow: none; gap: 0.35rem;
  }
  .nav-group[open] > .nav-sub { display: grid; }
  .nav-sub .nav-link { color: #fff; border-color: rgba(255,255,255,0.28); }
  .nav-sub .nav-link.active { background: var(--lime); color: var(--forest); border-color: var(--lime); }
  .chart-grid { grid-template-columns: 1fr; }
  .chart-y { height: 150px; }
  .chart-plot { height: 150px; }
  .topbar-row, .subnav, .page, .pos-layout {
    padding-left: max(0.85rem, env(safe-area-inset-left));
    padding-right: max(0.85rem, env(safe-area-inset-right));
  }
  h1 { font-size: 1.45rem; }
  .wide-label { display: none; }
  .short-label { display: inline; }
  .who { display: none; }
  .page-head .btn, .filters > .btn { width: 100%; }
  .pos-layout { grid-template-columns: 1fr; padding-bottom: calc(5.5rem + env(safe-area-inset-bottom)); }
  .cart-panel { position: static; max-height: none; overflow: visible; }
  .product-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .product-card img, .placeholder { height: 92px; }
  .cart-dock:not([hidden]) {
    display: flex; position: fixed; z-index: 30; align-items: center; justify-content: space-between;
    left: max(0.85rem, env(safe-area-inset-left)); right: max(0.85rem, env(safe-area-inset-right));
    bottom: max(0.75rem, env(safe-area-inset-bottom));
    border: 0; border-radius: 14px; background: var(--forest); color: #fff;
    padding: 0.9rem 1rem; font: inherit; font-weight: 700; box-shadow: var(--shadow); cursor: pointer;
  }
  .cart-dock strong { color: var(--lime); font-size: 1.15rem; }
  input, select, textarea { font-size: 16px; }
  .table-wrap { background: transparent; border: 0; padding: 0; overflow: visible; }
  .page table thead {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0);
  }
  .page table, .page tbody, .page tr, .page td { display: block; width: 100%; }
  .page tr {
    background: #fff; border: 1px solid var(--line); border-radius: 14px; margin: 0 0 0.75rem; padding: 0.35rem 0.8rem;
  }
  .page td {
    position: relative; border: 0; padding: 0.45rem 0 0.45rem 42%; text-align: right; overflow-wrap: anywhere;
  }
  .page td::before {
    content: attr(data-label); position: absolute; left: 0; top: 0.45rem; width: 40%;
    text-align: left; font-weight: 700; color: var(--forest);
  }
  .page td:not([data-label]) { padding-left: 0; text-align: left; }
  .page td:not([data-label])::before { content: none; }
  .page td.nowrap { white-space: normal; }
  .customer { padding: 1rem; }
  .customer-head, .customer-meta, .customer-total { flex-wrap: wrap; }
  .customer-order h1, .customer-empty h1 { font-size: 1.55rem; }
  .customer-total { font-size: 1.2rem; }
  .customer-empty, .customer-order { min-height: 0; padding: 1rem; }
}
@media (max-width: 560px) {
  .line-grid { grid-template-columns: 1fr; }
  .session-pill { display: none; }
}
@media (max-width: 380px) {
  .product-grid { grid-template-columns: 1fr; }
}
