/* ============================================ */
/* Suraksha Medicine Mart — Management System   */
/* Complete Stylesheet                          */
/* ============================================ */

:root, [data-theme="light"] {
    /* Google Fonts */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --font-heading: 'Plus Jakarta Sans', var(--font-sans);
    --font-mono: 'JetBrains Mono', SFMono-Regular, Menlo, Monaco, Consolas, monospace;

    /* Brand Primary Accent (Executive Sapphire Medical Blue) */
    --primary: #1d4ed8;
    --primary-dark: #1e40af;
    --primary-light: #eef2ff;
    --primary-border: #c7d2fe;
    --primary-glow: rgba(29, 78, 216, 0.2);

    /* Semantic Status Accents (Rich, refined luxury tones) */
    --success: #0f766e;
    --success-dark: #115e59;
    --success-light: #f0fdfa;
    --success-border: #99f6e4;

    --warning: #b45309;
    --warning-dark: #92400e;
    --warning-light: #fffbeb;
    --warning-border: #fde68a;

    --danger: #b91c1c;
    --danger-dark: #991b1b;
    --danger-light: #fef2f2;
    --danger-border: #fecaca;

    --info: #0369a1;
    --info-dark: #075985;
    --info-light: #f0f9ff;
    --info-border: #bae6fd;

    /* Light Theme Surfaces & Backgrounds (Refined Warm Light Creme) */
    --bg-app: #faf8f5;
    --bg-surface: #ffffff;
    --bg-card: #ffffff;
    --bg-subtle: #f5f2eb;
    --bg-hover: #f3efe6;
    --bg-active: #e9e4d8;
    --bg-input: #ffffff;
    --bg-table-header: #f7f4ed;
    --bg-table-stripe: #fdfbf7;

    /* Light Theme Borders (Warm Cashmere & Sandstone Dividers) */
    --border-color: #e7e2d7;
    --border-subtle: #eee9df;
    --border-focus: #1d4ed8;

    /* Light Theme Typography (Deep Midnight Navy & Warm Charcoal) */
    --text-primary: #0f172a;
    --text-secondary: #293548;
    --text-muted: #5e6d82;
    --text-inverted: #ffffff;

    /* Neutral Scale (Light Warm Stone) */
    --gray-50: #faf8f5;
    --gray-100: #f5f2eb;
    --gray-200: #e7e2d7;
    --gray-300: #d6cfbf;
    --gray-400: #a39c8e;
    --gray-500: #736c60;
    --gray-600: #4d473d;
    --gray-700: #332f28;
    --gray-800: #201e1a;
    --gray-900: #0f172a;

    /* Layout & Geometry */
    --sidebar-width: 250px;
    --sidebar-collapsed: 60px;
    --topbar-height: 64px;
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;

    /* Elevation Shadows (Soft Warm Ambient Glow) */
    --shadow-xs: 0 1px 2px rgba(32, 30, 26, 0.04);
    --shadow-sm: 0 1px 3px rgba(32, 30, 26, 0.07), 0 1px 2px rgba(32, 30, 26, 0.04);
    --shadow: 0 4px 6px -1px rgba(32, 30, 26, 0.06), 0 2px 4px -2px rgba(32, 30, 26, 0.04);
    --shadow-md: 0 10px 15px -3px rgba(32, 30, 26, 0.07), 0 4px 6px -4px rgba(32, 30, 26, 0.04);
    --shadow-lg: 0 20px 25px -5px rgba(32, 30, 26, 0.09), 0 8px 10px -6px rgba(32, 30, 26, 0.04);

    /* Sidebar Light Palette (Harmonious Creme & Ivory with Crisp Divider) */
    --sidebar-bg: #fcfbf9;
    --sidebar-text: #475569;
    --sidebar-border: #e7e2d7;
    --sidebar-active-bg: #eff3ff;
    --sidebar-active-text: #1d4ed8;
    --sidebar-hover-bg: #f3efe6;
    --sidebar-header-color: #1d4ed8;
    --sidebar-subtitle-color: #5e6d82;
    --sidebar-lang-bg: #f5f2eb;
    --sidebar-lang-border: #e7e2d7;
    --sidebar-lang-color: #1e293b;
}

