﻿:root {
    --bg-primary: #1A202C;
    --bg-secondary: #2D3748;
    --bg-tertiary: rgba(26, 32, 44, 0.5);
    --text-primary: #F7FAFC;
    --text-secondary: #A0AEC0;
    --text-muted: #718096;
    --border-color: #4A5568;
    --accent: #E86A33;
    --accent-hover: #ff7b43;
    --viewer-bg: #1A202C;
    --ground-color: 0x2D3748;
    --grid-color1: 0x4A5568;
    --grid-color2: 0x2D3748;
}

html.light {
    --bg-primary: #F7FAFC;
    --bg-secondary: #EDF2F7;
    --bg-tertiary: rgba(237, 242, 247, 0.8);
    --text-primary: #1A202C;
    --text-secondary: #4A5568;
    --text-muted: #718096;
    --border-color: #CBD5E0;
    --viewer-bg: #E2E8F0;
    --ground-color: 0xCBD5E0;
    --grid-color1: 0xA0AEC0;
    --grid-color2: 0xCBD5E0;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-family: system-ui, -apple-system, sans-serif;
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
}

.input-panel {
    width: 320px;
    min-width: 320px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.input-header {
    padding: 16px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.input-header-text h1 {
    color: var(--text-primary);
    font-size: 18px;
    margin-bottom: 4px;
}

.input-header-text .subtitle {
    color: var(--text-muted);
    font-size: 11px;
}

.header-buttons {
    display: flex;
    gap: 6px;
    align-items: center;
}

.icon-btn {
    background: var(--border-color);
    color: var(--text-primary);
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

    .icon-btn:hover {
        background: var(--accent);
    }

.mobile-toggle {
    display: none;
    background: var(--border-color);
    color: var(--text-primary);
    border: none;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
}

.input-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.section {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    margin-bottom: 10px;
}

.section-header {
    padding: 10px 12px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
}

    .section-header:hover {
        background: rgba(74, 85, 104, 0.3);
    }

.section-title {
    color: var(--accent);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.section-toggle {
    color: var(--text-muted);
    font-size: 12px;
    transition: transform 0.2s;
}

.section.collapsed .section-toggle {
    transform: rotate(-90deg);
}

.section-content {
    padding: 0 12px 12px;
}

.section.collapsed .section-content {
    display: none;
}

.form-row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.form-group {
    flex: 1;
    position: relative;
}

    .form-group label {
        display: flex;
        align-items: center;
        gap: 4px;
        font-size: 10px;
        color: var(--text-secondary);
        margin-bottom: 3px;
    }

    .form-group input, .form-group select {
        width: 100%;
        background: var(--bg-primary);
        border: 1px solid var(--border-color);
        color: var(--text-primary);
        padding: 6px 8px;
        border-radius: 4px;
        font-size: 13px;
    }

        .form-group input:focus, .form-group select:focus {
            outline: none;
            border-color: var(--accent);
        }

.help-text {
    font-size: 9px;
    color: var(--text-muted);
    margin-top: 2px;
}

.tooltip-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 13px;
    height: 13px;
    background: var(--border-color);
    color: var(--text-primary);
    border-radius: 50%;
    font-size: 9px;
    font-weight: bold;
    cursor: help;
}

    .tooltip-icon:hover + .tooltip-text, .tooltip-text:hover {
        display: block;
    }

.tooltip-text {
    display: none;
    position: absolute;
    left: 0;
    top: 100%;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    padding: 8px 10px;
    border-radius: 4px;
    font-size: 10px;
    color: var(--text-secondary);
    z-index: 100;
    width: 220px;
    line-height: 1.4;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.analyze-btn {
    width: 100%;
    background: var(--accent);
    color: white;
    padding: 12px;
    font-size: 14px;
    font-weight: 600;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    margin-top: 8px;
}

    .analyze-btn:hover:not(:disabled) {
        background: var(--accent-hover);
    }

    .analyze-btn:disabled {
        background: var(--border-color);
        cursor: not-allowed;
    }

.viewer-panel {
    flex: 1;
    position: relative;
    background: var(--viewer-bg);
}

#viewer-container {
    width: 100%;
    height: 100%;
    touch-action: none;
}

.viewer-placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--border-color);
}

    .viewer-placeholder svg {
        width: 80px;
        height: 80px;
        margin-bottom: 16px;
        opacity: 0.5;
    }

.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(26, 32, 44, 0.9);
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    z-index: 100;
}

