/* GOOGLE ANTIGRAVITY TYPOGRAPHY SYSTEM */
@import url('https://fonts.googleapis.com/css2?family=Google+Sans:wght@400;500;700&display=swap');

:root {
    /* --- ANTIGRAVITY MINIMALIST PALETTE --- */
    --color-bg-primary: #ffffff;
    --color-bg-secondary: #fafafa;
    --color-bg-tertiary: #f5f5f5;

    --color-text-primary: #000000;
    --color-text-secondary: #666666;
    --color-text-tertiary: #999999;

    --color-border: #e5e5e5;
    --color-border-strong: #000000;

    /* Legacy Mappings (Preserving functionality) */
    --bg-dark: var(--color-bg-primary);
    --bg-panel: var(--color-bg-secondary);
    --text-primary: var(--color-text-primary);
    --text-secondary: var(--color-text-secondary);
    --accent: #000000;
    --bg-user-message: var(--color-bg-tertiary);

    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    /* User requested Inter in Home.jsx */
    --font-sans: var(--font-family);
    --font-serif: 'Playfair Display', serif;

    /* Spacing & Sizes */
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --text-3xl: 1.875rem;
    --text-4xl: 2.25rem;
    --text-5xl: 3rem;
}

/* TYPOGRAPHY UTILITIES */
.title-main {
    font-family: var(--font-family) !important;
    font-size: var(--text-5xl);
    /* Removed !important to allow overrides */
    font-weight: var(--font-bold) !important;
    line-height: var(--leading-tight) !important;
    letter-spacing: -0.02em !important;
    white-space: nowrap;
    /* Prevent wrapping globally */
}

@media (max-width: 768px) {
    .title-main {
        font-size: 2.5rem !important;
        /* Force smaller size on mobile */
    }
}

.title-section {
    font-family: var(--font-family) !important;
    font-size: var(--text-3xl) !important;
    font-weight: var(--font-bold) !important;
    line-height: var(--leading-tight) !important;
}

.subtitle {
    font-family: var(--font-family) !important;
    font-size: var(--text-xl) !important;
    font-weight: var(--font-medium) !important;
    line-height: var(--leading-normal) !important;
}

.text-body {
    font-family: var(--font-family) !important;
    font-size: var(--text-base) !important;
    font-weight: var(--font-normal) !important;
    line-height: var(--leading-relaxed) !important;
}

.text-small {
    font-family: var(--font-family) !important;
    font-size: var(--text-sm) !important;
    line-height: var(--leading-normal) !important;
}

/* GLOBAL RESET OVERRIDES */
* {
    font-family: var(--font-family) !important;
}

h1 {
    font-size: var(--text-5xl);
    font-weight: var(--font-bold);
}

h2 {
    font-size: var(--text-3xl);
    font-weight: var(--font-bold);
}

h3 {
    font-size: var(--text-2xl);
    font-weight: var(--font-medium);
}

p {
    font-size: var(--text-base);
    line-height: var(--leading-relaxed);
}

[data-theme="dark"] {
    --color-bg-primary: #0a0a0a;
    --color-bg-secondary: #1a1a1a;
    --color-bg-tertiary: #2a2a2a;

    --color-text-primary: #ffffff;
    --color-text-secondary: #a0a0a0;
    --color-text-tertiary: #707070;

    --color-border: #2a2a2a;
    --color-border-strong: #ffffff;

    /* Legacy Mappings */
    --bg-dark: var(--color-bg-primary);
    --bg-panel: var(--color-bg-secondary);
    --text-primary: var(--color-text-primary);
    --text-secondary: var(--color-text-secondary);
    --accent: #ffffff;
    --bg-user-message: var(--color-bg-tertiary);
}

/* CARD SYSTEM CLASSES */
.card-base {
    border-radius: 0.75rem;
    /* rounded-xl */
    padding: 1.5rem;
    /* p-6 */
    transition: all 0.2s ease;
    width: 100%;
}

.card-base:hover {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    /* hover:shadow-md */
}

/* default: 'bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-800' */
.card-default {
    background-color: var(--color-bg-primary);
    border: 1px solid var(--color-border);
}

/* highlight: 'bg-white dark:bg-gray-900 border-2 border-black dark:border-white' */
.card-highlight {
    background-color: var(--color-bg-primary);
    border: 2px solid var(--color-border-strong);
}

/* subtle: 'bg-gray-50 dark:bg-gray-800/50 border border-gray-100 dark:border-gray-700' */
.card-subtle {
    background-color: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
}

/* ========================================= 
   CHAT INPUT - SINGLE SOURCE OF TRUTH 
   All other #chat-input rules should be deleted
   ========================================= */
#chat-input {
    width: 100%;
    min-height: 50px;
    max-height: 250px;
    padding: 12px 16px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--bg-panel);
    color: var(--text-primary);
    font-size: 16px;
    font-family: var(--font-sans);
    line-height: 1.4;
    resize: none;
    overflow-y: auto;
    box-sizing: border-box;
    /* Height is controlled by JavaScript - never set fixed height here */
}

/* REMOVED: Duplicate .message.user .content - see line 678 for Gemini-style */

* {
    margin: 0;
    padding: 0;
}

/* 🖱️ SCROLLBARS INVISIBLES (Minimalista) */
/* SCROLLBAR Removed to avoid duplication - consolidated in ROOT block */

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: rgba(128, 128, 128, 0.4) transparent;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    font-family: var(--font-sans);
    min-height: 100vh;
    overflow-y: auto;
    /* Allow window scroll */
    overflow-x: hidden;
    transition: background-color 0.2s, color 0.2s;
}

#app {
    display: flex;
    width: 100vw;
    min-height: 100vh;
    overflow: visible;
    /* Use window scroll */
}

/* Scrollbar sutil al final derecha - estilo Antigravity */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.2);
}

.dark ::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
}

.dark ::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.1) transparent;
}

.dark * {
    scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

/* Eliminar scroll interno de contenedores */
.overflow-y-auto {
    overflow-y: visible !important;
}

/* Main Content Area adjustments for window scroll */
.content-wrapper {
    overflow: visible !important;
    height: auto !important;
}

.main-content {
    overflow: visible !important;
    height: auto !important;
}

/* Sidebar (Gemini Style) */
.sidebar {
    width: 250px;
    background: var(--bg-panel);
    border-right: none;
    /* Gemini usually clean */
    box-shadow: none !important;
    /* Remove any shadow that extends beyond sidebar */
    display: flex;
    flex-direction: column;
    padding: 10px 0;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
}

.sidebar.collapsed {
    width: 70px !important;
    min-width: 70px !important;
}

.sidebar.collapsed .brand-text,
.sidebar.collapsed .label,
.sidebar.collapsed .nav-item span,
/* Ensure span text is hidden */
.sidebar.collapsed .system-status .label,
.sidebar.collapsed .system-status small {
    display: none !important;
}

.sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 0;
    width: 48px;
    height: 48px;
    margin: 0 auto 5px auto;
    border-radius: 50%;
    /* Circle hover effect */
}

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   LUCIDE ICONS SYSTEM - Unified Icon Styling
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */

