body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f0f4f8; /* Light blue-grey background */
    color: #333;
    margin: 0;
    /* Default centering for login page */
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

/* Base Container (Login style) */
.container {
    background-color: #ffffff;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    width: 90%;
    max-width: 400px;
    text-align: center;
    box-sizing: border-box;
}

/* Overrides for Admin/Dashboard Pages */
body.admin-body {
    display: block;
    height: auto;
    padding: 10px;
    min-height: 100vh;
}

body.admin-body .container {
    max-width: 1400px; /* Use full width for configurator */
    margin: 0 auto;
    text-align: left;
    padding: 10px;
}

/* Desktop Split Layout */
.configurator-layout {
    display: flex;
    gap: 15px;
    align-items: flex-start; /* Top align */
    width: 100%;
}

.configurator-main {
    flex: 1; /* Take remaining space */
    min-width: 0; /* Prevent flex overflow */
}

.configurator-preview {
    flex: 1; /* Take equal space (50/50 split) */
    min-width: 350px; /* But keep a minimum sane width */
    position: sticky;
    top: 10px;
    height: calc(100vh - 20px); /* Full height minus padding */
    overflow-y: auto;
    background-color: #fdfdfd;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

/* Adjust the preview panel internal styling */
#doc-preview-panel {
    position: static;
    width: 100%;
    height: auto;
    box-shadow: none;
    border: none;
    padding: 10px;
    transform: none;
}

#doc-preview-header {
    margin-top: 0;
    border-bottom: 1px solid #eee;
    padding-bottom: 5px;
    font-size: 1.1em;
    color: #0056b3;
    position: sticky;
    top: 0;
    background: #fdfdfd;
    z-index: 10;
}

/* General Styles (COMPRESSED DESKTOP) */
h1, h2 {
    color: #0056b3;
    margin-bottom: 0.5rem;
    font-size: 1.3rem;
}

h3 {
    color: #0056b3;
    margin-bottom: 0.3rem;
    font-size: 1.1rem;
}

input[type="text"],
input[type="password"],
input[type="number"],
select {
    width: 100%;
    padding: 4px 6px;
    margin: 3px 0;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
    font-size: 0.9rem;
}

button {
    background-color: #0056b3;
    color: white;
    padding: 6px 10px;
    margin: 3px 0;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    width: 100%;
    font-size: 0.9rem;
    transition: background-color 0.3s;
}

button:hover {
    background-color: #004494;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 5px;
    background-color: #fff;
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    font-size: 0.85rem;
}

th, td {
    padding: 5px 8px;
    text-align: left;
    border-bottom: 1px solid #eee;
}

th {
    background-color: #0056b3;
    color: white;
    font-weight: 600;
}

tr:hover {
    background-color: #f8f9fa;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    border-bottom: 2px solid #0056b3;
    padding-bottom: 5px;
}

.logout-btn {
    width: auto;
    background-color: #6c757d;
    padding: 4px 10px;
    margin-left: 10px;
}
.logout-btn:hover {
    background-color: #5a6268;
}

.user-form {
    background-color: #ffffff;
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 15px;
    border: 1px solid #e9ecef;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.filter-group {
    margin-bottom: 5px;
}

.form-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.form-row input,
.form-row select {
    flex: 1;
    margin: 1px 0;
}

.form-row button {
    width: auto;
    white-space: nowrap;
    margin: 1px 0;
    height: 30px;
    padding: 0 12px;
}

.action-btn {
    padding: 3px 6px;
    font-size: 0.8rem;
    width: auto;
    margin-right: 3px;
}

