:root {
  --ink: #1c1c1c;
  --line: #222;
  --header: #d9d9d9;
  --header-top: #f3f3f3;
  --paper: #fff;
  --bg: #ece7dc;
  --card: #f7f3eb;
  --accent: #5f6f5c;
  --accent-ink: #fff;
  --shadow: 0 18px 50px rgba(40, 36, 28, 0.18);
  font-family: "Segoe UI", Calibri, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: #1f211d;
}

html {
  min-height: 100dvh;
}

body {
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

@media (display-mode: standalone) {
  body {
    overscroll-behavior: none;
  }
}

.app {
  max-width: 520px;
  margin: 0 auto;
  padding: 16px 16px calc(28px + 64px + env(safe-area-inset-bottom));
  min-width: 0;
}

.card {
  background: var(--card);
  border: 1px solid #d5cfc3;
  border-radius: 18px;
  padding: 22px 16px 18px;
  min-width: 0;
  overflow: hidden;
}

.eyebrow {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
}

.brand {
  margin: 0 0 14px;
}

.brand-logo {
  display: block;
  height: 40px;
  width: auto;
}

.card h1 {
  margin: 0 0 8px;
  font-size: 26px;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.lede {
  margin: 0 0 20px;
  color: #4d5248;
  font-size: 16px;
  line-height: 1.4;
}

label {
  display: block;
  margin-bottom: 12px;
  font-size: 15px;
  font-weight: 700;
}

.opt { font-weight: 500; color: #72786c; }

label input {
  display: block;
  width: 100%;
  margin-top: 6px;
  border: 1px solid #c5bfb3;
  background: #fff;
  border-radius: 12px;
  padding: 12px 14px;
  font: 20px/1.2 "Segoe UI", Calibri, Arial, sans-serif;
}

.hours-label input {
  font-size: 44px;
  font-weight: 700;
  padding: 14px 16px;
}

.rate-line {
  margin: -4px 0 18px;
  color: #4d5248;
  font-size: 16px;
}

.date-label { margin-top: 8px; }
.date-label input { font-size: 18px; }

.period {
  background: #fff;
  border: 1px solid #d5cfc3;
  border-radius: 12px;
  padding: 12px 12px 14px;
  margin: 0 0 16px;
  min-width: 0;
  overflow: hidden;
}

.period-head {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  gap: 8px;
}

.period-week {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  text-align: center;
}

.week-nav {
  width: 48px;
  height: 48px;
  border: 1px solid #c5bfb3;
  background: #f7f3eb;
  border-radius: 12px;
  font: 700 28px/1 "Segoe UI", Calibri, Arial, sans-serif;
  color: #3f4c3d;
}

.week-nav:disabled {
  opacity: 0.35;
}

.period-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
}

.sent-banner {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #e4eee0;
  color: #2f4a2c;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.35;
}

.sent-banner.saved {
  background: #efe8d8;
  color: #5a4a28;
}

.linkish {
  border: 0;
  background: none;
  color: var(--accent);
  font: 700 14px/1 "Segoe UI", Calibri, Arial, sans-serif;
  padding: 8px 0;
  min-height: 44px;
}

.period-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 10px;
  min-width: 0;
}

.period-grid label {
  margin-bottom: 0;
  min-width: 0;
}

.period-grid input {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 10px 8px;
  font-size: 15px;
}

.period-grid input[type="date"] {
  min-width: 0;
}

.period-grid input[type="date"]::-webkit-datetime-edit {
  min-width: 0;
  padding: 0;
}

.period-grid input[type="date"]::-webkit-calendar-picker-indicator {
  margin-left: 2px;
  padding: 0;
  width: 16px;
  height: 16px;
}

label input:focus {
  outline: 3px solid #8a9a82;
  outline-offset: 1px;
}

.sum {
  background: #fff;
  border: 1px solid #d5cfc3;
  border-radius: 12px;
  padding: 12px 14px;
  margin: 8px 0 14px;
}

.sum div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
  font-size: 16px;
}

.sum-pay {
  border-top: 1px solid #ddd6ca;
  margin-top: 6px;
  padding-top: 8px !important;
  font-size: 20px !important;
}

.status {
  margin: 0 0 12px;
  color: #3d5a38;
  font-weight: 600;
}

.actions {
  display: grid;
  gap: 8px;
}

.more {
  margin: 0 0 14px;
  border: 1px solid #d5cfc3;
  border-radius: 12px;
  background: #fff;
  padding: 4px 14px 4px;
}

.more summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 15px;
  padding: 12px 0;
  list-style: none;
  color: #3f4c3d;
}

.more summary::-webkit-details-marker { display: none; }

.more[open] summary {
  border-bottom: 1px solid #ddd6ca;
  margin-bottom: 12px;
}

.more label:last-child { margin-bottom: 12px; }

