/* ==========================================================================
   Galaxy POS Web Reporting - design system (single stylesheet)
   1. Tokens  2. Base  3. Layout  4. Navigation  5. Page header  6. Cards & KPIs
   7. Tables  8. Lists & groups  9. Forms & buttons  10. Feedback  11. Auth
   12. Dashboard  13. Utilities  14. Responsive  15. Print
   ========================================================================== */

/* 1. Tokens ---------------------------------------------------------------- */
:root {
  /* colour: navigation (deep navy) */
  --navy-950: #0a1626;
  --navy-900: #0f2237;
  --navy-800: #16304d;
  --navy-700: #1f4166;
  --nav-text: #c3d0e0;
  --nav-muted: #8398b1;

  /* colour: brand (emerald / teal) */
  --brand-50: #e8f6f3;
  --brand-100: #c9ece6;
  --brand-500: #0f9b88;
  --brand-600: #0b7f70;
  --brand-700: #096b5e;

  /* colour: surfaces and text */
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --text: #0f1f33;
  --muted: #526276;
  --faint: #5a6a7e;

  /* colour: status */
  --ok: #166534;
  --ok-bg: #e7f6ec;
  --warn: #b45309;
  --warn-bg: #fdf3e0;
  --danger: #b91c1c;
  --danger-bg: #fdeaea;
  --info: #1d4ed8;
  --info-bg: #e8effd;

  /* colour: chart palette (read by assets/pws.js) */
  --c1: #0f9b88;
  --c2: #1f4166;
  --c3: #d97706;
  --c4: #6366f1;
  --c5: #e11d48;
  --c6: #64748b;
  --c7: #0284c7;
  --c8: #a855f7;

  /* typography */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-md: 14px;
  --fs-lg: 16px;
  --fs-xl: 20px;
  --fs-2xl: 26px;

  /* spacing (4px scale) */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 20px;
  --s6: 24px;
  --s8: 32px;

  /* shape and depth */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 31, 51, .06);
  --shadow: 0 1px 3px rgba(15, 31, 51, .08), 0 4px 12px rgba(15, 31, 51, .04);

  --sidebar-w: 248px;
  --topbar-h: 56px;
}

