:root {
  --red: #D7141A; --red-d: #B01016; --red-soft: #FDE8E9;
  --ink: #1F2328; --muted: #6B7280; --line: #E3E5E8; --bg: #F4F5F7; --card: #fff;
  --ok: #15803D; --ok-soft: #DCFCE7; --warn: #92400E; --warn-soft: #FEF3C7;
  --radius: 10px; --side: 232px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; color: var(--ink);
       background: var(--bg); -webkit-text-size-adjust: 100%; }
a { color: var(--red); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 0; font-weight: 650; }
h2 { font-size: 17px; margin: 0 0 12px; font-weight: 650; }
.muted { color: var(--muted); } .small { font-size: 13px; } .right { text-align: right; }
.nowrap { white-space: nowrap; } .mono { font-variant-numeric: tabular-nums; }

/* ---------- layout */
.side { position: fixed; inset: 0 auto 0 0; width: var(--side); background: var(--ink); display: flex;
        flex-direction: column; padding: 16px 0 12px; z-index: 20; }
.side .logo { background: #fff; border-radius: 8px; margin: 0 14px 18px; padding: 8px; display: block; }
.side .logo img { width: 100%; display: block; }
.side nav a { display: flex; gap: 10px; align-items: center; color: #D1D5DB; padding: 11px 20px;
              border-left: 3px solid transparent; font-size: 15px; }
.side nav a:hover { background: #2B3036; color: #fff; text-decoration: none; }
.side nav a.on { background: #2B3036; color: #fff; border-left-color: var(--red); }
.side nav .sep { height: 1px; background: #343a41; margin: 8px 16px; }
.side .foot { margin-top: auto; color: #8B949E; font-size: 12px; padding: 0 20px; }
.side .foot a { color: #C9D1D9; }
main { margin-left: var(--side); padding: 22px 28px 40px; max-width: 1400px; }
.topline { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.topline .grow { flex: 1; }
.mobilebar, .tabbar { display: none; }

/* ---------- cards & grids */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.stat .lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.stat .val { font-size: 22px; font-weight: 650; margin-top: 2px; }
.stat .val.big { font-size: 28px; color: var(--red); }
.bigbtns { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.bigbtn { display: flex; flex-direction: column; gap: 4px; padding: 22px; border-radius: var(--radius);
          background: var(--red); color: #fff; font-size: 20px; font-weight: 650; }
.bigbtn small { font-weight: 400; font-size: 14px; opacity: .9; }
.bigbtn.dark { background: var(--ink); }
.bigbtn:hover { text-decoration: none; filter: brightness(.95); }

/* ---------- forms */
label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 4px; }
input, select, textarea { font: inherit; color: inherit; width: 100%; padding: 9px 11px; border: 1px solid #D1D5DB;
  border-radius: 7px; background: #fff; min-height: 42px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
textarea { min-height: 80px; }
input[type=checkbox] { width: 20px; min-height: 20px; height: 20px; vertical-align: middle; accent-color: var(--red); }
.field { margin-bottom: 12px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 15px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px;
       min-height: 42px; border-radius: 7px; border: 1px solid #D1D5DB; background: #fff; color: var(--ink);
       font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #F9FAFB; text-decoration: none; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-d); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.danger { color: var(--red); }
.btn.link { border: none; background: none; color: var(--red); padding: 6px 4px; min-height: 0; }
.btn[disabled] { opacity: .55; cursor: wait; }
.btn.wide { width: 100%; min-height: 50px; font-size: 17px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 14px; }
.filters > div { min-width: 140px; } .filters .grow { flex: 1; min-width: 200px; }

/* ---------- tables */
.tablewrap { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase;
     letter-spacing: .03em; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #FAFAFB; white-space: nowrap; }
td { padding: 11px 12px; border-bottom: 1px solid #EEF0F2; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr.click { cursor: pointer; } tr.click:hover td { background: #FDF6F6; }
tr.void td { color: #9CA3AF; } tr.void td.amt { text-decoration: line-through; }
tfoot td { font-weight: 650; background: #FAFAFB; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600;
         background: #EEF0F2; color: var(--muted); }
.badge.red { background: var(--red-soft); color: var(--red); } .badge.green { background: var(--ok-soft); color: var(--ok); }
.badge.amber { background: var(--warn-soft); color: var(--warn); }

/* ---------- messages */
.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 12px; background: var(--ok-soft); color: #14532D; }
.flash.error { background: #FEE2E2; color: #991B1B; }
.flash.warn { background: var(--warn-soft); color: var(--warn); }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* ---------- document entry */
.docgrid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.totals { position: sticky; top: 16px; display: grid; gap: 10px; }
.cust-picked { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.cust-results { border: 1px solid var(--line); border-radius: 8px; margin-top: 6px; max-height: 300px; overflow: auto; background: #fff; }
.cust-results button { display: block; width: 100%; text-align: left; padding: 10px 12px; border: none;
                       border-bottom: 1px solid #EEF0F2; background: #fff; font: inherit; cursor: pointer; }
.cust-results button:hover, .cust-results button:focus { background: var(--red-soft); outline: none; }
.lines .line { display: grid; grid-template-columns: 1.3fr 1.6fr 1fr 1.1fr 1fr 40px; gap: 8px; align-items: center;
               padding: 8px 0; border-bottom: 1px solid #EEF0F2; }
.lines .head { font-size: 12px; color: var(--muted); text-transform: uppercase; font-weight: 600; padding-top: 0; }
.lines .ltotal { text-align: right; font-weight: 600; }
.lines .del { border: none; background: none; color: #9CA3AF; font-size: 20px; cursor: pointer; min-height: 40px; }
.lines .del:hover { color: var(--red); }
.lines .lbl { display: none; }
dialog { border: none; border-radius: 12px; padding: 0; width: min(560px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(17,24,39,.45); }
dialog .dlg { padding: 18px; }
dialog .dlg-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }

/* ---------- login */
.loginbox { max-width: 400px; margin: 8vh auto; padding: 0 16px; }
.loginbox .logo { background: #fff; padding: 18px; border-radius: 12px; margin-bottom: 16px; border: 1px solid var(--line); }
.loginbox .logo img { width: 100%; display: block; }
.qr svg { width: 220px; height: 220px; }

/* ---------- phones & small tablets */
@media (max-width: 900px) {
  .side { display: none; }
  main { margin: 0; padding: 14px 14px 90px; }
  .mobilebar { display: flex; align-items: center; gap: 10px; background: var(--ink); color: #fff; padding: 8px 14px;
               position: sticky; top: 0; z-index: 30; }
  .mobilebar img { height: 30px; background: #fff; border-radius: 5px; padding: 3px 6px; }
  .mobilebar .grow { flex: 1; }
  .mobilebar a { color: #fff; font-size: 14px; }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; inset: auto 0 0 0;
            background: #fff; border-top: 1px solid var(--line); z-index: 30; padding-bottom: env(safe-area-inset-bottom); }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 9px;
              color: var(--muted); font-size: 11px; }
  .tabbar a.on { color: var(--red); }
  .tabbar svg { width: 22px; height: 22px; }
  .tabbar a:hover { text-decoration: none; }
  h1 { font-size: 21px; }
  .g3, .g4, .g5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g2 { grid-template-columns: 1fr; }
  .docgrid { grid-template-columns: 1fr; }
  .totals { position: static; }
  .lines .head { display: none; }
  .lines .line { grid-template-columns: 1fr 1fr; gap: 8px; background: #FAFAFB; border: 1px solid var(--line);
                 border-radius: 8px; padding: 10px; margin-bottom: 10px; position: relative; }
  .lines .line .c-prod { grid-column: 1 / -1; padding-right: 36px; }
  .lines .line .c-desc { grid-column: 1 / -1; }
  .lines .lbl { display: block; font-size: 11px; color: var(--muted); margin-bottom: 2px; }
  .lines .ltotal { grid-column: 1 / -1; text-align: right; font-size: 16px; }
  .lines .c-del { position: absolute; top: 8px; right: 6px; }
  .hide-m { display: none; }
  .filters > div { min-width: 0; flex: 1 1 140px; }
  .bigbtn { padding: 18px; font-size: 18px; }
  td, th { padding: 9px 8px; }
  table { font-size: 14px; }
  td.docno { white-space: normal; min-width: 90px; }
  td.docno .badge { margin-top: 2px; }
  td .muted.small { font-size: 12px; }
}
@media (max-width: 420px) { .bigbtns { grid-template-columns: 1fr; } }
@media print { .side, .mobilebar, .tabbar, .noprint { display: none !important; } main { margin: 0; } }

.acts { white-space: nowrap; }
@media (max-width: 640px) { .acts { white-space: normal; } .acts .btn, .acts form { display: block; text-align: right; } }
