/* ===== Variables ===== */
:root {
    --primary: #1a56db;
    --primary-hover: #1644b0;
    --secondary: #059669;
    --bg: #f8fafc;
    --bg-chat: #f1f5f9;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --bubble-user: #1a56db;
    --bubble-assistant: #ffffff;
    --radius: 14px;
    --sidebar-width: 280px;
    --sidebar-bg: #0f172a;
    --sidebar-hover: #1e293b;
    --sidebar-active: #334155;
    --sidebar-text: #cbd5e1;
    --sidebar-text-muted: #64748b;
}

/* ===== Base ===== */
*, *::before, *::after { box-sizing: border-box; }
html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    font-size: 15px;
    color: var(--text);
    background: var(--bg);
}

/* ===== App Wrapper (Sidebar + Chat) ===== */
.app-wrapper {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform 0.25s ease, margin-left 0.25s ease;
    z-index: 1000;
}
.sidebar-header {
    padding: 0.85rem;
    flex-shrink: 0;
}
.sidebar-new-chat-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.7rem 0.9rem;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.08);
    background: rgba(255,255,255,0.05);
    color: var(--sidebar-text);
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.sidebar-new-chat-btn:hover {
    background: var(--sidebar-hover);
    border-color: rgba(255,255,255,0.15);
}
.sidebar-new-chat-btn i {
    font-size: 1.05rem;
}

/* Conversations list */
.sidebar-conversations {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0.5rem 0.5rem 0.5rem;
}
.sidebar-conversations::-webkit-scrollbar {
    width: 5px;
}
.sidebar-conversations::-webkit-scrollbar-track {
    background: transparent;
}
.sidebar-conversations::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 3px;
}

.sidebar-empty {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--sidebar-text-muted);
}
.sidebar-empty i {
    font-size: 1.75rem;
    margin-bottom: 0.5rem;
    display: block;
    opacity: 0.5;
}
.sidebar-empty p {
    font-size: 0.8rem;
    margin: 0;
}

/* Conversation item */
.conv-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 0.75rem;
    border-radius: 8px;
    cursor: pointer;
    color: var(--sidebar-text);
    font-size: 0.825rem;
    line-height: 1.4;
    transition: background 0.15s;
    position: relative;
    margin-bottom: 2px;
}
.conv-item:hover {
    background: var(--sidebar-hover);
}
.conv-item.active {
    background: var(--sidebar-active);
}
.conv-item-icon {
    flex-shrink: 0;
    font-size: 0.9rem;
    opacity: 0.7;
    margin-top: 1px;
}
.conv-item-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.conv-item-delete {
    flex-shrink: 0;
    opacity: 0;
    background: none;
    border: none;
    color: var(--sidebar-text-muted);
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    font-size: 0.85rem;
    transition: opacity 0.15s, color 0.15s, background 0.15s;
}
.conv-item:hover .conv-item-delete {
    opacity: 1;
}
.conv-item-delete:hover {
    color: #ef4444;
    background: rgba(239,68,68,0.1);
}

/* Sidebar footer */
.sidebar-footer {
    padding: 0.75rem 0.85rem;
    border-top: 1px solid rgba(255,255,255,0.06);
    flex-shrink: 0;
}
.sidebar-clear-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.75rem;
    border-radius: 8px;
    border: none;
    background: none;
    color: var(--sidebar-text-muted);
    font-family: inherit;
    font-size: 0.825rem;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    margin-bottom: 0.5rem;
}
.sidebar-clear-btn:hover {
    background: rgba(239,68,68,0.1);
    color: #ef4444;
}
.sidebar-clear-btn i {
    font-size: 0.9rem;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--sidebar-text);
    font-size: 0.8rem;
    font-weight: 500;
    opacity: 0.7;
}
.sidebar-brand-text {
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

/* Sidebar toggle (mobile) */
.sidebar-toggle {
    display: none;
}

/* Sidebar Mobile Header */
.sidebar-mobile-header {
    display: none;
}

/* Sidebar Backdrop */
.sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    z-index: 999;
}
.sidebar-backdrop.show {
    display: block;
}

