/* AES Overheating Tool — shares look & feel with the SAP Schedule Generator. */

:root {
  --bg: #f2f2f2;
  --surface: #fff;
  --surface-2: #f7f7f7;       /* slightly off-white for nested panels */
  --text: #1a1a1a;
  --muted: #666;
  --border: #e0e0e0;
  --border-light: #eeeeee;
  --accent: #009B8D;
  --accent-light: #e0f5f3;
  --accent-hover: #007a6e;
  --brand-green: #8DC63F;
  --amber: #b45309;
  --amber-bg: #fef3c7;
  --red: #c0392b;
  --red-bg: #fee2e2;
  --blue: #0077B6;
  --blue-bg: #e0f0fb;
  --pass: #16a34a;
  --pass-bg: #dcfce7;
  --na: #6b7280;
  --radius: 8px;
  --radius-sm: 5px;

  /* Tool-specific */
  --canvas-bg: #fafafa;       /* very light grey behind the canvas */
  --tool-active: var(--accent);
  --snap: #f59e0b;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Sora', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
}
.mono, .build-pill, .doc-name, .uploaded-file .name {
  font-family: 'IBM Plex Mono', ui-monospace, Menlo, monospace;
}
input, select, button, textarea { font: inherit; color: inherit; }

/* ---- Top bar ---- */
.topbar {
  background: var(--surface);
  height: 64px;
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 0 var(--border);
  border-bottom: 3px solid var(--brand-green);
}
.topbar .brand { display: inline-flex; align-items: center; text-decoration: none; }
.topbar .brand img { height: 36px; width: auto; display: block; }
.topbar .tagline {
  font-size: 12px; color: var(--muted);
  border-left: 1px solid var(--border);
  padding-left: 16px;
}
.topbar .job-meta {
  display: flex; gap: 8px; flex: 1; max-width: 540px;
  margin: 0 auto;
}
.topbar .job-meta input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 12px;
  flex: 1; min-width: 0;
}
.topbar .topbar-actions { display: flex; align-items: center; gap: 8px; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 600;
  font-size: 12px;
  padding: 7px 14px;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--accent); border-color: var(--accent); }
.btn-secondary:hover { background: var(--accent-light); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-mini {
  font-size: 11px; padding: 5px 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer; color: var(--text);
}
.btn-mini:hover { background: var(--accent-light); border-color: var(--accent); color: var(--accent); }

/* Status pills */
.status-pill {
  padding: 3px 9px; border-radius: 20px;
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.4px;
  background: var(--border-light); color: var(--muted);
}
.status-pill.build-pill {
  background: transparent; color: #999; border: 1px solid var(--border);
  letter-spacing: 0;
}

/* ---- Layout ---- */
.layout {
  display: grid;
  grid-template-columns: 240px 1fr 360px;
  height: calc(100vh - 64px);
}
.left, .right {
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 14px 14px 60px;
}
.right { border-right: none; border-left: 1px solid var(--border); }

.centre {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  background: var(--canvas-bg);
}

/* ---- Canvas toolbar ---- */
.canvas-toolbar {
  display: flex; gap: 6px; align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-wrap: wrap;
  min-height: 44px;
}
.btn-tool {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 11px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  transition: all 0.12s;
}
.btn-tool:hover:not(:disabled) {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}
.btn-tool:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-tool.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.toolbar-spacer { flex: 1; }
.zoom-readout {
  font-variant-numeric: tabular-nums;
  min-width: 3.6rem; text-align: center;
  font-size: 12px; color: var(--muted);
  cursor: pointer; user-select: none;
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
}
.zoom-readout:hover { color: var(--text); }

/* ---- Canvas host & stack ---- */
.canvas-host {
  flex: 1; overflow: auto;
  display: flex;
  justify-content: safe center;
  align-items: safe flex-start;
  padding: 16px;
}
.canvas-stack {
  position: relative; display: inline-block; flex-shrink: 0;
  background: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08), 0 0 0 1px var(--border);
}
#pdfCanvas { display: block; }
#overlayCanvas {
  position: absolute; inset: 0;
  background: transparent;
  pointer-events: auto;
  cursor: crosshair;
}
.canvas-statusbar {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 5px 12px; color: var(--muted);
  font-size: 11px; min-height: 22px;
}

