/* Enterprise extras: chart palette and chart-card refinements */
:root {
    --chart-1: #0EA5A4; /* teal */
    --chart-2: #06B6D4; /* cyan */
    --chart-3: #3B82F6; /* blue */
    --chart-4: #F59E0B; /* amber */
    --chart-5: #EF4444; /* red */
}

.chart-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    box-shadow: var(--shadow-sm);
}

.chart-card h3 { margin: 0 0 12px 0; font-size: 1rem; font-weight: 700; color: var(--text-primary); }

.chart-card canvas { width: 100% !important; height: 260px !important; }

.chart-legend { display:flex; gap: 12px; align-items:center; flex-wrap:wrap; }
.chart-legend .legend-item { display:inline-flex; align-items:center; gap:8px; color: var(--text-muted); font-size: 0.9rem; }
.chart-legend .legend-swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.chart-legend .swatch-1 { background: var(--chart-1); }
.chart-legend .swatch-2 { background: var(--chart-2); }
.chart-legend .swatch-3 { background: var(--chart-3); }
.chart-legend .swatch-4 { background: var(--chart-4); }
.chart-legend .swatch-5 { background: var(--chart-5); }

/* ============================================================
   AI Assistant Panel Styles
   ============================================================ */
.floating-chat-button {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 1100;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px 10px 10px;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--primary), #3b82f6);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 16px 34px rgba(37, 99, 235, 0.28);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.floating-chat-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 20px 40px rgba(37, 99, 235, 0.34);
    color: white;
}

.floating-chat-icon {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: rgba(255,255,255,0.2);
    font-size: 1rem;
    font-weight: 700;
}

.floating-chat-label {
    font-weight: 700;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.assistant-panel-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.36);
    z-index: 1150;
    backdrop-filter: blur(2px);
}

.assistant-panel {
    position: fixed;
    right: 24px;
    bottom: 90px;
    width: min(420px, calc(100vw - 24px));
    max-height: min(680px, calc(100vh - 110px));
    display: flex;
    flex-direction: column;
    background: white;
    border-radius: 20px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.24);
    overflow: hidden;
    z-index: 1160;
}

.assistant-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    border-bottom: 1px solid rgba(148,163,184,0.16);
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.08), rgba(255,255,255,0.95));
}

.assistant-panel-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.assistant-panel-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, var(--primary), #3b82f6);
    color: white;
    font-weight: 700;
}

.assistant-panel-title h4 {
    margin: 0 0 2px;
    font-size: 0.98rem;
}

.assistant-panel-title p {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.assistant-panel-close {
    border: none;
    background: rgba(15, 23, 42, 0.06);
    width: 34px;
    height: 34px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--text-dark);
}

.assistant-panel-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px 0;
    font-size: 0.8rem;
    color: var(--primary);
    font-weight: 600;
}

.assistant-panel-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
    animation: assistantPulse 1.2s infinite ease-in-out;
}

@keyframes assistantPulse {
    0%, 100% { transform: scale(1); opacity: 0.7; }
    50% { transform: scale(1.2); opacity: 1; }
}

.assistant-panel-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: linear-gradient(180deg, rgba(248,250,252,0.85), rgba(255,255,255,0.95));
}

.assistant-empty-state {
    margin: auto;
    text-align: center;
    color: var(--text-muted);
    padding: 24px 12px;
}

.assistant-empty-icon {
    font-size: 1.7rem;
    margin-bottom: 8px;
}

.assistant-panel-composer {
    padding: 12px;
    border-top: 1px solid rgba(148,163,184,0.16);
    background: white;
}

.assistant-panel-form {
    display: flex;
    gap: 8px;
}

.assistant-panel-form .form-input {
    margin: 0;
    flex: 1;
    border-radius: 999px;
    padding: 10px 12px;
}

.assistant-panel .chat-message {
    display: flex;
}

.assistant-panel .chat-message.user {
    justify-content: flex-end;
}

.assistant-panel .chat-bubble {
    display: flex;
    gap: 8px;
    max-width: 86%;
    padding: 10px 12px;
    border-radius: 14px;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.06);
}

