html { overflow-x: hidden; }
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --red: #D0202A;
  --red-dark: #b01820;
  --bg: #F7F7F8;
  --card: #ffffff;
  --text: #1a1a1a;
  --muted: #6b7280;
  --border: #e5e7eb;
  --radius: 14px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
}

body {
  font-family: 'Titillium Web', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 32px 16px 64px;
  overflow-x: hidden; /* prevent 794px PDF preview from causing horizontal scroll */
}

/* ── Header ── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1200px;
  margin: 0 auto 36px;
}
.app-header h1 {
  font-size: 26px;
  font-weight: 700;
  color: var(--red);
  letter-spacing: -0.02em;
}
.app-header h1 span {
  font-weight: 300;
  color: var(--muted);
}

/* ── Layout ── */
.layout {
  display: grid;
  grid-template-columns: 3fr 7fr;
  gap: 24px;
  max-width: 1200px;
  margin: 0 auto;
  align-items: start;
  min-width: 0; /* prevent grid blowout */
}
.layout > * { min-width: 0; } /* both columns can shrink */

/* ── Panels ── */
.panel {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}
.panel h2 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--red);
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.panel h2::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ── Form elements ── */
.form-group { margin-bottom: 16px; }
.form-group:last-child { margin-bottom: 0; }
label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}
input, textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 9px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
input:focus, textarea:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(208,32,42,0.10);
  background: #fff;
}
.form-row { display: grid; grid-template-columns: 3fr 7fr; gap: 12px; }

