/* static/css/style.css */

:root {
    --primary: #0073ea; 
    --dark: #2b3348;
    --light: #f5f6f8;
    --danger: #e24c4c;
    --border-color: #ddd;
}

body, html { 
    margin: 0; padding: 0; 
    font-family: 'Figtree', sans-serif; 
    background: var(--light);
    min-height: 100vh;
}

/* --- NAVIGATION --- */
.top-nav {
    height: 60px; background: white; border-bottom: 1px solid var(--border-color);
    display: flex; align-items: center; justify-content: space-between; padding: 0 30px;
    position: sticky; top: 0; z-index: 1000;
}
.nav-left, .nav-right { display: flex; align-items: center; gap: 15px; }

.nav-btn { 
    cursor: pointer; padding: 18px 15px; font-weight: 600; color: #555; 
    border-bottom: 3px solid transparent; transition: 0.3s;
}
.nav-btn.active { color: var(--primary); border-color: var(--primary); }
.nav-btn.disabled { opacity: 0.3; pointer-events: none; color: #999 !important; }

.icon-btn { font-size: 1.3rem; color: var(--dark); cursor: pointer; transition: 0.2s; }
.icon-btn:hover { color: var(--primary); transform: scale(1.1); }

/* Sales envelope: visible hover label (native title on <button> is unreliable over the <i> icon) */
.nav-sales-tooltip-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.nav-sales-tooltip-wrap .nav-sales-tip {
    position: absolute;
    bottom: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%);
    padding: 7px 12px;
    background: var(--dark);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    border-radius: 6px;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.15s ease, visibility 0.15s;
    z-index: 1100;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}
.nav-sales-tooltip-wrap .nav-sales-tip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -6px;
    border: 6px solid transparent;
    border-top-color: var(--dark);
}
.nav-sales-tooltip-wrap:hover .nav-sales-tip,
.nav-sales-tooltip-wrap:focus-within .nav-sales-tip {
    opacity: 1;
    visibility: visible;
}
.top-user-badge {
    font-size: 0.9rem;
    color: #444;
    font-weight: 600;
    white-space: nowrap;
}

/* --- HOME PAGE --- */
.home-content { padding: 20px; max-width: 1400px; margin: 0 auto; }

.hero-banner {
    height: 350px;
    background-size: cover;
    background-position: center;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    text-shadow: 2px 2px 10px rgba(0,0,0,0.7);
    margin-bottom: 25px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.hero-banner h1 { font-size: 4rem; text-transform: uppercase; letter-spacing: 2px; }

.home-images {
    display: flex;
    gap: 20px;
    justify-content: space-between;
}
.home-images img {
    width: 32%; height: 280px;
    border-radius: 10px;
    object-fit: cover;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    transition: transform 0.3s;
}
.home-images img:hover { transform: translateY(-5px); }

/* --- DATA TAB & TABLE BUTTONS (Restored for the 20 items) --- */
.table-selector-bar {
    display: flex; flex-wrap: wrap; gap: 8px; 
    padding: 15px; background: white; 
    border-bottom: 1px solid var(--border-color);
}
.table-btn {
    padding: 8px 14px; background: #eee; border: 1px solid #ccc;
    border-radius: 4px; cursor: pointer; font-size: 0.85rem; font-weight: 600;
}
.table-btn.active { background: var(--primary); color: white; border-color: var(--primary); }

/* --- PHOTO ASSIGNMENT DASHBOARD --- */
.photo-assign-layout { display: flex; gap: 20px; margin: 20px; }

.photo-assign-column { 
    flex: 1; background: white; border-radius: 8px; 
    box-shadow: 0 2px 6px rgba(0,0,0,0.06); padding: 10px; 
    min-height: 260px; display: flex; flex-direction: column; 
}
.photo-assign-column h3 { font-size: 1rem; color: var(--dark); border-bottom: 1px solid #eee; padding-bottom: 10px; }

.photo-assign-list { flex: 1; overflow-y: auto; border: 1px dashed #ddd; border-radius: 4px; padding: 4px; font-size: 0.85rem; }

.photo-item, .project-item, .customer-item { 
    background: #f8f9fc; margin-bottom: 4px; padding: 6px 8px; 
    border-radius: 4px; cursor: grab; border: 1px solid #eee;
}
.photo-item.selected { border: 2px solid var(--primary); background: #e8f2ff; }
.photo-assign-controls { display: flex; justify-content: space-between; align-items: center; margin: 10px 20px; gap: 10px; }

/* --- MODAL --- */
.modal {
    display: none; position: fixed; z-index: 9999;
    left: 0; top: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.6); justify-content: center; align-items: center;
}
.modal-content {
    background: white; padding: 35px; border-radius: 12px;
    width: 90%; max-width: 400px; position: relative;
}
.close-btn { position: absolute; right: 20px; top: 15px; font-size: 24px; cursor: pointer; color: #aaa; }

/* Billing: Create Estimate / Create Invoice — scroll long line items; keep Cancel/Save visible */
.modal.billing-modal-tall {
    align-items: flex-start;
    justify-content: center;
    overflow-y: auto;
    padding: 24px 12px;
    box-sizing: border-box;
}
#billing-quote-modal .billing-quote-modal-inner,
#billing-invoice-modal .billing-invoice-modal-inner {
    display: flex;
    flex-direction: column;
    max-height: min(92vh, calc(100vh - 48px));
    overflow: hidden !important; /* keep footer pinned; scroll is on .billing-*-modal-scroll */
    box-sizing: border-box;
    margin: 0 auto;
}
#billing-quote-modal .billing-quote-modal-scroll,
#billing-invoice-modal .billing-invoice-modal-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding-right: 4px;
}
#billing-quote-modal .billing-quote-modal-actions,
#billing-invoice-modal .billing-invoice-modal-actions {
    flex-shrink: 0;
    background: #fff;
}

/* Purchases report: Create/Edit — scroll long form; keep footer actions visible */
.modal.purchase-modal-tall {
    align-items: flex-start;
    justify-content: center;
    overflow-y: auto;
    padding: 24px 12px;
    box-sizing: border-box;
}
#purchase-modal .purchase-modal-inner {
    display: flex;
    flex-direction: column;
    max-height: min(92vh, calc(100vh - 48px));
    overflow: hidden !important;
    box-sizing: border-box;
    margin: 0 auto;
}
#purchase-modal .purchase-modal-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding-right: 4px;
}
#purchase-modal .purchase-modal-actions {
    flex-shrink: 0;
    background: #fff;
    padding-top: 4px;
}

