/* -- Reset & Base ------------------------------------------------------------- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --blue-dark: #0a3d73;
    --blue-mid: #105bab;
    --blue-light: #1a73d4;
    --yellow: #f5c518;
    --gray-bg: #f5f5f5;
    --gray-light: #e8e8e8;
    --gray-mid: #999;
    --white: #ffffff;
    --text-dark: #1a1a1a;
    --text-mid: #444;
    --sidebar-width: 280px;
    --topbar-height: 56px;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 15px;
    color: var(--text-dark);
    background: var(--white);
}

body {
    display: flex;
    overflow: hidden;
}

/* -- Sidebar ---------------------------------------------------------------- */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--blue-dark);
    color: var(--white);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 20px 16px 14px;
    text-align: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.logo-prefeitura {
    width: 180px;
    max-width: 80%;
    height: auto;
    margin-bottom: 8px;
}

.sidebar-header .subtitle {
    font-size: 15px;
    font-weight: bold;
    opacity: 0.9;
    margin-top: 6px;
}

.btn-new-conv {
    margin: 12px 16px;
    padding: 10px;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.3);
    color: var(--white);
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}

.btn-new-conv:hover {
    background: rgba(255,255,255,0.1);
}

/* Filters */
.filters {
    padding: 8px 16px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.filters label {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.6;
    margin: 8px 0 4px;
}

.filters label:first-child {
    margin-top: 0;
}

.filters select {
    width: 100%;
    padding: 6px 8px;
    border-radius: 6px;
    border: none;
    background: rgba(255,255,255,0.12);
    color: var(--white);
    font-size: 13px;
    cursor: pointer;
}

.filters select option {
    background: var(--blue-dark);
    color: var(--white);
}

/* Conversations list */
.conversations-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.conv-item {
    padding: 10px 16px;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-left: 3px solid transparent;
    transition: background 0.15s;
}

.conv-item:hover {
    background: rgba(255,255,255,0.08);
}

.conv-item.active {
    background: rgba(255,255,255,0.12);
    border-left-color: var(--yellow);
}

.conv-item .conv-date {
    font-size: 10px;
    opacity: 0.5;
    display: block;
    margin-top: 2px;
}

.sidebar-footer {
    padding: 10px 16px;
    font-size: 10px;
    opacity: 0.4;
    text-align: center;
    border-top: 1px solid rgba(255,255,255,0.1);
    line-height: 1.6;
}

.sidebar-footer span {
    display: block;
}

.sidebar-footer .footer-powered {
    font-size: 9px;
    opacity: 0.7;
}

/* Sidebar toggle (mobile) */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1000;
    background: var(--blue-dark);
    color: var(--white);
    border: none;
    border-radius: 8px;
    width: 40px;
    height: 40px;
    font-size: 20px;
    cursor: pointer;
}

/* -- Chat Area -------------------------------------------------------------- */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    min-width: 0;
}

.topbar {
    height: var(--topbar-height);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--gray-light);
    background: var(--white);
    flex-shrink: 0;
}

#topbar-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-dark);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-delete {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    opacity: 0.5;
    transition: opacity 0.2s;
    padding: 4px 8px;
}

.btn-delete:hover {
    opacity: 1;
}

/* Messages */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    text-align: center;
    color: var(--text-mid);
}

.welcome-logo {
    width: 160px;
    height: auto;
    margin-bottom: 20px;
    border-radius: 8px;
}

.welcome h2 {
    font-size: 24px;
    color: var(--blue-dark);
    margin-bottom: 8px;
}

.welcome p {
    margin-bottom: 24px;
    font-size: 15px;
}

.examples {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    max-width: 600px;
}

.example-btn {
    padding: 10px 16px;
    background: var(--white);
    border: 1px solid var(--gray-light);
    border-radius: 12px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-mid);
    transition: border-color 0.2s, color 0.2s;
}

.example-btn:hover {
    border-color: var(--blue-mid);
    color: var(--blue-mid);
}

/* Message bubbles */
.msg {
    max-width: 780px;
    width: 100%;
    margin: 0 auto;
    line-height: 1.6;
}

