:root {
    /* ── Paleta Oficial Prefeitura de Paulo Afonso 2026 ── */
    --primary: #244e9c;
    --primary-hover: #1a3a78;
    --primary-light: #e8eef8;
    --accent: #38beef;
    --accent-light: #e0f7fd;
    --brand-yellow: #fccf00;
    --brand-orange: #e9561e;
    --brand-green: #47ab34;
    --brand-dark-green: #005e34;

    --bg-base: #f0f4f8;
    --bg-surface: #ffffff;
    --bg-surface-hover: #f8fafc;
    --bg-elevated: #ffffff;

    --text-primary: #0d1b2a;
    --text-secondary: #3d5066;
    --text-tertiary: #8a99b0;

    --border-subtle: #eef2f8;
    --border-color: #dce4f0;
    --border-strong: #b8c8e0;

    /* Sidebar — sempre azul institucional */
    --sidebar-bg: #244e9c;
    --sidebar-bg-hover: rgba(255,255,255,0.10);
    --sidebar-active-bg: rgba(56,190,239,0.18);
    --sidebar-text: rgba(255,255,255,0.72);
    --sidebar-text-active: #38beef;
    --sidebar-border: rgba(255,255,255,0.10);
    --sidebar-section: rgba(255,255,255,0.40);

    /* Semânticas — alinhadas à paleta da marca */
    --success: #47ab34;
    --warning: #fccf00;
    --danger: #e9561e;
    --info: #38beef;

    --success-bg: #e8f8e4;
    --warning-bg: #fff9e0;
    --danger-bg:  #fdeee9;
    --info-bg:    #e0f7fd;

    --success-text: #1a5c0e;
    --warning-text: #7a5c00;
    --danger-text:  #7a1c00;
    --info-text:    #0a5f7a;

    /* Métricas */
    --sidebar-width: 280px;
    --header-height: 72px;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.06);
    --shadow-md: 0 4px 12px -2px rgb(0 0 0 / 0.08), 0 2px 4px -2px rgb(0 0 0 / 0.05);
    --shadow-lg: 0 12px 28px -5px rgb(0 0 0 / 0.12), 0 6px 10px -4px rgb(0 0 0 / 0.06);
}

[data-theme="dark"] {
    --bg-base: #0a1220;
    --bg-surface: #0f1e35;
    --bg-surface-hover: #162844;
    --bg-elevated: #0f1e35;

    --text-primary: #e8eef8;
    --text-secondary: #a0b4cc;
    --text-tertiary: #5a7090;

    --border-subtle: #0f1e35;
    --border-color: #1a2e4a;
    --border-strong: #2a4068;

    --primary: #3a6fd4;
    --primary-hover: #4a7fe4;
    --primary-light: rgba(36,78,156,0.25);

    --success-bg: rgba(71,171,52,0.15);
    --warning-bg: rgba(252,207,0,0.12);
    --danger-bg:  rgba(233,86,30,0.15);
    --info-bg:    rgba(56,190,239,0.12);

    --success-text: #6dce57;
    --warning-text: #ffe066;
    --danger-text:  #f5896a;
    --info-text:    #7adeff;

    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.4);
    --shadow-md: 0 4px 12px -2px rgb(0 0 0 / 0.5);
    --shadow-lg: 0 20px 40px -8px rgb(0 0 0 / 0.6), 0 8px 12px -4px rgb(0 0 0 / 0.5);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
}

body {
    background-color: var(--bg-base);
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
    overflow: hidden; /* Prevent body scroll, let views scroll */
    -webkit-font-smoothing: antialiased;
}

/* Base Layout Structure */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Typography Utility */
h1, h2, h3, h4, h5, h6 { font-family: 'Nunito', sans-serif; font-weight: 700; color: var(--text-primary); }
p { color: var(--text-secondary); line-height: 1.6; }

/* === SIDEBAR — Identidade Institucional Prefeitura de Paulo Afonso === */
.sidebar {
    width: var(--sidebar-width);
    background-color: #244e9c;
    border-right: none;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    z-index: 100;
    box-shadow: 4px 0 20px rgba(0,0,0,0.18);
}

