/* ═══════════════════════════════════════════════════════════
   FISCALIA - Chat Page Styles (chat_v2.html)

   Note: Critical FOUC prevention CSS should stay inline in the template

   SCOPING: All tokens scoped to .page-chat to avoid conflicts with
   design-system.css global tokens. Uses CSS cascade inheritance.
   ═══════════════════════════════════════════════════════════ */


/* ============================================
       CSS CUSTOM PROPERTIES - HARVEY DESIGN SYSTEM
       Scoped to .page-chat to prevent global conflicts
       ============================================ */
.page-chat {
    /* Color tokens - Claude-inspired, teal accent */
    --bg-100: #faf9f6;
    --bg-200: #EFECE4;
    --bg-300: #E5E1D7;
    --bg-sidebar: #faf9f6;
    --bg-sidebar-active: #EFECE4;
    --sidebar-hover-bg: var(--bg-300);
    --bg-primary: var(--bg-100);
    --bg-elevated: #FFFFFF;
    --bg-card: #FFFFFF;
    --bg-input: #FFFFFF;
    --bg-pill: #F7F5F0;

    /* Text */
    --text-primary: #141413;
    --text-secondary: #3D3D3A;
    --text-tertiary: #5E5D59;
    --text-muted: #B0AEA5;
    --text-quaternary: var(--text-muted);

    /* Accent */
    --accent: #0F766E;
    --accent-hover: #115E59;
    --accent-light: #0F766E;
    --accent-on: #FFFFFF;
    --accent-glow: rgba(15, 118, 110, 0.25);
    --accent-muted: rgba(15, 118, 110, 0.10);
    --accent-focus: rgba(15, 118, 110, 0.45);

    /* Teal Accents - brand */
    --teal-deep: #115E59;
    --teal-mid: #0F766E;
    --teal-soft: rgba(15, 118, 110, 0.14);
    --teal-pale: rgba(15, 118, 110, 0.10);
    --teal-text: #0F766E;

    /* Borders */
    --border: rgba(20, 20, 19, 0.10);
    --border-hover: rgba(20, 20, 19, 0.20);
    --border-input: rgba(20, 20, 19, 0.10);

    /* Status */
    --success: #16A34A;
    --warning: #D97706;
    --error: #B42318;

    /* Typography */
    --font-ui: "Sora", system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    --font-display: "Sora", system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    --font-sidebar: "Sora", system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    --font-body: "Source Serif 4", Georgia, "Times New Roman", serif;
    --font-mono: "DM Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

    /* Spacing */
    --space-xs: 0.5rem;
    --space-sm: 1rem;
    --space-md: 1.5rem;
    --space-lg: 2rem;
    --space-xl: 3rem;
    --space-2xl: 4rem;
    --space-3xl: 6rem;

    /* Transitions */
    --ease: ease;
    --duration: 200ms;
    --duration-press: 120ms;

    /* Radius */
    --radius-xs: 4px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 28px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-soft: none;
    --shadow-input: none;

    /* Layout sizing */
    --sidebar-width: 288px;
    --chat-max-width: 720px;
    --chat-input-radius: 12px;
    --chat-input-width: 752px;
}

/* ============================================
       DARK THEME - Harvey design logic (inverted)
       Scoped to .page-chat to prevent global conflicts
       ============================================ */
[data-theme="dark"] .page-chat {
    --bg-100: #151413;
    --bg-200: #131211;
    --bg-300: #1F1E1C;
    --bg-sidebar: #1D1C1A;
    --bg-sidebar-active: #171614;
    --sidebar-hover-bg: var(--bg-300);
    --bg-primary: var(--bg-100);
    --bg-elevated: #1D1C1A;
    --bg-card: #1D1C1A;
    --bg-input: #1F1E1C;
    --bg-pill: #1F1E1C;

    /* Text */
    --text-primary: #FAF9F5;
    --text-secondary: #D6D2C7;
    --text-tertiary: #A8A296;
    --text-muted: #7F7A70;
    --text-quaternary: var(--text-muted);

    /* Accent */
    --accent: #0F766E;
    --accent-hover: #115E59;
    --accent-light: #0F766E;
    --accent-glow: rgba(15, 118, 110, 0.25);
    --accent-muted: rgba(15, 118, 110, 0.18);
    --accent-focus: rgba(15, 118, 110, 0.45);

    /* Teal Accents - softened for dark */
    --teal-deep: #0F766E;
    --teal-mid: #0F766E;
    --teal-soft: rgba(15, 118, 110, 0.24);
    --teal-pale: rgba(15, 118, 110, 0.18);
    --teal-text: #5EEAD4;

    /* Borders */
    --border: rgba(250, 249, 245, 0.12);
    --border-hover: rgba(250, 249, 245, 0.24);
    --border-input: rgba(250, 249, 245, 0.16);

    /* Shadows */
    --shadow-soft: none;
    --shadow-input: none;

    /* Status */
    --success: #16A34A;
    --warning: #D97706;
    --error: #B42318;
}

/* ============================================
       BASE STYLES (scoped to .page-chat)
       Global resets are in design-system.css
       ============================================ */

/* Apply chat-specific styling to page wrapper */
.page-chat {
    font-family: var(--font-body);
    color: var(--text-primary);
    background-color: var(--bg-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
    width: 100%;
}

/* ============================================
       SIDEBAR (scoped to .page-chat)
       ============================================ */
.page-chat .sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--bg-sidebar);
    padding: 18px 16px;
    border-right: 0.8px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 20px;
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    overflow: hidden;
    font-family: var(--font-sidebar);
}

/* ============================================
       HAMBURGER MENU (Mobile Only, scoped to .page-chat)
       ============================================ */
.page-chat .hamburger-menu {
    display: none; /* Hidden on desktop */
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1001;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 10px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
    transition: all var(--duration) var(--ease);
}

.page-chat .hamburger-menu:hover {
    background: var(--bg-300);
    border-color: var(--border-hover);
}

.page-chat .hamburger-menu:active {
    transform: translateY(1px);
}

.page-chat .hamburger-line {
    width: 20px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 2px;
    transition: all var(--duration) var(--ease);
}

/* Hamburger animation when sidebar is open */
.page-chat .sidebar.open .hamburger-menu .hamburger-line:nth-child(1) {
    transform: translateY(8px) rotate(45deg);
}

.page-chat .sidebar.open .hamburger-menu .hamburger-line:nth-child(2) {
    opacity: 0;
}

.page-chat .sidebar.open .hamburger-menu .hamburger-line:nth-child(3) {
    transform: translateY(-8px) rotate(-45deg);
}

/* ============================================
       SIDEBAR BACKDROP (Mobile Only, scoped to .page-chat)
       ============================================ */
.page-chat .sidebar-backdrop {
    display: none; /* Hidden by default */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--duration) var(--ease);
}

.page-chat .sidebar-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

/* ============================================
       MOBILE RESPONSIVE LAYOUT (scoped to .page-chat)
       ============================================ */