/* ===== Layout ===== */
.chat-layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
    flex: 1;
    min-width: 0;
    background: var(--bg);
}

/* ===== Header ===== */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    background: #fff;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.chat-header-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.chat-header-avatar {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, #1a56db, #064e7b);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}
.chat-header-avatar-text {
    font-weight: 700;
    font-size: 1.1rem;
    line-height: 1;
}
.chat-header-title {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0;
    line-height: 1.3;
}
.chat-header-status {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.35rem;
}
.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--secondary);
    display: inline-block;
}
.chat-header-action {
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-muted);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.chat-header-action:hover {
    background: #fee2e2;
    color: #dc2626;
    border-color: #fecaca;
}

/* ===== Empresa Ativa Banner (contexto NIF) ===== */
.empresa-ativa-banner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1.25rem;
    background: linear-gradient(135deg, #eff6ff, #dbeafe);
    border-bottom: 1px solid #bfdbfe;
    font-size: 0.8rem;
    color: #1e40af;
    flex-shrink: 0;
    animation: fadeInMsg 0.25s ease-out;
    overflow: hidden;
    white-space: nowrap;
}
.empresa-ativa-banner > i {
    font-size: 1rem;
    color: #1a56db;
    flex-shrink: 0;
}
.empresa-ativa-nome {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
}
.empresa-ativa-sep {
    color: #93c5fd;
    flex-shrink: 0;
}
.empresa-ativa-nif,
.empresa-ativa-tipo,
.empresa-ativa-regime {
    flex-shrink: 0;
}
.empresa-ativa-remove {
    margin-left: auto;
    flex-shrink: 0;
    background: none;
    border: none;
    color: #1e40af;
    cursor: pointer;
    font-size: 0.8rem;
    padding: 2px 6px;
    border-radius: 4px;
    transition: background 0.15s, color 0.15s;
}
.empresa-ativa-remove:hover {
    background: rgba(30, 64, 175, 0.1);
    color: #1e3a8a;
}

@media (max-width: 768px) {
    .empresa-ativa-banner {
        padding: 0.5rem 1rem;
        font-size: 0.75rem;
    }
    .empresa-ativa-tipo,
    .empresa-ativa-regime {
        display: none;
    }
}

/* ===== Chat Messages Area ===== */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    background: var(--bg-chat);
    scroll-behavior: smooth;
}

/* ===== Empty State ===== */
.empty-state {
    margin: auto;
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
}
.empty-state-icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    background: #e2e8f0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--text-muted);
}
.empty-state h2 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
    margin: 0 0 0.4rem;
}
.empty-state p {
    font-size: 0.875rem;
    margin: 0 auto;
    max-width: 420px;
    line-height: 1.5;
}

/* Suggestion chips */
.suggestion-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    margin-top: 1.5rem;
    max-width: 480px;
}
.suggestion-chip {
    padding: 0.5rem 0.9rem;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, transform 0.1s;
    white-space: nowrap;
}
.suggestion-chip:hover {
    border-color: var(--primary);
    background: var(--bg);
}
.suggestion-chip:active {
    transform: scale(0.96);
}

/* NIF start button (empty state) */
.nif-start-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 1rem;
    padding: 0.5rem 1.1rem;
    border-radius: 20px;
    border: 1px solid var(--primary);
    background: #fff;
    color: var(--primary);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, transform 0.1s;
}
.nif-start-btn:hover {
    background: var(--primary);
    color: #fff;
}
.nif-start-btn:active {
    transform: scale(0.96);
}

/* ===== Message Bubbles ===== */
.chat-messages .d-flex {
    animation: fadeInMsg 0.25s ease-out;
    max-width: 100%;
}

/* User bubble */
.chat-messages .bg-primary {
    background: var(--bubble-user) !important;
    color: #fff;
    border-radius: var(--radius) var(--radius) 4px var(--radius);
    font-size: 0.9375rem;
    line-height: 1.55;
    box-shadow: 0 1px 3px rgba(26, 86, 219, 0.15);
    max-width: 75% !important;
    padding: 0.65rem 1rem !important;
    overflow-wrap: break-word;
    word-break: break-word;
}

