:root {
    --primary: #1a237e;
    --secondary: #ff6f00;
    --accent: #c62828;
    --bg-dark: #0f1117;
    --bg-card: #1a1d2e;
    --bg-card-hover: #232740;
    --text-primary: #ffffff;
    --text-secondary: #b0b8e0;
    --text-muted-contrast: #94a3b8;
    --border-subtle: rgba(255, 255, 255, 0.12);
    --input-bg: rgba(255, 255, 255, 0.1);
    --input-border: rgba(255, 255, 255, 0.2);
    --gradient-primary: linear-gradient(135deg, #1a237e 0%, #283593 100%);
    --gradient-accent: linear-gradient(135deg, #ff6f00 0%, #ff8f00 100%);
    --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.3);
    --skeleton: rgba(255, 255, 255, 0.05);
}

* {
    box-sizing: border-box;
}

html,
body {
    overflow-x: hidden;
    width: 100%;
    position: relative;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100%;
    margin: 0;
    touch-action: manipulation;
}

/* ── Sidebar ── */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 260px;
    height: 100vh;
    background: linear-gradient(180deg, #111327 0%, #0f1117 100%);
    border-right: 1px solid var(--border-subtle);
    padding: 0.5rem 0;
    z-index: 100;
    overflow-y: auto;
    transition: transform 0.3s ease;
}

.sidebar .brand {
    padding: 0.5rem 1.5rem 0.75rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sidebar .brand i {
    color: var(--secondary);
    font-size: 1.4rem;
}

.sidebar .nav-section {
    padding: 0.75rem 1rem 0.25rem;
    font-size: 0.8rem;
    font-weight: 750;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: rgba(255, 255, 255, 0.45);
}

.sidebar a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.38rem 1.5rem 0.38rem 1.75rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.2s;
    border-radius: 0;
}

.sidebar a:hover,
.sidebar a.active {
    color: #fff;
    background: rgba(255, 255, 255, 0.06);
}

.sidebar a.active {
    border-left: 3px solid var(--secondary);
    padding-left: calc(1.75rem - 3px);
}

.sidebar a i {
    font-size: 1.1rem;
    width: 20px;
    text-align: center;
}

/* ── Glassmorphism & High-end Sidebar ── */
@media (min-width: 769px) {
    .sidebar {
        background: linear-gradient(180deg, rgba(17, 19, 39, 0.95) 0%, rgba(15, 17, 23, 0.98) 100%);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
    }
}

.sidebar-user {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-subtle);
    background: rgba(0, 0, 0, 0.2);
}

.sidebar-user .name {
    font-size: 0.85rem;
    font-weight: 600;
}