/* Força sidebar sempre azul, independente do tema */
.sidebar,
[data-theme="dark"] .sidebar {
    background-color: #244e9c !important;
}
.sidebar-header,
[data-theme="dark"] .sidebar-header {
    background: #1a3a78 !important;
    border-bottom-color: rgba(255,255,255,0.1) !important;
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    background: #1a3a78;
}

/* Brasão / Logo Institucional */
.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
}

.logo-brasao {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

.logo-text {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
}

.logo-text .logo-prefeitura {
    font-family: 'Nunito', sans-serif;
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #38beef;
    opacity: 0.9;
}

.logo-text .logo-name {
    font-family: 'Nunito', sans-serif;
    font-size: 0.95rem;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: -0.01em;
}

/* Compatibilidade com código legado que usa .logo i / .logo b */
.logo i { display: none; }
.logo > span { display: none; }

.mobile-menu-toggle {
    display: none;
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.7);
    font-size: 1.5rem;
    cursor: pointer;
}

.nav-section-title {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgba(255,255,255,0.4);
    font-weight: 700;
    margin: 20px 16px 6px 16px;
    font-family: 'Nunito', sans-serif;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
}

.sidebar-nav::-webkit-scrollbar { width: 3px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 11px 14px;
    border-radius: var(--radius-md);
    color: rgba(255,255,255,0.72);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.18s ease;
    position: relative;
    font-size: 0.9rem;
}

.nav-item i { font-size: 1.25rem; flex-shrink: 0; }

.nav-item:hover {
    background-color: rgba(255,255,255,0.1);
    color: #ffffff;
}

.nav-item.active {
    background-color: rgba(56,190,239,0.18);
    color: #38beef;
    font-weight: 600;
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 20%;
    height: 60%;
    width: 3px;
    background: #38beef;
    border-radius: 0 3px 3px 0;
}

.nav-badge {
    margin-left: auto;
    background-color: #fccf00;
    color: #1a1200;
    font-size: 0.72rem;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-weight: 700;
}

.sidebar-footer {
    padding: 16px 12px;
    border-top: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: rgba(0,0,0,0.15);
}

.icon-button {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.12);
    color: rgba(255,255,255,0.65);
    border-radius: var(--radius-full);
    width: 38px;
    height: 38px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

.icon-button:hover {
    background: rgba(255,255,255,0.15);
    color: #ffffff;
    transform: translateY(-1px);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius-md);
    transition: background 0.2s;
    border: 1px solid transparent;
}

.user-profile:hover {
    background: rgba(255,255,255,0.07);
    border-color: rgba(255,255,255,0.1);
    cursor: pointer;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #38beef;
}

.user-info { display: flex; flex-direction: column; }
.user-name { font-size: 0.88rem; font-weight: 600; color: rgba(255,255,255,0.9); }
.user-role { font-size: 0.76rem; color: rgba(255,255,255,0.45); }
.flex-end { margin-left: auto; color: rgba(255,255,255,0.35); }

/* === MAIN CONTENT === */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.top-header {
    height: var(--header-height);
    background-color: var(--bg-elevated);
    border-bottom: 2px solid #f0f4ff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(36,78,156,0.06);
}

.header-left { display: flex; align-items: center; gap: 16px; }

#page-title {
    font-family: 'Nunito', sans-serif;
    font-size: 1.35rem;
    font-weight: 800;
    color: #244e9c;
    letter-spacing: -0.01em;
}

.header-actions { display: flex; align-items: center; gap: 16px; }

.search-bar {
    display: flex;
    align-items: center;
    background-color: var(--bg-surface-hover);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    padding: 8px 16px;
    width: 300px;
    transition: all 0.2s;
}

.search-bar:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.search-bar i { color: var(--text-tertiary); font-size: 1.2rem; margin-right: 8px; }
.search-bar input {
    border: none;
    background: transparent;
    outline: none;
    color: var(--text-primary);
    width: 100%;
    font-size: 0.9rem;
}

.action-btn {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 1.4rem;
    cursor: pointer;
    position: relative;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

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

.badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background-color: var(--danger);
    color: white;
    font-size: 0.7rem;
    font-weight: bold;
    height: 20px;
    min-width: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    border: 2px solid var(--bg-surface);
}

.view-container {
    flex: 1;
    padding: 36px;
    padding-bottom: 100px; /* espaço para o botão de chat flutuante não cobrir conteúdo */
    overflow-y: auto;
    position: relative;
}