.msg-user {
    background: var(--blue-mid);
    color: var(--white);
    padding: 12px 16px;
    border-radius: 16px 16px 4px 16px;
    align-self: flex-end;
    max-width: 75%;
    margin-left: auto;
}

.msg-assistant {
    background: var(--gray-bg);
    color: var(--text-dark);
    padding: 16px;
    border-radius: 16px 16px 16px 4px;
}

.msg-assistant p {
    margin-bottom: 10px;
}

.msg-assistant p:last-child {
    margin-bottom: 0;
}

.msg-assistant ul, .msg-assistant ol {
    margin: 8px 0 12px 20px;
}

.msg-assistant li {
    margin-bottom: 4px;
}

.msg-assistant strong {
    font-weight: 600;
}

.msg-assistant em {
    font-style: italic;
}

.msg-assistant h1, .msg-assistant h2, .msg-assistant h3,
.msg-assistant h4, .msg-assistant h5, .msg-assistant h6 {
    margin: 16px 0 8px;
    color: var(--blue-dark);
    line-height: 1.3;
}

.msg-assistant h1 { font-size: 1.4em; }
.msg-assistant h2 { font-size: 1.25em; }
.msg-assistant h3 { font-size: 1.1em; }

.msg-assistant h1:first-child,
.msg-assistant h2:first-child,
.msg-assistant h3:first-child {
    margin-top: 0;
}

.msg-assistant table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 13px;
}

.msg-assistant th, .msg-assistant td {
    border: 1px solid var(--gray-light);
    padding: 8px 10px;
    text-align: left;
}

.msg-assistant th {
    background: var(--blue-dark);
    color: var(--white);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.msg-assistant tr:nth-child(even) {
    background: rgba(0,0,0,0.02);
}

.msg-assistant tr:hover {
    background: rgba(16,91,171,0.05);
}

.msg-assistant code {
    background: rgba(0,0,0,0.06);
    padding: 2px 5px;
    border-radius: 4px;
    font-size: 0.9em;
    font-family: 'Consolas', 'Monaco', monospace;
}

.msg-assistant pre {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 14px 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 12px 0;
    font-size: 13px;
    line-height: 1.5;
}

.msg-assistant pre code {
    background: none;
    padding: 0;
    color: inherit;
    font-size: inherit;
}

.msg-assistant blockquote {
    border-left: 3px solid var(--blue-mid);
    margin: 12px 0;
    padding: 8px 14px;
    background: rgba(16,91,171,0.04);
    color: var(--text-mid);
}

.msg-assistant hr {
    border: none;
    border-top: 1px solid var(--gray-light);
    margin: 16px 0;
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    align-items: center;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--gray-mid);
    border-radius: 50%;
    animation: typing-bounce 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* Sources */
.sources-container {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.source-card {
    border: 1px solid var(--gray-light);
    border-left: 3px solid var(--blue-mid);
    border-radius: 8px;
    padding: 10px 12px;
    background: var(--white);
    font-size: 13px;
}

.source-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.source-name {
    font-weight: 600;
    color: var(--blue-dark);
    font-size: 12px;
}

.source-meta {
    font-size: 11px;
    color: var(--gray-mid);
}

.source-quote {
    font-size: 12px;
    color: var(--text-dark);
    background: var(--gray-bg);
    padding: 8px 10px;
    border-radius: 4px;
    margin-bottom: 8px;
    line-height: 1.6;
    transition: max-height 0.3s ease;
}

.source-quote.collapsed {
    max-height: 80px;
    overflow: hidden;
    position: relative;
}

.source-quote.collapsed::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 30px;
    background: linear-gradient(transparent, var(--gray-bg));
}

.source-quote mark {
    background: #fff3a8;
    color: var(--text-dark);
    padding: 1px 3px;
    border-radius: 2px;
}

.source-no-quote {
    font-size: 11px;
    color: var(--gray-mid);
    font-style: italic;
    margin-bottom: 4px;
}

.btn-expand {
    display: inline-block;
    padding: 4px 10px;
    background: transparent;
    color: var(--blue-mid);
    border: 1px solid var(--blue-mid);
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.btn-expand:hover {
    background: var(--blue-mid);
    color: var(--white);
}

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

.btn-download {
    display: inline-block;
    padding: 4px 10px;
    background: var(--blue-mid);
    color: var(--white);
    border: none;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s;
}

.btn-download:hover {
    background: var(--blue-dark);
}

/* -- Input Area ------------------------------------------------------------- */
.input-area {
    padding: 16px 24px 12px;
    border-top: 1px solid var(--gray-light);
    background: var(--white);
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 780px;
    margin: 0 auto;
    background: var(--gray-bg);
    border-radius: 16px;
    padding: 8px 12px;
    border: 1px solid var(--gray-light);
    transition: border-color 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--blue-mid);
}

#user-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 15px;
    line-height: 1.5;
    resize: none;
    outline: none;
    max-height: 120px;
    font-family: inherit;
    color: var(--text-dark);
}