/* Icon Sizes */
.icon-sm,
[data-lucide].icon-sm {
    width: 16px;
    height: 16px;
    stroke-width: 2;
}

.icon-md,
[data-lucide].icon-md {
    width: 20px;
    height: 20px;
    stroke-width: 2;
}

.icon-lg,
[data-lucide].icon-lg {
    width: 24px;
    height: 24px;
    stroke-width: 2;
}

/* Dark Mode Icon Colors */
[data-theme="dark"] [data-lucide],
[data-theme="dark"] .icon {
    color: #ffffff;
    stroke: #ffffff;
}

[data-theme="dark"] .icon-secondary,
[data-theme="dark"] .nav-item:not(.active) [data-lucide] {
    color: #888888;
    stroke: #888888;
}

[data-theme="dark"] .icon-disabled {
    color: #444444;
    stroke: #444444;
    opacity: 0.5;
}

/* Light Mode Icon Colors */
[data-theme="light"] [data-lucide],
[data-theme="light"] .icon {
    color: #000000;
    stroke: #000000;
}

[data-theme="light"] .icon-secondary,
[data-theme="light"] .nav-item:not(.active) [data-lucide] {
    color: #666666;
    stroke: #666666;
}

[data-theme="light"] .icon-disabled {
    color: #cccccc;
    stroke: #cccccc;
    opacity: 0.5;
}

/* Icon Transitions */
[data-lucide] {
    transition: color 0.2s, stroke 0.2s, opacity 0.2s;
}

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */

/* Nav Items */
nav {
    padding: 0 10px;
}

.nav-item {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    text-align: left;
    padding: 0 12px;
    height: 36px;
    margin-bottom: 2px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: 6px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
    overflow: hidden;
    letter-spacing: 0.2px;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

/* 🌗 MONOCHROME SELECTION */
.nav-item.active {
    background-color: rgba(255, 255, 255, 0.1) !important;
    /* Glassy Gray */
    color: #ffffff !important;
    border-left: 3px solid #ffffff !important;
    /* Pure White Indicator */
    border-radius: 0 6px 6px 0;
    /* Align with border-left */
    font-weight: 600;
}

/* ☀️ LIGHT MODE MENU FIX */
[data-theme="light"] .nav-item.active {
    background-color: rgba(0, 0, 0, 0.05) !important;
    /* Subtle Dark Tint */
    color: #000000 !important;
    /* Black Text */
    border-left: 3px solid #000000 !important;
    /* Black Indicator */
}

/* --- PRICING GRID --- */
.pricing-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    /* FORCE 3 COLUMNS */
    gap: 1.5rem;
    padding: 1rem;
    max-width: 1200px;
    margin: 0 auto;
}

.sidebar-header {
    overflow-x: visible !important;
    overflow-y: visible !important;
    width: 250px !important;
    /* Match sidebar width exactly */
    max-width: 250px !important;
    box-shadow: none !important;
    /* Remove shadow that extends beyond sidebar */
    background: inherit !important;
    /* Inherit from sidebar which has var(--bg-panel) */
}

.brand-text {
    overflow: visible !important;
    white-space: nowrap !important;
    width: auto !important;
    max-width: none !important;
    flex-shrink: 0 !important;
}

/* Mobile Menu Button - Antigravity monochrome (gray, not black) */
#mobile-menu-btn,
.mobile-only {
    outline: none !important;
    border: none !important;
    box-shadow: none !important;
    -webkit-tap-highlight-color: transparent !important;
    background: transparent !important;
    color: var(--text-secondary) !important;
    /* Gray instead of black */
}

#mobile-menu-btn:focus,
#mobile-menu-btn:active,
.mobile-only:focus,
.mobile-only:active {
    outline: none !important;
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
    color: var(--text-secondary) !important;
    /* Gray instead of black */
}

#mobile-menu-btn svg,
.mobile-only svg {
    stroke: var(--text-secondary) !important;
    /* Gray strokes */
}

@media (max-width: 768px) {
    .pricing-grid {
        grid-template-columns: 1fr;
        /* Stack on mobile */
    }

    /* Ensure logo is fully visible on mobile */
    .sidebar-header {
        padding: 0 10px !important;
        gap: 8px !important;
    }

    .brand-text {
        font-size: 0.95rem !important;
        letter-spacing: -0.3px !important;
    }
}

.pricing-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
    text-align: center;
    position: relative;
    display: flex;
    flex-direction: column;
}

.pricing-card.pro {
    border-color: var(--text-primary);
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
}

.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 100px;
    font-size: 0.7rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

/* --- CASE CARDS RESTORATION --- */
.cases-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
    padding: 1rem;
}

.case-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.5rem;
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
}

.case-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    border-color: var(--text-secondary);
}

.case-card h3 {
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.case-card .meta {
    font-size: 0.85rem;
    color: var(--text-secondary);
    display: flex;
    gap: 10px;
}

/* --- CHAT BUTTON VISIBILITY FIX --- */
.chat-input-container {
    background: var(--bg-panel) !important;
}

/* SEND BUTTON styles moved to line 754 - SINGLE SOURCE OF TRUTH */

.attach-btn {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background-color: var(--bg-panel) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border) !important;
}

.attach-btn svg {
    width: 24px;
    height: 24px;
    display: block;
}

/* Attach button SVG uses stroke */
.attach-btn svg path {
    stroke: currentColor;
    stroke-width: 2px;
}

[data-theme="dark"] .nav-item.active {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

/* Main Content Area */
.main-content {
    background: var(--bg-dark);
}

/* View Container - Centered Content like Gemini */
#view-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 2rem;
    width: 100%;
}

/* Status Indicator */
.system-status {
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 10px;
    border-top: 1px solid var(--border);
    margin-top: auto;
    color: var(--text-secondary);
}

/* Gemini Top Bar Profile */
.profile-pill {
    background: var(--accent);
    color: var(--bg-dark);
    padding: 8px 20px;
    border-radius: 100px;
    font-weight: 600;
    font-size: 0.9rem;
    border: none;
    cursor: pointer;
    transition: transform 0.2s;
}

.profile-pill:hover {
    transform: scale(1.05);
}

.user-avatar-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid var(--border);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    background: var(--bg-panel);
    color: var(--text-primary);
    overflow: hidden;
}

