/* ============================================
   MODERN PREMIUM DESIGN SYSTEM - LOOK IN ORA
   ============================================ */

:root {
    color-scheme: light dark;
    /* Colors - Modern Palette
       --primary / semantic aliases are AA ink+fill (≥4.5:1 on white and white-on-fill).
       Bright decorative steps stay on *-500 for charts/gradients only. */
    --primary: #6D28D9;
    --primary-dark: #5B21B6;
    --secondary: #DB2777;
    --dark: #0F172A;
    --darker: #020617;
    --surface: #FFFFFF;
    --bg: #F8FAFC;
    --primary-50: #F5F3FF;
    --primary-100: #EDE9FE;
    --primary-200: #DDD6FE;
    --primary-300: #C4B5FD;
    --primary-400: #A78BFA;
    --primary-500: #8B5CF6;
    --primary-600: #7C3AED;
    --primary-700: #6D28D9;
    --primary-800: #5B21B6;
    
    --accent-50: #FDF2F8;
    --accent-100: #FCE7F3;
    --accent-300: #F9A8D4;
    --accent-500: #EC4899;
    --accent-600: #DB2777;
    
    /* Semantic Colors */
    --success-50: #F0FDF4;
    --success-100: #DCFCE7;
    --success-500: #10B981;
    --success-600: #059669;
    --success-700: #047857;
    
    --warning-50: #FFFBEB;
    --warning-100: #FEF3C7;
    --warning-500: #F59E0B;
    --warning-600: #D97706;
    --warning-700: #B45309;
    
    --danger-50: #FEF2F2;
    --danger-100: #FEE2E2;
    --danger-500: #EF4444;
    --danger-600: #DC2626;
    --danger-700: #B91C1C;
    
    --info-50: #F0F9FF;
    --info-100: #E0F2FE;
    --info-500: #0EA5E9;
    --info-600: #0284C7;
    --info-700: #0369A1;
    
    /* Neutrals */
    --slate-50: #F8FAFC;
    --slate-100: #F1F5F9;
    --slate-200: #E2E8F0;
    --slate-300: #CBD5E1;
    --slate-400: #94A3B8;
    --slate-500: #64748B;
    --slate-600: #475569;
    --slate-700: #334155;
    --slate-800: #1E293B;
    --slate-900: #0F172A;
    
    /* Role tokens (prefer these in new CSS) */
    --primary-ink: var(--primary);
    --success-ink: var(--success-700);
    --warning-ink: var(--warning-700);
    --danger-ink: var(--danger-600);
    --info-ink: var(--info-700);
    
    /* Legacy mappings for compatibility */
    --bg-body: var(--bg);
    --bg-surface: var(--surface);
    --bg-subtle: #F3F4F6;
    --text-main: #1F2937;
    --text-muted: #6B7280;
    --border-light: #E5E7EB;
    --border-focus: var(--primary);
    --ring-focus: rgba(109, 40, 217, 0.18);
    
    --primary-from: var(--primary-600);
    --primary-to: var(--accent-600);
    --primary-border: var(--primary-dark);
    --table-header-gradient: linear-gradient(135deg, #F7F2FF 0%, #FCE7F3 100%);
    --table-header-text: #4C1D95;
    
    --danger-from: var(--danger-600);
    --danger-to: var(--danger-700);
    --danger-border: var(--danger-700);
    
    --success: var(--success-ink);
    --warning: var(--warning-ink);
    --danger: var(--danger-ink);
    --online: var(--success-ink);
    --busy: var(--warning-ink);
    --away: var(--slate-500);
    --offline: var(--slate-500);
    --app-border-strong: rgba(109, 40, 217, 0.28);
    --app-border-glow: inset 0 0 0 1px rgba(255, 255, 255, 0.42);
    
    /* Spacing Scale */
    --space-0: 0;
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;
    --space-16: 4rem;
    
    /* Radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-2xl: 1.5rem;
    --radius-full: 9999px;
    
    /* Shadows - Modern Depth */
    --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.04);
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    --shadow-float: 0 25px 50px -12px rgba(139, 92, 246, 0.15);
    
    /* Typography */
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
}

