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

:root {
    /* Brand Colors */
    --primary: #0284c7;
    /* Sky 600 - darker/more restrained blue */
    --primary-dark: #0369a1;
    --secondary: #9333ea;
    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;

    /* Gradients (Removed/Simplified for flat look) */
    --gradient-primary: linear-gradient(135deg, #0284c7 0%, #0ea5e9 100%);

    /* Neutrals - Light Theme */
    --bg-primary: #f8fafc;
    /* Slate 50 */
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --border-color: #cbd5e1;
    /* Slate 300 */
    --text-primary: #0f172a;
    /* Slate 900 */
    --text-secondary: #64748b;
    /* Slate 500 */

    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;

    /* Border radius - Flatter */
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;

    /* Shadows - Minimal/None */
    --shadow-sm: none;
    --shadow-md: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    padding: var(--spacing-md);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: var(--spacing-xl);
    padding: var(--spacing-xl) 0;
}

.title {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--spacing-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-md);
}

.icon {
    font-size: 3rem;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* Card */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    margin-bottom: var(--spacing-lg);
    box-shadow: var(--shadow-sm);
}

/* Header Actions */
.header {
    position: relative;
    /* margin-bottom reduced for compactness */
    margin-bottom: var(--spacing-md);
    padding: var(--spacing-md) 0;
}

.settings-btn {
    position: fixed;
    top: 20px;
    right: 20px;
    background: white;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
    cursor: pointer;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    color: var(--text-secondary);
}

.settings-btn:hover {
    color: var(--primary);
    transform: rotate(45deg);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

/* Compact Form Grid (Read-Only Info Bar) */
.compact-form-grid {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-md);
    align-items: center;
    justify-content: space-between;
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--spacing-sm) var(--spacing-lg);
}

.compact-form-grid .form-group {
    flex-direction: row;
    align-items: center;
    gap: var(--spacing-sm);
}

.compact-form-grid .form-group label {
    font-size: 0.8rem;
    margin-bottom: 0;
    color: var(--text-secondary);
    white-space: nowrap;
}

.compact-form-grid .form-group input {
    width: 80px;
    padding: 0;
    background: transparent;
    border: none;
    font-weight: 700;
    color: var(--text-primary);
    font-size: 0.95rem;
    text-align: left;
}

.compact-form-grid .form-group input:disabled {
    background: transparent;
    color: var(--text-primary);
    cursor: default;
    opacity: 1;
    /* Override default disabled opacity */
}

/* Bitrix Select in Modal */
.bitrix-select {
    width: 100%;
    padding: var(--spacing-sm);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    font-size: 0.95rem;
}


/* Form Grid */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--spacing-lg);
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.form-group label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-group input,
.form-group select {
    padding: var(--spacing-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 1rem;
    transition: all 0.2s ease;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(2, 132, 199, 0.1);
}

.form-group input:hover,
.form-group select:hover {
    border-color: var(--primary);
}

/* Table Container */
.table-container {
    overflow-x: auto;
    margin-bottom: var(--spacing-lg);
}

.items-table {
    width: 100%;
    border-collapse: collapse;
}

.items-table th {
    background: #f1f5f9;
    /* Slate 100 */
    padding: var(--spacing-sm);
    text-align: left;
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    text-transform: uppercase;
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.items-table td {
    padding: 0.4rem var(--spacing-sm);
    /* More compact vertical padding */
    border-bottom: 1px solid var(--border-color);
}

.items-table tbody tr {
    transition: background 0.2s ease;
}

.items-table tbody tr:hover {
    background: rgba(47, 198, 246, 0.05);
}

/* Table inputs and selects */
.material-select,
.width-select,
.quantity-input {
    width: 100%;
    padding: var(--spacing-sm);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: all 0.2s ease;
}

.material-select:focus,
.width-select:focus,
.quantity-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(47, 198, 246, 0.1);
}

.material-select:disabled,
.width-select:disabled,
.quantity-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Result cells */
.result-cell {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.text-truncate {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Add button */
.btn-add {
    padding: var(--spacing-sm) var(--spacing-lg);
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    transition: all 0.2s ease;
}

.btn-add:hover {
    border-color: var(--primary);
    background: rgba(47, 198, 246, 0.05);
    color: var(--primary);
}

.btn-add .btn-icon {
    font-size: 1.5rem;
}

/* Delete button */
.btn-delete {
    background: transparent;
    border: none;
    color: var(--error);
    cursor: pointer;
    font-size: 1.5rem;
    padding: var(--spacing-xs);
    transition: all 0.2s ease;
    border-radius: var(--radius-sm);
}

.btn-delete:hover {
    background: rgba(239, 68, 68, 0.1);
    transform: scale(1.1);
}

.delete-icon {
    font-size: 1.8rem;
    line-height: 1;
    display: block;
}

/* Action Section */
.action-section {
    display: flex;
    justify-content: center;
    margin: var(--spacing-xl) 0;
}

.btn-primary {
    padding: var(--spacing-md) var(--spacing-xl);
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    transition: background 0.2s ease;
    box-shadow: var(--shadow-sm);
    min-width: 200px;
    justify-content: center;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-xl);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-icon {
    font-size: 1.5rem;
}

/* Total row */
.total-row {
    background: #f0f9ff !important;
    /* light blue bg */
    font-size: 1.1rem;
    color: var(--text-primary);
    font-weight: 600;
}

.total-row td {
    border-bottom: none;
    padding: var(--spacing-lg);
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-lg);
    z-index: 1000;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Error Message */
.error-message {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.1) 0%, rgba(220, 38, 38, 0.1) 100%);
    border: 1px solid var(--error);
    border-radius: var(--radius-md);
    padding: var(--spacing-lg);
    margin: var(--spacing-lg) 0;
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    color: var(--error);
    animation: shake 0.5s ease;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-10px);
    }

    75% {
        transform: translateX(10px);
    }
}

.error-icon {
    font-size: 1.5rem;
}

/* Responsive */
@media (max-width: 768px) {
    .title {
        font-size: 2rem;
        flex-direction: column;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .items-table {
        font-size: 0.875rem;
    }

    .items-table th,
    .items-table td {
        padding: var(--spacing-sm);
    }

    .btn-primary {
        min-width: 100%;
    }

    .text-truncate {
        max-width: 150px;
    }
}

@media (max-width: 480px) {

    .items-table th,
    .items-table td {
        padding: 0.4rem;
        font-size: 0.8rem;
    }

    .material-select,
    .width-select,
    .quantity-input {
        font-size: 0.85rem;
        padding: 0.4rem;
    }
}