@media (max-width: 768px) {
    /* Hide sidebar by default on mobile */
    .page-chat .sidebar {
        transform: translateX(-100%);
        z-index: 1000;
        transition: transform var(--duration) var(--ease);
        padding: 12px 14px;
        gap: 12px;
        overflow-y: auto;
        overflow-x: hidden;
    }

    /* Show sidebar when open class is added */
    .page-chat .sidebar.open {
        transform: translateX(0);
    }

    /* Remove left offset on main content */
    .page-chat .main {
        left: 0 !important;
    }

    /* Remove left offset on query section */
    .page-chat #view-consulta .query-section {
        left: 0 !important;
    }

    /* Show hamburger button on mobile */
    .page-chat .hamburger-menu {
        display: flex;
    }

    /* Move hamburger to top-right when sidebar is open */
    .page-chat .sidebar.open ~ .hamburger-menu {
        left: auto;
        right: 20px;
        top: 16px;
    }

    /* Enable backdrop on mobile */
    .page-chat .sidebar-backdrop {
        display: block;
    }

    /* Sidebar logo - minimal margins */
    .page-chat .logo {
        font-size: 1.6rem;
        margin-top: -6px !important;
        margin-bottom: 0 !important;
        margin-left: -2px;
    }

    /* Navigation - minimal spacing */
    .page-chat .nav {
        gap: 4px;
    }

    .page-chat .nav-item {
        padding: var(--sidebar-item-padding-y, 10px) var(--sidebar-item-padding-x, 12px) !important;
        font-size: var(--sidebar-item-font-size, 12px);
        line-height: var(--sidebar-item-line-height, 16px);
        gap: 12px;
    }

    .page-chat .nav-icon {
        width: 18px;
        height: 18px;
    }

    /* Conversation history - minimal spacing */
    .page-chat .conversation-history {
        margin-top: 6px;
        gap: 2px;
        flex: 1;
        min-height: 0;
        max-height: 30vh;
        overflow-y: auto;
    }

    .page-chat .history-header {
        font-size: 0.6875rem;
        margin-bottom: 2px !important;
        padding: 0 10px;
    }

    .page-chat .history-item {
        padding: 7px 10px;
        font-size: 0.75rem;
    }

    .page-chat .history-title {
        font-size: 0.75rem;
    }

    .page-chat .history-time {
        display: none !important;
    }

    /* User profile mobile styles moved to app-sidebar.css for consistency */

    /* Footer - minimal spacing */
    .page-chat .sidebar-footer {
        gap: 4px;
        margin-top: 4px;
    }

    .page-chat .theme-toggle {
        display: none !important;
    }

    .chat-topbar {
        padding: 14px 16px 8px;
    }

    .chat-topbar-title {
        font-size: 0.8125rem;
    }

    #view-consulta .response-section {
        padding: 16px 16px 0;
    }

    .page-chat .conversation-input-wrapper {
        left: 0;
        padding: 12px 16px 20px;
        min-height: auto;
    }
}

/* ============================================
       SAFE AREA INSETS (Notched Phones)
       ============================================ */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    #view-consulta .query-section,
    .conversation-input-wrapper {
        padding-bottom: calc(24px + env(safe-area-inset-bottom));
    }
}

/* Main content area - offset for fixed sidebar (scoped to .page-chat) */
.page-chat .main {
    position: absolute;
    left: var(--sidebar-width);
    right: 0;
    min-height: 100vh;
    padding: 0;
    display: flex;
    justify-content: flex-start;
    align-items: stretch;
    background: transparent;
}

.layout-app.embed-mode .main {
    position: relative;
    left: 0;
    right: 0;
    width: 100%;
    padding: 0;
    display: block;
    overflow: visible;
    align-items: stretch;
    justify-content: flex-start;
    background: transparent;
}

.layout-app.embed-mode .conversation-input-wrapper {
    left: 0;
}

.page-chat .logo {
    font-family: var(--font-logo) !important;
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--logo-color);
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    margin-left: -2px;
    margin-top: -6px;
    text-decoration: none;
}

.page-chat .logo:hover {
    color: var(--logo-color);
    text-decoration: none;
}

.page-chat .logo-lab {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-secondary);
}

/* Navigation (scoped to .page-chat) */
.page-chat .nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.page-chat .nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: var(--sidebar-item-padding-y, 10px) var(--sidebar-item-padding-x, 12px);
    border-radius: var(--sidebar-item-radius, var(--radius-sm));
    color: var(--text-secondary);
    text-decoration: none;
    font-family: var(--font-ui);
    font-size: var(--sidebar-item-font-size, 12px);
    line-height: var(--sidebar-item-line-height, 16px);
    font-weight: 500;
    cursor: pointer;
    transition: color var(--duration) var(--ease),
                opacity var(--duration) var(--ease);
    background: transparent;
    border: none;
    width: 100%;
    text-align: left;
    margin: 0;
    min-height: var(--sidebar-item-min-height, 36px);
}

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

[data-theme="dark"] .page-chat .nav-item:hover {
    background: var(--sidebar-hover-bg);
}

.page-chat .nav-item.active {
    background: var(--sidebar-hover-bg);
    color: var(--text-primary);
    font-weight: 600;
}

.page-chat .nav-icon {
    width: 18px;
    height: 18px;
    opacity: 0.7;
    flex-shrink: 0;
    transition: opacity var(--duration) var(--ease);
}

.page-chat .nav-item.active .nav-icon {
    opacity: 1;
}

/* Navigation Dropdown (scoped to .page-chat) */
.page-chat .nav-dropdown {
    position: relative;
}

.page-chat .nav-dropdown-toggle {
    justify-content: space-between;
}

.page-chat .chevron-icon {
    opacity: 0.5;
    transition: transform 0.2s ease;
}

.page-chat .nav-dropdown.open .chevron-icon {
    transform: rotate(180deg);
}

.page-chat .nav-dropdown-content {
    display: none;
    flex-direction: column;
    gap: 4px;
    padding-left: 28px;
    margin-top: 4px;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.page-chat .nav-dropdown.open .nav-dropdown-content {
    display: flex;
    max-height: 500px;
}

.page-chat .nav-dropdown-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-family: var(--font-ui);
    font-size: 12px;
    line-height: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--duration) var(--ease);
}

.page-chat .nav-dropdown-item:hover {
    background: var(--sidebar-hover-bg);
    color: var(--text-primary);
    text-decoration: none;
}

[data-theme="dark"] .page-chat .nav-dropdown-item:hover {
    background: var(--sidebar-hover-bg);
}

.page-chat .nav-dropdown-item .nav-icon {
    width: 16px;
    height: 16px;
}

/* Conversation History (scoped to .page-chat) */
.page-chat .conversation-history {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow-y: auto;
    margin-top: 16px;
    gap: 6px;
}

.page-chat .history-header {
    font-family: var(--font-ui);
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 8px;
    padding: 0 12px;
}

.page-chat .history-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.page-chat .history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px;
    font-family: var(--font-ui);
    font-size: 12px;
    line-height: 16px;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--duration) var(--ease);
}

.page-chat .history-item:hover {
    background: var(--bg-300);
    color: var(--text-primary);
}

[data-theme="dark"] .page-chat .history-item:hover {
    background: var(--bg-300);
}

.page-chat .history-item.active {
    background: var(--sidebar-hover-bg);
    color: var(--text-primary);
    font-weight: 500;
}

.page-chat .history-item-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
}

.page-chat .history-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 12px;
    line-height: 16px;
}

.page-chat .history-time {
    font-size: 0.6875rem;
    color: var(--text-tertiary);
    font-family: var(--font-ui);
}

.page-chat .history-delete-btn {
    opacity: 0;
    background: transparent;
    border: none;
    padding: 4px;
    border-radius: 4px;
    color: var(--text-tertiary);
    cursor: pointer;
    transition: all 0.15s ease;
    min-height: auto;
    width: auto;
    margin: 0;
    flex-shrink: 0;
}

.page-chat .history-item:hover .history-delete-btn {
    opacity: 1;
}

.page-chat .history-delete-btn:hover {
    background: var(--bg-300);
    color: var(--error);
}

.page-chat .history-empty {
    padding: 16px;
    font-family: var(--font-sidebar);
    font-size: 0.6875rem;
    color: var(--text-tertiary);
    text-align: center;
    font-style: italic;
}

/* Sidebar Footer (scoped to .page-chat) */
.page-chat .sidebar-footer {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.page-chat .sidebar-footer .input-group {
    width: 100%;
}

.page-chat .sidebar-footer .input-group input {
    font-size: 0.75rem;
    padding: 0.75rem 1rem;
}

.page-chat .sidebar-footer .input-group label {
    font-size: 0.6875rem;
}

.page-chat .pill {
    background: var(--bg-pill);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    font-family: var(--font-ui);
    white-space: nowrap;
    border: none;
    text-align: left;
    cursor: pointer;
    transition: all var(--duration) var(--ease);
}

.page-chat .pill:hover {
    background: var(--teal-pale);
    color: var(--teal-text);
}

/* Theme Toggle Button (scoped to .page-chat) */
.page-chat .theme-toggle {
    display: none; /* Hidden for now */
}

.page-chat .theme-toggle:hover {
    background: var(--bg-300);
    border-color: var(--border-hover);
}

.page-chat .theme-toggle #theme-icon {
    display: inline-block;
}

/* User Profile Section (scoped to .page-chat) */
.page-chat .user-profile {
    display: none;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    gap: 8px;
    flex-direction: column;
}

.page-chat .user-profile.visible {
    display: flex;
}

.page-chat .user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.page-chat .user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--teal-deep);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
    flex-shrink: 0;
}

