/* ═══════════════════════════════════════════════════════════════════════════
   Conduvia — design system v5  (clean professional)
   Font: Inter (Google Fonts), 14px base
   ═══════════════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Design tokens ─────────────────────────────────────────────────────── */
:root {
  --bg-page:      #f0f2f5;
  --bg-panel:     #ffffff;
  --bg-input:     #f7f8fa;
  --border:       #e2e8f0;
  --border-focus: #3b6fd4;
  --text:         #1a1f36;
  --text-muted:   #6b7280;
  --accent:       #3b6fd4;
  --accent-light: #ebf0fb;
  --success:      #16a34a;
  --warning:      #d97706;
  --error:        #dc2626;
  --header-bg:    #1a2a4a;
  --shadow-card:  0 1px 4px rgba(0,0,0,0.08);
  --radius-sm:    6px;
  --radius-md:    10px;
  --radius-lg:    12px;
}

/* ── Animations (only for spinner — never on .card) ────────────────────── */
@keyframes spin { to { transform: rotate(360deg) } }

/* ── Base ──────────────────────────────────────────────────────────────── */
html, body {
  height: 100%;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-page);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

/* ── Header — flat solid navy, 52px ───────────────────────────────────── */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 52px;
  background: var(--header-bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 500;
}

.app-header .brand {
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -.2px;
}

.app-header .tagline {
  font-size: 13px;
  color: #fff;
}

/* ── Page body ─────────────────────────────────────────────────────────── */
.page-body {
  margin-top: 52px;
  padding: 24px;
  max-width: 1100px;
  margin-left: auto;
  margin-right: auto;
}

/* ── Card — white flat panel ─────────────────────────────────────────────
   CRITICAL: NO animation, opacity, transform, or filter here.
   These create WebKit stacking contexts that clip fixed dropdowns.
   ─────────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-panel);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  margin-bottom: 20px;
  overflow: visible;
}

/* ── Section title ─────────────────────────────────────────────────────── */
.section-title {
  padding: 18px 24px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

.card-body {
  padding: 24px 24px 28px;
  overflow: visible;
}

/* ── Utility ───────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Global controls ───────────────────────────────────────────────────── */
.global-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 20px 40px;
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.global-control-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.global-control-group label.check-label {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
  color: var(--text);
}

/* Toggle switch — pill 44×24px, off=#cbd5e0, on=#3b6fd4 */
.global-control-group input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 44px;
  height: 24px;
  background: #cbd5e0;
  border-radius: 12px;
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  transition: background .2s;
}

.global-control-group input[type="checkbox"]::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 18px; height: 18px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}

.global-control-group input[type="checkbox"]:checked            { background: var(--accent); }
.global-control-group input[type="checkbox"]:checked::after     { transform: translateX(20px); }

.global-sub {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: 56px;
}

.global-sub label {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
}

.global-sub input[type="number"] {
  width: 88px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg-input);
  transition: border-color .15s, box-shadow .15s;
}

.global-sub input[type="number"]:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59,111,212,.10);
}

/* ── Floor table — clean, no cell borders ─────────────────────────────── */
.table-wrap { overflow-x: auto; }

.floor-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.floor-table thead th {
  background: var(--bg-input);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 8px 12px;
  text-align: left;
  white-space: nowrap;
}

.floor-table tbody tr { border-bottom: 1px solid var(--border); }
.floor-table tbody tr:last-child { border-bottom: none; }

.floor-table td {
  padding: 10px 12px;
  vertical-align: middle;
  overflow: visible;
}

/* ── Floor name input ──────────────────────────────────────────────────── */
.floor-name-input {
  width: 90px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg-input);
  transition: border-color .15s, box-shadow .15s;
}

.floor-name-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59,111,212,.10);
}

/* ── Scale input ───────────────────────────────────────────────────────── */
.scale-input {
  width: 72px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg-input);
  transition: border-color .15s, box-shadow .15s;
}

.scale-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59,111,212,.10);
}

/* ── DXF file cell ─────────────────────────────────────────────────────── */
.file-cell {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 160px;
}

/* Browse button: dashed border, accent blue */
.file-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: none;
  border: 1.5px dashed #cbd5e0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  color: var(--accent);
  transition: background .15s, border-color .15s, border-style .15s;
  white-space: nowrap;
}

.file-btn:hover {
  background: var(--accent-light);
  border-color: var(--accent);
  border-style: solid;
}

.file-status {
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.file-status .spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}