/* ---- Left pane (drawings & pages) ---- */
.panel-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px;
}
.panel-header h3 {
  margin: 0; font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--muted);
}
.hint { color: var(--muted); font-size: 11px; }

.page-list { list-style: none; margin: 0; padding: 0; }

.page-list li.doc-row {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 4px 6px;
  margin-top: 4px;
  border-top: 1px solid var(--border-light);
}
.page-list li.doc-row:first-child { border-top: none; margin-top: 0; }
.page-list li.doc-row .doc-name {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--text); font-weight: 600; font-size: 12px;
  font-family: inherit;
}
.page-list li.doc-row .doc-meta { font-size: 10px; color: var(--muted); }
.page-list li.doc-row .doc-remove {
  background: transparent; border: 1px solid var(--border-light);
  color: var(--muted); cursor: pointer;
  width: 20px; height: 20px; padding: 0;
  border-radius: 3px; line-height: 1; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center;
}
.page-list li.doc-row .doc-remove:hover { color: var(--red); border-color: var(--red); }

.page-list li.page-row {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px 6px 18px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  font-size: 12px;
  margin-top: 1px;
}
.page-list li.page-row:hover { background: var(--accent-light); }
.page-list li.page-row.active {
  background: var(--accent-light);
  border-color: var(--accent);
}
.page-list li.page-row.active .page-label { color: var(--accent); font-weight: 600; }
.page-list li.page-row .page-label {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.page-list li.page-row .role-tag {
  font-size: 9px; padding: 2px 6px;
  border-radius: 10px;
  background: var(--border-light); color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600;
}
.page-list li.page-row.role-plan .role-tag { background: var(--accent-light); color: var(--accent); }
.page-list li.page-row.role-elev .role-tag { background: #f3e8ff; color: #7c3aed; }
.page-list li.page-row.role-both .role-tag { background: #fef3c7; color: #b45309; }

.active-page-controls {
  display: flex; flex-direction: column; gap: 8px;
  margin-top: 4px;
}
.active-page-controls label {
  display: flex; flex-direction: column; gap: 3px;
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--muted); font-weight: 600;
}
.active-page-controls select,
.active-page-controls input[type="text"] {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 8px; font-size: 12px;
  color: var(--text); font-family: inherit;
  text-transform: none; letter-spacing: 0; font-weight: 400;
}
.active-page-controls select:focus,
.active-page-controls input[type="text"]:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-light);
}
.scale-status {
  font-size: 11px; color: var(--muted);
  padding: 6px 0;
  text-transform: none; letter-spacing: 0; font-weight: 400;
}
.scale-status.set { color: var(--pass); }

/* ---- Right pane (cards) ---- */
details {
  margin-bottom: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--brand-green);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  overflow: hidden;
}
details > summary {
  padding: 10px 14px;
  cursor: pointer; font-weight: 600; font-size: 13px;
  user-select: none;
}
details > summary:hover { background: var(--surface-2); }
details[open] > summary { border-bottom: 1px solid var(--border-light); }

.form { display: flex; flex-direction: column; gap: 10px; padding: 12px; }
.form label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--muted); font-weight: 600;
  position: relative;
}
.form label.row-totals {
  flex-direction: row; justify-content: space-between; align-items: center;
  padding: 6px 0;
  border-top: 1px solid var(--border-light);
  margin-top: 4px;
  text-transform: none; letter-spacing: 0;
}
.form label.row-totals span:first-child { color: var(--muted); }
.form input[type="text"], .form input[type="number"], .form select {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 9px; font-size: 12px; color: var(--text);
  text-transform: none; letter-spacing: 0; font-weight: 400;
  font-family: inherit;
}
.form input:focus, .form select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-light);
}
.readout {
  color: var(--text); font-weight: 700;
  font-family: 'IBM Plex Mono', monospace; font-size: 12px;
}
.risk-tag {
  position: absolute; right: 4px; bottom: 4px;
  font-size: 9px; padding: 2px 7px; border-radius: 10px;
  background: var(--accent-light); color: var(--accent);
  text-transform: uppercase; letter-spacing: 0.4px; font-weight: 700;
}
.risk-tag.high { background: var(--red-bg); color: var(--red); }