/* --- GLOBAL LAYOUT --- */
.main-wrapper { padding: 0; } /* Set to 0 so the table bar hits the edges */
.view-section { display: none; }
.view-section.active { display: block; animation: fadeIn 0.4s ease; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ===== MOBILE-ONLY ELEMENTS (hidden on desktop) ===== */
.mobile-menu-btn {
    display: none;
    background: none; border: none; color: var(--dark);
    font-size: 1.3rem; cursor: pointer; padding: 4px 8px;
}
.mobile-nav-backdrop {
    display: none; position: fixed; inset: 0; z-index: 9998;
    background: rgba(0,0,0,0.35);
}
.mobile-nav-backdrop.open { display: block; }
.mobile-nav-drawer {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 9999;
    width: 250px; background: white;
    transform: translateX(-100%); transition: transform 0.25s ease;
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
    overflow-y: auto; display: none;
}
.mobile-nav-drawer.open { transform: translateX(0); }
.mobile-nav-item {
    padding: 14px 18px; cursor: pointer; color: #444;
    font-weight: 500; font-size: 0.95rem;
    border-bottom: 1px solid #f0f0f0;
    display: flex; align-items: center; gap: 10px;
}
.mobile-nav-item:hover, .mobile-nav-item:active { background: #f0f4f8; color: var(--primary); }
.mobile-nav-item.disabled { color: #bbb; pointer-events: none; }

.mobile-only-nav-section { display: none; }

.sidebar-toggle {
    display: none;
    position: fixed; bottom: 18px; left: 18px; z-index: 10001;
    width: 48px; height: 48px; border-radius: 50%;
    background: var(--primary); color: white; border: none;
    font-size: 1.3rem; cursor: pointer;
    box-shadow: 0 3px 12px rgba(0,0,0,0.3);
    align-items: center; justify-content: center;
}

/* ===== RESPONSIVE: <= 768px ===== */
@media (max-width: 768px) {

    /* --- TOP NAV --- */
    .top-nav { padding: 0 10px; height: 50px; }
    .nav-left { gap: 6px; flex-shrink: 1; }
    .nav-btn.nav-restricted { display: none !important; }
    .mobile-menu-btn { display: inline-flex !important; align-items: center; }
    .mobile-nav-drawer { display: block; }
    .nav-btn { padding: 14px 8px; font-size: 0.85rem; white-space: nowrap; }
    .nav-right { gap: 8px; flex-shrink: 0; }
    .icon-btn { font-size: 1.1rem; }
    .top-user-badge { font-size: 0.75rem; max-width: 90px; overflow: hidden; text-overflow: ellipsis; }

    /* --- HOME --- */
    .home-content { padding: 10px; }
    .home-images { flex-direction: column; }
    .home-images img { width: 100% !important; height: 200px; }
    .hero-banner { height: 200px; }
    .hero-banner h1 { font-size: 1.8rem; }

    /* --- SIDEBAR → COLLAPSIBLE OVERLAY --- */
    .sidebar-toggle { display: flex; }

    .analytics-wrapper { flex-direction: column; }

    .ana-sidebar {
        position: fixed; left: 0; top: 50px; bottom: 0; z-index: 10000;
        width: 220px; transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: 4px 0 20px rgba(0,0,0,0.15);
        overflow-y: auto;
    }
    .ana-sidebar.open { transform: translateX(0); }

    .sidebar-backdrop {
        display: none; position: fixed; inset: 0; z-index: 9999;
        background: rgba(0,0,0,0.35);
    }
    .sidebar-backdrop.open { display: block; }

    .ana-main-content { padding: 12px !important; width: 100% !important; }
    .mobile-only-nav-section { display: block; }

    /* --- FILTER BARS --- */
    .filter-bar,
    .card.filter-bar {
        flex-wrap: wrap !important;
        gap: 8px !important;
        padding: 10px !important;
    }
    .filter-item { min-width: 0 !important; flex: 1 1 100% !important; }

    /* --- KPI GRIDS (override inline repeat(3/4, 1fr)) --- */
    .kpi-grid,
    .dashboard-container > div[style*="repeat(4"],
    .dashboard-container > div[style*="repeat(3"],
    div[style*="grid-template-columns: repeat(4"],
    div[style*="grid-template-columns: repeat(3"] {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }

    /* --- CHART GRIDS & TWO-COL LAYOUTS --- */
    .chart-grid,
    .dashboard-container div[style*="grid-template-columns: 1fr 1fr"],
    .dashboard-container div[style*="grid-template-columns:1fr 1fr"],
    .modal-content div[style*="grid-template-columns: 1fr 1fr"],
    .modal-content div[style*="grid-template-columns:1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* --- BUTTON GROUPS (billing bounding boxes, photo action bars) --- */
    div[style*="display:flex"][style*="gap"] > fieldset,
    div[style*="display: flex"][style*="gap"] > fieldset {
        flex: 1 1 100% !important;
        min-width: 0 !important;
    }

    /* --- TABLES --- */
    .full-width-table { font-size: 0.78rem; }
    .full-width-table th,
    .full-width-table td { padding: 8px 6px !important; }

    /* Scrollable table wrappers */
    div[style*="overflow-x: auto"],
    div[style*="overflow-x:auto"] {
        max-height: none !important;
    }

    /* --- MODALS --- */
    .modal-content {
        width: 96% !important;
        max-width: 100% !important;
        max-height: 90vh !important;
        overflow-y: auto !important;
        padding: 18px !important;
        border-radius: 10px !important;
        margin: 5vh auto !important;
    }
    #billing-quote-modal .billing-quote-modal-inner,
    #billing-invoice-modal .billing-invoice-modal-inner {
        overflow: hidden !important;
        max-height: min(90vh, calc(100vh - 40px)) !important;
    }
    #purchase-modal .purchase-modal-inner {
        overflow: hidden !important;
        max-height: min(90vh, calc(100vh - 40px)) !important;
    }
    .close-btn { right: 12px; top: 10px; }

    /* --- PHOTO ASSIGNMENT LAYOUT --- */
    .photo-assign-layout { flex-direction: column; }
    .photo-assign-controls { flex-wrap: wrap; }

    /* --- BOUNDING BOXES / FIELDSETS --- */
    fieldset { padding: 8px !important; }
    fieldset legend { font-size: 0.8rem !important; }
    fieldset button { font-size: 0.75rem !important; padding: 6px 10px !important; }

    /* --- INPUTS: prevent iOS zoom & improve touch targets --- */
    input, select, textarea {
        font-size: 16px !important;
        min-height: 40px;
    }
    button { min-height: 40px; }

    /* --- MISC INLINE OVERRIDES --- */
    .ana-sidebar-item { font-size: 0.9rem; padding: 10px 12px; }
    .table-selector-bar { gap: 4px; padding: 10px; }
    .table-btn { font-size: 0.75rem; padding: 6px 10px; }

    /* --- DATA TAB: form layout --- */
    #view-data .main-wrapper,
    #view-data { padding: 8px; }
}