.page-chat .user-details {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.page-chat .user-email {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.page-chat .user-plan {
    font-size: 0.6875rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 4px;
}

.page-chat .plan-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.625rem;
    font-weight: 600;
    text-transform: uppercase;
}

.page-chat .plan-badge.trial {
    background: var(--teal-pale);
    color: var(--teal-text);
}

.page-chat .plan-badge.pro {
    background: var(--accent);
    color: var(--accent-on);
}

.page-chat .plan-badge.lab {
    background: var(--bg-300);
    color: var(--text-secondary);
}

.page-chat .lab-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.625rem;
    font-weight: 600;
    background: var(--bg-300);
    color: var(--text-secondary);
    margin-left: 4px;
}

.page-chat .user-actions {
    display: flex;
    gap: 8px;
    width: 100%;
}

/* User action button styles moved to app-sidebar.css for consistency */

/* View sections (replace tab panels) */
.view {
    display: none;
    flex-direction: column;
    height: 100vh;
    overflow-y: auto;
    width: 100%;
    max-width: 900px;
    padding: 40px;
}

#view-consulta {
    overflow-y: visible;
    padding: 0;
    height: 100vh;
    max-width: none;
}


.view.active {
    display: flex;
}

#view-consulta.active {
    display: flex;
    flex-direction: column;
}

/* Empty state (centered greeting) */
.consulta-empty-state {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 0 200px 0;
    min-height: 0;
}

.empty-state-content {
    width: 100%;
    max-width: var(--chat-max-width);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.empty-state-greeting {
    font-family: "Sora", system-ui, sans-serif;
    font-size: 2rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin: 0 0 3rem 0;
    line-height: 1.5;
    letter-spacing: 0;
}

.greeting-line {
    display: block;
}

.greeting-emblem {
    display: inline-flex;
    width: 28px;
    height: 28px;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    background: var(--accent-muted);
    color: var(--accent);
    margin-right: 8px;
    vertical-align: middle;
}

.greeting-emblem svg {
    width: 18px;
    height: 18px;
}

.rotating-text {
    color: var(--accent);
    font-weight: 600;
    display: inline;
}

.empty-state-subtitle {
    font-family: var(--font-body);
    font-size: 0.9375rem;
    color: var(--text-tertiary);
    margin: 0 0 2.5rem 0;
}

/* Knowledge Base Post-it Note */
.knowledge-postit {
    background: var(--bg-card);
    border: 0.8px solid var(--border);
    padding: 1rem 1.25rem;
    border-radius: 2px;
    max-width: 280px;
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.knowledge-postit.hidden {
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
}

.postit-title {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.postit-list {
    list-style: none;
    padding: 0;
    margin: 0 0 0.5rem 0;
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.postit-list li::before {
    content: '• ';
    color: var(--accent);
}

.postit-footer {
    font-size: 0.6875rem;
    color: var(--text-tertiary);
    font-style: italic;
    text-align: right;
}

.postit-close {
    position: absolute;
    top: 0;
    right: 0;
    background: transparent;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 16px;
    line-height: 1;
    transition: all 0.2s ease;
    margin: 4px;
}

.postit-close:hover {
    background: var(--accent-muted);
    transform: translateY(1px);
}

/* Dark mode post-it */
[data-theme="dark"] .knowledge-postit {
    background: var(--bg-card);
}

[data-theme="dark"] .postit-title,
[data-theme="dark"] .postit-list,
[data-theme="dark"] .postit-footer {
    color: var(--text-secondary);
}

[data-theme="dark"] .postit-list li::before {
    color: var(--accent);
}

[data-theme="dark"] .postit-close {
    background: transparent;
    color: var(--text-secondary);
}

[data-theme="dark"] .postit-close:hover {
    background: var(--accent-muted);
}

.empty-input-container,
.conversation-input-container {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-input);
    border-radius: var(--chat-input-radius);
    padding: 14px;
    transition: border-color var(--duration) var(--ease);
    justify-content: space-between;
}

.empty-input-container {
    min-height: 121.6px;
}

.empty-input-container:hover,
.conversation-input-container:hover {
    border-color: var(--border-hover);
}

.empty-input-container:focus-within,
.conversation-input-container:focus-within {
    border-color: var(--border-hover);
    outline: none;
}

.empty-input-container textarea,
.conversation-input-container textarea {
    width: 100%;
    border: none;
    background: transparent;
    padding: 4px 2px 2px;
    min-height: 64px;
    height: 64px;
    resize: none;
    font-family: "Sora", system-ui, sans-serif;
    font-size: 1rem;
    line-height: 1.4;
    color: var(--text-primary);
    overflow-y: hidden;
    transition: height 0.1s ease;
    flex: 1;
}

.empty-input-container textarea:focus,
.conversation-input-container textarea:focus {
    outline: none;
    box-shadow: none;
}

.empty-input-container textarea::placeholder,
.conversation-input-container textarea::placeholder {
    color: var(--text-tertiary);
    font-family: "Sora", system-ui, sans-serif;
}

.empty-input-controls,
.conversation-input-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-content: space-between;
    margin-top: auto;
}

.input-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.input-actions-left {
    color: var(--text-secondary);
    flex-shrink: 0;
    display: flex;
    justify-content: flex-end;
}

.input-actions-right {
    margin-left: auto;
}

.model-selector {
    padding: 6px 20px 6px 8px;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    font-family: var(--font-ui);
    font-size: 14px;
    font-weight: 400;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.2s ease;
    width: auto;
    height: 32px;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 12 12' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%235E5D59' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 4px center;
    flex-shrink: 0;
}

/* Agent selectors - visible in both states */

.model-selector:hover {
    background-color: transparent;
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 12 12' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%235E5D59' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    color: var(--text-primary);
}

.model-selector:focus {
    outline: none;
    background-color: transparent;
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 12 12' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%235E5D59' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
}

[data-theme="dark"] .model-selector {
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 12 12' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%23D6D2C7' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    color: var(--text-secondary);
}

[data-theme="dark"] .model-selector:hover,
[data-theme="dark"] .model-selector:focus {
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 12 12' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%23D6D2C7' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

.send-btn {
    width: 32px !important;
    height: 32px !important;
    min-width: 32px !important;
    min-height: 32px !important;
    max-width: 32px !important;
    max-height: 32px !important;
    padding: 0 !important;
    background: var(--accent) !important;
    color: var(--accent-on);
    border: none !important;
    border-radius: var(--radius-sm) !important;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background var(--duration) var(--ease),
                transform var(--duration-press) var(--ease);
    flex-shrink: 0;
    margin-left: auto;
    margin-top: 0 !important;
}

.send-btn svg {
    width: 20px;
    height: 20px;
}

.send-btn:hover {
    background: var(--accent-hover) !important;
    transform: translateY(-1px);
}

.send-btn:active {
    transform: translateY(1px);
}

.send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.empty-input-error {
    position: absolute;
    bottom: -28px;
    left: 20px;
    font-size: 0.8125rem;
    color: var(--error);
    font-family: var(--font-body);
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

.empty-input-error.show {
    opacity: 1;
}

.empty-input-container-wrapper {
    position: relative;
    width: 100%;
    max-width: 760px;
    margin: 0 auto;
}

.example-prompts {
    margin-top: 20px;
    width: 100%;
    max-width: 700px;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
    min-height: 120px;
}

.example-prompts-label {
    font-family: var(--font-ui);
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.example-prompts-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.example-prompt {
    border: 1px solid var(--border);
    background: var(--bg-100);
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: 0.75rem;
    font-weight: 400;
    padding: 6px 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color var(--duration) var(--ease), border-color var(--duration) var(--ease);
}

.example-prompt:hover {
    background: var(--bg-300);
    border-color: var(--border-hover);
}

/* Conversation view */
.consulta-conversation {
    width: 100%;
    padding-bottom: 200px; /* Space for fixed input */
    display: flex;
    flex-direction: column;
}

.conversation-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 24px;
    width: 100%;
    max-width: calc(var(--chat-max-width) + 320px + 24px);
    margin: 0 auto;
    padding: 0 24px;
}

#view-consulta .response-section {
    padding: 24px 0 0;
    max-width: var(--chat-max-width);
    margin: 0;
    background: transparent;
    width: 100%;
}

.chat-topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 24px 10px;
    background: var(--bg-primary);
    border-bottom: 0.8px solid var(--border);
    max-width: calc(var(--chat-max-width) + 320px + 24px);
    width: 100%;
    margin: 0 auto;
}

.chat-topbar-title {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font-ui);
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.chat-title {
    color: var(--text-primary);
    font-weight: 600;
}

.chat-title-chevron {
    width: 14px;
    height: 14px;
    color: var(--text-tertiary);
}

.chat-topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.agent-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 999px;
    background: var(--bg-200);
    color: var(--text-secondary);
    font-family: var(--font-ui);
    font-size: 0.75rem;
    line-height: 1;
}

.agent-badge-avatar {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.agent-badge-initial {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--accent-on);
}

.agent-badge-title {
    white-space: nowrap;
}

.sources-panel {
    background: var(--bg-card);
    border: 0.8px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    position: sticky;
    top: 90px;
    align-self: start;
    max-height: calc(100vh - 140px);
    overflow: auto;
}

.sources-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-family: var(--font-ui);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.sources-count {
    font-size: 0.75rem;
    background: var(--bg-200);
    border-radius: 999px;
    padding: 2px 6px;
}

.sources-updated {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    margin-bottom: 12px;
}

.sources-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sources-item {
    padding: 10px;
    border-radius: 10px;
    background: var(--bg-100);
    border: 1px solid var(--border);
}

.sources-item-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.sources-item-meta {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.sources-empty {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    text-align: center;
    padding: 16px 0;
}

.conversation-input-wrapper {
    position: fixed;
    bottom: 0;
    left: var(--sidebar-width);
    right: 0;
    padding: 24px 24px 24px;
    background: var(--bg-primary);
    border-top: 0.8px solid var(--border);
    z-index: 10;
    display: flex;
    justify-content: center;
    min-height: 158px;
}

.conversation-input-container {
    width: min(100%, var(--chat-input-width));
    min-height: 121.6px;
    height: 100%;
}

[data-theme="dark"] .conversation-input-wrapper {
    background: var(--bg-primary);
}

#view-consulta .query-section {
    position: fixed;
    bottom: 0;
    left: var(--sidebar-width);
    right: 0;
    padding: 20px 40px 24px 40px;
    background: var(--bg-primary);
    z-index: 100;
    border-top: 0.8px solid var(--border);
}

#view-consulta .query-section .query-input-wrapper {
    max-width: 750px;
    margin: 0 auto;
    background: var(--bg-card);
    border: 0.8px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: border-color 0.2s ease;
}