body.theme-dark {
    color-scheme: dark;
    --bg: #07101F;
    --surface: #0F172A;
    --dark: #020617;
    --darker: #01040B;
    --bg-body: #07101F;
    --bg-surface: #0F172A;
    --bg-subtle: #172033;
    --text-main: #F8FAFC;
    --text-muted: #A8B3C7;
    --border-light: #223049;
    /* Lighter inks on dark surfaces (≥4.5:1 vs #0F172A) */
    --primary: #C4B5FD;
    --primary-dark: #A78BFA;
    --secondary: #F9A8D4;
    --primary-ink: var(--primary);
    --success-ink: #6EE7B7;
    --warning-ink: #FCD34D;
    --danger-ink: #FCA5A5;
    --info-ink: #7DD3FC;
    --success: var(--success-ink);
    --warning: var(--warning-ink);
    --danger: var(--danger-ink);
    --online: var(--success-ink);
    --busy: var(--warning-ink);
    --away: var(--slate-500);
    --offline: var(--slate-500);

    --slate-50: #0F172A;
    --slate-100: #1E293B;
    --slate-200: #334155;
    --slate-300: #475569;
    --slate-400: #64748B;
    --slate-500: #94A3B8;
    --slate-600: #CBD5E1;
    --slate-700: #E2E8F0;
    --slate-800: #F1F5F9;
    --slate-900: #F8FAFC;

    --primary-50: #2E1065;
    --primary-100: #3B0764;
    --success-50: #052E16;
    --success-100: #064E3B;
    --warning-50: #451A03;
    --warning-100: #78350F;
    --danger-50: #4C0519;
    --danger-100: #881337;
    --info-50: #082F49;
    --info-100: #0C4A6E;
    --app-border-strong: rgba(129, 140, 248, 0.3);
    --app-border-glow: inset 0 0 0 1px rgba(129, 140, 248, 0.08);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Visible focus for keyboard users (do not rely on outline:none alone). */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Shared confirm dialog (replaces window.confirm for money paths). */
.lio-confirm-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 20050;
    align-items: center;
    justify-content: center;
    padding: 16px;
    padding-bottom: max(16px, env(safe-area-inset-bottom, 0px));
    background: rgba(15, 23, 42, 0.55);
}

.lio-confirm-modal.is-open {
    display: flex;
}

.lio-confirm-dialog {
    width: min(420px, 100%);
    background: var(--bg-surface);
    color: var(--text-main);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-2xl);
    padding: 24px;
}

.lio-confirm-dialog h2 {
    font-size: 1.15rem;
    margin: 0 0 8px;
    color: var(--text-main);
}

.lio-confirm-dialog p {
    margin: 0 0 20px;
    color: var(--text-muted);
    white-space: pre-wrap;
}

.lio-confirm-actions {
    display: flex;
    gap: 10px;
}

.lio-confirm-actions button {
    flex: 1;
    min-height: 44px;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}

.lio-confirm-cancel {
    background: var(--bg-subtle);
    border: 1px solid var(--border-light);
    color: var(--text-main);
}

.lio-confirm-ok {
    background: var(--primary);
    border: none;
    color: #fff;
}

.lio-confirm-ok.is-danger {
    background: var(--danger-ink);
}

/* ============================================
   TYPOGRAPHY
   ============================================ */

h1 {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.02em;
    color: var(--slate-900);
    margin-bottom: var(--space-6);
}

h2 {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.3;
    letter-spacing: -0.01em;
    color: var(--slate-800);
    margin-bottom: var(--space-4);
}

h3 {
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1.4;
    color: var(--slate-800);
    margin-bottom: var(--space-3);
}

h4 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--slate-700);
}

h5, h6 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--slate-700);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

p {
    color: var(--text-main);
    margin-bottom: var(--space-4);
}

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

a:hover {
    color: var(--primary-700);
    text-decoration: underline;
}

/* ============================================
   LAYOUT & CONTAINERS
   ============================================ */

.app-container {
    max-width: 1440px;
    margin: 0 auto;
    padding: var(--space-6);
}

.container {
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    padding-left: var(--space-6);
    padding-right: var(--space-6);
}

