/**
 * Estimate Builder Styles
 * Infinite Renovations V3: Warm Terracotta & Espresso
 * Professional estimating interface for roofing & renovation contractors
 */

/* ========================================
   LAYOUT
   ======================================== */

.builder-layout {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 24px;
    padding: 20px;
    min-height: calc(100vh - 140px);
}

.builder-main {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding-right: 8px;
    padding-bottom: 40px;
}

.builder-sidebar {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-right: 8px;
    padding-bottom: 40px;
    position: sticky;
    top: 20px;
    height: fit-content;
    max-height: calc(100vh - 160px);
    overflow-y: auto;
}

/* ========================================
   HEADER ADDITIONS
   ======================================== */

.back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: rgba(196, 184, 168, 0.1);
    border-radius: 0;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s;
    margin-right: 12px;
}

.back-btn:hover {
    background: rgba(196, 184, 168, 0.2);
    color: var(--text-primary);
}

.estimate-number {
    background: rgba(212, 132, 90, 0.15);
    color: #D4845A;
    padding: 4px 12px;
    border-radius: 0;
    font-size: 13px;
    font-weight: 600;
    margin-left: 12px;
}

/* ========================================
   BUILDER SECTIONS
   ======================================== */

.builder-section {
    background: var(--card-bg, rgba(48, 42, 36, 0.5));
    border: 1px solid var(--border-color, rgba(196, 184, 168, 0.1));
    border-radius: 0;
    overflow: hidden;
}

.builder-section .section-header-v2 {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color, rgba(196, 184, 168, 0.1));
    background: rgba(30, 27, 24, 0.3);
}

.builder-section .section-title-v2 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

/* ========================================
   INFO GRID
   ======================================== */

.info-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    padding: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.input-v2,
.select-v2,
.textarea-v2 {
    width: 100%;
    padding: 10px 14px;
    background: rgba(30, 27, 24, 0.5);
    border: 1px solid var(--border-color, rgba(196, 184, 168, 0.2));
    border-radius: 0;
    color: var(--text-primary);
    font-size: 14px;
    transition: all 0.2s;
}

.input-v2:focus,
.select-v2:focus,
.textarea-v2:focus {
    outline: none;
    border-color: #D4845A;
    box-shadow: 0 0 0 3px rgba(212, 132, 90, 0.15);
}

.textarea-v2 {
    resize: vertical;
    min-height: 80px;
}

/* ========================================
   LINE ITEMS TABLE
   ======================================== */

.line-items-table {
    padding: 0;
}

.table-header {
    display: grid;
    grid-template-columns: 2fr 80px 80px 100px 90px 110px 40px;
    gap: 12px;
    padding: 12px 20px;
    background: rgba(30, 27, 24, 0.5);
    border-bottom: 1px solid var(--border-color, rgba(196, 184, 168, 0.1));
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.line-items-body {
    min-height: 60px;
}

.line-item-row {
    display: grid;
    grid-template-columns: 2fr 80px 80px 100px 90px 110px 40px;
    gap: 12px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-color, rgba(196, 184, 168, 0.05));
    align-items: center;
    transition: background 0.2s;
}

.line-item-row:hover {
    background: rgba(212, 132, 90, 0.05);
}

.line-item-row input,
.line-item-row select {
    padding: 8px 10px;
    background: rgba(30, 27, 24, 0.5);
    border: 1px solid var(--border-color, rgba(196, 184, 168, 0.15));
    border-radius: 0;
    color: var(--text-primary);
    font-size: 13px;
    width: 100%;
}

.line-item-row input:focus,
.line-item-row select:focus {
    outline: none;
    border-color: #D4845A;
}

.line-item-row .item-name {
    font-weight: 500;
}

.line-item-row .item-total {
    font-weight: 600;
    color: var(--text-primary);
    text-align: right;
    padding-right: 8px;
}

.line-item-row .delete-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    border-radius: 0;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.line-item-row .delete-btn:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

.line-items-subtotal {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    background: rgba(212, 132, 90, 0.08);
    font-weight: 600;
    color: var(--text-primary);
}

.empty-line-items {
    padding: 30px 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

/* ========================================
   NOTES GRID
   ======================================== */

.notes-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    padding: 20px;
}

/* ========================================
   SUMMARY CARD
   ======================================== */

.summary-card {
    background: var(--card-bg, rgba(48, 42, 36, 0.5));
    border: 1px solid var(--border-color, rgba(196, 184, 168, 0.1));
    border-radius: 0;
    padding: 20px;
}

.summary-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 16px 0;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color, rgba(196, 184, 168, 0.1));
}

.summary-section {
    margin-bottom: 12px;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    font-size: 13px;
    color: var(--text-secondary);
}

.summary-row.subtotal {
    font-weight: 600;
    color: var(--text-primary);
    padding-top: 8px;
    margin-top: 4px;
    border-top: 1px dashed var(--border-color, rgba(196, 184, 168, 0.1));
}

.summary-row.editable span {
    display: flex;
    align-items: center;
    gap: 6px;
}

.inline-input {
    width: 50px;
    padding: 4px 8px;
    background: rgba(30, 27, 24, 0.5);
    border: 1px solid var(--border-color, rgba(196, 184, 168, 0.2));
    border-radius: 0;
    color: var(--text-primary);
    font-size: 13px;
    text-align: center;
}

.inline-input:focus {
    outline: none;
    border-color: #D4845A;
}