#view-consulta .query-section .query-input-wrapper:focus-within {
    border-color: var(--border-hover);
}

#view-consulta .query-section textarea {
    flex: 1;
    border: none;
    background: transparent;
    padding: 0;
    min-height: 24px;
    max-height: 200px;
    resize: none;
    font-family: var(--font-body);
    font-size: 1rem;
    line-height: 1.5;
    color: var(--text-primary);
    overflow-y: auto;
}

#view-consulta .query-section textarea:focus {
    outline: none;
    border: none;
    box-shadow: none;
}

#view-consulta .query-section textarea::placeholder {
    color: var(--text-tertiary);
}

#view-consulta .response-section .meta {
    margin-top: 16px;
    margin-bottom: 24px;
    font-size: 0.75rem;
    color: var(--text-tertiary);
    text-align: left;
}

/* ============================================
       SECTIONS & ANIMATIONS
       ============================================ */
section {
    animation: fadeInUp 0.8s var(--ease) backwards;
    position: relative;
}

section:nth-child(1) {
    animation-delay: 0.1s;
}
section:nth-child(2) {
    animation-delay: 0.2s;
}
section:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
       CARDS & PANELS - Harvey Style (no borders, no shadows, no hover)
       ============================================ */
.query-panel,
.result-panel {
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 40px;
    position: relative;
    overflow: hidden;
    box-shadow: none;
    font-family: var(--font-body);
}


/* NO HOVER EFFECTS (Harvey style) */

.result-panel {
    position: sticky;
    top: var(--space-lg);
    max-height: calc(100vh - 4rem);
    overflow-y: auto;
}

/* Section headings */
h2 {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--space-md);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    letter-spacing: -0.02em;
}

/* ============================================
       FORM INPUTS
       ============================================ */
.input-group {
    position: relative;
    margin-bottom: var(--space-md);
}

.input-group label {
    position: absolute;
    left: var(--space-sm);
    top: 0.9rem;
    font-family: var(--font-ui);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-tertiary);
    transition: all var(--duration) var(--ease);
    pointer-events: none;
    background: transparent;
    padding: 0 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: calc(100% - 2rem);
}

.input-group input:focus + label,
.input-group input:not(:placeholder-shown) + label,
.input-group textarea + label,
.input-group select:focus + label,
.input-group select:not([value=""]) + label {
    top: -0.6rem;
    left: 0.75rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 600;
    background: var(--bg-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: calc(100% - 1.5rem);
}

input,
textarea,
select {
    width: 100%;
    padding: 1rem 1.25rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: 1rem;
    transition:
        border-color var(--duration) var(--ease),
        background var(--duration) var(--ease);
    outline: none;
}

input::placeholder {
    color: var(--text-tertiary);
    font-weight: 400;
}

textarea::placeholder {
    color: var(--text-tertiary);
    font-weight: 400;
}

input:hover,
textarea:hover,
select:hover {
    border-color: var(--border-input);
    background: var(--bg-card);
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--border);
    background: var(--bg-card);
    box-shadow: none;
    outline: none;
}

/* Reset border for filled but unfocused inputs */
input:not(:focus):not(:placeholder-shown),
textarea:not(:focus),
select:not(:focus) {
    border-color: var(--border);
}

/* Browser autofill styling */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
    -webkit-text-fill-color: var(--text-primary) !important;
    border-color: var(--border) !important;
    transition: background-color 5000s ease-in-out 0s;
}

input:-webkit-autofill:focus {
    border-color: var(--border-hover) !important;
}

textarea {
    min-height: 120px;
    resize: vertical;
    font-family: var(--font-ui);
}

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='%235E5D59' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 2.5rem;
    transition: none;
}

[data-theme="dark"] select {
    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='%23D6D2C7' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
}

/* ============================================
       BUTTONS - Harvey Style (black, no effects)
       ============================================ */
button {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-family: var(--font-ui);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color var(--duration) var(--ease),
                border-color var(--duration) var(--ease),
                color var(--duration) var(--ease),
                transform var(--duration-press) var(--ease);
    width: auto;
    margin-top: 0;
    box-shadow: none;
    transform: none;
    min-height: auto;
}

button:hover {
    background: var(--bg-300);
    box-shadow: none;
    transform: none;
}

button:active {
    transform: translateY(1px);
    background: var(--bg-300);
}

button:disabled {
    background: var(--bg-elevated);
    color: var(--text-tertiary);
    cursor: not-allowed;
    transform: none;
    opacity: 0.5;
}

/* Light theme button styles - removed, using CSS variables now */

/* ============================================
       ANSWER DISPLAY
       ============================================ */
.answer-container {
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
    font-family: var(--font-body);
    font-size: 1rem;
    line-height: 1.5;
    color: var(--text-primary);
    min-height: auto;
    position: relative;
}

.answer-empty {
    color: var(--text-tertiary);
    font-style: italic;
    text-align: center;
    padding: var(--space-xl) var(--space-sm);
    font-family: var(--font-body);
}

.answer-container strong {
    color: var(--text-primary);
    font-weight: 700;
}

.answer-container p {
    margin: 0 0 var(--space-sm) 0;
}

.answer-container p:last-child {
    margin-bottom: 0;
}

.answer-container ol,
.answer-container ul {
    margin: var(--space-sm) 0;
    padding-left: 1.75rem;
}

.answer-container ol {
    list-style-type: decimal;
}

.answer-container ul {
    list-style-type: disc;
}

.answer-container li {
    margin: var(--space-xs) 0;
    line-height: 1.6;
}

.answer-container code {
    font-family: var(--font-mono);
    font-size: 0.875rem;
    background: var(--bg-card);
    padding: 0.2em 0.4em;
    border-radius: 4px;
    border: 1px solid var(--border);
    color: var(--accent);
}

.answer-container pre {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: var(--space-sm);
    margin: var(--space-sm) 0;
    overflow-x: auto;
}

.answer-container pre code {
    background: none;
    border: none;
    padding: 0;
    color: var(--text-primary);
    font-size: 0.875rem;
    line-height: 1.5;
}