@media (max-width: 640px) {
    .container,
    .app-container {
        padding-left: var(--space-4);
        padding-right: var(--space-4);
    }
}

/* ============================================
   GLOBAL MOBILE COMPACTION LAYER
   ============================================ */
@media (max-width: 768px) {
    html, body {
        font-size: 14px;
    }

    .container,
    .app-container {
        padding-left: 10px;
        padding-right: 10px;
    }

    .card {
        border-radius: 12px;
    }

    .card-header,
    .card-body,
    .card-footer {
        padding: 12px;
    }

    .purchase-content,
    .inventory-content,
    .customer-content,
    .reports-content,
    .expenses-content,
    .settings-content,
    .flow-content,
    .offer-content,
    .vendor-content,
    .stall-content,
    .sip-content {
        padding: 12px !important;
        gap: 12px !important;
    }

    .purchase-toolbar,
    .inventory-controls,
    .customer-toolbar,
    .reports-toolbar,
    .expenses-toolbar {
        gap: 10px !important;
    }

    .purchase-grid-2,
    .form-grid,
    .grid-cols-2,
    .grid-cols-3,
    .grid-cols-4 {
        gap: 10px !important;
    }

    input,
    select,
    textarea,
    button,
    .btn,
    .btn-primary,
    .btn-secondary,
    .purchase-input,
    .purchase-btn,
    .filter-select,
    .search-box input {
        min-height: 38px;
        font-size: 0.92rem !important;
        padding-top: 8px !important;
        padding-bottom: 8px !important;
    }

    h1 { font-size: 1.35rem !important; margin-bottom: 10px !important; }
    h2 { font-size: 1.15rem !important; margin-bottom: 8px !important; }
    h3 { font-size: 1rem !important; margin-bottom: 6px !important; }

    .modal-content,
    .purchase-modal-content,
    .inventory-modal-content,
    .customer-modal-content {
        max-height: calc(100dvh - 10px) !important;
    }

    .modal-body,
    .purchase-modal-body,
    .inventory-modal-body,
    .customer-modal-body {
        padding: 12px !important;
    }

    .modal-footer,
    .purchase-modal-footer,
    .inventory-modal-footer,
    .customer-modal-footer {
        padding: 10px 12px max(10px, env(safe-area-inset-bottom)) !important;
        gap: 8px !important;
    }
}

@media (max-width: 480px) {
    html, body {
        font-size: 13px;
    }

    .container,
    .app-container {
        padding-left: 8px;
        padding-right: 8px;
    }

    .card-header,
    .card-body,
    .card-footer {
        padding: 10px;
    }

    .purchase-content,
    .inventory-content,
    .customer-content,
    .reports-content,
    .expenses-content,
    .settings-content,
    .flow-content,
    .offer-content,
    .vendor-content,
    .stall-content,
    .sip-content {
        padding: 10px !important;
        gap: 10px !important;
    }
}

.grid {
    display: grid;
}

.flex {
    display: flex;
}

.gap-0 { gap: 0; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }
.gap-8 { gap: var(--space-8); }

.grid-cols-1 { grid-template-columns: 1fr; }
.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (max-width: 768px) {
    .md\:grid-cols-1 { grid-template-columns: 1fr; }
    .md\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .md\:grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
    .sm\:grid-cols-1 { grid-template-columns: 1fr; }
    .grid-cols-2, .grid-cols-3, .grid-cols-4 { grid-template-columns: 1fr; }
    /* KPI summary tiles stay 2-across on phones instead of a single stack. */
    .grid.kpi-tiles.grid-cols-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }
}

/* ============================================
   CARDS & SECTIONS
   ============================================ */

.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: all 0.2s ease;
}

.card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--slate-300);
}

.card-header {
    padding: var(--space-6);
    border-bottom: 1px solid var(--border-light);
    background: linear-gradient(135deg, var(--primary-from) 0%, var(--primary-to) 100%);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-weight: 600;
    color: #FFFFFF;
}

.card-header i {
    color: #FFFFFF;
    font-size: 1.25rem;
    opacity: 0.9;
}

.card-body {
    padding: var(--space-6);
}

.card-footer {
    padding: var(--space-6);
    border-top: 1px solid var(--border-light);
    background: var(--slate-50);
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
}