.summary-divider {
    height: 1px;
    background: var(--border-color, rgba(196, 184, 168, 0.15));
    margin: 16px 0;
}

.summary-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: linear-gradient(135deg, rgba(212, 132, 90, 0.15) 0%, rgba(34, 197, 94, 0.15) 100%);
    border-radius: 0;
    margin-top: 12px;
}

.summary-total span:first-child {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.summary-total span:last-child {
    font-size: 24px;
    font-weight: 700;
    color: #4ade80;
}

/* ========================================
   MARGIN ANALYSIS
   ======================================== */

.margin-analysis {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color, rgba(196, 184, 168, 0.1));
}

.margin-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px;
    background: rgba(30, 27, 24, 0.4);
    border-radius: 0;
}

.margin-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.margin-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

.margin-value.positive {
    color: #4ade80;
}

.margin-value.warning {
    color: #fbbf24;
}

.margin-value.negative {
    color: #f87171;
}

/* ========================================
   QUICK ACTIONS CARD
   ======================================== */

.quick-actions-card {
    background: var(--card-bg, rgba(48, 42, 36, 0.5));
    border: 1px solid var(--border-color, rgba(196, 184, 168, 0.1));
    border-radius: 0;
    padding: 16px;
}

.quick-actions-card h4 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 0 0 12px 0;
}

.quick-add-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.quick-add-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: rgba(30, 27, 24, 0.5);
    border: 1px solid var(--border-color, rgba(196, 184, 168, 0.15));
    border-radius: 0;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.quick-add-btn:hover {
    background: rgba(212, 132, 90, 0.1);
    border-color: rgba(212, 132, 90, 0.3);
    color: var(--text-primary);
}

.quick-add-btn svg {
    width: 14px;
    height: 14px;
    color: #D4845A;
}

/* ========================================
   VALIDITY CARD
   ======================================== */

.validity-card {
    background: var(--card-bg, rgba(48, 42, 36, 0.5));
    border: 1px solid var(--border-color, rgba(196, 184, 168, 0.1));
    border-radius: 0;
    padding: 16px;
}

.validity-date {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color, rgba(196, 184, 168, 0.1));
    font-size: 13px;
    color: var(--text-secondary);
}

.validity-date span {
    font-weight: 600;
    color: var(--text-primary);
}

/* ========================================
   MODALS
   ======================================== */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(43, 37, 32, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: var(--card-bg, #1E1B18);
    border: 1px solid var(--border-color, rgba(196, 184, 168, 0.2));
    border-radius: 0;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 25px 50px -12px rgba(43, 37, 32, 0.5);
}

.modal-md {
    max-width: 500px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color, rgba(196, 184, 168, 0.1));
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    border-radius: 0;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.modal-close:hover {
    background: rgba(196, 184, 168, 0.1);
    color: var(--text-primary);
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-color, rgba(196, 184, 168, 0.1));
}

/* Send Modal Specifics */
.send-preview {
    background: rgba(30, 27, 24, 0.5);
    border-radius: 0;
    padding: 16px;
    margin-bottom: 20px;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.preview-header strong {
    color: var(--text-primary);
}

.preview-header span {
    font-size: 13px;
    color: var(--text-secondary);
}

.preview-total {
    font-size: 18px;
    color: var(--text-secondary);
}

.preview-total strong {
    color: #4ade80;
}

.send-options {
    display: flex;
    gap: 16px;
}

.send-option {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 14px;
}

.send-option input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #D4845A;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 14px;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #D4845A;
}

/* ========================================
   BUTTON VARIANTS
   ======================================== */

.btn-v2-sm {
    padding: 6px 12px;
    font-size: 13px;
}

.btn-v2-sm svg {
    width: 14px;
    height: 14px;
}

/* ========================================
   RESPONSIVE
   ======================================== */

@media (max-width: 1200px) {
    .builder-layout {
        grid-template-columns: 1fr;
    }

    .builder-sidebar {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }

    .summary-card {
        grid-column: span 2;
    }
}

@media (max-width: 768px) {
    .builder-layout {
        padding: 12px;
    }

    .info-grid,
    .notes-grid {
        grid-template-columns: 1fr;
    }

    .table-header,
    .line-item-row {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .table-header {
        display: none;
    }

    .line-item-row {
        padding: 16px;
        position: relative;
    }

    .line-item-row::before {
        content: attr(data-label);
        position: absolute;
        top: 8px;
        left: 16px;
        font-size: 11px;
        font-weight: 600;
        color: var(--text-muted);
        text-transform: uppercase;
    }

    .builder-sidebar {
        grid-template-columns: 1fr;
    }

    .summary-card {
        grid-column: span 1;
    }

    .header-right {
        flex-wrap: wrap;
        gap: 8px;
    }

    .header-right .btn-v2 {
        flex: 1;
        min-width: 120px;
        justify-content: center;
    }
}

/* ========================================
   SCROLLBAR STYLING
   ======================================== */

.builder-main::-webkit-scrollbar,
.builder-sidebar::-webkit-scrollbar {
    width: 6px;
}

.builder-main::-webkit-scrollbar-track,
.builder-sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.builder-main::-webkit-scrollbar-thumb,
.builder-sidebar::-webkit-scrollbar-thumb {
    background: rgba(196, 184, 168, 0.2);
    border-radius: 0;
}

.builder-main::-webkit-scrollbar-thumb:hover,
.builder-sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(196, 184, 168, 0.3);
}
