/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* ECOstyle brand palette */
  --brand:        #72a800;   /* ECOstyle fresh grass-green */
  --brand-dark:   #517800;   /* donkerder groen voor hover/active */
  --brand-light:  #eef6d6;   /* lichte groentint achtergrond */
  --accent:       #f07800;   /* oranje accent (ECO in logo) */
  --green:        #3d9970;   /* positieve waarden */
  --red:          #d93025;   /* negatieve waarden */
  --bg:           #f5f7f0;   /* licht groene achtergrond */
  --surface:      #ffffff;
  --border:       #dde5c8;   /* licht groene rand */
  --text:         #1e2a0e;   /* donker groen-zwart voor tekst */
  --text-muted:   #6b7c50;   /* gedempte groentint */
  --radius:       8px;
  --shadow:       0 1px 4px rgba(60,80,20,.08), 0 4px 16px rgba(60,80,20,.06);
}

body {
  font-family: "Nunito", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ===== HEADER ===== */
.header {
  background: var(--surface);
  color: var(--text);
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 3px solid var(--brand);
  box-shadow: 0 2px 8px rgba(60,80,20,.12);
}
.header-inner { display: flex; align-items: center; gap: 0; width: 100%; }
.header-logo-group {
  display: flex;
  align-items: center;
  gap: 14px;
}
.header-logo {
  height: 42px;
  width: auto;
  display: block;
}
.header-title {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -.3px;
  color: var(--brand-dark);
  border-left: 2px solid var(--border);
  padding-left: 14px;
}
.header-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: auto;
}

/* ===== FILTERBAR ===== */
.filter-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 14px 24px;
  padding: 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.filter-row-top {
  display: flex;
  align-items: flex-end;
  gap: 20px;
  flex-wrap: wrap;
}
.filter-row-bottom {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 130px;
  flex: 1;
}
.filter-group label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .4px;
}
.filter-group select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  outline: none;
  transition: border-color .15s;
}
.filter-group select:focus { border-color: var(--brand); }

