:root {
    --primary: #0E4C92;
    --primary-dark: #0a3a6e;
    --accent: #F39C12;
    --success: #27AE60;
    --dark: #1F2937;
    --light-bg: #F8FAFC;
    --card-bg: #ffffff;
    --text-primary: #1F2937;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -2px rgba(0,0,0,.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -4px rgba(0,0,0,.1);
}

[data-theme="dark"] {
    --light-bg: #111827;
    --card-bg: #1F2937;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #374151;
    --shadow: 0 4px 6px -1px rgba(0,0,0,.3);
}

* { font-family: 'Inter', sans-serif; }

body {
    background-color: var(--light-bg);
    color: var(--text-primary);
    transition: background-color .3s, color .3s;
}

.text-accent { color: var(--accent) !important; }
.text-primary-brand { color: var(--primary) !important; }

/* Navbar */
.navbar-pro {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    padding: .75rem 0;
}

.navbar-pro .navbar-brand {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--primary);
}

.navbar-pro .nav-link {
    color: var(--text-secondary);
    font-weight: 500;
    padding: .5rem 1rem !important;
    border-radius: 8px;
    transition: all .2s;
}

.navbar-pro .nav-link:hover,
.navbar-pro .nav-link.active {
    color: var(--primary);
    background: rgba(14, 76, 146, .08);
}

.navbar-pro .navbar-toggler {
    border-color: var(--border-color);
    padding: .4rem .65rem;
}

.navbar-pro .navbar-toggler:focus {
    box-shadow: 0 0 0 3px rgba(14, 76, 146, .2);
}

.btn-accent {
    background: var(--accent);
    color: #fff;
    border: none;
    font-weight: 600;
    border-radius: 8px;
    padding: .5rem 1.25rem;
    transition: all .2s;
}

.btn-accent:hover {
    background: #e08e0b;
    color: #fff;
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.btn-primary-brand {
    background: var(--primary);
    color: #fff;
    border: none;
    font-weight: 600;
    border-radius: 8px;
}

.btn-primary-brand:hover {
    background: var(--primary-dark);
    color: #fff;
}

.btn-theme-toggle {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: .4rem .75rem;
    color: var(--text-secondary);
}

/* Hero */
.hero-section {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 60%, #0a2540 100%);
    color: #fff;
    padding: 5rem 0 6rem;
    position: relative;
    overflow: hidden;
}

.hero-section::before {
    content: '';
    position: absolute;
    top: 0; right: 0; bottom: 0; left: 0;
    background: url('https://images.unsplash.com/photo-1541888946425-d81bb19240f5?w=1920') center/cover;
    opacity: .15;
}

.hero-content { position: relative; z-index: 1; }

.hero-title {
    font-size: 3rem;
    font-weight: 800;
    line-height: 1.2;
    margin-bottom: 1.5rem;
}

.hero-subtitle {
    font-size: 1.2rem;
    opacity: .9;
    margin-bottom: 2rem;
    max-width: 540px;
}

.hero-image {
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.hero-image img {
    width: 100%;
    height: 400px;
    object-fit: cover;
}

.hero-badge {
    display: inline-block;
    background: rgba(243, 156, 18, .2);
    color: var(--accent);
    padding: .35rem 1rem;
    border-radius: 50px;
    font-size: .85rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

/* Cards */
.stat-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    transition: all .3s;
    height: 100%;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.stat-card .stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    margin-bottom: 1rem;
}

.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-card .stat-label {
    color: var(--text-secondary);
    font-size: .875rem;
    font-weight: 500;
}

.icon-primary { background: rgba(14, 76, 146, .12); color: var(--primary); }
.icon-accent { background: rgba(243, 156, 18, .12); color: var(--accent); }
.icon-success { background: rgba(39, 174, 96, .12); color: var(--success); }
.icon-dark { background: rgba(31, 41, 55, .12); color: var(--dark); }

/* Feature Cards */
.feature-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 2rem;
    border: 1px solid var(--border-color);
    transition: all .3s;
    height: 100%;
}

.feature-card:hover {
    transform: translateY(-6px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
}

.feature-card .feature-icon {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-bottom: 1.25rem;
}

.feature-card h5 { font-weight: 700; margin-bottom: .75rem; }
.feature-card p { color: var(--text-secondary); margin: 0; }

/* Page Header */
.page-header {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    padding: 2.5rem 0;
    margin-bottom: 2rem;
}

.page-header h1 { font-weight: 700; margin: 0; }
.page-header p { opacity: .85; margin: .5rem 0 0; }

/* Content Card */
.content-card {
    background: var(--card-bg);
    border-radius: 16px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.content-card .card-header-custom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.content-card .card-header-custom h5 {
    margin: 0;
    font-weight: 700;
}

/* Tables */
.table-pro {
    --bs-table-bg: transparent;
}

.table-pro thead th {
    background: rgba(14, 76, 146, .06);
    color: var(--primary);
    font-weight: 600;
    font-size: .85rem;
    text-transform: uppercase;
    letter-spacing: .5px;
    border: none;
    padding: .875rem 1rem;
}

.table-pro tbody td {
    padding: .875rem 1rem;
    vertical-align: middle;
    border-color: var(--border-color);
}

.table-pro tbody tr:hover {
    background: rgba(14, 76, 146, .04);
}

/* Cost analysis: horizontal scroll with sticky action column */
.cost-items-table-scroll {
    overflow-x: auto;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
}

#costItemsTable {
    min-width: 960px;
    margin-bottom: 0;
}

#costItemsTable thead th.sticky-col-actions,
#costItemsTable tbody td.cell-actions {
    position: sticky;
    right: 0;
    z-index: 2;
    background: var(--card-bg);
    box-shadow: -6px 0 10px -4px rgba(0, 0, 0, .12);
}

#costItemsTable thead th.sticky-col-actions {
    z-index: 3;
    background: rgba(14, 76, 146, .06);
}