.actions-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.btn {
  width: 100%;
  border: 1px solid #4f5e4c;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 12px;
  padding: 16px 14px;
  font: 700 18px/1 "Segoe UI", Calibri, Arial, sans-serif;
}

.btn:disabled { opacity: 0.65; }

.btn:active { transform: translateY(1px); }

.btn.whatsapp {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: #128c7e;
  border-color: #0f6f64;
}

.wa-icon {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
}

.btn.ghost {
  background: #e7e1d5;
  border-color: #b7b1a5;
  color: #1f211d;
}

.hint-line {
  margin: -2px 0 6px;
  color: #5c6356;
  font-size: 13px;
  text-align: center;
  line-height: 1.35;
}

.btn.quiet {
  background: transparent;
  border-color: transparent;
  color: #5c6356;
  padding: 10px 14px;
  font-size: 15px;
}

.archive-card {
  margin-top: 16px;
}

.archive-card h2 {
  margin: 0 0 6px;
  font-size: 20px;
}

.lede.small {
  margin-bottom: 14px;
  font-size: 14px;
}

.archive-list {
  display: grid;
  gap: 10px;
}

.archive-item {
  background: #fff;
  border: 1px solid #d5cfc3;
  border-radius: 12px;
  padding: 12px;
}

.archive-item h3 {
  margin: 0 0 2px;
  font-size: 16px;
}

.archive-item p {
  margin: 0 0 10px;
  color: #5c6356;
  font-size: 14px;
}

.archive-item .actions-row {
  margin-top: 4px;
}

.archive-item .btn {
  padding: 10px 8px;
  font-size: 14px;
}

.archive-empty {
  margin: 0;
  color: #6a655c;
}

.preview-wrap { margin-top: 28px; }

.preview-label {
  margin: 0 0 10px;
  color: #6a655c;
  font-size: 13px;
}

.preview-frame {
  height: 210px;
  overflow: hidden;
  border-radius: 12px;
  box-shadow: var(--shadow);
  background: #fff;
}

.preview-frame .sheet {
  transform: scale(0.38);
  transform-origin: top left;
}

.sheet {
  width: 210mm;
  min-height: 297mm;
  background: var(--paper);
  color: var(--ink);
  padding: 12mm 16mm 16mm;
  font: 12.5px/1.35 Calibri, "Segoe UI", Arial, sans-serif;
}

.logo {
  display: block;
  height: 15mm;
  width: auto;
  margin: 0 22mm 1mm auto;
}

.top {
  display: grid;
  grid-template-columns: 1fr 58mm;
  align-items: start;
  margin-bottom: 3mm;
}