.assistant-panel .chat-bubble.user {
    background: linear-gradient(135deg, var(--primary), #3b82f6);
    color: white;
    border-top-right-radius: 4px;
    flex-direction: row-reverse;
}

.assistant-panel .chat-bubble.assistant {
    background: white;
    color: var(--text-dark);
    border-top-left-radius: 4px;
}

.assistant-panel .chat-bubble .avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 0.72rem;
    font-weight: 700;
    flex-shrink: 0;
}

.assistant-panel .chat-bubble.user .avatar {
    background: rgba(255,255,255,0.2);
}

.assistant-panel .chat-bubble.assistant .avatar {
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary);
}

.assistant-panel .message-meta {
    font-size: 0.68rem;
    margin-bottom: 3px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    opacity: 0.8;
}

.assistant-panel .typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 16px;
}

.assistant-panel .typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.55;
    animation: assistantTyping 1.2s infinite ease-in-out;
}

.assistant-panel .typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.assistant-panel .typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes assistantTyping {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.45; }
    40% { transform: translateY(-4px); opacity: 1; }
}

@media (max-width: 768px) {
    .floating-chat-button {
        right: 14px;
        bottom: 14px;
        padding: 8px 12px 8px 8px;
    }

    .floating-chat-label {
        display: none;
    }

    .assistant-panel {
        right: 12px;
        left: 12px;
        bottom: 78px;
        width: auto;
    }
}

/* ── Dashboard Page Styles (extracted from inline for caching) ───────────── */
.dashboard-stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}
.stat-card-premium {
    background: linear-gradient(180deg, rgba(248,250,252,0.96) 0%, rgba(255,255,255,0.98) 100%);
    border: 1px solid rgba(148,163,184,0.18);
    border-radius: calc(var(--radius-lg) + 4px);
    padding: 24px 26px;
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.06);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 150px;
    transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
    position: relative;
    overflow: hidden;
}
.stat-card-premium:hover {
    transform: translateY(-3px);
    box-shadow: 0 24px 50px rgba(15, 23, 42, 0.1);
    border-color: rgba(16, 185, 129, 0.24);
}
.stat-card-premium::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 56px;
    height: 4px;
    background: var(--primary);
    border-bottom-right-radius: 8px;
    transition: width 0.25s ease, background 0.25s ease;
}
.stat-card-premium:hover::before { width: 100%; }
.stat-card-premium.profit::before { background: var(--success); }
.stat-card-premium.credit::before { background: var(--danger); }
.stat-card-premium.alert::before  { background: var(--warning); }

.stat-label-premium {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 8px;
}
.stat-value-premium {
    font-size: 1.85rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    line-height: 1.2;
}
.stat-desc-premium {
    font-size: 0.76rem;
    color: var(--text-muted);
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.analytics-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}
@media (max-width: 1024px) {
    .analytics-grid { grid-template-columns: 1fr; }
}

/* Override chart-card with dashboard-specific spacing */
.dashboard-page .chart-card {
    padding: 24px;
    transition: box-shadow 0.3s ease;
}
.dashboard-page .chart-card:hover { box-shadow: var(--shadow); }

.card-header {
    background: var(--bg);
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
}
.card-header h3 {
    margin: 0;
    font-size: 1rem;
    letter-spacing: -0.01em;
}
.table-wrapper {
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
}
.table thead { background: var(--bg); }
.table tbody tr { transition: background-color 0.2s ease; }
.table tbody tr:hover { background-color: rgba(99, 102, 241, 0.05); }

/* =============================================================
   DARK THEME — MISSING COVERAGE PATCH
   Fills gaps in enterprise.css dark mode rules so the theme
   works correctly on ALL screen sizes including mobile & POS.
   ============================================================= */

/* --- Assistant panel dark mode --- */
[data-theme="dark"] .assistant-panel {
    background: #1E293B;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .assistant-panel-header {
    background: linear-gradient(135deg, rgba(52, 211, 153, 0.08), rgba(30, 41, 59, 0.98));
    border-bottom-color: var(--border);
}

