/* DataForge — FINIX-Inspired Clean Dashboard Style */

/* ============================================================
   Design System — Custom Properties
   ============================================================ */
:root {
    --bg: #F0F2F8;
    --card-bg: #ffffff;
    --card-radius: 16px;
    --card-shadow: 0 2px 8px rgba(0,0,0,0.04);
    --primary: #1B2B3A;
    --accent: #2EC4B6;
    --accent-light: rgba(46,196,182,0.1);
    --text-primary: #1B2B3A;
    --text-secondary: #8E95A2;
    --text-muted: #B0B7C3;
    --border-color: #E8ECF1;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-pill: 20px;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ============================================================
   Base
   ============================================================ */
body {
    background-color: var(--bg);
    font-family: var(--font-family);
    color: var(--text-primary);
}

h1, h2, h3, h4, h5, h6 {
    color: var(--text-primary);
    font-weight: 600;
}

a { color: var(--accent); }
a:hover { color: #26a89c; }

/* ============================================================
   Top Bar
   ============================================================ */
.app-topbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    display: flex;
    align-items: center;
    padding: 0.75rem 1.5rem;
    gap: 1rem;
}

.topbar-brand {
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--primary);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}
.topbar-brand:hover { color: var(--primary); text-decoration: none; }
.topbar-brand i { color: var(--accent); }

.topbar-nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-left: 1.5rem;
}

.topbar-nav-link {
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-pill);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}
.topbar-nav-link:hover {
    background: var(--accent-light);
    color: var(--accent);
    text-decoration: none;
}
.topbar-nav-link.active {
    background: var(--accent-light);
    color: var(--accent);
}

.topbar-spacer { flex: 1; }

.topbar-search {
    max-width: 280px;
    position: relative;
}
.topbar-search input {
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-pill);
    padding: 0.4rem 1rem 0.4rem 2.25rem;
    background: var(--bg);
    font-size: 0.85rem;
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.15s;
}
.topbar-search input:focus {
    border-color: var(--accent);
}
.topbar-search i {
    position: absolute;
    left: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.8rem;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-left: auto;
}

.topbar-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
    flex-shrink: 0;
}

.topbar-username {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

.topbar-logout {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.3rem 0.65rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}
.topbar-logout:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* Mobile hamburger */
.topbar-toggler {
    display: none;
    background: none;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.35rem 0.55rem;
    font-size: 1rem;
    color: var(--text-secondary);
    cursor: pointer;
}

/* ============================================================
   Layout
   ============================================================ */
.app-content {
    padding: 1.5rem;
    min-height: calc(100vh - 60px);
}

.app-footer {
    text-align: center;
    padding: 1rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border-color);
}

/* Auth layout (unauthenticated) */
.auth-layout {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    width: 100%;
}
.auth-layout > .card {
    width: 100%;
    min-width: 320px;
    max-width: 420px;
}

/* ============================================================
   Cards
   ============================================================ */
.card {
    border: none;
    border-radius: var(--card-radius);
    box-shadow: var(--card-shadow);
    background: var(--card-bg);
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    font-size: 1rem;
    padding: 1rem 1.25rem;
    color: var(--text-primary);
}

.card-body {
    padding: 1.25rem;
}

/* Stat Cards */
.stat-card .card-body {
    padding: 1.25rem;
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--text-primary);
}

.stat-label {
    font-size: 0.825rem;
    color: var(--text-secondary);
}

/* Widget Cards */
.widget-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.widget-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.08);
}

/* ============================================================
   Tables
   ============================================================ */
.table th {
    font-weight: 500;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    border-top: none;
    border-bottom: 1px solid var(--border-color) !important;
    letter-spacing: 0;
    text-transform: none;
}

.table td {
    vertical-align: middle;
    border-bottom: 1px solid var(--border-color);
}

.table > tbody > tr:last-child > td {
    border-bottom: none;
}

.table-hover > tbody > tr:hover {
    background-color: rgba(46,196,182,0.04);
}

/* ============================================================
   Buttons
   ============================================================ */
.btn-primary {
    background-color: var(--primary);
    border-color: var(--primary);
    border-radius: var(--radius-md);
    padding: 0.5rem 1.25rem;
    font-weight: 500;
}
.btn-primary:hover, .btn-primary:focus {
    background-color: #243a4d;
    border-color: #243a4d;
}

