:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #1a2233;
  --muted: #6b7280;
  --line: #e5e7eb;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --green: #059669;
  --green-soft: #d1fae5;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --amber: #d97706;
  --amber-soft: #fef3c7;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.45;
}

.hidden { display: none !important; }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 650; }
.asof { color: var(--muted); font-size: 12px; margin-top: 2px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.lastload { color: var(--muted); font-size: 12px; }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  padding: 8px 16px;
  border: 1px solid transparent;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-secondary { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-secondary:hover { background: #f3f4f6; }

/* Banner */
.banner {
  margin: 16px 24px 0;
  padding: 14px 16px;
  border-radius: var(--radius);
  font-size: 14px;
}
.banner.loading { background: var(--blue-soft); color: #1e3a8a; }
.banner.error { background: var(--red-soft); color: #7f1d1d; }

main { padding: 20px 24px 40px; max-width: 1280px; margin: 0 auto; }

/* Filters */
.filters {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.filters-hint { flex-basis: 100%; font-size: 12px; color: var(--muted); }
.filters label, .period label {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  color: var(--muted);
  gap: 4px;
}
select, input[type="date"] {
  font: inherit;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.card h2 { font-size: 15px; margin: 0 0 4px; font-weight: 650; }
.card h3 { font-size: 13px; margin: 20px 0 10px; font-weight: 600; color: var(--muted); }
.sub { color: var(--muted); font-size: 12px; margin: 0 0 14px; }
.note { color: var(--muted); font-size: 12px; margin: 12px 0 0; font-style: italic; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.period { display: flex; align-items: flex-end; gap: 10px; }
.custom-range { font-size: 12px; color: var(--muted); }

/* Chase this week */
.chase { border-top: 3px solid var(--red); }
.empty { color: var(--muted); font-size: 13px; padding: 6px 0; }

/* Chase — grouped by company */
.chase-company {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 12px;
}
.chase-company:last-child { margin-bottom: 0; }
.chase-company-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.chase-company-name { font-size: 14px; }
.chase-company-name .cur-tag { font-size: 11px; color: var(--muted); font-weight: 600; margin-left: 6px; }
.chase-totals { display: flex; gap: 10px; }
.chase-total { font-weight: 700; color: var(--red); }
.chase-owners { color: var(--muted); font-size: 12px; margin: 6px 0 10px; }
.chase-invs { margin-bottom: 12px; }
.chase-inv {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  padding: 5px 0;
  border-bottom: 1px solid var(--line);
  align-items: center;
  font-size: 13px;
}
.chase-inv:last-child { border-bottom: none; }
.chase-inv .amt { font-weight: 650; text-align: right; }
.chase-inv .dov { color: var(--red); font-weight: 600; text-align: right; }
.chase-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chase-actions .chase-mail { padding: 8px 16px; text-decoration: none; display: inline-block; }
.chase-actions .chase-mail:hover { text-decoration: none; background: #f3f4f6; }
.chase-contact { font-size: 12px; color: var(--muted); }
.chase-contact .muted { font-style: italic; }

/* KPIs */
.kpi-wrap { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; margin-bottom: 4px; }
.kpi {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}
.kpi .label { font-size: 12px; color: var(--muted); margin-bottom: 10px; font-weight: 600; }
.kpi .cur-block { display: flex; justify-content: space-between; align-items: baseline; padding: 4px 0; }
.kpi .cur-tag { font-size: 11px; color: var(--muted); font-weight: 600; }
.kpi .val { font-size: 20px; font-weight: 680; }
.kpi .val.small { font-size: 15px; }
.kpi .pct { font-size: 12px; color: var(--amber); font-weight: 600; }
.kpi.key { border-left: 3px solid var(--amber); }

/* Two-column (EUR | USD) layout */
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px; }
.cur-panel { border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.cur-panel h4 { margin: 0 0 12px; font-size: 13px; display: flex; justify-content: space-between; }
.metric-row { display: flex; justify-content: space-between; padding: 5px 0; font-size: 13px; }
.metric-row .k { color: var(--muted); }
.metric-row .v { font-weight: 640; }
.rate-badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 650; background: var(--green-soft); color: var(--green); }
.dso-big { font-size: 34px; font-weight: 720; }
.dso-big.alt { color: var(--blue); }
.dso-unit { font-size: 13px; color: var(--muted); font-weight: 500; }
.dso-duo { display: flex; gap: 18px; margin-bottom: 8px; flex-wrap: wrap; }
.dso-cell { flex: 1; min-width: 120px; }
.dso-cap { font-size: 11px; color: var(--muted); font-weight: 600; margin-top: 2px; }

/* KPI explanatory note */
.kpi-note { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); font-size: 11px; color: var(--muted); line-height: 1.4; }

/* Per-bucket invoice lists under Overdue by age */
.age-item { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0 3px 12px; font-size: 12px; color: var(--ink); }
.age-item.empty { color: var(--muted); font-style: italic; }
.age-item .cur-tag { color: var(--muted); }

/* Charts (inline SVG) */
.chart { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* Table */
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
td.num, th.num { text-align: right; }
tbody tr:hover { background: #fafbfc; }
.age-30 { color: var(--red); font-weight: 650; }
.escalation { color: var(--red); font-weight: 650; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Data quality */
.quality { border-left: 3px solid var(--amber); }
.q-item { font-size: 13px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.q-item:last-child { border-bottom: none; }
.q-tag { display: inline-block; background: var(--amber-soft); color: var(--amber); border-radius: 6px; padding: 1px 7px; font-size: 11px; font-weight: 600; margin-left: 6px; }
.q-status { display: inline-block; border-radius: 6px; padding: 1px 7px; font-size: 11px; font-weight: 700; margin-left: 4px; }
.q-status.paid { background: var(--green-soft); color: var(--green); }
.q-status.open { background: var(--red-soft); color: var(--red); }

/* Exceptional cases */
.exceptional { border-left: 3px solid var(--muted); }
.exc-status {
  display: inline-block;
  background: #eef1f5;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 11px;
  font-weight: 600;
  margin-left: 8px;
  vertical-align: middle;
}
.exceptional .chase-total { color: var(--ink); }

.foot { color: var(--muted); font-size: 12px; text-align: center; margin-top: 24px; }

/* CEO modal */
.modal { position: fixed; inset: 0; background: rgba(16, 24, 40, 0.45); display: flex; align-items: flex-start; justify-content: center; padding: 30px 16px; overflow-y: auto; z-index: 50; }
.modal-inner { background: #fff; border-radius: var(--radius); max-width: 900px; width: 100%; padding: 26px 30px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.modal-head h2 { margin: 0; }
.modal-head > div { display: flex; gap: 10px; }
.ceo-content h3 { font-size: 16px; margin: 20px 0 10px; }
.ceo-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.ceo-panel { border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.ceo-panel h4 { margin: 0 0 12px; font-size: 14px; }
.ceo-content table { font-size: 12px; margin-bottom: 6px; table-layout: fixed; width: 100%; }
.ceo-content th, .ceo-content td { white-space: normal; word-break: break-word; vertical-align: top; }
.ceo-content h3 { border-top: 1px solid var(--line); padding-top: 14px; }

/* Print: make wide tables fit the PDF page, force colors to render */
@media print {
  .ceo-content table { font-size: 10px; }
  .ceo-content th, .ceo-content td { padding: 4px 6px; white-space: normal; }
  .ceo-grid { grid-template-columns: 1fr 1fr; }
  .age-30, .escalation { color: #dc2626 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Print: show only CEO content */
@media print {
  body { background: #fff; }
  body > *:not(#ceoModal) { display: none !important; }
  #ceoModal { position: static; background: #fff; padding: 0; display: block; }
  .modal-inner { box-shadow: none; max-width: none; padding: 0; }
  .no-print { display: none !important; }
}
