/* ===================================================================
   Hafam Medical Store — one stylesheet.
   Tokens → base → layout → components → responsive → print → dark.
   =================================================================== */

/* ------------------------------------------------------------ tokens */
:root {
  /* brand */
  --teal-900: #0b2f37;
  --teal-800: #103c45;
  --teal-700: #0b544e;
  --teal-600: #0f766e;
  --teal-500: #12988c;
  --teal-300: #19b3a6;
  --teal-50:  #e9f6f4;

  /* surfaces + text */
  --bg:        #f1f6f7;
  --surface:   #ffffff;
  --surface-2: #f7fafb;
  --line:      #dde8ec;
  --line-2:    #eef4f6;
  --ink:       #13303a;
  --ink-2:     #41626d;
  --muted:     #7d969f;

  /* states */
  --good:   #146c37;
  --good-bg:#e7f6ed;
  --good-ln:#bfe3cd;
  --bad:    #b02a30;
  --bad-bg: #fdecec;
  --bad-ln: #f2c6c6;
  --warn:   #8a5300;
  --warn-bg:#fdf3e3;
  --warn-ln:#f0ddb9;

  /* shape + depth */
  --r-sm: 8px;
  --r:    12px;
  --r-lg: 16px;
  --shadow-1: 0 1px 2px rgba(15,40,50,.06);
  --shadow-2: 0 1px 2px rgba(15,40,50,.05), 0 10px 28px rgba(15,40,50,.07);
  --ring: 0 0 0 3px rgba(15,118,110,.26);

  --topbar-h: 60px;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

/* -------------------------------------------------------------- base */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }
html, body { overflow-x: clip; }   /* nothing may push the page sideways */

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
p { margin: 0; }
a { color: var(--teal-600); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { max-width: 100%; }

:where(a, button, input, select, textarea):focus-visible {
  outline: none;
  box-shadow: var(--ring);
  border-radius: var(--r-sm);
}

.sr, .skip:not(:focus) {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip:focus {
  position: fixed; top: 10px; left: 10px; z-index: 100;
  background: var(--surface); color: var(--ink);
  padding: 10px 16px; border-radius: var(--r-sm); box-shadow: var(--shadow-2);
}

.ic { width: 1.05em; height: 1.05em; flex: none; vertical-align: -.15em; }

/* ------------------------------------------------------------ topbar */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--teal-800);
  color: #fff;
  box-shadow: 0 1px 0 rgba(0,0,0,.15);
  padding-top: env(safe-area-inset-top);
}
.bar {
  max-width: 1180px; margin: 0 auto;
  min-height: var(--topbar-h);
  display: flex; align-items: center; gap: 18px;
  padding: 8px 20px;
}
.brand {
  display: flex; align-items: center; gap: 11px;
  color: #fff; text-decoration: none; font-weight: 700; font-size: 17px;
  margin-right: auto; min-width: 0;
}
.brand:hover { text-decoration: none; }
.brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mark {
  display: grid; place-items: center; flex: none;
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--teal-300); color: #04302c;
}
.mark .ic { width: 20px; height: 20px; stroke-width: 2.8; vertical-align: 0; }

