:root {
  --brand: #D90001;
  --brand-dark: #a80001;
  --ink: #1f2226;
  --ink-2: #2b2f35;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f4f5f7;
  --tint: #fdecec;
  --sidebar-w: 236px;
}
body { background: var(--bg); color: var(--ink); font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; font-size: 14px; }
a { color: var(--brand); }
.btn-brand { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-brand:hover, .btn-brand:focus { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.text-brand { color: var(--brand) !important; }

/* ---------- sidebar ---------- */
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); background: var(--ink); color: #cfd3d8; overflow-y: auto; z-index: 1040; transition: transform .2s; }
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 16px 18px; color: #fff; text-decoration: none; border-bottom: 1px solid #33373d; }
.sidebar .brand img { height: 34px; background: #fff; border-radius: 6px; padding: 3px; }
.sidebar .brand span { font-size: 17px; letter-spacing: .5px; }
.sidebar .brand b { color: #ff3b3c; }
.sidebar nav { padding: 8px 0 24px; }
.sidebar .nav-head { font-size: 10.5px; letter-spacing: 1.2px; color: #7d848c; padding: 14px 20px 4px; font-weight: 600; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; padding: 7px 20px; color: #cfd3d8; text-decoration: none; border-left: 3px solid transparent; }
.sidebar nav a:hover { background: #2a2e34; color: #fff; }
.sidebar nav a.active { background: #2f1416; color: #fff; border-left-color: var(--brand); }
.sidebar nav a i { font-size: 15px; width: 18px; text-align: center; }
.main { margin-left: var(--sidebar-w); min-height: 100vh; }
.topbar { display: flex; align-items: center; gap: 12px; background: #fff; padding: 12px 24px; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 1030; }
.page-title { font-size: 19px; font-weight: 600; margin: 0; }
.content { padding: 22px 24px 40px; }
@media (max-width: 991px) {
  .sidebar { transform: translateX(-100%); }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .main { margin-left: 0; }
  .content { padding: 16px 12px 40px; }
}

/* ---------- cards / stats ---------- */
.card { border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.card-header { background: #fff; border-bottom: 1px solid var(--line); font-weight: 600; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; height: 100%; position: relative; overflow: hidden; }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.stat .value { font-size: 21px; font-weight: 700; margin-top: 2px; white-space: nowrap; }
.stat .sub { font-size: 12px; color: var(--muted); }
.stat i.bg-icon { position: absolute; right: 12px; top: 10px; font-size: 26px; color: #e9eaec; }
.stat.red .value { color: var(--brand); }
.stat.green .value { color: #15803d; }

/* ---------- tables ---------- */
.table { --bs-table-bg: #fff; margin-bottom: 0; }
.table thead th { background: var(--ink-2); color: #fff; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .3px; border: none; white-space: nowrap; }
.table td { vertical-align: middle; }
.table tfoot td, .table tr.total td { background: var(--tint); font-weight: 700; }
.table-wrap { background: #fff; border: 1px solid var(--line); border-radius: 10px; overflow: auto; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.badge-soft { background: var(--tint); color: var(--brand); font-weight: 600; }
.pos { color: #15803d; } .neg { color: var(--brand); }

/* ---------- forms ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-start; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin-bottom: 16px; }
.filters label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.form-label { font-weight: 600; font-size: 12.5px; color: #374151; }
.lines td { padding: 4px; }
.lines .form-control, .lines .form-select { font-size: 13px; }
.totals-box { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; }
.totals-box .row > div { padding-top: 4px; padding-bottom: 4px; }
.section-title { font-size: 13px; font-weight: 700; color: var(--brand); text-transform: uppercase; letter-spacing: .6px; border-bottom: 2px solid var(--brand); padding-bottom: 4px; margin: 18px 0 10px; }

/* ---------- login ---------- */
.content-plain { padding: 0; }
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #1f2226 0%, #3a1012 100%); padding: 16px; }
.login-card { background: #fff; border-radius: 14px; padding: 36px 32px; width: 100%; max-width: 380px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.login-logo { height: 80px; }
.login-card h2 { font-size: 22px; font-weight: 800; margin: 10px 0 0; } .login-card h2 span { color: var(--brand); }

/* ---------- printable documents ---------- */
.doc { background: #fff; max-width: 850px; margin: 0 auto; padding: 32px 36px; border: 1px solid var(--line); border-radius: 10px; }
.letterhead { display: flex; align-items: center; gap: 18px; border-bottom: 4px solid var(--brand); padding-bottom: 10px; margin-bottom: 16px; }
.letterhead img { height: 72px; }
.lh-text { margin-left: auto; text-align: right; font-size: 11.5px; color: #555; line-height: 1.5; }
.lh-name { font-size: 26px; font-weight: 800; color: var(--ink); letter-spacing: .5px; line-height: 1.1; margin-bottom: 4px; }
.lh-name span { color: var(--brand); }
.doc-title { background: var(--ink); color: #fff; text-align: center; font-weight: 700; letter-spacing: 2px; padding: 6px; font-size: 16px; margin-bottom: 14px; }
.doc .box { border: 1px solid #d5d7db; border-radius: 4px; }
.doc .row > div > .box:only-child { height: 100%; }
.doc .box + .box { margin-top: 8px; }
.doc .box-h { background: var(--tint); color: var(--brand); font-weight: 700; font-size: 11px; letter-spacing: .6px; padding: 4px 10px; border-bottom: 2px solid var(--brand); }
.doc .box-b { padding: 8px 10px; font-size: 13px; }
.doc table.items { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 14px; }
.doc table.items th { background: var(--ink-2); color: #fff; padding: 6px 8px; font-size: 11.5px; text-transform: uppercase; }
.doc table.items td { border: 1px solid #d5d7db; padding: 5px 8px; }
.doc table.items tr:nth-child(even) td { background: #fafafa; }
.doc .sum td { padding: 4px 10px; border: 1px solid #d5d7db; font-size: 13px; }
.doc .sum tr.strong td { background: var(--tint); font-weight: 700; }
.doc .sign { margin-top: 60px; display: flex; justify-content: space-between; gap: 40px; font-size: 12.5px; }
.doc .sign div { flex: 1; max-width: 240px; border-top: 1px solid #333; text-align: center; padding-top: 4px; }
.doc .foot { margin-top: 26px; border-top: 1px solid var(--line); padding-top: 6px; font-size: 11px; color: var(--muted); text-align: center; }

@media print {
  @page { size: A4; margin: 10mm; }
  body { background: #fff; font-size: 12px; }
  .sidebar, .topbar, .no-print, .btn, .filters { display: none !important; }
  .main { margin: 0; }
  .content { padding: 0; }
  .doc { border: none; padding: 0; max-width: none; }
  .table-wrap, .card { border: none; box-shadow: none; }
  .table thead th, .doc table.items th, .doc-title, .table tfoot td, .doc .box-h, .doc .sum tr.strong td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  a { color: inherit; text-decoration: none; }
  .print-only { display: block !important; }
}
.print-only { display: none; }
/* customer category tabs */
.cat-tabs .nav-link { background: #fff; border: 1px solid #e3e5e8; color: #2b2f35; padding: .4rem .8rem; line-height: 1.2; }
.cat-tabs .nav-link.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.cat-tabs .nav-link .small { font-size: .72rem; }
/* permissions: view-only users don't see entry forms / edit links; entry users don't see delete buttons */
body.perm-view .main form[method=post], body.perm-view .main form[method="POST"],
body.perm-view .main a[href*="_form"] { display: none !important; }
body.perm-nodel .main form:has(input[name=action][value=delete]),
body.perm-nodel .main form:has(input[name=action][value^="del_"]) { display: none !important; }
/* phone: entry tables scroll sideways instead of squeezing the item column */
@media (max-width: 767px) {
  table.lines { min-width: 640px; }
  table.lines td:first-child, table.lines th:first-child { min-width: 220px; }
  .topbar .page-title { font-size: 17px; }
  #installApp { padding: 2px 8px; }
}

/* searchable dropdowns */
.ss-wrap { position: relative; display: block; min-width: 0; }
.ss-wrap > .ss-hidden { position: absolute !important; left: 0; right: 0; bottom: 0; height: 1px !important; opacity: 0; pointer-events: none; padding: 0; border: 0; }
.ss-input { cursor: text; text-overflow: ellipsis; }
.ss-input::placeholder { color: #6c757d; }
.ss-list { position: fixed; z-index: 2000; overflow-y: auto; background: #fff; border: 1px solid #cfd4da; border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.15); padding: 4px 0; font-size: 14px; max-width: 92vw; }
.ss-opt { padding: 6px 12px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ss-opt small { color: #8a9099; margin-left: 6px; }
.ss-opt.ss-act { background: #D90001; color: #fff; }
.ss-opt.ss-act small { color: #ffd9d9; }
.ss-opt.ss-sel:not(.ss-act) { font-weight: 600; background: #fbeaea; }
.ss-grp { padding: 6px 12px 2px; font-size: 11px; font-weight: 700; color: #8a9099; text-transform: uppercase; letter-spacing: .04em; }
.ss-none { padding: 8px 12px; color: #8a9099; }
@media print { .ss-input { border: 0; background: none; padding: 0; } }