/* Modal Backdrop */
dialog::backdrop {
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.system-status {
    border-top: 1px solid var(--border);
    padding-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.status-indicator {
    width: 8px;
    height: 8px;
    background: var(--text-primary);
    border-radius: 50%;
    display: inline-block;
    margin-right: 5px;
    box-shadow: 0 0 5px rgba(255, 255, 255, 0.5);
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
}

.view-header {
    margin-bottom: 1.5rem;
    border: none;
    /* CLEAN LOOK - No lines */
    padding-bottom: 0.5rem;
    padding-right: 60px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.view-header h2 {
    font-family: var(--font-sans);
    font-weight: 500;
    font-size: 1.5rem;
    letter-spacing: -0.5px;
    color: var(--text-primary);
}

/* Dashboard */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 3rem;
}

.stat-card {
    background: var(--bg-panel);
    padding: 1rem;
    border-radius: 8px;
    border: none;
    /* Removed border */
    /* border: 1px solid var(--border); */
}

.stat-card h3 {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.stat-card .value {
    font-size: 2rem;
    /* Reduced from 2.5rem */
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -1px;
}

.stat-card.highlight .value {
    color: var(--accent);
}

/* Pricing Card Minimalist */
.pricing-card {
    background: var(--bg-panel);
    padding: 2rem;
    border-radius: 16px;
    /* Slightly more rounded for substantial items */
    border: none;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
}

.pricing-card.featured {
    background: var(--bg-panel);
    position: relative;
    box-shadow: 0 4px 40px rgba(0, 0, 0, 0.1);
    border-top: 4px solid var(--accent);
}

.pricing-amount {
    font-size: 2rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -1px;
}

/* Chat View */
.chat-view {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-height: 80vh;
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* =========================================
   CHAT MESSAGES - GEMINI STYLE (Full Width)
   ========================================= */
.message {
    display: flex;
    gap: 0.75rem;
    width: 100%;
    max-width: 100%;
    padding: 0.5rem 0;
}

.message.user {
    flex-direction: row-reverse;
}

.message .avatar {
    width: 32px;
    height: 32px;
    min-width: 32px;
    background: var(--accent);
    color: var(--bg-dark);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.75rem;
}

.message.user .avatar {
    background: #555;
    color: #fff;
}

.message .content {
    flex: 1;
    background: var(--bg-panel);
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    line-height: 1.6;
    font-size: 0.95rem;
    color: var(--text-primary);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}



.message.user .content {
    text-align: right;
    color: var(--text-secondary);
}

.chat-input-area {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
}

/* ========================================= 
   SEND BUTTON - SINGLE SOURCE OF TRUTH 
   All other #send-btn and .send-btn rules should be deleted
   ========================================= */
/* ========================================= 
   SEND BUTTON - SINGLE SOURCE OF TRUTH 
   All other #send-btn and .send-btn rules should be deleted
   ========================================= */
#send-btn,
.send-btn {
    width: 48px;
    height: 48px;
    padding: 0;
    /* DEFAULT / DARK MODE (Black/Grey) */
    background: #2d2d2d !important;
    color: white !important;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: all 0.2s ease;
}

#send-btn:hover,
.send-btn:hover {
    background: #3d3d3d !important;
}

/* Light Mode Override */
[data-theme="light"] #send-btn,
[data-theme="light"] .send-btn {
    background: #1a1a1a !important;
    color: white !important;
}

[data-theme="light"] #send-btn:hover,
[data-theme="light"] .send-btn:hover {
    background: #2d2d2d !important;
}

#send-btn svg,
.send-btn svg {
    width: 24px;
    height: 24px;
    fill: white !important;
    stroke: none !important;
}

#send-btn svg path,
.send-btn svg path {
    fill: white !important;
    stroke: none !important;
}

/* ========== TARJETAS BASE (todas las secciones) ========== */

/* Shared Base Styles */
.case-card,
.rule-card,
.expert-card {
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    transition: all 0.2s ease;
    cursor: pointer;
}

/* Modo claro - Tarjetas */
[data-theme="light"] .case-card,
[data-theme="light"] .rule-card,
[data-theme="light"] .expert-card {
    background: #f8f9fa !important;
    border: 1px solid #e5e7eb !important;
}

[data-theme="light"] .case-card:hover,
[data-theme="light"] .rule-card:hover,
[data-theme="light"] .expert-card:hover {
    border-color: #cbd5e1 !important;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

/* Modo oscuro - Tarjetas */
[data-theme="dark"] .case-card,
[data-theme="dark"] .rule-card,
[data-theme="dark"] .expert-card,
/* Fallback/Default if no theme attr */
.case-card,
.rule-card,
.expert-card {
    background: #1a1a1a !important;
    border: 1px solid #2d2d2d !important;
}

[data-theme="dark"] .case-card:hover,
[data-theme="dark"] .rule-card:hover,
[data-theme="dark"] .expert-card:hover,
.case-card:hover,
.rule-card:hover,
.expert-card:hover {
    border-color: #3d3d3d !important;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

/* Cases Grid used in Cases View */
.cases-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

/* Specific Content Styles inside cards */
.case-card h3,
.rule-card h3,
.expert-card h3 {
    margin-bottom: 0.25rem;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.case-card h4 {
    margin-bottom: 1rem;
    font-weight: 500;
    font-family: var(--font-sans);
    letter-spacing: -0.2px;
}

/* ========== ICONOS EXPERTO ========== */

.expert-avatar,
.expert-icon {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
}

/* Icono de experto - Modo claro */
[data-theme="light"] .expert-avatar,
[data-theme="light"] .expert-icon {
    background: #1a1a1a !important;
    color: white !important;
    border: 2px solid #e5e7eb !important;
}

/* Icono de experto - Modo oscuro */
[data-theme="dark"] .expert-avatar,
[data-theme="dark"] .expert-icon,
.expert-avatar,
.expert-icon {
    background: #2d2d2d !important;
    color: white !important;
    border: 2px solid #3d3d3d !important;
}

/* Si el icono es SVG, aplicar también */
[data-theme="light"] .expert-avatar svg,
[data-theme="light"] .expert-icon svg {
    fill: #1a1a1a !important;
}

[data-theme="dark"] .expert-avatar svg,
[data-theme="dark"] .expert-icon svg,
.expert-avatar svg,
.expert-icon svg {
    fill: white !important;
}

.case-card p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    /* Reduced lines */
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.4;
}

/* Markdown formatting in chat */
.content strong {
    color: var(--accent);
}

.content blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 1rem;
    margin: 1rem 0;
    color: var(--text-secondary);
    font-style: italic;
}

/* =========================================
   MOBILE RESPONSIVENESS (Max Width 768px)
   ========================================= */
@media (max-width: 768px) {

    /* 1. LAYOUT RESET */
    #app {
        flex-direction: column;
        height: auto;
        /* Allow scrolling */
        overflow-y: auto;
    }

    body {
        overflow-y: auto;
        /* Unlock scroll */
        height: auto;
    }

    .content-wrapper {
        width: 100%;
        height: auto;
        overflow: visible;
    }

    /* 2. SIDEBAR - Hidden by default, Overlay when toggled */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        width: 280px !important;
        /* Force width */
        z-index: 9999;
        transform: translateX(-100%);
        /* Start hidden */
        box-shadow: none;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    /* When toggled (class 'collapsed' added via JS), we SHOW it on mobile */
    /* Note: We invert the meaning of 'collapsed' for mobile for code simplicity */
    .sidebar.collapsed {
        transform: translateX(0);
        /* Slide in */
        box-shadow: 5px 0 15px rgba(0, 0, 0, 0.5);
    }

    /* FIX: Force labels to show when open on mobile */
    .sidebar.collapsed .brand-text,
    .sidebar.collapsed .label,
    .sidebar.collapsed .system-status .label,
    .sidebar.collapsed .system-status small {
        display: block !important;
    }

    .sidebar.collapsed .nav-item {
        justify-content: flex-start !important;
        padding: 0 16px !important;
        width: auto !important;
        margin: 0 0 4px 0 !important;
        border-radius: 24px !important;
    }

    /* Overlay Effect when sidebar matches .collapsed */
    .sidebar.collapsed::before {
        content: '';
        position: fixed;
        top: 0;
        left: 280px;
        width: 100vw;
        height: 100vh;
        background: rgba(0, 0, 0, 0.5);
        display: block;
        pointer-events: none;
        /* simple backdrop visual */
    }

    /* 3. GRIDS - Stack Vertically */
    .pricing-grid {
        grid-template-columns: 1fr !important;
    }

    .stats-grid,
    .cases-grid {
        grid-template-columns: 1fr !important;
    }

    .admin-view .stats-grid {
        grid-template-columns: 1fr 1fr !important;
        /* 2 cols for admin stats ok */
    }

    .admin-view div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
        /* Stack Admin tables */
    }

    /* 4. TEXT & PADDING - Natural content flow */
    #view-container {
        padding: 1rem;
        max-width: 100%;
        /* Removed excessive padding-bottom - content flows naturally */
    }

    /* 5. TYPOGRAPHY SCALING (Luxury Standard) */
    .stat-card .value,
    .pricing-amount {
        font-size: 1.5rem !important;
        /* 24px - Balanced */
        letter-spacing: -0.5px !important;
    }

    .view-header h2 {
        font-size: 1.25rem !important;
        /* 20px */
        letter-spacing: -0.2px !important;
    }


    /* Mobile Header Adjustments */
    .view-header {
        padding-right: 0;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    /* Mobile Chat Input */
    .chat-input-area {
        flex-direction: row;
        /* Keep row for button + input */
        gap: 0.5rem;
    }

    /* REMOVED: Duplicate #chat-input */
    /* REMOVED: Duplicate #send-btn - see line 732 */

    /* Mobile Menu Toggle Logic */
    .mobile-only {
        display: flex !important;
    }
}


/* =========================================
   MOBILE OVERRIDES PART 2 (The Missing Block)
   ========================================= */
@media (max-width: 768px) {

    /* 5. FIX THEME TOGGLE POSITION ON MOBILE */
    /* 5. FIX THEME TOGGLE POSITION ON MOBILE */
    .theme-toggle {
        right: 5rem !important;
        /* Move further left */
        top: 1rem !important;
        width: 36px !important;
        height: 36px !important;
        border: none !important;
    }

    /* 6. DASHBOARD SPLIT - Stack Vertically */
    .dashboard-split {
        display: block !important;
        grid-template-columns: 1fr !important;
    }

    .context-column {
        display: none !important;
        /* Hide context column on mobile to simplify scrolling */
    }

    /* 7. CHAT LAYOUT FIXES (Nuclear Option) */
    /* 7. SCROLL LOCK FIX (NUCLEAR) */
    /* 7. SCROLL LOCK FIX (NUCLEAR) */
    #app,
    .content-wrapper,
    .main-content,
    .chat-view,
    #view-container {
        height: auto !important;
        min-height: 100% !important;
        /* Ensure it fills at least screen */
        max-height: none !important;
        overflow: visible !important;
        flex: none !important;
        display: block !important;
        /* Kill flex constraints on wrappers */
        padding-bottom: 58px !important;
        /* SUPER TIGHT: Input(50) + Pad(8) */
    }



    .chat-history {
        overflow-y: visible !important;
        /* Let body scroll */
        height: auto !important;
        flex: none !important;
    }

    /* Fixed Input Area at Bottom */
    .chat-input-area {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        width: 100% !important;
        background: var(--bg-panel) !important;
        padding: 8px 12px !important;
        border-top: 1px solid var(--border) !important;
        z-index: 9999 !important;
        display: flex !important;
        flex-direction: row !important;
        align-items: flex-end !important;
        /* GEMINI STYLE: Cross at bottom */
        gap: 8px !important;
    }

    /* REMOVED: Heavy #chat-input override - now using single source at line 162 */

    #btn-upload {
        flex: 0 0 44px !important;
        /* Fixed width */
        width: 44px !important;
        height: 44px !important;
        margin: 0 !important;
    }

    /* REMOVED: Duplicate #send-btn - single source at line 732 */

    /* View container - natural content flow, no artificial padding */
    #view-container {
        padding-bottom: 0 !important;
        height: auto !important;
        overflow: visible !important;
    }
}



