/**
 * Bonsai Reborn - Modern Botanical Emerald Design System & PWA UI
 */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

:root {
    --br-primary: #0f5132;
    --br-primary-dark: #07291a;
    --br-primary-light: #10b981;
    --br-accent: #d97706;
    --br-bg: #f1f5f4;
    --br-surface: #ffffff;
    --br-surface-alt: #f8faf9;
    --br-border: #e2e8f0;
    --br-text: #0f172a;
    --br-text-muted: #64748b;
    --br-radius-lg: 16px;
    --br-radius-md: 12px;
    --br-radius-sm: 8px;
    --br-shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.05);
    --br-shadow-md: 0 10px 25px -5px rgba(15, 23, 42, 0.08), 0 4px 10px -3px rgba(15, 23, 42, 0.04);
    --br-shadow-lg: 0 20px 35px -10px rgba(15, 81, 50, 0.16);
}

[data-theme="dark"],
body.bonsai-dark {
    --br-bg: #0b1512;
    --br-surface: #12211c;
    --br-surface-alt: #182b24;
    --br-border: #233b32;
    --br-text: #f1f5f9;
    --br-text-muted: #94a3b8;
    --br-shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.35);
    --br-shadow-md: 0 12px 28px rgba(0, 0, 0, 0.45);
}

body {
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
    background-color: var(--br-bg) !important;
    color: var(--br-text) !important;
    letter-spacing: -0.01em;
}

#content-wrapper {
    background-color: var(--br-bg) !important;
}

/* =========================================================================
   1. MODERN SIDEBAR (Botanical Emerald Gradient)
   ========================================================================= */
.sidebar.bg-gradient-dark,
.modern-sidebar {
    background: linear-gradient(180deg, #072719 0%, #0d3d28 55%, #062115 100%) !important;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.12);
    border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar .sidebar-brand {
    height: 4.75rem !important;
    padding: 0 1.25rem !important;
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    text-transform: none !important;
}

.sidebar .sidebar-brand-icon img {
    width: 44px !important;
    height: 44px !important;
    object-fit: contain;
    filter: drop-shadow(0 4px 8px rgba(16, 185, 129, 0.35));
    transition: transform 0.3s ease;
}

.sidebar .sidebar-brand:hover .sidebar-brand-icon img {
    transform: scale(1.08) rotate(5deg);
}

.sidebar .sidebar-brand-text {
    font-weight: 800 !important;
    font-size: 1.05rem !important;
    letter-spacing: 0.02em;
    color: #ffffff;
    line-height: 1.15;
}

.sidebar .sidebar-brand-sub {
    display: block;
    font-size: 0.65rem;
    font-weight: 600;
    color: #34d399;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.sidebar hr.sidebar-divider {
    border-top: 1px solid rgba(255, 255, 255, 0.08) !important;
    margin: 0.5rem 1rem !important;
}

.sidebar .nav-item .nav-link {
    margin: 3px 10px;
    padding: 0.72rem 0.95rem !important;
    border-radius: 11px;
    font-weight: 600;
    font-size: 0.86rem;
    color: rgba(255, 255, 255, 0.82) !important;
    transition: all 0.2s ease;
    width: auto !important;
}

.sidebar .nav-item .nav-link i {
    color: #34d399 !important;
    font-size: 0.95rem;
    margin-right: 0.65rem;
    transition: transform 0.2s ease;
}

.sidebar .nav-item .nav-link:hover,
.sidebar .nav-item.active > .nav-link,
.sidebar .nav-item .nav-link[aria-expanded="true"] {
    background: rgba(16, 185, 129, 0.16) !important;
    color: #ffffff !important;
    box-shadow: inset 0 0 0 1px rgba(52, 211, 153, 0.28);
}

.sidebar .nav-item .collapse .collapse-inner {
    background: rgba(6, 28, 18, 0.72) !important;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px !important;
    margin: 4px 10px 8px 10px !important;
    padding: 0.45rem !important;
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.2);
}

.sidebar .nav-item .collapse .collapse-inner .collapse-item {
    color: rgba(255, 255, 255, 0.76) !important;
    border-radius: 8px !important;
    padding: 0.52rem 0.85rem !important;
    font-size: 0.82rem;
    font-weight: 500;
    margin-bottom: 2px;
    transition: all 0.18s ease;
    white-space: normal;
}

.sidebar .nav-item .collapse .collapse-inner .collapse-item:hover,
.sidebar .nav-item .collapse .collapse-inner .collapse-item.active {
    background: linear-gradient(135deg, #10b981, #059669) !important;
    color: #ffffff !important;
    font-weight: 600;
    transform: translateX(3px);
}

/* =========================================================================
   2. MODERN GLASSMORPHIC TOPBAR & PWA STATUS PILLS
   ========================================================================= */
.topbar.modern-topbar {
    background: rgba(255, 255, 255, 0.86) !important;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--br-border);
    box-shadow: var(--br-shadow-sm) !important;
    height: 4.35rem !important;
    position: sticky;
    top: 0;
    z-index: 1020;
}

body.bonsai-dark .topbar.modern-topbar {
    background: rgba(18, 33, 28, 0.88) !important;
    border-bottom-color: var(--br-border);
}

.topbar-page-context {
    display: flex;
    align-items: center;
    gap: 10px;
}

.topbar-event-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: rgba(16, 185, 129, 0.12);
    color: #0f5132;
    border: 1px solid rgba(16, 185, 129, 0.25);
    padding: 5px 13px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
}