.btn-send {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--blue-mid);
    color: var(--white);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, opacity 0.2s;
}

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

.btn-send:not(:disabled):hover {
    background: var(--blue-dark);
}

.disclaimer {
    text-align: center;
    font-size: 11px;
    color: var(--gray-mid);
    margin-top: 8px;
}

/* -- Responsive ------------------------------------------------------------- */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        z-index: 999;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .topbar {
        padding-left: 56px;
    }

    .messages {
        padding: 16px;
    }

    .msg-user {
        max-width: 90%;
    }

    .support-fab {
        top: 12px;
        bottom: auto;
        right: 12px;
        width: 44px;
        height: 44px;
    }
}

/* -- Support FAB + Modal ---------------------------------------------------- */
.support-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 900;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--white);
    border: 2px solid var(--blue-mid);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(0,0,0,0.18);
    transition: transform 0.2s, box-shadow 0.2s;
    overflow: hidden;
    padding: 0;
}

.support-fab svg {
    width: 56px;
    height: 56px;
}

.support-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0,0,0,0.28);
    border-color: var(--blue-dark);
}

.support-overlay {
    position: fixed;
    inset: 0;
    z-index: 1100;
    background: rgba(0,0,0,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
}

.support-modal {
    background: var(--white);
    border-radius: 14px;
    width: 420px;
    max-width: 92vw;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 12px 40px rgba(0,0,0,0.2);
}

.support-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 20px 0;
}

.support-modal-header h3 {
    font-size: 17px;
    color: var(--blue-dark);
}

.support-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--gray-mid);
    line-height: 1;
    padding: 0 4px;
}

.support-close:hover {
    color: var(--text-dark);
}

.support-form {
    padding: 16px 20px 20px;
}

.support-form label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-mid);
    margin: 12px 0 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.support-form label:first-child {
    margin-top: 0;
}

.support-form input,
.support-form select,
.support-form textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--gray-light);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    color: var(--text-dark);
    background: var(--white);
    transition: border-color 0.2s;
}

.support-form input:focus,
.support-form select:focus,
.support-form textarea:focus {
    outline: none;
    border-color: var(--blue-mid);
}

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

.support-submit {
    margin-top: 16px;
    width: 100%;
    padding: 11px;
    background: var(--blue-mid);
    color: var(--white);
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.support-submit:hover {
    background: var(--blue-dark);
}

.support-submit:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.support-feedback {
    margin-top: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 13px;
    text-align: center;
}

.support-feedback.success {
    background: #e8f5e9;
    color: #2e7d32;
}

.support-feedback.error {
    background: #fce4ec;
    color: #c62828;
}

/* -- Scrollbar -------------------------------------------------------------- */
.messages::-webkit-scrollbar,
.conversations-list::-webkit-scrollbar {
    width: 6px;
}

.messages::-webkit-scrollbar-track,
.conversations-list::-webkit-scrollbar-track {
    background: transparent;
}

.messages::-webkit-scrollbar-thumb {
    background: var(--gray-light);
    border-radius: 3px;
}

.conversations-list::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 3px;
}