[data-theme="dark"] .assistant-panel-messages {
    background: linear-gradient(180deg, #0F172A, #1E293B);
}

[data-theme="dark"] .assistant-panel-composer {
    background: #1E293B;
    border-top-color: var(--border);
}

[data-theme="dark"] .assistant-panel .chat-bubble.assistant {
    background: #0F172A;
    color: var(--text-primary);
    border: 1px solid var(--border);
}

[data-theme="dark"] .assistant-panel-close {
    background: rgba(255, 255, 255, 0.06);
    color: #94A3B8;
}

[data-theme="dark"] .assistant-panel-backdrop {
    background: rgba(0, 0, 0, 0.55);
}

/* --- Mobile menu button dark mode --- */
[data-theme="dark"] .mobile-menu-btn {
    background: rgba(30, 41, 59, 0.95);
    border-color: rgba(255, 255, 255, 0.1);
    color: #F1F5F9;
}

/* --- Mobile overlay dark mode --- */
[data-theme="dark"] .mobile-overlay,
[data-theme="dark"] .sidebar-expanded .mobile-overlay {
    background: rgba(0, 0, 0, 0.65);
}

/* --- Sidebar footer dark mode (already dark bg, but text needs coverage) --- */
[data-theme="dark"] .user-name { color: #F1F5F9; }
[data-theme="dark"] .user-role { color: #64748B; }

/* --- Dashboard stat-card-premium dark mode --- */
[data-theme="dark"] .stat-card-premium {
    background: linear-gradient(180deg, rgba(30, 41, 59, 0.97) 0%, rgba(15, 23, 42, 0.99) 100%);
    border-color: var(--border);
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.25);
}

[data-theme="dark"] .stat-card-premium:hover {
    box-shadow: 0 24px 50px rgba(0, 0, 0, 0.4);
    border-color: rgba(52, 211, 153, 0.24);
}

[data-theme="dark"] .stat-label-premium { color: #94A3B8; }
[data-theme="dark"] .stat-value-premium { color: #F1F5F9; }
[data-theme="dark"] .stat-desc-premium  { color: #64748B; }

/* --- Chart card dark mode --- */
[data-theme="dark"] .chart-card {
    background: var(--surface);
    border-color: var(--border);
}

[data-theme="dark"] .chart-card h3 { color: #F1F5F9; }
[data-theme="dark"] .chart-legend .legend-item { color: #94A3B8; }

/* --- POS dark mode — missing elements --- */
[data-theme="dark"] .pos-catalog-panel {
    background: transparent;
}

[data-theme="dark"] .pos-search-bar .form-input {
    background: #0F172A;
    border-color: var(--border);
    color: var(--text-primary);
}

[data-theme="dark"] .pos-cart-header {
    background: #1E293B;
    border-bottom-color: var(--border);
    color: #F1F5F9;
}

[data-theme="dark"] .pos-cart-items {
    background: #1E293B;
    border-bottom-color: var(--border);
}

[data-theme="dark"] .pos-cart-item {
    border-bottom-color: var(--border);
}

[data-theme="dark"] .pos-product-name {
    color: #F1F5F9;
}

[data-theme="dark"] .pos-product-meta {
    color: #94A3B8;
}

[data-theme="dark"] .pos-product-price {
    color: #34D399;
}

[data-theme="dark"] .pos-product-card:hover {
    border-color: #34D399;
    background: #1a2a40;
}

[data-theme="dark"] .pos-summary-row {
    color: #CBD5E1;
}

[data-theme="dark"] .pos-summary-row.total {
    color: #F1F5F9;
    border-top-color: var(--border);
}

[data-theme="dark"] .pos-actions {
    background: #1E293B;
}

/* --- Modal overlay dark mode --- */
[data-theme="dark"] .modal-overlay {
    background: rgba(0, 0, 0, 0.72);
}

[data-theme="dark"] .modal-body {
    background: var(--surface);
    color: #F1F5F9;
}

/* --- Page-level background dark mode --- */
[data-theme="dark"] .page-content {
    background: var(--bg);
}

[data-theme="dark"] .main-content {
    background: var(--bg);
}

[data-theme="dark"] .app-shell {
    background: var(--bg);
}

/* --- Topbar dark: date badge and actions area --- */
[data-theme="dark"] .topbar-actions .badge-primary {
    background: rgba(52, 211, 153, 0.1);
    color: #34D399;
    border-color: rgba(52, 211, 153, 0.2);
}

/* --- Flash zone alerts dark border fix --- */
[data-theme="dark"] .flash-zone .alert { border-left-width: 4px; }

/* --- Nav section label dark mode --- */
[data-theme="dark"] .nav-section-label {
    color: #475569;
}

/* --- Form group / form section backgrounds dark mode --- */
[data-theme="dark"] .form-group { background: transparent; }

/* --- Table wrapper full dark fix --- */
[data-theme="dark"] .table-wrapper {
    background: var(--surface);
}

/* =============================================================
   POS PAGE — MOBILE RESPONSIVE FIXES
   Ensures POS cart panel and product grid are usable on phones.
   ============================================================= */

/* On mobile, POS panels stack — cart needs a sensible min-height
   and should not collapse to 0 when parent height is auto */
@media (max-width: 992px) {
    .pos-container {
        display: flex;
        flex-direction: column;
        height: auto !important;
        gap: 20px;
    }

    .pos-catalog-panel {
        flex: none;
        height: auto;
        min-height: 0;
    }

    .pos-product-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        max-height: 60vh;
        overflow-y: auto;
    }

    .pos-cart-panel {
        flex: none;
        height: auto;
        min-height: 340px;
    }

    .pos-cart-items {
        max-height: 280px;
        overflow-y: auto;
    }

    .pos-cart-item {
        grid-template-columns: 2fr 1fr 1fr;
    }
}

@media (max-width: 576px) {
    .pos-product-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 10px;
        max-height: 55vh;
    }

    .pos-product-card {
        padding: 12px;
        min-height: 100px;
    }

    .pos-product-name {
        font-size: 0.85rem;
    }

    .pos-product-price {
        font-size: 0.95rem;
    }

    .pos-cart-item {
        /* On very small phones, name takes full width, qty+price share a row */
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto;
    }

    /* Cart item name spans full width */
    .pos-cart-item > *:first-child {
        grid-column: 1 / -1;
    }

    .pos-summary-row.total {
        font-size: 1.05rem;
    }

    .pos-cart-header {
        font-size: 0.92rem;
        padding: 14px 16px;
    }

    .pos-summary-section {
        padding: 14px 16px;
    }

    .pos-actions {
        padding: 14px 16px;
    }
}

/* =============================================================
   DARK THEME — MOBILE-SPECIFIC OVERRIDES
   Dark theme rules that apply ONLY at mobile breakpoints where
   some elements get different base styles (e.g. the fixed sidebar).
   ============================================================= */

@media (max-width: 992px) {
    /* Sidebar gets a hardcoded gradient at this breakpoint in enterprise.css.
       In dark mode, override it to use the dark surface token instead. */
    [data-theme="dark"] .sidebar {
        background: linear-gradient(180deg, #0F172A 0%, #1E293B 100%) !important;
    }

    /* Topbar padding shift — ensure background is correct */
    [data-theme="dark"] .topbar {
        background: #1E293B;
    }

    /* Main content area fill */
    [data-theme="dark"] .main-content {
        background: #0F172A;
    }

    /* POS dark on mobile */
    [data-theme="dark"] .pos-cart-panel {
        background: #1E293B;
        border-color: #334155;
    }

    [data-theme="dark"] .pos-product-grid {
        background: transparent;
    }

    [data-theme="dark"] .pos-product-card {
        background: #1E293B;
        border-color: #334155;
    }
}

@media (max-width: 768px) {
    /* Full-screen dark bg on phones */
    [data-theme="dark"] body,
    [data-theme="dark"] .app-shell,
    [data-theme="dark"] .main-content,
    [data-theme="dark"] .page-content {
        background: #0F172A;
    }

    /* Cards in dark mobile */
    [data-theme="dark"] .card,
    [data-theme="dark"] .stat-card,
    [data-theme="dark"] .chart-card {
        background: #1E293B;
        border-color: #334155;
    }

    /* Topbar on phones dark */
    [data-theme="dark"] .topbar {
        background: #1E293B;
        border-bottom-color: #334155;
    }

    /* Table dark on mobile */
    [data-theme="dark"] .table-wrapper {
        background: #1E293B;
        border-color: #334155;
    }

    [data-theme="dark"] .table th {
        background: #0F172A;
        color: #64748B;
    }

    [data-theme="dark"] .table td {
        color: #F1F5F9;
        border-bottom-color: #334155;
    }

    /* Modal on mobile dark */
    [data-theme="dark"] .modal-content {
        background: #1E293B;
        border-color: #334155;
    }

    [data-theme="dark"] .modal-header,
    [data-theme="dark"] .modal-footer {
        background: #0F172A;
        border-color: #334155;
    }
}