/* ---- Tables (rooms / windows) ---- */
table { width: 100%; border-collapse: collapse; font-size: 11px; }
table th, table td {
  padding: 5px 6px; text-align: left;
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap;
}
table th {
  color: var(--muted); font-weight: 600;
  font-size: 9px; text-transform: uppercase; letter-spacing: 0.4px;
}
table td input, table td select {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 3px; padding: 3px 6px;
  color: var(--text); width: 100%; font-size: 11px;
  font-family: inherit;
}
table td.numeric input { text-align: right; font-family: 'IBM Plex Mono', monospace; }
.icon-btn {
  background: transparent; border: 1px solid var(--border-light);
  color: var(--muted); cursor: pointer;
  padding: 1px 6px; border-radius: 3px; font-size: 11px;
}
.icon-btn:hover { color: var(--red); border-color: var(--red); }

details > table { margin: 0; }
details > .form, details > .results, details > table { padding: 12px; }
details > button { margin: 0 12px 12px; }

/* ---- Results panel ---- */
.results { padding: 12px; }
.criterion {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 6px 10px;
  align-items: baseline;
  padding: 7px 0;
  border-bottom: 1px solid var(--border-light);
}
.criterion:last-of-type { border-bottom: none; }
.criterion .name {
  color: var(--muted); font-size: 10px;
  text-transform: uppercase; letter-spacing: 0.4px; font-weight: 600;
}
.criterion .detail {
  color: var(--muted); font-size: 11px;
  font-family: 'IBM Plex Mono', monospace;
}
.verdict {
  font-weight: 700; padding: 2px 8px;
  border-radius: 10px; font-size: 9px;
  letter-spacing: 0.5px; text-transform: uppercase;
}
.verdict.pass { background: var(--pass-bg); color: var(--pass); }
.verdict.fail { background: var(--red-bg); color: var(--red); }
.verdict.na { background: var(--border-light); color: var(--na); }

.results .overall {
  margin-top: 10px;
  padding: 10px 14px;
  border-radius: var(--radius);
  text-align: center;
  font-weight: 700; letter-spacing: 1px;
  text-transform: uppercase;
  font-size: 13px;
}
.results .overall.pass { background: var(--pass-bg); color: var(--pass); border: 1px solid #bbf7d0; }
.results .overall.fail { background: var(--red-bg); color: var(--red); border: 1px solid #fecaca; }

/* ---- Modal dialogs ---- */
.modal-root {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
}
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(20, 20, 20, 0.45);
  backdrop-filter: blur(2px);
}
.modal-card {
  position: relative;
  background: var(--surface);
  border-top: 3px solid var(--brand-green);
  border-radius: var(--radius);
  padding: 20px 22px;
  /* Wider default than 420px so multi-button action rows and 3-column
     input rows (bay window dialog) don't overflow. Capped at 95vw with
     box-sizing border-box so padding doesn't push us over. */
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  box-sizing: border-box;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
  display: flex; flex-direction: column; gap: 12px;
}
.modal-card h3 { font-size: 15px; font-weight: 600; margin: 0 0 4px; }
.modal-card .modal-hint {
  font-size: 11px; color: var(--muted);
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  margin: -4px 0 4px;
}
.modal-card label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--muted); font-weight: 600;
}
.modal-card label input,
.modal-card label select {
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 10px; font-size: 13px; color: var(--text);
  text-transform: none; letter-spacing: 0; font-weight: 400;
  font-family: inherit;
  /* Without border-box, padding pushes inputs over 100% inside flex rows
     and they overflow the modal card. */
  box-sizing: border-box;
  max-width: 100%;
}
.modal-card label input:focus, .modal-card label select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light);
}
.modal-actions {
  display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px;
  margin-top: 6px;
}
.modal-actions .btn { white-space: nowrap; }

.modal-detected {
  display: inline-block;
  font-size: 9px;
  color: var(--accent);
  background: var(--accent-light);
  padding: 1px 6px;
  border-radius: 8px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-weight: 600;
  margin-left: 6px;
  vertical-align: middle;
}

