:root {
  --brand-blue: #00aeef;
  --brand-orange: #f15a22;
  --brand-charcoal: #1f2937;
  --bg: #f3f5f6;
  --surface: #ffffff;
  --border: #dde2e6;
  --text: #1f2937;
  --text-muted: #5b6570;
  --danger: #dc2626;
  --danger-bg: #fde8e8;
  --success: #15803d;
  --success-bg: #e7f6ec;
  --warn-bg: #fff4e5;
  --warn: #b45309;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

body.has-nav { padding-bottom: 76px; }

a { color: var(--brand-blue); text-decoration: none; }

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand-badge { width: 34px; height: 34px; border-radius: 8px; flex-shrink: 0; }
.brand-text { line-height: 1.15; flex: 1; min-width: 0; }
.brand-name { font-weight: 800; font-size: 15px; color: var(--brand-blue); }
.brand-slogan { font-size: 10.5px; font-style: italic; color: var(--brand-orange); font-weight: 600; }

.link-btn {
  background: none; border: none; color: var(--text-muted);
  font-size: 13px; padding: 6px 4px; cursor: pointer;
}

.content { max-width: 640px; margin: 0 auto; padding: 14px 14px 24px; width: 100%; }

.flash-stack { max-width: 640px; margin: 10px auto 0; padding: 0 14px; }
.flash {
  padding: 10px 12px; border-radius: 10px; margin-bottom: 8px; font-size: 14px;
}
.flash-error { background: var(--danger-bg); color: var(--danger); }
.flash-success { background: var(--success-bg); color: var(--success); }
.flash-info { background: var(--warn-bg); color: var(--warn); }

/* -- Bottom nav -- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 4px 0 max(4px, env(safe-area-inset-bottom));
  z-index: 10;
}
.bottom-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 2px; color: var(--text-muted); font-size: 11px; font-weight: 600;
}
.bottom-nav a.active { color: var(--brand-blue); }
.bottom-nav .nav-icon { font-size: 19px; line-height: 1; }

/* -- Cards -- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 16px; margin-bottom: 12px;
}
.form-card h1 { font-size: 20px; margin: 0 0 12px; }
.muted { color: var(--text-muted); font-size: 13px; }

/* -- Forms -- */
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-muted); margin: 12px 0 4px; }
label:first-of-type { margin-top: 0; }
input, select, textarea {
  width: 100%; padding: 11px 12px; font-size: 16px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text);
}
input[readonly] { background: var(--bg); color: var(--text-muted); }
textarea { resize: vertical; min-height: 60px; }

.btn {
  display: inline-block; padding: 12px 16px; border-radius: 10px; border: none;
  font-size: 15px; font-weight: 700; cursor: pointer; text-align: center;
}
.btn-primary { background: var(--brand-blue); color: #fff; }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-block { display: block; width: 100%; margin-top: 14px; }
.btn-sm { padding: 8px 12px; font-size: 13px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.btn-row form { flex: 1; }
.btn-row .btn { width: 100%; }

/* -- Line-item cart rows -- */
.cart-row, .list-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--border); gap: 10px;
}
.cart-row:last-child, .list-row:last-child { border-bottom: none; }
.cart-row .desc { font-size: 12px; color: var(--text-muted); font-style: italic; }
.row-main { flex: 1; min-width: 0; }
.row-main .title { font-weight: 600; }
.row-main .meta { font-size: 12.5px; color: var(--text-muted); }
.row-amount { font-weight: 700; white-space: nowrap; }

/* -- Totals -- */
.totals { margin-top: 10px; padding-top: 10px; border-top: 2px solid var(--border); }
.totals .line { display: flex; justify-content: space-between; padding: 3px 0; font-size: 14px; }
.totals .line.grand { font-weight: 800; font-size: 17px; }

/* -- Status pills -- */
.pill {
  display: inline-block; padding: 2px 9px; border-radius: 100px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .02em;
}
.pill-paid { background: var(--success-bg); color: var(--success); }
.pill-partial, .pill-unpaid { background: var(--warn-bg); color: var(--warn); }
.pill-void { background: var(--danger-bg); color: var(--danger); }
.pill-low { background: var(--danger-bg); color: var(--danger); }

/* -- Section headers -- */
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); margin: 18px 0 8px; }

/* -- Empty state -- */
.empty-state { text-align: center; color: var(--text-muted); padding: 30px 10px; font-size: 14px; }