#costItemsTable tbody tr:hover td.cell-actions {
    background: rgba(14, 76, 146, .04);
}

#costItemsTable tbody tr.row-editing td.cell-actions {
    background: rgba(255, 193, 7, .08);
}

#costItemsTable_wrapper > .row:last-child,
#costItemsTable_area > .row:last-child {
    margin-top: .75rem;
    padding-top: .75rem;
    border-top: 1px solid var(--border-color);
}

.table-pro .cell-actions {
    white-space: nowrap;
    min-width: 130px;
}

.table-pro .action-group {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    flex-wrap: nowrap;
}

.table-pro .quantity-cell {
    min-width: 110px;
}

.table-pro .qty-display,
.table-pro .profit-display {
    cursor: pointer;
    padding: .25rem .5rem;
    border-radius: 6px;
    display: inline-block;
    min-width: 3rem;
}

.table-pro .qty-display:hover,
.table-pro .profit-display:hover {
    background: rgba(14, 76, 146, .08);
}

.table-pro tr.row-editing {
    background: rgba(255, 193, 7, .08) !important;
}

.table-pro tr.row-editing .qty-input,
.table-pro tr.row-editing .profit-input {
    width: 90px;
    display: inline-block !important;
}

.table-pro .qty-input,
.table-pro .profit-input {
    display: none !important;
}

/* Labor calculation modal */
.labor-calc-box {
    border-radius: 10px;
    padding: 1rem 1.25rem;
    border: 2px solid transparent;
}

.labor-calc-box .label {
    font-size: .8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .4px;
    margin-bottom: .35rem;
}

.labor-calc-box .value {
    font-size: 1.35rem;
    font-weight: 700;
}

.labor-calc-box .formula {
    margin-top: .35rem;
    opacity: .75;
}

.labor-calc-orange {
    background: rgba(255, 152, 0, .12);
    border-color: rgba(255, 152, 0, .35);
    color: #e65100;
}

.labor-calc-yellow {
    background: rgba(255, 235, 59, .18);
    border-color: rgba(255, 193, 7, .45);
    color: #f57f17;
}

/* Forms */
.form-control, .form-select {
    border-radius: 8px;
    border-color: var(--border-color);
    padding: .625rem 1rem;
    background: var(--card-bg);
    color: var(--text-primary);
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(14, 76, 146, .15);
}

.form-label { font-weight: 600; font-size: .875rem; color: var(--text-secondary); }

/* Status Badges */
.badge-status {
    padding: .35rem .75rem;
    border-radius: 50px;
    font-size: .75rem;
    font-weight: 600;
}