.doc-title {
  margin: 3mm 0 0;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.company {
  text-align: right;
  font-size: 12.5px;
  line-height: 1.35;
}

.company p,
.aan p,
.pay p { margin: 0; }

.company-name { font-weight: 700; }

.kvk-line {
  margin-top: 5mm;
  display: grid;
  grid-template-columns: 1fr auto;
  column-gap: 4mm;
}

.mid {
  display: grid;
  grid-template-columns: 1fr 78mm;
  gap: 8mm;
  align-items: start;
  margin-bottom: 8mm;
}

.aan { width: 100%; border-collapse: collapse; }

.aan th,
.meta th,
.lines th {
  background: linear-gradient(180deg, var(--header-top), var(--header));
  border: 1px solid #6f6f6f;
  font-size: 11px;
  letter-spacing: 0.04em;
  padding: 3px 6px;
  font-weight: 700;
}

.aan th { text-align: center; }

.aan td {
  border: 1px solid var(--line);
  height: 32mm;
  padding: 7mm 5mm 4mm;
  vertical-align: top;
  font-size: 13px;
}

.pay { padding-top: 12mm; font-size: 12.5px; }

.pay p {
  display: grid;
  grid-template-columns: 16mm 1fr;
  column-gap: 4mm;
  margin-bottom: 1.2mm;
}

.pay .lbl,
.kvk-line .lbl { text-align: right; }

.email-line { margin-top: 6mm; }

.meta {
  width: 148mm;
  border-collapse: collapse;
  margin: 2mm 0 4mm;
}

.period-sheet {
  margin-bottom: 6mm;
}

.meta th, .meta td {
  border: 1px solid var(--line);
  text-align: center;
  width: 33.33%;
}

.meta td { padding: 4px 6px; }

.lines {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 3mm;
}

.lines th, .lines td {
  border: 1px solid var(--line);
  padding: 3px 6px;
  height: 6.2mm;
}

.col-desc { text-align: left; }
.col-qty, .col-price, .col-btw, .col-sum { text-align: center; }
.col-qty { width: 18mm; }
.col-price { width: 22mm; }
.col-btw { width: 16mm; }
.col-sum { width: 34mm; }

.money { font-variant-numeric: tabular-nums; white-space: nowrap; }

.money-inner {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.totals {
  width: 78mm;
  margin-left: auto;
  border-collapse: collapse;
}

.totals th,
.totals td {
  border: none;
  padding: 2px 0 2px 8px;
  font-size: 12.5px;
}

.totals th {
  text-align: right;
  font-weight: 400;
  padding-right: 6mm;
}

.totals td {
  border: 1px solid var(--line);
  width: 34mm;
}

.totals .pay-row th,
.totals .pay-row td { font-weight: 700; }

@media (min-width: 1100px) {
  .app {
    max-width: 1180px;
    display: grid;
    grid-template-columns: 420px 1fr;
    gap: 28px;
    align-items: start;
    padding: 28px;
  }

  .phone-only,
  .tabbar { display: none !important; }

  .desktop-only { display: block; }

  .left { min-width: 0; }

  .preview-frame {
    height: auto;
    overflow: visible;
    box-shadow: none;
    background: transparent;
  }

  .preview-frame .sheet {
    transform: none;
    box-shadow: var(--shadow);
  }
}

body.pdf-export .preview-wrap {
  display: block !important;
  position: fixed !important;
  left: -10000px !important;
  top: 0 !important;
  right: auto !important;
  bottom: auto !important;
  margin: 0 !important;
  padding: 0 !important;
  background: transparent !important;
  overflow: visible !important;
  inset: auto !important;
}

body.pdf-export .preview-frame {
  height: auto !important;
  overflow: visible !important;
}

body.pdf-export .preview-frame .sheet {
  transform: none !important;
}

.install-bar {
  margin: 12px 16px 0;
  max-width: 520px;
  margin-left: auto;
  margin-right: auto;
  background: #fff;
  border: 1px solid #d5cfc3;
  border-radius: 16px;
  padding: 14px 16px 12px;
}

.install-bar p {
  margin: 0 0 10px;
  font-size: 15px;
  line-height: 1.35;
  color: #1f211d;
}

.install-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.install-actions .btn {
  padding: 12px 14px;
  font-size: 16px;
}

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: #f7f3eb;
  border-top: 1px solid #d5cfc3;
  padding-bottom: env(safe-area-inset-bottom);
}

.tabbar button {
  min-height: 52px;
  border: 0;
  background: transparent;
  color: #5c6356;
  font: 700 15px/1 "Segoe UI", Calibri, Arial, sans-serif;
}

.tabbar button[aria-current="page"] {
  color: #3f4c3d;
  box-shadow: inset 0 3px 0 var(--accent);
}

.desktop-only { display: none; }

@media (max-width: 1099px) {
  body[data-screen="archive"] #screen-invoice { display: none; }
  body[data-screen="invoice"] #screen-archive { display: none; }

  .desktop-only { display: none !important; }

  .preview-wrap {
    display: none;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 50;
    margin: 0;
    padding: 16px 12px 24px;
    background: #2a2a28;
    overflow: auto;
  }

  body.preview-open .preview-wrap { display: block; }
  body.preview-open .tabbar { visibility: hidden; }

  .preview-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    max-width: 520px;
    margin: 0 auto 12px;
  }

  .preview-toolbar .preview-label {
    margin: 0;
    color: #fff;
  }

  .preview-toolbar .btn {
    width: auto;
    padding: 10px 14px;
    font-size: 15px;
  }

  .preview-frame {
    width: min(calc(100vw - 24px), 210mm);
    height: calc(min(calc(100vw - 24px), 210mm) * 297 / 210);
    overflow: hidden;
    margin: 0 auto;
  }

  .preview-frame .sheet {
    transform: scale(calc(min(100vw - 24px, 210mm) / 210mm));
    transform-origin: top left;
  }
}

@media (min-width: 1100px) {
  .install-bar { max-width: 1180px; }
}

.install-dialog {
  border: 1px solid #d5cfc3;
  border-radius: 18px;
  padding: 22px 18px 16px;
  background: var(--card);
  color: #1f211d;
  width: min(92vw, 360px);
}

.install-dialog::backdrop {
  background: rgba(28, 28, 28, 0.45);
}

.install-dialog h2 {
  margin: 0 0 12px;
  font-size: 22px;
}

.install-dialog ol {
  margin: 0 0 16px;
  padding-left: 22px;
  line-height: 1.45;
}

@media print {
  @page { size: A4; margin: 0; }

  html, body { background: #fff; }
  .card, .archive-card, .left, .preview-label, .tabbar, .install-bar, .install-dialog, .preview-toolbar { display: none !important; }
  .app, .preview-wrap, .preview-frame {
    display: block !important;
    position: static !important;
    max-width: none;
    margin: 0;
    padding: 0;
    height: auto;
    overflow: visible;
    box-shadow: none;
    background: #fff !important;
    inset: auto !important;
  }
  .preview-frame .sheet {
    transform: none;
    box-shadow: none;
  }
}