/* ============================================
       CHAT MESSAGES - Claude/ChatGPT Style
       ============================================ */
.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding-top: 16px;
    padding-bottom: 32px;
}

.chat-message {
    display: flex;
    flex-direction: column;
    gap: 4px;
    animation: messageSlideIn 0.3s var(--ease) forwards;
    opacity: 0;
}

.chat-message.no-animate {
    animation: none;
    opacity: 1;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message.user {
    align-items: flex-end;
}

.chat-message.assistant {
    align-items: flex-start;
}

.message-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.message-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
}

.chat-message.user .message-avatar {
    background: var(--teal-pale);
    color: var(--teal-text);
}

.chat-message.assistant .message-avatar {
    background: var(--bg-elevated);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.message-sender {
    font-family: var(--font-display);
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--teal-mid);
    display: none;
}

.message-confidence {
    display: none;
    align-items: center;
    padding: 2px 8px;
    border-radius: 9999px;
    border: 0.8px solid var(--border);
    font-family: var(--font-ui);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: var(--text-secondary);
    background: var(--bg-100);
}

.message-confidence[data-level="high"] {
    background: var(--accent-muted);
    color: var(--accent-light);
    border-color: transparent;
}

.message-confidence[data-level="medium"] {
    background: var(--bg-200);
    color: var(--text-secondary);
}

.message-confidence[data-level="low"] {
    background: var(--bg-100);
    color: var(--text-muted);
}

/* ============================================
   TRUST FLIP BANNER (V2 - Jan 2026)
   Educates users about citation hover on first answer
   ============================================ */
.trust-flip-banner {
    background: var(--teal-pale);
    border: 0.8px solid var(--teal-mid);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    margin: 1rem 0;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    animation: bannerSlideIn 0.4s var(--ease) forwards;
}

@keyframes bannerSlideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.trust-flip-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
}

.trust-flip-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
}

.trust-flip-content p {
    margin: 0;
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

html[data-theme="dark"] .trust-flip-content p {
    color: var(--text-secondary);
}

.trust-flip-content strong {
    color: var(--teal-deep);
    font-weight: 600;
}

html[data-theme="dark"] .trust-flip-content strong {
    color: var(--teal-mid);
}

.trust-flip-dismiss {
    background: var(--accent);
    color: var(--accent-on);
    border: none;
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s ease;
}

.trust-flip-dismiss:hover {
    background: var(--accent-hover);
}

html[data-theme="dark"] .trust-flip-banner {
    background: rgba(74, 128, 124, 0.15);
    border-color: var(--teal-mid);
}

@media (max-width: 768px) {
    .trust-flip-banner {
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.75rem;
    }

    .trust-flip-content {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
    }

    .trust-flip-dismiss {
        width: 100%;
    }
}

.message-content {
    max-width: 100%;
    padding: 0;
    font-family: var(--font-body);
    font-size: 1rem;
    line-height: 1.5;
    color: var(--text-primary);
}

.chat-message.user .message-content {
    background: var(--bg-200);
    color: var(--text-primary);
    padding: 10px 16px;
    border-radius: 12px;
    border: 1px solid transparent;
    max-width: 72%;
    font-size: 1rem;
}

.chat-message.assistant .message-content {
    background: transparent;
    padding-left: 8px;
    padding-right: 32px;
    max-width: 100%;
}

.response-table-placeholder {
    height: 48px;
    border: 0.8px dashed var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-100);
    margin: 8px 0;
}

/* Message feedback (thumbs up/down) */
.message-feedback {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 0.8px solid var(--border);
}

.feedback-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 44px;
    margin-top: 0;
}

.feedback-btn svg {
    width: 18px;
    height: 18px;
    color: var(--text-tertiary);
    transition: color 0.2s ease;
}

.feedback-btn:hover:not(:disabled) {
    background: var(--bg-300);
}

.feedback-btn:hover:not(:disabled) svg {
    color: var(--text-secondary);
}

.feedback-btn.selected {
    background: var(--teal-pale);
}

.feedback-btn.selected svg {
    color: var(--teal-text);
}

.feedback-btn:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

/* Inherit answer-container styles for assistant messages */
.chat-message.assistant .message-content p {
    margin: 0 0 var(--space-sm) 0;
}

.chat-message.assistant .message-content p:last-child {
    margin-bottom: 0;
}

.chat-message.assistant .message-content ol,
.chat-message.assistant .message-content ul {
    margin: var(--space-sm) 0;
    padding-left: 1.75rem;
}

.chat-message.assistant .message-content ol {
    list-style-type: decimal;
}

.chat-message.assistant .message-content ul {
    list-style-type: disc;
}

.chat-message.assistant .message-content li {
    margin: var(--space-xs) 0;
    line-height: 1.6;
}

.chat-message.assistant .message-content code {
    font-family: var(--font-mono);
    font-size: 0.875rem;
    background: var(--bg-card);
    padding: 0.2em 0.4em;
    border-radius: 4px;
    border: 1px solid var(--border);
    color: var(--accent);
}

.chat-message.assistant .message-content strong {
    color: var(--text-primary);
    font-weight: 700;
}

.chat-message.assistant .message-content h2 {
    font-family: var(--font-ui);
    font-size: 1.25rem;
    font-weight: 700;
    margin: var(--space-md) 0 var(--space-sm) 0;
    color: var(--text-primary);
}

.chat-message.assistant .message-content h3 {
    font-family: var(--font-ui);
    font-size: 1.1rem;
    font-weight: 600;
    margin: var(--space-sm) 0 var(--space-xs) 0;
    color: var(--text-primary);
}

.chat-message.assistant .message-content h4 {
    font-family: var(--font-ui);
    font-size: 1rem;
    font-weight: 600;
    margin: var(--space-xs) 0;
    color: var(--text-primary);
}

.chat-message.assistant .message-content h2:first-child,
.chat-message.assistant .message-content h3:first-child,
.chat-message.assistant .message-content h4:first-child {
    margin-top: 0;
}

/* Response Tables */
.message-content .response-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
    font-size: 0.9375rem;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border);
}

.message-content .response-table th {
    font-weight: 600;
    text-align: left;
    padding: 10px 14px;
    background: var(--bg-200);
    color: var(--text-primary);
    border-bottom: 1px solid var(--border);
}

.message-content .response-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
}

.message-content .response-table tr:last-child td {
    border-bottom: none;
}

.message-content .response-table tr:hover td {
    background: var(--accent-muted);
}

/* Message metadata (time, actions) */
.message-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 4px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.chat-message:hover .message-meta {
    opacity: 1;
}

.message-time {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    font-family: var(--font-ui);
}

.message-actions {
    display: flex;
    gap: 4px;
}

.message-action-btn {
    background: transparent;
    border: none;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: 0.75rem;
    font-family: var(--font-ui);
    min-height: auto;
    width: auto;
    margin: 0;
    transition: all 0.15s ease;
}

.message-action-btn:hover {
    background: var(--bg-300);
    color: var(--text-primary);
}

/* Streaming indicator for assistant messages */
.message-streaming {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: 4px;
}

.message-streaming .dot {
    width: 4px;
    height: 4px;
    background: var(--teal-mid);
    border-radius: 50%;
    animation: streamingPulse 1.4s infinite ease-in-out;
}

.message-streaming .dot:nth-child(1) {
    animation-delay: 0s;
}
.message-streaming .dot:nth-child(2) {
    animation-delay: 0.2s;
}
.message-streaming .dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes streamingPulse {
    0%,
    80%,
    100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Phase indicator within message */
.message-phase-indicator {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 0;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-family: var(--font-ui);
}

.message-phase-step {
    display: flex;
    align-items: center;
    gap: 8px;
    opacity: 0.5;
    transition: opacity 0.3s ease;
}

.message-phase-step.active {
    opacity: 1;
    color: var(--teal-mid);
}

.message-phase-step.complete {
    opacity: 1;
    color: var(--success);
}

.message-phase-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
}

.message-phase-step.active .message-phase-dot {
    animation: phasePulse 1s infinite ease-in-out;
}

@keyframes phasePulse {
    0%,
    100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
    }
}

/* New conversation button */
.new-conversation-btn {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-family: var(--font-ui);
    font-size: 12px;
    line-height: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 0;
    margin-bottom: 16px;
    min-height: auto;
}

