*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --brand:       #1a56a4;
  --brand-light: #e8f0fb;
  --text:        #1a1a2e;
  --muted:       #6b7280;
  --border:      #d1d5db;
  --bg:          #f3f4f8;
  --white:       #ffffff;
  --radius:      6px;
  --shadow:      0 2px 16px rgba(26,86,164,.08);
}

/* ── Dark mode ── */
html.dark {
  --brand:       #3b82f6;
  --brand-light: #1e3a5f;
  --text:        #e5e7eb;
  --muted:       #9ca3af;
  --border:      #374151;
  --bg:          #111827;
  --white:       #1f2937;
  --shadow:      0 2px 16px rgba(0,0,0,.4);
}

/* ── High contrast ── */
html.high-contrast {
  --brand:       #0040c0;
  --brand-light: #d0e4ff;
  --text:        #000000;
  --muted:       #333333;
  --border:      #000000;
  --bg:          #ffffff;
  --white:       #ffffff;
}
html.dark.high-contrast {
  --brand:       #66aaff;
  --brand-light: #003366;
  --text:        #ffffff;
  --muted:       #cccccc;
  --border:      #ffffff;
  --bg:          #000000;
  --white:       #111111;
}
html.high-contrast .field input,
html.high-contrast .field select,
html.high-contrast .field textarea,
html.high-contrast .doc-input,
html.high-contrast .line-input {
  border-color: var(--border) !important;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  min-height: 100vh;
}

/* ── Top bar ── */
.topbar {
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 200;
  box-shadow: 0 2px 8px rgba(26,86,164,.25);
}