/* Ações compactas nas tabelas de documentos (quebram em 2 linhas, não colidem com o chat) */
.doc-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    max-width: 116px;
}
.doc-actions .icon-button {
    width: 32px;
    height: 32px;
    font-size: 1.05rem;
    background: var(--bg-surface-hover);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}
.doc-actions .icon-button:hover {
    background: var(--border-color);
    color: var(--text-primary);
    transform: none;
}

/* === UTILITY CLASSES FOR VIEWS === */
.fade-in { animation: fadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards; }

.grid-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.stat-card {
    background-color: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 16px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

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

.stat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stat-title { font-size: 0.95rem; font-weight: 600; color: var(--text-secondary); }
.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    background-color: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
}

.stat-value { font-size: 2.2rem; font-weight: 700; color: var(--text-primary); }
.stat-footer { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; }
.trend-up { color: var(--success); display: flex; align-items: center; gap: 4px; font-weight: 600;}
.trend-down { color: var(--danger); display: flex; align-items: center; gap: 4px; font-weight: 600;}

/* Data Tables & Lists */
.panel {
    background-color: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    margin-bottom: 32px;
}

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

.panel-title { font-size: 1.1rem; font-weight: 600; color: var(--text-primary); }

.table-responsive { width: 100%; overflow-x: auto; }

table { width: 100%; border-collapse: collapse; text-align: left; }

th {
    padding: 16px 24px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-tertiary);
    background-color: var(--bg-surface-hover);
    border-bottom: 1px solid var(--border-color);
    letter-spacing: 0.05em;
}

td {
    padding: 16px 24px;
    font-size: 0.95rem;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-subtle);
    vertical-align: middle;
}

tr:hover td { background-color: var(--bg-surface-hover); }
tr:last-child td { border-bottom: none; }

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    font-weight: 600;
}

.status-success { background-color: var(--success-bg); color: var(--success-text); }
.status-warning { background-color: var(--warning-bg); color: var(--warning-text); }
.status-danger { background-color: var(--danger-bg); color: var(--danger-text); }
.status-info { background-color: var(--info-bg); color: var(--info-text); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    font-family: inherit;
}

.btn-primary {
    background: #244e9c;
    color: white;
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    letter-spacing: 0.02em;
    box-shadow: 0 2px 8px rgba(36,78,156,0.25);
}
.btn-primary:hover { background: #1a3a78; transform: translateY(-1px); box-shadow: 0 4px 14px rgba(36,78,156,0.35); }

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

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

/* Responsiveness */
@media (max-width: 1024px) {
    .search-bar { width: 200px; }
}

@media (max-width: 768px) {
    .app-container { position: relative; }
    .sidebar { position: absolute; left: -100%; height: 100%; box-shadow: var(--shadow-lg); }
    .sidebar.open { left: 0; }
    .mobile-menu-toggle { display: block; }
    .search-bar { display: none; }
    .top-header { padding: 0 20px; }
    .view-container { padding: 20px; }
}

/* === MODAL & FORMS === */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.modal-container {
    background: var(--bg-elevated);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    border: 1px solid var(--border-color);
}

.modal-overlay.active .modal-container {
    transform: translateY(0) scale(1);
}

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

.modal-header h3 { font-size: 1.15rem; }

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* Form Elements */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    transition: all 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

textarea.form-control {
    resize: vertical;
    min-height: 80px;
}

.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--bg-elevated);
    border-left: 4px solid var(--success);
    color: var(--text-primary);
    padding: 16px 24px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    z-index: 2000;
    display: flex;
    align-items: center;
    gap: 12px;
    transform: translateX(120%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast.show {
    transform: translateX(0);
}

.toast i { font-size: 1.5rem; color: var(--success); }

@media print {
    body {
        background: white;
        color: black;
    }
    .sidebar, .top-header, .toast, .modal-footer, .btn, .search-bar, .header-actions {
        display: none !important;
    }
    .main-content, .view-container {
        margin: 0;
        padding: 0;
        width: 100%;
        box-shadow: none;
    }
    .modal-overlay {
        position: static;
        background: none;
        backdrop-filter: none;
        display: block;
        opacity: 1;
        pointer-events: auto;
    }
    .modal-container {
        box-shadow: none;
        border: none;
        width: 100%;
        max-width: 100%;
        transform: none;
        margin: 0;
    }
    /* If modal is open, we hide the rest of the app to print just the modal */
    body.modal-open .app-container {
        display: none !important;
    }
}

/* === CHAT WIDGET === */
.chat-widget {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.chat-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: #244e9c;
    color: white;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, background-color 0.2s;
    position: relative;
}

.chat-toggle-btn:hover {
    transform: scale(1.05);
    background-color: #1a3a78;
}

.chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background-color: var(--danger);
    color: white;
    font-size: 0.8rem;
    font-weight: bold;
    min-width: 24px;
    height: 24px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--bg-surface);
}

