:root {
  --bg: #f5f3ee;
  --panel: #ffffff;
  --ink: #1d1d1b;
  --ink-soft: #5b5b58;
  --line: #e1ddd3;
  --accent: #c14a2a;
  --accent-soft: #e7d3cb;
  --hi: #2b6cb0;
  --warn: #c08a1f;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

header h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.header-actions { display: flex; gap: 6px; align-items: center; }

#btn-help {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 4px;
  text-decoration: none;
  font-family: inherit;
  display: inline-block;
}
#btn-help:hover { border-color: var(--ink-soft); }

button {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
}
button:hover { border-color: var(--ink-soft); }
button.primary {
  background: var(--ink);
  color: var(--panel);
  border-color: var(--ink);
}
button.primary:hover { background: #000; }

main {
  display: grid;
  grid-template-columns: 280px 1fr;
  flex: 1;
  min-height: 0;
}

#sidebar {
  border-right: 1px solid var(--line);
  background: var(--panel);
  overflow-y: auto;
  padding: 14px 14px 30px;
}

#sidebar section,
#sidebar .sidebar-section { margin-bottom: 18px; }

#sidebar h2 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  margin: 0 0 8px;
}

/* Collapsible <details> sections */
.sidebar-section > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
  border-bottom: 1px solid var(--line);
}
.sidebar-section > summary::-webkit-details-marker { display: none; }
.sidebar-section > summary h2 { margin: 0; }
.sidebar-section > summary::after {
  content: "▸";
  font-size: 10px;
  color: var(--ink-soft);
  transition: transform 0.12s;
}
.sidebar-section[open] > summary::after { transform: rotate(90deg); }
.sidebar-section > summary:hover { background: var(--bg); }
.sidebar-section[open] > *:not(summary) { margin-top: 10px; }

.hint {
  font-size: 12px;
  color: var(--ink-soft);
  margin: 0 0 10px;
  line-height: 1.4;
}

kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0 4px;
}

#catalog-list { display: flex; flex-direction: column; gap: 4px; }

.cat-item {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  background: transparent;
  text-align: left;
  width: 100%;
  font-family: inherit;
  color: inherit;
}
.cat-item:hover { background: var(--bg); }
.cat-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.cat-item .swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.15);
}
.cat-item .label { font-weight: 500; }
.cat-item .cost { font-size: 11px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

.cat-group {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  margin: 10px 0 4px;
  padding-left: 4px;
}

dl#readouts, dl.meta {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  margin: 0;
  font-size: 13px;
}
dl#readouts dt, dl.meta dt { color: var(--ink-soft); }
dl#readouts dd, dl.meta dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
dl#readouts dt .r-faint { color: #8e8a82; font-weight: 400; }
dl#readouts dd.r-over { color: var(--accent); }
dl#readouts dt.r-sub, dl#readouts dd.r-sub { font-size: 11px; padding-left: 12px; }
.r-hidden { display: none !important; }

/* Project actions (Export / Import) inside the Scenarios section */
#project-actions { margin-top: 10px; }
.project-actions-row { display: flex; gap: 6px; }
.project-actions-row .rev-btn { flex: 1; padding: 4px 8px; font-size: 12px; }

/* Revenue panel */
#revenue-section { margin-bottom: 12px; }
#revenue-panel { display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
#revenue-panel .rev-empty { margin: 0; }
.rev-head { color: var(--ink-soft); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }
.rev-variant-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.rev-variant-label { color: var(--ink-soft); }
.rev-variant { flex: 1 1 auto; min-width: 80px; font-size: 13px; padding: 2px 4px; }
.rev-btn {
  background: #f0ece4;
  border: 1px solid #d6d0c4;
  border-radius: 4px;
  padding: 2px 8px;
  font: inherit;
  font-size: 11px;
  color: var(--ink-soft);
  cursor: pointer;
}
.rev-btn:hover { background: #e6e0d4; color: var(--ink); }
.rev-btn-del, .rev-btn-del-variant { padding: 2px 6px; }
.rev-lines { display: flex; flex-direction: column; gap: 4px; }
.rev-line {
  display: grid;
  grid-template-columns: auto 70px 1fr auto;
  gap: 4px;
  align-items: center;
}
.rev-pound { color: var(--ink-soft); padding-right: 2px; }
.rev-price, .rev-mode {
  font: inherit;
  font-size: 13px;
  padding: 2px 4px;
  border: 1px solid #d6d0c4;
  border-radius: 3px;
  background: #fff;
  min-width: 0;
}
.rev-cond { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.rev-cond-row {
  display: grid;
  grid-template-columns: 1fr 70px;
  gap: 6px;
  align-items: center;
  color: var(--ink-soft);
}
.rev-cond-row input {
  font: inherit; font-size: 13px;
  padding: 2px 4px;
  border: 1px solid #d6d0c4; border-radius: 3px;
  background: #fff;
  text-align: right;
}

#canvas-host {
  position: relative;
  min-height: 0;
  overflow: hidden;
}

#canvas {
  width: 100%;
  height: 100%;
  display: block;
  background: var(--bg);
  cursor: crosshair;
}
#canvas.dragging { cursor: grabbing; }
#canvas.placing { cursor: copy; }

#hud-top, #hud-bottom {
  position: absolute;
  left: 14px;
  font-size: 12px;
  color: var(--ink-soft);
  background: rgba(255,255,255,0.85);
  padding: 5px 9px;
  border-radius: 4px;
  pointer-events: none;
  display: flex;
  gap: 12px;
}
#hud-top { top: 14px; }
#hud-bottom { bottom: 14px; }

#hud-scenario {
  position: absolute;
  top: 14px;
  right: 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  background: rgba(255,255,255,0.92);
  padding: 6px 12px;
  border-radius: 4px;
  pointer-events: none;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}
#hud-scenario:empty { display: none; }

#scenarios-list { display: flex; flex-direction: column; gap: 3px; }
.scenario-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 9px;
  font-size: 12.5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  color: inherit;
  cursor: pointer;
  font-family: inherit;
}
.scenario-item:hover { border-color: var(--ink-soft); background: var(--bg); }
.scenario-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--ink);
}
.scenario-item .s-label { font-weight: 600; }
.scenario-item .s-desc { display: block; font-size: 11px; color: var(--ink-soft); margin-top: 2px; }

#hud-selection:not(:empty)::before { content: "·"; padding-right: 8px; color: var(--line); }

.cat-tooltip {
  position: fixed;
  background: #1d1d1b;
  color: #f5f3ee;
  padding: 9px 11px;
  border-radius: 5px;
  font-size: 12px;
  max-width: 280px;
  pointer-events: none;
  z-index: 1000;
  box-shadow: 0 6px 16px rgba(0,0,0,0.22);
  line-height: 1.45;
}
.cat-tooltip.hidden { display: none; }
.cat-tooltip .tt-label { font-weight: 600; font-size: 13px; margin-bottom: 5px; }
.cat-tooltip .tt-row { color: #cfc9be; font-variant-numeric: tabular-nums; }
.cat-tooltip .tt-row strong { color: #f5f3ee; font-weight: 500; }
.cat-tooltip .tt-faint { color: #8e8a82; font-size: 11px; }
.cat-tooltip .tt-notes {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid rgba(255,255,255,0.12);
  color: #cfc9be;
  font-style: italic;
}