.section {
    margin-bottom: var(--space-8);
}

.section-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--slate-900);
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-4);
    border-bottom: 2px solid var(--border-light);
}

/* ============================================
   FORMS
   ============================================ */

.form-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin-bottom: var(--space-6);
}

.form-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--slate-700);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.form-group label .required {
    color: var(--danger-500);
}

.form-control,
input[type="text"],
input[type="number"],
input[type="email"],
input[type="url"],
input[type="tel"],
input[type="password"],
input[type="date"],
input[type="time"],
input[type="search"],
select,
textarea {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.875rem;
    color: var(--text-main);
    box-shadow: var(--shadow-xs);
    transition: all 0.2s ease;
}

.form-control::placeholder,
input::placeholder,
textarea::placeholder {
    color: var(--slate-400);
}

.form-control:hover,
input:hover,
select:hover,
textarea:hover {
    border-color: var(--slate-300);
}

.form-control:focus,
input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary-500);
    outline: none;
    box-shadow: 0 0 0 3px var(--primary-100), var(--shadow-sm);
}

.form-control:disabled,
input:disabled,
select:disabled,
textarea:disabled {
    background: var(--slate-50);
    color: var(--slate-400);
    cursor: not-allowed;
    opacity: 0.6;
}

textarea {
    resize: vertical;
    min-height: 100px;
}

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748B' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-3) center;
    padding-right: calc(var(--space-4) + 20px);
}

.form-hint {
    font-size: 0.75rem;
    color: var(--slate-500);
    margin-top: var(--space-1);
}

.form-error {
    color: var(--danger-600);
    font-size: 0.75rem;
    margin-top: var(--space-1);
}

.form-inline {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-6);
}

/* ============================================
   GLOBAL MINIMAL MODE (ALL PAGES EXCEPT BILLING)
   ============================================ */
html.lio-minimal-ui body {
    background: #f6f8fb;
}

html.lio-minimal-ui .card {
    border-radius: 12px;
    border-color: #e4e9f3;
    box-shadow: none;
}

html.lio-minimal-ui .card:hover {
    box-shadow: none;
    border-color: #d6deea;
}

html.lio-minimal-ui .card-header {
    background: #ffffff;
    color: var(--text-main);
    border-bottom: 1px solid #e8edf6;
}

html.lio-minimal-ui .card-header i {
    color: var(--slate-500);
}

html.lio-minimal-ui .card-body,
html.lio-minimal-ui .card-footer {
    padding: 14px;
}

html.lio-minimal-ui .section-title {
    font-size: 1rem;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid #e8edf6;
}

html.lio-minimal-ui .btn,
html.lio-minimal-ui button {
    border-radius: 10px;
    min-height: 38px;
    box-shadow: none;
}

html.lio-minimal-ui .btn-primary {
    background: #111827;
    border-color: #111827;
}

html.lio-minimal-ui .btn-primary:hover {
    background: #0b1220;
    border-color: #0b1220;
}

html.lio-minimal-ui .btn-secondary {
    background: #fff;
    border-color: #d8e0ec;
}

html.lio-minimal-ui .form-control,
html.lio-minimal-ui input[type="text"],
html.lio-minimal-ui input[type="number"],
html.lio-minimal-ui input[type="email"],
html.lio-minimal-ui input[type="url"],
html.lio-minimal-ui input[type="tel"],
html.lio-minimal-ui input[type="password"],
html.lio-minimal-ui input[type="date"],
html.lio-minimal-ui input[type="time"],
html.lio-minimal-ui input[type="search"],
html.lio-minimal-ui select,
html.lio-minimal-ui textarea {
    border-color: #d7deea;
    box-shadow: none;
    border-radius: 10px;
    padding-top: 9px;
    padding-bottom: 9px;
}

html.lio-minimal-ui .form-control:focus,
html.lio-minimal-ui input:focus,
html.lio-minimal-ui select:focus,
html.lio-minimal-ui textarea:focus {
    border-color: #94a3b8;
    box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.12);
}