/* ========== DARK THEME (MIDNIGHT OBSIDIAN LUXURY) ========== */
[data-theme="dark"] {
    /* Brand Primary Accent (Glowing High-Luminance Sapphire) */
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --primary-light: rgba(59, 130, 246, 0.16);
    --primary-border: rgba(59, 130, 246, 0.4);
    --primary-glow: rgba(59, 130, 246, 0.35);

    /* Semantic Status Accents */
    --success: #10b981;
    --success-dark: #059669;
    --success-light: rgba(16, 185, 129, 0.16);
    --success-border: rgba(16, 185, 129, 0.4);

    --warning: #f59e0b;
    --warning-dark: #d97706;
    --warning-light: rgba(245, 158, 11, 0.16);
    --warning-border: rgba(245, 158, 11, 0.4);

    --danger: #ef4444;
    --danger-dark: #dc2626;
    --danger-light: rgba(239, 68, 68, 0.16);
    --danger-border: rgba(239, 68, 68, 0.4);

    --info: #06b6d4;
    --info-dark: #0891b2;
    --info-light: rgba(6, 182, 212, 0.16);
    --info-border: rgba(6, 182, 212, 0.4);

    /* Dark Theme Obsidian Surfaces & Canvas */
    --bg-app: #080d1a;
    --bg-surface: #0f172a;
    --bg-card: #0f172a;
    --bg-subtle: #1e293b;
    --bg-hover: #1e293b;
    --bg-active: #273549;
    --bg-input: #080d1a;
    --bg-table-header: #131c31;
    --bg-table-stripe: rgba(30, 41, 59, 0.35);

    /* Dark Theme Borders */
    --border-color: #1e293b;
    --border-subtle: #1e293b;
    --border-focus: #60a5fa;

    /* Dark Theme Typography */
    --text-primary: #f8fafc;
    --text-secondary: #e2e8f0;
    --text-muted: #94a3b8;
    --text-inverted: #080d1a;

    /* Neutral Scale (Dark Mode Inversion) */
    --gray-50: #1e293b;
    --gray-100: #1a2234;
    --gray-200: #273549;
    --gray-300: #334155;
    --gray-400: #64748b;
    --gray-500: #94a3b8;
    --gray-600: #cbd5e1;
    --gray-700: #e2e8f0;
    --gray-800: #f1f5f9;
    --gray-900: #f8fafc;

    /* Shadows (Deep Rich Ambient Glow) */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5), 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.6), 0 4px 6px -4px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.7), 0 8px 10px -6px rgba(0, 0, 0, 0.6);

    /* Sidebar Dark Palette */
    --sidebar-bg: #0f172a;
    --sidebar-text: #94a3b8;
    --sidebar-border: #1e293b;
    --sidebar-active-bg: rgba(59, 130, 246, 0.18);
    --sidebar-active-text: #60a5fa;
    --sidebar-hover-bg: #1e293b;
    --sidebar-header-color: #60a5fa;
    --sidebar-subtitle-color: #94a3b8;
    --sidebar-lang-bg: #1e293b;
    --sidebar-lang-border: #273549;
    --sidebar-lang-color: #f8fafc;
}

/* ========== GLOBAL BASE & RESETS ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-app);
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color 0.25s ease, color 0.25s ease;
}

/* Typography Scale */
h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    color: var(--text-primary);
    letter-spacing: -0.015em;
    font-weight: 700;
}

code, pre, .mono, .stat-value, .gstin-code, .batch-pill, .price-val {
    font-family: var(--font-mono);
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color 0.2s ease;
}
a:hover {
    color: var(--primary-dark);
}

/* ========== SIDEBAR ========== */
#sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    color: var(--sidebar-text);
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease, background-color 0.25s ease, border-color 0.25s ease;
    overflow-y: auto;
}

#sidebar.collapsed { transform: translateX(-100%); }

.sidebar-header {
    padding: 20px 18px;
    border-bottom: 1px solid var(--sidebar-border);
    text-align: left;
}

.shop-name {
    font-size: 16px;
    font-weight: 700;
    line-height: 1.35;
    color: var(--sidebar-header-color);
}

