/* Main CSS */
:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-main: #f8fafc;
    --bg-surface: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --bg-glass: rgba(255, 255, 255, 0.7);
    --bg-glass-strong: rgba(255, 255, 255, 0.9);
    --glass-border: 1px solid rgba(255, 255, 255, 0.2);
    --glass-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --radius-md: 8px;
    --radius-lg: 12px;
}

[data-theme="dark"] {
    --primary: #3b82f6;
    --bg-main: #0f172a;
    --bg-surface: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --bg-glass: rgba(15, 23, 42, 0.7);
    --bg-glass-strong: rgba(30, 41, 59, 0.9);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
}

body {
    background: var(--bg-main);
    color: var(--text-primary);
    transition: background 0.3s;
}

.app-container {
    max-width: 1920px;
    margin: 0 auto;
    padding: 20px;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 0 20px 0;
}

.logo-container .logo-text {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -1px;
    color: var(--primary);
}

.header-actions {
    display: flex;
    gap: 10px;
}

.btn-icon {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
}

/* Dashboard Grid */
.dashboard-container {
    display: grid;
    /* Grid Template: Left (320px) - Resizer (6px) - Center (1fr) - Resizer (6px) - Right (300px) */
    grid-template-columns: 320px 6px 1fr 6px 300px;
    gap: 0;
    margin-bottom: 30px;
    align-items: stretch;
    min-height: calc(100vh - 120px);
}

/* Panels */
.dashboard-left,
.dashboard-right {
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    padding: 24px;
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
}

.dashboard-center {
    background: var(--bg-main);
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding: 20px;
    border-radius: var(--radius-lg);
}

/* Resizer */
.resizer {
    width: 6px;
    cursor: col-resize;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
}

.resizer:hover,
.resizer.resizing {
    background: rgba(59, 130, 246, 0.1);
}

.resizer::after {
    content: "";
    width: 2px;
    height: 30px;
    background: var(--border-color);
    border-radius: 2px;
}

.resizer:hover::after,
.resizer.resizing::after {
    background: var(--primary);
}

/* Inputs */
.panel-section h3 {
    font-size: 0.9rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 5px;
}

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

.glass-input,
.glass-select {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.5);
}

.compact-input-row {
    display: flex;
    gap: 10px;
}

.compact-input-row>div {
    flex: 1;
}

.compact-input-row label {
    display: block;
    font-size: 0.8rem;
    margin-bottom: 4px;
}