@media (max-width: 768px) {
    html.lio-minimal-ui .app-container,
    html.lio-minimal-ui .container {
        padding-left: 10px;
        padding-right: 10px;
    }

    html.lio-minimal-ui .card-body,
    html.lio-minimal-ui .card-footer {
        padding: 11px;
    }

    html.lio-minimal-ui h1 {
        font-size: 1.2rem !important;
    }
}

@media (max-width: 640px) {
    .form-inline {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   BUTTONS
   ============================================ */

.btn,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-6);
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    outline: none;
    text-decoration: none;
    font-family: inherit;
    line-height: 1.5;
    white-space: nowrap;
}

/* Primary Button */
.btn-primary,
button.btn-primary {
    background: linear-gradient(135deg, var(--primary-600) 0%, var(--primary-700) 100%);
    color: white;
    box-shadow: 0 4px 14px rgba(139, 92, 246, 0.3);
}

.btn-primary:hover,
button.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(139, 92, 246, 0.4);
    background: linear-gradient(135deg, #7C3AED 0%, #6D28D9 100%);
}

.btn-primary:active,
button.btn-primary:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.2);
}

/* Secondary Button */
.btn-secondary,
button.btn-secondary {
    background: var(--slate-100);
    color: var(--slate-700);
    border: 1px solid var(--slate-200);
    box-shadow: var(--shadow-xs);
}

.btn-secondary:hover,
button.btn-secondary:hover {
    background: var(--slate-200);
    border-color: var(--slate-300);
    box-shadow: var(--shadow-sm);
}

.btn-secondary:active,
button.btn-secondary:active {
    background: var(--slate-300);
}

/* Danger Button */
.btn-danger,
button.btn-danger {
    background: linear-gradient(135deg, var(--danger-to) 0%, var(--danger-border) 100%);
    color: white;
    box-shadow: 0 4px 14px rgba(239, 68, 68, 0.3);
}

.btn-danger:hover,
button.btn-danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(239, 68, 68, 0.4);
    background: linear-gradient(135deg, #DC2626 0%, #991B1B 100%);
}

.btn-danger:active,
button.btn-danger:active {
    transform: translateY(0);
}

/* Ghost Button */
.btn-ghost {
    background: transparent;
    color: var(--slate-600);
    border: 1px solid transparent;
}

.btn-ghost:hover {
    background: var(--slate-100);
    border-color: var(--slate-200);
}

/* Button Sizes */
.btn-sm {
    padding: var(--space-2) var(--space-4);
    font-size: 0.75rem;
}

.btn-lg {
    padding: var(--space-4) var(--space-8);
    font-size: 1rem;
}

.btn:disabled,
button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* ============================================
   BADGES & LABELS
   ============================================ */

.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--slate-100);
    color: var(--slate-700);
}

.badge-success {
    background: var(--success-100);
    color: var(--success-600);
}

.badge-warning {
    background: var(--warning-100);
    color: var(--warning-600);
}

.badge-danger {
    background: var(--danger-100);
    color: var(--danger-600);
}

.badge-info {
    background: var(--info-100);
    color: var(--info-600);
}

.badge-primary {
    background: var(--primary-100);
    color: var(--primary-600);
}

/* ============================================
   TABLES
   ============================================ */

.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-light);
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-surface);
}

thead {
    background: linear-gradient(135deg, var(--slate-50) 0%, var(--primary-50) 100%);
    border-bottom: 2px solid var(--border-light);
}

thead th {
    padding: var(--space-4) var(--space-6);
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--slate-700);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

tbody td {
    padding: var(--space-4) var(--space-6);
    border-bottom: 1px solid var(--slate-100);
    font-size: 0.875rem;
    color: var(--text-main);
}

tbody tr {
    transition: background-color 0.2s ease;
}

tbody tr:hover {
    background-color: var(--slate-50);
}

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

