:root {
  --bg: #e4e7eb;
  --panel: #f8f9fb;
  --ink: #1c2430;
  --muted: #5a6573;
  --line: #c5ccd6;
  --accent: #0b4f8a;
  --accent-ink: #fff;
  --warn: #9a3412;
  --ok: #166534;
  --err-bg: #fef2f2;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  color: var(--ink);
  background: linear-gradient(165deg, #d8dde4 0%, var(--bg) 45%, #eef1f5 100%);
}

.top {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: rgba(248, 249, 251, 0.95);
}
.brand {
  font-family: "IBM Plex Serif", Georgia, serif;
  font-size: 1.45rem;
  letter-spacing: 0.02em;
}
.subtitle { color: var(--muted); font-size: 0.92rem; }

.workspace {
  display: grid;
  grid-template-columns: minmax(300px, 340px) 1fr;
  gap: 0.75rem;
  padding: 0.75rem;
  height: calc(100vh - 3.25rem);
  min-height: 0;
  overflow: hidden;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 0.85rem 1rem;
  overflow: auto;
  min-height: 0;
  max-height: 100%;
}
.panel h2 {
  margin: 0 0 0.55rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

.template-block { margin-bottom: 0.25rem; }
.template-name {
  margin: 0 0 0.35rem;
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.35;
}
.template-block code {
  font-size: 0.75rem;
  background: #eef2f7;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
}

.controls label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.8rem;
  margin-bottom: 0.5rem;
}
.controls input,
.controls select {
  font: inherit;
  padding: 0.38rem 0.45rem;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 2px;
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.45rem; }

.mode-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem;
  align-items: start;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--line);
  background: #fff;
  margin-bottom: 0.4rem;
  cursor: pointer;
  border-radius: 3px;
}
.mode-card.recommended { border-color: var(--accent); background: #f0f6fc; }
.mode-card strong { display: block; font-size: 0.85rem; }
.mode-card small { display: block; color: var(--muted); font-size: 0.72rem; line-height: 1.35; margin-top: 0.1rem; }

.primary {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.72rem 1rem;
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border-radius: 3px;
}
.primary:disabled { opacity: 0.55; cursor: wait; }

.note { font-size: 0.72rem; color: var(--muted); line-height: 1.35; margin: 0.25rem 0 0; }
.warn {
  font-size: 0.78rem;
  color: var(--warn);
  background: #fff7ed;
  border: 1px solid #fdba74;
  padding: 0.45rem 0.55rem;
  border-radius: 3px;
  margin: 0.25rem 0 0.5rem;
}
.warn.hidden { display: none; }

.status { min-height: 1.2rem; font-size: 0.82rem; margin-top: 0.45rem; }
.status.ok { color: var(--ok); }
.status.err { color: var(--warn); }

.calc-banner {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  margin-top: 0.55rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--accent);
  background: #eef5fb;
  border-radius: 3px;
}
.calc-banner.hidden { display: none; }
.spinner {
  width: 1rem; height: 1rem; margin-top: 0.12rem;
  border: 2px solid #9bbad4; border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.result-summary {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}
.result-summary.hidden { display: none; }

.summary-dl { margin: 0; }
.summary-dl > div {
  display: grid;
  grid-template-columns: 5.5rem 1fr;
  gap: 0.3rem;
  padding: 0.22rem 0;
  border-bottom: 1px solid #e8ecf1;
  font-size: 0.86rem;
}
.summary-dl.compact { font-size: 0.8rem; }
.summary-dl dt { color: var(--muted); }
.summary-dl dd { margin: 0; font-weight: 500; }
#sumQty { font-size: 1.35rem; font-weight: 700; color: var(--accent); }

.tech-details { margin-top: 0.55rem; font-size: 0.82rem; }
.tech-details summary { cursor: pointer; color: var(--muted); user-select: none; }

.actions { margin-top: 0.6rem; }
.actions button {
  width: 100%;
  padding: 0.42rem 0.55rem;
  border: 1px solid var(--line);
  background: #fff;
  font: inherit;
  cursor: pointer;
  border-radius: 3px;
}
.actions button:disabled { opacity: 0.5; cursor: not-allowed; }

.preview {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding: 0.65rem 0.85rem;
}
.preview-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}
.preview-header h2 {
  margin: 0;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}
.preview-toolbar { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.preview-toolbar button {
  border: 1px solid var(--line);
  background: #fff;
  padding: 0.28rem 0.55rem;
  font: inherit;
  cursor: pointer;
  border-radius: 3px;
  min-width: 2.2rem;
}

.svg-host {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 3px;
  background:
    linear-gradient(45deg, #e8ebef 25%, transparent 25%),
    linear-gradient(-45deg, #e8ebef 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e8ebef 75%),
    linear-gradient(-45deg, transparent 75%, #e8ebef 75%);
  background-size: 14px 14px;
  background-position: 0 0, 0 7px, 7px -7px, -7px 0;
  background-color: #f1f3f6;
  display: flex;
  align-items: center;
  justify-content: center;
}
.svg-host.is-zoomed {
  overflow: auto;
  align-items: flex-start;
  justify-content: flex-start;
}
.svg-host svg {
  display: block;
  flex-shrink: 0;
  max-width: none;
  max-height: none;
}
.empty-state {
  padding: 1.25rem 1.5rem;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
  max-width: 28rem;
}
.empty-state.error {
  background: var(--err-bg);
  color: var(--warn);
  border-left: 3px solid var(--warn);
  margin: 0.75rem;
}

@media (max-width: 900px) {
  html, body { overflow: auto; }
  .workspace { grid-template-columns: 1fr; height: auto; overflow: visible; }
  .preview { min-height: 380px; }
  .svg-host { height: min(70vh, 640px); }
}