/* ==========================================================================
   PHASE 41: FRONTEND RECONSTRUCTION (UX/UI OVERHAUL)
   ========================================================================== */

/* --- GLOBAL RESET & MOBILE FIXES --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    width: 100%;
    overflow-x: hidden;
}

body {
    min-height: 100vh;
    min-height: -webkit-fill-available;
    /* iOS fix */
    background: var(--bg-dark);
    color: var(--text-primary);
}

#app {
    min-height: 100vh;
    min-height: -webkit-fill-available;
    display: flex;
    flex-direction: column;
}

.main-container {
    flex: 1;
    display: flex;
    min-height: 0;
}

.content-wrapper {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    height: 100vh;
    /* Restore height to allow internal scroll */
}

/* FIX para iOS - evita espacio inferior */
@supports (-webkit-touch-callout: none) {
    body {
        min-height: -webkit-fill-available;
    }
}

/* --- HOME PAGE (Welcome) --- */
.welcome-container {
    min-height: 90vh;
    /* Adjust for internal view */
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--bg-panel) 0%, var(--bg-dark) 100%);
    padding: 2rem;
}

.welcome-content {
    max-width: 600px;
    width: 100%;
    /* Ensure width on mobile */
    text-align: center;
    background: var(--bg-panel);
    padding: 3rem;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
}