/* ============================================
   MODALS & OVERLAYS
   ============================================ */

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: max(var(--space-4), env(safe-area-inset-top)) max(var(--space-4), env(safe-area-inset-right)) max(var(--space-4), env(safe-area-inset-bottom)) max(var(--space-4), env(safe-area-inset-left));
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: var(--bg-surface);
    border-radius: var(--radius-2xl);
    width: 100%;
    max-width: 600px;
    max-height: min(90vh, calc(100dvh - 24px));
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-2xl);
    border: 1px solid var(--border-light);
    overflow-y: hidden;
    overflow-x: hidden;
    animation: modal-in 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modal-in {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-content form {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.modal-header {
    padding: var(--space-6);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, var(--primary-from) 0%, var(--primary-to) 100%);
    flex: 0 0 auto;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.25rem;
    color: #FFFFFF;
}

.modal-close {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #FFFFFF;
}

.modal-body {
    padding: var(--space-6);
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}

.modal-footer {
    padding: var(--space-6);
    border-top: 1px solid var(--border-light);
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
    background: var(--slate-50);
    flex: 0 0 auto;
    padding-bottom: max(var(--space-6), env(safe-area-inset-bottom));
}

/* ============================================
   COMMENTS & CHAT
   ============================================ */

.comments-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.comment {
    display: flex;
    gap: var(--space-3);
}

.comment-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-500) 0%, var(--accent-600) 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.comment-content {
    flex: 1;
}

.comment-header {
    display: flex;
    align-items: baseline;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
}

.comment-author {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--slate-900);
}

.comment-time {
    font-size: 0.75rem;
    color: var(--slate-400);
}

.comment-bubble {
    background: var(--slate-50);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-lg);
    font-size: 0.875rem;
    color: var(--text-main);
    line-height: 1.5;
    border: 1px solid var(--border-light);
    word-break: break-word;
}

.comment-form {
    display: flex;
    gap: var(--space-3);
    margin-top: var(--space-4);
    padding-top: var(--space-4);
    border-top: 1px solid var(--border-light);
}

.comment-input-wrapper {
    flex: 1;
}

.comment-form textarea {
    min-height: 80px;
}

.comment-submit {
    padding: var(--space-3) var(--space-4);
    background: linear-gradient(135deg, var(--primary-600) 0%, var(--primary-700) 100%);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
    height: fit-content;
    align-self: flex-end;
}

.comment-submit:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

/* ============================================
   EMPTY STATES
   ============================================ */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-12) var(--space-6);
    color: var(--text-muted);
    text-align: center;
}

.empty-state-icon {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--primary-100);
    color: var(--primary-400);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    margin-bottom: var(--space-6);
}

.empty-state-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--slate-900);
    margin-bottom: var(--space-2);
}

.empty-state-text {
    font-size: 0.875rem;
    color: var(--text-muted);
    max-width: 400px;
    margin-bottom: var(--space-6);
}

/* ============================================
   LOADERS & SPINNERS
   ============================================ */

.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--primary-200);
    border-top-color: var(--primary-600);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-4);
    padding: var(--space-12) var(--space-6);
}

.loader-text {
    font-size: 0.875rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* ============================================
   TOASTS
   ============================================ */

.toast {
    position: fixed;
    bottom: var(--space-6);
    right: var(--space-6);
    z-index: 5000;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-6);
    border-radius: var(--radius-lg);
    background: var(--slate-900);
    color: white;
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: var(--shadow-xl);
    animation: toast-in 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toast.success {
    background: var(--success-600);
}

.toast.warning {
    background: var(--warning-600);
}

.toast.error {
    background: var(--danger-600);
}

.toast.info {
    background: var(--info-600);
}

@keyframes toast-in {
    from {
        transform: translateY(20px) translateX(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0) translateX(0);
        opacity: 1;
    }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.font-medium { font-weight: 500; }
.font-normal { font-weight: 400; }

.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger-600); }
.text-success { color: var(--success-600); }
.text-warning { color: var(--warning-600); }
.text-info { color: var(--info-600); }

.opacity-50 { opacity: 0.5; }
.opacity-75 { opacity: 0.75; }

.rounded { border-radius: var(--radius-md); }
.rounded-lg { border-radius: var(--radius-lg); }
.rounded-xl { border-radius: var(--radius-xl); }
.rounded-2xl { border-radius: var(--radius-2xl); }
.rounded-full { border-radius: var(--radius-full); }

.shadow { box-shadow: var(--shadow-md); }
.shadow-lg { box-shadow: var(--shadow-lg); }
.shadow-xl { box-shadow: var(--shadow-xl); }