/* -- Sale item list on detail page -- */
.item-line { padding: 10px 0; border-bottom: 1px solid var(--border); }
.item-line:last-child { border-bottom: none; }
.item-line .top { display: flex; justify-content: space-between; font-weight: 600; }
.item-line .sub { font-size: 12.5px; color: var(--text-muted); }
.item-line .for { font-size: 12px; color: var(--text-muted); font-style: italic; margin-top: 2px; }

@media (min-width: 640px) {
  .content { padding-top: 20px; }
}

/* ======================================================================
   Layout for the full system (phone first, sidebar + wide pages on a PC)
   ====================================================================== */
.layout { display: block; }
.side-nav { display: none; }
.page-title { font-size: 20px; margin: 4px 0 12px; }
.user-chip { font-size: 13px; font-weight: 700; color: var(--text); padding: 4px 8px; border-radius: 100px; background: var(--bg); }
.topbar .logout-form { margin: 0; }

input[type=checkbox], input[type=radio] { width: auto; padding: 0; margin: 0 6px 0 0; accent-color: var(--brand-blue); }
label.check { display: flex; align-items: center; font-size: 14px; font-weight: 600; color: var(--text); margin: 12px 0 0; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
.row-inline { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.row-inline > * { flex: 1 1 140px; }
.row-inline > .btn { flex: 0 0 auto; }
.hint { font-size: 12.5px; color: var(--text-muted); margin: 8px 0 0; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 6px 0 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); background: var(--bg); padding: 9px 10px; white-space: nowrap; }
table.data td { padding: 9px 10px; border-top: 1px solid var(--border); vertical-align: top; }
table.data .num, table.data th.num { text-align: right; white-space: nowrap; }
table.data tr.low td { background: var(--danger-bg); }
table.data tr.total td { font-weight: 800; background: var(--bg); }
table.data tr.inactive td { color: #98a1ab; }
table.data a { font-weight: 600; }

.subtabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 14px; }
.subtabs a { padding: 8px 12px; border-radius: 100px; background: var(--surface); border: 1px solid var(--border); color: var(--text-muted); font-size: 13px; font-weight: 700; }
.subtabs a.active { background: var(--brand-blue); border-color: var(--brand-blue); color: #fff; }

.more-list a { display: flex; justify-content: space-between; align-items: center; padding: 14px 4px; border-bottom: 1px solid var(--border); color: var(--text); font-weight: 600; }
.more-list a:last-child { border-bottom: none; }
.more-list a span.chev { color: var(--text-muted); }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px; }
.stat .label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); font-weight: 700; }
.stat .value { font-size: 19px; font-weight: 800; margin-top: 2px; }
.stat.good .value { color: var(--success); }
.stat.bad .value { color: var(--danger); }

.banner { background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }
.pill-ok { background: var(--success-bg); color: var(--success); }
.pill-off { background: var(--bg); color: var(--text-muted); }

@media (min-width: 900px) {
  body.has-nav { padding-bottom: 0; }
  .bottom-nav { display: none; }
  .layout { display: flex; align-items: flex-start; max-width: 1240px; margin: 0 auto; }
  .side-nav {
    display: block; flex: 0 0 210px; position: sticky; top: 64px; padding: 16px 8px 24px 14px;
    max-height: calc(100vh - 64px); overflow-y: auto;
  }
  .side-nav a { display: block; padding: 9px 12px; border-radius: 10px; color: var(--text); font-weight: 600; font-size: 14.5px; }
  .side-nav a:hover { background: var(--surface); }
  .side-nav a.active { background: var(--brand-blue); color: #fff; }
  .side-group { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); font-weight: 800; margin: 14px 12px 4px; }
  .side-group:first-child { margin-top: 0; }
  .content { max-width: 1000px; margin: 0; padding: 20px 20px 40px; flex: 1; min-width: 0; }
  .flash-stack { max-width: 1240px; padding: 0 14px; }
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .form-card { max-width: 420px; margin-left: auto; margin-right: auto; }
}

/* -- Branch bar: which branch the pages are about (head office picks one) -- */
.branch-bar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px;
  padding: 7px 14px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.branch-bar form { display: flex; align-items: center; gap: 8px; margin: 0; }
.branch-bar label { margin: 0; font-size: 11px; font-weight: 800; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-muted); }
.branch-bar select { width: auto; min-width: 190px; padding: 6px 10px; font-size: 14px; font-weight: 600; }
.branch-chip { display: inline-block; padding: 3px 12px; border-radius: 100px; font-size: 13px;
  font-weight: 700; background: var(--bg); color: var(--brand-charcoal); border: 1px solid var(--border); }
@media (min-width: 900px) {
  .branch-bar { padding-left: max(14px, calc((100vw - 1240px) / 2 + 14px)); }
}
