/* =====================================================================
   Estilos — Agente de Decisões Estratégicas no Varejo
   ===================================================================== */

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f5;
    --bg-tertiary: #e8e8e8;
    --bg-input: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #555555;
    --text-muted: #999999;
    --accent: #1a1a1a;
    --accent-hover: #333333;
    --user-bubble: #1a1a1a;
    --assistant-bubble: transparent;
    --tool-bg: #f5f5f5;
    --border: #e0e0e0;
    --success: #4caf50;
    --warning: #ff9800;
    --danger: #f44336;
    --radius: 12px;
    --transition: 0.2s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

/* Layout principal */
.app {
    display: flex;
    height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
    width: 280px;
    min-width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform var(--transition);
}

.sidebar.hidden {
    transform: translateX(-100%);
    position: absolute;
    z-index: 10;
    height: 100%;
}

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

.sidebar-header h2 {
    font-size: 16px;
    font-weight: 600;
}

.btn-new {
    background: var(--accent);
    color: white;
    border: none;
    padding: 6px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: background var(--transition);
}

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

.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.conversation-item {
    padding: 10px 14px;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 4px;
    font-size: 14px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background var(--transition);
}

.conversation-item:hover {
    background: var(--bg-tertiary);
}

.conversation-item.active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-weight: 500;
}

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-label {
    font-size: 12px;
    color: var(--text-muted);
}

.user-name {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-logout {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 10px;
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: background var(--transition);
}

.btn-logout:hover {
    background: var(--bg-tertiary);
}

/* ---- Tela de login (SCRUM-44) ---- */
.login-screen {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
}

.login-screen[hidden] {
    display: none;
}

.login-card {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 320px;
    padding: 32px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.login-card h2 {
    font-size: 20px;
    text-align: center;
}

.login-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
    margin-bottom: 8px;
}

.login-card input {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 14px;
    color: var(--text-primary);
}

.login-error {
    font-size: 13px;
    color: var(--danger);
    text-align: center;
}

.btn-login {
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 10px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition);
}

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

.btn-login:disabled {
    opacity: 0.6;
    cursor: default;
}

.login-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    text-decoration: underline;
}

/* ---- Gestão de usuários (SCRUM-45) ---- */
.users-card {
    width: 620px;
    max-width: 95vw;
    max-height: 85vh;
    overflow-y: auto;
}

.users-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.users-table th, .users-table td {
    border-bottom: 1px solid var(--border);
    padding: 6px 8px;
    text-align: left;
}

.users-table tr.inactive td {
    color: var(--text-muted);
}

.users-table select {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 2px 6px;
    font-size: 12px;
}

.users-form {
    display: flex;
    gap: 8px;
}

.users-form input, .users-form select {
    flex: 1;
    min-width: 0;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 13px;
}

.users-form .btn-login {
    flex: 0 0 auto;
    padding: 8px 14px;
}

/* ---- Área principal ---- */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.main-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}

.btn-toggle-sidebar {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    display: none;
}

.main-header h1 {
    font-size: 16px;
    font-weight: 600;
    flex: 1;
}

.header-badge {
    background: var(--accent);
    color: white;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

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

/* Tela de boas-vindas */
.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    text-align: center;
    gap: 12px;
}

.welcome-icon {
    font-size: 48px;
}

.welcome h2 {
    font-size: 22px;
    font-weight: 600;
}

.welcome p {
    color: var(--text-secondary);
    max-width: 500px;
}

.welcome-examples {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 16px;
    max-width: 600px;
}

.example-btn {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 10px 16px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 13px;
    transition: all var(--transition);
    text-align: left;
}

.example-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--accent);
}

/* Bolhas de mensagem */
.message {
    display: flex;
    gap: 12px;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
}

.message-avatar {
    display: none;
}

.message-body {
    flex: 1;
    min-width: 0;
}

.message-content {
    padding: 12px 16px;
    border-radius: var(--radius);
    line-height: 1.6;
    font-size: 14px;
}

.message.user .message-content {
    background: var(--user-bubble);
    color: white;
}

.message.assistant .message-content {
    background: transparent;
    border: none;
}

/* Markdown dentro das mensagens */
.message-content p { margin-bottom: 8px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content ul, .message-content ol { padding-left: 20px; margin-bottom: 8px; }
.message-content code {
    background: rgba(0,0,0,0.06);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}
.message-content pre {
    background: rgba(0,0,0,0.06);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}
.message-content pre code {
    background: none;
    padding: 0;
}
.message-content table {
    border-collapse: collapse;
    margin: 8px 0;
    width: 100%;
}
.message-content th, .message-content td {
    border: 1px solid var(--border);
    padding: 6px 10px;
    text-align: left;
    font-size: 13px;
}
.message-content th {
    background: rgba(0,0,0,0.06);
}
.message-content strong { font-weight: 600; }
.message-content h1, .message-content h2, .message-content h3 {
    margin: 12px 0 6px;
}

/* Indicador de tool call */
.tool-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--tool-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.tool-indicator .tool-icon {
    font-size: 14px;
}

.tool-indicator .tool-name {
    color: var(--accent);
    font-weight: 500;
}

/* Informações de debug */
.debug-info {
    margin-bottom: 8px;
}

.debug-info details {
    background: #f9f9f9;
    border: 1px solid #e94560;
    border-radius: 8px;
    font-size: 12px;
    overflow: hidden;
}

.debug-info summary {
    padding: 8px 12px;
    cursor: pointer;
    color: #e94560;
    font-weight: 500;
    user-select: none;
}

.debug-info pre {
    margin: 0;
    padding: 8px 12px 12px;
    background: #f0f0f0;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

.debug-info code {
    color: #2e7d32;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 12px;
}

/* Indicador de digitação */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 12px 16px;
}

.typing-dot {
    width: 10px;
    height: 10px;
    background: var(--accent);
    border-radius: 50%;
    animation: typing 1.4s ease-in-out infinite;
}

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

@keyframes typing {
    0%, 60%, 100% { opacity: 0.2; transform: scale(0.7); }
    30% { opacity: 1; transform: scale(1.1); }
}

/* ---- Input ---- */
.input-container {
    padding: 12px 20px 16px;
    background: var(--bg-primary);
}

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

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

#message-input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    max-height: 150px;
    outline: none;
    font-family: inherit;
}

#message-input::placeholder {
    color: var(--text-muted);
}

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

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

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

.input-footer {
    text-align: center;
    margin-top: 6px;
}

.input-hint {
    font-size: 11px;
    color: var(--text-muted);
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar {
    width: 6px;
}

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

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

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ---- Responsivo ---- */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        z-index: 10;
        height: 100%;
        transform: translateX(-100%);
    }

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

    .btn-toggle-sidebar {
        display: block;
    }
}