.mt-4 { margin-top: var(--space-4); }
.mb-4 { margin-bottom: var(--space-4); }
.mx-auto { margin-left: auto; margin-right: auto; }

.hidden { display: none; }
.block { display: block; }
.inline-block { display: inline-block; }
.inline { display: inline; }

.w-full { width: 100%; }
.max-w-full { max-width: 100%; }

.lio-has-input-icon {
    position: relative;
}

.lio-has-input-icon > .lio-input-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #7c3aed;
    opacity: 0.72;
    font-size: 0.9rem;
    pointer-events: none;
    z-index: 2;
}

.lio-has-input-icon > label + .lio-input-icon {
    top: calc(50% + 12px);
}

.lio-has-input-icon > input:not([type="hidden"]):not([type="radio"]):not([type="checkbox"]),
.lio-has-input-icon > select,
.lio-has-input-icon > textarea {
    padding-left: 42px !important;
}

.lio-has-input-icon:has(> textarea) > .lio-input-icon {
    top: 44px;
    transform: none;
}

.lio-item-identity {
    display: inline-grid;
    grid-template-columns: 42px minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    max-width: 100%;
    vertical-align: middle;
}

.lio-item-identity.compact {
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 8px;
}

.lio-item-identity-copy {
    min-width: 0;
    overflow-wrap: anywhere;
}

.lio-item-image-button {
    width: 42px;
    height: 42px;
    border: 1px solid rgba(139, 92, 246, 0.22);
    border-radius: 8px;
    background: rgba(139, 92, 246, 0.08);
    color: var(--primary-600, #7c3aed);
    display: inline-grid;
    place-items: center;
    padding: 0;
    overflow: hidden;
    cursor: default;
    flex: 0 0 auto;
}

.lio-item-identity.compact .lio-item-image-button {
    width: 34px;
    height: 34px;
}

.lio-item-image-button.has-image {
    cursor: pointer;
    background: #fff;
}

.lio-item-image-button img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.lio-item-image-preview-modal {
    position: fixed;
    inset: 0;
    z-index: 20000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(15, 23, 42, 0.72);
    backdrop-filter: blur(8px);
}

.lio-item-image-preview-modal.show {
    display: flex;
}

.lio-item-image-preview-dialog {
    width: min(92vw, 760px);
    max-height: 92vh;
    background: var(--bg-card, #fff);
    color: var(--text-primary, #111827);
    border: 1px solid var(--border-subtle, #e5e7eb);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 24px 80px rgba(15, 23, 42, 0.35);
}

.lio-item-image-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-subtle, #e5e7eb);
}

.lio-item-image-preview-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 800;
}

.lio-item-image-preview-close {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger-600, #dc2626);
    cursor: pointer;
}

.lio-item-image-preview-body {
    display: grid;
    place-items: center;
    padding: 14px;
    background: rgba(15, 23, 42, 0.04);
}

.lio-item-image-preview-body img {
    max-width: 100%;
    max-height: calc(92vh - 96px);
    object-fit: contain;
    border-radius: 8px;
}

.lio-item-image-preview-fallback {
    min-height: 180px;
    display: grid;
    place-items: center;
    gap: 10px;
    color: var(--text-muted, #64748b);
    font-weight: 700;
}

.lio-item-image-preview-fallback[hidden] {
    display: none !important;
}

.lio-item-image-preview-fallback i {
    font-size: 2rem;
    color: var(--primary-600, #7c3aed);
}

body.theme-dark .lio-item-image-button {
    background: rgba(148, 163, 184, 0.12);
    border-color: rgba(148, 163, 184, 0.28);
    color: #c4b5fd;
}

body.theme-dark .lio-item-image-button.has-image,
body.theme-dark .lio-item-image-preview-dialog {
    background: #0f172a;
    color: #f8fafc;
    border-color: rgba(148, 163, 184, 0.24);
}

body.theme-dark .lio-item-image-preview-body {
    background: #020617;
}

@media (max-width: 768px) {
    .responsive-hide { display: none; }
}

@media (min-width: 768px) {
    .responsive-show { display: none; }
}