html.light .loading-overlay {
    background: rgba(247, 250, 252, 0.9);
}

.loading-overlay.active {
    display: flex;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--bg-secondary);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 12px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.results-panel, .view-controls, .legend-panel {
    position: absolute;
    background: rgba(45, 55, 72, 0.95);
    padding: 12px;
    border-radius: 8px;
    display: none;
    z-index: 50;
}

html.light .results-panel, html.light .view-controls, html.light .legend-panel {
    background: rgba(237, 242, 247, 0.95);
}

.results-panel.active, .view-controls.active, .legend-panel.active {
    display: block;
}

.results-panel {
    top: 12px;
    right: 12px;
    min-width: 180px;
}

.view-controls {
    top: 12px;
    left: 12px;
    min-width: 160px;
}

.legend-panel {
    bottom: 12px;
    left: 12px;
}

.results-panel h3, .control-label, .legend-title {
    font-size: 10px;
    font-weight: 600;
    color: #E86A33;
    margin-bottom: 8px;
    text-transform: uppercase;
}

.result-row {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    padding: 2px 0;
    border-bottom: 1px solid rgba(74, 85, 104, 0.5);
}

    .result-row:last-child {
        border-bottom: none;
    }

.result-label {
    color: #A0AEC0;
}

.result-value {
    color: #F7FAFC;
    font-weight: 500;
}

/* Utilization color classes */
.util-ok { color: #22c55e; }
.util-warning { color: #eab308; }
.util-high { color: #f97316; }
.util-over { color: #ef4444; }

/* Design check rows */
.design-checks-section {
    border-bottom: 1px solid #4A5568;
    margin-bottom: 4px;
    padding-bottom: 4px;
}

.design-check-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
}

.util-bar-container {
    flex: 1;
    height: 4px;
    background: #2D3748;
    border-radius: 2px;
    margin-left: 8px;
    min-width: 40px;
    max-width: 80px;
}

.util-bar {
    height: 100%;
    border-radius: 2px;
    transition: width 0.3s, background-color 0.3s;
}

/* Bolt results table */
.bolt-results-section h4 {
    font-size: 11px;
    color: #A0AEC0;
    margin: 6px 0 4px;
}

.bolt-results-table {
    width: 100%;
    font-size: 10px;
    border-collapse: collapse;
}

.bolt-results-table th {
    color: #A0AEC0;
    font-weight: 500;
    text-align: left;
    padding: 2px 4px;
    border-bottom: 1px solid #4A5568;
}

.bolt-results-table td {
    padding: 2px 4px;
    color: #E2E8F0;
}

/* Stiffener controls */
.stiffener-controls.hidden {
    display: none;
}

.view-controls select {
    width: 100%;
    background: #2D3748;
    color: #F7FAFC;
    border: 1px solid #4A5568;
    padding: 5px 8px;
    border-radius: 4px;
    font-size: 11px;
    margin-bottom: 8px;
}

.slider-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
}

    .slider-row input[type="range"] {
        flex: 1;
        -webkit-appearance: none;
        background: #2D3748;
        height: 4px;
        border-radius: 2px;
    }

        .slider-row input[type="range"]::-webkit-slider-thumb {
            -webkit-appearance: none;
            width: 12px;
            height: 12px;
            background: #E86A33;
            border-radius: 50%;
            cursor: pointer;
        }

.slider-value {
    font-size: 10px;
    color: #F7FAFC;
    min-width: 30px;
    text-align: right;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 10px;
    color: #E2E8F0;
    margin-bottom: 3px;
    cursor: pointer;
}

    .checkbox-row input {
        accent-color: #E86A33;
    }

#legend-gradient {
    height: 10px;
    border-radius: 2px;
    margin-bottom: 4px;
}

.legend-labels {
    display: flex;
    justify-content: space-between;
    font-size: 9px;
    color: #A0AEC0;
}

.log-toggle, .mobile-overlay-toggle {
    position: absolute;
    background: #4A5568;
    color: #F7FAFC;
    padding: 6px 10px;
    border: none;
    border-radius: 4px;
    font-size: 10px;
    cursor: pointer;
    display: none;
    z-index: 50;
}

.log-toggle {
    bottom: 12px;
    right: 12px;
}

    .log-toggle.active {
        display: block;
    }

.mobile-overlay-toggle {
    bottom: 12px;
    left: 12px;
}

    .mobile-overlay-toggle.active {
        display: none;
    }

.log-modal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #1A202C;
    border: 1px solid #4A5568;
    border-radius: 8px;
    width: 80%;
    max-width: 700px;
    max-height: 80%;
    display: none;
    flex-direction: column;
    z-index: 200;
}

    .log-modal.active {
        display: flex;
    }