/* 2. Base ------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 600; }
p { margin: 0; }
a { color: var(--brand-600); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--brand-600); outline-offset: 2px; }
.i { width: 1em; height: 1em; fill: currentColor; flex: none; vertical-align: -0.125em; }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 8px; top: -48px; z-index: 100;
  background: var(--brand-600); color: #fff; padding: 8px 12px; border-radius: var(--radius-sm);
}
.skip-link:focus { top: 8px; text-decoration: none; }

/* 3. Layout ---------------------------------------------------------------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 40;
  width: var(--sidebar-w);
  display: flex; flex-direction: column;
  background: var(--navy-900); color: var(--nav-text);
  overflow: hidden;
}
.main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: var(--s3);
  padding: 0 var(--s6);
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar__title { font-size: var(--fs-lg); font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar__spacer { flex: 1; }
.userbox { display: flex; align-items: center; gap: var(--s2); color: var(--muted); font-size: var(--fs-sm); }
.userbox__avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--brand-50); color: var(--brand-700);
}
.menu-btn {
  display: none; align-items: center; justify-content: center;
  width: 36px; height: 36px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); cursor: pointer;
}
.backdrop { position: fixed; inset: 0; z-index: 35; background: rgba(10, 22, 38, .5); }
.content { width: 100%; max-width: 1240px; margin: 0 auto; padding: var(--s6); flex: 1; }
.app-footer { padding: var(--s4) var(--s6); color: var(--faint); font-size: var(--fs-xs); border-top: 1px solid var(--line); background: var(--surface); }

/* 4. Navigation ------------------------------------------------------------ */
.brand {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s5) var(--s5) var(--s4);
  color: #fff; text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand__mark {
  width: 36px; height: 36px; border-radius: var(--radius); overflow: hidden; flex: none;
  display: grid; place-items: center; background: #fff; padding: 3px;
}
.brand__mark img { display: block; width: 100%; height: 100%; object-fit: contain; }
.brand__name { font-weight: 700; font-size: var(--fs-lg); line-height: 1.1; }
.brand__sub { font-size: var(--fs-xs); color: var(--nav-muted); font-weight: 400; }
.nav { padding: 0 var(--s3) var(--s3); flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .2) transparent; }
.nav__label {
  padding: var(--s4) var(--s3) var(--s2);
  font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--nav-muted); font-weight: 600;
}
.nav__link {
  display: flex; align-items: center; gap: var(--s3);
  padding: 8px var(--s3); margin: 1px 0;
  border-radius: var(--radius-sm); color: var(--nav-text);
  font-size: var(--fs-md); font-weight: 500; text-decoration: none;
}
.nav__link:hover { background: rgba(255, 255, 255, .07); color: #fff; text-decoration: none; }
.nav__link .i { font-size: 16px; opacity: .85; }
.nav__link.is-active { background: var(--brand-600); color: #fff; }
.nav__link.is-active .i { opacity: 1; }
.nav__branch {
  margin: var(--s2) var(--s3) var(--s2); padding: var(--s3);
  border-radius: var(--radius); background: rgba(255, 255, 255, .06);
}
.nav__branch-name { color: #fff; font-weight: 600; font-size: var(--fs-md); overflow-wrap: anywhere; }
.nav__branch-sync { color: var(--nav-muted); font-size: var(--fs-xs); margin-top: 2px; }
.nav__foot { padding: var(--s3); border-top: 1px solid rgba(255, 255, 255, .08); }
.sidebar :focus-visible { outline-color: #fff; }

/* 5. Page header ----------------------------------------------------------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s5); }
.page-head h1 { font-size: var(--fs-xl); letter-spacing: -.01em; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--faint); margin-bottom: 6px; }
.crumbs a { color: var(--faint); }
.crumbs a:hover { color: var(--brand-600); }
.crumbs .i { font-size: 10px; }
.context { display: flex; flex-wrap: wrap; gap: var(--s2); }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  font-size: var(--fs-xs); color: var(--muted); font-weight: 500; white-space: nowrap;
}
.chip .i { color: var(--brand-600); }
.chip--ok { background: var(--ok-bg); border-color: transparent; color: var(--ok); }
.chip--ok .i { color: var(--ok); }
.chip--warn { background: var(--warn-bg); border-color: transparent; color: var(--warn); }
.chip--warn .i { color: var(--warn); }

/* 6. Cards & KPIs ---------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.content > .card, .content > .cols-2, .content > .record-grid, .content > .report-grid, .content > .branch-grid { margin-bottom: var(--s4); }
.card__head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); }
.card__title { font-size: var(--fs-md); font-weight: 600; }
.card__sub { font-size: var(--fs-xs); color: var(--faint); }
.card__body { padding: var(--s4); }
.card--flush .card__body { padding: 0; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--s4); margin-bottom: var(--s4); }
.kpi { padding: var(--s4); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.kpi__label { font-size: var(--fs-xs); color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi__value { margin-top: 6px; font-size: var(--fs-2xl); font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi__sub { margin-top: 2px; font-size: var(--fs-xs); color: var(--faint); }
.kpi--primary { background: var(--navy-900); border-color: var(--navy-900); }
.kpi--primary .kpi__label, .kpi--primary .kpi__sub { color: var(--nav-text); }
.kpi--primary .kpi__value { color: #fff; }
.kpi--danger .kpi__value { color: var(--danger); }
.cols-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s4); align-items: start; }
.cols-2 > .card + .card { margin-top: 0; }
.rs { font-weight: 500; opacity: .75; margin-right: 1px; }

/* 7. Tables ---------------------------------------------------------------- */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table caption { text-align: left; padding: var(--s3) var(--s4); font-size: var(--fs-md); font-weight: 600; caption-side: top; }
.table th {
  padding: 9px var(--s3); text-align: left; white-space: nowrap;
  font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); background: var(--surface-2); border-bottom: 1px solid var(--line-strong);
}
.table td { padding: 8px var(--s3); border-bottom: 1px solid var(--line); vertical-align: top; }
.table tbody tr:hover td { background: var(--surface-2); }
.table th:first-child, .table td:first-child { padding-left: var(--s4); }
.table th:last-child, .table td:last-child { padding-right: var(--s4); }
.num, .table th.num, .table td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tfoot td, .table .total td { font-weight: 700; background: var(--surface-2); border-top: 2px solid var(--line-strong); border-bottom: 0; }
.table .note td { color: var(--danger); font-size: var(--fs-xs); border-bottom: 1px solid var(--line); }
.table--kv td:last-child { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table--kv td:first-child { color: var(--muted); }
.table--kv tr.strong td { font-weight: 700; color: var(--text); }
.table--kv tr.strong td:first-child { color: var(--text); }
.pos { color: var(--ok); }
.neg { color: var(--danger); }

/* 8. Lists & expandable groups -------------------------------------------- */
.group { border-bottom: 1px solid var(--line); }
.group:last-child { border-bottom: 0; }
.group > summary {
  display: grid; grid-template-columns: var(--cols, 18px minmax(0, 1fr) auto auto); align-items: center; gap: var(--s3);
  padding: 10px var(--s4); cursor: pointer; list-style: none; font-size: var(--fs-sm); font-weight: 500;
}
.group > summary::-webkit-details-marker { display: none; }
.group > summary:hover { background: var(--surface-2); }
.group > summary .i { font-size: 11px; color: var(--faint); transition: transform .15s; }
.group[open] > summary .i { transform: rotate(90deg); }
.group[open] > summary { background: var(--surface-2); }
.group-cols { display: grid; grid-template-columns: var(--cols, 18px minmax(0, 1fr) auto auto); gap: var(--s3); padding: 8px var(--s4); background: var(--surface-2); border-bottom: 1px solid var(--line-strong); font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.group-cols .num { text-align: right; }
.group__qty { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.group__amt { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; min-width: 90px; }
.group__body { padding: 0 var(--s4) var(--s3) calc(var(--s4) + 18px + var(--s3)); background: var(--surface-2); }
.group__body .table th { background: transparent; }
.group__body .table td { border-bottom-color: var(--line); }
.record-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--s4); }
.record { padding: var(--s4); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.record + .record { margin-top: 0; }
.record__head { display: flex; justify-content: space-between; gap: var(--s3); font-weight: 600; margin-bottom: var(--s2); }
.record__row { display: flex; justify-content: space-between; gap: var(--s3); padding: 3px 0; font-size: var(--fs-sm); }
.record__k { color: var(--faint); }
.record__v { text-align: right; font-weight: 500; overflow-wrap: anywhere; }
.record__note { margin-top: var(--s2); padding-top: var(--s2); border-top: 1px dashed var(--line-strong); font-size: var(--fs-sm); color: var(--muted); overflow-wrap: anywhere; }

/* 9. Forms & buttons ------------------------------------------------------- */
.filter-bar {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--s3);
  padding: var(--s3) var(--s4); margin-bottom: var(--s4);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label, .label { font-size: var(--fs-xs); font-weight: 600; color: var(--muted); }
.input {
  width: 100%; height: 38px; padding: 0 var(--s3);
  font: inherit; font-size: var(--fs-md); color: var(--text);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
}
.input:hover { border-color: var(--faint); }
.input:focus-visible { outline: 2px solid var(--brand-600); outline-offset: 0; border-color: var(--brand-600); }
.input[disabled] { background: var(--surface-2); color: var(--muted); }
.input-icon { position: relative; }
.input-icon .i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--faint); font-size: 14px; }
.input-icon .input { padding-left: 36px; }
.field__error { color: var(--danger); font-size: var(--fs-xs); min-height: 1em; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  height: 38px; padding: 0 var(--s4);
  font: inherit; font-size: var(--fs-md); font-weight: 600; line-height: 1;
  border: 1px solid transparent; border-radius: var(--radius-sm); cursor: pointer; text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn--primary { background: var(--brand-600); color: #fff; }
.btn--primary:hover { background: var(--brand-700); }
.btn--ghost { background: var(--surface); color: var(--text); border-color: var(--line-strong); }
.btn--ghost:hover { background: var(--surface-2); }
.btn--block { width: 100%; }
.btn--sm { height: 32px; padding: 0 var(--s3); font-size: var(--fs-sm); }
.check-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: var(--s2); }
.check {
  display: flex; align-items: center; gap: var(--s3);
  padding: 10px var(--s3); border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer;
}
.check:hover { border-color: var(--brand-500); }
.check input { width: 18px; height: 18px; accent-color: var(--brand-600); }
.check .i { color: var(--brand-600); font-size: 16px; }
.form-actions { display: flex; gap: var(--s3); margin-top: var(--s5); flex-wrap: wrap; }
.report-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--s3); }
.report-tile {
  display: flex; align-items: center; gap: var(--s3);
  width: 100%; padding: var(--s4); text-align: left;
  font: inherit; font-size: var(--fs-md); font-weight: 600; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); cursor: pointer;
}
.report-tile:hover { text-decoration: none; border-color: var(--brand-500); box-shadow: var(--shadow); }
.report-tile__icon { width: 38px; height: 38px; border-radius: var(--radius-sm); display: grid; place-items: center; background: var(--brand-50); color: var(--brand-700); font-size: 17px; flex: none; }

/* 10. Feedback ------------------------------------------------------------- */
.alert { display: flex; gap: var(--s3); align-items: flex-start; padding: var(--s3) var(--s4); border-radius: var(--radius-sm); font-size: var(--fs-sm); border: 1px solid transparent; margin-bottom: var(--s4); }
.alert .i { margin-top: 2px; }
.alert--error { background: var(--danger-bg); color: var(--danger); border-color: #f5c2c2; }
.alert--ok { background: var(--ok-bg); color: var(--ok); border-color: #bfe3cb; }
.alert--info { background: var(--info-bg); color: var(--info); border-color: #c4d6f8; }
.empty { padding: var(--s8) var(--s4); text-align: center; color: var(--muted); }
.empty .i { font-size: 28px; color: var(--line-strong); margin-bottom: var(--s2); }
.empty__title { font-weight: 600; color: var(--text); font-size: var(--fs-md); }
.empty__text { font-size: var(--fs-sm); margin-top: 2px; }

/* 11. Auth ----------------------------------------------------------------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); background: var(--surface); }
.auth__brand {
  display: flex; flex-direction: column; justify-content: center; gap: var(--s4);
  padding: var(--s8) 56px; color: #fff; background: var(--navy-900);
}
.auth__brand .brand__mark { width: 48px; height: 48px; font-size: 24px; }
.auth__brand h1 { font-size: 30px; letter-spacing: -.02em; }
.auth__brand p { color: var(--nav-text); max-width: 34ch; font-size: var(--fs-lg); }
.auth__panel { display: flex; align-items: center; justify-content: center; padding: var(--s8) var(--s6); background: var(--bg); }
.auth__card { width: 100%; max-width: 400px; padding: var(--s8); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.auth__card h2 { font-size: var(--fs-xl); margin-bottom: 4px; }
.auth__card .muted { margin-bottom: var(--s5); }
.stack > * + * { margin-top: var(--s4); }

/* 12. Dashboard ------------------------------------------------------------ */
.branch-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: var(--s4); align-items: start; }
.branch-card .card__head { padding: var(--s4); }
.branch-card__name { font-size: var(--fs-lg); font-weight: 700; overflow-wrap: anywhere; }
.branch-card__body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--s4); padding: var(--s4); align-items: center; }
.chart-box { position: relative; height: 260px; }
.chart-box--lg { height: 320px; }
.metric-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: var(--s3); padding: var(--s4); }
.metric { padding: var(--s3); background: var(--surface-2); border-radius: var(--radius-sm); }
.metric__k { display: block; font-size: var(--fs-xs); color: var(--faint); }
.metric__v { font-weight: 700; font-variant-numeric: tabular-nums; font-size: var(--fs-md); }
.metric--primary { background: var(--navy-900); }
.metric--primary .metric__k { color: var(--nav-text); }
.metric--primary .metric__v { color: #fff; }
.legend-list { list-style: none; margin: 0; padding: 0; }
.legend-list li { display: flex; align-items: center; gap: var(--s2); padding: 5px 0; font-size: var(--fs-sm); border-bottom: 1px solid var(--line); }
.legend-list li:last-child { border-bottom: 0; }
.legend-list .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend-list .k { flex: 1; color: var(--muted); }
.legend-list .v { font-weight: 600; font-variant-numeric: tabular-nums; }

/* 13. Utilities ------------------------------------------------------------ */
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.flex { display: flex; align-items: center; gap: var(--s2); }

/* 14. Responsive ----------------------------------------------------------- */
@media (max-width: 991px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: none; }
  .sidebar.is-open { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .35); }
  .main { margin-left: 0; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 0 var(--s4); }
  .content { padding: var(--s4); }
  .cols-2 { grid-template-columns: minmax(0, 1fr); }
  .branch-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 767px) {
  .auth { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .auth__brand { padding: calc(var(--s6) + env(safe-area-inset-top, 0px)) var(--s5) var(--s6); gap: var(--s2); }
  .auth__brand h1 { font-size: var(--fs-xl); }
  .auth__brand p { display: none; }
  .auth__panel { padding: var(--s5) var(--s4); align-items: flex-start; }
  .auth__card { padding: var(--s5); }
  .branch-card__body { grid-template-columns: minmax(0, 1fr); }
  .kpi__value { font-size: 22px; }
}
@media (max-width: 520px) {
  .userbox__name { display: none; }
  .page-head h1 { font-size: var(--fs-lg); }
  .filter-bar .field { flex: 1 1 100%; }
  .filter-bar .btn { flex: 1 1 0; width: auto; }
  .filter-bar { gap: var(--s2); }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s3); }
  .kpi-grid .kpi--primary { grid-column: 1 / -1; }
  .group > summary, .group-cols { grid-template-columns: var(--cols-sm, var(--cols, 18px minmax(0, 1fr) auto auto)); }
  .hide-sm { display: none; }
  .group__body { padding-left: var(--s4); }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* 15. Print ---------------------------------------------------------------- */