.logo-section {
    margin-bottom: 2.5rem;
}

.logo-icon svg {
    width: 80px;
    height: 80px;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.main-title {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    letter-spacing: -0.5px;
    font-family: 'Playfair Display', serif;
}

.subtitle {
    font-size: 1.1rem;
    color: var(--text-secondary);
    font-weight: 400;
}

.stats-section {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.5rem;
    margin: 2rem 0;
    padding: 1.5rem;
    background: var(--bg-dark);
    border-radius: 12px;
    border: 1px solid var(--border);
}

.stat-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.stat-number {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
}

.stat-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-divider {
    font-size: 1.5rem;
    color: var(--border);
}

.objective-section {
    margin: 2rem 0;
}

.objective-text {
    font-size: 1.1rem;
    line-height: 1.6;
    color: var(--text-primary);
}

.cta-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 2.5rem;
}

.btn-primary,
.btn-secondary {
    padding: 1rem 2rem;
    font-size: 1.1rem;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
    width: 100%;
}

.btn-primary {
    background: var(--text-primary);
    color: var(--bg-dark);
}

.btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-secondary {
    background: transparent;
    color: var(--text-primary);
    border: 2px solid var(--text-primary);
}

.btn-secondary:hover {
    background: var(--text-primary);
    color: var(--bg-dark);
    transform: translateY(-2px);
}

/* --- DASHBOARD HEADERS --- */
.dashboard-header {
    text-align: center;
    margin-bottom: 3rem;
    padding: 2rem 0;
}

.dashboard-title {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    font-family: 'Playfair Display', serif;
    white-space: nowrap;
    /* Prevent wrapping */
}

@media (max-width: 768px) {
    .dashboard-title {
        font-size: 1.75rem !important;
        /* Reduce size for mobile */
        white-space: nowrap;
    }
}

.dashboard-subtitle {
    font-size: 1.1rem;
    color: var(--text-secondary);
}

.section-title {
    text-align: center;
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

/* --- CHAT INPUT OVERHAUL --- */
/* --- CHAT INPUT OVERHAUL --- */
.chat-input-container {
    position: fixed;
    bottom: 0;
    left: 280px;
    /* Sidebar width matching .sidebar */
    right: 0;
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
    padding: 1rem;
    display: flex;
    gap: 0.75rem;
    align-items: center;
    /* Center items vertically */
    z-index: 100;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    transition: left 0.3s ease;
    /* Smooth transition if sidebar collapses */
}

/* Mobile Constraint moved to media query block or handled by specificity */
@media (max-width: 768px) {
    .chat-input-container {
        left: 0 !important;
    }
}

.attach-btn {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--bg-dark);
    color: var(--text-secondary);
}

/* REMOVED: Duplicate .send-btn - single source at line 732 */

.chat-textarea {
    flex: 1;
    border: 1px solid var(--border);
    background: var(--bg-dark);
    color: var(--text-primary);
    border-radius: 22px;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    font-family: inherit;
    resize: none;
    outline: none;
    min-height: 44px;
    max-height: 200px;
    overflow-y: auto;
    line-height: 1.5;
}

.chat-textarea:focus {
    border-color: var(--accent);
}

/* --- SIDEBAR STICKY --- */
@media (min-width: 769px) {
    .sidebar {
        position: sticky !important;
        top: 0;
        height: 100vh;
        width: 280px;
        background: var(--bg-panel);
        border-right: 1px solid var(--border);
        display: flex;
        flex-direction: column;
        overflow-y: auto;
    }
}

/* --- MOBILE SPECIFIC RESPONSIVE --- */
@media (max-width: 768px) {
    .welcome-content {
        padding: 2rem 1.5rem;
    }

    .main-title {
        font-size: 2rem;
    }

    .stats-section {
        flex-wrap: wrap;
        gap: 1rem;
    }

    .stat-divider {
        display: none;
    }

    .chat-input-container {
        padding: 0.75rem;
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
    }

    .attach-btn {
        width: 40px;
        height: 40px;
    }

    /* send-btn size controlled at line 732 */

    /* Mobile Sidebar Transition */
    .sidebar {
        position: fixed;
        left: -280px;
        transition: left 0.3s ease;
        z-index: 1000;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.5);
        background: var(--bg-panel);
        height: 100%;
        top: 0;
    }

    .sidebar.open,
    .sidebar.active {
        left: 0 !important;
        transform: translateX(0) !important;
        /* TRAER AL CENTRO */
        display: flex !important;
        /* Force flex for layout */
        visibility: visible !important;
        opacity: 1 !important;
        z-index: 1000001 !important;
        /* Encima del overlay */
    }

    /* Overlay */
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        display: none;
    }

    .sidebar-overlay.active {
        display: block !important;
        opacity: 1 !important;
        background: rgba(0, 0, 0, 0.7) !important;
        z-index: 1000000 !important;
        /* Justo debajo del menú */
        pointer-events: auto !important;
    }

    .sidebar-overlay.active {
        display: block;
    }

    /* Mobile Menu Button */
    /* 🛡️ MOBILE MENU RESCUE (Brute Force V2) */
    .app-top-bar {
        position: sticky !important;
        top: 0 !important;
        z-index: 99999 !important;
        /* Force Header Above All */
    }

    button#mobile-menu-btn,
    .mobile-menu-btn {
        display: flex !important;
        z-index: 100000 !important;
        /* Button even higher */
        pointer-events: auto !important;
        cursor: pointer !important;
    }

    .menu-toggle,
    .mobile-menu-btn,
    button[aria-label="Menu"] {
        position: fixed !important;
        /* Fixed is required for floating over content */
        top: 15px !important;
        left: 15px !important;
        z-index: 999999 !important;
        /* High Z-Index */
        pointer-events: auto !important;
        /* Force Clicks */
        cursor: pointer !important;
        background: var(--bg-panel);
        border: 1px solid var(--border);
        border-radius: 8px;
        width: 44px;
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.5rem;
        color: var(--text-primary);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    }

    /* Ensure nothing covers it */
    .mobile-menu-btn svg {
        pointer-events: none;
    }

    /* 📂 SIDEBAR Z-INDEX SUPREMACY */
    .sidebar,
    .sidebar.open,
    .mobile-menu-overlay,
    .sidebar-overlay {
        z-index: 1000000 !important;
        /* Higher than button */
    }

    /* Ensure nothing covers it */
    .mobile-menu-btn svg {
        pointer-events: none;
        /* Let clicks pass to button */
    }

    .app-top-bar {
        display: flex !important;
        /* Restore Visibility */
        position: fixed !important;
        top: 0;
        left: 0;
        right: 0;
        z-index: 99 !important;
        background: var(--bg-panel);
        border-bottom: 1px solid var(--border);
        height: 60px !important;
        padding-top: env(safe-area-inset-top);
    }

    /* Adjust Main Content to not hide behind header */
    .main-content {
        margin-top: 60px !important;
        padding-top: 1rem !important;
    }

    /* Move Mobile Toggle to Left of Header */
    #mobile-menu-btn {
        display: flex !important;
        margin-right: auto;
        /* Push everything else right */
    }

    /* Hide floating button since we have header button now */
    .mobile-menu-btn {
        display: none !important;
    }
}

