:root {
  color-scheme: light;
  --ink: #172321;
  --muted: #66736f;
  --paper: #f3f1e9;
  --card: #fffdf7;
  --line: #d5d2c7;
  --green: #165c4c;
  --mint: #92d7bd;
  --amber: #e2a440;
  --red: #ce5a4a;
  --blue: #4b78a8;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font: 15px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.shell { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 42px 0 70px; }
header { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
.brand { color: var(--ink); text-decoration: none; font: 800 24px/1 monospace; letter-spacing: -.06em; }
.brand span { color: var(--green); }
header p { margin: 0; color: var(--muted); }
.panel { background: var(--card); border: 1px solid var(--line); box-shadow: 5px 5px 0 #dcd8cc; }
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 22px 26px; padding: 30px; }
.wide, .section-title, .actions, .custom-fields { grid-column: 1 / -1; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); padding-bottom: 18px; }
.section-title > div { display: flex; align-items: center; gap: 12px; }
.section-title span:first-child { color: var(--green); font: 700 12px monospace; }
h1, h2 { margin: 0; font-size: 20px; letter-spacing: -.02em; }
.status { color: var(--muted); font-size: 13px; }
.status.error { color: var(--red); }
.field { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
label, legend { font-weight: 700; font-size: 13px; }
select, textarea, input[type="file"] {
  width: 100%; border: 1px solid #aaa99f; border-radius: 0; background: white; color: var(--ink);
  padding: 11px 12px; font: inherit;
}
select[multiple] { min-height: 132px; }
textarea { resize: vertical; }
small { color: var(--muted); }
.mode-field { border: 0; margin: 0; padding: 0; }
.mode-options { display: flex; gap: 8px; flex-wrap: wrap; }
.mode-options label { border: 1px solid var(--line); background: white; padding: 10px 14px; cursor: pointer; font-weight: 600; }
.mode-options label:has(input:checked) { color: white; border-color: var(--green); background: var(--green); }
.mode-options input { position: absolute; opacity: 0; }
.custom-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 22px 26px; padding-top: 5px; }
.hidden { display: none !important; }
.actions { display: flex; gap: 10px; padding-top: 4px; }
button { border: 0; padding: 12px 17px; font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; }
button:disabled { opacity: .55; cursor: wait; }
.primary { background: var(--green); color: white; }
.secondary { background: transparent; color: var(--green); border: 1px solid var(--green); }
.text-button { color: var(--muted); background: transparent; padding: 4px; }
.results-panel { margin-top: 24px; padding: 30px; }
.empty-state { padding: 65px 10px; text-align: center; color: var(--muted); }
.empty-state strong { color: var(--ink); font-size: 18px; }
.empty-state p { margin: 6px 0 0; }
.results { padding-top: 24px; display: grid; gap: 18px; }
.result-card { border: 1px solid var(--line); padding: 20px; background: white; }
.result-head { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.result-head h3 { margin: 0; font-size: 16px; }
.result-head p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.cache-badge { align-self: start; color: var(--green); background: #e3f3ed; padding: 4px 8px; font-size: 11px; font-weight: 700; }
.error-badge { align-self: start; color: var(--red); background: #f8e4e0; padding: 4px 8px; font-size: 11px; font-weight: 700; }
.result-error { border-color: #e4aaa1; }
.error-message { margin: 0; color: #963b30; background: #fff2ef; padding: 13px 15px; }
.result-warning { margin: -6px 0 16px; color: #875a14; background: #fff5df; padding: 9px 12px; font-size: 12px; }
.comparison-card { overflow-x: auto; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: -4px 0 24px; color: var(--muted); font-size: 12px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 7px; }
.chart-legend i { width: 10px; height: 10px; display: inline-block; }
.comparison-chart { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); align-items: end; gap: 18px; min-width: 680px; min-height: 265px; border-bottom: 1px solid var(--line); }
.metric-group { display: flex; height: 245px; flex-direction: column; justify-content: end; gap: 10px; text-align: center; }
.group-bars { height: 195px; display: flex; align-items: end; justify-content: center; gap: 5px; padding: 0 5px; background: repeating-linear-gradient(to top, transparent 0, transparent 48px, #e4e1d8 49px); }
.series-bar-wrap { position: relative; display: flex; flex: 1 1 0; height: 100%; min-width: 20px; max-width: 70px; align-items: end; justify-content: center; }
.series-bar-wrap strong { position: absolute; bottom: calc(var(--bar-height, 0%) + 4px); font: 700 10px monospace; writing-mode: vertical-rl; transform: rotate(180deg); color: var(--muted); }
.series-bar { width: 100%; min-height: 2px; transition: height .4s ease; }
.metric-group > span { min-height: 30px; color: var(--muted); font-size: 12px; font-weight: 700; }
.chart-note { margin: 12px 0 0; color: var(--muted); text-align: right; font-size: 11px; }
.history { margin-top: 32px; }
.compact { padding-bottom: 12px; }
.history-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; padding-top: 14px; }
.history-item { text-align: left; border: 1px solid var(--line); background: transparent; padding: 14px; }
.history-item strong, .history-item span { display: block; }
.history-item span { margin-top: 4px; color: var(--muted); font-size: 11px; }
.history-empty { color: var(--muted); font-size: 13px; }

@media (max-width: 720px) {
  .shell { width: min(100% - 22px, 1180px); padding-top: 24px; }
  header { display: block; }
  header p { margin-top: 10px; }
  .controls, .custom-fields { grid-template-columns: 1fr; padding: 20px; }
  .field, .custom-fields .wide { grid-column: 1; }
  .results-panel { padding: 20px; }
  .comparison-chart { grid-template-columns: repeat(4, minmax(130px, 1fr)); }
  .history-list { grid-template-columns: 1fr; }
  .actions { flex-direction: column; }
}