@media print {
  .sidebar, .topbar, .filter-bar, .menu-btn, .backdrop, .app-footer, .form-actions { display: none !important; }
  .main { margin-left: 0; }
  body { background: #fff; }
  .card, .kpi, .record { box-shadow: none; }
}

/* 16. Mobile / installed-app (PWA) ------------------------------------------
   The app is used as an installed phone app: safe-area insets, a bottom tab
   bar, a back button (there is no browser chrome) and 44px touch targets.   */
html { -webkit-tap-highlight-color: transparent; }
a, button, summary, label.check { touch-action: manipulation; }
body { overscroll-behavior-y: none; }
.topbar__back {
  display: none; align-items: center; justify-content: center; flex: none;
  width: 40px; height: 40px; margin-left: -8px;
  border-radius: var(--radius-sm); color: var(--text);
}
.topbar__back:hover { background: var(--surface-2); text-decoration: none; }
.tabbar { display: none; }

@media (max-width: 991px) {
  .topbar {
    height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
    padding-top: env(safe-area-inset-top, 0px);
    padding-left: max(var(--s4), env(safe-area-inset-left, 0px));
    padding-right: max(var(--s4), env(safe-area-inset-right, 0px));
  }
  .topbar__back { display: inline-flex; }
  .content {
    padding-left: max(var(--s4), env(safe-area-inset-left, 0px));
    padding-right: max(var(--s4), env(safe-area-inset-right, 0px));
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }
  .app-footer { display: none; }
  .sidebar { padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }

  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--surface); border-top: 1px solid var(--line);
    box-shadow: 0 -2px 10px rgba(15, 31, 51, .06);
  }
  .tabbar__item {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    min-height: 56px; padding: 6px 4px;
    font: inherit; font-size: 11px; font-weight: 600; color: var(--muted);
    background: none; border: 0; cursor: pointer; text-decoration: none;
  }
  .tabbar__item .i { font-size: 20px; }
  .tabbar__item:hover { text-decoration: none; }
  .tabbar__item.is-active { color: var(--brand-600); }
  .tabbar__item.is-active .i { color: var(--brand-600); }

  /* touch targets: 44px, and 16px text in inputs so iOS does not zoom on focus */
  .btn, .input { min-height: 44px; font-size: 16px; }
  .btn--sm { min-height: 40px; }
  .nav__link { padding: 12px var(--s3); }
  .group > summary { padding: 14px var(--s4); }
  .check { min-height: 48px; }
  .report-tile { min-height: 64px; }
  /* two tiles per row on phones: fewer screens to scroll through the 17 reports */
  .report-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s2); }
  .report-tile { flex-direction: column; align-items: flex-start; justify-content: center; gap: var(--s2); padding: var(--s3); min-height: 96px; font-size: var(--fs-sm); }
  .topbar .menu-btn { display: none; }   /* the tab bar has the Menu button */
  .chart-box { height: 220px; }
  .chart-box--lg { height: 260px; }
}
@media (display-mode: standalone) {
  body { user-select: none; -webkit-user-select: none; }
  .table td, .record, .input, .kpi__value { user-select: text; -webkit-user-select: text; }
}