.topbar-logo {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -.3px;
  color: #fff;
  text-decoration: none;
  flex-shrink: 0;
}
.topbar-logo span { color: #93c5fd; }

.topbar-actions { display: flex; gap: 8px; align-items: center; }

.save-indicator {
  font-size: 12px;
  color: #86efac;
  opacity: 0;
  transition: opacity .3s;
  white-space: nowrap;
  margin-right: 4px;
}
.save-indicator.visible { opacity: 1; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background .15s, box-shadow .15s;
  text-decoration: none;
}
.btn-primary { background: #fff; color: var(--brand); }
.btn-primary:hover { background: #dbeafe; }

.btn-outline {
  background: transparent;
  color: #fff;
  border: 1.5px solid rgba(255,255,255,.5);
}
.btn-outline:hover { background: rgba(255,255,255,.15); }

.btn-icon {
  background: transparent;
  border: none;
  color: rgba(255,255,255,.85);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s;
}
.btn-icon:hover { background: rgba(255,255,255,.15); color: #fff; }

.btn-sm {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  background: var(--white);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.btn-sm:hover { border-color: var(--brand); background: var(--brand-light); color: var(--brand); }

/* ── Page layout ── */
.page {
  max-width: 1180px;
  margin: 28px auto 80px;
  padding: 0 20px;
  display: flex;
  gap: 24px;
  align-items: flex-start;
}

.invoice-main { flex: 1; min-width: 0; }

/* ── Invoice card ── */
.invoice-card {
  background: var(--white);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* ── Invoice top ── */
.invoice-top {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 24px;
  padding: 28px 40px 24px;
  border-bottom: 1px solid var(--border);
}

.invoice-label {
  font-size: 28px;
  font-weight: 800;
  color: var(--brand);
  letter-spacing: -.5px;
  margin-bottom: 16px;
}

/* ── Input fields ── */
.field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 8px;
}
.field label {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .6px;
}
.field input, .field select, .field textarea {
  border: 1.5px solid transparent;
  border-radius: var(--radius);
  padding: 6px 8px;
  font-size: 13px;
  color: var(--text);
  background: transparent;
  transition: border-color .15s, background .15s;
  width: 100%;
  font-family: inherit;
}
.field input:hover, .field select:hover { border-color: var(--border); background: var(--bg); }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--brand);
  background: var(--brand-light);
}
.field input::placeholder, .field textarea::placeholder { color: #c4c8d4; }

/* ── Document-style inputs ── */
.doc-input {
  display: block;
  width: 100%;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.65;
  color: var(--text);
  background: transparent;
  border: 1.5px solid transparent;
  border-radius: 4px;
  padding: 1px 6px;
  transition: border-color .15s, background .15s;
}
.doc-input:hover { border-color: var(--border); background: var(--bg); }
.doc-input:focus { outline: none; border-color: var(--brand); background: var(--brand-light); }
.doc-input::placeholder { color: #c4c8d4; }
.doc-company { font-size: 15px; font-weight: 700; margin-bottom: 1px; }
.doc-spacer { margin-top: 8px; }
.doc-meta-row { display: flex; align-items: center; gap: 4px; }
.doc-prefix { font-size: 11px; color: var(--muted); font-weight: 600; min-width: 30px; padding-left: 6px; flex-shrink: 0; }
.doc-inline { flex: 1; }
.client-doc-block { display: flex; flex-direction: column; }
.invoice-meta { min-width: 220px; }

/* ── Client / body section ── */
.invoice-body { padding: 28px 40px 20px; border-bottom: 1px solid var(--border); }
.section-label { font-size: 10px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .8px; margin-bottom: 10px; }

/* ── Line items ── */
.invoice-lines { padding: 0 40px 20px; border-bottom: 1px solid var(--border); }
.lines-table { width: 100%; border-collapse: collapse; margin-top: 4px; }
.lines-table th {
  text-align: left;
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .6px;
  padding: 6px 8px;
  border-bottom: 1.5px solid var(--border);
}
.lines-table th.col-handle { width: 28px; }
.lines-table th.col-desc { width: auto; }
.lines-table th.col-qty { width: 70px; text-align: right; }
.lines-table th.col-price { width: 90px; text-align: right; }
.lines-table th.col-vat { width: 70px; text-align: center; }
.lines-table th.col-total { width: 90px; text-align: right; }
.lines-table th.col-del { width: 32px; }
.lines-table td { padding: 4px 4px; border-bottom: 1px solid var(--bg); vertical-align: middle; }
.lines-table td:first-child { padding-left: 0; }

.line-input {
  border: 1.5px solid transparent;
  border-radius: var(--radius);
  padding: 6px 8px;
  font-size: 13px;
  color: var(--text);
  background: transparent;
  width: 100%;
  font-family: inherit;
  transition: border-color .15s, background .15s;
}
.line-input:hover { border-color: var(--border); background: var(--bg); }
.line-input:focus { outline: none; border-color: var(--brand); background: var(--brand-light); }
.num-input { text-align: right; }
.vat-select { text-align: center; cursor: pointer; }
.line-total { text-align: right; font-weight: 600; padding-right: 8px; white-space: nowrap; font-size: 13px; }
.drag-handle { cursor: grab; color: #c4c8d4; font-size: 16px; text-align: center; user-select: none; padding: 0 4px; }
.drag-handle:hover { color: var(--brand); }
.row-ghost { opacity: .4; background: var(--brand-light); }
.btn-remove-line {
  background: none; border: none; color: #c4c8d4; cursor: pointer; font-size: 14px;
  padding: 4px 6px; border-radius: 4px; transition: color .15s, background .15s;
  display: flex; align-items: center;
}
.btn-remove-line:hover { color: #ef4444; background: #fef2f2; }
.add-line-row { padding: 14px 0 4px; }
.btn-add-line {
  background: none; border: 1.5px dashed var(--border); color: var(--brand);
  font-size: 13px; font-weight: 600; padding: 7px 16px; border-radius: var(--radius);
  cursor: pointer; transition: border-color .15s, background .15s;
}
.btn-add-line:hover { border-color: var(--brand); background: var(--brand-light); }

/* ── Totals ── */
.invoice-totals { padding: 20px 40px; display: flex; justify-content: flex-end; border-bottom: 1px solid var(--border); }
#totals-block { min-width: 280px; }
.total-row { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; font-size: 13px; }
.vat-row { color: var(--muted); font-size: 12px; }
.grand-total { font-size: 15px; font-weight: 700; padding-top: 8px; margin-top: 4px; border-top: 2px solid var(--text); }

/* ── Notes / footer ── */
.invoice-footer { padding: 20px 40px 32px; }
.field textarea { resize: vertical; min-height: 60px; line-height: 1.5; }

/* ── Asperion promo ── */
.promo-bar {
  background: var(--brand-light);
  border-top: 1px solid #bfdbfe;
  padding: 18px 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
html.dark .promo-bar { border-top-color: #1e3a5f; }
.promo-bar p { font-size: 13px; color: var(--brand); }
.promo-bar strong { font-weight: 700; }
.promo-bar a {
  white-space: nowrap; background: var(--brand); color: #fff;
  padding: 8px 16px; border-radius: var(--radius); text-decoration: none;
  font-size: 13px; font-weight: 600; flex-shrink: 0;
}
.promo-bar a:hover { opacity: .9; }

/* ── Site footer ── */
.site-footer { text-align: center; font-size: 11px; color: var(--muted); margin-top: 20px; padding-bottom: 32px; }
.site-footer a, .link-terms { color: var(--brand); text-decoration: none; cursor: pointer; }
.site-footer a:hover, .link-terms:hover { text-decoration: underline; }

/* ── Logo ── */
.logo-area { margin-bottom: 10px; }
.logo-preview { min-height: 0; margin-bottom: 4px; }
.logo-preview img { max-width: 200px; max-height: 80px; object-fit: contain; display: block; border-radius: 3px; }
.logo-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.logo-btn {
  display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600;
  color: var(--brand); cursor: pointer; padding: 4px 8px; border: 1.5px solid var(--border);
  border-radius: var(--radius); background: none; transition: border-color .15s, background .15s;
  font-family: inherit; line-height: 1;
}
.logo-btn:hover { border-color: var(--brand); background: var(--brand-light); }
.logo-remove-btn { color: #ef4444; border-color: #fecaca; }
.logo-remove-btn:hover { background: #fef2f2; border-color: #ef4444; }

/* ── Invoice sidebar ── */
.invoice-sidebar {
  width: 272px;
  flex-shrink: 0;
  background: var(--white);
  border-radius: 12px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 80px);
  position: sticky;
  top: 68px;
  overflow: hidden;
}

.sidebar-header {
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  flex: 1;
  white-space: nowrap;
}

.year-filter {
  font-size: 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 6px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
}
.year-filter:focus { outline: none; border-color: var(--brand); }

.invoice-list-items {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px;
}

.list-empty {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 24px 12px;
  line-height: 1.5;
}

.inv-list-item {
  position: relative;
  padding: 9px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .12s;
  border: 1.5px solid transparent;
  margin-bottom: 3px;
}
.inv-list-item:hover { background: var(--bg); }
.inv-list-item.active { background: var(--brand-light); border-color: var(--brand); }

.inv-item-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 2px;
}

.inv-item-num {
  font-size: 12px;
  font-weight: 700;
  color: var(--brand);
  white-space: nowrap;
}
.inv-list-item.active .inv-item-num { color: var(--brand); }

.inv-item-amount {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.inv-item-client {
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.no-client { color: var(--muted); font-style: italic; }

.inv-item-date {
  font-size: 11px;
  color: var(--muted);
}

.inv-item-delete {
  position: absolute;
  top: 7px;
  right: 6px;
  background: none;
  border: none;
  color: transparent;
  font-size: 11px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 3px;
  line-height: 1;
  transition: color .12s, background .12s;
}
.inv-list-item:hover .inv-item-delete { color: #c4c8d4; }
.inv-item-delete:hover { color: #ef4444 !important; background: #fef2f2; }

/* Pagination */
.list-pagination {
  padding: 8px 8px;
  display: flex;
  gap: 3px;
  justify-content: center;
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.page-btn {
  background: var(--bg);
  border: 1.5px solid var(--border);
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: border-color .12s, background .12s;
  min-width: 28px;
}
.page-btn:hover:not(:disabled) { border-color: var(--brand); background: var(--brand-light); color: var(--brand); }
.page-btn.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.page-btn:disabled { opacity: .4; cursor: default; }

/* ── Modals ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 400;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; }

.modal-box {
  background: var(--white);
  border-radius: 12px;
  box-shadow: 0 8px 40px rgba(0,0,0,.2);
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-box--wide { max-width: 560px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h2 { font-size: 16px; font-weight: 700; color: var(--text); }

.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background .12s, color .12s;
  line-height: 1;
}
.modal-close:hover { background: var(--bg); color: var(--text); }

.modal-body {
  padding: 16px 20px 20px;
  overflow-y: auto;
}

/* Settings modal */
.setting-group { margin-bottom: 20px; }
.setting-group-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--muted);
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
}
.setting-label { display: flex; flex-direction: column; gap: 2px; }
.setting-label span { font-size: 13px; font-weight: 600; color: var(--text); }
.setting-label small { font-size: 11px; color: var(--muted); }
.modal-footer-note { margin-top: 4px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); padding-top: 14px; }

/* Toggle switch */
.toggle-switch { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.toggle-switch input { display: none; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 24px;
  cursor: pointer;
  transition: background .2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle-switch input:checked + .toggle-slider { background: var(--brand); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(20px); }

/* Terms modal */
.terms-body h3 { font-size: 14px; font-weight: 700; color: var(--text); margin: 16px 0 6px; }
.terms-body h3:first-child { margin-top: 0; }
.terms-body p { font-size: 13px; color: var(--muted); line-height: 1.6; }
.terms-body a { color: var(--brand); text-decoration: none; }
.terms-body a:hover { text-decoration: underline; }
.terms-body strong { color: var(--text); }

/* ── Cookie banner ── */
.cookie-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--white);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 12px rgba(0,0,0,.1);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 20px;
}
.cookie-content {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 700px;
  width: 100%;
}
.cookie-content p { font-size: 12px; color: var(--muted); line-height: 1.5; flex: 1; }
.cookie-content a { color: var(--brand); text-decoration: none; }
.cookie-content a:hover { text-decoration: underline; }
.btn-sm-cookie {
  padding: 6px 14px;
  font-size: 12px;
  flex-shrink: 0;
}

/* ── Responsive ── */
@media (max-width: 900px) {
  .invoice-sidebar { width: 240px; }
}

@media (max-width: 767px) {
  .page { flex-direction: column; margin-top: 16px; padding: 0 8px; }
  .invoice-main { width: 100%; }

  /* Mobile: sidebar is an overlay */
  .invoice-sidebar {
    position: fixed;
    top: 0;
    right: -100%;
    bottom: 0;
    width: 300px;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
    z-index: 350;
    transition: right .25s ease;
    box-shadow: -4px 0 24px rgba(0,0,0,.2);
  }
  .invoice-sidebar.open { right: 0; }

  /* Backdrop for mobile sidebar */
  .invoice-sidebar.open::before {
    content: '';
    position: fixed;
    inset: 0;
    right: 300px;
    background: rgba(0,0,0,.4);
    z-index: -1;
  }

  .invoice-top { grid-template-columns: 1fr; padding: 24px 20px 20px; }
  .invoice-body { padding: 20px 20px 16px; }
  .invoice-lines { padding: 0 12px 16px; }
  .invoice-totals { padding: 16px 20px; }
  .invoice-footer { padding: 16px 20px 24px; }
  .promo-bar { flex-direction: column; align-items: flex-start; padding: 16px 20px; }

  .lines-table th.col-price, .lines-table td:nth-child(4) { display: none; }

  .btn-label { display: none; }
}

@media (min-width: 768px) {
  #btn-toggle-sidebar { display: none; }
}

/* ── Brand color picker ── */
.color-picker-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  flex-shrink: 0;
}
.color-picker-label input[type="color"] {
  width: 34px;
  height: 34px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  padding: 2px;
  background: none;
  -webkit-appearance: none;
  appearance: none;
}
.color-picker-label input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; border-radius: 4px; }
.color-picker-label input[type="color"]::-webkit-color-swatch { border: none; border-radius: 4px; }
.color-preview-hex {
  font-size: 12px;
  color: var(--muted);
  font-family: 'Courier New', Courier, monospace;
  letter-spacing: .3px;
}

/* ── Layout picker ── */
.setting-row--block {
  flex-direction: column;
  align-items: flex-start;
}
.layout-picker {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  width: 100%;
}
.layout-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: none;
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  min-width: 80px;
  font-family: inherit;
}
.layout-btn:hover { border-color: var(--brand); color: var(--brand); }
.layout-btn.active { border-color: var(--brand); background: var(--brand-light); color: var(--brand); }

/* Layout thumbnail previews */
.layout-thumb {
  width: 56px;
  height: 70px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: #ffffff;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}
html.dark .layout-thumb { background: #374151; }

/* Klassiek: horizontal line rows + thin grey footer line */
.layout-thumb--1::before {
  content: '';
  position: absolute;
  left: 6px; right: 6px;
  top: 20px; height: 1.5px;
  background: var(--border);
}
.layout-thumb--1::after {
  content: '';
  position: absolute;
  bottom: 10px;
  left: 0; right: 0; height: 1px;
  background: #cccccc;
}

/* Professioneel: brand colored table header + brand footer bar */
.layout-thumb--2::before {
  content: '';
  position: absolute;
  left: 0; right: 0;
  top: 20px; height: 8px;
  background: var(--thumb-brand, #1a56a4);
}
.layout-thumb--2::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0; right: 0; height: 10px;
  background: var(--thumb-brand, #1a56a4);
}

/* Modern: thin colored top accent bar + thick colored footer line */
.layout-thumb--3::before {
  content: '';
  position: absolute;
  left: 0; right: 0;
  top: 0; height: 4px;
  background: var(--thumb-brand, #1a56a4);
}
.layout-thumb--3::after {
  content: '';
  position: absolute;
  bottom: 10px;
  left: 0; right: 0; height: 2.5px;
  background: var(--thumb-brand, #1a56a4);
}
