:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #172033;
  --muted: #667085;
  --border: #e2e7f0;
  --header: #303d4f;
  --accent: #2357d9;
  --accent-dark: #1a43aa;
  --actual: #ffffff;
  --forecast: #d7dde6;
  --subtotal: #f1f1f1;
  --danger: #b42318;
  --success: #027a48;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, Segoe UI, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.shell {
  width: min(98vw, 1800px);
  margin: 0 auto;
  padding: 16px 10px 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.topbar h1 { margin: 0 0 4px 0; font-size: 26px; margin-bottom: 4px; }
.topbar p { margin: 0; color: var(--muted); margin-top: 0;
  margin-bottom: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
   padding-top: 22px;
  box-shadow: 0 10px 30px rgba(16, 24, 40, 0.06);
}
.card.narrow { max-width: 480px; margin: 40px auto; }
.card h2 { margin-top: 0; }

label { display: block; margin: 14px 0 6px; font-weight: 600; font-size: 13px; }
input, select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  background: white;
}
button {
  margin-top: 16px;
  border: 0;
  border-radius: 10px;
  padding: 11px 16px;
  background: var(--accent);
  color: white;
  font-weight: 700;
  cursor: pointer;
}
button:hover { background: var(--accent-dark); }
button.secondary { background: #edf1f7; color: var(--text); }
button.secondary:hover { background: #dfe7f3; }
button.primary { background: var(--success); }
button.primary:hover { background: #02653c; }
button:disabled { opacity: .55; cursor: not-allowed; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.message { min-height: 22px; margin-top: 12px; font-size: 14px; }
.message.error { color: var(--danger); }
.message.ok { color: var(--success); }

.view-options {
  display: flex;
  justify-content: flex-end;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1.3fr) 230px 200px auto;
  gap: 16px;
  margin-bottom: 10px;
  align-items: end;
}
.toolbar-actions { display: flex; gap: 8px; align-items: end; }
.toolbar-actions button { margin-top: 0; white-space: nowrap; }

.legend { display: flex; gap: 22px; margin: 16px 0 10px; color: var(--muted); font-size: 14px; }
.legend b { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.actual-dot { background: var(--actual); border: 1px solid #cbd5e1; }
.forecast-dot { background: var(--forecast); border: 1px solid #aab4c4; }

.table-wrap {
  overflow-x: auto;
  overflow-y: visible;
  border-radius: 6px;
  padding-bottom: 4px;
}

#forecastTable {
  width: 100%;
  min-width: 1520px;
  border-collapse: separate;
  border-spacing: 0 8px;
  table-layout: fixed;
}

#forecastTable th,
#forecastTable td {
  text-align: right;
  padding: 0 4px;
  height: 30px;
  white-space: nowrap;
  border: 0;
}

#forecastTable thead th {
  height: 40px;
  background: var(--header);
  color: #fff;
  font-size: 18px;
  font-weight: 800;
}

#forecastTable thead th:first-child {
  text-align: left;
  width: 295px;
}

#forecastTable thead th:last-child {
  width: 110px;
}

#forecastTable td:first-child {
  text-align: left;
  width: 295px;
  position: sticky;
  left: 0;
  z-index: 2;
  background: #fff;
}

#forecastTable td.actual { background: var(--actual); }
#forecastTable td.forecast { background: var(--forecast); }
#forecastTable td.year-total {
  background: #f3f3f3;
  font-weight: 700;
}

.line-name { font-size: 16px; }