/* ===== VIEW TOGGLE ===== */
.view-toggle-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.view-toggle-group label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .4px;
}
.view-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.toggle-btn {
  padding: 6px 18px;
  font-size: 13px;
  font-weight: 600;
  border: none;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.toggle-btn.active {
  background: var(--brand);
  color: #fff;
}
.toggle-btn:not(.active):hover { background: var(--brand-light); }

/* ===== MAIN ===== */
.main { padding: 0 24px 32px; }

/* ===== KPI-KAARTEN ===== */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 14px;
  margin-bottom: 16px;
}
.kpi-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.kpi-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .4px;
  margin-bottom: 8px;
}
.kpi-value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -.5px;
  line-height: 1.1;
}
.kpi-sub { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.kpi-subtotal { font-size: 11px; color: var(--text-muted); margin-top: 2px; opacity: .75; }
.kpi-value.positive { color: var(--brand); }
.kpi-value.negative { color: var(--red); }

/* ===== GRAFIEK + INSIGHTS ===== */
.chart-insights-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
.chart-card, .insights-card, .table-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card-title { font-size: 14px; font-weight: 700; margin-bottom: 16px; }
canvas { max-height: 280px; }

/* ===== INSIGHTS ===== */
.insights-body        { font-size: 13px; line-height: 1.7; }
.insights-placeholder { color: var(--text-muted); font-style: italic; }
.insight-block        { margin-bottom: 14px; }
.insight-block strong { color: var(--brand); }
.insight-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  margin: 2px 3px 2px 0;
}
.chip-neg     { background: #fde8e8; color: var(--red); }
.chip-pos     { background: #d8f0b0; color: var(--brand-dark); }
.chip-neutral { background: #e9edde; color: var(--text-muted); }

/* ===== TABELLEN ===== */
.tables-row { margin-bottom: 16px; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left;
  padding: 8px 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .4px;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  background: #fafafa;
}
th.num, td.num { text-align: right; }
td { padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
/* Groepsscheiding in tabellen (omzet | afzet | marge) */
th.col-sep, td.col-sep { border-left: 2px solid var(--border); padding-left: 14px; }
tr:hover td { background: #f9fafb; }
.empty-row  { text-align: center; color: var(--text-muted); padding: 24px; font-style: italic; }
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
}
.badge-pos     { background: #d8f0b0; color: var(--brand-dark); }
.badge-neg     { background: #fde8e8; color: var(--red); }
.badge-neutral { background: #e9edde; color: var(--text-muted); }

/* ===== REFRESH TOAST ===== */
.restart-btn {
  margin-left: 16px;
  padding: 6px 14px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background: var(--brand);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s;
}
.restart-btn:hover:not(:disabled) { background: var(--brand-dark); }
.restart-btn:disabled { opacity: .5; cursor: not-allowed; }

.refresh-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  z-index: 9999;
  transition: opacity .4s;
  pointer-events: none;
}
.toast-loading { background: var(--brand);  color: #fff; }
.toast-success { background: var(--green);  color: #fff; }
.toast-error   { background: #e74c3c;       color: #fff; }

/* ===== FUTURE PERIOD NOTE ===== */
.future-note {
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 12px;
  color: #92400e;
  margin-bottom: 14px;
  display: none;
}
.future-note.visible { display: block; }

/* ===== TOPPERS / ZAKKERS SECTIE-KOPPEN ===== */
.sub-section-head {
  font-size: 13px;
  font-weight: 700;
  padding: 14px 0 6px;
  color: var(--text);
  border-top: 1px solid var(--border);
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sub-section-head:first-child { border-top: none; margin-top: 0; }
.sub-section-head .count {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
}
.sub-section-head.toppers { color: var(--brand-dark); }
.sub-section-head.zakkers { color: var(--red); }

/* Sectiekoprij binnen een gedeelde tabel (buildGroupedTable) */
td.group-header-row {
  font-size: 13px;
  font-weight: 700;
  padding: 14px 10px 6px;
  color: var(--text);
  border-top: 2px solid var(--border);
  border-bottom: none;
  background: var(--surface);
}
td.group-header-row:first-child,
tr:first-child td.group-header-row { border-top: none; padding-top: 6px; }
td.group-header-row .count {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  margin-left: 6px;
}
td.group-header-row.toppers { color: var(--brand-dark); }
td.group-header-row.zakkers { color: var(--red); }

/* ===== Y-2 LEGENDA ===== */
.chart-legend-y2 { opacity: .65; }

/* ===== FOOTER ===== */
.footer {
  text-align: center;
  padding: 16px;
  font-size: 11px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

/* ===== MULTI-SELECT ===== */
.ms-wrap {
  position: relative;
  display: inline-block;
  width: 100%;
}

.ms-btn {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid #d0d7c8;
  border-radius: 6px;
  background: #fff;
  text-align: left;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: border-color .15s;
  box-sizing: border-box;
}

.ms-btn:hover { border-color: var(--brand); }

.ms-btn.ms-has-filter {
  background: #eaf2d0;
  border-color: var(--brand);
  font-weight: 600;
}

.ms-list {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 100%;
  max-height: 260px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #d0d7c8;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,.14);
  z-index: 300;
  padding: 4px 0;
}

.ms-wrap.ms-open .ms-list { display: block; }

.ms-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  transition: background .1s;
  white-space: nowrap;
}

.ms-item:hover { background: var(--bg); }

.ms-item input[type="checkbox"] {
  accent-color: var(--brand);
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  cursor: pointer;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1100px) {
  .kpi-row { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 900px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .chart-insights-row { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .main { padding-left: 12px; padding-right: 12px; }
  .filter-bar { margin: 10px 12px; }
  .kpi-row { grid-template-columns: 1fr 1fr; }
}
