:root {
  color-scheme: light;
  --ink: #17212b;
  --muted: #5d6b79;
  --line: #d7dee5;
  --line-strong: #b8c4cf;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --soft: #eef2f5;
  --accent: #1f6f5c;
  --accent-soft: #dcefe9;
  --warn: #8a5a00;
  --danger: #a33a2b;
  --shadow: 0 8px 24px rgba(23, 33, 43, 0.08);
  --radius: 8px;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.45;
}

button, input, select, textarea { font: inherit; }

a { color: var(--accent); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 20;
  padding: 8px 12px;
  background: var(--ink);
  color: #fff;
  border-radius: 0 0 6px 6px;
}
.skip-link:focus { top: 0; }

.app-header {
  display: grid;
  grid-template-columns: auto minmax(260px, 1fr) minmax(220px, 340px) auto auto;
  align-items: center;
  gap: 16px;
  min-height: 64px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  min-width: 150px;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.brand-text { display: grid; line-height: 1.15; }
.brand-text strong { font-size: 16px; }
.brand-text span { color: var(--muted); font-size: 12px; }

.workspaces, .panel-nav { display: flex; gap: 4px; flex-wrap: wrap; }
.workspaces { justify-content: flex-start; }

.workspace-tab, .panel-tab {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.workspace-tab:hover, .panel-tab:hover { background: var(--soft); color: var(--ink); }
.workspace-tab[aria-selected="true"], .panel-tab[aria-selected="true"] {
  background: var(--ink);
  color: #fff;
}
.workspace-tab:focus-visible, .panel-tab:focus-visible,
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.global-search {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  background: var(--bg);
}
.global-search input {
  border: 0;
  background: transparent;
  min-width: 0;
  width: 100%;
  outline: none;
}
kbd {
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 5px;
  color: var(--muted);
  font-size: 11px;
  background: #fff;
}

.skin-control { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.skin-control select, .field select, .field input {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  background: #fff;
  color: var(--ink);
}

.header-status { color: var(--muted); font-size: 12px; white-space: nowrap; }
.header-status[data-kind="error"] { color: var(--danger); }
.header-status[data-kind="ok"] { color: var(--accent); }

.app-main {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: calc(100vh - 64px);
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 14px;
  overflow: auto;
  max-height: calc(100vh - 64px);
}
.panel-nav { margin-bottom: 14px; }

.side-detail {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}
.side-detail h3 { margin: 0 0 6px; color: var(--ink); font-size: 14px; }
.side-detail dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 8px; }
.side-detail dt { color: var(--muted); }
.side-detail dd { margin: 0; color: var(--ink); }
.side-detail ul { padding-left: 0; margin: 6px 0; list-style: none; }
.side-detail li { display: flex; justify-content: space-between; gap: 8px; }
.side-detail li a { text-align: right; }

.panel {
  padding: 20px 24px 48px;
  overflow: auto;
  max-height: calc(100vh - 64px);
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.panel-head h2 { margin: 0; font-size: 22px; letter-spacing: -0.01em; }
.panel-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.hint { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12px; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
}
.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 12px 14px;
  display: grid;
  gap: 6px;
  box-shadow: 0 1px 0 rgba(23, 33, 43, 0.03);
}
.card h3 { margin: 0; font-size: 15px; }
.card p { margin: 0; color: var(--muted); }
.card .card-foot { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 4px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--soft);
  color: var(--muted);
}
.badge.fit { background: var(--accent-soft); color: var(--accent); }
.badge.inventory { background: #e8eef8; color: #2d4d7a; }
.badge.landscape { background: #f4ecdc; color: var(--warn); }
.badge.synthesis { background: #f1e8f5; color: #6a3b7c; }

button.primary, button.secondary, .button {
  appearance: none;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  padding: 7px 12px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
button.secondary, .button.secondary {
  background: #fff;
  color: var(--accent);
}
button:disabled { opacity: 0.55; cursor: not-allowed; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  padding: 5px 11px;
  cursor: pointer;
  color: var(--muted);
}
.chip[aria-pressed="true"] { border-color: var(--ink); background: var(--ink); color: #fff; }

.fit-layout {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.form-card, .result-card, .table-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 14px 16px;
}
.form-card { display: grid; gap: 12px; }
.field { display: grid; gap: 4px; }
.field label { font-weight: 600; font-size: 12px; color: var(--muted); }
.field input, .field select { width: 100%; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; }
.check-grid label { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--ink); }
.form-note { margin: 0; color: var(--muted); font-size: 12px; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.metric {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 10px 12px;
}
.metric span { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
.metric strong { font-size: 18px; font-variant-numeric: tabular-nums; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { background: var(--soft); color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; overflow-wrap: anywhere; min-width: 180px; }

.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.chart-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); padding: 10px; }
.chart-card h3 { margin: 0 0 6px; font-size: 13px; color: var(--muted); }
canvas { width: 100%; height: 240px; display: block; }

.legend-list { display: flex; gap: 10px; flex-wrap: wrap; margin: 8px 0 14px; }
.legend-item { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); font-size: 12px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; border: 1px solid rgba(0, 0, 0, 0.15); }

.landscape-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 10px;
}
.landscape-map { width: 100%; height: auto; display: block; }
.landscape-map path { stroke: #fff; stroke-width: 1.2; cursor: pointer; transition: opacity 120ms ease; }
.landscape-map path:hover, .landscape-map path.selected { opacity: 0.72; stroke: var(--ink); stroke-width: 2; }
.landscape-map text { fill: var(--ink); font-size: 10px; pointer-events: none; }

.split {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(0, 1.6fr);
  gap: 16px;
  align-items: start;
}

.code-block {
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: #1d2733;
  color: #e7edf3;
  overflow: auto;
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.file-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.file-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: var(--panel);
}
.file-list .mono { color: var(--muted); }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  background: var(--ink);
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 30;
}
.toast[data-kind="error"] { background: var(--danger); }

.loading { color: var(--muted); padding: 20px 0; }
.error { color: var(--danger); }
.empty {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.6);
}

@media (max-width: 1100px) {
  .app-header { grid-template-columns: auto 1fr auto; }
  .workspaces { grid-column: 1 / -1; order: 5; }
  .global-search { grid-column: 2; }
  .fit-layout, .split { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .app-main { grid-template-columns: 1fr; }
  .sidebar { max-height: none; border-right: 0; border-bottom: 1px solid var(--line); }
  .panel { max-height: none; padding: 16px; }
  .chart-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
