/* Premier ERP - one small stylesheet, no framework. Light + dark follow the OS setting. */

:root {
  color-scheme: light dark;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;   /* blue: stock, sales, receivables */
  --series-2: #eb6834;   /* orange: payables */
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --danger: #b3261e;
  --good: #006300;        /* success text (status: good) */
  --serious: #ec835a;     /* status: needs attention - always with icon + label */
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --ring: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-2: #d95926;
    --accent: #3987e5;
    --danger: #f2877f;
    --good: #0ca30c;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.45 var(--font);
  color: var(--ink);
  background: var(--page);
}
h1 { font-size: 1.35rem; margin: 0 0 .75rem; font-weight: 600; }
h2 { font-size: .95rem; margin: 0; font-weight: 600; }
a { color: var(--accent); }
.muted { color: var(--ink-2); }
.small { font-size: .8rem; }

/* ---- header ---------------------------------------------------------------------------- */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.25rem;
  padding: .6rem 16px; background: var(--surface); border-bottom: 1px solid var(--ring);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; letter-spacing: .2px; color: var(--ink); text-decoration: none; }
.nav { display: flex; gap: .25rem; overflow-x: auto; flex: 1 1 auto; }
.nav a {
  padding: .4rem .75rem; border-radius: 8px; color: var(--ink-2);
  text-decoration: none; white-space: nowrap; font-weight: 500;
}
.nav a:hover { background: var(--page); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--page); color: var(--ink); box-shadow: inset 0 -2px 0 var(--accent); }
.user { display: flex; align-items: center; gap: .6rem; color: var(--ink-2); font-size: .85rem; }
.user form { margin: 0; }

main.container { max-width: 1280px; margin: 0 auto; padding: 16px; }

/* ---- controls -------------------------------------------------------------------------- */
.btn {
  font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; display: inline-block;
  padding: .45rem .85rem; border-radius: 8px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--axis);
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.small { padding: .25rem .6rem; font-size: .8rem; }
.btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible, th button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
input, select {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--axis); border-radius: 8px; padding: .45rem .6rem; min-width: 0;
}

.filters {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: .6rem 1rem; margin-bottom: 1rem;
}
.filters label { display: flex; flex-direction: column; gap: .2rem; font-size: .75rem; color: var(--ink-2); font-weight: 500; }
.filters.spaced { margin-top: 12px; }
.filters .grow { flex: 1 1 220px; }
.filters .grow input { width: 100%; }
.presets { display: flex; gap: .25rem; }
.filters .spacer { flex: 1 1 auto; }

.alert {
  padding: .6rem .8rem; border-radius: 8px; margin: 0 0 1rem;
  border: 1px solid var(--danger); color: var(--danger); background: var(--surface);
}
.hint { margin: -.4rem 0 1rem; }

/* ---- stat tiles ------------------------------------------------------------------------ */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 12px; }
.tile {
  background: var(--surface); border: 1px solid var(--ring); border-radius: var(--radius);
  padding: 14px 16px; min-width: 0;
}
.tile-label { font-size: .8rem; color: var(--ink-2); font-weight: 500; }
.tile-value { font-size: 1.7rem; font-weight: 650; margin: .15rem 0; line-height: 1.15; }
.tile-sub { font-size: .78rem; color: var(--muted); }

/* ---- chart cards ----------------------------------------------------------------------- */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 12px; transition: opacity .15s; }
.grid.loading, .kpis.loading { opacity: .55; }
.card {
  background: var(--surface); border: 1px solid var(--ring); border-radius: var(--radius);
  padding: 14px 16px 12px; min-width: 0; display: flex; flex-direction: column; gap: .5rem;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; }
.card-sub { font-size: .78rem; color: var(--muted); margin-top: -.35rem; }
.chart-box { position: relative; height: 280px; }
.chart-box.tall { height: 340px; }
.table-view { max-height: 340px; overflow: auto; }

