* { box-sizing: border-box; }

:root{
  --max: 1100px;
  --bg: #ffffff;
  --text: #111827;      
  --muted: #6b7280;   
  --line: #e5e7eb;      
  --pos: #2a7d46;      
  --neg: #b24949;      

  --cat-solid: #111827;  
  --cat-tint:  #f5f5f5; 

  /* darker grey for subcat rows*/
  --sub-dark:  #ffffff; 
  --sub-light: #cecece; 
}

html { scroll-behavior: smooth; }
body {
  margin:0; background:var(--bg); color:var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  font-size:14px;
}
.container { max-width: var(--max); margin: 0 auto; padding: 1rem; }

/* Header */
.site-header { position: sticky; top: 0; background:#fff; border-bottom:1px solid var(--line); z-index: 10; }
.site-header h1 { margin:.25rem 0 .5rem; font-size: 1.15rem; }
.toolbar { display:flex; gap:.5rem; align-items:center; flex-wrap:wrap; }
.btn { padding:.4rem .7rem; border-radius:.45rem; border:1px solid #d1d5db; background:#fff; cursor:pointer; }
.btn:hover { background:#f9fafb; }
.btn.primary { background:#111827; color:#fff; border-color:#111827; }
.muted { color: var(--muted); }

/* Table */
.table-wrap { background:#fff; border:1px solid var(--line); border-radius:.5rem; overflow:hidden; box-shadow:0 6px 14px rgba(0,0,0,.06); }
table { width:100%; border-collapse: collapse; font-size:13px; }

/* Column headings (at top) */
thead th {
  position: static;
  padding:.55rem .7rem; line-height:1.25;
  background:#f3f4f6;
  color:#000;                 /* black headings text */
  text-align:center; font-weight:700;
  font-size:15px;             
  border-bottom:1px solid var(--line);
  border-right:1px solid var(--line);   /* vertical lines */
}
thead th:last-child { border-right:none; }

/* cells both row and column lines */
tbody th, tbody td {
  padding:.45rem .6rem; line-height:1.25;
  border-bottom:1px solid var(--line);  /* row lines */
  border-right:1px solid var(--line);   /* column lines */
  vertical-align:middle;
}
tbody th:last-child, tbody td:last-child { border-right:none; }
tbody tr:hover { background:#f9fafb; }
.num { text-align:right; white-space:nowrap; font-variant-numeric: tabular-nums; }

/* First column product names always left-aligned */
tbody td:first-child, tbody th:first-child { text-align: left; }

.row-category-header th {
  background: var(--cat-solid);
  color:#000;
  font-weight:700;
  font-size: 16px;
}

/* Category TOTAL row: tinted version of category colour (same size) */
.row-category-total th {
  background: var(--cat-tint);
  font-weight:700;
  font-size: 16px;           /* same as category header */
}

/* Repeat headings row per category (looks like thead) */
.row-headings th {
  background:#f3f4f6;
  color:#000;
  font-weight:700;
  font-size:15px;
  text-align:left;
  border-bottom:1px solid var(--line);
  border-right:1px solid var(--line);
}
.row-headings th:last-child { border-right:none; }

/* Subcategory header row */
.row-subhead th {
  background: var(--sub-dark);
  color:#000;
  font-weight:700;
  font-size:14px;
  text-align:center;
  border-right: none;
}

/* Subcategory subtotal row */
.row-subtotal th {
  background: var(--sub-light);
  font-weight:700;
  font-size:14px;
}

/* Product rows */
.row-product .name { padding-left:1rem; font-weight:500; }

/* Variance colours */
.var .pos { color: var(--pos); font-weight:600; }
.var .neg { color: var(--neg); font-weight:600; }

/* Footer */
.site-footer { color:var(--muted); font-size:.9rem; padding:1.25rem 0; }

/* Charts layout */
.charts { margin: .5rem 0 .75rem; }
.chart-toolbar { display:flex; gap:.5rem; align-items:center; margin-bottom:.5rem; }

.charts-grid {
  display:grid;
  grid-template-columns: minmax(0,1fr) minmax(0,1fr);
  gap:.6rem;
  align-items: start;
}

.chart-card {
  position: relative;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: .5rem;
  padding: .5rem;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.chart-card.bar { height: 280px; }
.chart-card.pie { height: 280px; }

.chart-title {
  margin: 0 0 .35rem;
  font-weight: 700;
  font-size: .95rem;
  color: var(--text);
}

.chart-card canvas {
  flex: 1 1 0;
  width: 100% !important;
  height: 100% !important;
  min-height: 0;
}

.chart-card.pie canvas{
  height: auto !important;   
  aspect-ratio: 1 / 1;     
  width: 100% !important;
  margin: 0 auto;
}

@media (max-width: 800px){
  .charts-grid { grid-template-columns: 1fr; }
  .chart-card.bar,
  .chart-card.pie { height: 240px; }
}

@media print {
  body { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .site-header { position: static; border: none; }
  .toolbar, .chart-toolbar, .btn { display: none !important; } /* hide controls */
  .table-wrap { box-shadow: none; }
}
table, thead, tbody, tr, th, td { break-inside: avoid; page-break-inside: avoid; }
.page-break { break-after: page; page-break-after: always; }

.btn.is-active {
  background:#111827;
  color:#fff;
  border-color:#111827;
}

/* Stack title, then filters, then your existing toolbars */
.page-top { display:flex; flex-direction:column; align-items:flex-start; gap:.6rem; margin:.5rem 0 .75rem; }
.page-top h1 { margin:.25rem 0 .25rem; font-size:1.15rem; }

/* Filters container */
.filters{
  width:100%;
  background:#f9fafb;
  border:1px solid var(--line);
  border-radius:.5rem;
  padding:.75rem;
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap:.9rem 1.2rem;
}
.filter-group { display:flex; flex-direction:column; gap:.35rem; }
.filter-label { font-weight:600; color:var(--muted); }

.date-range{ display:flex; align-items:center; gap:.4rem; }
.date-range input[type="date"]{
  border:1px solid #d1d5db; border-radius:.45rem; padding:.4rem .55rem; background:#fff; font-size:14px;
}
.date-range .to{
  padding:.35rem .55rem; background:#e5e7eb; border-radius:.45rem; color:#111827; font-weight:600;
}

/* Actions (Submit / Export) aligned right on the grid */
.filter-actions{
  grid-column: 1 / -1;
  display:flex; justify-content:flex-end; gap:.5rem; margin-top:.25rem;
}

.choices{
  width:100%;
}
.choices__inner{
  border:1px solid #d1d5db !important;
  border-radius:.45rem !important;
  background:#fff !important;
  min-height:2.35rem !important;
  padding:.35rem .55rem !important;
  font-size:14px !important;
}
.choices__list--dropdown{
  border:1px solid var(--line) !important;
  box-shadow:0 6px 14px rgba(0,0,0,.06);
}
.choices__input{
  border:none !important;
  box-shadow:none !important;
  font-size:14px !important;
}
.choices__list--dropdown .choices__item--selectable.is-highlighted{
  background:#eef2ff !important;
}

/* Responsive: stack filters in one column on small screens */
@media (max-width: 900px){
  .filters{ grid-template-columns: 1fr; }
}

/* Product group tiles */
.seg-tiles{
  display:grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  border:1px solid var(--line); border-radius:.5rem; overflow:hidden; background:#f3f4f6;
}
.seg-tiles .tile{
  display:flex; align-items:center; gap:.5rem; padding:.6rem .75rem;
  border-right:1px solid var(--line); border-bottom:1px solid var(--line);
}
.seg-tiles .tile input{ accent-color:#111827; }
.seg-tiles .tile span{ font-weight:600; color:#111827; }
.seg-tiles .tile:nth-child(7n){ border-right:none; }
.chk-inline{ display:flex; align-items:center; gap:.4rem; margin-top:.5rem; color:#111827; }

/* Hierarchy bands/rows for detailed page */
.row-master th{
  background:#fff;
  color:#000;
  font-weight:700;
  font-size:14px;
}
.row-subname th{
  background:#fff;
  color:#111827;
  font-weight:600;
  font-size:13px;
  padding-left:.75rem;
  text-align:left;
  border-right:none;
}
.row-subtotal th{
  background: var(--sub-light);
  font-weight:700;
  font-size:14px;
}
.row-master-total th{
  background: var(--cat-tint);
  font-weight:700;
  font-size:15px;
}

