/* ==========================================================================
   SurfaceScope -- Stylesheet
   ========================================================================== */

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-panel: #0f3460;
    --accent: #e94560;
    --accent-hover: #ff6b81;
    --text-primary: #eee;
    --text-secondary: #aab;
    --border: #2a2a4a;
    --input-bg: #1a1a3e;
    --success: #4ecdc4;
    --warning: #f39c12;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Header */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--bg-secondary);
    border-bottom: 2px solid var(--accent);
}

header h1 {
    font-size: 1.3rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.version {
    font-size: 0.8rem;
    color: var(--text-secondary);
    background: var(--bg-panel);
    padding: 2px 10px;
    border-radius: 10px;
}

/* Main layout -- 3-panel */
main {
    display: grid;
    grid-template-columns: 400px 1fr 320px;
    gap: 8px;
    padding: 8px;
    height: calc(100vh - 56px);
    min-height: 600px;
}

/* Panels */
.panel {
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 12px;
    overflow-y: auto;
    border: 1px solid var(--border);
}

.panel h2 {
    font-size: 1rem;
    margin-bottom: 10px;
    color: var(--accent);
    border-bottom: 1px solid var(--border);
    padding-bottom: 6px;
}

/* Left panel -- 2D images */
.image-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.image-box {
    text-align: center;
}

.image-box h3 {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.image-box canvas {
    border: 1px solid var(--border);
    border-radius: 4px;
    max-width: 100%;
    cursor: crosshair;
    background: #111;
}

.profile-section {
    margin-top: 10px;
}

.profile-section h3 {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.hint {
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-style: italic;
    margin-bottom: 4px;
}

#canvas-profile {
    width: 100%;
    height: 150px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: #111;
}

/* Center panel -- 3D */
#panel-center {
    display: flex;
    flex-direction: column;
}

#three-container {
    flex: 1;
    min-height: 400px;
    border: 1px solid var(--border);
    border-radius: 4px;
    overflow: hidden;
    background: #0a0a1a;
}

.render-info {
    display: flex;
    gap: 20px;
    padding: 4px 0;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Right panel -- controls */
#panel-right {
    font-size: 0.85rem;
}

fieldset {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 10px;
}

legend {
    font-size: 0.8rem;
    color: var(--accent);
    padding: 0 6px;
    font-weight: 600;
}

label {
    display: block;
    margin: 6px 0 2px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

select, input[type="number"], input[type="file"] {
    width: 100%;
    padding: 5px 8px;
    background: var(--input-bg);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.8rem;
    margin-bottom: 4px;
}

input[type="range"] {
    width: 100%;
    margin: 4px 0;
    accent-color: var(--accent);
}

input[type="checkbox"] {
    accent-color: var(--accent);
    margin-right: 4px;
}

/* Buttons */
.btn-primary, .btn-secondary {
    display: block;
    width: 100%;
    padding: 8px;
    margin-top: 8px;
    border: none;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--bg-panel);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: #1a4a7a;
}

.btn-primary:disabled, .btn-secondary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Metrics box */
.metrics-box {
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 8px;
    margin-top: 6px;
    font-size: 0.75rem;
    font-family: 'Consolas', 'Courier New', monospace;
    color: var(--success);
    min-height: 30px;
    white-space: pre-wrap;
}

/* Status bar */
.status-bar {
    margin-top: 10px;
    padding: 6px 10px;
    background: var(--bg-panel);
    border-radius: 4px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-align: center;
}

.status-bar.error {
    color: var(--accent);
    border: 1px solid var(--accent);
}

.status-bar.success {
    color: var(--success);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

/* Header right group */
.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Help button */
.btn-help {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid var(--accent);
    background: transparent;
    color: var(--accent);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
}

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

/* Help Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--accent);
    border-radius: 10px;
    width: 640px;
    max-width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 1.1rem;
    color: var(--accent);
    margin: 0;
    border: none;
    padding: 0;
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.btn-close:hover {
    color: var(--accent);
}

.modal-body {
    padding: 16px 20px;
    font-size: 0.85rem;
    line-height: 1.6;
    color: var(--text-primary);
}

.modal-body h3 {
    color: var(--accent);
    font-size: 0.95rem;
    margin: 16px 0 8px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 4px;
}

.modal-body h3:first-child {
    margin-top: 0;
}

.modal-body ol, .modal-body ul {
    padding-left: 20px;
    margin: 6px 0;
}

.modal-body li {
    margin-bottom: 4px;
}

.modal-body p {
    margin: 6px 0;
}

.help-table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0;
}

.help-table td {
    padding: 4px 8px;
    border-bottom: 1px solid var(--border);
    font-size: 0.8rem;
}

.help-table td:first-child {
    white-space: nowrap;
    color: var(--success);
    font-family: 'Consolas', 'Courier New', monospace;
    width: 200px;
}

/* Viewport hints overlay */
.viewport-hints {
    position: fixed;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 16px;
    background: rgba(15, 52, 96, 0.8);
    padding: 4px 14px;
    border-radius: 12px;
    font-size: 0.7rem;
    color: var(--text-secondary);
    pointer-events: none;
    z-index: 100;
}

.viewport-hints span {
    white-space: nowrap;
}

/* Responsive fallback */
@media (max-width: 1100px) {
    main {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
        height: auto;
    }
}
