:root {
  --bg: #f4f5f7; --panel: #fff; --ink: #1c2230; --muted: #667085; --line: #e1e4ea;
  --accent: #1f6f5c; --accent-ink: #fff; --accent-soft: #e3f1ec;
  --warn: #b54708; --warn-soft: #fef0c7; --bad: #b42318; --bad-soft: #fee4e2; --ok: #067647; --ok-soft: #dcfae6;
  --radius: 8px;
  font-family: "Segoe UI", Tahoma, system-ui, sans-serif; font-size: 14px; color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
.hidden { display: none !important; }
h1 { font-size: 20px; margin: 0 0 14px; }
h2 { font-size: 16px; margin: 18px 0 10px; }
h3 { font-size: 14px; margin: 12px 0 8px; color: var(--muted); }
.muted { color: var(--muted); }
.num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
[dir=rtl] .num { direction: ltr; text-align: start; }

/* layout */
.shell { display: flex; min-height: 100vh; }
.side { width: 200px; flex: none; background: #17202b; color: #cfd6e0; display: flex; flex-direction: column;
        padding: 14px 10px; gap: 2px; position: sticky; top: 0; height: 100vh; }
.side .brand { color: #fff; font-weight: 700; font-size: 15px; padding: 4px 10px 14px; }
.side a { color: inherit; text-decoration: none; padding: 9px 10px; border-radius: 6px; }
.side a:hover { background: #243140; color: #fff; }
.side a.active { background: #2c3c4f; color: #fff; }
.side a.primary { background: var(--accent); color: #fff; margin: 4px 0 8px; font-weight: 600; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 8px 6px; }
.side-foot select { background: #243140; color: #fff; border: 0; }
.side .link { color: #cfd6e0; }
.page { flex: 1; padding: 22px 26px 60px; min-width: 0; }

/* controls */
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea { border: 1px solid #cfd4dc; border-radius: 6px; padding: 6px 8px; background: #fff; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9ec5b8; outline-offset: 0; border-color: var(--accent); }
input[type=number] { text-align: end; }
input[type=checkbox] { width: 16px; height: 16px; }
button { border: 1px solid #cfd4dc; background: #fff; border-radius: 6px; padding: 6px 12px; cursor: pointer; }
button:hover { background: #f2f4f7; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--bad); border-color: #f1b5af; }
button.small { padding: 3px 8px; font-size: 12.5px; }
button.link { background: none; border: 0; padding: 0; text-decoration: underline; cursor: pointer; }
button:disabled { opacity: .5; cursor: default; }
.bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.bar .grow { flex: 1; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px 14px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
label.f > input, label.f > select, label.f > textarea { color: var(--ink); font-size: 14px; }
label.f.req > span::after { content: " *"; color: var(--bad); }
label.chk { display: inline-flex; gap: 6px; align-items: center; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }

/* tables */
table.t { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.t th { text-align: start; font-weight: 600; font-size: 12.5px; color: var(--muted); background: #f8f9fb; padding: 8px; border-bottom: 1px solid var(--line); }
table.t td { padding: 7px 8px; border-bottom: 1px solid #eef0f3; vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: #f6faf8; }
table.t tr.dim td { color: #98a2b3; }
.scroll { overflow: auto; }

/* badges & cards */
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; background: #eef0f3; white-space: nowrap; }
.b-preparing { background: #eef4ff; color: #3538cd; }
.b-sent { background: #fef6ee; color: #b93815; }
.b-delivered { background: var(--ok-soft); color: var(--ok); }
.b-cancelled { background: #f2f4f7; color: #667085; }
.b-returning { background: var(--warn-soft); color: var(--warn); }
.b-returned { background: var(--bad-soft); color: var(--bad); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 16px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.card .k { font-size: 12.5px; color: var(--muted); }
.card .v { font-size: 20px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
[dir=rtl] .card .v { direction: ltr; text-align: end; }
.card.good .v { color: var(--ok); }
.card.bad .v { color: var(--bad); }
.alert { border-radius: var(--radius); padding: 10px 12px; margin: 8px 0; }
.alert.warn { background: var(--warn-soft); color: #7a2e0e; }
.alert.bad { background: var(--bad-soft); color: #7a271a; }
.alert.ok { background: var(--ok-soft); color: #074d31; }

/* order form */
.order-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 14px; align-items: start; }
.order-lines td input { width: 100%; }
.order-lines .qty { width: 80px; }
.order-lines .money { width: 105px; }
.disc { display: flex; gap: 4px; }
.disc select { width: 76px; }
.disc input { width: 80px; }
.sumbox table { width: 100%; }
.sumbox td { padding: 4px 0; }
.sumbox tr.big td { font-weight: 700; font-size: 16px; border-top: 1px solid var(--line); padding-top: 8px; }
.picker { position: relative; }
.picker .list { position: absolute; inset-inline: 0; top: 100%; z-index: 20; background: #fff; border: 1px solid #cfd4dc;
                border-radius: 6px; max-height: 280px; overflow: auto; box-shadow: 0 8px 24px rgba(16,24,40,.12); }
.picker .list div { padding: 7px 10px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.picker .list div:hover, .picker .list div.hi { background: var(--accent-soft); }
.seg { display: inline-flex; border: 1px solid #cfd4dc; border-radius: 6px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; }
.seg button.on { background: var(--accent); color: #fff; }

/* modal & toast */
.modal { position: fixed; inset: 0; background: rgba(16,24,40,.45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow: auto; }
.modal-box { background: #fff; border-radius: 10px; padding: 18px 20px; width: min(760px, 100%); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal-box.wide { width: min(1000px, 100%); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.toast { position: fixed; bottom: 18px; inset-inline-start: 50%; transform: translateX(-50%); background: #17202b; color: #fff;
         padding: 10px 16px; border-radius: 8px; z-index: 60; max-width: 80vw; }
[dir=rtl] .toast { transform: translateX(50%); }
.toast.err { background: var(--bad); }

/* auth */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.auth .panel { width: 360px; display: flex; flex-direction: column; gap: 10px; }
.auth h1 { text-align: center; }

.side-top { display: flex; align-items: center; justify-content: space-between; }
.menu-btn { display: none; }

@media (max-width: 1100px) { .order-layout { grid-template-columns: minmax(0, 1fr); } }

/* phones: the side menu becomes a top bar with a ☰ button; tables scroll sideways */
@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .side { width: auto; height: auto; position: sticky; top: 0; z-index: 40; padding: 8px 10px; gap: 0; }
  .side .brand { padding: 6px 4px; }
  .menu-btn { display: block; background: #243140; color: #fff; border: 0; font-size: 20px; line-height: 1; padding: 8px 12px; }
  .menu-btn:hover { background: #2c3c4f; }
  .side > a, .side-foot { display: none; }
  .side.open { max-height: 100vh; overflow-y: auto; }
  .side.open > a { display: block; padding: 12px 10px; }
  .side.open .side-foot { display: flex; flex-direction: row; align-items: center; justify-content: space-between; margin-top: 6px; }
  .page { padding: 14px 12px 70px; }
  h1 { font-size: 18px; }
  .panel { padding: 12px; }
  /* 16px stops iPhone from zooming in on every field */
  input, select, textarea, label.f > input, label.f > select, label.f > textarea { font-size: 16px; }
  button { padding: 8px 12px; }
  .grid, .grid.two { grid-template-columns: minmax(0, 1fr); }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .card { padding: 10px; }
  .card .v { font-size: 17px; overflow-wrap: anywhere; }
  table.t { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }
  .bar > input, .bar > select, .bar > .grow { flex: 1 1 140px; }
  .bar > input.grow { flex-basis: 100%; } /* search box gets its own full row */
  .bar > span.grow { display: none; }
  .picker input, .picker > input { width: 100%; }
  .modal { padding: 0; align-items: stretch; }
  .modal-box, .modal-box.wide { width: 100%; min-height: 100%; border-radius: 0; padding: 14px 12px; }
  .modal-actions { position: sticky; bottom: 0; background: #fff; padding: 10px 0; margin-top: 10px; }
  .modal-actions button { flex: 1; }
  .auth { padding: 16px; }
  .auth .panel { width: 100%; max-width: 380px; }
  .toast { max-width: 92vw; }
  .muted, .panel p { overflow-wrap: anywhere; }
}