.shop-subtitle {
    font-size: 11px;
    color: var(--sidebar-subtitle-color);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

.nav-menu { list-style: none; padding: 12px 10px; flex: 1; display: flex; flex-direction: column; gap: 4px; }

.nav-item {
    display: flex;
    align-items: center;
    padding: 11px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s ease;
    border-left: 3px solid transparent;
    color: var(--sidebar-text);
    font-size: 13.5px;
    font-weight: 500;
    white-space: nowrap;
}

.nav-item:hover {
    background: var(--sidebar-hover-bg);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--sidebar-active-bg);
    border-left: 3px solid var(--sidebar-active-text);
    color: var(--sidebar-active-text);
    font-weight: 700;
}

/* User requirement: clean removal of icons from navigation */
.nav-icon {
    display: none !important;
}

.nav-text {
    display: inline-block;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--sidebar-border);
}

.lang-select {
    width: 100%;
    padding: 9px 12px;
    background: var(--sidebar-lang-bg);
    border: 1px solid var(--sidebar-lang-border);
    color: var(--sidebar-lang-color);
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}
.lang-select:focus {
    border-color: var(--primary);
    outline: none;
}
.lang-select option {
    background: var(--bg-surface);
    color: var(--text-primary);
}

/* ========== MAIN CONTENT ========== */
#mainContent {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
    min-width: 0;
    max-width: calc(100vw - var(--sidebar-width));
    transition: margin-left 0.3s ease;
}

.top-bar {
    height: var(--topbar-height);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-xs);
    backdrop-filter: blur(12px);
    transition: background-color 0.25s ease, border-color 0.25s ease;
}

.top-bar h2 {
    font-size: 18px;
    font-weight: 700;
    flex: 1;
    color: var(--text-primary);
}

.top-bar-actions {
    font-size: 13px;
    color: var(--text-muted);
}

/* Topbar Theme Toggle Button */
.theme-toggle-btn {
    background: var(--bg-subtle);
    border: 1.5px solid var(--border-color);
    color: var(--text-primary);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-xs);
    user-select: none;
}

.theme-toggle-btn:hover {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary-border);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.theme-toggle-btn:active {
    transform: translateY(0);
}

.theme-toggle-btn.is-dark {
    background: #1e293b;
    border-color: #3b82f6;
    color: #93c5fd;
}
.theme-toggle-btn.is-dark:hover {
    background: #2563eb;
    color: #ffffff;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    margin-right: 15px;
    color: var(--text-primary);
}

/* ========== PAGES ========== */
.page {
    display: none;
    padding: 26px;
}
.page.active {
    display: block;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 22px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-header h3 {
    font-size: 21px;
    font-weight: 800;
    color: var(--text-primary);
}

.page-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

/* ========== STATS GRID ========== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 25px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    border-left: 4px solid transparent;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.25s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-sales { border-left-color: var(--success); }
.stat-purchase { border-left-color: var(--primary); }
.stat-profit { border-left-color: #8b5cf6; }
.stat-stock { border-left-color: var(--info); }
.stat-expiry { border-left-color: var(--warning); }
.stat-low { border-left-color: var(--danger); }
.stat-gst { border-left-color: #f59e0b; }
.stat-discount { border-left-color: #ec4899; }
.stat-bills { border-left-color: #6366f1; }

.stat-icon {
    font-size: 32px;
    line-height: 1;
}

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 11.5px;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.6px;
}

.stat-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    font-family: var(--font-mono);
    margin-top: 2px;
}

/* ========== CARDS ========== */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 22px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    margin-bottom: 22px;
    max-width: 100%;
    min-width: 0;
    transition: background-color 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

.card h3 {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.card h4 {
    font-size: 14.5px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-secondary);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
    gap: 22px;
    margin-bottom: 25px;
}

.chart-container {
    position: relative;
    height: 250px;
    max-height: 250px;
    width: 100%;
}

.card canvas {
    max-height: 250px !important;
    width: 100% !important;
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 16px;
}

/* ========== BUTTONS ========== */
.btn {
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 13.5px;
    font-weight: 600;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    text-decoration: none;
    user-select: none;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--bg-subtle);
    color: var(--text-secondary);
    border-color: var(--border-color);
}
.btn-secondary:hover {
    background: var(--bg-active);
    color: var(--text-primary);
}

.btn-success {
    background: var(--success);
    color: white;
}
.btn-success:hover {
    background: var(--success-dark);
}

.btn-warning {
    background: var(--warning);
    color: white;
}
.btn-warning:hover {
    background: var(--warning-dark);
}