.month-input {
  width: 100%;
  min-width: 70px;
  max-width: 100px;
  text-align: right;
  padding: 4px 3px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-size: 15px;
  background: transparent;
  color: var(--text);
}
.month-input:not(:disabled) {
  background: rgba(255,255,255,.45);
  border-color: rgba(100,116,139,.25);
}
.month-input:disabled {
  background: transparent;
  border-color: transparent;
  opacity: 1;
  color: var(--text);
}
.month-input.changed { outline: 2px solid #f79009; background: #fff7ed; }

tr.subtotal td,
tr.total-row td {
  background: var(--subtotal) !important;
  font-weight: 800;
}

tr.subtotal td:first-child,
tr.total-row td:first-child {
  background: var(--subtotal) !important;
}

tr.dotted-before td {
  border-top: 1px dotted #333 !important;
}

tr.kpi td {
  font-style: italic;
  background: #f0f0f0 !important;
}

tr.kpi td:first-child {
  font-weight: 500;
  background: #f0f0f0 !important;
}

tr.spacer td { height: 4px; background: transparent !important; }
tr.spacer-lg td { height: 28px; background: transparent !important; }

@media (max-width: 900px) {
  .shell { width: 100%; padding: 12px; }
  .toolbar { grid-template-columns: 1fr; }
  .toolbar-actions { align-items: stretch; }
  .toolbar-actions button { flex: 1; }
}

.tabs {
  display: flex;
  gap: 8px;
  margin: 16px 0 12px;
  border-bottom: 1px solid var(--border);
}

.tab {
  margin-top: 0;
  border-radius: 10px 10px 0 0;
  background: #edf1f7;
  color: var(--text);
  padding: 10px 16px;
}

.tab:hover { background: #dfe7f3; }

.tab.active {
  background: var(--header);
  color: #fff;
}

.tab-panel {
  margin-top: 10px;
}

/* Whole report area: table and charts get the same height */
.report-layout {
  display: grid;
  grid-template-columns: minmax(620px, 1fr) minmax(620px, 1fr);
  gap: 14px;
  align-items: stretch;
  height: calc(100vh - 300px);
  min-height: 640px;
  max-height: 780px;
}

/* Left side */
.report-left {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.report-header-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  border-bottom: 1px solid #777;
  margin-bottom: 14px;
  flex: 0 0 auto;
}

.report-header-row h2 {
  margin: 0 0 4px 0;
  font-size: 18px;
  color: #4b5563;
}

#reportUnits {
  font-size: 14px;
  color: #111827;
}

.report-table-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.report-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 8px;
  table-layout: fixed;
}

.report-table th,
.report-table td {
  text-align: right;
  padding: 6px 6px;
  white-space: nowrap;
}

.report-table th:first-child,
.report-table td:first-child {
  text-align: left;
  width: 260px;
}

.report-table thead th {
  background: var(--header);
  color: #fff;
  font-weight: 800;
}

.report-table tr.subtotal td,
.report-table tr.total-row td {
  background: var(--subtotal);
  font-weight: 800;
}

.report-table tr.kpi td {
  background: #f0f0f0;
  font-style: italic;
}

.report-table tr.spacer td {
  background: transparent;
  height: 12px;
}

.report-table tr.spacer-lg td {
  background: transparent;
  height: 24px;
}

.report-table tr.dotted-before td {
  border-top: 1px dotted #333;
}

/* Right side */
.report-right {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.report-controls {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 14px;
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
  flex: 0 0 auto;
}

.report-select-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-weight: 500;
}

.compact-select {
  width: auto;
  min-width: 160px;
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 13px;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-weight: 500;
}

.checkbox-label input {
  width: auto;
  margin: 0;
}

.report-charts {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.chart-card {
  border: 1px solid #d0d5dd;
  background: #fff;
  padding: 10px 12px 12px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chart-card h3 {
  margin: 0 0 8px;
  text-align: center;
  color: #7a7a7a;
  font-size: 16px;
  flex: 0 0 auto;
}

.mini-chart {
  flex: 1;
  min-height: 0;
  position: relative;
}

.bar-chart {
  display: flex;
  align-items: end;
  gap: 8px;
  height: calc(100% - 22px);
  min-height: 0;
  border-bottom: 1px solid #c9ced6;
  padding: 0 8px;
}

.bar-chart.has-labels {
  padding-top: 12px;
}

.bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: end;
  align-items: center;
  height: 100%;
  min-width: 0;
}

.bar {
  width: 70%;
  min-height: 2px;
  background: #aeb9ca;
}

.combo-bar {
  fill: #aeb9ca;
}

.combo-prior-line {
  stroke: #667085;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 2 4;
}

.combo-prior-dot {
  fill: #667085;
  stroke: #ffffff;
  stroke-width: 1;
}

.bar-labels {
  display: flex;
  gap: 8px;
  padding: 4px 8px 0;
  font-size: 12px;
  color: #555;
  flex: 0 0 auto;
}

.bar-labels span {
  flex: 1;
  text-align: center;
}

.chart-value-label {
  font-size: 10px;
  line-height: 1;
  color: #475467;
  margin-bottom: 3px;
  white-space: nowrap;
}

.line-chart-svg {
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: visible;
}

.chart-axis-label {
  font-size: 11px;
  fill: #555;
}

.chart-value-label-svg {
  font-size: 10px;
  fill: #475467;
}

@media (max-width: 1300px) {
  .report-layout {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 0;
    max-height: none;
  }

  .report-left,
  .report-right {
    height: auto;
  }

  .report-table-wrap {
    max-height: none;
    overflow: auto;
  }

  .report-charts {
    grid-template-rows: none;
  }

  .chart-card {
    height: 240px;
  }
}

@media (max-width: 1200px) {
  .report-layout { grid-template-columns: 1fr; }
}

/* =========================================================
   Compact forecast header + message/options row
   Added for app/index.html structure:
   <div class="message-options-row">
     <div id="appMessage" class="message"></div>
     <label class="checkbox-label compact-checkbox">...</label>
   </div>
   ========================================================= */

.shell {
  width: min(98vw, 1800px);
  padding-top: 12px;
}

.topbar {
  margin-bottom: 12px;
}

.topbar h1 {
  margin: 0 0 2px;
  font-size: 26px;
  line-height: 1.15;
}

.topbar p {
  margin: 0;
  line-height: 1.25;
}

#appCard.card {
  padding: 16px 22px 20px;
}

