
:root{
  --bg:#f4f4f4;
  --card:#ffffff;
  --text:#161616;
  --muted:#6f6f6f;
  --border:#dddddd;
  --dark:#111111;
  --soft:#efefef;
}
*{box-sizing:border-box}
body{margin:0;font-family:Arial,Helvetica,sans-serif;background:var(--bg);color:var(--text)}
button,input,select,textarea{font:inherit}
button{cursor:pointer}
.topbar{display:flex;justify-content:space-between;align-items:center;padding:24px 34px;background:#111;color:white;position:sticky;top:0;z-index:10}
.topbar h1{margin:0;font-size:24px;letter-spacing:.5px}
.topbar p{margin:4px 0 0;color:#cfcfcf}
main{max-width:1450px;margin:0 auto;padding:28px}
.view{display:none}.view.active{display:block}
.primary,.secondary,.ghost{border-radius:10px;padding:11px 16px;border:1px solid transparent;font-weight:700}
.primary{background:#fff;color:#111}
.secondary{background:#111;color:white}
.ghost{background:white;border-color:#d5d5d5;color:#111}
.stats-grid{display:grid;grid-template-columns:repeat(6,minmax(150px,1fr));gap:14px;margin-bottom:22px}
.stat-card{background:white;border:1px solid var(--border);border-radius:16px;padding:18px}
.stat-card span{display:block;color:var(--muted);font-size:13px;margin-bottom:8px}
.stat-card strong{font-size:25px}
.stat-card.accent{background:#111;color:#fff}.stat-card.accent span{color:#cfcfcf}
.panel{background:white;border:1px solid var(--border);border-radius:18px;padding:20px}
.panel-head{display:flex;justify-content:space-between;gap:20px;align-items:center;margin-bottom:16px}
.panel-head h2{margin:0}.panel-head p{margin:5px 0 0;color:var(--muted)}
.panel-head input{min-width:320px;padding:11px 13px;border:1px solid var(--border);border-radius:10px}
.table-wrap{overflow:auto}
table{width:100%;border-collapse:collapse}
th,td{padding:12px 10px;border-bottom:1px solid #e8e8e8;text-align:left;vertical-align:middle}
th{font-size:12px;text-transform:uppercase;letter-spacing:.04em;color:#666}
td{font-size:14px}
.status-badge{display:inline-block;padding:5px 8px;border-radius:999px;background:#eee;font-size:12px;font-weight:700}
.action-btn{border:0;background:transparent;text-decoration:underline;margin-right:8px;padding:3px}
.editor-toolbar{display:flex;justify-content:space-between;align-items:center;margin-bottom:18px}
.toolbar-actions{display:flex;gap:10px}
.quote-sheet{background:white;border:1px solid var(--border);border-radius:18px;padding:32px}
.quote-header{display:flex;justify-content:space-between;gap:30px;border-bottom:2px solid #111;padding-bottom:24px;margin-bottom:24px}
.quote-header h2{margin:0 0 6px;font-size:24px}.quote-header p{margin:0;color:var(--muted)}
.quote-meta{display:grid;grid-template-columns:1fr 1fr;gap:10px;min-width:420px}
label{display:flex;flex-direction:column;gap:6px;font-size:12px;font-weight:700;color:#555}
input,select,textarea{width:100%;padding:10px 11px;border:1px solid var(--border);border-radius:9px;background:white;color:#111}
textarea{resize:vertical}
.form-grid{display:grid;gap:14px}.form-grid.two{grid-template-columns:1fr 1fr}
.items-head{display:flex;justify-content:space-between;align-items:center;margin-top:28px;margin-bottom:12px}
.items-head h3{margin:0}.items-head p{margin:4px 0 0;color:var(--muted)}
.items-table input,.items-table select{min-width:90px;padding:8px}
.items-table td:first-child input{min-width:260px}
.num{text-align:right}
.remove-line{border:0;background:transparent;font-size:18px}
.bottom-grid{display:grid;grid-template-columns:1.5fr .8fr;gap:24px;margin-top:24px}
.bottom-grid label{margin-bottom:14px}
.totals-card{border:1px solid var(--border);border-radius:14px;padding:18px;height:max-content}
.totals-card>div{display:flex;justify-content:space-between;padding:10px 0;border-bottom:1px solid #eee}
.totals-card>div:last-child{border-bottom:0}
.totals-card .grand{font-size:20px;padding-top:16px}
.acceptance{display:flex;justify-content:space-between;gap:20px;border-top:1px solid #ddd;margin-top:30px;padding-top:24px}
.empty{padding:34px;text-align:center;color:#777}
@media(max-width:1100px){
  .stats-grid{grid-template-columns:repeat(3,1fr)}
  .quote-header{flex-direction:column}
  .quote-meta{min-width:0}
}
@media(max-width:720px){
  main{padding:14px}.topbar{padding:18px}
  .stats-grid{grid-template-columns:1fr 1fr}
  .panel-head,.editor-toolbar{align-items:stretch;flex-direction:column}
  .panel-head input{min-width:0}
  .quote-sheet{padding:18px}
  .quote-meta,.form-grid.two,.bottom-grid{grid-template-columns:1fr}
}
@media print{
  body{background:#fff}
  main{padding:0;max-width:none}
  .no-print{display:none!important}
  #dashboardView{display:none!important}
  #editorView{display:block!important}
  .quote-sheet{border:0;border-radius:0;padding:0}
  input,select,textarea{border:0;padding:0;background:transparent;appearance:none}
  .items-table input,.items-table select{min-width:0}
  @page{size:A4;margin:12mm}
}


/* ===== V2 PRINT / PDF IMPROVEMENTS ===== */
.quote-header h2{
  font-size:28px;
  letter-spacing:.8px;
}
.quote-header > div:first-child p{
  font-size:16px;
  letter-spacing:.08em;
  text-transform:uppercase;
  color:#333;
}

@media print{
  html,body{
    width:210mm;
    min-height:297mm;
    margin:0;
    padding:0;
    background:#fff!important;
  }

  body{
    font-size:10.5pt;
  }

  main{
    padding:0!important;
    margin:0!important;
    max-width:none!important;
  }

  .quote-sheet{
    width:100%!important;
    margin:0!important;
    padding:0!important;
    border:0!important;
    box-shadow:none!important;
    overflow:visible!important;
  }

  .quote-header{
    display:grid!important;
    grid-template-columns:1.45fr .75fr!important;
    gap:18mm!important;
    align-items:start!important;
    border-bottom:1.5px solid #111!important;
    padding-bottom:7mm!important;
    margin-bottom:7mm!important;
  }

  .quote-header h2{
    margin:0 0 2mm!important;
    font-size:22pt!important;
    line-height:1!important;
    letter-spacing:.5px!important;
  }

  .quote-header > div:first-child p{
    margin:0!important;
    font-size:10.5pt!important;
    letter-spacing:.12em!important;
    text-transform:uppercase!important;
    color:#333!important;
  }

  .quote-meta{
    display:grid!important;
    grid-template-columns:1fr 1fr!important;
    gap:3mm!important;
    min-width:0!important;
  }

  .quote-meta label,
  .form-grid label,
  .bottom-grid label{
    font-size:8.5pt!important;
    color:#333!important;
    gap:1mm!important;
  }

  input,select,textarea{
    border:0!important;
    padding:0!important;
    background:transparent!important;
    box-shadow:none!important;
    color:#000!important;
    overflow:visible!important;
  }

  select{
    appearance:none!important;
    -webkit-appearance:none!important;
  }

  textarea{
    resize:none!important;
  }

  .form-grid.two{
    grid-template-columns:1fr 1fr!important;
    gap:5mm 10mm!important;
    border-bottom:1px solid #cfcfcf!important;
    padding-bottom:6mm!important;
    margin-bottom:6mm!important;
  }

  .items-head{
    margin:0 0 3mm!important;
  }

  .items-head h3{
    font-size:13pt!important;
    margin:0!important;
  }

  .table-wrap{
    overflow:visible!important;
  }

  .items-table{
    width:100%!important;
    table-layout:fixed!important;
    border-collapse:collapse!important;
    font-size:8.2pt!important;
  }

  .items-table th,
  .items-table td{
    padding:2.6mm 1.5mm!important;
    border-bottom:1px solid #d7d7d7!important;
    white-space:normal!important;
    overflow:visible!important;
    word-break:break-word!important;
  }

  .items-table th{
    font-size:7.4pt!important;
    color:#222!important;
  }

  .items-table th:nth-child(1){width:29%!important;}
  .items-table th:nth-child(2){width:9%!important;}
  .items-table th:nth-child(3){width:12%!important;}
  .items-table th:nth-child(4){width:10%!important;}
  .items-table th:nth-child(5){width:9%!important;}
  .items-table th:nth-child(6){width:14%!important;}
  .items-table th:nth-child(7){width:17%!important;}

  .items-table td:first-child input{
    min-width:0!important;
    width:100%!important;
  }

  .items-table input,
  .items-table select{
    min-width:0!important;
    width:100%!important;
    padding:0!important;
    font-size:8.2pt!important;
  }

  .items-table .num,
  .items-table td:nth-child(n+2){
    text-align:right!important;
  }

  .bottom-grid{
    display:grid!important;
    grid-template-columns:1.45fr .75fr!important;
    gap:8mm!important;
    margin-top:7mm!important;
    break-inside:avoid!important;
  }

  .bottom-grid textarea{
    font-size:8.5pt!important;
    line-height:1.3!important;
  }

  .totals-card{
    border:1px solid #ccc!important;
    border-radius:0!important;
    padding:4mm!important;
    break-inside:avoid!important;
  }

  .totals-card>div{
    padding:2.4mm 0!important;
    font-size:9.5pt!important;
  }

  .totals-card .grand{
    font-size:13pt!important;
    padding-top:4mm!important;
  }

  .acceptance{
    margin-top:8mm!important;
    padding-top:5mm!important;
    border-top:1px solid #bbb!important;
    font-size:9pt!important;
    break-inside:avoid!important;
  }

  /* Never show scrollbars or action columns in PDF */
  .table-wrap::-webkit-scrollbar{display:none!important;}
  .table-wrap{scrollbar-width:none!important;}
}


/* ===== V3: FORCE QUOTATION TO STAY ON ONE A4 PAGE ===== */
@media print {
  @page { size: A4 portrait; margin: 7mm; }

  html, body {
    width: 210mm !important;
    min-height: 0 !important;
    height: auto !important;
    overflow: visible !important;
  }

  .quote-sheet{
    page-break-inside: avoid !important;
    break-inside: avoid-page !important;
    transform-origin: top left !important;
  }

  .quote-header{
    padding-bottom: 4mm !important;
    margin-bottom: 4mm !important;
    gap: 10mm !important;
  }

  .quote-header h2{
    font-size: 19pt !important;
  }

  .quote-header > div:first-child p{
    font-size: 9pt !important;
  }

  .quote-meta{
    gap: 1.8mm 3mm !important;
  }

  .form-grid.two{
    gap: 3mm 8mm !important;
    padding-bottom: 4mm !important;
    margin-bottom: 4mm !important;
  }

  .items-head{
    margin: 0 0 1.5mm !important;
  }

  .items-head h3{
    font-size: 11.5pt !important;
  }

  .items-table th,
  .items-table td{
    padding-top: 1.55mm !important;
    padding-bottom: 1.55mm !important;
    line-height: 1.08 !important;
  }

  .bottom-grid{
    gap: 5mm !important;
    margin-top: 4mm !important;
  }

  .bottom-grid label{
    margin-bottom: 2.5mm !important;
  }

  .bottom-grid textarea{
    line-height: 1.12 !important;
  }

  .totals-card{
    padding: 3mm !important;
  }

  .totals-card>div{
    padding: 1.5mm 0 !important;
  }

  .totals-card .grand{
    padding-top: 2.5mm !important;
  }

  .acceptance{
    margin-top: 4mm !important;
    padding-top: 3mm !important;
  }

  /* Density levels based on number of service lines */
  body.print-compact .quote-sheet{ zoom: .92; }
  body.print-compact .items-table th,
  body.print-compact .items-table td{ padding-top: 1.15mm !important; padding-bottom: 1.15mm !important; }
  body.print-compact .bottom-grid{ margin-top: 3mm !important; }
  body.print-compact .acceptance{ margin-top: 3mm !important; }

  body.print-dense .quote-sheet{ zoom: .84; }
  body.print-dense .items-table{ font-size: 7.7pt !important; }
  body.print-dense .items-table th,
  body.print-dense .items-table td{ padding-top: .85mm !important; padding-bottom: .85mm !important; }
  body.print-dense .quote-header{ margin-bottom: 3mm !important; padding-bottom: 3mm !important; }
  body.print-dense .form-grid.two{ margin-bottom: 3mm !important; padding-bottom: 3mm !important; }
  body.print-dense .bottom-grid{ margin-top: 2.5mm !important; }
  body.print-dense .acceptance{ margin-top: 2.5mm !important; }

  body.print-ultra .quote-sheet{ zoom: .76; }
  body.print-ultra .items-table{ font-size: 7.1pt !important; }
  body.print-ultra .items-table th,
  body.print-ultra .items-table td{ padding-top: .55mm !important; padding-bottom: .55mm !important; }
  body.print-ultra .bottom-grid textarea{ font-size: 7.8pt !important; }
  body.print-ultra .acceptance{ font-size: 8pt !important; }

  /* Hide empty helper placeholders from printed PDF */
  textarea::placeholder, input::placeholder{ color: transparent !important; }

  /* Prevent accidental second page caused by fixed textarea sizing */
  #notes, #terms{
    min-height: 0 !important;
    height: auto !important;
  }
}


/* ===== V4: larger, more readable A4 quotation ===== */
@media print {
  /* Default / 1-4 lines: approximately 22% larger than V3 */
  .quote-sheet { zoom: 1.00 !important; }

  .quote-header h2 { font-size: 23pt !important; }
  .quote-header > div:first-child p { font-size: 10.5pt !important; }

  .quote-meta label,
  .form-grid label,
  .bottom-grid label { font-size: 9.3pt !important; }

  .quote-meta input,
  .quote-meta select,
  .form-grid input { font-size: 10pt !important; }

  .items-head h3 { font-size: 13.5pt !important; }

  .items-table { font-size: 9.5pt !important; }
  .items-table th { font-size: 8.4pt !important; }
  .items-table input,
  .items-table select { font-size: 9.5pt !important; }

  .items-table th,
  .items-table td {
    padding-top: 2.0mm !important;
    padding-bottom: 2.0mm !important;
  }

  .bottom-grid textarea {
    font-size: 9.3pt !important;
    line-height: 1.22 !important;
  }

  .totals-card > div { font-size: 10.5pt !important; }
  .totals-card .grand { font-size: 14.5pt !important; }
  .acceptance { font-size: 9.5pt !important; }

  /* 5-7 lines: still large, only slight compression */
  body.print-compact .quote-sheet { zoom: .98 !important; }
  body.print-compact .items-table { font-size: 9.1pt !important; }
  body.print-compact .items-table th { font-size: 8.1pt !important; }
  body.print-compact .items-table input,
  body.print-compact .items-table select { font-size: 9.1pt !important; }
  body.print-compact .items-table th,
  body.print-compact .items-table td {
    padding-top: 1.55mm !important;
    padding-bottom: 1.55mm !important;
  }

  /* 8-10 lines: moderate compression to preserve one page */
  body.print-dense .quote-sheet { zoom: .90 !important; }
  body.print-dense .items-table { font-size: 8.4pt !important; }
  body.print-dense .items-table th { font-size: 7.7pt !important; }
  body.print-dense .items-table input,
  body.print-dense .items-table select { font-size: 8.4pt !important; }
  body.print-dense .items-table th,
  body.print-dense .items-table td {
    padding-top: 1.1mm !important;
    padding-bottom: 1.1mm !important;
  }

  /* 11+ lines: stronger compression only when necessary */
  body.print-ultra .quote-sheet { zoom: .82 !important; }
  body.print-ultra .items-table { font-size: 7.7pt !important; }
  body.print-ultra .items-table th { font-size: 7.1pt !important; }
  body.print-ultra .items-table input,
  body.print-ultra .items-table select { font-size: 7.7pt !important; }
  body.print-ultra .items-table th,
  body.print-ultra .items-table td {
    padding-top: .7mm !important;
    padding-bottom: .7mm !important;
  }
}