/* End of File Style Overrides */

/* --- CRITICAL CHAT FIXES (Step 675) --- */

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding-bottom: 2rem;
}

/* REMOVED: Duplicate .message styles - see line 678 for Gemini-style single source */

/* Keep word-wrap fix for Safari */
.message .content {
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
}

/* High Contrast Text Fix */
.message .content strong {
    font-weight: 700;
    color: var(--text-primary);
}

/* --- MOBILE INPUT UX (GEMINI STYLE - ICONS BELOW) --- */
@media (max-width: 768px) {

    /* Input Container - Fixed to bottom, stacked layout */
    .chat-input-container {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        padding: 12px 16px !important;
        padding-bottom: calc(12px + env(safe-area-inset-bottom)) !important;
        background: var(--bg-panel) !important;
        border-top: 1px solid var(--border) !important;
        z-index: 1000 !important;
    }

    /* Form - Full width, column layout */
    #chat-form {
        width: 100% !important;
        max-width: none !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 8px !important;
        background: transparent !important;
        border: none !important;
        padding: 0 !important;
    }

    /* REMOVED: Duplicate #chat-input - single source at line 162 */

    /* Icons Row - Below the input */
    .chat-input-actions {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        padding: 0 4px !important;
    }

    /* Upload Button - Left side */
    #btn-upload {
        display: flex !important;
        width: 44px !important;
        height: 44px !important;
        border-radius: 50% !important;
        background: var(--bg-dark) !important;
        border: 1px solid var(--border) !important;
        color: var(--text-secondary) !important;
        align-items: center !important;
        justify-content: center !important;
    }

    #btn-upload svg {
        width: 22px !important;
        height: 22px !important;
    }

    /* REMOVED: Duplicate #send-btn - single source at line 732 */

    /* Message container - Just enough for input bar */
    .chat-messages {
        padding-bottom: 80px !important;
    }

    /* Header Fixes */
    #profile-section {
        display: flex !important;
        transform: scale(0.85);
    }

    .desktop-only {
        display: none !important;
    }

    /* All view templates - reduce bottom empty space */
    .content-wrapper,
    .dashboard-view,
    .cases-explorer-view,
    .knowledge-base-view,
    .rules-panel-view,
    .expert-wisdom-view,
    .pricing-view {
        padding-bottom: 20px !important;
        min-height: auto !important;
    }
}

/* ========== CORRECCIONES FINALES (USER REQUEST) ========== */

/* 1. ICONOS DE EXPERTO - FUERZA BRUTA (Blanco/Negro) */
.expert-avatar,
.expert-icon,
[class*="expert"] svg,
[class*="Expert"] svg {
    background: #2d2d2d !important;
    color: white !important;
    fill: white !important;
    border: none !important;
    /* Reset borders to avoid purple leaks if any */
}

/* Modo claro */
[data-theme="light"] .expert-avatar,
[data-theme="light"] .expert-icon,
[data-theme="light"] [class*="expert"] svg,
[data-theme="light"] [class*="Expert"] svg {
    background: #1a1a1a !important;
    color: white !important;
    fill: white !important;
}

/* SVG Inline fix */
svg[class*="user"],
svg[class*="person"],
svg[fill="#a855f7"],
svg[fill="#8b5cf6"],
svg[fill="purple"] {
    fill: white !important;
}

[data-theme="light"] svg[class*="user"],
[data-theme="light"] svg[class*="person"] {
    fill: #1a1a1a !important;
}


/* 2. TARJETAS CHAT - AJUSTE DE COLORES */
/* Mensajes del sistema */
.chat-message.system,
.message-system,
[class*="system-message"],
.message {
    /* General message container fallback */
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
}

[data-theme="light"] .chat-message.system,
[data-theme="light"] .message-system,
[data-theme="light"] [class*="system-message"],
[data-theme="light"] .message {
    background: transparent !important;
    border: none !important;
}

/* Mensajes del usuario (Override) */
.chat-message.user,
.message-user,
.message.user,
[class*="user-message"] {
    background: transparent !important;
    border: none !important;
}

[data-theme="light"] .chat-message.user,
[data-theme="light"] .message-user,
[data-theme="light"] .message.user,
[data-theme="light"] [class*="user-message"] {
    background: transparent !important;
    border: none !important;
}


/* 3. HEADER - ICONOS GRISES Y FIJOS */
/* Header - Contenedor fijo */
.header,
[class*="header"],
header,
.app-top-bar {
    /* Adding specific class from index.html */
    position: sticky !important;
    top: 0 !important;
    z-index: 1000 !important;
    background: var(--bg-dark) !important;
    border-bottom: 1px solid var(--border) !important;
}

/* Header - Iconos grises */
.header svg,
.header button,
.header-icon,
.theme-toggle,
.profile-icon,
.level-badge,
.app-top-bar button,
.app-top-bar svg {
    color: #9ca3af !important;
    fill: #9ca3af !important;
}

/* Header - Hover de iconos */
.header svg:hover,
.header button:hover,
.theme-toggle:hover,
.profile-icon:hover,
.app-top-bar button:hover,
.app-top-bar svg:hover {
    color: #d1d5db !important;
    fill: #d1d5db !important;
}

/* Modo claro - Iconos grises también */
[data-theme="light"] .header svg,
[data-theme="light"] .header button,
[data-theme="light"] .theme-toggle,
[data-theme="light"] .profile-icon,
[data-theme="light"] .level-badge,
[data-theme="light"] .app-top-bar button,
[data-theme="light"] .app-top-bar svg {
    color: #6b7280 !important;
    fill: #6b7280 !important;
}

[data-theme="light"] .header svg:hover,
[data-theme="light"] .header button:hover,
[data-theme="light"] .theme-toggle:hover,
[data-theme="light"] .profile-icon:hover,
[data-theme="light"] .app-top-bar button:hover,
[data-theme="light"] .app-top-bar svg:hover {
    color: #4b5563 !important;
    fill: #4b5563 !important;
}

/* Badge de nivel - Gris con texto */
.level-badge,
[class*="nivel"],
[class*="NIVEL"] {
    background: #2d2d2d !important;
    color: #fbbf24 !important;
    border: 1px solid #3d3d3d !important;
}

