body {
    font-family: sans-serif;
    display: flex;
    flex-direction: column;
    height: 100vh;
    margin: 0;
    background-color: #f0f0f0;
    padding: 5px;
    box-sizing: border-box;
}

h1 {
    margin-bottom: 10px;
    text-align: center;
    flex-shrink: 0;
}

canvas {
    border: 1px solid #ccc;
    background-color: #fff;
    display: block;
    width: 100%;
    height: 100%;
}

canvas.invalid-geometry {
    background-color: #ffe0e0; /* Light red background for error state */
}

.main-container {
    display: flex;
    flex-direction: row;
    align-items: stretch; /* Make columns same height */
    gap: 5px;
    width: 100%;
    flex-grow: 1;
    overflow: hidden; /* Prevent container from causing scrollbars */
}

.controls {
    width: 320px;
    padding: 15px;
    border: 1px solid #ccc;
    background-color: #fafafa;
    font-size: 14px;
    flex-shrink: 0; /* Prevent controls from shrinking */
    overflow-y: auto; /* Allow this panel to scroll if content is too tall */
}

.controls h3, .measurements h3, .analysis h3 {
    margin-top: 0;
    text-align: center;
    border-bottom: 1px solid #ddd;
    padding-bottom: 10px;
    margin-bottom: 10px;
}

.controls h4, .measurements h4 {
    margin-top: 10px;
    margin-bottom: 10px;
    text-align: center;
    color: #333;
}

.control-row {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
}

.control-row label {
    width: 105px;
    font-weight: bold;
    white-space: nowrap;
}

.control-row input[type="range"] {
    flex-grow: 1;
    margin: 0 5px;
}

.control-row input[type="number"] {
    width: 55px;
    text-align: right;
}

.display-options.canvas-overlay .toggle-row {
    display: flex;
    align-items: center;
    margin-bottom: 6px;
}

.display-options.canvas-overlay .toggle-row:last-child {
    margin-bottom: 0;
}

.display-options.canvas-overlay .toggle-row label {
    font-weight: normal;
    margin-left: 6px;
    white-space: nowrap;
    font-size: 11px;
}

.display-options.canvas-overlay .toggle-row input[type="checkbox"] {
    width: 12px;
    height: 12px;
}

.control-row input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin-right: 8px;
}

.control-row label[for="constrain-xd"] {
    width: auto;
    flex-grow: 1;
}

.checkbox-container {
    width: 55px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-left: 5px;
}

.shock-state-section {
    margin-top: 15px;
}

.shock-state-section h5 {
    margin: 10px 0 5px 0;
    font-size: 13px;
    font-weight: bold;
    color: #333;
}

.shock-detail {
    margin: 4px 0;
    font-size: 12px;
    padding-left: 8px;
}

.shock-status-ok {
    color: #008000;
    font-weight: bold;
}

.shock-status-warning {
    color: #FF8C00;
    font-weight: bold;
}

.shock-status-error {
    color: #D8000C;
    font-weight: bold;
}

.canvas-container {
    position: relative;
    flex-grow: 1; /* Allow canvas to take up available space */
    display: flex;
    min-width: 0; /* Important for flex-grow in a flex container */
}

/* Tooltip System */
.tooltip {
    position: relative;
    cursor: help;
}

.tooltip::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    background-color: #2c3e50;
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: normal;
    line-height: 1.4;
    white-space: pre-line;
    max-width: 280px;
    width: max-content;
    text-align: left;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    transition-delay: 1s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.tooltip::after {
    content: "";
    position: absolute;
    bottom: 115%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: #2c3e50;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    transition-delay: 1s;
}

.tooltip:hover::before,
.tooltip:hover::after {
    opacity: 1;
    visibility: visible;
}

/* Tooltip positioning variants */
.tooltip-right::before {
    bottom: auto;
    top: 50%;
    left: 115%;
    transform: translateY(-50%);
}

.tooltip-right::after {
    bottom: auto;
    top: 50%;
    left: 109%;
    transform: translateY(-50%);
    border: 6px solid transparent;
    border-right-color: #2c3e50;
}

.tooltip-left::before {
    bottom: auto;
    top: 50%;
    right: 115%;
    left: auto;
    transform: translateY(-50%);
}

.tooltip-left::after {
    bottom: auto;
    top: 50%;
    right: 109%;
    left: auto;
    transform: translateY(-50%);
    border: 6px solid transparent;
    border-left-color: #2c3e50;
}

.tooltip-top::before {
    top: auto;
    bottom: 125%;
}

.tooltip-top::after {
    top: auto;
    bottom: 115%;
    border-top-color: #2c3e50;
    border-bottom-color: transparent;
}

#reset-view-btn {
    position: absolute;
    bottom: 10px;
    left: 10px;
    padding: 8px 12px;
    font-size: 12px;
    cursor: pointer;
    background-color: #f0f0f0;
    border: 1px solid #ccc;
    border-radius: 4px;
}

#reset-view-btn:hover {
    background-color: #e0e0e0;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex-shrink: 0; /* Prevent sidebar from shrinking */
    overflow-y: auto; /* Allow this entire sidebar to scroll */
}

.measurements, .analysis {
    width: 320px;
    padding: 15px;
    border: 1px solid #ccc;
    background-color: #fafafa;
    font-size: 14px;
}

.measurements p {
    display: flex;
    justify-content: space-between;
    margin: 8px 0;
}

.measurements span.error {
    color: #D8000C;
    font-weight: bold;
}