/* Assistant bubble */
.chat-messages .bg-light {
    background: var(--bubble-assistant) !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--radius) var(--radius) var(--radius) 4px;
    font-size: 0.9375rem;
    line-height: 1.55;
    color: var(--text);
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
    max-width: 75% !important;
    padding: 0.65rem 1rem !important;
    overflow-wrap: break-word;
    word-break: break-word;
}

/* ===== Markdown Content (assistant bubbles) ===== */
.md-content {
    white-space: normal;
}
.md-content > *:first-child { margin-top: 0; }
.md-content > *:last-child { margin-bottom: 0; }
.md-content .md-p {
    margin: 0 0 0.6rem;
    line-height: 1.55;
}
.md-content .md-h1,
.md-content .md-h2,
.md-content .md-h3,
.md-content .md-h4,
.md-content .md-h5,
.md-content .md-h6 {
    font-weight: 600;
    line-height: 1.3;
    margin: 0.9rem 0 0.5rem;
    color: var(--text);
}
.md-content .md-h1 { font-size: 1.35rem; }
.md-content .md-h2 { font-size: 1.2rem; }
.md-content .md-h3 { font-size: 1.08rem; }
.md-content .md-h4 { font-size: 1rem; }
.md-content .md-h5 { font-size: 0.9rem; }
.md-content .md-h6 { font-size: 0.85rem; color: var(--text-muted); }
.md-content strong { font-weight: 600; }
.md-content em { font-style: italic; }
.md-content del { opacity: 0.7; }
.md-content a {
    color: var(--primary);
    text-decoration: underline;
    word-break: break-word;
}
.md-content a:hover { color: var(--primary-hover); }
.md-content .md-ul,
.md-content .md-ol {
    margin: 0 0 0.6rem;
    padding-left: 1.4rem;
}
.md-content .md-ul li,
.md-content .md-ol li {
    margin-bottom: 0.25rem;
    line-height: 1.5;
}
.md-content .md-blockquote {
    margin: 0 0 0.6rem;
    padding: 0.4rem 0.9rem;
    border-left: 3px solid var(--border);
    background: var(--bg-chat);
    border-radius: 6px;
    color: var(--text-muted);
}
.md-content .md-blockquote > *:last-child { margin-bottom: 0; }
.md-content .md-hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 0.8rem 0;
}
.md-content .md-code-inline {
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.85em;
    background: #f1f5f9;
    color: #be123c;
    padding: 0.12rem 0.35rem;
    border-radius: 5px;
    border: 1px solid var(--border);
}
.md-content .md-pre {
    margin: 0 0 0.6rem;
    padding: 0.75rem 0.9rem;
    background: #0f172a;
    border-radius: 10px;
    overflow-x: auto;
}
.md-content .md-pre .md-code-block {
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.82rem;
    line-height: 1.55;
    color: #e2e8f0;
    background: none;
    border: none;
    padding: 0;
    white-space: pre;
}
.md-content .md-pre::-webkit-scrollbar { height: 6px; }
.md-content .md-pre::-webkit-scrollbar-track { background: transparent; }
.md-content .md-pre::-webkit-scrollbar-thumb {
    background: #475569;
    border-radius: 3px;
}
.md-content .md-table-wrap {
    margin: 0 0 0.6rem;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
}
.md-content .md-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.md-content .md-table th,
.md-content .md-table td {
    padding: 0.5rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
    vertical-align: top;
    white-space: nowrap;
}
.md-content .md-table th:last-child,
.md-content .md-table td:last-child { border-right: none; }
.md-content .md-table tbody tr:last-child td { border-bottom: none; }
.md-content .md-table thead th {
    background: var(--bg-chat);
    font-weight: 600;
    color: var(--text);
}
.md-content .md-table tbody tr:nth-child(even) td {
    background: rgba(148, 163, 184, 0.06);
}
.md-content .md-table-wrap::-webkit-scrollbar { height: 6px; }
.md-content .md-table-wrap::-webkit-scrollbar-track { background: transparent; }
.md-content .md-table-wrap::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