.file-status .checkmark { color: var(--success); font-size: 14px; }
.file-status .err-icon  { color: var(--error);   font-size: 14px; }
.file-status .filename  { color: #166534; font-size: 12px; word-break: break-all; }

/* ── Server room layer readonly ────────────────────────────────────────── */
.server-layer-readonly {
  color: var(--text-muted);
  font-style: italic;
  font-size: 13px;
}

/* ── Inter-floor cell ──────────────────────────────────────────────────── */
.interfloor-cell {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 200px;
}

.interfloor-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.interfloor-row label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.relay-text-wrap {
  display: flex;
  gap: 6px;
  align-items: center;
}

.relay-text-input {
  flex: 1;
  min-width: 120px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg-input);
  transition: border-color .15s, box-shadow .15s;
}

.relay-text-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59,111,212,.10);
}

.find-btn {
  padding: 7px 10px;
  background: var(--accent-light);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  color: var(--accent);
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}

.find-btn:hover   { background: var(--accent); color: #fff; border-color: var(--accent); }
.find-btn:disabled { opacity: .4; cursor: not-allowed; }

.suggestion-list {
  display: none;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  max-height: 150px;
  overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0,0,0,.10);
}

.suggestion-list.open { display: flex; }

.suggestion-item {
  padding: 7px 12px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}

.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:hover       { background: var(--accent-light); }

/* ── Remove button ─────────────────────────────────────────────────────── */
.remove-btn {
  width: 28px; height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: #cbd5e0;
  font-size: 18px;
  line-height: 1;
  transition: color .15s;
}

.remove-btn:hover { color: var(--error); }

/* ── Add floor button ──────────────────────────────────────────────────── */
.add-floor-wrap { margin-top: 16px; }

.add-floor-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  background: none;
  border: 1.5px solid var(--accent);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, color .15s;
}

.add-floor-btn:hover {
  background: var(--accent);
  color: #fff;
}

/* ── Searchable dropdown ───────────────────────────────────────────────── */
.sd-wrapper {
  position: relative;
  min-width: 160px;
}

.sd-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  height: 34px;
  box-sizing: border-box;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  user-select: none;
  width: 100%;
  text-align: left;
  transition: border-color .15s, box-shadow .15s;
}

.sd-trigger:hover:not(.sd-disabled) { border-color: var(--border-focus); }

.sd-trigger.sd-open {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59,111,212,.10);
}

.sd-trigger.sd-disabled {
  background: var(--bg-input);
  color: #adb5bd;
  cursor: not-allowed;
}

.sd-trigger-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sd-caret {
  flex-shrink: 0;
  font-size: 10px;
  color: var(--text-muted);
  display: inline-block;
  transition: transform .2s;
}

.sd-trigger.sd-open .sd-caret { transform: rotate(180deg); }

.sd-warn {
  color: var(--warning);
  font-size: 14px;
  flex-shrink: 0;
  cursor: help;
}

/* Dropdown panel — position: fixed, z-index: 9999 (never clipped by ancestors) */
.sd-panel {
  position: fixed;
  min-width: 160px;
  max-width: 320px;
  max-height: 280px;
  background: #fff;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  z-index: 9999;
  display: none;
  flex-direction: column;
  overflow: visible;
}

.sd-panel.sd-open {
  display: flex;
  flex-direction: column;
}