.log-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
}

    .log-header h3 {
        color: var(--accent);
        font-size: 13px;
    }

    .log-header button {
        background: var(--border-color);
        color: var(--text-primary);
        border: none;
        padding: 5px 10px;
        border-radius: 4px;
        font-size: 11px;
        cursor: pointer;
        margin-left: 6px;
    }

.log-content {
    flex: 1;
    overflow: auto;
    padding: 14px;
}

    .log-content pre {
        font-family: Consolas, monospace;
        font-size: 10px;
        color: var(--text-secondary);
        white-space: pre-wrap;
    }

.error-toast {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #C53030;
    color: white;
    padding: 10px 16px;
    border-radius: 6px;
    font-size: 12px;
    display: none;
    z-index: 300;
}

    .error-toast.active {
        display: block;
    }

.pdf-btn {
    width: 100%;
    background: var(--border-color);
    color: var(--text-primary);
    padding: 10px;
    font-size: 12px;
    font-weight: 500;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    margin-top: 6px;
}

    .pdf-btn:hover:not(:disabled) {
        background: #5A6578;
    }

    .pdf-btn:disabled {
        opacity: 0.5;
        cursor: not-allowed;
    }

.bottom-links {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-top: 12px;
}

    .bottom-links a {
        font-size: 9px;
        color: var(--text-muted);
        cursor: pointer;
        text-decoration: underline;
    }

        .bottom-links a:hover {
            color: var(--text-secondary);
        }

.info-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 400;
}

    .info-modal.active {
        display: flex;
    }

.info-content {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    max-width: 750px;
    max-height: 85vh;
    margin: 20px;
    display: flex;
    flex-direction: column;
}

.info-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

    .info-header h3 {
        color: var(--accent);
        font-size: 14px;
    }

    .info-header button {
        background: var(--border-color);
        color: var(--text-primary);
        border: none;
        padding: 5px 10px;
        border-radius: 4px;
        font-size: 11px;
        cursor: pointer;
    }

.info-body {
    padding: 16px;
    overflow-y: auto;
    font-size: 11px;
    line-height: 1.6;
    color: var(--text-secondary);
}

    .info-body h4 {
        color: var(--text-primary);
        margin: 16px 0 8px;
        font-size: 13px;
        border-bottom: 1px solid var(--border-color);
        padding-bottom: 4px;
    }

    .info-body h5 {
        color: var(--accent);
        margin: 12px 0 6px;
        font-size: 11px;
    }

    .info-body p {
        margin-bottom: 10px;
    }

    .info-body ul {
        margin: 8px 0 12px 20px;
    }

    .info-body li {
        margin-bottom: 4px;
    }

    .info-body code {
        background: var(--bg-secondary);
        padding: 1px 4px;
        border-radius: 3px;
        font-family: Consolas, monospace;
        font-size: 10px;
    }

    .info-body .formula {
        background: var(--bg-secondary);
        padding: 8px 12px;
        border-radius: 4px;
        margin: 8px 0;
        font-family: Consolas, monospace;
        font-size: 10px;
    }

    .info-body .note {
        background: rgba(232, 106, 51, 0.1);
        border-left: 3px solid var(--accent);
        padding: 8px 12px;
        margin: 10px 0;
        font-size: 10px;
    }

    .info-body .warning {
        background: rgba(197, 48, 48, 0.1);
        border-left: 3px solid #C53030;
        padding: 8px 12px;
        margin: 10px 0;
        font-size: 10px;
    }