[data-theme="light"] .level-badge,
[data-theme="light"] [class*="nivel"],
[data-theme="light"] [class*="NIVEL"] {
    background: #f3f4f6 !important;
    color: #f59e0b !important;
    border: 1px solid #e5e7eb !important;
}

/* Avatar de perfil - Gris */
.profile-avatar,
.header img[alt*="profile"],
.header img[alt*="Profile"],
.user-avatar-btn {
    border: 2px solid #2d2d2d !important;
}

[data-theme="light"] .profile-avatar,
[data-theme="light"] .header img[alt*="profile"],
[data-theme="light"] .user-avatar-btn {
    border: 2px solid #e5e7eb !important;
}

/* Botón tema - Sin color de fondo */
.theme-toggle,
.theme-toggle-header {
    background: transparent !important;
}

/* ========== CORRECCIONES CRÍTICAS FINALES REVERTED ========== */

/* --- ROBUST VISUAL FIXES (FINAL) --- */

/* 1. Header Fix - Sticky & Safe (Desktop + Mobile) */
.app-top-bar,
.header {
    position: sticky !important;
    top: 0 !important;
    z-index: 1100 !important;
    /* Above sidebar (1000) */
    background: var(--bg-dark) !important;
    border-bottom: 1px solid var(--border) !important;
    width: 100% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    transition: background 0.3s ease;
}

/* Ensure header content doesn't shrink/cut */
.header-right,
.header-icons,
.app-top-bar>div {
    flex-shrink: 0 !important;
    display: flex !important;
    align-items: center !important;
    gap: 1rem !important;
}

/* 2. Dashboard Title - Center Alignment */
.dashboard-title,
.landing-title {
    text-align: center !important;
    width: 100%;
}

/* 3. Expert Icons - Geminified (Black/White/Grey) */
.expert-avatar,
.expert-icon,
[class*="expert"] .avatar {
    background: #2d2d2d !important;
    /* Dark Grey */
    color: white !important;
    border: 2px solid #3d3d3d !important;
    box-shadow: none !important;
    /* Flatten */
}

/* Light Mode */
[data-theme="light"] .expert-avatar,
[data-theme="light"] .expert-icon {
    background: #f3f4f6 !important;
    /* Light Grey */
    color: #1a1a1a !important;
    /* Dark Text */
    border: 2px solid #e5e7eb !important;
}

/* Force SVG colors (Kill Purple) */
.expert-avatar svg,
.expert-icon svg,
[class*="expert"] svg {
    fill: white !important;
}

[data-theme="light"] .expert-avatar svg,
[data-theme="light"] .expert-icon svg {
    fill: #1a1a1a !important;
}

/* Global Purple Cleaner */
svg[fill*="purple"],
svg[fill*="#a855f7"],
svg[fill*="#8b5cf6"] {
    fill: currentColor !important;
    /* Inherit parent color */
}

/* 4. Level Badge - Minimalist */
.level-badge,
[class*="nivel"] {
    background: #2d2d2d !important;
    color: #fbbf24 !important;
    /* Gold text ok for status */
    border: 1px solid #3d3d3d !important;
    font-weight: 600 !important;
}

[data-theme="light"] .level-badge,
[data-theme="light"] [class*="nivel"] {
    background: #fff !important;
    color: #f59e0b !important;
    border: 1px solid #e5e7eb !important;
}

/* --- UNIVERSAL VIEW SPACING FIX (ROBUST V4) --- */
/* Ensures all views clear the sticky/fixed header properly */
.dashboard-view,
.cases-view,
.rules-view,
.expert-wisdom-view,
.pricing-view,
.knowledge-base-view {
    padding-top: 100px !important;
    /* 60px Header + 40px Buffer */
    padding-left: 2rem;
    padding-right: 2rem;
    box-sizing: border-box !important;
    width: 100%;
}

/* STICKY PAGE TITLES (User Request) */
/* Titles stick below the main app header */
.dashboard-header {
    position: sticky !important;
    top: 60px !important;
    /* height of app-top-bar */
    z-index: 900 !important;
    background: var(--bg-dark) !important;
    /* Prevent text overlap */
    margin-bottom: 2rem !important;
    text-align: center !important;
    width: 100%;
    padding-bottom: 1rem;
    padding-top: 1rem;
    /* Extra buffer */
}

/* Dashboard Specific: Adjust split height to avoid double scrolls */
@media (min-width: 1024px) {
    .dashboard-split {
        /* 100vh - Header(60) - PaddingTop(100) - PaddingBottom(20) */
        height: calc(100vh - 180px) !important;
        overflow: hidden !important;
    }
}

.dashboard-title {
    margin-top: 0 !important;
    line-height: 1.2 !important;
}

/* Mobile Adjustments */
@media (max-width: 768px) {

    .dashboard-view,
    .cases-view,
    .rules-view,
    .expert-wisdom-view,
    .pricing-view {
        padding-top: 5rem !important;
        /* ~80px */
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }

    .dashboard-header {
        top: 60px !important;
    }
}

/* CHAT SPECIFIC OVERRIDES (V13) */
/* Disable sticky header for Chat to mimic Gemini behavior */
.chat-container .dashboard-header {
    position: relative !important;
    top: auto !important;
    z-index: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    margin-bottom: 2rem !important;
}

/* EXPERT WISDOM VIEW OVERRIDE (V18/V19) */
/* Reduces spacing between header and injected toolbar for cleaner layout without inline patches */
.expert-wisdom-view .dashboard-header {
    margin-bottom: 0 !important;
    /* Zero gap. JS Spacer controls the 20px */
}

/* V25 SCROLL ANCHOR STRATEGY */
.chat-messages {
    padding-bottom: 200px !important;
    /* Vital space for anchor visibility */
    scroll-behavior: smooth;
}

/* --- PRICING FEATURES --- */
.feature-included {
    color: #ffffff !important;
    /* Blanco puro en modo oscuro */
}

/* Light mode override for included features */
[data-theme="light"] .feature-included {
    color: #000000 !important;
    /* Negro puro en modo claro */
}

/* --- MOBILE MENU FIXES --- */
.mobile-sidebar {
    background: #1a1a1a;
    /* Modo oscuro por defecto */
    border: none !important;
    /* SIN BORDE */
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
    /* Sombra sutil */
}

[data-theme="light"] .mobile-sidebar {
    background: #ffffff;
}

/* Hamburger button */
.hamburger-menu {
    background: transparent;
    border: none;
    outline: none !important;
    /* CRÍTICO: Quita el outline verde */
    box-shadow: none !important;
}

/* Cuando está abierto */
.hamburger-menu:focus,
.hamburger-menu:active {
    outline: none !important;
    /* NO mostrar outline en ningún estado */
    box-shadow: none !important;
    border: none !important;
}