.new-conversation-btn:hover {
    background: var(--bg-sidebar);
    border-color: var(--border-hover);
    color: var(--text-primary);
}

.new-conversation-btn svg {
    width: 16px;
    height: 16px;
}

/* ============================================
       ARTICLE REFERENCES & TOOLTIPS
       ============================================ */
.art-ref,
.table-ref,
.annex-ref {
    color: var(--teal-mid);
    cursor: help;
    font-weight: 500;
    transition: all var(--duration) var(--ease);
}

.art-ref:hover,
.table-ref:hover,
.annex-ref:hover {
    color: var(--teal-deep);
    text-decoration-style: solid;
}

/* Trust signals for citations */
.art-ref.verified,
.art-ref.unverified {
    border-bottom: 2px solid var(--teal-mid);
    text-decoration: none;
}

/* ============================================
       META INFO
       ============================================ */
.meta {
    margin-top: var(--space-sm);
    padding: var(--space-sm) var(--space-sm);
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    color: var(--text-secondary);
    display: flex;
    gap: var(--space-md);
    flex-wrap: wrap;
    font-family: var(--font-ui);
}

.meta-item {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.meta-item::before {
    content: "●";
    color: var(--accent);
    font-size: 0.5rem;
}

/* ============================================
       FOLLOW-UP CHIPS
       ============================================ */
.follow-up-container {
    margin-top: var(--space-md);
    padding-top: var(--space-md);
    border-top: 0.8px solid var(--border);
}

.follow-up-label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
    font-weight: 500;
    letter-spacing: 0.02em;
    font-family: var(--font-ui);
}

.follow-up-chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
}

.follow-up-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    height: 32px;
    border: 0.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0 10px;
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--bg-100);
    cursor: pointer;
    transition: all var(--duration) var(--ease);
    user-select: none;
}

.follow-up-chip:hover {
    background: var(--bg-300);
    border-color: var(--border-hover);
    color: var(--text-primary);
    transform: scale(0.995);
}

.follow-up-chip:active {
    transform: translateY(1px);
}

/* Answer Actions Bar */
.answer-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 1rem;
    padding: 1.5rem 0 0 0;
    background: transparent;
    border-top: 0.8px solid var(--border);
    opacity: 0;
    transform: translateY(10px);
    animation: fadeInUp 0.3s ease-out forwards;
    animation-delay: 0.2s;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all var(--duration) var(--ease);
    border-radius: var(--radius-sm);
    position: relative;
    width: auto;
    min-height: auto;
    margin-top: 0;
}

.action-btn:hover:not(:disabled) {
    background: var(--accent-muted);
    color: var(--accent-light);
}

.action-btn:active:not(:disabled) {
    transform: scale(0.995);
}

.action-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.action-btn.success {
    color: var(--accent);
}

.action-icon {
    font-size: 1rem;
    line-height: 1;
}

.executive-summary {
    margin-top: 16px;
    padding: 16px;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: var(--bg-card);
}

.executive-summary-header {
    font-family: var(--font-ui);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.executive-summary-body {
    font-family: var(--font-body);
    font-size: 0.9375rem;
    line-height: 1.6;
    color: var(--text-primary);
}

.action-label {
    font-weight: 500;
    letter-spacing: 0.01em;
}

.action-divider {
    width: 1px;
    height: 24px;
    background: var(--border);
    margin: 0 0.5rem;
}

@media (max-width: 768px) {
    .answer-actions {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .action-divider {
        display: none;
    }

    .action-btn {
        flex: 1;
        justify-content: center;
    }
}

/* Rich Citation Cards */
.art-ref.has-article {
    cursor: pointer;
    position: relative;
}

.citation-card {
    position: absolute;
    z-index: 1000;
    min-width: 400px;
    max-width: 500px;
    background: var(--bg-card);
    border: 0.8px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    opacity: 0;
    transform: scale(0.95) translateY(-10px);
    pointer-events: auto; /* Always allow pointer events to prevent flickering */
    transition: all var(--duration) var(--ease);
    font-family: var(--font-ui);
}

/* Invisible bridge to connect ref to tooltip (prevents gap-induced flickering) */
.citation-card::before {
    content: '';
    position: absolute;
    top: -12px;
    left: 0;
    right: 0;
    height: 12px;
    background: transparent;
}

.citation-card.show {
    opacity: 1;
    transform: scale(1) translateY(0);
}

.citation-card-header {
    margin-bottom: 0.75rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.citation-header-left {
    width: 100%;
}

.citation-copy-btn {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    padding: 0.75rem 1rem;
    min-height: 44px;
    min-width: 44px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--duration) var(--ease);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    font-family: var(--font-ui);
    white-space: nowrap;
    width: auto;
    margin: 0;
    z-index: 10;
}

.citation-copy-btn:hover {
    background: var(--bg-300);
    border-color: var(--border-hover);
}

.citation-copy-btn.copied {
    background: var(--accent-muted);
    border-color: var(--accent);
    color: var(--accent);
}

.citation-article-num {
    font-family: var(--font-ui);
    font-size: 0.875rem;
    color: var(--text-primary);
    font-weight: 600;
    margin-bottom: 0.25rem;
    display: block;
}

.citation-hierarchy {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.4;
    display: block;
}

.citation-content {
    font-size: 0.8125rem;
    line-height: 1.6;
    color: var(--text-primary);
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 0.75rem;
    padding-right: 0.5rem;
    white-space: normal;
}

/* Legal text markers: §, Roman numerals, letter items */
.citation-content .law-marker {
    color: var(--accent);
    font-weight: 600;
}

.citation-content::-webkit-scrollbar {
    width: 4px;
}

.citation-content::-webkit-scrollbar-thumb {
    background: var(--accent);
    border-radius: 2px;
}

.citation-content.truncated {
    max-height: 120px;
    overflow: hidden;
    position: relative;
}

.citation-content.truncated::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 40px;
    background: var(--bg-card);
    opacity: 0.9;
}

.citation-expand-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0.75rem 1rem;
    min-height: 44px;
    min-width: 44px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--duration) var(--ease);
}

.citation-expand-btn:hover {
    background: var(--bg-300);
    border-color: var(--border-hover);
}

@media (max-width: 768px) {
    .citation-card {
        min-width: 300px;
        max-width: 90vw;
    }
}

/* Dark theme: remove blur/shadow from citation card */
[data-theme="dark"] .citation-card {
    box-shadow: none;
}

/* Clickable Pill (scoped to .page-chat) */
.page-chat .pill-clickable {
    cursor: pointer;
    transition: all var(--duration) var(--ease);
    border: none;
    font-family: inherit;
    font-size: inherit;
}

.page-chat .pill-clickable:hover {
    background: var(--accent);
    color: var(--bg-card) !important;
}

.hidden {
    display: none;
}

/* Footer */
/* Footer Info */
.footer-info {
    margin-top: auto;
    padding: 24px 0;
    border-top: 0.8px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    font-family: var(--font-ui);
}

.footer-brand {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--text-primary);
}

.footer-source {
    color: var(--text-secondary);
}

.footer-link {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color var(--duration) var(--ease);
}

.footer-link:hover {
    color: var(--text-primary);
}

.footer-divider {
    color: var(--border);
    opacity: 0.5;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-elevated);
}

::-webkit-scrollbar-thumb {
    background: var(--accent);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-light);
}

/* Loading animation */
@keyframes pulse {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.loading {
    animation: pulse 1.5s ease-in-out infinite;
}

.shortcut-hint {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-tertiary);
    margin-top: 0.5rem;
    opacity: 0.7;
    font-family: var(--font-ui);
}

/* ========================================
       Tax Result Card Styles
       ======================================== */

.tax-result-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 24px;
}