/* ---- Annotation card list (rooms + windows) ---- */
.ann-list { display: flex; flex-direction: column; gap: 4px; padding: 8px; }
.ann-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 7px 9px;
  font-size: 12px;
  transition: background 0.12s, border-color 0.12s;
}
.ann-card:hover {
  background: var(--accent-light);
  border-color: var(--accent);
}
.ann-row1 {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 3px;
}
.ann-name {
  font-weight: 700;
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  font-size: 12px;
}
.ann-tag {
  font-size: 9px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.4px;
  padding: 2px 6px; border-radius: 10px;
}
.ann-tag-facade { background: var(--accent-light); color: var(--accent); }
.ann-tag-type { background: #f3e8ff; color: #7c3aed; }
.ann-edit, .ann-del {
  margin-left: auto;
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--muted);
  cursor: pointer;
  width: 22px; height: 22px; padding: 0;
  border-radius: 3px; line-height: 1; font-size: 12px;
  display: inline-flex; align-items: center; justify-content: center;
}
.ann-edit:hover { color: var(--accent); border-color: var(--accent); }
.ann-del:hover { color: var(--red); border-color: var(--red); }
.ann-del { margin-left: 0; }
.ann-row2 {
  font-size: 11px; color: var(--muted);
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
}
.ann-meta { white-space: nowrap; }
.ann-sep { color: var(--border); margin: 0 4px; }

/* Modal danger button + row layout for paired fields */
.btn-danger {
  background: var(--surface); color: var(--red);
  border-color: var(--red);
}
.btn-danger:hover { background: var(--red-bg); }
.modal-row { display: flex; flex-wrap: wrap; gap: 10px; }
.modal-row > label { min-width: 0; }
.modal-row > label input,
.modal-row > label select { width: 100%; box-sizing: border-box; }

/* Modal sub-label hint and glazing-measure button */
.modal-sub {
  font-weight: 400; text-transform: none; letter-spacing: 0;
  color: var(--muted); font-size: 10px;
}
.modal-glaz-measure {
  margin-top: 4px;
  background: var(--surface); color: var(--accent);
  border: 1px solid var(--accent);
  padding: 5px 9px; border-radius: var(--radius-sm);
  font-size: 11px; cursor: pointer; font-family: inherit;
  text-align: left;
}
.modal-glaz-measure:hover { background: var(--accent-light); }

.modal-computed {
  font-size: 11px;
  color: var(--muted);
  background: var(--surface-2);
  padding: 6px 9px;
  border-radius: var(--radius-sm);
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  border: 1px dashed var(--border);
}
.modal-computed #m_angle_val { color: var(--accent); font-weight: 700; }

/* ===== Instructions / help drawer ===== */
/* Same pattern as the AES Planning Calcs tool — scrim + slide-in panel
   from the right. Triggered by the "? Instructions" topbar button. */
.help-scrim {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 50;
  opacity: 0;
  transition: opacity 180ms ease;
}
.help-scrim:not([hidden]) { opacity: 1; }

.help-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(520px, 94vw);
  background: #fff;
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.12);
  z-index: 60;
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform 220ms ease;
}
.help-panel:not([hidden]) { transform: translateX(0); }

.help-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 22px;
  background: var(--brand-teal, #009B8D);
  color: #fff;
  flex-shrink: 0;
}
.help-header h2 {
  margin: 0;
  font-size: 16px; font-weight: 600; color: #fff;
}
.help-close {
  background: transparent; border: none;
  color: #fff; font-size: 28px; line-height: 1;
  cursor: pointer; padding: 0 6px;
  opacity: 0.85;
}
.help-close:hover { opacity: 1; }

.help-body {
  padding: 18px 22px 32px;
  overflow-y: auto; flex: 1;
  font-size: 13px; line-height: 1.55;
  color: var(--text, #1a1a1a);
}
.help-body h3 {
  margin: 22px 0 8px;
  font-size: 13px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--brand-teal, #009B8D);
}
.help-body h3:first-child { margin-top: 0; }
.help-body p, .help-body ul, .help-body ol { margin: 0 0 10px 0; }
.help-body ul, .help-body ol { padding-left: 20px; }
.help-body li { margin-bottom: 6px; }
.help-body code {
  background: var(--accent-light, #e0f2f1);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  font-size: 12px;
}
.help-body em { font-style: italic; color: var(--muted, #666); }
.help-body strong { color: var(--text, #1a1a1a); font-weight: 600; }

.help-callout {
  background: var(--accent-light, #e0f2f1);
  border-left: 3px solid var(--brand-teal, #009B8D);
  padding: 10px 14px;
  border-radius: 4px;
  margin: 10px 0;
}
.help-tip {
  margin: 8px 0 12px !important;
  padding: 8px 12px;
  background: #fff8e1;
  border-left: 3px solid #f59e0b;
  border-radius: 4px;
  font-size: 12.5px;
}
.help-tip strong { color: #b45309; }