/* --- PRICING TIERS HIERARCHY --- */
.tier-card {
    background: #1a1a1a;
    /* Match expert wisdom cards - was #2d2d2d */
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    transition: transform 0.2s;
}

[data-theme="light"] .tier-card {
    background: #fafafa;
    /* Match expert wisdom cards - was #f8f8f8 */
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.tier-card:hover {
    transform: translateY(-5px);
}

/* Tier RECOMENDADO (Insider) */
.tier-card.recommended {
    border: 2px solid #ffffff;
    position: relative;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

[data-theme="light"] .tier-card.recommended {
    border: 2px solid #000000;
}



/* Tier nombre */
.tier-name {
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #888888;
    margin-bottom: 8px;
    font-weight: 600;
}

/* Tier precio */
.tier-price {
    font-size: 48px;
    /* Grande y visible */
    font-weight: 700;
    margin-bottom: 8px;
    line-height: 1;
}

.tier-period {
    font-size: 16px;
    color: var(--text-secondary);
    font-weight: 400;
}

/* Descripción tier */
.tier-description {
    font-size: 16px;
    color: #aaaaaa;
    margin-bottom: 24px;
    min-height: 48px;
    /* Alignment fix */
}

[data-theme="light"] .tier-description {
    color: #666666;
}

.tier-features {
    list-style: none;
    padding: 0;
    margin-bottom: 2rem;
    font-size: 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    flex: 1;
}


.feature-excluded {
    color: #666666 !important;
    /* Gris medio - UNIVERSAL */
    text-decoration: line-through;
    opacity: 0.5;
}

/* --- ROBUST MOBILE SIDEBAR & OVERLAY (V-FINAL-3) --- */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99990;
    /* High but below sidebar */
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(2px);
}

.sidebar-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

#mobile-menu-btn,
.mobile-menu-btn {
    outline: none !important;
    box-shadow: none !important;
    -webkit-tap-highlight-color: transparent !important;
}

#mobile-menu-btn:focus,
#mobile-menu-btn:active {
    background-color: transparent !important;
}

@media (max-width: 768px) {

    .mobile-sidebar,
    .sidebar {
        position: fixed !important;
        top: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        height: 100vh !important;
        width: 280px !important;
        max-width: 80vw !important;
        background: #1a1a1a !important;
        box-shadow: 5px 0 25px rgba(0, 0, 0, 0.5) !important;
        z-index: 99999 !important;
        /* MAX Z-INDEX */
        transform: translateX(-105%) !important;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
        display: flex !important;
        flex-direction: column !important;
    }

    /* Solid Header Background to prevent bleed-through */
    .sidebar .sidebar-header {
        background-color: var(--bg-panel) !important;
        position: relative;
        z-index: 2;
        padding-right: 20px !important;
        /* Safety padding */
    }

    /* Safe Text Truncation */
    .sidebar .brand-text {
        max-width: 180px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        display: block;
    }

    .sidebar .desktop-only {
        display: none !important;
    }

    /* OPEN STATE */
    .mobile-sidebar.open,
    .sidebar.open {
        transform: translateX(0) !important;
        box-shadow: 10px 0 40px rgba(0, 0, 0, 0.8) !important;
    }

    [data-theme="light"] .mobile-sidebar,
    [data-theme="light"] .sidebar {
        background: #ffffff !important;
        border-right: 1px solid rgba(0, 0, 0, 0.1) !important;
    }

    /* Prevent collapsed state from interfering */
    .sidebar.collapsed {
        width: 280px !important;
        min-width: 280px !important;
        align-items: flex-start !important;
    }

    /* Ensure content inside is visible */
    .sidebar.collapsed .brand-text,
    .sidebar.collapsed .label,
    .sidebar.collapsed .nav-item span {
        display: inline-block !important;
        opacity: 1 !important;
        visibility: visible !important;
    }

    .sidebar.collapsed .nav-item {
        width: 100% !important;
        justify-content: flex-start !important;
        padding: 0 12px !important;
    }
}

/* ========== LEGAL PAGES ========== */

.legal-page {
    padding: 2rem;
    max-width: 800px;
    margin: 0 auto;
}

.legal-page-inner {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 3rem;
    line-height: 1.8;
    color: var(--text-primary);
}

.legal-page-inner h1 {
    font-family: 'Playfair Display', serif;
    font-size: 2.2rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    letter-spacing: -0.5px;
}

.legal-page-inner h2 {
    font-size: 1.25rem;
    font-weight: 700;
    margin-top: 2.5rem;
    margin-bottom: 0.75rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}

.legal-page-inner h3 {
    font-size: 1.05rem;
    font-weight: 600;
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.legal-page-inner p {
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

.legal-page-inner ul {
    padding-left: 1.5rem;
    margin-bottom: 1rem;
}

.legal-page-inner ul li {
    margin-bottom: 0.4rem;
    color: var(--text-secondary);
}

.legal-page-inner a {
    color: var(--text-primary);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.legal-page-inner a:hover {
    opacity: 0.7;
}

.legal-updated {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 2rem;
    font-style: italic;
}

.legal-back-link {
    display: inline-block;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
    color: var(--text-secondary) !important;
    text-decoration: none !important;
    transition: color 0.2s ease;
}

.legal-back-link:hover {
    color: var(--text-primary) !important;
}

@media (max-width: 768px) {
    .legal-page {
        padding: 1rem;
    }

    .legal-page-inner {
        padding: 1.5rem;
    }

    .legal-page-inner h1 {
        font-size: 1.6rem;
    }
}

/* ========== SITE FOOTER ========== */

.site-footer {
    padding: 1.5rem 2rem;
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.site-footer-inner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.site-footer-sep {
    color: var(--border);
}

.site-footer a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.2s ease;
}

.site-footer a:hover {
    color: var(--text-primary);
    text-decoration: underline;
}

/* ========== COOKIE CONSENT BANNER ========== */

.cookie-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 999999;
    display: flex;
    justify-content: center;
    padding: 1rem;
    pointer-events: none;
}

.cookie-banner-inner {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    max-width: 800px;
    width: 100%;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem 1.5rem;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.cookie-banner-inner p {
    margin: 0;
    flex: 1;
    line-height: 1.5;
}

.cookie-banner-inner a {
    color: var(--text-primary);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.cookie-accept-btn {
    flex-shrink: 0;
    padding: 8px 24px;
    background: var(--text-primary);
    color: var(--bg-dark);
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: opacity 0.2s ease;
    white-space: nowrap;
}

.cookie-accept-btn:hover {
    opacity: 0.85;
}

@media (max-width: 768px) {
    .cookie-banner-inner {
        flex-direction: column;
        gap: 0.75rem;
        text-align: center;
    }

    .cookie-accept-btn {
        width: 100%;
    }
}