.badge-active { background: rgba(39, 174, 96, .15); color: var(--success); }
.badge-pending { background: rgba(243, 156, 18, .15); color: var(--accent); }
.badge-draft { background: rgba(100, 116, 139, .15); color: var(--text-secondary); }
.badge-completed { background: rgba(14, 76, 146, .15); color: var(--primary); }

/* Footer */
.footer-pro {
    background: var(--dark);
    color: #cbd5e1;
    padding: 3rem 0 1.5rem;
    margin-top: 4rem;
}

.footer-pro h5, .footer-pro h6 {
    color: #fff;
    font-weight: 700;
    margin-bottom: 1rem;
}

.footer-links { list-style: none; padding: 0; }
.footer-links li { margin-bottom: .5rem; }
.footer-links a { color: #94a3b8; text-decoration: none; transition: color .2s; }
.footer-links a:hover { color: var(--accent); }

.footer-contact { list-style: none; padding: 0; }
.footer-contact li { margin-bottom: .5rem; color: #94a3b8; }

.social-links a {
    display: inline-flex;
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,.1);
    border-radius: 8px;
    color: #fff;
    margin-right: .5rem;
    transition: all .2s;
}

.social-links a:hover { background: var(--accent); color: #fff; }

.footer-divider { border-color: rgba(255,255,255,.1); margin: 2rem 0 1rem; }

/* Reference Cards */
.ref-card {
    background: var(--card-bg);
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    transition: all .3s;
}

.ref-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.ref-card img {
    width: 100%;
    height: 200px;
    object-fit: cover;
}

.ref-card .ref-body { padding: 1.25rem; }

/* Chart Container */
.chart-container {
    position: relative;
    height: 300px;
}

/* Toast */
.toast-success {
    background: var(--success);
    color: #fff;
    border: none;
    border-radius: 12px;
}

/* About Section */
.about-section {
    padding: 4rem 0;
}

.value-card {
    text-align: center;
    padding: 2rem;
    background: var(--card-bg);
    border-radius: 16px;
    border: 1px solid var(--border-color);
    height: 100%;
}

.value-card i {
    font-size: 2.5rem;
    color: var(--primary);
    margin-bottom: 1rem;
}

/* Contact */
.contact-info-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 2rem;
    border: 1px solid var(--border-color);
    height: 100%;
}

.map-placeholder {
    background: var(--border-color);
    border-radius: 16px;
    height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

/* Cost Summary */
.cost-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
}

.cost-summary-item {
    background: rgba(14, 76, 146, .06);
    border-radius: 12px;
    padding: 1rem;
    text-align: center;
}

.cost-summary-item .label { font-size: .8rem; color: var(--text-secondary); }
.cost-summary-item .value { font-size: 1.25rem; font-weight: 700; color: var(--primary); }

.cost-summary-item.total {
    background: var(--primary);
    color: #fff;
}

.cost-summary-item.total .label,
.cost-summary-item.total .value { color: #fff; }

/* Responsive */
@media (max-width: 991.98px) {
    .container, .container-fluid {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .navbar-pro .navbar-collapse {
        padding-top: .5rem;
    }

    .navbar-pro .dropdown-menu {
        border: none;
        box-shadow: none;
        background: transparent;
        padding-left: .5rem;
    }

    .navbar-pro .dropdown-item {
        padding: .5rem .75rem;
        border-radius: 8px;
    }

    .navbar-actions {
        width: 100%;
        flex-wrap: wrap;
    }

    .page-header {
        padding: 1.5rem 0;
        margin-bottom: 1.25rem;
    }

    .page-header h1 {
        font-size: 1.35rem;
        line-height: 1.3;
    }

    .page-header p {
        font-size: .9rem;
    }

    .page-header .btn {
        width: 100%;
    }

    .content-card {
        padding: 1rem;
        border-radius: 12px;
    }

    .content-card .card-header-custom {
        flex-direction: column;
        align-items: flex-start;
        gap: .5rem;
    }

    .stat-card {
        padding: 1rem;
    }

    .stat-card .stat-value {
        font-size: 1.35rem;
    }

    .chart-container {
        height: 220px;
    }

    .cost-summary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter {
        text-align: left !important;
        margin-bottom: .75rem;
    }

    .dataTables_wrapper .dataTables_filter input {
        width: 100% !important;
        margin-left: 0 !important;
        margin-top: .35rem;
    }

    .dataTables_wrapper .dataTables_paginate {
        margin-top: .75rem;
    }

    .table-pro .btn-sm,
    .btn-sm {
        min-height: 38px;
        min-width: 38px;
        padding: .4rem .55rem;
    }

    /* Card-style tables on mobile (except wide scroll tables) */
    .table-responsive-pro:not(.table-scroll-only) .table-pro thead {
        display: none;
    }

    .table-responsive-pro:not(.table-scroll-only) .table-pro tbody tr {
        display: block;
        margin-bottom: 1rem;
        padding: .75rem;
        border: 1px solid var(--border-color);
        border-radius: 12px;
        background: var(--card-bg);
        box-shadow: var(--shadow);
    }

    .table-responsive-pro:not(.table-scroll-only) .table-pro tbody tr:hover {
        background: var(--card-bg);
    }

    .table-responsive-pro:not(.table-scroll-only) .table-pro tbody td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: .75rem;
        padding: .55rem 0;
        border: none;
        border-bottom: 1px solid var(--border-color);
        text-align: right !important;
    }

    .table-responsive-pro:not(.table-scroll-only) .table-pro tbody td:last-child {
        border-bottom: none;
        justify-content: flex-end;
        flex-wrap: wrap;
    }

    .table-responsive-pro:not(.table-scroll-only) .table-pro tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: .72rem;
        color: var(--text-secondary);
        text-transform: uppercase;
        letter-spacing: .3px;
        text-align: left;
        flex: 1 1 40%;
    }

    .table-responsive-pro:not(.table-scroll-only) .table-pro tbody td[data-label=""]::before,
    .table-responsive-pro:not(.table-scroll-only) .table-pro tbody td:not([data-label])::before {
        content: none;
    }

    /* Breakdown / template line editors */
    .auto-save-line .col-md-1,
    .auto-save-line .col-md-2,
    .auto-save-line .col-md-3,
    .auto-save-line .col-md-4,
    .auto-save-line .col-md-10,
    .auto-save-line .col-md-11 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    .auto-save-line .col-md-1.text-end,
    .auto-save-line .col-md-2.text-end {
        text-align: left !important;
        margin-top: .25rem;
    }

    .auto-save-line .d-flex.gap-1 {
        justify-content: flex-start !important;
    }

    .form-label-mobile {
        display: block;
        font-size: .72rem;
        font-weight: 600;
        color: var(--text-secondary);
        text-transform: uppercase;
        letter-spacing: .3px;
        margin-bottom: .25rem;
    }

    .modal-dialog.modal-lg {
        max-width: calc(100vw - 1rem);
        margin: .5rem auto;
    }

    .toast-container {
        left: .75rem !important;
        right: .75rem !important;
        width: auto;
    }
}

@media (max-width: 575.98px) {
    .hero-title { font-size: 2rem; }
    .hero-section { padding: 3rem 0; }

    .cost-summary-grid {
        grid-template-columns: 1fr;
    }

    #costItemsTable {
        min-width: 720px;
    }

    .table-pro .cell-actions {
        min-width: 110px;
    }

    main .container.pb-5 {
        padding-bottom: 2rem !important;
    }
}

@media (min-width: 992px) {
    .form-label-mobile {
        display: none;
    }
}

/* DataTables dark mode */
[data-theme="dark"] .dataTables_wrapper .dataTables_filter input,
[data-theme="dark"] .dataTables_wrapper .dataTables_length select {
    background: var(--card-bg);
    color: var(--text-primary);
    border-color: var(--border-color);
}

[data-theme="dark"] .page-link {
    background: var(--card-bg);
    color: var(--text-primary);
    border-color: var(--border-color);
}

[data-theme="dark"] .dropdown-menu {
    background: var(--card-bg);
    border-color: var(--border-color);
}

[data-theme="dark"] .dropdown-item {
    color: var(--text-primary);
}

[data-theme="dark"] .dropdown-item:hover {
    background: rgba(14, 76, 146, .15);
}