.tabs { display: flex; gap: 6px; }
.tab {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 16px; border-radius: 9px; min-height: 40px;
  color: #c3dade; font-weight: 600; font-size: 15px; text-decoration: none;
  transition: background .12s ease, color .12s ease;
}
.tab:hover { background: rgba(255,255,255,.1); color: #fff; text-decoration: none; }
.tab.on { background: var(--teal-300); color: #04302c; }

.signout { display: flex; align-items: center; gap: 7px; color: #a8c7cd; font-size: 14.5px; }
.signout:hover { color: #fff; text-decoration: none; }

/* ------------------------------------------------------------ layout */
.wrap { max-width: 1180px; margin: 0 auto; padding: 22px 20px 48px; }
.wrap.msg { padding-bottom: 0; }

.cols {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
.sticky { position: sticky; top: calc(var(--topbar-h) + 16px); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
  padding: 20px;
}
.card h2 {
  display: flex; align-items: center; gap: 9px;
  font-size: 17px; padding-bottom: 14px; margin-bottom: 18px;
  border-bottom: 1px solid var(--line-2);
}
.card h2 .ic { color: var(--teal-600); width: 19px; height: 19px; }
.count {
  margin-left: auto; flex: none;
  background: var(--teal-50); color: var(--teal-700);
  font-size: 13px; font-weight: 700; padding: 2px 11px; border-radius: 999px;
}

.foot {
  max-width: 1180px; margin: 0 auto;
  padding: 0 20px 34px;
  color: var(--muted); font-size: 13px;
  display: flex; gap: 8px; justify-content: center;
}
.foot .dot { opacity: .6; }

/* ------------------------------------------------------------- forms */
.field { margin-bottom: 16px; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
label { display: block; font-size: 13.5px; font-weight: 650; color: var(--ink-2); margin-bottom: 6px; }

input, select {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font: inherit; font-size: 16px;
  transition: border-color .12s ease, box-shadow .12s ease;
}
input:hover, select:hover { border-color: #c5d8de; }
input::placeholder { color: #a9bcc3; }
input[type="date"] { min-height: 46px; }

select {
  appearance: none; padding-right: 36px; cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8'><path d='M1 1l5 5 5-5' fill='none' stroke='%237d969f' stroke-width='1.9' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat; background-position: right 13px center;
}

/* ----------------------------------------- search-as-you-type box */
.combo { position: relative; }
.combo .combo-input { padding-right: 38px; margin-bottom: 0; }   /* keep the box tight,
     so the list below it starts exactly at its bottom edge and covers nothing */
.combo-clear {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  width: 28px; height: 28px; display: grid; place-items: center;
  border: 0; border-radius: 7px; background: transparent;
  color: var(--muted); font-size: 20px; line-height: 1; cursor: pointer;
}
.combo-clear:hover { background: var(--surface-2); color: var(--bad); }

.combo-list {
  position: absolute; z-index: 40; left: 0; right: 0; top: calc(100% + 5px);
  margin: 0; padding: 4px; list-style: none;
  max-height: 290px; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: var(--shadow-2);
}
.combo-item {
  display: flex; align-items: baseline; gap: 10px;
  padding: 9px 11px; border-radius: 8px; cursor: pointer;
}
.combo-item.on { background: var(--teal-50); }
.combo-item .combo-name { flex: 1; min-width: 0; font-size: 15px; }
.combo-item .combo-price {
  flex: none; font-size: 14px; font-weight: 700; color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.combo-item mark { background: #ffe9a8; color: inherit; border-radius: 3px; padding: 0 1px; }
.combo-none { padding: 11px; color: var(--muted); font-size: 14px; text-align: center; }

.field-error {
  margin: -8px 0 12px; color: var(--bad); font-size: 13.5px; font-weight: 600;
}

/* a currency sign sitting inside the box */
.prefixed { position: relative; }
.prefixed .prefix {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-weight: 600; pointer-events: none;
}
.prefixed input { padding-left: 32px; }

.actions { display: flex; gap: 10px; align-items: center; }
.actions .btn-main { flex: 1; }

/* an inline icon, not a flex row — otherwise every <strong> inside the
   sentence becomes its own flex item and the text breaks into columns */
.hint {
  font-size: 13px; color: var(--muted); margin-top: 14px; line-height: 1.55;
}
.hint .ic { width: 15px; height: 15px; margin-right: 5px; vertical-align: -3px; color: inherit; }
.hint.warn { color: var(--warn); }
.hint input[type=checkbox] { margin-right: 6px; vertical-align: -2px; }
.hint strong { color: inherit; }

.inline { display: inline; }

/* ----------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 11px 17px;
  border: 1px solid transparent; border-radius: 10px;
  background: #e9eff1; color: var(--ink);
  font: inherit; font-size: 15px; font-weight: 650;
  cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .12s ease, border-color .12s ease, color .12s ease, transform .06s ease;
}
.btn:hover { background: #dee6e9; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn.busy { opacity: .6; pointer-events: none; }
.btn.off { opacity: .4; pointer-events: none; cursor: default; }

.btn-main { background: var(--teal-600); color: #fff; }
.btn-main:hover { background: var(--teal-700); }
.btn-big { min-height: 52px; font-size: 16.5px; width: 100%; }
.btn-plain { background: var(--surface); border-color: var(--line); color: var(--ink-2); }
.btn-plain:hover { background: var(--surface-2); color: var(--ink); border-color: #c5d8de; }
.btn-sm { min-height: 36px; padding: 7px 12px; font-size: 13.5px; border-radius: 9px; }
.btn-bad:hover { color: var(--bad); border-color: var(--bad-ln); background: var(--bad-bg); }

.chip {
  min-height: 34px; padding: 5px 13px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--ink-2);
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
}
.chip:hover { border-color: var(--teal-500); color: var(--teal-700); background: var(--teal-50); }
.quickqty { display: flex; gap: 7px; flex-wrap: wrap; margin: -4px 0 16px; }

/* ----------------------------------------------------------- toolbar */
.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 18px;
}
.searchbox { position: relative; flex: 1 1 190px; min-width: 0; }
.searchbox > .ic {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; color: var(--muted); pointer-events: none;
}
.searchbox input { padding-left: 38px; padding-right: 38px; }
.searchbox input::-webkit-search-cancel-button { display: none; }
.searchbox .clear {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  display: grid; place-items: center; width: 28px; height: 28px;
  border-radius: 7px; color: var(--muted);
}
.searchbox .clear:hover { background: var(--surface-2); color: var(--bad); }

/* day / month / year / range switcher */
.viewtabs {
  display: inline-flex; padding: 3px; margin-bottom: 14px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
}
.vt {
  padding: 7px 15px; border-radius: 8px; min-height: 34px;
  display: inline-flex; align-items: center;
  color: var(--ink-2); font-size: 14px; font-weight: 650; text-decoration: none;
}
.vt:hover { color: var(--teal-700); text-decoration: none; }
.vt.on { background: var(--surface); color: var(--teal-700); box-shadow: var(--shadow-1); }

.periodpick { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.periodpick input, .periodpick select { width: auto; min-width: 140px; }
.periodpick select { min-width: 110px; }
.periodpick .to { color: var(--muted); font-size: 13.5px; }

/* the day-by-day / month-by-month summary */
.breakdown { margin-bottom: 18px; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.breakdown > summary {
  padding: 11px 14px; cursor: pointer; background: var(--surface-2);
  font-size: 14px; font-weight: 650; color: var(--ink-2); list-style: none;
}
.breakdown > summary::-webkit-details-marker { display: none; }
.breakdown > summary::before { content: "▸ "; color: var(--muted); }
.breakdown[open] > summary::before { content: "▾ "; }
.breakdown > summary:hover { color: var(--teal-700); }
.breakdown .scroll { padding: 0 14px 10px; }
table.compact th, table.compact td { padding: 8px 8px; font-size: 14px; }
table.compact tbody tr:hover { background: transparent; }

.perpage { display: flex; align-items: center; gap: 7px; margin: 0; white-space: nowrap; }
.perpage span { font-size: 13px; font-weight: 650; color: var(--muted); }
.perpage select { width: auto; min-width: 74px; padding: 8px 32px 8px 11px; font-size: 14px; min-height: 36px; }

.js .only-nojs { display: none; }   /* only needed when JS cannot auto-apply */

/* ------------------------------------------------------------- stats */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--r); padding: 13px 15px;
}
.stat span {
  display: block; font-size: 12px; font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase; color: var(--muted);
}
.stat strong {
  display: block; margin-top: 4px; overflow-wrap: anywhere;
  font-size: clamp(20px, 2.4vw, 25px); font-weight: 800;
  font-variant-numeric: tabular-nums; letter-spacing: -.02em;
}
.stat:first-child strong { color: var(--teal-600); }
.stat small { display: block; margin-top: 2px; color: var(--muted); font-size: 12.5px; }

/* best sellers */
.best {
  list-style: none; margin: 0 0 18px; padding: 0;
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px;
}
.best li {
  display: flex; align-items: center; gap: 10px; min-width: 0;
  padding: 8px 12px; background: var(--surface-2);
  border: 1px solid var(--line-2); border-radius: 10px; font-size: 14px;
}
.best .rank {
  display: grid; place-items: center; flex: none; width: 21px; height: 21px;
  border-radius: 50%; background: var(--teal-50); color: var(--teal-700);
  font-size: 11.5px; font-weight: 800;
}
.best .bname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.best .bqty { color: var(--muted); font-size: 13px; }
.best .btot { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ tables */
.scroll { overflow-x: auto; margin: 0 -2px; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: 15px; }
table.data th, table.data td { padding: 12px 10px; text-align: left; border-bottom: 1px solid var(--line-2); }
table.data thead th {
  font-size: 11.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); border-bottom: 1px solid var(--line); white-space: nowrap;
  padding-top: 0;
}
table.data tbody tr { transition: background .1s ease; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr.editing { background: var(--teal-50); box-shadow: inset 3px 0 0 var(--teal-500); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tfoot td {
  font-weight: 700; border-top: 2px solid var(--line); border-bottom: 0;
  background: var(--surface-2); padding-top: 13px; padding-bottom: 13px;
}
.tfoot-label { color: var(--ink-2); }
.right { text-align: right; }
.money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.strong { font-weight: 700; }
.dim { color: var(--muted); font-size: 14px; }
.nowrap { white-space: nowrap; }
.name { font-weight: 600; }
.meta { display: block; font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.rowacts { display: inline-flex; gap: 6px; justify-content: flex-end; }

.sorter { display: inline-flex; align-items: center; gap: 4px; color: inherit; }
.sorter:hover { color: var(--teal-600); text-decoration: none; }
.sorter .ic { width: 14px; height: 14px; stroke-width: 2.6; }
.sorter.on { color: var(--teal-600); }

.tablefoot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; padding-top: 16px; margin-top: 4px;
  border-top: 1px solid var(--line-2);
}
.showing { font-size: 13.5px; color: var(--muted); }
.showing strong { color: var(--ink-2); }

/* --------------------------------------------------------- paginator */
.pager { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.pg {
  display: grid; place-items: center;
  min-width: 38px; height: 38px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 9px;
  background: var(--surface); color: var(--ink-2);
  font-size: 14px; font-weight: 650; font-variant-numeric: tabular-nums;
}
.pg:hover { border-color: var(--teal-500); color: var(--teal-700); background: var(--teal-50); text-decoration: none; }
.pg.on { background: var(--teal-600); border-color: var(--teal-600); color: #fff; }
.pg.off { opacity: .35; }
.pg .ic { width: 16px; height: 16px; }
.gap { color: var(--muted); padding: 0 2px; }

/* ------------------------------------------------------------ states */
.empty { text-align: center; padding: 34px 16px; color: var(--muted); }
.empty > .ic { width: 34px; height: 34px; color: #c3d6dc; stroke-width: 1.5; margin-bottom: 10px; }
.empty p { margin-bottom: 14px; font-size: 15px; }
.empty p:last-child { margin-bottom: 0; }
.empty .sub { font-size: 13.5px; }
.empty strong { color: var(--ink-2); }

.note {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border: 1px solid; border-radius: var(--r);
  font-size: 15px; margin-bottom: 18px;
  animation: drop .18s ease-out;
}
.note span { flex: 1; }
p.note { margin: 0 0 16px; }
.note .x {
  display: grid; place-items: center; flex: none;
  width: 28px; height: 28px; border: 0; border-radius: 7px;
  background: transparent; color: inherit; opacity: .6; cursor: pointer;
}
.note .x:hover { opacity: 1; background: rgba(0,0,0,.06); }
.note-good { background: var(--good-bg); border-color: var(--good-ln); color: var(--good); }
.note-bad  { background: var(--bad-bg);  border-color: var(--bad-ln);  color: var(--bad); }
@keyframes drop { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

.bigtotal {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px; min-width: 0;
  background: var(--teal-50); border: 1px solid #cce7e3;
  border-radius: var(--r); padding: 14px 16px; margin-bottom: 16px;
}
.bigtotal span { color: var(--ink-2); font-weight: 650; font-size: 14px; }
.bigtotal strong {
  font-size: clamp(24px, 4vw, 29px); font-weight: 800; color: var(--teal-600);
  font-variant-numeric: tabular-nums; letter-spacing: -.02em;
}

/* ----------------------------------------------- the "are you sure" box */
dialog.ask {
  width: min(430px, calc(100vw - 32px));
  padding: 0; border: 1px solid var(--line); border-radius: var(--r-lg);
  background: var(--surface); color: var(--ink);
  box-shadow: 0 24px 60px rgba(10,30,38,.3);
}
dialog.ask::backdrop { background: rgba(9,28,34,.55); backdrop-filter: blur(2px); }
dialog.ask form { padding: 22px; margin: 0; }
.ask-title { font-size: 18px; margin: 0 0 8px; }
.ask-detail { color: var(--ink-2); font-size: 14.5px; line-height: 1.5; margin: 0; }
.ask-buttons { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }
.ask-buttons .btn { min-width: 108px; }
.btn-danger { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn-danger:hover { background: #8e2126; }

dialog.ask[open] { animation: askIn .14s ease-out; }
@keyframes askIn { from { opacity: 0; transform: translateY(-8px) scale(.98); } to { opacity: 1; transform: none; } }

@media (max-width: 420px) {
  .ask-buttons { flex-direction: column-reverse; }
  .ask-buttons .btn { width: 100%; }
}

/* ----------------------------------------------------------- sign in */
.signin {
  display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; padding: 20px;
  background: linear-gradient(145deg, var(--teal-800), var(--teal-900) 55%, #12454f);
}
.login { width: 100%; max-width: 380px; text-align: center; }
.login .mark { width: 56px; height: 56px; margin: 0 auto 16px; border-radius: 16px; }
.login .mark .ic { width: 32px; height: 32px; }
.login h1 { font-size: 21px; }
.login .sub { color: var(--muted); font-size: 14px; margin: 5px 0 22px; }
.login label { text-align: left; }
.login .btn { margin-top: 6px; }
.login .note { text-align: left; font-size: 14px; }

/* ------------------------------------------------------- responsive */
.printonly { display: none; }

@media (max-width: 1040px) {
  .cols { grid-template-columns: minmax(0, 1fr); }
  .sticky { position: static; }
  .only-wide { display: none; }
}

@media (max-width: 860px) {
  .bar { gap: 12px; padding: 8px 14px; flex-wrap: wrap; }
  .brand { font-size: 16px; }
  .tabs { order: 3; width: 100%; gap: 6px; }
  .tab { flex: 1; justify-content: center; }
  .signout span { display: none; }
  .wrap { padding: 16px 14px 40px; }
  .card { padding: 16px; border-radius: var(--r); }
  .sticky { top: 0; }
}

@media (max-width: 900px) { .hide-sm { display: none; } }

/* narrow phones: each table row becomes its own small card */
@media (max-width: 700px) {
  table.data thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.data, table.data tbody, table.data tfoot, table.data tr, table.data td { display: block; width: 100%; }
  table.data tr {
    border: 1px solid var(--line); border-radius: var(--r);
    padding: 10px 13px; margin-bottom: 10px; background: var(--surface);
  }
  table.data tr:hover { background: var(--surface); }
  table.data td {
    display: flex; align-items: center; justify-content: space-between; gap: 14px;
    padding: 5px 0; border: 0; text-align: right; min-width: 0;
  }
  table.data td > * { min-width: 0; overflow-wrap: anywhere; }
  table.data td::before {
    content: attr(data-label);
    flex: none; color: var(--muted); font-size: 12.5px; font-weight: 650;
    text-transform: uppercase; letter-spacing: .04em;
  }
  table.data td[data-label=""]::before { content: none; }
  table.data td .name, table.data td.dim { text-align: right; }
  table.data .hide-sm { display: flex; }
  table.data tfoot tr { background: var(--surface-2); border-color: var(--line); }
  table.data tfoot .tfoot-label { font-size: 13px; color: var(--muted); }
  .scroll { overflow: visible; margin: 0; }
  .rowacts { width: 100%; justify-content: flex-end; }
  .rowacts .btn { min-height: 40px; }
  .tablefoot { justify-content: center; }
  .stats { gap: 10px; }
  .toolbar { gap: 8px; }
  .periodpick { flex: 1 1 100%; }
  .periodpick input, .periodpick select { flex: 1; min-width: 0; }
  .periodpick .to { flex: none; }
  .viewtabs { display: flex; width: 100%; }
  .vt { flex: 1; justify-content: center; padding: 8px 6px; }
  .breakdown .scroll { padding: 0 10px 10px; }
  .searchbox { flex: 1 1 100%; }
  .perpage { margin-left: auto; }
}

/* big numbers need the full width before the small inputs do */
@media (max-width: 400px) {
  .stats { grid-template-columns: minmax(0, 1fr); }
  .brand-name { font-size: 15px; }
  .tab span { font-size: 14px; }
  .wrap { padding: 14px 11px 36px; }
}

/* two date boxes plus two arrows will not fit a narrow phone in one line */
@media (max-width: 440px) {
  .periodpick input[type="date"] { flex: 1 1 100%; min-width: 0; }
  .periodpick .to { width: 100%; text-align: center; margin: -2px 0; }
}

@media (max-width: 700px) {
  .combo-list { max-height: 54vh; }
}

@media (max-width: 345px) {
  .field-row { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ------------------------------------------------------------- print */
@media print {
  .topbar, .toolbar, .viewtabs, .no-print, .foot, .skip, .best, .tablefoot, .note { display: none !important; }
  .breakdown { border-color: #999; }
  .breakdown > summary { display: none; }
  .breakdown[open] .scroll, .breakdown .scroll { display: block; padding: 0; }
  body { background: #fff; font-size: 12pt; }
  .wrap { max-width: none; padding: 0; display: block; }
  .cols { display: block; }
  .card { border: 0; box-shadow: none; padding: 0; }
  .card h2 { border-bottom: 1px solid #000; }
  .printonly { display: block; }
  .printhead { margin: 0 0 14px; font-size: 11pt; color: #000; }
  .printhead strong { font-size: 13pt; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat { border: 1px solid #999; }
  table.data { font-size: 11pt; }
  table.data th, table.data td { border-bottom: 1px solid #ccc; }
  tr { page-break-inside: avoid; }
}

/* -------------------------------------------------------- dark mode */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0e1a1f;
    --surface:   #152a31;
    --surface-2: #1a333b;
    --line:      #27454f;
    --line-2:    #1f3a43;
    --ink:       #e6f1f4;
    --ink-2:     #b3cbd2;
    --muted:     #85a3ac;
    --teal-50:   #15393a;
    --teal-600:  #2bb5a5;
    --teal-700:  #4fcabb;
    --good:   #74d79b; --good-bg: #16352a; --good-ln: #27543d;
    --bad:    #ff9a9a; --bad-bg:  #3a1f21; --bad-ln:  #5e2f32;
    --warn:   #f0c070; --warn-bg: #3a2e18; --warn-ln: #5c4824;
    --shadow-1: 0 1px 2px rgba(0,0,0,.4);
    --shadow-2: 0 1px 2px rgba(0,0,0,.35), 0 10px 28px rgba(0,0,0,.3);
    --ring: 0 0 0 3px rgba(43,181,165,.35);
  }
  .btn { background: #22414a; color: var(--ink); }
  .btn:hover { background: #2a4e58; }
  .btn-main { background: var(--teal-600); color: #04302c; }
  .btn-main:hover { background: var(--teal-700); }
  .btn-plain { background: var(--surface); border-color: var(--line); }
  .btn-plain:hover { background: var(--surface-2); }
  .chip { background: var(--surface); }
  .mark { background: var(--teal-300); }
  .bigtotal { background: #14343a; border-color: #255a56; }
  .bigtotal strong { color: var(--teal-700); }
  .count { background: #14343a; color: var(--teal-700); }
  .empty > .ic { color: #35606c; }
  input, select { background: #102229; }
  input:hover, select:hover { border-color: #38606c; }
  .pg.on { color: #04302c; }
  .note .x:hover { background: rgba(255,255,255,.1); }
  table.data tbody tr.editing { background: #14343a; }
  .combo-item.on { background: #14343a; }
  dialog.ask::backdrop { background: rgba(0,0,0,.66); }
  .btn-danger { background: #c2454a; color: #fff; border-color: #c2454a; }
  .btn-danger:hover { background: #d2555a; }
  .combo-item mark { background: #6b5a1f; color: #ffe9a8; }
  .combo-clear:hover { background: #22414a; }
}