.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-danger:hover {
    background: var(--danger-dark);
}

.btn-info {
    background: var(--info);
    color: white;
}
.btn-info:hover {
    background: var(--info-dark);
}

.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}
.btn-outline:hover {
    background: var(--bg-hover);
    color: var(--primary);
    border-color: var(--primary);
}

.btn-lg {
    padding: 12px 24px;
    font-size: 15px;
    border-radius: var(--radius-lg);
}

.btn-sm {
    padding: 5px 11px;
    font-size: 12px;
}

/* ========== FORMS & INPUTS ========== */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.form-group label {
    font-size: 11.5px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.form-input {
    padding: 9px 13px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 13.5px;
    font-family: var(--font-sans);
    transition: all 0.2s ease;
    background: var(--bg-input);
    color: var(--text-primary);
    width: 100%;
    outline: none;
}

.form-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 18px;
}

.search-input {
    padding-left: 14px;
}

/* ========== TABLES ========== */
.table-responsive {
    overflow-x: auto;
    max-width: 100%;
    width: 100%;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-card);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table th {
    background: var(--bg-table-header);
    padding: 11px 10px;
    text-align: left;
    font-weight: 700;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.data-table td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
    color: var(--text-primary);
}

.data-table tr:hover {
    background: var(--bg-hover);
}

.data-table input {
    padding: 5px 8px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 13px;
    width: 100%;
    min-width: 60px;
    background: var(--bg-input);
    color: var(--text-primary);
    font-family: var(--font-sans);
    outline: none;
}

.data-table input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-glow);
}

/* ========== MODALS ========== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(11, 15, 25, 0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
    backdrop-filter: blur(5px);
}

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.modal-lg {
    max-width: 920px;
}

.modal-xl {
    max-width: 1300px;
    width: 94vw;
}

#chartModalScrollWrapper::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
#chartModalScrollWrapper::-webkit-scrollbar-track {
    background: var(--bg-subtle);
    border-radius: 4px;
}
#chartModalScrollWrapper::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}
#chartModalScrollWrapper::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px 12px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 26px;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
    transition: color 0.15s ease;
}
.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 22px 24px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-surface);
}

/* ========== SCAN / UPLOAD ZONE ========== */
.upload-zone {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    padding: 50px 30px;
    text-align: center;
    background: var(--bg-card);
    transition: all 0.2s ease;
    cursor: pointer;
}

.upload-zone:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.upload-zone-small {
    padding: 25px 20px;
}

.upload-icon {
    font-size: 46px;
    margin-bottom: 14px;
}

.upload-zone h3 {
    color: var(--text-primary);
    margin-bottom: 8px;
    font-size: 17px;
}
.upload-zone p {
    color: var(--text-muted);
    font-size: 13.5px;
    margin-bottom: 18px;
}

.preview-image {
    max-width: 100%;
    max-height: 400px;
    border-radius: var(--radius);
    margin-bottom: 15px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
}

/* ========== LOADING SPINNER ========== */
.loading-container {
    text-align: center;
    padding: 40px;
}

.spinner {
    width: 42px;
    height: 42px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 15px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ========== BADGES ========== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.3px;
}

.badge-info {
    background: var(--info-light);
    color: var(--info);
    border: 1px solid var(--info-border);
}
.badge-success {
    background: var(--success-light);
    color: var(--success);
    border: 1px solid var(--success-border);
}
.badge-warning {
    background: var(--warning-light);
    color: var(--warning);
    border: 1px solid var(--warning-border);
}
.badge-danger {
    background: var(--danger-light);
    color: var(--danger);
    border: 1px solid var(--danger-border);
}

/* ========== INVENTORY LIST & BATCHES ========== */
.inventory-item {
    background: var(--bg-card);
    border-radius: var(--radius);
    margin-bottom: 10px;
    box-shadow: var(--shadow-xs);
    border: 1px solid var(--border-color);
    overflow: hidden;
    transition: all 0.2s ease;
}

.inventory-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 13px 18px;
    cursor: pointer;
    transition: background 0.2s;
    border-left: 4px solid var(--primary);
    background: var(--bg-card);
}

.inventory-item-header:hover {
    background: var(--bg-hover);
}

