:root {
  --bg: #f4f7f9; --card: #fff; --ink: #172b3a; --muted: #5d7280; --line: #e1e8ec;
  --brand: #0b7a8a; --brand-dark: #12384a; --good: #1a7f4b; --good-bg: #e3f5ec;
  --bad: #b42323; --bad-bg: #fce9e9; --warn: #8a5a00; --warn-bg: #fff3d6; --info: #1c5fa8; --info-bg: #e6f0fb;
  --neutral-bg: #eaeff2;
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif; color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 15px; line-height: 1.45; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
h1, h2, h3 { margin: 0; }

.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, #12384a, #0b7a8a); padding: 20px; }
.login-card { background: var(--card); border-radius: 14px; padding: 32px; width: 100%; max-width: 380px; display: grid; gap: 14px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-card h1 { font-size: 1.5rem; } .login-card p { margin: 0; }
.brand-mark { width: 52px; height: 52px; border-radius: 12px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 1.2rem; }
.brand-mark.small { width: 34px; height: 34px; font-size: .9rem; border-radius: 9px; }
.form-error { color: var(--bad); min-height: 1.2em; font-size: .9rem; }
label { display: grid; gap: 5px; font-weight: 600; font-size: .85rem; }
input, select { padding: 10px 12px; border: 1px solid #b9c8cf; border-radius: 8px; font: inherit; background: #fff; color: var(--ink); }
input:focus, select:focus, button:focus-visible, a:focus-visible { outline: 3px solid rgba(11,122,138,.35); outline-offset: 1px; }

.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; transition: grid-template-columns .2s ease; }
.app.collapsed { grid-template-columns: 68px 1fr; }
.collapse-btn { margin-left: auto; background: rgba(255,255,255,.08); color: #fff; border: 0; border-radius: 8px; width: 28px; height: 28px; cursor: pointer; font-size: 1rem; line-height: 1; }
.collapse-btn:hover { background: rgba(255,255,255,.18); }
.ico-out { display: none; }
.app.collapsed .sidebar { padding: 18px 8px; overflow: visible; }
.app.collapsed .lbl, .app.collapsed #who { display: none; }
.app.collapsed .brand { flex-direction: column; padding: 0; gap: 10px; }
.app.collapsed .collapse-btn { margin-left: 0; transform: rotate(180deg); }
.app.collapsed nav a { justify-content: center; padding: 10px 0; }
.app.collapsed .sidebar-foot { padding: 0; }
.app.collapsed #logout .ico-out { display: inline; }
.app.collapsed #logout { padding: 6px 0; }
.sidebar { background: var(--brand-dark); color: #fff; padding: 18px 12px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; padding: 0 8px; }
nav { display: grid; gap: 4px; overflow-y: auto; min-height: 0; }
.nav-group { min-width: 0; border-top: 1px solid rgba(255,255,255,.12); margin-top: 6px; padding-top: 6px; }
.nav-group summary { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; font-size: .85rem; font-weight: 700; color: #fff; cursor: pointer; list-style: none; }
.nav-group summary::-webkit-details-marker { display: none; }
.nav-group summary::after { content: '+'; margin-left: auto; }
.nav-group[open] summary::after { content: '-'; }
.nav-group summary:hover { background: rgba(255,255,255,.08); }
.nav-group summary:focus-visible { outline: 2px solid #cfe2e8; outline-offset: -2px; }
.nav-group summary .ico { display: none; }
.app.collapsed .nav-group summary { padding: 8px 2px; gap: 2px; }
.app.collapsed .nav-group summary .ico { display: inline; }
nav a { color: #cfe2e8; text-decoration: none; padding: 10px 12px; border-radius: 8px; display: flex; gap: 10px; align-items: center; }
nav a:hover { background: rgba(255,255,255,.08); }
nav a.active { background: var(--brand); color: #fff; }
.ico { width: 18px; text-align: center; }
.sidebar-foot { margin-top: auto; display: grid; gap: 8px; padding: 0 8px; color: #cfe2e8; }
.main { min-width: 0; }
@media (min-width: 861px) {
  .app.collapsed .sidebar { z-index: 10; }
  .app.collapsed .main { position: relative; z-index: 0; }
  .app.collapsed nav { overflow: visible; }
  .app.collapsed .nav-group { position: relative; }
  .app.collapsed .nav-group-links { position: absolute; left: 100%; top: 0; width: 260px; max-height: min(60vh, 420px); overflow-y: auto; padding: 8px; background: var(--brand-dark); border: 1px solid rgba(255,255,255,.2); border-radius: 0 10px 10px 10px; box-shadow: 0 12px 24px rgba(0,0,0,.25); }
  .app.collapsed .nav-group-links .lbl { display: inline; }
  .app.collapsed .nav-group-links a { justify-content: flex-start; padding: 10px 12px; }
}
.cards.sales-cards { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 18px; }
#sales-results { min-width: 0; }
.sales-chart { margin-bottom: 18px; min-width: 0; max-width: 100%; }
.sales-svg { display: block; width: 100%; height: auto; }
.sales-chart-head, .sales-chart-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; }
.sales-chart-head { justify-content: space-between; margin-bottom: 12px; }
.sales-chart-controls label { min-width: 100px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.sales-change { margin-top: 10px; font-size: .9rem; }
.sales-change.good { color: var(--good); }
.sales-change.bad { color: var(--bad); }
.stock-controls, .stock-item { display: grid; gap: 12px; min-width: 0; }
.stock-search { display: flex; align-items: end; gap: 12px; }
.stock-search label { flex: 1; min-width: 0; }
.stock-results { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 14px; }
.stock-item input, .stock-item select, .stock-controls select, .stock-search input { width: 100%; min-width: 0; }
.stock-cart-line { display: grid; grid-template-columns: minmax(0, 1fr) 140px auto auto; gap: 12px; align-items: end; border-bottom: 1px solid var(--line); padding: 14px 0; }
.stock-cart-line input { width: 100%; }
.stock-cart-line strong, #stock-review li { overflow-wrap: anywhere; }
.stock-notification { overflow-wrap: anywhere; }
#stock-review form { display: grid; gap: 12px; margin: 14px 0; }
#stock-review textarea, #stock-review select { width: 100%; min-width: 0; font: inherit; }
.stock-cart .btn, .stock-item .btn, .stock-controls .btn { min-height: 44px; }
.stock-cart-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 16px; position: sticky; bottom: 0; background: var(--card); padding: 12px 0; }
@media (max-width: 600px) {
  .stock-search { flex-direction: column; align-items: stretch; }
  .stock-cart-line { grid-template-columns: 1fr 1fr; }
  .stock-cart-line > div { grid-column: 1 / -1; }
  .stock-cart input, .stock-item input, .stock-item select, .stock-controls select, .stock-search input { font-size: 16px; min-height: 44px; }
}
.sales-cards .stat { font-size: clamp(1rem, 2.3vw, 2rem); overflow-wrap: anywhere; }
.sales-net { background: var(--good); }
.sales-actual { background: #2563eb; }
.sales-refunds { background: var(--bad); }
.sales-discounts { background: #c88817; }
@media (max-width: 600px) {
  .cards.sales-cards { grid-template-columns: 1fr; }
}
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 22px 28px 6px; }
.page-head h2 { font-size: 1.4rem; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.view { padding: 14px 28px 40px; display: grid; gap: 18px; max-width: 1300px; }
.banner { padding: 12px 28px; font-weight: 600; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.bad { background: var(--bad-bg); color: var(--bad); }

.btn { border: 1px solid transparent; border-radius: 8px; padding: 9px 14px; font: inherit; font-weight: 600; cursor: pointer; background: var(--neutral-bg); color: var(--ink); }
.btn:hover { filter: brightness(.96); } .btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--brand); color: #fff; } .btn.danger { background: var(--bad); color: #fff; }
.btn.good { background: var(--good); color: #fff; }
.btn.ghost { background: transparent; border-color: rgba(120,140,150,.5); color: inherit; }
.btn.wide { width: 100%; } .small-btn { padding: 5px 10px; font-size: .85rem; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; }
.card h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 8px; }
.stat { font-size: 2rem; font-weight: 700; line-height: 1.1; }
.stat.good { color: var(--good); } .stat.bad { color: var(--bad); } .stat.warn { color: var(--warn); }
.card .sub { color: var(--muted); font-size: .85rem; margin-top: 4px; }
.card.link { cursor: pointer; } .card.link:hover { border-color: var(--brand); }
.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; }

.table-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.table-card > h3 { padding: 14px 16px 0; font-size: 1rem; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { background: #f8fafb; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; } tr.clickable:hover td { background: #f6fafb; }
td.empty { text-align: center; color: var(--muted); padding: 30px; }
.nowrap { white-space: nowrap; }

.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; white-space: nowrap; }
.pill.good { background: var(--good-bg); color: var(--good); } .pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.warn { background: var(--warn-bg); color: var(--warn); } .pill.info { background: var(--info-bg); color: var(--info); }
.pill.neutral { background: var(--neutral-bg); color: var(--muted); }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.toolbar label { min-width: 150px; } .toolbar .grow { flex: 1; min-width: 200px; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; padding: 10px 14px; }

.chart { width: 100%; height: 180px; display: block; }
.legend { display: flex; gap: 14px; font-size: .8rem; color: var(--muted); margin-top: 6px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }
.list { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.list li { display: flex; gap: 10px; justify-content: space-between; align-items: flex-start; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.check:last-child { border-bottom: 0; }
.check .mark { font-weight: 700; width: 22px; flex: none; }
.check .mark.ok { color: var(--good); } .check .mark.no { color: var(--bad); } .check .mark.na { color: var(--muted); }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; font-size: .92rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-word; }

.switch-row { display: flex; justify-content: space-between; gap: 14px; align-items: center; flex-wrap: wrap; }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.form-row label { flex: 1; min-width: 180px; }
.notice { background: var(--info-bg); color: var(--info); padding: 10px 12px; border-radius: 8px; font-size: .9rem; }
.notice.bad { background: var(--bad-bg); color: var(--bad); }

.log { display: grid; gap: 0; background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.log-row { padding: 9px 14px; border-bottom: 1px solid var(--line); font-family: Consolas, monospace; font-size: .82rem; }
.log-row:last-child { border-bottom: 0; }
.log-row summary { cursor: pointer; display: flex; gap: 10px; }
.log-row .t { color: var(--muted); flex: none; } .log-row .m { word-break: break-word; }
.log-row.error { background: #fff7f7; } .log-row.warn { background: #fffaf0; }
.log-row pre { margin: 8px 0 0; white-space: pre-wrap; word-break: break-word; max-height: 300px; overflow: auto; background: #f4f7f9; padding: 8px; border-radius: 6px; }

.drawer { position: fixed; inset: 0; background: rgba(10,25,35,.45); display: flex; justify-content: flex-end; z-index: 20; }
.drawer-panel { background: #fff; width: min(460px, 100%); height: 100%; overflow-y: auto; padding: 24px; position: relative; display: grid; gap: 14px; align-content: start; }
.drawer-panel .close { position: absolute; top: 12px; right: 12px; font-size: 1.2rem; }
.toasts { position: fixed; bottom: 18px; right: 18px; display: grid; gap: 8px; z-index: 30; }
.toast { background: var(--brand-dark); color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 360px; }
.toast.bad { background: var(--bad); } .toast.good { background: var(--good); }
.spinner { color: var(--muted); padding: 30px; text-align: center; }

@media (max-width: 860px) {
  .app, .app.collapsed { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .collapse-btn, .ico-out { display: none !important; }
  .app.collapsed .lbl { display: inline; }
  .app.collapsed nav a { justify-content: flex-start; padding: 8px 10px; }
  .sidebar, .app.collapsed .sidebar { position: relative; z-index: 10; overflow: visible; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px; gap: 8px; }
  .main { position: relative; z-index: 0; }
  nav { width: 100%; order: 3; display: flex; gap: 2px; position: relative; overflow: visible; z-index: 10; }
  nav > a { flex: 0 0 auto; }
  nav a, .app.collapsed nav a { padding: 8px 6px; } .ico { display: none; }
  .nav-group { flex: 1 1 auto; border: 0; margin: 0; padding: 0; }
  .nav-group summary, .app.collapsed .nav-group summary { padding: 8px 4px; gap: 4px; font-size: .8rem; white-space: nowrap; min-height: 44px; }
  nav > a { font-size: .8rem; min-height: 44px; }
  .nav-group-links { position: absolute; top: 100%; right: 0; width: min(280px, 100%); max-height: min(60vh, 420px); overflow-y: auto; padding: 8px; background: var(--brand-dark); border: 1px solid rgba(255,255,255,.2); border-radius: 0 0 10px 10px; box-shadow: 0 12px 24px rgba(0,0,0,.25); }
  [data-nav-group="sales"] .nav-group-links { left: 0; right: auto; }
  .nav-group-links a, .app.collapsed .nav-group-links a { padding: 10px 12px; }
  .app.collapsed .nav-group summary .ico { display: none; }
  .sidebar-foot { margin: 0 0 0 auto; display: flex; align-items: center; }
  .page-head, .view, .banner { padding-left: 14px; padding-right: 14px; }
  .grid-2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
}
@media (max-width: 380px) {
  nav { gap: 0; }
  nav > a, .app.collapsed nav > a { padding: 8px 4px; font-size: .75rem; }
  .nav-group summary, .app.collapsed .nav-group summary { padding: 8px 2px; gap: 2px; font-size: .75rem; }
}

.bars { display: flex; gap: 6px; align-items: flex-end; height: 190px; }
.bar-col { flex: 1; display: flex; flex-direction: column; height: 100%; min-width: 0; }
.bar-stack { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; }
.seg { width: 100%; min-height: 0; }
.seg.delivered, .dot.d-delivered { background: var(--good); }
.seg.other, .dot.d-other { background: #8fb7d9; }
.seg.failed, .dot.d-failed { background: var(--bad); }
.seg:first-child { border-radius: 4px 4px 0 0; }
.bar-label { text-align: center; font-size: .72rem; color: var(--muted); padding-top: 4px; }
.small-stat { font-size: 1.4rem; }
.gap-top { margin-top: 18px; }
label.inline { display: flex; align-items: center; gap: 6px; min-width: 0; font-weight: 500; }
label.inline input { padding: 0; }
.permission-table { min-width: 680px; }
.permission-table td:not(:first-child), .permission-table th:not(:first-child) { text-align: center; }
.permission-table input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--brand); }
.permission-table input[type="checkbox"]:disabled { accent-color: #87949a; cursor: not-allowed; }
.access-section { display: grid; gap: 14px; }
.access-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.access-actions .btn { min-height: 38px; }
.muted-row { opacity: .7; }
.daily-sales-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 14px; }
.daily-sales-page, .daily-sales-page > *, #daily-sales-records { min-width: 0; }
.daily-sales-form input, .daily-sales-form select { width: 100%; min-width: 0; }
.daily-sales-date label { width: 100%; max-width: 280px; }
.daily-sales-form input[readonly] { background: var(--bg); }
.sales-full, .daily-sales-date { grid-column: 1 / -1; }
.daily-sales-date { display: grid; grid-template-columns: repeat(2, minmax(0, 280px)); gap: 10px; }
.daily-sales-date > p { grid-column: 1 / -1; }
.daily-sales-form .btn { min-height: 44px; }
@media (max-width: 600px) {
  .daily-sales-form, .daily-sales-date { grid-template-columns: minmax(0, 1fr); }
  .daily-sales-date label { max-width: none; }
}

.field { display: flex; flex-direction: column; font-size: .85rem; color: var(--muted); font-weight: 600; min-width: 220px; position: relative; }
.datepick { position: relative; margin-top: 4px; }
.datebtn { width: 100%; text-align: left; border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 9px 12px; font: inherit; font-weight: 400; color: var(--ink); cursor: pointer; }
.datebtn::after { content: '▾'; float: right; color: var(--muted); }
.dp-pop { position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px rgba(18,56,74,.22); width: 560px; max-width: calc(100vw - 32px); color: var(--ink); font-weight: 400; }
.dp-pop.hidden { display: none; }
.dp-body { display: flex; }
.dp-cal { flex: 1; padding: 14px 16px; border-right: 1px solid var(--line); min-width: 0; }
.dp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.dp-nav { border: 0; background: none; font-size: 1.4rem; cursor: pointer; padding: 0 10px; color: var(--ink); } .dp-nav:disabled { color: #c4cdd2; cursor: default; }
.dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); row-gap: 2px; text-align: center; }
.dp-dow span { font-size: .8rem; padding: 4px 0; color: var(--ink); border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.dp-day { border: 0; background: none; height: 34px; font: inherit; font-size: .9rem; cursor: pointer; color: var(--ink); border-radius: 0; }
.dp-day.other { color: #8a99a3; } .dp-day.future { color: #c4cdd2; cursor: default; }
.dp-day.in { background: #d9eef1; }
.dp-day span { display: inline-block; width: 34px; line-height: 34px; border-radius: 50%; }
.dp-day.end { color: #fff; } .dp-day.end span { background: var(--brand); }
.dp-inputs { display: flex; gap: 12px; margin-top: 10px; }
.dp-inputs label { flex: 1; min-width: 0; font-size: .75rem; color: var(--muted); } .dp-inputs input { width: 100%; margin-top: 2px; }
.dp-presets { display: flex; flex-direction: column; padding: 8px 0; width: 150px; }
.dp-presets button { border: 0; background: none; text-align: left; padding: 9px 18px; font: inherit; cursor: pointer; color: var(--ink); } .dp-presets button:hover { background: var(--bg); }
.dp-foot { display: flex; justify-content: flex-end; gap: 22px; padding: 10px 18px; border-top: 1px solid var(--line); }
.dp-link { border: 0; background: none; font: inherit; font-weight: 700; letter-spacing: .03em; cursor: pointer; color: var(--ink); } .dp-link.done { color: var(--brand); }
@media (max-width: 600px) { .dp-body { flex-direction: column; } .dp-cal { border-right: 0; border-bottom: 1px solid var(--line); } .dp-presets { flex-direction: row; flex-wrap: wrap; width: auto; } .dp-pop { width: calc(100vw - 32px); } }