/* Alert (error messages) */
.chat-messages .alert-danger {
    border-radius: var(--radius);
    font-size: 0.875rem;
    border: 1px solid #fecaca;
    background: #fef2f2;
    color: #991b1b;
}

/* Debug info */
.chat-messages .text-muted.small {
    font-size: 0.75rem;
    color: var(--text-muted) !important;
    opacity: 0.7;
}

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

/* ===== Typing Indicator ===== */
@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}
.typing-indicator {
    background: var(--bubble-assistant) !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--radius) var(--radius) var(--radius) 4px;
    padding: 0.75rem 1rem !important;
    display: inline-flex;
    align-items: center;
    gap: 2px;
}
.typing-indicator span {
    display: inline-block;
    width: 7px;
    height: 7px;
    margin: 0 2px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typing-bounce 1.2s infinite ease-in-out;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

/* ===== Input Area ===== */
.chat-input-area {
    padding: 1rem 1.25rem 1.5rem;
    background: #fff;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.chat-form {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.35rem 0.35rem 0.35rem 1rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.chat-form:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.1);
}
.chat-disclaimer {
    margin: 0.5rem 0 0;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted, #6b7280);
}
.chat-input {
    flex: 1;
    min-width: 0;
    border: none;
    outline: none;
    background: transparent;
    font-family: inherit;
    font-size: 0.9375rem;
    color: var(--text);
    padding: 0.4rem 0;
    resize: none;
    max-height: 120px;
    overflow-y: auto;
    line-height: 1.5;
}
.chat-input::placeholder {
    color: #94a3b8;
}
.chat-input::-webkit-scrollbar {
    width: 5px;
}
.chat-input::-webkit-scrollbar-track {
    background: transparent;
}
.chat-input::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}
.chat-input::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}
.chat-input {
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}
.chat-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: none;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.95rem;
    flex-shrink: 0;
    transition: background 0.15s, transform 0.1s;
}
.chat-send-btn:hover {
    background: var(--primary-hover);
}
.chat-send-btn:active {
    transform: scale(0.95);
}
.chat-send-btn:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
}

/* ===== Scrollbar ===== */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}
.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}
.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        border-radius: 8px;
        border: 1px solid var(--border);
        background: #fff;
        color: var(--text);
        cursor: pointer;
        font-size: 1.15rem;
        flex-shrink: 0;
        transition: background 0.15s, border-color 0.15s;
    }
    .sidebar-toggle:hover {
        background: var(--bg);
        border-color: #cbd5e1;
    }
    .chat-layout {
        max-width: 100%;
    }
    .chat-header {
        padding: 0.65rem 1rem;
    }
    .sidebar-mobile-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 1.1rem 1rem 0.75rem;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08);
        flex-shrink: 0;
    }
    .sidebar-mobile-header .sidebar-brand-text {
        font-size: 1rem;
        font-weight: 600;
        color: var(--sidebar-text);
    }
    .sidebar-close-btn {
        background: none;
        border: none;
        color: var(--sidebar-text-muted);
        cursor: pointer;
        font-size: 1.3rem;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 4px;
        border-radius: 6px;
        transition: background 0.15s, color 0.15s;
    }
    .sidebar-close-btn:hover {
        background: var(--sidebar-hover);
        color: var(--sidebar-text);
    }
    .chat-messages {
        padding: 1rem;
    }
    .chat-messages .bg-primary,
    .chat-messages .bg-light {
        max-width: 88% !important;
    }
    .chat-input-area {
        padding: 0.75rem 0.75rem 1.25rem;
    }
    .chat-form {
        padding: 0.25rem 0.25rem 0.25rem 0.85rem;
    }
    .empty-state {
        padding: 1.5rem 1rem;
    }
    .conv-item-delete {
        opacity: 0.8;
    }
}

