* { box-sizing: border-box; }

html, body { height: 100%; overflow: hidden; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    margin: 0;
    padding: 0;
    background: #eef1f5;
    color: #222;
    display: flex;
    flex-direction: column;
}

header {
    padding: 10px 20px;
    background: #1f2933;
    color: #fff;
    display: flex;
    align-items: baseline;
    gap: 16px;
    flex-shrink: 0;
}

header h1 { margin: 0; font-size: 16px; font-weight: 600; }
header .subtitle { font-size: 12px; opacity: 0.65; }
header .status { margin-left: auto; font-size: 12px; }
header .status.pending { color: #f6ad55; }
header .status.done { color: #68d391; }
header .status.waiting { color: #a0aec0; }
header .status.error { color: #fc8181; }

main {
    display: grid;
    grid-template-columns: 380px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    gap: 12px;
    padding: 12px;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.panel {
    background: #fff;
    padding: 16px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    min-width: 0;
    overflow-y: auto;
    overflow-x: hidden;
}

/* View panel needs flex for the tab bar (fixed) + tab body (flex:1) layout. */
.view-panel {
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ---------- Collapsible sections in the form panel ---------- */

.section {
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    margin-bottom: 8px;
    background: #ffffff;
    overflow: hidden;
}

.section > summary {
    cursor: pointer;
    list-style: none;
    padding: 10px 12px;
    font-size: 13px;
    font-weight: 600;
    color: #2d3748;
    background: #f7fafc;
    border-bottom: 1px solid transparent;
    display: flex;
    align-items: center;
    gap: 6px;
    user-select: none;
}
.section > summary::-webkit-details-marker { display: none; }
.section > summary::before {
    content: "▸";
    font-size: 10px;
    color: #718096;
    transition: transform 0.15s ease;
    display: inline-block;
    width: 12px;
}
.section[open] > summary::before { transform: rotate(90deg); }
.section[open] > summary { border-bottom-color: #e2e8f0; }
.section > summary:hover { background: #edf2f7; }
.section.advanced > summary { background: #fefcbf22; }

.section > .grid-form,
.section > p,
.section > .subsection-title,
.section > .row,
.section > button,
.section > div,
.section > label {
    margin-left: 12px;
    margin-right: 12px;
}
.section > .grid-form:first-of-type { margin-top: 10px; }
.section > .grid-form:last-of-type,
.section > button:last-of-type,
.section > div:last-of-type { margin-bottom: 12px; }
.section > .grid-form + .grid-form { margin-top: 8px; }

.section-block {
    padding: 10px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    margin-bottom: 8px;
    background: #fff;
}
.section-title {
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #718096;
    margin-bottom: 6px;
}

.section-desc {
    font-size: 11px;
    color: #718096;
    font-style: italic;
    margin: 8px 12px 8px 12px;
    line-height: 1.4;
}

.subsection-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #a0aec0;
    font-weight: 600;
    margin: 10px 12px 4px 12px;
}

.badge {
    font-size: 10px;
    padding: 1px 6px;
    background: #ecc94b;
    color: #744210;
    border-radius: 8px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    font-weight: 700;
    margin-left: 4px;
}

/* Only right-panel h2 (used in charts, results, etc.) */
.view-panel h2 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: #718096;
    margin: 14px 0 6px;
    font-weight: 600;
}
.view-panel h2:first-child { margin-top: 0; }

/* ---------- Form controls ---------- */

.grid-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 10px;
}

label {
    display: flex;
    flex-direction: column;
    font-size: 11px;
    color: #4a5568;
}

input[type="number"], select, input[type="text"] {
    padding: 5px 7px;
    font-size: 13px;
    border: 1px solid #cbd5e0;
    border-radius: 4px;
    background: #fff;
    margin-top: 2px;
    color: #2d3748;
}
input[type="number"]:focus, select:focus, input[type="text"]:focus {
    outline: none;
    border-color: #2b6cb0;
    box-shadow: 0 0 0 2px rgba(43, 108, 176, 0.15);
}

button {
    padding: 5px 10px;
    font-size: 12px;
    background: #edf2f7;
    color: #2d3748;
    border: 1px solid #cbd5e0;
    border-radius: 4px;
    cursor: pointer;
}
button:hover { background: #e2e8f0; }

button.primary {
    background: #2b6cb0;
    color: #fff;
    border-color: #2b6cb0;
    padding: 8px 12px;
    margin-top: 8px;
    width: 100%;
    font-weight: 500;
}
button.primary:hover { background: #2c5282; }

/* Toggle buttons — both states are neutral & informational.
   Active (data-value=true) uses a subtle blue accent.
   Inactive (data-value=false) uses a subtle gray — NOT red — because
   "false" is a valid state, not an error. */
button.toggle {
    padding: 5px 8px;
    margin-top: 2px;
    background: #ebf4ff;
    color: #2b6cb0;
    border: 1px solid #90cdf4;
    text-align: center;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}
button.toggle:hover { background: #bee3f8; }
button.toggle[data-value="false"] {
    background: #edf2f7;
    color: #4a5568;
    border-color: #cbd5e0;
}
button.toggle[data-value="false"]:hover { background: #e2e8f0; }

/* ---------- Preset rows ---------- */

#presets-list { display: flex; flex-direction: column; gap: 5px; margin: 8px 0 6px 0; }
.preset-row {
    display: grid;
    grid-template-columns: 1fr 80px 48px 22px;
    gap: 4px;
    align-items: center;
}
.preset-row input, .preset-row select {
    font-size: 12px;
    padding: 3px 5px;
}
.preset-row .remove {
    background: transparent;
    border: none;
    color: #c53030;
    cursor: pointer;
    font-size: 14px;
    padding: 0;
}
#add-preset { font-size: 12px; padding: 4px 10px; }

/* ---------- Global warnings banner ---------- */

.warnings {
    margin: 0 12px 8px 12px;
    padding: 8px 12px;
    background: #fefcbf;
    border: 1px solid #ecc94b;
    border-radius: 4px;
    font-size: 12px;
    color: #744210;
    display: none;
}
.warnings.show { display: block; }
.warnings strong { display: block; margin-bottom: 4px; }
.warnings ul { margin: 4px 0 0 20px; padding: 0; }

/* ---------- Tabs (right panel) ---------- */

.tabs {
    display: flex;
    background: #f7fafc;
    border-bottom: 1px solid #e2e8f0;
    padding: 0 8px;
    flex-shrink: 0;
}
.tab {
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: #4a5568;
    font-size: 13px;
    padding: 12px 16px;
    cursor: pointer;
    margin-bottom: -1px;
    border-radius: 0;
}
.tab:hover { background: #edf2f7; color: #2d3748; }
.tab.active {
    color: #2b6cb0;
    border-bottom-color: #2b6cb0;
    font-weight: 500;
    background: #fff;
}

.tab-body {
    padding: 16px;
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.tab-body.hidden { display: none; }

/* ---------- SVG diagram ---------- */

#mech-svg {
    width: 100%;
    flex: 1;
    min-height: 320px;
    background: #fafbfc;
    border-radius: 6px;
    border: 1px solid #edf2f7;
}

.anim-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 10px;
    flex-wrap: wrap;
}
#preset-buttons { display: flex; flex-wrap: wrap; gap: 4px; }
#preset-buttons button { font-size: 12px; padding: 5px 10px; }
#preset-buttons button.active {
    background: #2b6cb0;
    color: #fff;
    border-color: #2b6cb0;
}
#preset-buttons button.endpoint-btn {
    background: #fefcbf;
    border-color: #ecc94b;
    color: #744210;
    font-weight: 500;
}
#preset-buttons button.endpoint-btn:hover { background: #faf089; }
#preset-buttons button.endpoint-btn.active {
    background: #d69e2e;
    color: #fff;
    border-color: #b7791f;
}

.scrub {
    display: flex;
    flex-direction: column;
    font-size: 11px;
    color: #4a5568;
    flex: 1;
    min-width: 200px;
}
.scrub input[type="range"] { width: 100%; margin-top: 2px; }
.scrub b { font-family: "SF Mono", Menlo, monospace; color: #2d3748; }

/* ---------- Charts ---------- */

.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 12px;
    flex: 1;
    min-height: 0;
}
.chart-cell {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
}
.chart-cell h2 { margin: 0 0 4px; }
.chart {
    width: 100%;
    flex: 1;
    min-height: 0;
}

/* ---------- Info panels ---------- */

.info {
    font-size: 12px;
    color: #4a5568;
    margin-top: 8px;
    line-height: 1.6;
}
.info .hint {
    color: #a0aec0;
    font-size: 10px;
    font-style: italic;
}
.info b { color: #2d3748; }

textarea {
    width: 100%;
    font-family: "SF Mono", Menlo, Consolas, monospace;
    font-size: 11px;
    padding: 8px;
    border: 1px solid #cbd5e0;
    border-radius: 4px;
    resize: vertical;
    background: #fafbfc;
    min-height: 120px;
}
.row { display: flex; align-items: center; gap: 8px; margin: 6px 0; flex-wrap: wrap; }

#recompute-status.pending { color: #dd6b20; font-weight: 500; }
#recompute-status.done { color: #2f855a; }

/* ---------- Preset results table ---------- */

#preset-results {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin-top: 4px;
}
#preset-results th, #preset-results td {
    padding: 6px 8px;
    border-bottom: 1px solid #e2e8f0;
    text-align: left;
}
#preset-results th { background: #f7fafc; font-weight: 600; font-size: 11px; color: #4a5568; }
#preset-results td.num { font-family: "SF Mono", Menlo, monospace; text-align: right; }
#preset-results td.ok { color: #2f855a; }
#preset-results td.notok { color: #c53030; }
#preset-results td.warn { color: #b7791f; font-style: italic; font-size: 10px; }

/* ---------- Scrollbars ---------- */

.panel::-webkit-scrollbar, .tab-body::-webkit-scrollbar { width: 8px; }
.panel::-webkit-scrollbar-thumb, .tab-body::-webkit-scrollbar-thumb {
    background: #cbd5e0; border-radius: 4px;
}
.panel::-webkit-scrollbar-thumb:hover, .tab-body::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}