.compact-input-row input {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

/* Buttons */
.presets-container {
    margin-bottom: 10px;
}

.preset-buttons {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}

.btn-preset {
    flex: 1;
    padding: 6px;
    font-size: 0.8rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
}

.btn-preset.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Preview */
.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.preview-title {
    font-weight: 600;
}

.live-indicator {
    font-size: 0.7rem;
    color: #10b981;
}

.preview-large {
    flex: 1;
    min-height: 260px;
    /* Reduced to match smaller frame */
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    position: relative;
}

.preview-frame {
    border: 2px solid #334155;
    position: relative;
    height: 240px;
    /* Reduced height */
    zoom: 0.8;
    /* Scale down for better fit */
    display: flex;
    justify-content: center;
    background: #fff;
    width: 100%;
}



.preview-glass-panels {
    display: flex;
    height: 100%;
}

.preview-panel {
    flex: 1;
    border-right: 1px solid rgba(0, 0, 0, 0.2);
    background: rgba(200, 230, 255, 0.3);
}

/* Price Card */
.price-card {
    background: var(--bg-surface);
    padding: 20px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.card-header h3 {
    font-size: 1rem;
    margin-bottom: 15px;
}

.price-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.price-row.total-row {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--primary);
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed var(--border-color);
}

.btn-action {
    width: 100%;
    padding: 12px;
    margin-top: 10px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-action.primary {
    background: var(--primary);
    color: white;
}

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

.btn-action.ghost {
    background: transparent;
    color: #ef4444;
    font-size: 0.9rem;
}

.glass-options-vertical label {
    display: flex;
    justify-content: space-between;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    margin-bottom: 5px;
    cursor: pointer;
    transition: 0.2s;
}

.glass-options-vertical label:hover {
    background: var(--bg-surface);
}

.glass-options-vertical input:checked+span {
    font-weight: bold;
    color: var(--primary);
}

/* Dropdown Trigger Style */
.glass-select-trigger {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 10px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    font-weight: 500;
}

.glass-select-trigger:hover {
    border-color: var(--primary);
    background: #f1f5f9;
}

.glass-select-trigger .arrow {
    font-size: 0.8rem;
    color: var(--text-secondary);
    transition: transform 0.3s;
}

.glass-select-trigger.active .arrow {
    transform: rotate(180deg);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
}

.modal-content {
    background-color: var(--bg-surface);
    margin: 10% auto;
    padding: 0;
    border: 1px solid var(--border-color);
    width: 90%;
    max-width: 500px;
    border-radius: 12px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

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

.close {
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.tab-btn {
    background: none;
    border: none;
    padding: 10px;
    cursor: pointer;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Visualization Styles */
.preview-container-inner {
    position: relative;
    display: flex;
    align-items: flex-end;
    /* Align bottom */
    height: 100%;
    padding: 30px 0;
    /* Space for dimension lines */
    width: 100%;
}

.preview-panel {
    position: relative;
    border-right: 1px solid rgba(0, 0, 0, 0.2);
    box-shadow: 2px 0 5px rgba(0, 0, 0, 0.05);
    /* Depth */
    margin-right: 1px;
    /* Realistic gap */
}

/* Realistic Glass Profiles */
.profile-top {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 8px;
    background: linear-gradient(to bottom, #dbe4eb, #99aab5);
    border-bottom: 1px solid #777;
}

.profile-bottom {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 12px;
    background: linear-gradient(to top, #dbe4eb, #99aab5);
    border-top: 1px solid #777;
    z-index: 2;
}

/* Dimension Lines */
.measure-line-top {
    position: absolute;
    top: -30px;
    left: 0;
    width: 100%;
    height: 10px;
    border-bottom: 2px solid #333;
    /* Main line */
    display: flex;
    justify-content: center;
    align-items: flex-end;
}

.measure-line-top::after,
.measure-line-top::before {
    content: '';
    position: absolute;
    bottom: -5px;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid #333;
    /* Arrow */
}

.measure-line-top::before {
    left: 0;
}

.measure-line-top::after {
    right: 0;
}

.measure-text {
    background: white;
    padding: 0 5px;
    font-weight: bold;
    font-size: 14px;
    color: #333;
    margin-bottom: 5px;
    /* Above line */
    font-family: 'Segoe UI', sans-serif;
    position: absolute;
    top: -20px;
}

.panel-number {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 12px;
    color: #555;
    background: rgba(255, 255, 255, 0.7);
    padding: 2px 4px;
    border-radius: 4px;
    font-weight: 500;
}

/* Responsive Media Query (Mobile & Tablet) */
@media (max-width: 900px) {

    /* Stack Layout */
    .dashboard-container {
        display: flex;
        flex-direction: column;
        gap: 20px;
        min-height: auto;
    }

    /* Hide Resizers */
    .resizer {
        display: none;
    }

    /* Panels full width */
    .dashboard-left,
    .dashboard-center,
    .dashboard-right {
        width: 100%;
        max-height: none;
        /* Scroll within page, not panel */
        overflow-y: visible;
        position: static;
        /* Remove sticky */
        padding: 16px;
    }

    /* Touch Friendly Inputs */
    .glass-input,
    .glass-select,
    .btn-action,
    .btn-preset {
        min-height: 48px;
        /* Fat finger Rule */
        font-size: 16px;
        /* Prevent zoom on iOS */
    }

    /* Compact row stacks on very small screens */
    .compact-input-row {
        flex-direction: column;
        gap: 15px;
    }

    /* Adjust Preview Height */
    /* Adjust Preview Height */
    .preview-large {
        min-height: 200px;
        /* Reduced further */
        /* Adjusted to fit zoomed image tightly */
        overflow-x: auto;
        display: block;
        white-space: nowrap;
        padding-top: 10px;
    }

    .preview-frame {
        height: 250px;
        /* Reduced height */
        /* Increased height */
        width: auto !important;
        min-width: 650px;
        /* Slightly wider to be safe */
        zoom: 0.65;
        /* More shrink on mobile to fit screen */
        margin: 0 auto;
    }

    /* Sticky Bottom Action Bar for Mobile (Optional but good for UX) */
    .dashboard-right {
        order: 3;
        /* Ensure it's at the bottom */
    }

    /* Reorder for Mobile: Input -> Preview -> Result */
    .dashboard-left {
        order: 1;
    }

    .dashboard-center {
        order: 2;
    }
}

/* Print Styles */
@media print {
    body {
        background: white;
        color: black;
        font-size: 12pt;
    }

    .app-container {
        height: auto;
        padding: 0;
        display: block;
    }

    /* Hide UI Elements */
    .header-actions,
    .resizer,
    .presets-container,
    .btn-action,
    .btn-details-toggle,
    #themeToggle,
    #settingsBtn,
    #newBtn,
    #saveBtn,
    .kdv-toggle,
    .preview-controls,
    .preview-title,
    .live-indicator,
    .modal,
    #detailsPanel {
        display: none !important;
    }

    /* Hide inputs that shouldn't be seen or style them as text */
    input,
    select {
        border: none !important;
        background: transparent !important;
        padding: 0 !important;
        appearance: none;
        -webkit-appearance: none;
        font-weight: bold;
    }

    /* Layout for Print */
    .dashboard-container {
        display: block;
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .dashboard-left,
    .dashboard-right,
    .dashboard-center {
        background: transparent !important;
        box-shadow: none !important;
        border: 1px solid #ddd !important;
        margin-bottom: 20px;
        page-break-inside: avoid;
        overflow: visible;
        width: 100%;
        padding: 5px;
    }

    .panel-section h3,
    .card-header h3 {
        color: black;
        border-bottom: 2px solid black;
        margin-bottom: 10px;
    }

    /* Logo Enlarge */
    .logo-text {
        font-size: 24pt !important;
        color: black !important;
    }

    /* Price highlight */
    .price-row.total-row {
        font-size: 16pt;
        border-top: 2px solid black;
    }

    /* Footer */
    .print-footer {
        display: block !important;
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        text-align: center;
        border-top: 1px solid #ccc;
        padding-top: 10px;
        font-size: 10pt;
    }
}

/* --- New Dimension Styles (Added) --- */

.measure-line-vertical {
    position: absolute;
    top: 0;
    left: -30px;
    /* Shift to left of the panel */
    width: 20px;
    height: 100%;
    border-right: 1px solid #333;
    /* The vertical line */
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Redefine vertical arrows */
.measure-line-vertical .measure-arrow-v {
    position: absolute;
    right: -1px;
    /* Align with border-right line */
    width: 8px;
    height: 1px;
    /* Just a tick marker base */
    background: transparent;
}

.measure-line-vertical::before {
    content: '';
    position: absolute;
    top: 0;
    right: -4px;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-bottom: 8px solid #333;
    /* Up Arrow */
}

.measure-line-vertical::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: -4px;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 8px solid #333;
    /* Down Arrow */
}

.measure-text-vertical {
    transform: rotate(-90deg);
    background: white;
    padding: 0 5px;
    white-space: nowrap;
    font-size: 13px;
    font-weight: 600;
    color: #333;
    z-index: 5;
}

/* Horizontal Bottom Measure */
.measure-line-horizontal-bottom {
    position: absolute;
    bottom: -35px;
    /* Below rail */
    left: 0;
    width: 100%;
    height: 20px;
    border-top: 1px solid #333;
    display: flex;
    justify-content: center;
    align-items: center;
}

.measure-line-horizontal-bottom .measure-arrow-h {
    display: none;
    /* Handled by pseudo elements on container */
}

.measure-line-horizontal-bottom::before {
    content: '';
    position: absolute;
    top: -4.5px;
    /* Center on 1px line */
    left: 0;
    width: 0;
    height: 0;
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    border-right: 8px solid #333;
    /* Left Arrow */
}

.measure-line-horizontal-bottom::after {
    content: '';
    position: absolute;
    top: -4.5px;
    right: 0;
    width: 0;
    height: 0;
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    border-left: 8px solid #333;
    /* Right Arrow */
}

.measure-text-horizontal {
    background: white;
    padding: 0 5px;
    font-size: 13px;
    font-weight: 600;
    color: #333;
    margin-top: -11px;
    /* Move up to intersect line */
    z-index: 5;
}