/* === CHAT PANEL — flex column layout === */
.chat-panel {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 520px;
    background-color: var(--bg-elevated);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: fadeIn 0.3s ease;
}

.chat-header {
    flex-shrink: 0;
    height: 56px;
    padding: 0 16px;
    background-color: #244e9c;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 1rem;
}

.chat-header .icon-button {
    background: transparent;
    color: white;
    border: none;
    width: 32px;
    height: 32px;
}

.chat-header .icon-button:hover {
    background: rgba(255,255,255,0.2);
    border-radius: 6px;
}

/* Sidebar — contacts strip */
.chat-sidebar {
    flex-shrink: 0;
    height: 100px;
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
}

.chat-users-list {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    height: 100%;
    overflow-x: auto;
    box-sizing: border-box;
}

.chat-users-list::-webkit-scrollbar { height: 4px; }
.chat-users-list::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }

.chat-user-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    min-width: 54px;
    transition: opacity 0.2s;
    user-select: none;
}

.chat-user-name {
    font-size: 0.7rem;
    color: var(--text-secondary);
    white-space: nowrap;
    text-align: center;
    max-width: 54px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Messages area — grows to fill remaining space */
.chat-main {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-base);
    overflow: hidden;
}

.chat-messages-container {
    flex: 1;
    min-height: 0;
    padding: 12px 14px 16px 14px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Image thumbnails */
.chat-img-thumb {
    max-width: 210px;
    max-height: 160px;
    border-radius: 10px;
    object-fit: cover;
    cursor: pointer;
    display: block;
}

/* Input area — fixed height at bottom */
.chat-input-area {
    flex-shrink: 0;
    height: 68px;
    padding: 12px 14px;
    background-color: var(--bg-elevated);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 10px;
    box-sizing: border-box;
}

/* Message bubbles */

.msg-group {
    display: flex;
    flex-direction: column;
    max-width: 78%;
    gap: 3px;
}

.msg-group.self {
    align-self: flex-end;
    align-items: flex-end;
}

.msg-group.other {
    align-self: flex-start;
    align-items: flex-start;
}

.msg-meta {
    font-size: 0.7rem;
    color: var(--text-tertiary);
    margin-bottom: 2px;
    padding: 0 2px;
}

.msg-group.self .msg-meta { text-align: right; }

.msg-bubble {
    padding: 7px 12px;
    border-radius: 14px;
    font-size: 0.88rem;
    line-height: 1.45;
    word-break: break-word;
    max-width: 100%;
}

.msg-group.self .msg-bubble {
    background-color: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.msg-group.other .msg-bubble {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.msg-other-row {
    display: flex;
    align-items: flex-end;
    gap: 6px;
}

.msg-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

/* keep old compat classes */
.chat-message-info { font-size: 0.75rem; color: var(--text-tertiary); }
.chat-message-content { padding: 7px 12px; border-radius: 14px; font-size: 0.88rem; line-height: 1.45; }

#chat-input-field {
    flex: 1;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.2s;
    font-size: 0.9rem;
}

#chat-input-field:focus { border-color: var(--primary); }

.chat-send-btn {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-md);
    background-color: #244e9c;
    color: white;
    border: none;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color 0.2s;
}

.chat-send-btn:hover { background-color: #1a3a78; }

@media (max-width: 480px) {
    .chat-panel { width: 100vw; height: 100vh; bottom: 0; right: 0; border-radius: 0; }
    .chat-widget { bottom: 20px; right: 20px; }
}