.inventory-item-header.low-stock {
    border-left-color: var(--warning);
}
.inventory-item-header.out-of-stock {
    border-left-color: var(--danger);
}

.inventory-item-name {
    font-weight: 700;
    font-size: 14.5px;
    color: var(--text-primary);
}
.inventory-item-meta {
    display: flex;
    gap: 14px;
    font-size: 12.5px;
    color: var(--text-muted);
}

.inventory-batches {
    display: none;
    padding: 8px 18px 14px;
    background: var(--bg-subtle);
    border-top: 1px solid var(--border-color);
}

.inventory-batches.open {
    display: block;
}

.batch-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr 1fr auto;
    gap: 8px;
    padding: 9px 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 13px;
    align-items: center;
}

.batch-row:last-child {
    border-bottom: none;
}

.batch-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
}

/* ========== SECTIONAL INVENTORY FILTER TABS ========== */
.filter-tab-btn {
    cursor: pointer;
    padding: 7px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 700;
    border: 1.5px solid var(--border-color);
    background: var(--bg-subtle);
    color: var(--text-secondary);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-family: var(--font-sans);
}

.filter-tab-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.filter-tab-btn.filter-all.active {
    border-color: var(--primary);
    background: var(--primary);
    color: #ffffff;
    box-shadow: 0 3px 10px var(--primary-glow);
}

.filter-tab-btn.filter-in-stock.active {
    border-color: var(--success);
    background: var(--success);
    color: #ffffff;
    box-shadow: 0 3px 10px rgba(22, 163, 74, 0.35);
}

.filter-tab-btn.filter-low-stock.active {
    border-color: var(--warning);
    background: var(--warning);
    color: #ffffff;
    box-shadow: 0 3px 10px rgba(217, 119, 6, 0.35);
}

.filter-tab-btn.filter-out-of-stock.active {
    border-color: var(--danger);
    background: var(--danger);
    color: #ffffff;
    box-shadow: 0 3px 10px rgba(220, 38, 38, 0.35);
}

/* ========== BILLING ========== */
.method-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
}

.method-tab {
    padding: 11px 22px;
    background: var(--bg-subtle);
    border: 1px solid var(--border-color);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all 0.2s;
    font-family: var(--font-sans);
}

.method-tab:first-child {
    border-radius: var(--radius) 0 0 var(--radius);
}
.method-tab:last-child {
    border-radius: 0 var(--radius) var(--radius) 0;
}

.method-tab.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.method-content {
    display: none;
}
.method-content.active {
    display: block;
}

.medicine-search-row {
    position: relative;
    width: 100%;
}

.search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    width: 100%;
    background: var(--bg-surface) !important;
    border: 2px solid var(--primary);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    max-height: 320px;
    overflow-y: auto;
    z-index: 99999 !important;
}

.search-result-item {
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.15s;
    background: var(--bg-surface);
    text-align: left;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.search-result-item:hover {
    background: var(--primary-light) !important;
}

.search-result-name {
    font-weight: 700;
    font-size: 14.5px;
    color: var(--text-primary);
}

.search-result-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 3px;
}

/* ========== BILL TOTALS ========== */
.bill-totals {
    max-width: 400px;
    margin-left: auto;
}

.total-row {
    display: flex;
    justify-content: space-between;
    padding: 7px 0;
    font-size: 14px;
    color: var(--text-secondary);
}

.total-final {
    border-top: 2px solid var(--border-color);
    margin-top: 8px;
    padding-top: 10px;
    font-size: 19px;
    font-weight: 800;
    color: var(--text-primary);
    font-family: var(--font-mono);
}

/* ========== PROFIT POPUP ========== */
.profit-display {
    background: var(--bg-subtle);
    border-radius: var(--radius);
    padding: 20px;
    margin: 15px 0;
    border: 1px solid var(--border-color);
}

.profit-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 14.5px;
    color: var(--text-secondary);
}

.profit-final {
    border-top: 2px solid var(--border-color);
    margin-top: 8px;
    padding-top: 10px;
    font-weight: 800;
    font-size: 20px;
    font-family: var(--font-mono);
}

.profit-positive { color: var(--success); }
.profit-negative { color: var(--danger); }

/* ========== EXPIRY TABS ========== */
.expiry-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    overflow-x: auto;
}