.sidebar-user .role {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

/* ── Main content ── */
.main {
    margin-left: 260px;
    padding: 2rem;
    min-height: 100%;
    overflow-x: hidden;
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* ── Cards ── */
.card-dark {
    background: var(--bg-card) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow-card);
    transition: transform 0.2s, box-shadow 0.2s;
}

@media (min-width: 769px) {
    .card-dark:hover {
        transform: translateY(-2px);
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    }
}

.stat-card {
    text-align: center;
    padding: 1.25rem;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    background: var(--gradient-accent);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.stat-card .stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* ── Buttons ── */
.btn-primary-glow {
    background: var(--gradient-primary);
    color: #fff;
    border: none;
    padding: 0.6rem 1.5rem;
    border-radius: 8px;
    font-weight: 600;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary-glow:hover {
    box-shadow: 0 4px 20px rgba(26, 35, 126, 0.5);
    color: #fff;
}

@media (min-width: 769px) {
    .btn-primary-glow:hover {
        transform: translateY(-1px);
    }
}

.btn-accent {
    background: var(--gradient-accent);
    color: #fff;
    border: none;
    padding: 0.6rem 1.5rem;
    border-radius: 8px;
    font-weight: 600;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-accent:hover {
    box-shadow: 0 4px 20px rgba(255, 111, 0, 0.4);
    color: #fff;
}

@media (min-width: 769px) {
    .btn-accent:hover {
        transform: translateY(-1px);
    }
}

/* ── Forms ── */
.form-control,
.form-select {
    background: var(--input-bg) !important;
    border: 1px solid var(--input-border) !important;
    color: #fff !important;
    border-radius: 8px;
}

.form-select option {
    background-color: #1a1d2e; /* Solid background matching var(--bg-card) */
    color: #e8eaf6;            /* Light text matching var(--text-primary) */
}

.form-control:focus,
.form-select:focus {
    background: rgba(255, 255, 255, 0.12);
    border-color: var(--secondary);
    color: var(--text-primary);
    box-shadow: 0 0 0 0.2rem rgba(255, 111, 0, 0.15);
}

.form-label {
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
}

/* ── Tables ── */
.table-dark-custom {
    color: var(--text-primary) !important;
    --bs-table-bg: transparent !important;
    --bs-table-color: var(--text-primary) !important;
    --bs-table-striped-bg: rgba(255, 255, 255, 0.02) !important;
    background-color: transparent !important;
}

.table-dark-custom th {
    color: var(--text-secondary) !important;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border-subtle);
    padding: 0.75rem;
}

.table-dark-custom td {
    border-bottom: 1px solid var(--border-subtle);
    padding: 0.75rem;
    vertical-align: middle;
    color: var(--text-primary) !important;
}

.table-dark-custom tr:hover td {
    background: rgba(255, 255, 255, 0.03);
}

.bg-dark-audit {
    background: #232740 !important; /* Explicitly darker hex just in case */
    border: 1px solid var(--border-subtle);
}

.text-white-80 {
    color: rgba(255, 255, 255, 0.9) !important;
}

.text-white-50 {
    color: rgba(255, 255, 255, 0.7) !important;
}

.text-muted {
    color: var(--text-muted-contrast) !important;
}

/* ── Badges ── */
.badge-success {
    background: rgba(76, 175, 80, 0.15);
    color: #81c784;
}

.badge-warning {
    background: rgba(255, 152, 0, 0.15);
    color: #ffb74d;
}

.badge-danger {
    background: rgba(244, 67, 54, 0.15);
    color: #ef5350;
}

.badge-info {
    background: rgba(33, 150, 243, 0.15);
    color: #64b5f6;
}

/* ── Page header ── */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
}

/* ── Alerts ── */
.alert {
    border-radius: 8px;
    border: none;
}

/* ── Premium Aesthetics & Animations ── */
.skeleton {
    background: linear-gradient(90deg, var(--skeleton) 25%, rgba(255, 255, 255, 0.08) 50%, var(--skeleton) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
    display: inline-block;
    min-height: 1em;
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

/* Tap feedback */
@media (max-width: 768px) {

    .card-dark,
    .btn-primary-glow,
    .btn-accent,
    .sidebar a {
        -webkit-tap-highlight-color: transparent;
    }

    .card-dark:active,
    .btn-primary-glow:active,
    .btn-accent:active {
        transform: none !important;
        transition: none !important;
    }
}

/* Smooth page transitions for HTMX */
.htmx-settling {
    opacity: 0;
}

.htmx-request {
    filter: grayscale(100%) opacity(0.8);
    transition: all 0.3s ease;
}

/* ── Bottom Navigation Submenu ── */
.mobile-submenu {
    position: fixed;
    bottom: 85px;
    left: 50%;
    transform: translateX(-50%) translateY(15px);
    background: rgba(30, 34, 55, 0.98);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 20px;
    padding: 0.6rem;
    z-index: 1040;
    display: flex; /* Always flex but controlled by visibility/opacity */
    visibility: hidden;
    flex-direction: column;
    min-width: 220px;
    box-shadow: 0 15px 45px rgba(0, 0, 0, 0.7);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); /* Elastic feel */
    opacity: 0;
}

.mobile-submenu.show {
    visibility: visible;
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.mobile-submenu a {
    padding: 0.75rem 1rem;
    color: var(--text-primary);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.9rem;
    border-radius: 10px;
}

.mobile-submenu a:active {
    background: rgba(255, 255, 255, 0.08);
}

.mobile-submenu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1000;
    display: none;
    backdrop-filter: blur(4px);
}

.mobile-submenu-overlay.show {
    display: block;
}

/* ── Mobile ── */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 200;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    color: #fff;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    cursor: pointer;
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        background: rgba(15, 17, 23, 0.98);
        backdrop-filter: blur(15px);
        -webkit-backdrop-filter: blur(15px);
        width: 280px;
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .main {
        margin-left: 0;
        padding: 1rem;
        padding-top: calc(60px + 1rem); /* Header height + 1rem base padding */
        padding-bottom: 5rem;
        /* Space for bottom nav */
    }

    .sidebar-toggle {
        display: block;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .page-header .btn-primary-glow,
    .page-header .btn-accent {
        width: 100%;
        justify-content: center;
    }
}

/* ── Bottom Navigation ── */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 65px;
    background: rgba(26, 29, 46, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    z-index: 1030;
    justify-content: space-around;
    align-items: stretch; /* Stretch to allow top border to align perfectly */
    padding-bottom: env(safe-area-inset-bottom);
}

.mobile-bottom-nav a {
    color: var(--text-secondary);
    text-decoration: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center; /* Center content vertically */
    font-size: 0.72rem;
    gap: 2px;
    flex: 1; /* Equal width */
    transition: all 0.2s;
    border-top: 3px solid transparent; /* Placeholder for active state */
}

.mobile-bottom-nav a.active {
    color: var(--secondary);
    background: rgba(255, 111, 0, 0.03);
    border-top-color: var(--secondary);
}

.mobile-bottom-nav a i {
    font-size: 1.4rem;
}

@media (max-width: 768px) {
    .mobile-bottom-nav {
        display: flex !important;
        bottom: 0 !important;
    }
}

/* ── Floating Action Button (FAB) ── */
.fab {
    position: fixed;
    bottom: 95px; /* Shifted up slightly to clear nav area */
    right: 24px;
    width: 56px;
    height: 56px;
    background: var(--gradient-accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    box-shadow: 0 4px 15px rgba(255, 111, 0, 0.4);
    z-index: 999;
    transition: transform 0.2s;
    text-decoration: none;
}

.fab:active {
    transform: scale(0.9);
}

@media (min-width: 769px) {
    .fab {
        display: none;
    }
}

/* ── Customer Portal Floating Action Bar ── */
.floating-bar {
    position: fixed;
    bottom: 100px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 1000;
}

.floating-bar-btn {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    text-decoration: none;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    font-size: 1.3rem;
    position: relative;
}

.floating-bar-btn:hover {
    color: #fff;
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
}

.floating-bar-btn:active {
    transform: scale(0.93);
}

.floating-bar-btn--horoscope {
    background: var(--gradient-accent);
    box-shadow: 0 4px 14px rgba(255, 111, 0, 0.45);
}

.floating-bar-btn--horoscope:hover {
    box-shadow: 0 6px 22px rgba(255, 111, 0, 0.6);
}

.floating-bar-btn--whatsapp {
    background: #25D366;
    box-shadow: 0 4px 14px rgba(37, 211, 102, 0.45);
}

.floating-bar-btn--whatsapp:hover {
    box-shadow: 0 6px 22px rgba(37, 211, 102, 0.6);
}

.floating-bar-btn--call {
    background: #0ea5e9;
    box-shadow: 0 4px 14px rgba(14, 165, 233, 0.45);
}

.floating-bar-btn--call:hover {
    box-shadow: 0 6px 22px rgba(14, 165, 233, 0.6);
}

/* Tooltip label shown on hover */
.floating-bar-btn .fab-tooltip {
    position: absolute;
    right: 62px;
    white-space: nowrap;
    background: rgba(15, 23, 42, 0.92);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 5px 10px;
    border-radius: 6px;
    pointer-events: none;
    opacity: 0;
    transform: translateX(6px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    border: 1px solid rgba(255,255,255,0.08);
    backdrop-filter: blur(8px);
}

.floating-bar-btn:hover .fab-tooltip {
    opacity: 1;
    transform: translateX(0);
}

/* Desktop: shift left of sidebar edge */
@media (min-width: 769px) {
    .floating-bar {
        bottom: 32px;
        right: 28px;
    }
}

/* Mobile: sit above the bottom nav bar */
@media (max-width: 768px) {
    .floating-bar {
        bottom: 75px;
        right: 16px;
        gap: 10px;
    }

    .floating-bar-btn {
        width: 46px;
        height: 46px;
        font-size: 1.15rem;
    }
}

/* ── Mobile Header ── */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--bg-dark);
    border-bottom: 1px solid var(--border-subtle);
    z-index: 99;
    align-items: center;
    padding: 0 1rem;
    justify-content: space-between;
    transform: translateZ(0);
    backface-visibility: hidden;
}

@media (max-width: 768px) {
    .mobile-header {
        display: flex;
    }

    .sidebar-toggle {
        position: static;
    }
}

/* ── Toast Notifications ── */
.toast-container {
    position: fixed;
    bottom: 100px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.custom-toast {
    background: rgba(30, 34, 55, 0.95);
    backdrop-filter: blur(10px);
    color: #fff;
    padding: 12px 24px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    gap: 12px;
    animation: toast-in 0.3s ease forwards;
    min-width: 280px;
    pointer-events: auto !important;
}

.custom-toast.success i {
    color: #4caf50;
}

.custom-toast.error i {
    color: #f44336;
}

.custom-toast.info i {
    color: #2196f3;
}

@keyframes toast-in {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes toast-out {
    from {
        transform: translateX(0);
        opacity: 1;
    }

    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* ── Credit Visualization Gauges & Battery ── */
.astro-gauge-wrapper {
    position: relative;
    width: 140px;
    height: 140px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.astro-gauge-base {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 8px solid rgba(255, 255, 255, 0.05);
}

.astro-gauge {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: conic-gradient(var(--gauge-color) calc(var(--percentage) * 1%), transparent 0);
    -webkit-mask: radial-gradient(farthest-side, transparent 80%, black 81%);
    mask: radial-gradient(farthest-side, transparent 80%, black 81%);
    transition: background 0.5s ease;
}

.astro-gauge-content {
    text-align: center;
    z-index: 1;
}

.astro-gauge-value {
    font-size: 1.8rem;
    font-weight: 800;
    line-height: 1;
    color: #fff;
}

.astro-gauge-label {
    font-size: 0.65rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 2px;
}

/* Battery Bar Styles */
.battery-bar,
.battery-container {
    width: 100%;
    height: 32px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    position: relative;
    padding: 3px;
    display: flex;
    align-items: center;
}

.battery-container::after {
    content: "";
    position: absolute;
    right: -6px;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 12px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 0 3px 3px 0;
}

.battery-fill {
    height: 100%;
    background: var(--gauge-color);
    border-radius: 3px;
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 0 10px var(--gauge-glow);
}

/* Color Variables for States */
.state-green {
    --gauge-color: #00e676;
    --gauge-glow: rgba(0, 230, 118, 0.3);
}

.state-yellow {
    --gauge-color: #ffeb3b;
    --gauge-glow: rgba(255, 235, 59, 0.3);
}

.state-orange {
    --gauge-color: #ff9800;
    --gauge-glow: rgba(255, 152, 0, 0.3);
}

.state-red {
    --gauge-color: #f44336;
    --gauge-glow: rgba(244, 67, 54, 0.4);
    animation: pulse-red 2s infinite;
}

@keyframes pulse-red {
    0% { opacity: 1; }
    50% { opacity: 0.6; }
    100% { opacity: 1; }
}
/* ── Locked / Restricted Components ── */
.locked-engine-pattern {
    background: rgba(255, 255, 255, 0.03) !important;
    border: 1px dashed rgba(255, 255, 255, 0.2) !important;
    color: var(--text-muted-contrast) !important;
    cursor: not-allowed;
    transition: all 0.2s ease;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.locked-engine-pattern:hover {
    background: rgba(255, 255, 255, 0.05) !important;
    border-color: rgba(255, 255, 255, 0.4) !important;
    color: #fff !important;
}

.locked-engine-pattern .bi-lock-fill {
    color: #fbbf24 !important; /* Amber for better visibility */
}
