/*
 * FlowCAD3D — "Calculatie en offerte" (js/ui/estimate-view.js), column mapping (js/ui/import-mapper.js) and
 * "Leidinglijst importeren" (js/ui/linelist-dialog.js). Uses the theme variables of css/app.css (light and dark).
 * The quotation (.est-q) has a fixed paper look (white, dark text) on screen and in print.
 */

/* ---------- dialog ---------- */
.modal.est-modal { width: min(1280px, 100%); height: calc(100vh - 32px); }
@supports (height: 100dvh) { .modal.est-modal { height: calc(100dvh - 32px - var(--safe-t, 0px) - var(--safe-b, 0px)); } }
.modal.est-modal .mb { padding-top: 0; }
.est-dlg { display: flex; flex-direction: column; gap: 6px; min-height: 100%; }
.est-banner { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 10px 0 0; padding: 6px 10px; border-radius: 6px; background: var(--ban-warn-bg); color: var(--ban-warn-fg); }
.est-badge { display: inline-flex; align-items: center; padding: 1px 8px; border-radius: 10px; background: var(--warn); color: #111; font-size: 12px; font-weight: 700; white-space: nowrap; }
.est-tabs { position: sticky; top: 0; z-index: 3; background: var(--bg2); margin: 0 -16px; padding: 6px 16px 0; }
.est-content { padding: 8px 0 12px; }
.est-h3 { font-size: 16px; margin: 16px 0 6px; }
.est-bar { margin: 6px 0; gap: 8px; }
.est-chk { cursor: pointer; min-height: 32px; gap: 6px; }
.est-chk input { width: 18px; height: 18px; }
body.mode-touch .est-chk { min-height: 44px; padding: 0 12px; }
body.mode-touch .est-chk input { width: 24px; height: 24px; }

/* KPI tiles */
.est-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin: 8px 0 10px; }
.est-tile { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; background: var(--bg3); min-width: 0; }
.est-tile-k { font-size: 12px; color: var(--fg2); }
.est-tile-v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; margin: 2px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.est-tile-s { font-size: 12px; color: var(--fg3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.est-tile.est-t-total { border-color: var(--accent); background: var(--accentbg); }
.est-tile.est-t-spool .est-tile-s { color: var(--fg2); }

/* tables */
.est-wrap { margin: 6px 0 4px; max-width: 100%; }
.est-tbl td { vertical-align: middle; }
.est-tbl tfoot td { font-weight: 700; border-top: 2px solid var(--line2); background: var(--bg3); }
.est-tbl td.num, .est-tbl th.num { white-space: nowrap; }
.est-totals { max-width: 640px; }
.est-wrap:has(> .est-totals) { max-width: 640px; }
body:not(.mode-touch) .est-tbl .inp { min-height: 30px; padding: 2px 6px; }
.est-totals tr.est-sub td { font-weight: 600; background: var(--bg3); }
.est-totals tr.est-grand td { font-weight: 700; font-size: 14px; border-top: 2px solid var(--fg2); }
.est-tbl tr.est-unmatched td { background: rgba(220, 38, 38, .07); }
.est-tbl tr.est-unmatched td:first-child { box-shadow: inset 3px 0 0 var(--err); }
.est-tbl tr.est-largest td { background: var(--ban-warn-bg); color: var(--ban-warn-fg); }
.est-src { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 12px; white-space: nowrap; background: var(--bg4); }
.est-src.id, .est-src.attr, .est-src.desc { background: var(--ban-ok-bg); color: var(--ban-ok-fg); }
.est-src.manual { background: var(--accentbg); color: var(--fg); border: 1px solid var(--accent); }
.est-src.none { background: rgba(220, 38, 38, .14); color: var(--danger-fg); font-weight: 600; }
.est-unitwarn { color: var(--warn); }
.est-num { width: 96px; text-align: right; font-variant-numeric: tabular-nums; }
.est-num.est-price { width: 112px; }
.est-num.est-disc { width: 72px; }
.est-mat .inp::placeholder { color: var(--fg3); font-style: italic; }
.est-extras .inp:not(.est-num) { min-width: 180px; }
:is(.est-dlg, .est-pl-dlg, .ll-dlg) .chip.ok { background: var(--ban-ok-bg); color: var(--ban-ok-fg); }
:is(.est-dlg, .est-pl-dlg, .ll-dlg) .chip.warn { background: var(--ban-warn-bg); color: var(--ban-warn-fg); }
:is(.est-dlg, .est-pl-dlg, .ll-dlg) .chip.err { background: rgba(220, 38, 38, .14); color: var(--danger-fg); }
:is(.est-dlg, .est-pl-dlg, .ll-dlg) .chip.info { background: var(--accentbg); }

/* inputs with a label above */
.est-rates { gap: 12px; align-items: flex-end; margin: 6px 0; }
.est-fld { display: inline-flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--fg2); }
.est-fld > span { white-space: nowrap; }
.est-fld .inp { color: var(--fg); }

/* norms */
.est-norms { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; margin-top: 8px; }
.est-nbox { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px 10px; background: var(--bg2); min-width: 0; }
.est-nbox.wide { grid-column: 1 / -1; }
.est-nbox h4 { margin: 2px 0 6px; font-size: 14px; }
.est-band .tblwrap { margin-bottom: 6px; }
.est-bandtbl .est-num { width: 100%; min-width: 72px; }

/* quotation tab */
.est-qlayout { display: grid; grid-template-columns: minmax(280px, 400px) 1fr; gap: 16px; align-items: start; }
.est-qform { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px 10px; }
.est-qform > * { min-width: 0; }
.est-qform .est-fld { display: flex; }
.est-qform .full { grid-column: 1 / -1; }
.est-paper { background: #FFFFFF; color: var(--ink); border: 1px solid var(--line2); border-radius: 4px; box-shadow: var(--shadow); padding: 28px 30px; max-width: 820px; overflow: auto; }
@media (max-width: 1000px) { .est-qlayout { grid-template-columns: 1fr; } }
@media (max-width: 560px) { .est-qform { grid-template-columns: minmax(0, 1fr); } .est-paper { padding: 16px; } .est-tile-v { font-size: 18px; } }

/* ---------- quotation (screen preview and print) ---------- */
.est-q { font-family: var(--fc-font); font-size: 13px; line-height: 1.45; color: var(--ink); background: #FFFFFF; }
.est-q-head { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; border-bottom: 2px solid #0B1E3A; padding-bottom: 12px; margin-bottom: 16px; }
.est-q-logo { max-height: 60px; max-width: 220px; display: block; margin-bottom: 6px; }
.est-q-coname { font-size: 16px; font-weight: 700; color: var(--ink); }
.est-q-coaddr { color: var(--ink2); font-size: 12px; }
.est-q-title { text-align: right; }
.est-q-title h1 { margin: 0 0 6px; font-size: 24px; letter-spacing: .06em; color: var(--ink); }
.est-q-meta { border-collapse: collapse; margin-left: auto; font-size: 12px; }
.est-q-meta th { text-align: left; font-weight: 600; color: var(--ink2); padding: 1px 10px 1px 0; }
.est-q-meta td { text-align: right; padding: 1px 0; }
.est-q-to { margin: 0 0 12px; }
.est-q-lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink3); }
.est-q-cust { font-weight: 700; font-size: 14px; }
.est-q-proj { margin: 8px 0; }
.est-q-intro { margin: 10px 0 14px; }
.est-q-tbl { width: 100%; border-collapse: collapse; margin: 6px 0 16px; }
.est-q-tbl th { text-align: left; border-bottom: 1.5px solid #0B1E3A; padding: 5px 4px; font-size: 12px; color: var(--ink); }
.est-q-tbl td { padding: 5px 4px; border-bottom: 1px solid #E5E7EB; }
.est-q-tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.est-q-tbl tfoot td { border-bottom: 0; }
.est-q-tbl tfoot tr:first-child td { border-top: 1.5px solid #0B1E3A; }
.est-q-tbl tr.est-q-grand td { font-weight: 700; font-size: 14px; border-top: 1px solid #0B1E3A; }
.est-q-sub { color: var(--ink3); font-size: 12px; }
.est-q-terms h3 { font-size: 13px; margin: 10px 0 2px; color: var(--ink); }
.est-q-terms p { margin: 0 0 6px; }
.est-q-sign { margin: 22px 0 18px; }
.est-q-foot { border-top: 1px solid #D1D5DB; padding-top: 6px; font-size: 11px; color: var(--ink3); text-align: center; }

#est-print { display: none; }
@media print {
  @page { size: A4 portrait; margin: 16mm 15mm 14mm; }
  body.est-printing { background: #FFFFFF !important; }
  body.est-printing > *:not(#est-print) { display: none !important; }
  body.est-printing > #est-print { display: block !important; position: static; }
  body.est-printing #est-print, body.est-printing #est-print * { visibility: visible !important; }
  body.est-printing .est-q { font-size: 10.5pt; }
  body.est-printing .est-q-tbl tr, body.est-printing .est-q-terms, body.est-printing .est-q-sign { break-inside: avoid; }
  body.est-printing .est-q-foot { margin-top: 18px; }
}

/* ---------- column mapping (import-mapper) ---------- */
.imp-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.imp-top .field { grid-template-columns: auto 160px; margin: 0; }
.imp-top .imp-hdr { grid-template-columns: auto 90px; }
.imp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 4px 16px; }
.imp-row { display: grid; grid-template-columns: 150px 1fr; grid-template-rows: auto auto; align-items: center; gap: 0 8px; padding: 3px 0; border-bottom: 1px dashed var(--line); min-width: 0; }
.imp-row .imp-lbl { font-size: 13px; color: var(--fg2); }
.imp-row select.inp { min-width: 0; }
.imp-row .imp-smp { grid-column: 2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-height: 14px; }
.imp-row.missing .imp-lbl { color: var(--danger-fg); font-weight: 600; }
@media (max-width: 560px) { .imp-grid { grid-template-columns: 1fr; } .imp-row { grid-template-columns: 120px 1fr; } }

/* ---------- line list import ---------- */
.modal.ll-modal, .modal.est-pl-modal { width: min(1200px, 100%); }
.ll-moderow { margin: 8px 0; }
.ll-mode .btn { min-height: 36px; }
body.mode-touch .ll-mode .btn { min-height: 44px; }
.ll-specs { margin: 6px 0; }
.ll-counts { margin: 6px 0; }
.ll-wrap, .est-pl-dlg .tblwrap { max-height: 46vh; }
.ll-badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--bg4); }
.ll-badge.new { background: var(--ban-ok-bg); color: var(--ban-ok-fg); }
.ll-badge.update { background: var(--accentbg); color: var(--fg); border: 1px solid var(--accent); }
.ll-badge.error { background: rgba(220, 38, 38, .14); color: var(--danger-fg); }
.ll-tbl tr.ll-error td { background: rgba(220, 38, 38, .05); }
.ll-err { color: var(--danger-fg); font-size: 12px; }
.ll-warn { color: var(--warn); font-size: 12px; }
.est-fld .est-pickcust { align-self: flex-start; margin-top: 4px; }
.est-custlist { max-height: 50vh; overflow: auto; margin-top: 8px; }
.est-custrow { cursor: pointer; }
.est-warns .note { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