.expiry-tab {
    padding: 11px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    cursor: pointer;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all 0.2s;
    white-space: nowrap;
    font-family: var(--font-sans);
}

.expiry-tab:first-child {
    border-radius: var(--radius) 0 0 var(--radius);
}
.expiry-tab:last-child {
    border-radius: 0 var(--radius) var(--radius) 0;
}

.expiry-tab.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.tab-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 11px;
    background: rgba(0, 0, 0, 0.12);
    font-size: 11px;
    font-weight: 700;
    margin-left: 5px;
}

.expiry-tab.active .tab-count {
    background: rgba(255, 255, 255, 0.28);
}

/* ========== QUICK ACTIONS & LISTS ========== */
.quick-actions {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    margin-top: 6px;
}

.list-container {
    max-height: 300px;
    overflow-y: auto;
}

.list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 11px 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 13.5px;
    color: var(--text-primary);
}

.list-item:last-child {
    border-bottom: none;
}

.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
    font-size: 14.5px;
}

/* ========== TOAST NOTIFICATIONS ========== */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius);
    color: white;
    font-size: 13.5px;
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s ease;
    max-width: 380px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--info); }
.toast-warning { background: var(--warning); }

@keyframes toastIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ========== DISTRIBUTOR CARDS ========== */
.dist-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--primary);
}

.dist-card h4 {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text-primary);
}
.dist-card p {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.5;
}
.dist-card-actions {
    margin-top: 14px;
    display: flex;
    gap: 8px;
}

/* ========== SETTINGS APPEARANCE PICKER ========== */
.appearance-card {
    border: 1px solid var(--border-color);
}

.theme-selector-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px;
    margin-top: 14px;
}

.theme-option-card {
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 16px;
    cursor: pointer;
    transition: all 0.25s ease;
    background: var(--bg-surface);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.theme-option-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.theme-option-card.active {
    border-color: var(--primary);
    background: var(--primary-light);
    box-shadow: 0 0 0 1px var(--primary), var(--shadow-sm);
}

.theme-option-header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.theme-option-header input[type="radio"] {
    accent-color: var(--primary);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.theme-option-desc {
    font-size: 12.5px;
    color: var(--text-muted);
    line-height: 1.4;
}

/* Theme Previews */
.theme-option-preview {
    height: 90px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    display: flex;
    border: 1px solid var(--border-color);
}

.theme-preview-light {
    background: #f8fafc;
}
.theme-preview-light .preview-mini-nav {
    width: 25%;
    background: #0f172a;
}
.theme-preview-light .preview-mini-main {
    flex: 1;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: #f8fafc;
}
.theme-preview-light .preview-mini-bar {
    height: 12px;
    background: #ffffff;
    border-radius: 4px;
    border: 1px solid #e2e8f0;
}
.theme-preview-light .preview-mini-cards {
    display: flex;
    gap: 6px;
    flex: 1;
}
.theme-preview-light .preview-mini-box {
    flex: 1;
    background: #ffffff;
    border-radius: 4px;
    border: 1px solid #e2e8f0;
}

.theme-preview-dark {
    background: #0b0f19;
}
.theme-preview-dark .preview-mini-nav {
    width: 25%;
    background: #070a12;
}
.theme-preview-dark .preview-mini-main {
    flex: 1;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: #0b0f19;
}
.theme-preview-dark .preview-mini-bar {
    height: 12px;
    background: #111827;
    border-radius: 4px;
    border: 1px solid #273549;
}
.theme-preview-dark .preview-mini-cards {
    display: flex;
    gap: 6px;
    flex: 1;
}
.theme-preview-dark .preview-mini-box {
    flex: 1;
    background: #111827;
    border-radius: 4px;
    border: 1px solid #273549;
}

/* ========== TEXT HELPERS ========== */
.text-muted { color: var(--text-muted); }
.text-info { color: var(--info); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }

/* ========== CUSTOM SCROLLBARS ========== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: var(--bg-subtle);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb {
    background: var(--gray-400);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--gray-500);
}

.table-responsive::-webkit-scrollbar {
    height: 10px;
}
.table-responsive::-webkit-scrollbar-track {
    background: var(--bg-subtle);
    border-radius: 5px;
}
.table-responsive::-webkit-scrollbar-thumb {
    background: var(--gray-400);
    border-radius: 5px;
}
.table-responsive::-webkit-scrollbar-thumb:hover {
    background: var(--gray-500);
}

/* ========== FILTER HISTORY BUTTONS ========== */
.hist-filter-btn.active {
    box-shadow: 0 0 0 2px var(--primary);
    font-weight: 700;
}
.hist-filter-btn.btn-danger.active {
    background: #b91c1c;
    color: white;
    box-shadow: 0 0 0 2px #7f1d1d;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
    #sidebar { transform: translateX(-100%); }
    #sidebar.open { transform: translateX(0); }

    #mainContent {
        margin-left: 0;
        max-width: 100vw;
    }

    .menu-toggle { display: block; }

    .page { padding: 16px; }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .batch-row {
        grid-template-columns: 1fr 1fr;
    }

    .bill-totals { max-width: 100%; }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .top-bar h2 { font-size: 16px; }

    .stat-value { font-size: 18px; }

    .expiry-tabs { overflow-x: auto; }

    .modal-content { margin: 10px; max-height: 95vh; }

    .quick-actions {
        flex-direction: column;
    }

    .quick-actions .btn { width: 100%; justify-content: center; }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .stat-card { padding: 14px; }
    .stat-icon { font-size: 24px; }
    .stat-value { font-size: 16px; }
    .stat-label { font-size: 10px; }
}

/* ========== PRINT STYLES ========== */
@media print {
    @page {
        size: landscape;
        margin: 8mm;
    }
    #sidebar, .top-bar, .menu-toggle, .page-actions, .quick-actions, .btn, #themeToggleBtn {
        display: none !important;
    }
    #mainContent {
        margin-left: 0;
        max-width: 100vw;
    }
    .page { padding: 0; }
    .card {
        box-shadow: none;
        border: 1px solid #cbd5e1;
        background: #ffffff !important;
        color: #000000 !important;
    }
}