body.bonsai-dark .topbar-event-pill {
    color: #34d399;
    background: rgba(16, 185, 129, 0.15);
}

.pwa-net-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 5px 12px;
    border-radius: 999px;
    transition: all 0.25s ease;
}

.pwa-net-status .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.pwa-net-status.is-online {
    background: rgba(16, 185, 129, 0.12);
    color: #059669;
    border: 1px solid rgba(16, 185, 129, 0.28);
}

.pwa-net-status.is-online .status-dot {
    background: #10b981;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.22);
}

.pwa-net-status.is-offline {
    background: rgba(239, 68, 68, 0.14);
    color: #dc2626;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.pwa-net-status.is-offline .status-dot {
    background: #ef4444;
}

.btn-pwa-topbar {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: linear-gradient(135deg, #0f5132, #10b981);
    color: #ffffff !important;
    border: none;
    border-radius: 999px;
    padding: 6px 14px;
    font-size: 0.78rem;
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.28);
    transition: all 0.2s ease;
    cursor: pointer;
}

.btn-pwa-topbar:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(16, 185, 129, 0.4);
}

.btn-theme-toggle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--br-border);
    background: var(--br-surface-alt);
    color: var(--br-text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-theme-toggle:hover {
    background: rgba(16, 185, 129, 0.15);
    border-color: #10b981;
}

/* =========================================================================
   3. MODERN CARDS, HEADINGS, & KPI WIDGETS
   ========================================================================= */
.title-3d,
h1.h3.text-gray-800,
h1.h4.text-gray-800 {
    font-size: 1.45rem !important;
    font-weight: 800 !important;
    color: var(--br-text) !important;
    text-shadow: none !important;
    letter-spacing: -0.02em;
}

.card {
    background-color: var(--br-surface) !important;
    border: 1px solid var(--br-border) !important;
    border-radius: var(--br-radius-lg) !important;
    box-shadow: var(--br-shadow-sm) !important;
    transition: transform 0.22s ease, box-shadow 0.22s ease;
    overflow: hidden;
}

.card-header {
    background: var(--br-surface) !important;
    border-bottom: 1px solid var(--br-border) !important;
    padding: 1rem 1.35rem !important;
}

.card-3d {
    background: linear-gradient(145deg, var(--br-surface) 0%, var(--br-surface-alt) 100%) !important;
    border-radius: var(--br-radius-lg) !important;
    box-shadow: var(--br-shadow-md) !important;
}

.card-3d::before {
    display: none !important;
}

.card-3d:hover {
    transform: translateY(-5px) !important;
    box-shadow: var(--br-shadow-lg) !important;
}

.border-left-primary { border-left: 4px solid #2563eb !important; }
.border-left-success { border-left: 4px solid #10b981 !important; }
.border-left-info    { border-left: 4px solid #06b6d4 !important; }
.border-left-warning { border-left: 4px solid #f59e0b !important; }
.border-left-danger  { border-left: 4px solid #ef4444 !important; }
.border-left-dark    { border-left: 4px solid #334155 !important; }

body.bonsai-dark .text-gray-800,
body.bonsai-dark .text-gray-900,
body.bonsai-dark .text-dark {
    color: #f1f5f9 !important;
}

body.bonsai-dark .text-gray-600 {
    color: #cbd5e1 !important;
}

/* =========================================================================
   4. MODERN DATATABLES & TABLES
   ========================================================================= */
.table {
    color: var(--br-text) !important;
    border-collapse: separate;
    border-spacing: 0;
}

.table thead th,
#dataTab thead th {
    background: linear-gradient(135deg, #0b2e1e, #134e35) !important;
    color: #ffffff !important;
    font-weight: 700 !important;
    font-size: 0.78rem !important;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-color: rgba(255, 255, 255, 0.12) !important;
    padding: 0.85rem 0.75rem !important;
    vertical-align: middle !important;
}

.table tbody td {
    padding: 0.75rem !important;
    vertical-align: middle !important;
    font-size: 0.87rem;
    border-color: var(--br-border) !important;
}

.table-striped tbody tr:nth-of-type(odd) {
    background-color: var(--br-surface-alt) !important;
}

.table tbody tr:hover {
    background-color: rgba(16, 185, 129, 0.07) !important;
}

/* =========================================================================
   5. MODERN BUTTONS, BADGES, FORMS & MODALS
   ========================================================================= */
.btn {
    border-radius: 10px !important;
    font-weight: 600 !important;
    padding: 0.45rem 0.95rem;
    transition: all 0.18s ease !important;
}

.btn-sm {
    padding: 0.35rem 0.75rem !important;
    font-size: 0.82rem !important;
    border-radius: 8px !important;
}

.btn-primary {
    background: linear-gradient(135deg, #0f5132, #059669) !important;
    border-color: #059669 !important;
    box-shadow: 0 4px 12px rgba(5, 150, 105, 0.22);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(5, 150, 105, 0.35);
}

.badge-pill {
    padding: 0.42em 0.75em !important;
    font-weight: 600 !important;
    border-radius: 8px !important;
}

.form-control {
    border-radius: 10px !important;
    border: 1px solid var(--br-border) !important;
    background-color: var(--br-surface) !important;
    color: var(--br-text) !important;
    font-size: 0.9rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-control:focus {
    border-color: #10b981 !important;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.18) !important;
}

.modal-content {
    background-color: var(--br-surface) !important;
    color: var(--br-text) !important;
    border: 1px solid var(--br-border) !important;
    border-radius: 18px !important;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.3) !important;
    overflow: hidden;
}

.modal-header {
    background: linear-gradient(135deg, #0b2e1e, #134e35);
    color: #ffffff !important;
    border-bottom: none !important;
    padding: 1.1rem 1.4rem !important;
}

.modal-header .modal-title {
    font-weight: 700;
    color: #ffffff !important;
}

.modal-header .close {
    color: #ffffff !important;
    opacity: 0.85;
    text-shadow: none;
}

.sticky-footer {
    background-color: var(--br-surface) !important;
    border-top: 1px solid var(--br-border);
    padding: 1.1rem 0 !important;
}


/* =========================================================================
   6. MOBILE-FIRST RESPONSIVE DRAWER, BOTTOM NAV & TOUCH UX (< 768px)
   ========================================================================= */
.mobile-sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(4, 22, 14, 0.62);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 2040;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.mobile-sidebar-backdrop.show {
    display: block;
    opacity: 1;
}

.mobile-bottom-nav {
    display: none;
}

@media (max-width: 767.98px) {
    /* Give main content 100% width and space for bottom nav */
    #content-wrapper {
        width: 100% !important;
        min-height: 100vh;
        padding-bottom: 68px !important;
    }

    .container-fluid {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }

    /* Transform Sidebar into Smooth Off-Canvas Drawer on Mobile */
    .sidebar.modern-sidebar {
        position: fixed !important;
        top: 0;
        left: 0;
        bottom: 0;
        width: 268px !important;
        height: 100vh !important;
        z-index: 2050 !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        transform: translateX(0);
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1) !important;
    }

    /* When toggled (closed on mobile), hide off-screen to the left */
    .sidebar.modern-sidebar.toggled {
        width: 268px !important;
        overflow: hidden !important;
        transform: translateX(-105%) !important;
    }

    /* Keep full text and inline collapse inside mobile drawer */
    .sidebar.modern-sidebar .sidebar-brand-text {
        display: block !important;
    }

    .sidebar.modern-sidebar .nav-item .nav-link {
        text-align: left !important;
        padding: 0.75rem 1rem !important;
        width: auto !important;
        display: flex !important;
        align-items: center !important;
    }

    .sidebar.modern-sidebar .nav-item .nav-link span {
        font-size: 0.88rem !important;
        display: inline !important;
    }

    .sidebar.modern-sidebar .nav-item .nav-link i {
        font-size: 1rem !important;
        margin-right: 0.75rem !important;
        margin-bottom: 0 !important;
    }

    .sidebar.modern-sidebar .nav-item .collapse {
        position: static !important;
        left: auto !important;
        top: auto !important;
        z-index: 1 !important;
        animation: none !important;
    }

    .sidebar.modern-sidebar .nav-item .collapse .collapse-inner {
        width: auto !important;
        box-shadow: none !important;
    }

    /* Compact Topbar on Mobile */
    .topbar.modern-topbar {
        height: 3.75rem !important;
        padding: 0 0.65rem !important;
        margin-bottom: 0.85rem !important;
    }

    /* Responsive Card Headers & Action Toolbars */
    .card-header {
        padding: 0.85rem 1rem !important;
        gap: 10px;
    }

    .card-body {
        padding: 0.9rem !important;
    }

    .title-3d,
    h1.h3.text-gray-800,
    h1.h4.text-gray-800 {
        font-size: 1.15rem !important;
    }

    /* Touch-friendly Action Buttons in Tables */
    .action-buttons {
        gap: 6px !important;
        flex-wrap: nowrap;
    }

    .action-buttons .badge-pill {
        min-width: 32px;
        min-height: 32px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 0.85rem;
    }

    /* Responsive DataTables wrapper & controls */
    div.dataTables_wrapper div.dataTables_length,
    div.dataTables_wrapper div.dataTables_filter,
    div.dataTables_wrapper div.dataTables_info,
    div.dataTables_wrapper div.dataTables_paginate {
        text-align: left !important;
        margin-bottom: 0.5rem;
    }

    div.dataTables_wrapper div.dataTables_filter input {
        width: 100% !important;
        margin-left: 0 !important;
        margin-top: 4px;
    }

    .table-responsive,
    .card-body > div[style*="overflow-y"] {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    /* Prevent iOS auto-zoom on form inputs and make modals mobile-friendly */
    .form-control,
    select.form-control {
        font-size: 16px !important;
        min-height: 44px;
    }

    .modal-dialog {
        margin: 0.5rem !important;
    }

    .modal-body {
        padding: 1rem !important;
    }

    /* Fixed Mobile Bottom Navigation Bar */
    .mobile-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 62px;
        background: rgba(7, 39, 25, 0.96);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        border-top: 1px solid rgba(52, 211, 153, 0.22);
        box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.25);
        z-index: 1035;
        justify-content: space-around;
        align-items: center;
        padding: 0 4px env(safe-area-inset-bottom, 0px) 4px;
    }

    .mobile-bottom-nav .mob-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        color: rgba(255, 255, 255, 0.68);
        text-decoration: none !important;
        font-size: 0.68rem;
        font-weight: 600;
        padding: 6px 2px;
        border-radius: 10px;
        transition: all 0.18s ease;
        background: transparent;
        border: none;
    }

    .mobile-bottom-nav .mob-nav-item i {
        font-size: 1.1rem;
        margin-bottom: 3px;
        color: rgba(52, 211, 153, 0.85);
    }

    .mobile-bottom-nav .mob-nav-item.active,
    .mobile-bottom-nav .mob-nav-item:active {
        color: #ffffff;
        background: rgba(16, 185, 129, 0.18);
    }

    .mobile-bottom-nav .mob-nav-item.active i {
        color: #34d399;
        transform: translateY(-1px);
    }

    .scroll-to-top {
        bottom: 74px !important;
        right: 12px !important;
    }
}

/* =========================================================================
   7. BROWSER PRINT MEDIA OPTIMIZATION (@media print)
   ========================================================================= */
@media print {
    .sidebar,
    .topbar,
    .sticky-footer,
    .mobile-bottom-nav,
    .mobile-sidebar-backdrop,
    .scroll-to-top,
    .btn,
    .action-buttons,
    .dataTables_filter,
    .dataTables_length,
    .dataTables_paginate {
        display: none !important;
    }

    #content-wrapper,
    .container-fluid,
    .card,
    .card-body {
        background: #ffffff !important;
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        margin: 0 !important;
    }
}
