body { margin: 0; display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* ── Left sidebar ── */
.st-sidebar {
  width: 160px; flex-shrink: 0;
  display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border);
  overflow-y: auto; overflow-x: hidden;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.st-sidebar::-webkit-scrollbar { width: 3px; }
.st-sidebar::-webkit-scrollbar-track { background: transparent; }
.st-sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.sb-section { padding: 6px 6px 2px; }
.sb-section-label {
  font-size: 0.62rem; font-weight: 700; letter-spacing: 0.06em;
  color: var(--text-dim); text-transform: uppercase;
  padding: 0 2px 4px; display: block;
}
.sb-btn {
  display: block; width: 100%; padding: 6px 8px;
  border-radius: 4px; border: 1px solid transparent;
  background: transparent; color: var(--text);
  font-size: 0.82rem; cursor: pointer; text-align: left;
  font-family: inherit; margin-bottom: 2px; white-space: nowrap;
  transition: background 0.12s;
}
.sb-btn:hover { background: var(--surface2); border-color: var(--border); }
.sb-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.sb-sep { height: 1px; background: var(--border); margin: 4px 0; }
.sb-key { font-size: 0.67rem; color: var(--text-dim); float: right; opacity: 0.6; }
.sb-btn.active .sb-key { color: rgba(255,255,255,0.7); }
.sb-def-wrap { padding: 4px 6px 6px; font-size: 0.72rem; color: var(--text-dim); }
.sb-def-wrap input[type=range] { width: 100%; margin: 3px 0; }
.sb-diag-row { display: flex; gap: 4px; padding: 2px 6px 6px; }
.sb-diag-btn {
  flex: 1; padding: 4px 0; border-radius: 4px; border: 1px solid var(--border);
  background: var(--surface2); color: var(--text); font-size: 0.78rem;
  cursor: pointer; font-family: inherit; text-align: center;
}
.sb-diag-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Layout: sidebar lijevo, canvas sredina, dijagrami desno ── */
.st-main {
  display: grid; grid-template-columns: 160px 1fr 640px;
  flex: 1; overflow: hidden; min-height: 0;
}

/* ── Editor (SVG canvas) ── */
.st-editor { position: relative; overflow: hidden; background: var(--bg); }
#st-canvas { width: 100%; height: 100%; display: block; cursor: crosshair; user-select: none; }
#st-hover-tip {
  position: fixed; pointer-events: none; display: none;
  background: var(--navy-800, #0d2137); color: var(--text, #e0e0e0);
  border: 1px solid var(--border, #2a3f55); border-radius: 4px;
  font-size: 0.72rem; font-family: var(--font-mono, monospace);
  padding: 2px 7px; white-space: nowrap; z-index: 9999;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

/* ── Dijagrami — 3 panela vertikalno desno ── */
.st-diagrams {
  display: flex; flex-direction: column;
  border-left: 2px solid var(--border); overflow: hidden;
}
.diag-panel {
  flex: 1; display: flex; flex-direction: column;
  border-bottom: 1px solid var(--border); padding: 4px; min-height: 0; overflow: hidden;
}
.diag-panel:last-child { border-bottom: none; }
.diag-label {
  font-size: 0.72rem; font-weight: 600; padding: 2px 4px;
  flex-shrink: 0;
}
.diag-label.m { color: #ff6b35; }
.diag-label.v { color: #4caf50; }
.diag-label.n { color: #90caf9; }
.diag-label-row {
  display: flex; align-items: center; gap: 6px;
  flex-shrink: 0; padding: 2px 4px;
}
.n-filter-btns { display: flex; gap: 3px; }
.n-fbtn {
  background: none; border: 1px solid var(--border);
  color: var(--text-dim); font-size: 0.65rem; font-weight: 600;
  padding: 1px 5px; border-radius: 3px; cursor: pointer;
  font-family: inherit; transition: background 0.15s, color 0.15s;
}
.n-fbtn:hover { background: rgba(255,255,255,0.07); }
.n-fbtn.active[data-filter="all"]         { background: rgba(144,202,249,0.18); color: #90caf9; border-color: #90caf9; }
.n-fbtn.active[data-filter="tension"]     { background: rgba(144,202,249,0.18); color: #90caf9; border-color: #90caf9; }
.n-fbtn.active[data-filter="compression"] { background: rgba(239, 83, 80,0.18); color: #ef5350; border-color: #ef5350; }
.diag-svg { flex: 1; display: block; width: 100%; min-height: 0; }

/* ── EC0 toolbar ── */
.diag-ec0-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 3px; padding: 4px 6px;
  background: var(--surface2); border-bottom: 1px solid var(--border);
  flex-shrink: 0; position: relative;
}
.diag-ec0-btn {
  padding: 3px 8px; border-radius: 4px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 0.72rem;
  cursor: pointer; font-family: inherit; white-space: nowrap;
}
.diag-ec0-btn:hover { background: var(--surface2); }
.diag-ec0-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.diag-ec0-sep { flex: 1; }

/* ── Diagram tabs — overlay u gornjem lijevom kutu canvasa ── */
.diag-tabs {
  position: absolute; top: 6px; left: 6px; z-index: 5;
  display: flex; flex-wrap: wrap; gap: 2px;
  pointer-events: all;
}
.diag-tab {
  padding: 3px 9px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-dim); font-size: 0.68rem;
  cursor: pointer; font-family: inherit; white-space: nowrap;
}
.diag-tab:hover { background: var(--surface2); color: var(--text); }
.diag-tab.active { color: #fff; border-color: transparent; }
.diag-tab.tab-g.active  { background: #ff6b35; }
.diag-tab.tab-q.active  { background: #1e88e5; }
.diag-tab.tab-combined.active { background: var(--accent); }
.diag-fav-info {
  font-size: 0.68rem; padding: 2px 8px; flex-shrink: 0;
  color: var(--text-dim); background: var(--surface2); border-bottom: 1px solid var(--border);
}

/* ── Popups ── */
.st-popup {
  position: fixed; background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 10px; box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  z-index: 100; min-width: 200px; display: none;
}
.st-popup.visible { display: block; }
.st-popup h4 { margin: 0 0 8px; font-size: 0.85rem; color: var(--text); }
.st-popup label { font-size: 0.78rem; color: var(--text-dim); display: block; margin-bottom: 6px; }
.st-popup input, .st-popup select {
  width: 100%; padding: 4px 6px; border-radius: 4px;
  border: 1px solid var(--border); background: var(--bg);
  color: var(--text); font-size: 0.82rem; margin-top: 2px; box-sizing: border-box;
}
.st-popup .popup-row { display: flex; gap: 6px; }
.st-popup .popup-btns { display: flex; gap: 6px; margin-top: 8px; justify-content: flex-end; }
.popup-btn { padding: 4px 10px; border-radius: 4px; font-size: 0.78rem; cursor: pointer; border: 1px solid var(--border); background: var(--surface2); color: var(--text); }
.popup-btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Popup contrast: light on dark theme, dark on light theme */
.st-popup, .st-modal {
  background: #1a2433;
  border-color: #3a4a5a;
  color: #e0e0e0;
}
.st-popup h4, .st-modal h3 { color: #e0e0e0; }
.st-popup label { color: #90a4b0; }
.st-popup input, .st-popup select,
.st-modal .modal-row input, .st-modal .modal-row select {
  background: #0f1a28; border-color: #3a4a5a; color: #e0e0e0;
}
.popup-btn { background: #253040; color: #e0e0e0; border-color: #3a4a5a; }
.lib-params-form label { color: #90a4b0; }
.lib-params-form input { background: #0f1a28; border-color: #3a4a5a; color: #e0e0e0; }
.st-modal .modal-row label { color: #90a4b0; }

[data-theme="light"] .st-popup,
[data-theme="light"] .st-modal {
  background: #f0f4f8;
  border-color: #c0ccd8;
  color: #1a2433;
}
[data-theme="light"] .st-popup h4,
[data-theme="light"] .st-modal h3 { color: #1a2433; }
[data-theme="light"] .st-popup label { color: #546e7a; }
[data-theme="light"] .st-popup input, [data-theme="light"] .st-popup select,
[data-theme="light"] .st-modal .modal-row input, [data-theme="light"] .st-modal .modal-row select {
  background: #ffffff; border-color: #b0bec5; color: #1a2433;

}
[data-theme="light"] .popup-btn { background: #e0e8f0; color: #1a2433; border-color: #b0bec5; }
[data-theme="light"] .lib-params-form label { color: #546e7a; }
[data-theme="light"] .lib-params-form input { background: #ffffff; border-color: #b0bec5; color: #1a2433; }
[data-theme="light"] .st-modal .modal-row label { color: #546e7a; }

/* ── Settings modal ── */
.st-modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 200; display: none; align-items: center; justify-content: center; }
.st-modal-overlay.visible { display: flex; }
.st-modal { border-radius: 8px; padding: 20px; min-width: 320px; max-width: 400px; }
.st-modal h3 { margin: 0 0 14px; font-size: 1rem; }
.st-modal .modal-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; font-size: 0.82rem; }
.st-modal .modal-row label { }
.st-modal .modal-row input, .st-modal .modal-row select { width: 130px; }
.modal-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* ── Export picker ── */
.export-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.export-btn-card { padding: 10px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface2); cursor: pointer; text-align: center; font-size: 0.82rem; color: var(--text); transition: background 0.15s; }
.export-btn-card:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Info banner ── */
#st-banner { display: none; background: #f5a623; color: #000; font-size: 0.78rem; padding: 5px 12px; }
#st-banner.visible { display: flex; align-items: center; gap: 8px; }
#st-banner button { background: none; border: none; cursor: pointer; font-size: 1rem; color: #000; }
/* ── Results strip ── */
#st-results { flex-shrink: 0; border-top: 1px solid var(--border); background: var(--surface); overflow: hidden; transition: height 0.18s ease; height: 28px; }
#st-results.expanded { height: 200px; }
#st-results-header { display: flex; align-items: center; gap: 8px; padding: 5px 10px; cursor: pointer; user-select: none; font-size: 0.75rem; font-weight: 600; color: var(--text-dim); border-bottom: 1px solid var(--border); height: 28px; box-sizing: border-box; }
#st-results-header:hover { color: var(--text); }
#st-results-body { display: flex; gap: 16px; padding: 6px 10px; height: calc(100% - 28px); overflow-x: auto; overflow-y: auto; align-items: flex-start; }
.res-section { flex-shrink: 0; }
.res-section h5 { margin: 0 0 4px; font-size: 0.68rem; font-weight: 700; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }
.res-table { border-collapse: collapse; font-size: 0.72rem; white-space: nowrap; }
.res-table th { padding: 2px 8px; background: var(--surface2); color: var(--text-dim); font-weight: 600; border-bottom: 1px solid var(--border); }
.res-table td { padding: 2px 8px; color: var(--text); border-bottom: 1px solid rgba(128,128,128,0.08); }
.res-val-pos { color: #4caf50; }
.res-val-neg { color: #ff6b35; }
#st-results-empty { font-size: 0.75rem; color: var(--text-dim); padding: 8px 0; }
/* ── Library modal ── */
.lib-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.lib-card { padding: 10px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface2); cursor: pointer; text-align: center; transition: background 0.15s; }
.lib-card:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.lib-card-name { font-weight: 600; font-size: 0.82rem; margin-top: 5px; }
.lib-card-desc { font-size: 0.7rem; color: var(--text-dim); margin-top: 2px; }
.lib-card:hover .lib-card-desc { color: rgba(255,255,255,0.75); }
.lib-params-form { display: flex; flex-direction: column; gap: 8px; }
.lib-params-form label { font-size: 0.8rem; color: #546e7a; display: block; }
.lib-params-form input { display: block; width: 100%; margin-top: 3px; padding: 4px 6px; border-radius: 4px; border: 1px solid #b0bec5; background: #ffffff; color: #1a2433; font-size: 0.82rem; box-sizing: border-box; }
[data-theme="light"] .lib-params-form label { color: #90a4b0; }
[data-theme="light"] .lib-params-form input { background: #0f1a28; border-color: #3a4a5a; color: #e0e0e0; }

/* Direction buttons for force popup */
.pl-dir-row { display: flex; gap: 4px; margin-bottom: 8px; }
.pl-dir-btn {
  flex: 1; padding: 6px 0; font-size: 1.1rem;
  border-radius: 4px; border: 1px solid #b0bec5;
  background: #e0e8f0; color: #1a2433;
  cursor: pointer; font-family: inherit; transition: background 0.1s;
}
.pl-dir-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
[data-theme="light"] .pl-dir-btn { background: #253040; color: #e0e0e0; border-color: #3a4a5a; }
[data-theme="light"] .pl-dir-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Responsive: nedostupno <1000px, smanjeni dijagrami 1000–1400px ── */
.st-unavailable {
  display: none;
  flex: 1; flex-direction: column; align-items: center; justify-content: center;
  gap: 1.25rem; padding: 2.5rem 1.5rem; text-align: center; color: var(--text-dim);
}
.st-unavailable svg { opacity: 0.25; width: 72px; height: 72px; }
.st-unavailable h2 { font-size: 1.05rem; color: var(--text); margin: 0; font-weight: 600; }
.st-unavailable p  { font-size: 0.83rem; margin: 0; max-width: 340px; line-height: 1.6; }

/* ── Diagram toolbar (zoom reset + export) ── */
.diag-toolbar {
  display: flex;
  gap: 4px;
  padding: 3px 8px;
  background: var(--navy-800);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.diag-tool-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-dim);
  font-size: 0.75rem;
  padding: 2px 7px;
  cursor: pointer;
  font-family: var(--font-mono);
  transition: border-color 0.15s, color 0.15s;
}
.diag-tool-btn:hover { border-color: var(--accent); color: var(--text); }

/* ── Disabled sidebar button ── */
.sb-btn-na {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: auto;
}

@media (max-width: 999px) {
  .st-main        { display: none !important; }
  .st-unavailable { display: flex; }
  #st-badge, #st-title, #st-name-label, #st-project-name,
  #st-saves-wrap, #btn-dxf, #btn-settings, #btn-clear,
  #btn-export, #st-results { display: none !important; }
}
@media (min-width: 1000px) and (max-width: 1199px) {
  .st-main { grid-template-columns: 130px 1fr clamp(200px, 28vw, 380px); }
  .st-sidebar { width: 130px; }
}
@media (min-width: 1200px) and (max-width: 1399px) {
  .st-main { grid-template-columns: 150px 1fr clamp(300px, 34vw, 500px); }
}