.toolbar {
  grid-template-columns: minmax(260px, 1.3fr) 220px 190px auto;
  gap: 14px 18px;
  margin-bottom: 8px;
  align-items: end;
}

.toolbar label {
  margin: 0 0 6px;
}

.toolbar input,
.toolbar select {
  height: 42px;
}

.toolbar-actions {
  gap: 8px;
}

.toolbar-actions button {
  height: 42px;
  padding: 9px 16px;
}

/* New preferred layout: message left, "Vis i 1000" right */
.message-options-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: 6px 0 14px;
}

.message-options-row .message {
  flex: 1;
  min-height: 20px;
  margin: 0;
  line-height: 1.35;
}

.compact-checkbox {
  flex: 0 0 auto;
  white-space: nowrap;
}

/* Fallback if old .view-options still exists */
.view-options {
  justify-content: flex-end;
  margin: 4px 0 10px;
}

/* Make tabs sit closer to the message/options row */
.tabs {
  margin: 10px 0 12px;
}

.tab {
  padding: 9px 16px;
}

/* Make legend slightly more compact */
.legend {
  margin: 12px 0 8px;
}

/* =========================================================
   Forecast table widths
   Default: normal widths.
   When "Vis i 1000" is checked: narrower numeric columns.
   Uses :has(), supported in current Edge/Chrome.
   ========================================================= */

#forecastTable {
  min-width: 1400px;
}

#forecastTable th:first-child,
#forecastTable td:first-child {
  width: 270px;
}

#forecastTable th:not(:first-child),
#forecastTable td:not(:first-child) {
  min-width: 88px;
  width: 88px;
}

#forecastTable th:last-child,
#forecastTable td:last-child {
  min-width: 100px;
  width: 100px;
}

.month-input {
  max-width: 88px;
  height: 28px;
  padding: 3px 5px;
}

/* Compact numeric table when display is in thousands */
#appCard:has(#showInThousands:checked) #forecastTable {
  min-width: 1180px;
}

#appCard:has(#showInThousands:checked) #forecastTable th:first-child,
#appCard:has(#showInThousands:checked) #forecastTable td:first-child {
  width: 245px;
}

#appCard:has(#showInThousands:checked) #forecastTable th:not(:first-child),
#appCard:has(#showInThousands:checked) #forecastTable td:not(:first-child) {
  min-width: 72px;
  width: 72px;
}

#appCard:has(#showInThousands:checked) #forecastTable th:last-child,
#appCard:has(#showInThousands:checked) #forecastTable td:last-child {
  min-width: 88px;
  width: 88px;
}

#appCard:has(#showInThousands:checked) .month-input {
  max-width: 68px;
  height: 28px;
  padding-left: 4px;
  padding-right: 4px;
  font-size: 14px;
}

/* Keep layout usable on smaller screens */
@media (max-width: 1100px) {
  .message-options-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .compact-checkbox {
    margin-left: 0;
  }
}

