:root {
  --ink: #172033;
  --muted: #667085;
  --line: #d8dee8;
  --panel: #ffffff;
  --canvas: #eef2f7;
  --accent: #0b75a8;
  --accent-2: #7e4dad;
  --danger: #b42318;
  --soft: #f8fafc;
  font-family: Arial, "Noto Sans Thai", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
}

button, input, select { font: inherit; }

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
  background: #f9fbfd;
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand img {
  width: 86px;
  height: 58px;
  object-fit: contain;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.1;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.panel {
  display: grid;
  gap: 10px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.panel h2 {
  margin: 0;
  font-size: 14px;
}

.condition-panel {
  gap: 10px;
}

.condition-summary {
  padding: 8px 10px;
  border: 1px solid #bee2ef;
  border-radius: 7px;
  background: #edf7fb;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
}

label {
  display: grid;
  gap: 5px;
  color: #344054;
  font-size: 12px;
  font-weight: 700;
}

input, select {
  width: 100%;
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
  color: var(--ink);
}

input:focus, select:focus {
  outline: 2px solid rgba(11, 117, 168, 0.22);
  border-color: var(--accent);
}

.export-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  margin-top: auto;
  border: 0;
  border-radius: 7px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
  cursor: pointer;
}

.export-button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.download-again {
  display: inline-flex;
  justify-content: center;
  padding: 9px 10px;
  border: 1px solid #bee2ef;
  border-radius: 7px;
  background: #edf7fb;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}

.download-again[hidden] {
  display: none;
}

.workspace {
  padding: 18px;
  min-width: 0;
  min-height: 100vh;
}

.workbench {
  display: grid;
  grid-template-columns: minmax(340px, 380px) minmax(0, 1fr);
  gap: 16px;
  height: calc(100vh - 36px);
  min-height: 0;
}

.editor-pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  min-height: 0;
}

.editor-band {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.editor-band span {
  display: inline-flex;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.editor-band h2 {
  margin: 3px 0 0;
  font-size: 26px;
}

.summary-pills {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.summary-pills span {
  padding: 7px 10px;
  border-radius: 999px;
  background: #edf7fb;
  border: 1px solid #bee2ef;
}

.summary-pills span:nth-child(2) {
  color: var(--accent-2);
  background: #f5f0fa;
  border-color: #d9c8e8;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
  gap: 10px;
  min-height: 0;
  overflow: auto;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.field-wide { grid-column: span 2; }

.preview-wrap {
  min-height: 0;
  overflow: auto;
  padding: 18px;
  background: #dfe6ef;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.report-preview {
  width: 780px;
  min-height: 1120px;
  margin: 0 auto;
  padding: 44px 30px;
  background: #ffffff;
  border: 1px solid #cfd6e1;
  box-shadow: 0 12px 30px rgba(23, 32, 51, 0.12);
}

.company-name {
  color: #002060;
  font-size: 24px;
  font-weight: 700;
}

.company-line {
  margin-top: 5px;
  font-size: 13px;
}

.preview-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 190px;
  gap: 24px;
  align-items: start;
}

.preview-logo {
  width: 165px;
  height: auto;
}

.preview-meta {
  display: grid;
  grid-template-columns: 95px minmax(0, 1fr);
  gap: 4px 8px;
  margin-top: 6px;
  font-size: 13px;
}

.preview-meta strong { text-align: right; }

.report-title {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  margin: 14px 0 8px;
  padding: 8px 0;
  border-top: 2px solid #111;
  border-bottom: 2px solid #111;
  font-size: 15px;
  font-weight: 700;
}

.spec-grid {
  display: grid;
  grid-template-columns: 110px 132px 48px 28px 136px 116px 44px;
  gap: 3px 8px;
  align-items: baseline;
  font-size: 13px;
}

.label { font-weight: 700; }

.section {
  grid-column: 1 / -1;
  margin-top: 12px;
  padding-top: 4px;
  border-top: 2px solid #111;
  font-weight: 700;
}

.value {
  min-height: 20px;
  color: #101828;
}

.total {
  margin-top: 12px;
  padding: 7px 0 7px 22px;
  border-top: 2px solid #111;
  border-bottom: 2px solid #111;
  background: transparent;
  font-size: 13px;
  font-weight: 400;
}

.total strong {
  display: inline-block;
  min-width: 230px;
  font-weight: 400;
}

.construction-rule {
  grid-column: 1 / -1;
  border-top: 2px solid #111;
  margin-top: 10px;
}

.dimension-images {
  display: flex;
  gap: 24px;
  align-items: end;
  justify-content: flex-start;
  margin-top: 10px;
}

.dimension-images img {
  max-width: 100%;
  max-height: 134px;
  object-fit: contain;
}

.dimension-images.fan-qty-3 {
  gap: 34px;
}

.dimension-images.fan-qty-3 img:first-child {
  width: 330px;
  height: 149px;
  max-height: none;
}

.dimension-images.fan-qty-3 img:last-child {
  transform: translateY(-12px);
}

.remarks {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 2px solid #111;
  font-size: 11px;
  line-height: 1.35;
}

.remarks strong {
  display: block;
  margin-bottom: 5px;
}

#toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 7px;
  background: #172033;
  color: #ffffff;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

#toast.show {
  opacity: 1;
  transform: translateY(0);
}

svg { width: 18px; height: 18px; }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .workspace { min-height: auto; }
  .workbench {
    grid-template-columns: 1fr;
    height: auto;
  }
  .form-grid {
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 640px) {
  .workspace, .sidebar { padding: 12px; }
  .form-grid { grid-template-columns: 1fr; }
  .field-wide { grid-column: span 1; }
  .report-preview { width: 780px; }
}