@media (max-width: 480px) {
    .chat-header-title {
        font-size: 0.875rem;
    }
    .chat-header-avatar {
        width: 34px;
        height: 34px;
        font-size: 0.9rem;
    }
    .chat-messages .bg-primary,
    .chat-messages .bg-light {
        max-width: 92% !important;
        font-size: 0.875rem;
    }
    .chat-send-btn {
        width: 36px;
        height: 36px;
    }
}

/* ===== Confirm Modal ===== */
.confirm-modal {
    border: none;
    border-radius: 16px;
    max-width: 380px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
.confirm-modal .modal-body {
    text-align: center;
    padding: 2rem 1.5rem 1rem;
}
.confirm-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #fef3c7;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
}
.confirm-icon i {
    font-size: 1.6rem;
    color: #f59e0b;
}
.confirm-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
    margin: 0 0 0.4rem;
}
.confirm-text {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin: 0;
    line-height: 1.5;
}
.confirm-footer {
    border: none;
    padding: 0.5rem 1.5rem 1.5rem;
    justify-content: center;
    gap: 0.75rem;
}
.btn-cancel {
    padding: 0.55rem 1.5rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}
.btn-cancel:hover {
    background: var(--bg);
}
.btn-confirm {
    padding: 0.55rem 1.5rem;
    border-radius: 10px;
    border: none;
    background: #ef4444;
    color: #fff;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}
.btn-confirm:hover {
    background: #dc2626;
}

/* ===== NIF Button (header) ===== */
.nif-btn {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: var(--text-muted);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.nif-btn:hover {
    background: var(--bg);
    color: var(--primary);
    border-color: var(--primary);
}

/* ===== NIF Modal ===== */
.nif-modal {
    border: none;
    border-radius: 16px;
    max-width: 460px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
.nif-modal-header {
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.25rem;
}
.nif-modal-header .modal-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.nif-modal-header .modal-title i {
    color: var(--primary);
}
.nif-modal-body {
    padding: 1.25rem;
}

/* NIF Form */
.nif-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.nif-field {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}
.nif-field label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
}
.nif-field .form-control {
    border-radius: 8px;
    border-color: var(--border);
    font-size: 0.875rem;
}
.nif-field .form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.1);
}
.nif-submit-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.55rem 1.5rem;
    border-radius: 10px;
    border: none;
    background: var(--primary);
    color: #fff;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}
.nif-submit-btn:hover {
    background: var(--primary-hover);
}
.nif-submit-btn:active {
    transform: scale(0.97);
}
.nif-submit-btn:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
}

/* NIF Result */
.nif-result {
    margin-top: 1rem;
}
.nif-card {
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    animation: fadeInMsg 0.25s ease-out;
}
.nif-card-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: linear-gradient(135deg, #1a56db, #064e7b);
    color: #fff;
    font-size: 0.9rem;
    font-weight: 600;
}
.nif-card-header i {
    font-size: 1.1rem;
}
.nif-card-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
}
.nif-card-item {
    padding: 0.65rem 1rem;
    border-bottom: 1px solid var(--border);
}
.nif-card-item:nth-child(odd) {
    border-right: 1px solid var(--border);
}
.nif-card-item:nth-last-child(-n+2) {
    border-bottom: none;
}
.nif-label {
    display: block;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.2rem;
}
.nif-value {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text);
}