.sd-search {
  padding: 8px 10px;
  background: var(--bg-input);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sd-search input {
  width: 100%;
  padding: 6px 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  font-size: 13px;
  font-family: inherit;
  outline: none;
}

.sd-search input:focus { background: #eef0f6; }

.sd-list {
  flex: 1;
  min-height: 0;
  max-height: 220px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sd-option {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  transition: background .1s;
}

.sd-option:hover,
.sd-option.sd-focused   { background: var(--accent-light); }
.sd-option.sd-selected  { background: var(--accent-light); color: var(--accent); font-weight: 500; }
.sd-option.sd-none-opt  { color: var(--text-muted); font-style: italic; }
.sd-option.sd-hidden    { display: none; }

/* Multi-select variant — checkbox inside each option */
.sd-option-multi { display: flex; align-items: center; gap: 8px; }
.sd-multi-cb     { flex-shrink: 0; width: 14px; height: 14px; cursor: pointer; }
.sd-option-text  { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Card 2 — Analysis modules ─────────────────────────────────────────── */
.modules-toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
}

/* Small outlined buttons */
.btn-sm {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}

.btn-sm:hover               { background: var(--bg-input); color: var(--text); }
.btn-sm.btn-danger          { border-color: #fca5a5; color: var(--error); }
.btn-sm.btn-danger:hover    { background: #fef2f2; border-color: var(--error); }

/* 2×3 grid */
.modules-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

@media (max-width: 768px) { .modules-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 480px) { .modules-grid { grid-template-columns: 1fr; } }

/* Module card — horizontal layout: icon left, text middle, check right */
.module-card {
  position: relative;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 44px 14px 14px;
  cursor: pointer;
  display: grid;
  grid-template-columns: 48px 1fr;
  grid-template-rows: auto auto;
  column-gap: 12px;
  user-select: none;
  background: #fff;
  transition: border-color .2s, background .2s;
}

.module-card:hover    { border-color: var(--accent); }
.module-card.selected { border-color: var(--accent); background: #f0f4ff; }

/* Checkmark badge — absolute top-right */
.module-card-check {
  position: absolute;
  top: 12px; right: 12px;
  width: 20px; height: 20px;
  border: 1.5px solid var(--border);
  border-radius: 50%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: transparent;
  transition: background .15s, border-color .15s, color .15s;
}

.module-card.selected .module-card-check {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Icon: 48px circle */
.module-icon-wrap {
  grid-column: 1;
  grid-row: 1 / span 2;
  align-self: center;
  width: 48px; height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.module-icon { font-size: 20px; line-height: 1; }

.module-name {
  grid-column: 2;
  grid-row: 1;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  align-self: end;
  margin-bottom: 2px;
}

.module-desc {
  grid-column: 2;
  grid-row: 2;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
  align-self: start;
}

/* Per-module icon colours */
.module-card[data-mod-id="vd"]         .module-icon-wrap { background: #dbeafe; color: #2563eb; }
.module-card[data-mod-id="wifi"]       .module-icon-wrap { background: #d1fae5; color: #059669; }
.module-card[data-mod-id="cctv"]       .module-icon-wrap { background: #fee2e2; color: #dc2626; }
.module-card[data-mod-id="outlets"]    .module-icon-wrap { background: #fef3c7; color: #d97706; }
.module-card[data-mod-id="fo"]         .module-icon-wrap { background: #ede9fe; color: #7c3aed; }
.module-card[data-mod-id="interfloor"] .module-icon-wrap { background: #ccfbf1; color: #0d9488; }

/* ── Card 3 — Flat accordion (no box/border around sections) ───────────── */
.param-section {
  overflow: visible;
}

/* Sub-section header: full-width button, border-bottom only, no bg */
.param-section-hdr {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 0;
  border: none;
  border-bottom: 1px solid var(--border);
  background: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  text-align: left;
  font-family: inherit;
  transition: color .15s;
}

.param-section-hdr:hover { color: var(--accent); }

.ps-chevron {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
  width: 14px;
  display: inline-block;
  text-align: center;
}

/* Content just flows below — no wrapping box */
.param-section-body {
  overflow: visible;
}

/* ── Param grid ────────────────────────────────────────────────────────── */
.param-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  padding: 16px 0;
}

/* FO grid: always 4 columns on one row */
.fo-grid {
  grid-template-columns: repeat(4, 1fr);
}

.param-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.param-row label {
  font-size: 12px;
  color: var(--text-muted);
  display: block;
  font-weight: 500;
}

.param-row input[type="number"],
.param-row input[type="text"] {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg-input);
  transition: border-color .15s, box-shadow .15s;
}

.param-row input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59,111,212,.10);
}

.param-row .sd-wrapper { width: 100%; min-width: 0; }

.param-input-suffix {
  display: flex;
  align-items: center;
  gap: 8px;
}

.param-input-suffix input { flex: 1; min-width: 0; }

.param-suffix {
  font-size: 13px;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ── Layer Names — grouped grid layout ─────────────────────────────────── */
.layer-row {
  display: grid;
  grid-template-columns: 60px 1fr 1fr;
  gap: 12px;
  align-items: start;
  margin-bottom: 12px;
}

.layer-row:first-of-type { margin-top: 12px; }

.layer-system-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  padding-top: 24px;
}

.layer-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.layer-field label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.layer-row.fo-row { grid-template-columns: 60px 1fr 1fr; }
.layer-row.fo-row .layer-field { grid-column: 2; }

/* ── Inter-floor riser table ───────────────────────────────────────────── */
.riser-table {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-x: auto;
  padding: 16px 0 8px;
}

.riser-header,
.riser-row {
  display: grid;
  grid-template-columns: 70px 80px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
}

.riser-header {
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}

.riser-row {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
}

.riser-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
}

.riser-row input[type="number"] {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  width: 100%;
  min-width: 0;
  background: var(--bg-input);
  transition: border-color .15s, box-shadow .15s;
}

.riser-row input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59,111,212,.10);
}

.riser-row[data-riser="floor-height"] {
  border: none;
  border-radius: 0;
  background: transparent;
  padding-left: 0;
  padding-right: 0;
}

/* Riser total — pill badge */
.riser-total {
  display: inline-block;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.riser-note {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

/* ── Param action buttons ───────────────────────────────────────────────── */
.param-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.btn-param-action {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, color .15s;
}

.btn-param-action:hover            { background: var(--bg-input); color: var(--text); }
.btn-param-action.btn-reset        { border-color: #fca5a5; color: var(--error); }
.btn-param-action.btn-reset:hover  { background: #fef2f2; border-color: var(--error); }

/* ── Card 4 — Run & Results ─────────────────────────────────────────────── */

/* Run button: flat accent blue */
.run-btn {
  display: block;
  width: 100%;
  padding: 12px 32px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s;
  text-align: center;
  letter-spacing: .2px;
}

.run-btn:hover:not(:disabled) { background: #2d5bb8; }

.run-btn:disabled {
  background: #cbd5e0;
  cursor: not-allowed;
  color: #fff;
}

/* run-log-wrap is permanently hidden — replaced by the job progress panel */
.run-log-wrap { margin-top: 18px; }

/* Progress log — dark terminal */
.run-log {
  display: block;
  width: 100%;
  min-height: 160px;
  max-height: 400px;
  overflow-y: auto;
  background: #0f0e17;
  border-radius: 10px;
  padding: 20px;
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.7;
  color: #94a3b8;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 0;
  scroll-behavior: smooth;
}

/* Log line colours */
.run-log .log-ok   { color: #4ade80; }
.run-log .log-warn { color: #fbbf24; }
.run-log .log-err  { color: #f87171; }
.run-log .log-info { color: #93c5fd; }
.run-log .log-scan { color: #e2e8f0; }

/* Status banners */
.run-banner {
  margin-top: 16px;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #86efac;
}

.run-banner.run-banner-error {
  background: #fef2f2;
  color: #991b1b;
  border-color: #fca5a5;
}

.run-download-wrap { margin-top: 16px; }

/* Download button: flat green */
.btn-download {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 32px;
  background: var(--success);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s;
  letter-spacing: .2px;
}

.btn-download:hover { background: #15803d; }

.run-again-wrap {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

/* ── Inter-floor relay layer select (matches SD trigger style) ─────────── */
.relay-layer-select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  box-sizing: border-box;
}

.relay-layer-select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59,111,212,.10);
}

.relay-layer-select:disabled {
  color: #adb5bd;
  cursor: not-allowed;
}

/* ── Pattern detection UI ────────────────────────────────────────────────── */
.pattern-detect-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.detect-btn {
  padding: 4px 10px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-input);
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
}

.detect-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.detect-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }

.pattern-pills { display: flex; gap: 6px; flex-wrap: wrap; }

.pattern-pill {
  padding: 3px 10px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  background: var(--bg-input);
  color: var(--text);
  font-family: inherit;
  transition: all .15s;
}

.pattern-pill:hover { border-color: var(--accent); color: var(--accent); }
.pattern-pill.selected { background: var(--accent); color: white; border-color: var(--accent); }

.pattern-confirm { font-size: 11px; color: var(--text-muted); }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .page-body { padding: 16px 12px; }
  .card-body  { padding: 16px; }
  .fo-grid    { grid-template-columns: repeat(2, 1fr); }
}

/* ── Component Detection panel (Card 4) ─────────────────────────────────── */

.card-hint {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 16px;
  line-height: 1.5;
}

/* Per-system collapsible sections */
.sys-section {
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 8px;
  overflow: hidden;
}

.sys-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  background: #f8f8f8;
  user-select: none;
}

.sys-header:hover { background: #f0f0f0; }

.sys-arrow { font-size: 11px; color: #888; transition: transform 0.15s; }
.sys-section.collapsed .sys-arrow { transform: rotate(-90deg); }
.sys-section.collapsed .sys-body  { display: none; }

.sys-title { font-weight: 600; flex: 1; font-size: 14px; }

.sys-summary {
  font-size: 12px;
  color: #666;
  font-style: italic;
}

.sys-body {
  padding: 12px 14px;
  background: #fff;
}

.sys-search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  width: 100%;
}

.sys-query-input {
  flex: 1;
  min-width: 0;
  height: 34px;
  box-sizing: border-box;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  background: var(--bg-input);
  color: var(--text);
}
.sys-query-input:focus {
  outline: none;
  border-color: var(--border-focus);
  background: #fff;
}

/* Section 4 Find buttons: match .sd-trigger height (scoped to avoid other .btn-sm) */
.sys-search-row .btn-sm {
  height: 34px;
  box-sizing: border-box;
}

.sys-results {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sys-result-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border: 1px solid #eee;
  border-radius: 4px;
  background: #fafafa;
  font-size: 13px;
  cursor: pointer;
}
.sys-result-row:hover { background: #f4f4f4; }

.sys-result-label {
  flex: 1;
  font-family: monospace;
  font-size: 12px;
  word-break: break-word;
}

.sys-result-count {
  color: #666;
  font-size: 12px;
  white-space: nowrap;
}

.sys-struct-hint {
  display: block;
  font-size: 10px;
  color: #aaa;
  font-style: normal;
  margin-top: 2px;
  font-family: monospace;
}
/* Cable Tray — source layer shown below each matched pattern */
.ct-result-layers {
  display: block;
  font-size: 10px;
  color: #888;
  font-style: italic;
  margin-top: 2px;
}

.sys-result-badge {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  background: #e8e8e8;
  color: #555;
}

.sys-bulk-row {
  display: flex;
  gap: 12px;
  margin-bottom: 6px;
  font-size: 12px;
}

.sys-bulk-row a {
  color: #0066cc;
  cursor: pointer;
  text-decoration: none;
}
.sys-bulk-row a:hover { text-decoration: underline; }

.sys-count-summary {
  margin-top: 8px;
  font-size: 12px;
  color: #333;
  font-style: italic;
}

.sys-pattern-note {
  font-size: 11px;
  color: #888;
  margin-bottom: 6px;
  font-style: italic;
}

.sys-empty {
  color: var(--text-muted);
  font-style: italic;
  font-size: 13px;
  padding: 4px 0;
}

/* ── Relay search row in Section 1 ──────────────────────────────────── */
.relay-search-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  width: 100%;
}

.relay-label-text {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  font-weight: 500;
}

.relay-query-input {
  flex: 1;
  min-width: 0;
  width: 100%;
  height: 34px;
  box-sizing: border-box;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-family: inherit;
  background: var(--bg-input);
  color: var(--text);
}
.relay-query-input:focus {
  outline: none;
  border-color: var(--border-focus);
}

.relay-find-btn {
  flex-shrink: 0;
  height: 34px;
  box-sizing: border-box;
  padding: 5px 10px;
  background: var(--accent-light);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  color: var(--accent);
  white-space: nowrap;
}
.relay-find-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

.relay-results {
  margin-top: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.relay-result-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px;
  font-size: 12px;
  border-radius: 3px;
}
.relay-result-row:hover { background: #f4f4f4; }

.relay-result-label {
  flex: 1;
  font-family: monospace;
  font-size: 11px;
  cursor: pointer;
  word-break: break-word;
}

.relay-result-count {
  color: #888;
  font-size: 11px;
  white-space: nowrap;
}

/* ── System section two-column layout (Section 4) ──────────────────── */
.sys-inputs-row {
  display: flex;
  justify-content: flex-start; /* columns sit at the left; do not stretch */
  gap: 32px;
  align-items: flex-start;     /* both columns start at the same top edge */
  margin-bottom: 10px;
}

/* Both columns: same fixed width, no grow/shrink */
.sys-pattern-col,
.sys-layer-col {
  width: 280px;
  flex-shrink: 0;
  flex-grow: 0;
}

/* Label above the pattern search — matches Cable layer: label style */
.sys-input-label {
  font-size: 12px;
  color: #555;
  margin-bottom: 4px;
}

/* SD trigger fills the full column width */
.sys-layer-col .sd-wrapper {
  width: 100%;
  min-width: 0;
}

.sys-layer-label {
  font-size: 11px;
  color: #666;
  margin-bottom: 4px;
}

.sys-layer-search {
  width: 100%;
  padding: 5px 8px;
  border: 1px solid #ccc;
  border-radius: 4px 4px 0 0;
  font-size: 12px;
  box-sizing: border-box;
  font-family: inherit;
}
.sys-layer-search:focus {
  outline: none;
  border-color: var(--border-focus);
}

.sys-layer-select {
  width: 100%;
  height: 90px;
  border: 1px solid #ccc;
  border-top: none;
  border-radius: 0 0 4px 4px;
  font-size: 12px;
  font-family: monospace;
  background: var(--bg-input);
}
.sys-layer-select option { padding: 3px 6px; }

.sys-layer-selected {
  font-size: 11px;
  color: #0066cc;
  margin-top: 4px;
  font-style: italic;
  min-height: 16px;
}

/* ── Pre-flight validation warnings ────────────────────────────────── */
.preflight-warning {
  color: #b84000;
  font-size: 13px;
  padding: 4px 0;
  font-family: monospace;
}

.run-anyway-btn {
  margin-top: 12px;
  padding: 8px 16px;
  background: #fff3e0;
  border: 1px solid #b84000;
  border-radius: 4px;
  color: #b84000;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  display: block;
}
.run-anyway-btn:hover { background: #ffe0c0; }

/* ── Server room badge ─────────────────────────────────────────────── */
.server-badge {
  font-size: 11px;
  margin-top: 5px;
  padding: 4px 8px;
  border-radius: 4px;
  font-weight: 500;
  display: none;
}
.server-found {
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
}
.server-missing {
  background: #fff7ed;
  color: #9a3412;
  border: 1px solid #fed7aa;
  font-weight: 600;
}

/* ── Cable Tray subsection extras ─────────────────────────────────── */
.ct-extra-inputs {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 8px 0 4px 0;
}
.ct-extra-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.ct-extra-label {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}
.ct-extra-num {
  width: 68px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--bg-input);
  color: var(--text);
}
.ct-extra-num:focus {
  outline: none;
  border-color: var(--border-focus);
}
.ct-report-row {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.ct-report-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  font-weight: 500;
}
.ct-report-btn:hover { background: #2d5ab8; }
.ct-report-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.ct-report-status {
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Upload progress bar ─────────────────────────────────────────────── */
.upload-progress-wrap {
  width: 100%;
  height: 4px;
  background: #e5e7eb;
  border-radius: 2px;
  margin-top: 4px;
  overflow: hidden;
}
.upload-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.2s ease, opacity 0.8s ease;
  opacity: 1;
}
.upload-progress-bar.pulse {
  animation: upload-pulse 1s ease-in-out infinite;
}
@keyframes upload-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}
.upload-progress-bar.error {
  background: #ef4444;
}
.upload-progress-bar.fade-out {
  opacity: 0;
}

/* ── Job progress panel ──────────────────────────────────────────────── */
.job-progress-panel {
  height: 160px;
  overflow-y: auto;
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 8px;
  font-size: 12px;
  font-family: monospace;
  margin-top: 12px;
}
.job-progress-line.done    { color: #16a34a; }
.job-progress-line.running { color: #2563eb; }
.job-progress-line.failed  { color: #ef4444; }

/* ── Generated Reports panel ────────────────────────────────────────────── */
.reports-panel { margin-top: 16px; }
.reports-panel-header { display: flex; justify-content: space-between; align-items: center; }
.reports-toggle-icon  { font-size: 11px; color: #6b7280; transition: transform 0.2s; }
.reports-toggle-icon.open { transform: rotate(180deg); }

.reports-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  font-size: 13px;
}
.reports-table th {
  text-align: left;
  padding: 6px 8px;
  background: #f1f5f9;
  border-bottom: 2px solid #e5e7eb;
  font-weight: 600;
  color: #374151;
}
.reports-table td {
  padding: 8px;
  border-bottom: 1px solid #e5e7eb;
  vertical-align: middle;
}
.reports-table tr:last-child td { border-bottom: none; }

.report-download-btn {
  display: inline-block;
  padding: 4px 10px;
  background: var(--accent, #2563eb);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.report-download-btn:hover { background: #1d4ed8; }

.report-expired {
  color: #9ca3af;
  font-style: italic;
  font-size: 12px;
}

.report-row-new { background: #f0fdf4; }
.report-row-new td { transition: background 2s ease; }

/* ── Collapsible cards (Sections 3 & 4) ─────────────────────────────────── */
.card.collapsed .card-body { display: none; }
.section-title.collapsible  { cursor: pointer; user-select: none; }
.section-title.collapsible::after {
  content: ' ▲';
  float: right;
  font-size: 11px;
  color: #6b7280;
  transition: transform 0.2s;
}
.card.collapsed .section-title.collapsible::after { content: ' ▼'; }