/* ========== DARK MODE OVERRIDES & CONTRAST FIXES ========== */
[data-theme="dark"] #creditPendingBanner,
[data-theme="dark"] [style*="background:#fee2e2"],
[data-theme="dark"] [style*="background: #fee2e2"] {
    background: rgba(239, 68, 68, 0.15) !important;
    border-left-color: #ef4444 !important;
    color: #f87171 !important;
}

[data-theme="dark"] #liveOwnerProfitDisplay,
[data-theme="dark"] [style*="background:#f0fdf4"],
[data-theme="dark"] [style*="background: #f0fdf4"] {
    background: rgba(34, 197, 94, 0.15) !important;
    border-color: rgba(34, 197, 94, 0.3) !important;
    color: #4ade80 !important;
}

[data-theme="dark"] #crmChurnAlertBox,
[data-theme="dark"] [style*="background:#fffbeb"],
[data-theme="dark"] [style*="background: #fffbeb"] {
    background: rgba(245, 158, 11, 0.15) !important;
    border-color: rgba(245, 158, 11, 0.3) !important;
    color: #fbbf24 !important;
}

[data-theme="dark"] [style*="color:#6b7280"],
[data-theme="dark"] [style*="color: #6b7280"],
[data-theme="dark"] [style*="color:#4b5563"],
[data-theme="dark"] [style*="color: #4b5563"] {
    color: #94a3b8 !important;
}

[data-theme="dark"] [style*="color:#1d4ed8"],
[data-theme="dark"] [style*="color: #1d4ed8"],
[data-theme="dark"] [style*="color:#1e40af"],
[data-theme="dark"] [style*="color: #1e40af"] {
    color: #60a5fa !important;
}

[data-theme="dark"] [style*="color:#991b1b"],
[data-theme="dark"] [style*="color: #991b1b"] {
    color: #f87171 !important;
}

[data-theme="dark"] [style*="color:#16a34a"],
[data-theme="dark"] [style*="color: #16a34a"],
[data-theme="dark"] [style*="color:#15803d"],
[data-theme="dark"] [style*="color: #15803d"] {
    color: #4ade80 !important;
}

[data-theme="dark"] [style*="color:#78350f"],
[data-theme="dark"] [style*="color: #78350f"],
[data-theme="dark"] [style*="color:#b45309"],
[data-theme="dark"] [style*="color: #b45309"] {
    color: #fbbf24 !important;
}