.result-product {
    font-family: var(--font-ui);
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.result-official-description {
    font-family: var(--font-ui);
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.result-annex {
    font-family: var(--font-ui);
    font-size: 14px;
    font-weight: 500;
    color: var(--accent);
    margin-bottom: 6px;
}

.result-annex-description {
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 500;
    line-height: 1.5;
    color: var(--text-secondary);
    margin-bottom: 12px;
    padding: 8px 12px;
    background: var(--bg-elevated);
    border-left: 3px solid var(--accent);
    border-radius: 4px;
}

.result-meta {
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 500; /* Added font-weight for better readability */
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.tax-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 12px 0;
    font-family: var(--font-ui);
}

.tax-label {
    font-size: 18px;
    font-weight: 600; /* Increased from 500 to 600 for better readability */
    color: var(--text-primary);
}

.tax-value {
    text-align: right;
}

.tax-amount {
    font-family: var(--font-ui);
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}

.tax-rate {
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-top: 2px;
}

.tax-reduction {
    font-family: var(--font-ui);
    font-size: 11px;
    font-weight: 500;
    color: var(--text-quaternary);
    margin-top: 4px;
    font-style: italic;
}

.tax-total {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.tax-total-label {
    font-family: var(--font-ui);
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tax-total-value {
    text-align: right;
}

.tax-total-amount {
    font-family: var(--font-ui);
    font-size: 24px;
    font-weight: 700;
    color: var(--accent);
    white-space: nowrap;
}

.tax-total-rate {
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-tertiary);
    margin-top: 4px;
}

/* FOUC Prevention: Hide feature-controlled nav items until JS enables them */
.nav-item.feature-controlled {
    display: none;
}

/* ============================================
       RATE BADGES (IS/Zero/Reduced Detection)
       ============================================ */
.rate-badges-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.rate-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
}

.rate-badge.zero {
    background: rgba(16, 185, 129, 0.15);
    color: #047857;
}

.rate-badge.reduced {
    background: rgba(74, 128, 124, 0.15);
    color: var(--teal-deep);
}

.rate-badge.is {
    background: rgba(245, 158, 11, 0.15);
    color: #b45309;
}

.rate-badge.is-pending {
    background: rgba(107, 114, 128, 0.15);
    color: #6b7280;
}

/* ============================================
       RESPONSIVE BREAKPOINTS
       ============================================ */
@media (max-width: 1024px) {
    main {
        padding: var(--space-md);
    }
}

@media (max-width: 768px) {
    header {
        padding: var(--space-sm) var(--space-md);
    }

    .logo {
        font-size: 1.5rem;
    }

    .logo-lab {
        font-size: 1rem;
    }

    .tagline {
        display: none;
    }

    h2 {
        font-size: 1.25rem;
    }

    .query-panel,
    .result-panel {
        padding: var(--space-md);
    }

    /* Empty state mobile optimization */
    .consulta-empty-state {
        padding: 20px 16px;
        justify-content: flex-end;
    }

    .empty-state-content {
        max-width: 100%;
        padding: 0 8px;
    }

    .empty-state-greeting {
        font-size: 1.75rem;
        line-height: 1.25;
        margin-bottom: 0.75rem;
    }

    .empty-state-subtitle {
        font-size: 0.9375rem;
        margin-bottom: 2rem;
    }

    .empty-input-container-wrapper {
        width: 100%;
    }

    .empty-input-container {
        min-height: auto;
    }

    .empty-input-container textarea {
        font-size: 0.9375rem;
        min-height: 80px;
    }

    .conversation-input-container textarea {
        font-size: 0.9375rem;
        min-height: 56px;
    }

    .quota-display {
        font-size: 0.6875rem;
    }
}

@media (max-width: 480px) {
    .page-chat header {
        padding: var(--space-xs) var(--space-sm);
    }

    .page-chat .logo {
        font-size: 1.25rem;
    }

    .page-chat .logo-lab {
        font-size: 0.9375rem;
    }

    .page-chat .theme-toggle {
        width: 44px;
        height: 44px;
    }

    .page-chat main {
        padding: var(--space-sm);
    }

    .page-chat h2 {
        font-size: 1.125rem;
    }

    .page-chat .query-panel,
    .page-chat .result-panel {
        padding: var(--space-sm);
    }

    .page-chat button {
        padding: 0.875rem 1.5rem;
        font-size: 0.9375rem;
    }

    /* Empty state - even more compact on small screens */
    .page-chat .consulta-empty-state {
        padding: 16px 12px;
    }

    .page-chat .empty-state-greeting {
        font-size: 1.5rem;
        line-height: 1.3;
    }

    .greeting-emblem {
        width: 22px;
        height: 22px;
        margin-right: 6px;
    }

    .page-chat .empty-state-subtitle {
        font-size: 0.875rem;
        margin-bottom: 1.5rem;
    }

    .page-chat .empty-input-container textarea {
        font-size: 0.875rem;
        min-height: 70px;
        padding: 12px 14px;
    }

    .page-chat .empty-input-controls {
        flex-wrap: wrap;
        gap: 8px;
    }

    .page-chat .conversation-input-controls {
        flex-wrap: wrap;
        gap: 8px;
    }

    .page-chat .quota-display,
    .page-chat .quota-display-chat {
        font-size: 0.625rem;
        padding: 4px 8px;
    }
}

/* ============================================
       ACCESSIBILITY
       ============================================ */
.page-chat :focus-visible {
    outline: 2px solid var(--accent-focus);
    outline-offset: 4px;
}

.page-chat .empty-input-container textarea:focus-visible,
.page-chat .conversation-input-container textarea:focus-visible,
.page-chat .model-selector:focus-visible {
    outline: none;
}

/* Quota Display (inline with controls) */
.quota-display,
.quota-display-chat {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font-ui);
    font-size: 14px;
    font-weight: 400;
    color: var(--text-secondary);
    margin-top: 0;
    padding: 4px 8px;
    border-radius: 999px;
    border: none;
    background: transparent;
    white-space: nowrap;
    height: 28px;
}

.quota-display-chat {
    background: transparent;
    border: none;
    font-family: var(--font-ui);
    font-size: 14px;
    font-weight: 400;
    padding: 0;
    height: 32px;
    line-height: 1;
}

#quota-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

#quota-queries,
#quota-simulations {
    margin-top: 0 !important;
    white-space: nowrap;
    color: var(--text-secondary);
}

/* Hide simulation quota in consulta view */
#view-consulta #quota-simulations,
#view-consulta .quota-simulations-sync {
    display: none;
}

.quota-display.warning {
    color: #141413;
}

.quota-display.critical {
    color: #ef4444;
}

.quota-icon {
    flex-shrink: 0;
    opacity: 0.7;
}

#quota-count {
    font-weight: 400;
    color: var(--text-primary);
}

.quota-display.warning #quota-count,
.quota-display.critical #quota-count {
    color: inherit;
}

/* Auth Link (Signup/Login) - scoped to .page-chat */
.page-chat .auth-link {
    display: none; /* FOUC Prevention: Hide by default, JS shows for anonymous users */
    align-items: center;
    justify-content: center;
    padding: 12px 16px;
    font-size: 0.875rem;
    font-family: var(--font-sidebar);
    color: var(--text-secondary);
    border-top: 0.8px solid var(--border);
    text-align: center;
    gap: 4px;
}

.page-chat .auth-link a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s ease;
}

.page-chat .auth-link a:hover {
    color: var(--accent-hover);
}

/* Hide auth link for logged-in users */
.page-chat .sidebar-footer .user-profile.visible ~ .auth-link {
    display: none;
}

/* Signup Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: #ffffff; /* Always white - inverse of theme */
    border-radius: var(--radius-lg);
    padding: 40px;
    max-width: 700px;
    width: 90%;
    text-align: center;
    border: 1px solid var(--border);
}

.modal-content h2 {
    font-family: var(--font-display);
    color: var(--text-primary); /* Always dark text on white background */
    margin-bottom: 12px;
    font-size: 1.75rem;
    font-weight: 700;
    text-align: center !important;
    display: block !important;
}

.modal-content p {
    font-family: var(--font-body);
    color: var(--text-secondary); /* Dark gray for readability on white */
    margin-bottom: 32px;
    font-size: 1rem;
    line-height: 1.6;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.btn-primary {
    background: var(--accent);
    color: var(--accent-on);
    border: 1px solid transparent;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-family: var(--font-ui);
    font-size: 0.875rem;
    font-weight: 600;
    text-align: center;
    cursor: pointer;
    width: auto !important;
    min-height: auto !important;
    margin-top: 0 !important;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--bg-300);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-family: var(--font-ui);
    font-size: 0.875rem;
    font-weight: 600;
    text-align: center;
    cursor: pointer;
    width: auto !important;
    min-height: auto !important;
    margin-top: 0 !important;
}

.btn-secondary:hover {
    background: var(--bg-200);
}

/* Lock Icon on Nav Items */
.lock-icon {
    margin-left: auto;
    opacity: 0.5;
    color: var(--text-secondary);
    display: none; /* Hidden by default, shown via JS */
}

