/* Construction ERP — UI styles
   Palette: concrete base, slate ink, hi-vis yellow used only as a marker (active nav, primary action, hazard strip). */
:root {
  --concrete: #EDEFEE;
  --panel: #FFFFFF;
  --ink: #1D2A30;
  --ink-2: #4A5A61;
  --line: #D5DAD9;
  --slate: #1D2A30;
  --slate-2: #2B3B42;
  --hivis: #FFC400;
  --steel: #2F5D73;
  --steel-soft: #E3ECF0;
  --good: #1F6B47;
  --bad: #B3261E;
  --radius: 6px;
  --font: "Archivo", "Mukta", system-ui, sans-serif;
  --font-np: "Mukta", "Archivo", sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); font-size: 15px; line-height: 1.45; color: var(--ink); background: var(--concrete); -webkit-font-smoothing: antialiased; }
body.lang-ne { font-family: var(--font-np); font-size: 16px; }
.np { font-family: var(--font-np); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--steel); }
:focus-visible { outline: 3px solid var(--hivis); outline-offset: 1px; }
.num, td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--ink-2); }
.neg { color: var(--bad); }
.hidden { display: none !important; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { background: var(--slate); color: #DCE3E5; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { padding: 18px 18px 14px; border-bottom: 1px solid var(--slate-2); }
.brand b { display: block; font-size: 16px; color: #fff; font-weight: 700; letter-spacing: .01em; }
.brand small { color: #9FB0B6; font-size: 12px; }
.hazard { height: 6px; background: repeating-linear-gradient(-45deg, var(--hivis) 0 10px, var(--slate) 10px 20px); }
.nav { padding: 10px 8px; flex: 1; }
.nav h6 { margin: 14px 10px 4px; font-size: 12px; font-weight: 600; color: #7F9298; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 4px; color: #DCE3E5; text-decoration: none; font-size: 14px; border-left: 4px solid transparent; }
.nav a:hover { background: var(--slate-2); }
.nav a.on { background: var(--slate-2); border-left-color: var(--hivis); color: #fff; font-weight: 600; }
.nav svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.side-foot { padding: 12px 18px; font-size: 12px; color: #9FB0B6; border-top: 1px solid var(--slate-2); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 22px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar .title { font-weight: 700; font-size: 18px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .fy { font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 20px; padding: 4px 10px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.page { padding: 20px 22px 40px; max-width: 1400px; width: 100%; }

.bottom-nav { display: none; }
.fab { display: none; }

/* ---------- blocks ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.panel > header { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.panel > header h3 { margin: 0; font-size: 15px; flex: 1; }
.panel .body { padding: 14px 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)); }
.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; margin-bottom: 14px; }
.toolbar .grow { flex: 1; }
h2.page-h { margin: 0 0 14px; font-size: 22px; }

/* figures on dashboard: a ledger-strip rather than generic cards */
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 14px; }
.figure { padding: 14px 16px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.figure span { display: block; font-size: 13px; color: var(--ink-2); }
.figure strong { display: block; font-size: 21px; font-variant-numeric: tabular-nums; margin-top: 2px; }
.figure.key { box-shadow: inset 4px 0 0 var(--hivis); }

/* bars */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding-top: 8px; }
.bars .m { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; min-width: 0; }
.bars .pair { display: flex; gap: 2px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.bars i { display: block; width: 42%; max-width: 16px; border-radius: 2px 2px 0 0; }
.bars i.in { background: var(--steel); }
.bars i.out { background: #B9C6CB; }
.bars small { font-size: 11px; color: var(--ink-2); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.progress { height: 6px; background: var(--steel-soft); border-radius: 3px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--steel); }
.progress i.over { background: var(--bad); }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-weight: 600; color: var(--ink-2); background: #F6F7F7; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; }
.tbl td { padding: 7px 10px; border-bottom: 1px solid #ECEFEF; vertical-align: top; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: #F7F9F9; }
.tbl tfoot td { font-weight: 700; border-top: 2px solid var(--ink); background: #FAFBFB; }
.tbl tr.l1 td { font-weight: 700; background: #F3F5F5; }
.tbl tr.l2 td { font-weight: 600; }
.tbl td.ind2 { padding-left: 24px; } .tbl td.ind3 { padding-left: 40px; } .tbl td.ind4 { padding-left: 58px; color: var(--ink-2); }
.tbl .tag { font-size: 12px; padding: 1px 6px; border-radius: 3px; background: var(--steel-soft); color: var(--steel); white-space: nowrap; }
.empty { padding: 34px 16px; text-align: center; color: var(--ink-2); }

/* ---------- forms ---------- */
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-2); min-width: 0; }
label.f > span { font-weight: 500; }
.in, select.in, textarea.in { width: 100%; padding: 8px 10px; border: 1px solid #BFC7C8; border-radius: 4px; background: #fff; font-size: 15px; color: var(--ink); min-height: 38px; }
.in:focus { border-color: var(--steel); outline: none; box-shadow: 0 0 0 3px rgba(47,93,115,.18); }
textarea.in { min-height: 64px; }
.in.num { text-align: right; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink); }
.check input { width: 18px; height: 18px; accent-color: var(--steel); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 4px; border: 1px solid #BFC7C8; background: #fff; cursor: pointer; font-weight: 600; font-size: 14px; min-height: 38px; white-space: nowrap; text-decoration: none; color: var(--ink); }
.btn:hover { background: #F4F6F6; }
.btn.primary { background: var(--hivis); border-color: #E0AC00; color: #1D2A30; }
.btn.primary:hover { background: #FFCF33; }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.danger { color: var(--bad); border-color: #E3B3AF; }
.btn.small { padding: 4px 9px; min-height: 30px; font-size: 13px; }
.btn.icon { padding: 6px; min-width: 34px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.seg { display: inline-flex; border: 1px solid #BFC7C8; border-radius: 4px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 6px 10px; cursor: pointer; font-size: 13px; }
.seg button.on { background: var(--ink); color: #fff; }

/* date field with BS/AD switch */
.datef { display: flex; gap: 0; }
.datef .in { border-radius: 4px 0 0 4px; }
.datef button { border: 1px solid #BFC7C8; border-left: 0; background: #F4F6F6; border-radius: 0 4px 4px 0; padding: 0 8px; font-size: 12px; font-weight: 700; cursor: pointer; min-width: 40px; }
.datef-hint { font-size: 12px; color: var(--ink-2); min-height: 16px; }

/* combobox */
.combo { position: relative; }
.combo .list { position: absolute; z-index: 60; left: 0; right: 0; top: 100%; max-height: 260px; overflow-y: auto; background: #fff; border: 1px solid #BFC7C8; border-radius: 0 0 4px 4px; box-shadow: 0 8px 18px rgba(29,42,48,.16); }
.combo .opt { padding: 8px 10px; cursor: pointer; font-size: 14px; border-bottom: 1px solid #F0F2F2; }
.combo .opt small { color: var(--ink-2); margin-left: 6px; }
.combo .opt.hi, .combo .opt:hover { background: var(--steel-soft); }

/* voucher lines */
.lines { width: 100%; border-collapse: collapse; }
.lines th:first-child { width: 36%; }
.lines th { font-size: 12px; font-weight: 600; color: var(--ink-2); text-align: left; padding: 4px 4px; }
.lines td { padding: 3px 4px; vertical-align: top; }
.lines .in { min-height: 36px; padding: 6px 8px; }
.lines .stock-hint { font-size: 11px; color: var(--ink-2); padding: 2px 2px 0; }
.totals { margin-left: auto; width: min(360px, 100%); font-size: 14px; }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals div.grand { border-top: 2px solid var(--ink); font-weight: 700; font-size: 17px; padding-top: 7px; margin-top: 3px; }
.vtype-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }

/* ---------- modal / sheet ---------- */
.overlay { position: fixed; inset: 0; background: rgba(20,28,32,.45); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow-y: auto; }
.modal { background: var(--panel); border-radius: 8px; width: min(620px, 100%); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { width: min(1240px, 100%); }
.modal > header { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal > header h3 { margin: 0; flex: 1; font-size: 17px; }
.modal .body { padding: 16px 18px; display: grid; gap: 12px; }
.modal .body > * { min-width: 0; }
.panel, .grid > * { min-width: 0; }
.modal > footer { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }
.toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 6px; z-index: 200; font-size: 14px; max-width: 90vw; box-shadow: 0 8px 20px rgba(0,0,0,.25); }
.toast.err { background: var(--bad); }

/* ---------- tree (COA, P&L) ---------- */
.tree-row { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-bottom: 1px solid #EEF0F0; }
.tree-row:hover { background: #F8FAFA; }
.tree-row .tw { width: 20px; text-align: center; cursor: pointer; color: var(--ink-2); flex: none; user-select: none; }
.tree-row .nm { flex: 1; min-width: 0; }
.tree-row.lv1 { background: #F1F3F3; font-weight: 700; }
.tree-row.lv2 { font-weight: 600; }
.badge { font-size: 11px; padding: 1px 6px; border-radius: 3px; border: 1px solid var(--line); color: var(--ink-2); white-space: nowrap; }
.badge.fixed { border-color: #E0AC00; color: #7A5B00; background: #FFF6D6; }

/* P&L statement */
.stmt { max-width: 860px; }
.stmt .row { display: flex; gap: 10px; padding: 6px 12px; border-bottom: 1px solid #EEF0F0; align-items: baseline; }
.stmt .row .nm { flex: 1; }
.stmt .row .a { width: 150px; text-align: right; font-variant-numeric: tabular-nums; }
.stmt .row.head { font-weight: 700; background: #F3F5F5; }
.stmt .row.sub { font-weight: 700; border-top: 2px solid var(--ink); border-bottom: 2px solid var(--ink); background: #FAFBFB; }
.stmt .row.result { font-size: 17px; font-weight: 700; background: var(--ink); color: #fff; border-radius: 4px; margin-top: 6px; }
.stmt .row.d2 .nm { padding-left: 18px; } .stmt .row.d3 .nm { padding-left: 36px; } .stmt .row.d4 .nm { padding-left: 54px; color: var(--ink-2); }
.stmt .tg { cursor: pointer; color: var(--steel); user-select: none; display: inline-block; width: 16px; }
.stmt a { cursor: pointer; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--slate); }
.login .box { background: #fff; width: min(400px, 100%); border-radius: 8px; overflow: hidden; }
.login .box .hazard { height: 10px; }
.login .box .in-box { padding: 26px 26px 22px; display: grid; gap: 14px; }
.login h1 { margin: 0; font-size: 22px; }
.login p { margin: 0; color: var(--ink-2); font-size: 14px; }

/* ---------- print ---------- */
.print-page { background: #fff; color: #000; max-width: 800px; margin: 0 auto; padding: 26px 30px; font-size: 13px; }
.print-page .inv-head { text-align: center; border-bottom: 2px solid #000; padding-bottom: 8px; margin-bottom: 8px; }
.print-page .inv-head h1 { margin: 0; font-size: 20px; }
.print-page .inv-title { text-align: center; font-weight: 700; font-size: 16px; margin: 6px 0 10px; letter-spacing: .03em; }
.print-page table { width: 100%; border-collapse: collapse; }
.print-page .meta td { padding: 2px 0; vertical-align: top; }
.print-page .items th, .print-page .items td { border: 1px solid #000; padding: 4px 6px; }
.print-page .items th { background: #EEE; }
.print-page .sign { display: flex; justify-content: space-between; margin-top: 50px; }
.print-page .sign div { border-top: 1px solid #000; padding-top: 4px; width: 180px; text-align: center; }
.print-actions { display: flex; gap: 8px; justify-content: center; padding: 14px; }
/* margin 0 on the page box removes the browser's own header/footer (page URL = server IP, date, title);
   the content gets its margin from padding instead */
@page { size: auto; margin: 0; }
.print-only-head { display: none; }
@media print {
  body { background: #fff; padding: 10mm 12mm; }
  .print-only-head { display: block; }
  .rep-head { text-align: center; border-bottom: 2px solid #000; padding-bottom: 6px; margin-bottom: 10px; color: #000; }
  .rep-head h1 { margin: 0; font-size: 20px; }
  .rep-head h2 { margin: 4px 0 0; font-size: 15px; }
  .rep-head .rep-filters { font-size: 12px; margin-top: 2px; }
  .tbl thead { display: table-header-group; }   /* repeat column heads on every page */
  .tbl th { position: static; }
  .side, .topbar, .bottom-nav, .fab, .print-actions, .no-print { display: none !important; }
  .shell { display: block; }
  .page { padding: 0; max-width: none; }
  .print-page { padding: 0; }
  .panel { border: 0; }
}

/* ---------- mobile ---------- */
@media (max-width: 900px) {
  .toolbar > .seg[role=tablist] { max-width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .seg[role=tablist] button { white-space: nowrap; }
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: 270px; z-index: 90; transform: translateX(-100%); transition: transform .2s ease; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(20,28,32,.45); }
  .topbar { padding: calc(8px + var(--safe-t)) 12px 8px; }
  .topbar .fy { display: none; }
  .page { padding: 14px 12px calc(96px + var(--safe-b)); }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .bottom-nav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: var(--panel); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
  .bottom-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 7px; font-size: 11px; color: var(--ink-2); text-decoration: none; border-top: 3px solid transparent; }
  .bottom-nav a.on { color: var(--ink); border-top-color: var(--hivis); font-weight: 600; }
  .bottom-nav svg { width: 22px; height: 22px; }
  .fab { display: flex; position: fixed; right: 16px; bottom: calc(72px + var(--safe-b)); z-index: 41; width: 56px; height: 56px; border-radius: 50%; background: var(--hivis); border: 0; align-items: center; justify-content: center; box-shadow: 0 6px 16px rgba(0,0,0,.25); cursor: pointer; }
  .fab svg { width: 26px; height: 26px; }
  .overlay { padding: 0; align-items: flex-end; }
  .modal, .modal.wide { width: 100%; border-radius: 12px 12px 0 0; max-height: 94vh; overflow-y: auto; }
  .modal > footer { position: sticky; bottom: 0; background: #fff; padding-bottom: calc(12px + var(--safe-b)); }
  /* voucher lines become stacked cards */
  .lines thead { display: none; }
  .lines tr { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 10px; border: 1px solid var(--line); border-radius: 6px; margin-bottom: 8px; background: #FBFCFC; }
  .lines td { padding: 0; }
  .lines td.wide { grid-column: 1 / -1; }
  .lines td[data-l]::before { content: attr(data-l); display: block; font-size: 11px; color: var(--ink-2); }
  .figure strong { font-size: 18px; }
  .stmt .row .a { width: 110px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* required fields: red asterisk + highlight when left empty */
label.f.req > span:first-child::after, th.req::after, .req-mark::after { content: " *"; color: var(--bad); font-weight: 700; }
.in.invalid, select.in.invalid { border-color: var(--bad); box-shadow: 0 0 0 3px rgba(179,38,30,.15); }
/* "+" add-new button beside a dropdown */
.combo.has-add { display: flex; gap: 4px; align-items: stretch; }
.combo.has-add > input { flex: 1; min-width: 0; }
.combo.has-add > .list { right: 38px; }
.sel-add { display: flex; gap: 4px; align-items: stretch; }
.sel-add > select { flex: 1; min-width: 0; }
.add-btn { flex: none; min-width: 34px; min-height: 38px; font-weight: 700; font-size: 18px; line-height: 1; padding: 0 8px; color: var(--steel); }

/* number columns: header sits right above the amounts (".tbl th" / ".lines th" were forcing left) */
.tbl th.num, .lines th.num, .print-page th.num { text-align: right; }
/* entry lines: line the header up with the number inside the input (cell 4px + input border 1px + padding 10px) */
.lines th.num { padding-right: 15px; }
/* item lines: the Amount column (just before the remove button) shows plain text, not an input */
.lines th.num:nth-last-child(2) { padding-right: 4px; }