/* ── Line items ── */
.line-item {
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 12px;
  position: relative;
}
.remove-btn {
  position: absolute;
  top: 10px; right: 12px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 6px;
  transition: background .15s, color .15s;
}
.remove-btn:hover { background: #fee2e2; color: var(--red); }


/* Grey inner area for klantgegevens fields */
.fields-inner {
  background: var(--bg);
  border-radius: 10px;
  padding: 16px;
  border: 1.5px solid var(--border);
}
/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 20px;
  border-radius: 99px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all .15s;
  font-family: inherit;
}
.btn-ghost {
  background: var(--bg);
  color: var(--text);
  border: 1.5px solid var(--border);
}
.btn-ghost:hover { border-color: var(--red); color: var(--red); background: #fff5f5; }
.btn-primary {
  background: var(--red);
  color: #fff;
  width: 100%;
  justify-content: center;
  padding: 13px 24px;
  font-size: 15px;
  border-radius: 12px;
  margin-top: 20px;
  box-shadow: 0 4px 14px rgba(208,32,42,0.25);
}
.btn-primary:hover { background: var(--red-dark); box-shadow: 0 6px 18px rgba(208,32,42,0.35); }
.btn-primary:active { transform: scale(0.99); }
.btn-primary:disabled { background: #ccc; box-shadow: none; cursor: not-allowed; }

/* ── Toeslagen ── */
.toeslag-grid { display: grid; grid-template-columns: 3fr 7fr; gap: 8px; }
.toeslag-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 9px;
  padding: 9px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color .15s;
  user-select: none;
}
.toeslag-item:has(input:checked) { border-color: var(--red); background: #fff5f5; }
.toeslag-item input { width: 15px; height: 15px; accent-color: var(--red); flex-shrink: 0; }

/* ── Preview ── */
.preview-wrapper { position: sticky; top: 24px; }
.preview-wrapper > h2 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.preview-wrapper > h2::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.pdf-scale-outer {
  background: #777;
  border-radius: 10px;
  padding: 12px;
  overflow: hidden;
  /* contain the scaled 794px child — never leak outside */
  max-width: 100%;
  width: 100%;
}
.pdf-scale-inner {
  transform-origin: top left;
  width: 794px;
  /* prevent the 794px inner from pushing the outer wider */
  position: relative;
  float: left;
}
/* clearfix so outer wraps the floated inner */
.pdf-scale-outer::after { content: ''; display: table; clear: both; }

/* ── Status ── */
#status { margin-top: 12px; font-size: 13px; color: var(--muted); text-align: center; min-height: 20px; }
.spinner {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid var(--border); border-top-color: var(--red);
  border-radius: 50%; animation: spin .7s linear infinite;
  margin-right: 6px; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ════════════════════════════════════════
   PAGE 2 PDF STYLES  (always 794px wide)
   ════════════════════════════════════════ */
.pdf-page-sheet {
  width: 794px;
  height: 1122px;
  overflow: hidden;
  padding: 52px 58px 52px;
  background: #fff;
  font-family: 'Titillium Web', sans-serif;
  font-size: 13px;
  color: #1a1a1a;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  position: relative;
}
.pdf-page-sheet + .pdf-page-sheet { margin-top: 8px; }
#pdf-page2 { width: 794px; }

.pdf-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 32px;
}
.pdf-header img { height: 56px; }
.pdf-company-info { text-align: right; font-size: 11.5px; line-height: 1.75; color: #333; }
.pdf-company-info .co-name { font-size: 13px; font-weight: 700; color: #1a1a1a; display: block; margin-bottom: 2px; }

.pdf-addresses {
  display: flex;
  justify-content: space-between;
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 1px solid #e0e0e0;
}
.pdf-client { font-size: 13px; line-height: 1.85; }
.pdf-client .client-name { font-size: 14px; font-weight: 700; display: block; }

.pdf-section-title {
  font-size: 22px;
  font-weight: 700;
  color: #D0202A;
  margin-bottom: 32px;
}

.pdf-table { width: 100%; border-collapse: collapse; margin-bottom: 0; }
.pdf-table th {
  background: #f5f5f5;
  padding: 10px 13px;
  text-align: left;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #555;
  border-bottom: 2px solid #ddd;
}
.pdf-table th:nth-child(3),
.pdf-table th:nth-child(4) { text-align: right; }
.pdf-table td {
  padding: 13px;
  border-bottom: 1px solid #f0f0f0;
  font-size: 12.5px;
  vertical-align: top;
  line-height: 1.5;
}
.pdf-table td:first-child { font-weight: 600; width: 76px; }
.pdf-table td:nth-child(3),
.pdf-table td:nth-child(4) { text-align: right; white-space: nowrap; }

.pdf-totals td { padding: 9px 13px; border-bottom: none; font-size: 12.5px; }
.pdf-totals td:nth-child(1) { text-align: right; color: #555; }
.pdf-totals td:nth-child(2) { text-align: right; font-weight: 700; white-space: nowrap; }
.pdf-totals .total-row-final td {
  font-weight: 700 !important;
  font-size: 13.5px !important;
  padding-top: 11px !important;
  border-top: 2px solid #1a1a1a !important;
}

.pdf-toeslagen {
  margin-top: 24px;
  padding: 16px 18px;
  background: #fafafa;
  border-radius: 6px;
  border-left: 4px solid #D0202A;
}
.pdf-toeslagen p { font-size: 11.5px; font-weight: 700; margin-bottom: 8px; }
.pdf-toeslagen li { font-size: 11.5px; margin-left: 16px; line-height: 2; }

.pdf-footer {
  margin-top: auto;
  padding-top: 32px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.pdf-footer img.keurmerk { height: 38px; }
.pdf-footer-note { font-size: 9.5px; color: #888; line-height: 1.6; }

/* ════════════════════════════════════════
   RESPONSIVE BREAKPOINTS
   ════════════════════════════════════════ */

/* Tablet — stack columns, hide preview (PDF not useful on small screen) */
@media (max-width: 1024px) {
  .layout { grid-template-columns: 1fr; } /* override 3fr/7fr */
  .preview-wrapper { position: static; }
}

/* Hide preview below 768px — it's unreadable at that scale */
@media (max-width: 768px) {
  .preview-wrapper {
    position: static;
    grid-row: 1; /* show preview above form on mobile */
  }
  .layout > div:first-child {
    grid-row: 2;
  }
  body { padding: 20px 12px 48px; }
  .app-header { margin-bottom: 24px; }
  .app-header h1 { font-size: 20px; }
  .panel { padding: 20px 16px; }
  /* Make preview header look tappable */
  .preview-toggle {
    cursor: pointer;
    user-select: none;
    background: var(--card);
    padding: 12px 16px;
    border-radius: 10px;
    margin-bottom: 0 !important;
  }
  .preview-toggle::after { display: none; } /* remove the hr line on mobile */
}

/* Small phone */
@media (max-width: 480px) {
  body { padding: 12px 10px 40px; }
  .app-header h1 { font-size: 18px; }
  .panel { padding: 16px 14px; }
  label { font-size: 11px; }
  input, textarea { font-size: 15px; padding: 11px 12px; } /* 15px prevents iOS zoom */

  /* Stack all 2-col rows */
  .form-row { grid-template-columns: 1fr; gap: 0; }
  .toeslag-grid { grid-template-columns: 1fr; }

  /* Line items: stack aantal/tarief */
  .line-item .form-row { grid-template-columns: 1fr; }

  .btn-primary { font-size: 15px; padding: 14px 20px; }
  .btn-ghost { font-size: 13px; }

  /* Toeslag items slightly more compact */
  .toeslag-item { font-size: 12px; padding: 10px 10px; }
}
