:root {
  --paper: #EEF0EC;
  --panel: #FFFFFF;
  --ink: #1B2430;
  --ink-2: #5B6572;
  --line: #D8DCD6;
  --line-2: #C3C8C0;
  --teal: #0B7285;
  --teal-2: #0A5F6E;
  --teal-soft: #DCEFF2;
  --amber: #D9822B;
  --amber-soft: #FBE9D7;
  --red: #B23A3A;
  --green: #2F7D4F;
  --rail-w: 72px;
  --browser-w: 272px;
  --inspector-w: 300px;
  --top-h: 52px;
  --status-h: 30px;
  --radius: 6px;
  --font: "IBM Plex Sans", "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: "IBM Plex Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font-family: var(--font); font-size: 13.5px; color: var(--ink); background: var(--paper); overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
#app {
  display: grid; height: 100vh;
  grid-template-columns: var(--rail-w) var(--browser-w) 1fr var(--inspector-w);
  grid-template-rows: var(--top-h) 1fr;
  grid-template-areas: "top top top top" "rail browser stage inspector";
}
.hidden { display: none !important; }

/* top bar */
.topbar { grid-area: top; display: flex; align-items: center; gap: 18px; padding: 0 14px 0 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; letter-spacing: .01em; }
.brand .mark { width: 18px; height: 18px; border-radius: 4px; background: linear-gradient(135deg, var(--teal) 0 55%, var(--amber) 55% 100%); }
.project-title { display: flex; align-items: baseline; gap: 10px; }
.project-title input { border: 1px solid transparent; background: transparent; font-size: 15px; font-weight: 500; padding: 4px 6px; border-radius: 4px; min-width: 260px; }
.project-title input:hover, .project-title input:focus { border-color: var(--line); background: #fff; outline: none; }
.save-state { color: var(--ink-2); font-size: 12px; }
.levels { display: flex; gap: 4px; margin-left: 10px; }
.levels button { border: 1px solid var(--line); background: #fff; padding: 4px 10px; border-radius: 999px; cursor: pointer; color: var(--ink-2); }
.levels button.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.actions { margin-left: auto; display: flex; gap: 6px; }
.actions .btn { padding: 6px 9px; white-space: nowrap; }
.btn { border: 1px solid var(--line-2); background: #fff; padding: 6px 12px; border-radius: var(--radius); cursor: pointer; }
.btn:hover { border-color: var(--ink-2); }
.btn.primary { background: var(--teal); border-color: var(--teal); color: #fff; font-weight: 500; }
.btn.primary:hover { background: var(--teal-2); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); }
.btn:disabled { opacity: .5; cursor: default; }
.mini { border: 1px solid var(--line); background: #fff; border-radius: 4px; width: 22px; height: 22px; line-height: 18px; cursor: pointer; padding: 0; color: var(--ink-2); }
.mini:hover { color: var(--ink); border-color: var(--ink-2); }

/* rail */
.rail { grid-area: rail; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 8px 6px; gap: 14px; }
.tools { display: flex; flex-direction: column; gap: 2px; }
.tools.secondary { margin-top: auto; }
.tool { border: 0; background: transparent; border-radius: var(--radius); padding: 7px 2px 5px; display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer; color: var(--ink-2); font-size: 11px; }
.tool svg { width: 22px; height: 22px; fill: currentColor; }
.tool:hover { background: var(--paper); color: var(--ink); }
.tool.active { background: var(--teal-soft); color: var(--teal-2); }

/* browser */
.browser { grid-area: browser; background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; padding: 6px 0 20px; }
.browser section { padding: 10px 14px 8px; border-bottom: 1px solid var(--line); }
.browser h3, .inspector h3 { margin: 0 0 8px; font-size: 12px; font-weight: 600; color: var(--ink-2); display: flex; align-items: center; justify-content: space-between; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 4px; cursor: pointer; }
.list li:hover { background: var(--paper); }
.list li.active { background: var(--teal-soft); }
.list li .swatch { width: 10px; height: 10px; border-radius: 2px; border: 1px solid rgba(0,0,0,.2); flex: none; }
.list li .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list li .meta { color: var(--ink-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.form label { display: block; font-size: 12px; color: var(--ink-2); margin: 6px 0 2px; }
.form input, .form select, .form textarea { width: 100%; border: 1px solid var(--line); border-radius: 4px; padding: 5px 7px; background: #fff; margin-top: 2px; }
.form input:focus, .form select:focus { outline: 2px solid var(--teal-soft); border-color: var(--teal); }
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.form .row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.form .actions-row { display: flex; gap: 6px; margin-top: 10px; }

/* stage */
.stage { grid-area: stage; position: relative; background: var(--paper); overflow: hidden; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: calc(100% - var(--status-h)); display: block; }
.stage-hint { position: absolute; left: 50%; top: 44%; transform: translate(-50%, -50%); color: var(--ink-2); background: rgba(255,255,255,.85); padding: 12px 18px; border-radius: 8px; border: 1px dashed var(--line-2); pointer-events: none; }
.statusbar { position: absolute; left: 0; right: 0; bottom: 0; height: var(--status-h); background: var(--panel); border-top: 1px solid var(--line); display: flex; align-items: center; gap: 14px; padding: 0 12px; font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.statusbar .sep { width: 1px; height: 16px; background: var(--line); }
.statusbar .chk { display: flex; align-items: center; gap: 4px; }
.statusbar select { border: 1px solid var(--line); border-radius: 3px; padding: 0 2px; font-size: 12px; }
#cursorPos { font-family: var(--mono); min-width: 150px; }

/* inspector */
.inspector { grid-area: inspector; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 12px 14px 30px; }
.inspector .empty { color: var(--ink-2); padding: 10px 0; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; font-size: 12.5px; margin: 6px 0 10px; }
.kv span:nth-child(even) { font-variant-numeric: tabular-nums; text-align: right; }
.inspector .section-title { font-size: 11.5px; color: var(--ink-2); margin: 14px 0 4px; font-weight: 600; }
.win-row { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; padding: 4px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; cursor: pointer; }
.win-row:hover { background: var(--paper); }
.win-row.active { background: var(--amber-soft); }
.win-row .tag { font-family: var(--mono); font-size: 11.5px; color: var(--amber); }

/* progress + results */
.progress { position: fixed; left: calc(var(--rail-w) + var(--browser-w) + 16px); bottom: calc(var(--status-h) + 14px); width: 340px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; box-shadow: 0 6px 24px rgba(27,36,48,.12); z-index: 20; }
.progress { width: 380px; max-height: 50vh; overflow-y: auto; }
.progress .job { margin: 6px 0; }
.progress .job .name { font-size: 12px; display: flex; justify-content: space-between; color: var(--ink); }
.progress .job .name small { color: var(--ink-2); }
.progress .job .name button { font-size: 11px; }
.progress .bar { height: 6px; background: var(--paper); border-radius: 3px; overflow: hidden; }
.progress .fill { height: 100%; width: 0; background: var(--teal); transition: width .4s; }
.progress .label { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; font-size: 12.5px; color: var(--ink-2); }
.results { position: fixed; top: var(--top-h); right: 0; bottom: 0; width: 640px; background: var(--panel); border-left: 1px solid var(--line); box-shadow: -8px 0 30px rgba(27,36,48,.12); z-index: 30; overflow-y: auto; padding: 18px 22px 40px; }
.results h2 { margin: 0 0 4px; font-size: 18px; font-weight: 600; }
.results .sub { color: var(--ink-2); margin-bottom: 14px; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 12px 0 18px; }
.kpi { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.kpi b { display: block; font-size: 20px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--ink-2); }
.results table { width: 100%; border-collapse: collapse; font-size: 12.5px; margin: 6px 0 14px; }
.results th, .results td { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: right; font-variant-numeric: tabular-nums; }
.results th:first-child, .results td:first-child { text-align: left; }
.results th { color: var(--ink-2); font-weight: 500; }
.results .files a { margin-right: 12px; color: var(--teal); }
.results canvas { width: 100%; height: 190px; display: block; }
.closebtn { float: right; }
.warn { background: var(--amber-soft); border-left: 3px solid var(--amber); padding: 8px 10px; border-radius: 0 6px 6px 0; margin: 10px 0; font-size: 12.5px; }
.err { background: #F9E3E3; border-left: 3px solid var(--red); padding: 8px 10px; margin: 10px 0; font-size: 12.5px; white-space: pre-wrap; font-family: var(--mono); }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(27,36,48,.35); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-card { background: var(--panel); border-radius: 10px; width: min(760px, 92vw); max-height: 86vh; overflow: auto; padding: 20px 22px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-card h2 { margin: 0 0 10px; font-size: 17px; }
.modal-card pre { background: var(--paper); padding: 10px; border-radius: 6px; max-height: 50vh; overflow: auto; font-family: var(--mono); font-size: 11.5px; }
.modal-card .grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.shape-card { border: 1px solid var(--line); border-radius: 8px; padding: 10px; cursor: pointer; text-align: center; }
.shape-card:hover { border-color: var(--teal); background: var(--teal-soft); }
.shape-card svg { width: 80px; height: 60px; fill: var(--teal-soft); stroke: var(--teal); stroke-width: 2; }
.proj-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 6px; border-bottom: 1px solid var(--line); cursor: pointer; }
.proj-row:hover { background: var(--paper); }
.proj-row .meta { color: var(--ink-2); font-size: 12px; }
.toast { position: fixed; left: 50%; bottom: 48px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 9px 16px; border-radius: 8px; z-index: 60; font-size: 13px; }
.toast.error { background: var(--red); }

@media (max-width: 1100px) {
  #app { grid-template-columns: var(--rail-w) 220px 1fr 260px; }
  .results { width: 100%; }
}

.picklist { position: absolute; z-index: 40; background: var(--panel); border: 1px solid var(--line-2); border-radius: 6px; box-shadow: 0 8px 24px rgba(27,36,48,.15); width: 300px; max-height: 320px; overflow-y: auto; margin-top: -2px; }
.picklist div { padding: 6px 10px; cursor: pointer; font-size: 12.5px; display: flex; justify-content: space-between; gap: 8px; }
.picklist div:hover, .picklist div.active { background: var(--teal-soft); }
.picklist small { color: var(--ink-2); white-space: nowrap; }
.weather-info { font-size: 12px; color: var(--ink-2); margin: 4px 0 2px; line-height: 1.4; }

.param-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.param-grid .col { border: 1px solid var(--line); border-radius: 6px; padding: 8px; max-height: 280px; overflow-y: auto; font-size: 12px; }
.param-grid .col h4 { margin: 0 0 6px; font-size: 12px; color: var(--ink-2); }
.param-grid label { display: block; padding: 2px 0; }
.results .best { background: #E3F3E7; }

.login { position: fixed; inset: 0; background: var(--paper); z-index: 80; display: flex; align-items: center; justify-content: center; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px 30px; width: 380px; box-shadow: 0 20px 60px rgba(27,36,48,.12); }
.login-card h2 { margin: 0 0 10px; font-size: 18px; }
.ledger-row { display: grid; grid-template-columns: 110px 1fr 70px 70px; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.ledger-row span:nth-child(3), .ledger-row span:nth-child(4) { text-align: right; font-variant-numeric: tabular-nums; }
.pkg { border: 1px solid var(--line); border-radius: 8px; padding: 12px; text-align: center; cursor: pointer; }
.pkg:hover { border-color: var(--teal); background: var(--teal-soft); }
.pkg b { display: block; font-size: 22px; }

/* building wizard (File Generator style steps) */
.wizard-card { width: min(900px, 94vw); }
.wiz-steps { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0 12px; }
.wiz-steps button { border: 1px solid var(--line); background: #fff; padding: 4px 10px; border-radius: 999px; cursor: pointer; color: var(--ink-2); font-size: 12px; }
.wiz-steps button.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.wiz-steps button.done { border-color: var(--teal); color: var(--teal); }
.wiz-page { display: none; } .wiz-page.active { display: block; }
.wiz-geo { display: grid; grid-template-columns: 260px 1fr; gap: 14px; align-items: start; }
.wiz-geo svg { width: 100%; height: 230px; background: var(--paper); border: 1px solid var(--line); border-radius: 6px; }
.form .row4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.wiz-help { font-size: 11.5px; color: var(--ink-2); margin: 4px 0 8px; }
.units-toggle { display: inline-flex; gap: 0; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.units-toggle button { border: 0; background: #fff; padding: 3px 9px; cursor: pointer; font-size: 12px; color: var(--ink-2); }
.units-toggle button.active { background: var(--teal); color: #fff; }