/* NIF Badges */
.nif-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.6rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}
.nif-badge-a { background: #dcfce7; color: #166534; }
.nif-badge-c { background: #fee2e2; color: #991b1b; }
.nif-badge-d { background: #e0e7ff; color: #3730a3; }
.nif-badge-e { background: #fef3c7; color: #92400e; }
.nif-badge-f { background: #f3f4f6; color: #6b7280; }
.nif-badge-g { background: #ffedd5; color: #9a3412; }

/* NIF Error */
.nif-error {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-radius: 10px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
    font-size: 0.875rem;
    animation: fadeInMsg 0.25s ease-out;
}
.nif-error i {
    font-size: 1.1rem;
    flex-shrink: 0;
}

/* Responsive NIF */
@media (max-width: 480px) {
    .nif-card-grid {
        grid-template-columns: 1fr;
    }
    .nif-card-item:nth-child(odd) {
        border-right: none;
    }
    .nif-card-item:nth-last-child(2) {
        border-bottom: 1px solid var(--border);
    }
}

/* ===== Termos Modal ===== */
.termos-modal-dialog {
    max-width: 560px;
}
.termos-modal {
    border: none;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
    overflow: hidden;
}
.termos-modal-header {
    background: linear-gradient(135deg, #1a56db, #064e7b);
    border: none;
    padding: 1.25rem 1.5rem;
}
.termos-modal-header .modal-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.termos-modal-header .modal-title i {
    font-size: 1.3rem;
}
.termos-modal-body {
    padding: 1.5rem;
}
.termos-intro {
    font-size: 0.9rem;
    color: var(--text);
    margin-bottom: 1.25rem;
    line-height: 1.5;
}
.termos-links {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin-bottom: 1.25rem;
}
.termos-link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    text-decoration: none;
    color: var(--text);
    font-size: 0.875rem;
    font-weight: 500;
    transition: border-color 0.15s, background 0.15s;
}
.termos-link:hover {
    border-color: var(--primary);
    background: #eff6ff;
    color: var(--primary);
}
.termos-link i:first-child {
    font-size: 1.1rem;
    color: var(--primary);
}
.termos-link span {
    flex: 1;
}
.termos-link-external {
    font-size: 0.75rem;
    color: var(--text-muted);
}
.termos-resumo {
    background: var(--bg-chat);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem 1.25rem;
    margin-bottom: 1.25rem;
}
.termos-resumo h6 {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
    margin-bottom: 0.6rem;
}
.termos-resumo ul {
    margin: 0;
    padding-left: 1.2rem;
    font-size: 0.825rem;
    line-height: 1.55;
    color: var(--text);
}
.termos-resumo ul li {
    margin-bottom: 0.35rem;
}
.termos-resumo ul li:last-child {
    margin-bottom: 0;
}
.termos-resumo strong {
    color: #b91c1c;
}
.termos-checkbox-wrap {
    padding: 0.75rem 1rem;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 10px;
}
.termos-checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text);
    line-height: 1.5;
    margin: 0;
}
.termos-checkbox-label input[type="checkbox"] {
    margin-top: 0.2rem;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    accent-color: var(--primary);
    cursor: pointer;
}
.termos-checkbox-label a {
    color: var(--primary);
    text-decoration: underline;
    font-weight: 500;
}
.termos-checkbox-label a:hover {
    color: var(--primary-hover);
}
.termos-modal-footer {
    border: none;
    padding: 0.75rem 1.5rem 1.5rem;
    justify-content: flex-end;
    gap: 0.75rem;
}
.btn-termos-decline {
    padding: 0.55rem 1.25rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.btn-termos-decline:hover {
    background: #fef2f2;
    color: #dc2626;
    border-color: #fecaca;
}
.btn-termos-accept {
    padding: 0.55rem 1.5rem;
    border-radius: 10px;
    border: none;
    background: var(--primary);
    color: #fff;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}
.btn-termos-accept:hover:not(:disabled) {
    background: var(--primary-hover);
}
.btn-termos-accept:active:not(:disabled) {
    transform: scale(0.97);
}
.btn-termos-accept:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
}

/* Chat bloqueado overlay */
.chat-bloqueado .chat-messages {
    pointer-events: none;
    opacity: 0.6;
}
.chat-bloqueado .chat-input-area {
    pointer-events: none;
    opacity: 0.6;
}

@media (max-width: 480px) {
    .termos-modal-dialog {
        max-width: 95%;
        margin: 0.5rem;
    }
    .termos-modal-body {
        padding: 1rem;
    }
    .termos-modal-footer {
        flex-direction: column-reverse;
    }
    .btn-termos-decline,
    .btn-termos-accept {
        width: 100%;
    }
}