.bolt-table-container {
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

.bolt-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
}

    .bolt-table thead {
        position: sticky;
        top: 0;
        z-index: 1;
    }

    .bolt-table th {
        background: var(--bg-primary);
        color: var(--text-secondary);
        padding: 4px 6px;
        text-align: left;
        font-size: 9px;
        font-weight: 600;
        text-transform: uppercase;
        border-bottom: 1px solid var(--border-color);
    }

    .bolt-table td {
        padding: 3px 4px;
        border-bottom: 1px solid var(--border-color);
    }

    .bolt-table input {
        width: 70px;
        background: var(--bg-primary);
        border: 1px solid var(--border-color);
        color: var(--text-primary);
        padding: 3px 5px;
        border-radius: 3px;
        font-size: 11px;
    }

        .bolt-table input:focus {
            outline: none;
            border-color: var(--accent);
        }

    .bolt-table .remove-btn {
        background: #C53030;
        color: white;
        border: none;
        width: 20px;
        height: 20px;
        border-radius: 3px;
        cursor: pointer;
        font-size: 12px;
        line-height: 1;
        display: flex;
        align-items: center;
        justify-content: center;
    }

        .bolt-table .remove-btn:hover {
            background: #E53E3E;
        }

.add-bolt-btn {
    width: 100%;
    background: #2F855A;
    color: white;
    padding: 6px;
    font-size: 11px;
    font-weight: 500;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    margin-bottom: 8px;
}

    .add-bolt-btn:hover {
        background: #38A169;
    }

#patternOffsetControls.hidden {
    display: none;
}

@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
        height: 100vh;
        height: 100dvh;
    }

    .input-panel {
        width: 100%;
        min-width: 100%;
        height: auto;
        max-height: 50vh;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        flex-shrink: 0;
    }

        .input-panel.collapsed {
            max-height: 56px;
            min-height: 56px;
        }

            .input-panel.collapsed .input-scroll {
                display: none;
            }

    .mobile-toggle {
        display: block;
    }

    .viewer-panel {
        flex: 1 1 auto;
        min-height: 0;
        height: auto;
    }

    #viewer-container {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }

    .form-row {
        flex-direction: column;
        gap: 6px;
    }

    .view-controls, .results-panel {
        display: none !important;
    }

        .view-controls.mobile-visible, .results-panel.mobile-visible {
            display: block !important;
        }

    .mobile-overlay-toggle.active {
        display: block;
    }

    .legend-panel {
        max-width: 160px;
    }

        .legend-panel .legend-title {
            font-size: 9px;
        }

    .legend-labels {
        font-size: 8px;
    }
}

/* =================== */
/* SWEEP TABLE          */
/* =================== */
.sweep-results-container { margin-top: 8px; }
.sweep-table { width: 100%; border-collapse: collapse; font-size: 11px; table-layout: fixed; }
.sweep-table th, .sweep-table td { padding: 3px 4px; border: 1px solid var(--border-color); text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sweep-table th { background: var(--bg-secondary); color: var(--text-secondary); font-weight: 600; font-size: 10px; }
.sweep-table td { color: var(--text-primary); font-variant-numeric: tabular-nums; }
.sweep-ok { background: rgba(34, 197, 94, 0.15); color: #22c55e; }
.sweep-warn { background: rgba(234, 179, 8, 0.15); color: #eab308; }
.sweep-high { background: rgba(249, 115, 22, 0.15); color: #f97316; }
.sweep-over { background: rgba(239, 68, 68, 0.2); color: #ef4444; font-weight: 600; }
.sweep-timing { font-size: 10px; color: var(--text-muted); margin-top: 4px; text-align: right; }

/* =================== */
/* WATERMARK OVERLAY    */
/* =================== */
.watermark-overlay {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%) rotate(-30deg);
    font-size: 3rem;
    font-weight: bold;
    color: rgba(255, 255, 255, 0.08);
    pointer-events: none;
    white-space: nowrap;
    z-index: 5;
    user-select: none;
    letter-spacing: 0.3em;
}