.btn-outline-primary {
    color: var(--primary);
    border-color: var(--primary);
    border-radius: var(--radius-md);
}
.btn-outline-primary:hover {
    background-color: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.btn-secondary {
    border-radius: var(--radius-md);
}

.btn-outline-secondary {
    border-radius: var(--radius-md);
}

.btn-success {
    border-radius: var(--radius-md);
}

.btn-danger {
    border-radius: var(--radius-md);
}

.btn-warning {
    border-radius: var(--radius-md);
}

.btn-info {
    border-radius: var(--radius-md);
}

.btn-sm {
    border-radius: var(--radius-sm);
    padding: 0.35rem 0.85rem;
}

/* ============================================================
   Badges
   ============================================================ */
.badge {
    font-weight: 500;
    border-radius: var(--radius-pill);
}

/* ============================================================
   Forms
   ============================================================ */
.form-label {
    font-weight: 500;
    font-size: 0.875rem;
    margin-bottom: 0.35rem;
    color: var(--text-primary);
}

.form-control, .form-select {
    border-radius: var(--radius-sm);
    border-color: var(--border-color);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 0.2rem var(--accent-light);
}

.form-select-filter-sm { width: 140px; }
.form-select-filter-md { min-width: 160px; }
.form-select-filter-lg { width: 200px; }
.form-select-field { max-width: 300px; }

/* ============================================================
   Modals
   ============================================================ */
.modal-content {
    border: none;
    border-radius: var(--radius-lg);
    box-shadow: 0 16px 48px rgba(0,0,0,0.12);
}

.modal-header {
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.25rem;
}

.modal-footer {
    border-top: 1px solid var(--border-color);
    padding: 0.75rem 1.25rem;
}

/* ============================================================
   Dropdowns
   ============================================================ */
.dropdown-menu {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 24px rgba(0,0,0,0.08);
    padding: 0.5rem;
}

.dropdown-item {
    border-radius: var(--radius-sm);
    padding: 0.45rem 0.85rem;
    font-size: 0.875rem;
}

.dropdown-item:hover,
.dropdown-item:focus {
    background: var(--accent-light);
    color: var(--accent);
}

.dropdown-item.active,
.dropdown-item:active {
    background: var(--accent-light);
    color: var(--accent);
}

.dropdown-header {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0.35rem 0.85rem;
}

/* ============================================================
   Flash Messages — Accent Bar Style
   ============================================================ */
.flash-message {
    margin-bottom: 0.5rem;
    border-radius: var(--radius-md);
    border: none;
    border-left: 4px solid;
    box-shadow: var(--card-shadow);
}

.flash-message.alert-success { border-left-color: #22c55e; background: #f0fdf4; color: #166534; }
.flash-message.alert-danger  { border-left-color: #ef4444; background: #fef2f2; color: #991b1b; }
.flash-message.alert-warning { border-left-color: #f59e0b; background: #fffbeb; color: #92400e; }
.flash-message.alert-info    { border-left-color: var(--accent); background: #f0fdfa; color: #134e4a; }

/* ============================================================
   DataTables Overrides
   ============================================================ */
.dataTables_wrapper .dataTables_filter label {
    font-size: 0;
}
.dataTables_wrapper .dataTables_filter input {
    border-radius: var(--radius-pill);
    border: 1px solid var(--border-color);
    padding: 0.4rem 0.85rem 0.4rem 2.25rem;
    font-size: 0.85rem;
    background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' fill='%23B0B7C3' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.242.156a5 5 0 1 1 0-10 5 5 0 0 1 0 10z'/%3E%3C/svg%3E") no-repeat 0.85rem center;
    margin-left: 0 !important;
}
.dataTables_wrapper .dataTables_filter input:focus {
    border-color: var(--accent);
    outline: none;
    box-shadow: 0 0 0 0.15rem var(--accent-light);
}

.dataTables_wrapper .dataTables_length label {
    font-size: 0;
}
.dataTables_wrapper .dataTables_length select {
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    padding: 0.3rem 1.75rem 0.3rem 0.5rem;
    font-size: 0.85rem;
    background-color: var(--bg);
}

.dataTables_wrapper .dataTables_info {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
    border-radius: var(--radius-sm) !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background: var(--primary) !important;
    border-color: var(--primary) !important;
    color: #fff !important;
}

.dataTables_wrapper .row:first-child {
    margin-bottom: 0.75rem;
}
.dataTables_wrapper .row:last-child {
    margin-top: 0.75rem;
}
.dataTables_wrapper .dataTables_paginate .paginate_button {
    padding: 0.3rem 0.65rem !important;
}

/* ============================================================
   Budget Sub-Nav — Pill Bar
   ============================================================ */
.subnav-bar {
    background: var(--card-bg);
    border-radius: var(--card-radius);
    padding: 0.5rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--card-shadow);
    flex-wrap: wrap;
}

.subnav-brand {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--primary);
    text-decoration: none;
    padding-right: 0.75rem;
    border-right: 1px solid var(--border-color);
    margin-right: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
}
.subnav-brand:hover { color: var(--primary); text-decoration: none; }

.subnav-pills {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-wrap: wrap;
}

.subnav-pill {
    padding: 0.35rem 0.85rem;
    border-radius: var(--radius-pill);
    font-size: 0.84rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
    cursor: pointer;
    border: none;
    background: transparent;
}

.subnav-pill:hover {
    background: var(--accent-light);
    color: var(--accent);
    text-decoration: none;
}

.subnav-pill.active {
    background: var(--accent-light);
    color: var(--accent);
}

.subnav-pill .fa-chevron-down {
    font-size: 0.55em;
    vertical-align: 0.1em;
}

/* ============================================================
   Misc
   ============================================================ */

/* Column builder rows */
.column-row,
.schema-col-row {
    background-color: #fafbfc;
    border-radius: var(--radius-sm);
}

/* Auth pages */
.auth-card {
    max-width: 420px;
}

/* Truncated text in tables */
.text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Mapping rows */
.mapping-select {
    min-width: 180px;
}

/* Button spacing in action columns */
td .btn + .btn,
td .btn + form,
td form + .btn,
td form + form {
    margin-left: 0.35rem;
}

td form {
    display: inline;
}

/* Preview table */
#previewTable {
    font-size: 0.85rem;
}

#previewTable th {
    background-color: var(--bg);
}

/* Footer */
footer {
    font-size: 0.8rem;
}

/* Nav pills / tabs in pages (Bootstrap tabs) */
.nav-pills .nav-link {
    border-radius: var(--radius-pill);
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.875rem;
}

.nav-pills .nav-link.active {
    background: var(--primary);
    color: #fff;
}

.nav-tabs .nav-link {
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    color: var(--text-secondary);
    font-weight: 500;
}

.nav-tabs .nav-link.active {
    color: var(--primary);
    border-color: var(--border-color) var(--border-color) #fff;
}

/* Page headers */
.page-header {
    margin-bottom: 1.5rem;
}

/* Pagination */
.page-link {
    border-radius: var(--radius-sm);
    color: var(--primary);
}

.page-item.active .page-link {
    background-color: var(--primary);
    border-color: var(--primary);
}

/* ============================================================
   Responsive — Mobile
   ============================================================ */
@media (max-width: 767.98px) {
    .topbar-search { display: none; }
    .topbar-username { display: none; }
    .topbar-toggler { display: inline-flex; }

    .topbar-nav {
        display: none;
        flex-direction: column;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: #fff;
        padding: 0.75rem 1rem;
        box-shadow: 0 4px 12px rgba(0,0,0,0.06);
        gap: 0.25rem;
        z-index: 1029;
    }
    .topbar-nav.show { display: flex; }

    .topbar-right {
        display: none;
        flex-direction: column;
        align-items: flex-start;
        padding: 0.5rem 0;
        gap: 0.5rem;
    }
    .topbar-nav.show + .topbar-spacer + .topbar-right,
    .topbar-right.show { display: flex; }

    .app-content { padding: 1rem; }

    .subnav-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    .subnav-brand {
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        padding-bottom: 0.5rem;
        margin-right: 0;
        width: 100%;
    }
}

/* ============================================================
   Portal — Mobile-Optimized Styles
   ============================================================ */

/* Touch-friendly tap targets */
.portal-btn {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Offline indicator banner */
.offline-banner {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    background: var(--primary);
    color: #fff;
    text-align: center;
    padding: 0.5rem;
    font-size: 0.85rem;
    font-weight: 500;
}
.offline-banner.show {
    display: block;
}

/* Portal bottom nav for mobile */
.portal-bottom-nav {
    display: none;
}

@media (max-width: 767.98px) {
    .portal-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--card-bg);
        border-top: 1px solid var(--border-color);
        box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
        z-index: 1040;
        padding: 0.25rem 0;
    }
    .portal-bottom-nav a {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 0.5rem 0.25rem;
        color: var(--text-secondary);
        text-decoration: none;
        font-size: 0.7rem;
        min-height: 52px;
        transition: color 0.15s;
    }
    .portal-bottom-nav a.active,
    .portal-bottom-nav a:hover {
        color: var(--accent);
    }
    .portal-bottom-nav a i {
        font-size: 1.2rem;
        margin-bottom: 0.15rem;
    }
    /* Add bottom padding so content isn't hidden behind bottom nav */
    body.portal-page .app-content {
        padding-bottom: 70px;
    }
    body.portal-page .app-footer {
        display: none;
    }
}

/* ============================================================
   Auto-Expanding Textareas
   ============================================================ */
textarea.auto-expand {
    overflow: hidden;
    resize: vertical;
    min-height: 3em;
}