.nav-item.locked .lock-icon {
    display: block;
}

.nav-item.locked {
    opacity: 0.7;
}

.nav-item.locked:hover {
    cursor: not-allowed;
}

/* Upgrade Modal Icon */
.modal-icon {
    margin-bottom: 24px;
}

.modal-icon svg {
    stroke: var(--accent);
}

/* Plan Comparison Table */
.plan-comparison {
    margin: 32px 0;
    text-align: left;
}

.plan-comparison table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-ui);
    font-size: 0.9375rem;
}

.plan-comparison th {
    font-family: var(--font-ui);
    font-weight: 600;
    text-align: left;
    padding: 12px 16px;
    background: var(--bg-200);
    color: var(--text-primary);
    border-bottom: 1px solid var(--border);
}

.plan-comparison td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
}

.plan-comparison tr:last-child td {
    border-bottom: none;
}

.plan-comparison .plan-name {
    font-weight: 600;
    color: var(--text-primary);
}

.plan-comparison .check-mark {
    color: var(--accent);
    font-weight: 600;
}

.plan-comparison .cross-mark {
    color: var(--text-muted);
    font-weight: 600;
}

/* Plan Selection Cards */
.plan-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin: 32px 0;
}

.plan-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 24px;
    text-align: left;
    cursor: pointer;
    transition: border-color var(--duration) var(--ease),
                background-color var(--duration) var(--ease);
    background: var(--bg-card);
}

.plan-card:hover {
    border-color: var(--border-hover);
    background: var(--bg-200);
}

.plan-card.selected {
    border-color: var(--accent);
    background: var(--accent-muted);
}

.plan-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
}

.plan-card-name {
    font-family: var(--font-ui);
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.plan-card-price {
    font-family: var(--font-ui);
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 4px;
}

.plan-card-period {
    font-family: var(--font-ui);
    font-size: 0.875rem;
    color: var(--text-tertiary);
}

.plan-card-check {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color var(--duration) var(--ease),
                background-color var(--duration) var(--ease);
}

.plan-card.selected .plan-card-check {
    background: var(--accent);
    border-color: var(--accent);
}

.plan-card-check svg {
    width: 14px;
    height: 14px;
    stroke: var(--accent-on);
    display: none;
}

.plan-card.selected .plan-card-check svg {
    display: block;
}

.plan-card-features {
    list-style: none;
    padding: 0;
    margin: 0;
}

.plan-card-features li {
    font-family: var(--font-ui);
    font-size: 0.875rem;
    color: var(--text-secondary);
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
}

.plan-card-features li:last-child {
    border-bottom: none;
}

.plan-card-features li::before {
    content: "✓";
    color: var(--accent);
    font-weight: 700;
    margin-right: 8px;
}

/* Responsive: Stack plan cards on mobile */
@media (max-width: 640px) {
    .plan-cards {
        grid-template-columns: 1fr;
    }
}

/* ═══════════════════════════════════════════════════════ */
/* ACTIONS MENU (Three-Dot Dropdown) */
/* ═══════════════════════════════════════════════════════ */
.actions-menu-container {
    position: relative;
    z-index: 1000;
}

.actions-menu-btn {
    width: auto !important;
    min-width: 0 !important;
    min-height: 34px !important;
    height: auto !important;
    padding: 6px 10px !important;
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background-color var(--duration) var(--ease),
                border-color var(--duration) var(--ease),
                transform var(--duration-press) var(--ease);
    margin-top: 0 !important;
    white-space: nowrap;
    font-family: var(--font-ui);
}

.actions-menu-icon {
    width: 16px;
    height: 16px;
    color: var(--text-secondary);
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
}

.actions-menu-icon circle {
    fill: none;
}

.actions-menu-label {
    font-family: var(--font-sidebar);
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.actions-menu-caret {
    width: 12px;
    height: 12px;
    color: var(--text-tertiary);
}

.actions-menu-btn:hover {
    background: var(--bg-300);
    border-color: var(--border-hover);
}

.actions-menu-btn:active {
    transform: translateY(1px);
}

.actions-dropdown {
    position: absolute;
    top: 44px;
    right: 0;
    min-width: 210px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 8px 0;
}

.dropdown-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 0.8125rem;
    font-family: var(--font-sidebar);
    text-align: left;
    cursor: pointer;
    transition: background 0.2s ease;
    min-height: auto;
    margin-top: 0;
}

.dropdown-item:hover:not(:disabled) {
    background: var(--bg-300);
}

.dropdown-item:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.dropdown-item svg {
    flex-shrink: 0;
}

/* ========================================
   PIS/COFINS TOPIC BADGES
   ============================================ */
.topic-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    margin-top: 8px;
}
.topic-badge.credit {
    background: #22c55e;
    color: white;
}
.topic-badge.debit {
    background: #3b82f6;
    color: white;
}
.topic-badge.sped {
    background: #a855f7;
    color: white;
}
.topic-badge.general {
    background: #6b7280;
    color: white;
}

/* ============================================

/* ============================================
   MODALS (SIGNUP / UPGRADE / SHARE / EMAIL)
   ============================================ */
.signup-modal,
.upgrade-modal,
.share-modal,
.email-modal {
    position: fixed;
    inset: 0;
    background: rgba(20, 20, 19, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 24px;
}

.signup-modal-content,
.upgrade-modal-content,
.share-modal-content,
.email-modal-content {
    width: min(90vw, 520px);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: relative;
    box-shadow: 0 20px 60px rgba(12, 12, 10, 0.22);
    font-family: var(--font-ui);
}

.signup-modal-content h2,
.upgrade-modal-content h2,
.share-modal-content h2,
.email-modal-content h2 {
    font-family: var(--font-ui);
    font-size: 1rem;
    margin: 0;
}

.signup-modal-content p,
.upgrade-modal-content p,
.share-modal-content p,
.email-modal-content p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.signup-modal-close,
.upgrade-modal-close,
.share-modal-close,
.email-modal-close {
    position: absolute;
    top: 20px;
    right: 24px;
    width: 36px;
    height: 36px;
    padding: 0;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 1.25rem;
    line-height: 1;
    color: var(--text-secondary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.signup-modal-close:hover,
.upgrade-modal-close:hover,
.share-modal-close:hover,
.email-modal-close:hover {
    background: var(--bg-300);
}

.signup-modal-btn,
.checkout-btn {
    background: var(--accent);
    color: var(--accent-on);
    border: none;
    border-radius: 10px;
    padding: 10px 14px;
    font-family: var(--font-ui);
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
}

.signup-modal-login {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.signup-modal-login a {
    color: var(--accent);
    font-weight: 600;
    text-decoration: underline;
}

.plan-toggle {
    display: flex;
    gap: 8px;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-input);
}

.plan-btn {
    flex: 1;
    border: 0;
    background: transparent;
    color: var(--text-secondary);
    padding: 8px 10px;
    border-radius: 8px;
    font-family: var(--font-ui);
    font-size: 0.8rem;
    cursor: pointer;
}

.plan-btn.selected {
    background: var(--bg-card);
    color: var(--text-primary);
    box-shadow: 0 0 0 1px var(--border) inset;
}

.plan-price {
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.price-value {
    font-size: 1.5rem;
    font-weight: 700;
}

.price-period {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.share-link-row {
    display: flex;
    gap: 8px;
}

.share-link-row input {
    flex: 1;
}

.share-link-row input,
.email-modal-content input,
.email-modal-content textarea {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    font-family: var(--font-ui);
    font-size: 0.8125rem;
    color: var(--text-primary);
}

.share-copy-btn,
.share-action-btn,
.email-send-btn {
    background: var(--accent);
    color: var(--accent-on);
    border: none;
    border-radius: 8px;
    padding: 8px 12px;
    font-family: var(--font-ui);
    font-weight: 600;
    cursor: pointer;
}

.share-action-btn.danger {
    background: transparent;
    color: var(--error);
    border: 1px solid var(--border);
}

.share-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.share-status,
.email-status {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.email-modal-content label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-family: var(--font-ui);
}

.email-modal-content textarea {
    resize: vertical;
}

@media (max-width: 1024px) {
    .conversation-layout {
        grid-template-columns: 1fr;
        max-width: var(--chat-max-width);
    }

    .sources-panel {
        display: none;
    }

    .chat-topbar {
        max-width: var(--chat-max-width);
    }
}