.error-message {
    color: #D8000C;
    font-weight: bold;
    font-size: 12px;
    text-align: center;
    margin: 10px 0;
    padding: 8px;
    background-color: rgba(216, 0, 12, 0.1);
    border-radius: 4px;
}

#run-analysis-btn {
    width: 100%;
    padding: 10px;
    margin-bottom: 15px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
}

.results-grid {
    display: grid;
    grid-template-columns: auto auto;
    gap: 8px 15px;
    align-items: center;
}

.results-grid p {
    margin: 0;
    font-weight: bold;
    text-align: right;
}

.results-grid span {
    font-weight: bold;
    color: #0056b3;
}

.table-container {
    margin-top: 15px;
    /* max-height is no longer needed as the parent .sidebar will scroll */
    border: 1px solid #ddd;
    background-color: #fff;
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.results-table th, .results-table td {
    padding: 6px 8px;
    text-align: right;
    border-bottom: 1px solid #eee;
}

.results-table th {
    background-color: #f7f7f7;
    font-weight: bold;
    position: sticky;
    top: 0;
}

.results-table tbody tr:hover {
    background-color: #f1f1f1;
}


.constraint-active {
    color: #ff6600;
    font-weight: bold;
    font-size: 11px;
}

.control-row.disabled {
    opacity: 0.5;
}

.control-row.disabled input[type="range"],
.control-row.disabled input[type="number"] {
    cursor: not-allowed;
    background-color: #f5f5f5;
}

.control-row.disabled label {
    color: #999;
}

.control-row.constraint-failed {
    border: 2px solid #D8000C;
    border-radius: 4px;
}

/* Canvas Overlay Panels */
.canvas-overlay {
    position: absolute;
    z-index: 10;
    padding: 12px;
    border: 1px solid #ccc;
    background-color: rgba(250, 250, 250, 0.95);
    backdrop-filter: blur(4px);
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    font-size: 12px;
}

/* Display Options Panel - Top Left */
.display-options.canvas-overlay {
    top: 10px;
    left: 10px;
    width: 140px;
}

#preset-display {
    top: 10px;
    right: 10px;
    font-weight: bold;
    color: #333;
}

/* Interaction Modes Panel - Right Side Vertical */
.interaction-modes.canvas-overlay {
    top: 50%;
    right: 10px;
    transform: translateY(-50%);
    width: auto;
    padding: 8px;
}

.canvas-overlay h4 {
    margin: 0 0 8px 0;
    font-size: 12px;
    font-weight: bold;
    text-align: center;
    border-bottom: 1px solid #ddd;
    padding-bottom: 6px;
    color: #333;
}


.interaction-modes .mode-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.interaction-modes .mode-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px;
    background-color: rgba(255, 255, 255, 0.9);
    border: 2px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 50px;
    height: 50px;
    font-size: 12px;
}

.mode-btn:hover {
    background-color: #f8f9fa;
    border-color: #007bff;
    transform: translateY(-1px);
}

.mode-btn.active {
    background-color: #007bff;
    border-color: #0056b3;
    color: white;
    box-shadow: 0 2px 4px rgba(0,123,255,0.3);
}

.mode-btn.active:hover {
    background-color: #0056b3;
    transform: translateY(0);
}

.interaction-modes .mode-icon {
    font-size: 20px;
}

/* Preset Controls */
.preset-controls h4 {
    margin-bottom: 10px;
    text-align: center;
}

.preset-row {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

#preset-select {
    flex-grow: 1;
    padding: 5px;
}

#load-preset-btn {
    padding: 5px 15px;
    font-weight: bold;
    cursor: pointer;
}

#export-current-btn, #import-preset-btn {
    width: 100%;
    padding: 8px;
    font-weight: bold;
    cursor: pointer;
    background-color: #e0e0e0;
}

.controls hr, .measurements hr {
    border: 0;
    border-top: 1px solid #ddd;
}

/* Arm Color Styling */
.control-group {
    padding: 5px;
    margin: 5px 0;
    border-radius: 5px;
}

.control-group .control-row {
    margin-bottom: 0; /* Remove margin from rows inside a group to prevent double spacing */
}

.control-group-blue {
    background-color: rgba(0, 0, 255, 0.1);
}

.control-group-purple {
    background-color: rgba(128, 0, 128, 0.1);
}

.control-group-orange {
    background-color: rgba(255, 165, 0, 0.1);
}

.control-group-green {
    background-color: rgba(0, 128, 0, 0.1);
}

.control-group-neutral {
    background-color: rgba(0, 0, 0, 0.03);
}

/* --- Admin Login --- */
.admin-link {
    font-size: 12px;
    font-weight: normal;
    color: #007bff;
    cursor: pointer;
    text-decoration: underline;
}

.admin-link:hover {
    color: #0056b3;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.modal-content {
    background-color: #fff;
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    width: 100%;
    max-width: 350px;
    position: relative;
}

.close-btn {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 24px;
    font-weight: bold;
    color: #aaa;
    cursor: pointer;
}

.close-btn:hover {
    color: #333;
}

.modal-content h3 {
    margin-top: 0;
    margin-bottom: 20px;
    text-align: center;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

.form-group input {
    width: 100%;
    padding: 8px;
    box-sizing: border-box;
    border: 1px solid #ccc;
    border-radius: 4px;
}

#admin-login-form button {
    width: 100%;
    padding: 10px;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 16px;
    cursor: pointer;
}

#admin-login-form button:hover {
    background-color: #0056b3;
}