.btn-edit { background-color: #ffc107; color: #212529; }
.btn-delete { background-color: #dc3545; }

/* Selection Grid Styles */
.selection-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 3px;
    max-height: 200px; /* Compressed height */
    overflow-y: auto;
    padding: 4px;
    background-color: #f8f9fa;
    border-radius: 4px;
    border: 1px solid #e9ecef;
}

.grid-item {
    background-color: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 6px 10px;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
    font-size: 0.85rem;
    flex: 1 1 auto; /* Allow items to grow */
    text-align: center;
    min-width: 70px;
}

.grid-item:hover {
    background-color: #e9ecef;
}

.grid-item.selected {
    background-color: #0056b3;
    color: white;
    border-color: #004494;
}

/* --- MOBILE OPTIMIZATION (CLEAN STACKING FOR IPHONE) --- */
@media (max-width: 768px) {
    body.admin-body {
        padding: 5px;
        font-size: 14px; /* Slightly smaller base font for mobile */
    }

    /* Reset Flex layout to simple block flow for stability on mobile */
    .configurator-layout {
        display: block;
        width: 100%;
        gap: 0;
    }

    .configurator-main {
        width: 100%;
        margin-bottom: 20px;
    }

    /* Forced spacing for configurator panels */
    .user-form {
        padding: 15px;
        margin-bottom: 20px;
        border-radius: 10px;
    }

    /* Stack form rows with clear vertical separation */
    .form-row {
        display: block;
        margin-bottom: 15px;
    }

    .form-row input,
    .form-row select,
    .form-row button {
        width: 100%;
        height: 48px; /* Larger touch target */
        margin: 10px 0;
        font-size: 16px; /* Prevents auto-zoom on iOS */
        border-radius: 8px;
        padding: 12px;
    }

    /* Side-by-side rows should stack on mobile */
    .side-by-side-row {
        display: block;
        gap: 0;
    }
    
    .side-by-side-row > .filter-group {
        margin-bottom: 15px;
    }

    /* Larger grid items for reliable tapping */
    .grid-item {
        min-height: 50px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1rem;
        padding: 12px;
        min-width: 80px;
        margin: 3px;
        flex: 1 1 calc(50% - 6px); /* 2 items per row on mobile */
        box-sizing: border-box;
    }

    .selection-grid {
        gap: 6px;
        padding: 8px;
        max-height: 300px; /* Allow more items to be visible */
    }

    /* Sash type buttons - make them larger and stack */
    .sash-type-btn {
        padding: 20px 10px;
        font-size: 1rem;
        margin-bottom: 10px;
        flex-direction: row;
        gap: 15px;
        justify-content: flex-start;
        text-align: left;
    }
    
    .sash-icon-svg {
        width: 50px;
        height: 50px;
        flex-shrink: 0;
    }

    /* Config steps - better spacing */
    .config-step {
        margin-bottom: 30px;
        padding-bottom: 20px;
    }

    /* Section headers - better visibility */
    .section-header {
        padding: 15px;
        margin: 20px 0 15px 0;
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .section-header > div {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    /* Results Header Stack */
    #results-area > div {
        display: block;
        width: 100%;
        margin-bottom: 15px;
    }
    
    #results-area > div > div {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .document-section {
        padding: 15px;
        background: #f8f9fa;
        border-radius: 10px;
        margin-top: 15px;
    }
    
    .document-section .form-row {
        flex-direction: column;
        gap: 10px;
    }
    
    .document-section input,
    .document-section select,
    .document-section button {
        width: 100%;
        margin: 5px 0;
    }

    /* Scrollable tables for narrow screens */
    table, #result-table, .preview-table {
        display: block;
        width: 100%;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch; /* Smooth iOS scroll */
        font-size: 13px;
    }
    
    th, td {
        padding: 10px 8px;
        min-width: 80px; /* Ensure cells are wide enough */
    }

    /* Mobile-optimized preview panel */
    .configurator-preview {
        display: block;
        position: static;
        width: 100%;
        min-width: 0;
        height: auto;
        max-height: none;
        margin-top: 30px;
        border-top: 4px solid #0056b3;
        background: #fff;
        border-radius: 10px;
        padding: 15px;
        box-sizing: border-box;
    }

    #doc-preview-panel {
        padding: 0;
    }

    #doc-preview-header {
        position: static;
        font-size: 1.3rem;
        margin-bottom: 20px;
        padding-bottom: 10px;
        border-bottom: 2px solid #eee;
    }
    
    #preview-actions {
        display: flex;
        flex-direction: column;
        gap: 10px;
        margin-top: 15px;
    }
    
    #preview-actions select,
    #preview-actions button {
        width: 100%;
        height: 44px;
    }

    /* Preview position items - better touch targets */
    .preview-position {
        margin-bottom: 15px;
        border-radius: 10px;
        overflow: hidden;
    }
    
    .preview-pos-header {
        padding: 15px;
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }
    
    .preview-pos-info {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
        width: 100%;
    }
    
    .preview-pos-details {
        font-size: 14px;
        line-height: 1.4;
    }
    
    .preview-pos-content {
        padding: 15px;
    }

    /* iPhone-friendly Admin Header */
    .admin-header {
        display: flex;
        flex-direction: column;
        text-align: center;
        padding-bottom: 15px;
        gap: 15px;
    }

    .admin-header h2 {
        font-size: 1.5rem;
        margin: 0;
    }

    .admin-header div {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
        justify-content: center;
        width: 100%;
    }

    .admin-header button {
        flex: 1;
        min-width: 140px;
        height: 44px;
        font-size: 1rem;
    }
    
    /* Dimensions step - better layout */
    #dimensions-step {
        padding: 20px 15px;
    }
    
    #dimensions-step .form-row {
        flex-direction: column;
        gap: 15px;
    }
    
    #dimensions-step input,
    #dimensions-step select {
        width: 100%;
        max-width: none;
    }
    
    #dimensions-step button {
        width: 100%;
        padding: 15px;
        font-size: 1.1rem;
        margin-top: 10px;
    }
    
    /* Handle height step */
    #handle-height-step {
        width: 100%;
    }
    
    /* Better spacing for opening kind containers */
    #opening-kinds-container {
        flex-direction: column;
        gap: 20px;
    }
    
    #sash-container-1,
    #sash-container-2 {
        width: 100%;
    }
    
    /* Hide some less important elements on mobile */
    #config-set-info {
        font-size: 0.8em;
        padding: 3px 10px;
    }
    
    #selected-fitting-line-display {
        font-size: 0.9em;
        margin-left: 0;
        margin-top: 5px;
    }
}