/* ---- tables ---------------------------------------------------------------------------- */
.panel { background: var(--surface); border: 1px solid var(--ring); border-radius: var(--radius); padding: 14px 16px; }
.panel.narrow { max-width: 560px; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { padding: .5rem .6rem; text-align: left; border-bottom: 1px solid var(--grid); vertical-align: top; }
th { font-size: .75rem; color: var(--ink-2); font-weight: 600; white-space: nowrap; position: sticky; top: 0; background: var(--surface); }
th button { all: unset; cursor: pointer; font: inherit; color: inherit; font-weight: inherit; }
th button:hover { color: var(--ink); }
th[aria-sort] button::after { content: " ▲"; font-size: .65rem; }
th[aria-sort="descending"] button::after { content: " ▼"; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--page); }
.empty { padding: 2rem 0; text-align: center; color: var(--muted); }
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; margin-top: .75rem; }
.pager .btns { display: flex; gap: .4rem; }
/* Stock scan: an item's stock per branch, under its row. */
.branch-row td { background: var(--page); }
.branch-list { list-style: none; margin: 0; padding: .25rem 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .25rem 1.5rem; }
.branch-list li { display: flex; gap: .75rem; align-items: baseline; font-size: .85rem; border-bottom: 1px solid var(--grid); padding: .25rem 0; }
.branch-list .b-name { flex: 1 1 auto; }
.branch-list .b-qty { font-weight: 600; font-variant-numeric: tabular-nums; }
.branch-list .b-val { font-size: .78rem; font-variant-numeric: tabular-nums; }
td.actions { text-align: right; white-space: nowrap; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.badge { font-size: .72rem; padding: .1rem .45rem; border-radius: 999px; border: 1px solid var(--axis); color: var(--ink-2); white-space: nowrap; }

/* Phones: each table row becomes a labelled card. */
@media (max-width: 720px) {
  .stack-table thead { position: absolute; left: -9999px; }
  .stack-table, .stack-table tbody, .stack-table tr, .stack-table td { display: block; width: 100%; }
  .stack-table tr { border: 1px solid var(--ring); border-radius: 8px; padding: .4rem .6rem; margin-bottom: .6rem; background: var(--surface); }
  .stack-table td { display: flex; justify-content: space-between; gap: 1rem; border: 0; padding: .2rem 0; text-align: right; }
  .stack-table td::before { content: attr(data-label); color: var(--ink-2); font-size: .78rem; text-align: left; flex: none; }
  .stack-table td.primary { font-weight: 600; text-align: left; justify-content: flex-start; }
  .stack-table td.primary::before { content: none; }
  .stack-table td.actions { justify-content: flex-end; }
  .stack-table td.actions::before { content: none; }
  .stack-table tr.branch-row td { display: block; text-align: left; }
  .stack-table tr.branch-row td::before { content: none; }
  .topbar { padding: .5rem 12px; }
  main.container { padding: 12px; }
  .tile-value { font-size: 1.45rem; }
  .chart-box, .chart-box.tall { height: 250px; }
}

/* ---- login ----------------------------------------------------------------------------- */
body.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--ring);
  border-radius: 14px; padding: 28px 24px;
}
.login-card h1 { margin-bottom: .25rem; }
.login-card form { display: flex; flex-direction: column; gap: .35rem; margin-top: 1rem; }
.login-card label { font-size: .8rem; color: var(--ink-2); font-weight: 500; margin-top: .5rem; }
.login-card .btn { margin-top: 1rem; padding: .6rem; }

/* ---- Google sign-in / admin ------------------------------------------------------------ */
.login-card .btn.google { display: block; text-align: center; margin-top: 1.25rem; padding: .65rem; font-weight: 600; }
.admin-login { margin-top: 1.25rem; font-size: .9rem; }
.admin-login summary { cursor: pointer; color: var(--ink-2); }
.notice { padding: .6rem .8rem; border-radius: 8px; margin: 0 0 1rem; border: 1px solid var(--accent); background: var(--surface); }
.spaced-top { margin-top: 12px; }
.panel h2 { margin-bottom: .5rem; }

/* ---- finance ratios ---------------------------------------------------------------------- */
.ratio-tiles { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.ratio .status { font-weight: 600; color: var(--ink); }
.ratio .status-icon { display: inline-grid; place-items: center; width: 1.1em; height: 1.1em; border-radius: 50%;
  font-size: .75em; margin-right: .3em; color: #fff; vertical-align: text-bottom; }
.ratio.good .status-icon { background: var(--good); }
.ratio.attention .status-icon { background: var(--serious); }
.ratio.good { box-shadow: inset 3px 0 0 var(--good); }
.ratio.attention { box-shadow: inset 3px 0 0 var(--serious); }
.delta.up { color: var(--good); font-weight: 600; }
.delta.down { color: var(--danger); font-weight: 600; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
