/* FlavIA - Dark Mode SaaS Premium */

:root {
    --bg-primary: #0f1419;
    --bg-secondary: #1a2332;
    --bg-tertiary: #243044;
    --bg-card: #1e2a3a;
    --text-primary: #f0f4f8;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #22d3ee;
    --accent-hover: #06b6d4;
    --accent-muted: rgba(34, 211, 238, 0.15);
    --border: #334155;
    --danger: #f87171;
    --danger-hover: #ef4444;
    --sidebar-width: 260px;
    --sidebar-collapsed: 72px;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
    --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    font-family: var(--font);
    font-size: 16px;
    color: var(--text-primary);
    background: var(--bg-primary);
    line-height: 1.5;
}

.app {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: width 0.2s ease, min-width 0.2s ease;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed);
    min-width: var(--sidebar-collapsed);
}

.sidebar.collapsed .logo-text,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .nav-item span {
    opacity: 0;
    overflow: hidden;
    width: 0;
    padding: 0;
    margin: 0;
}

.sidebar-header {
    padding: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--accent), #0e7490);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.logo-text {
    font-weight: 600;
    font-size: 1.25rem;
    color: var(--text-primary);
    white-space: nowrap;
    transition: opacity 0.2s;
}

.sidebar-toggle {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background 0.2s;
}

.sidebar-toggle:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0.75rem;
    overflow-y: auto;
}

.nav-label {
    display: block;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    padding: 0 0.75rem 0.5rem;
    margin-bottom: 0.25rem;
    transition: opacity 0.2s;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.75rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-sm);
    margin-bottom: 2px;
    transition: background 0.2s, color 0.2s;
}

.nav-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--accent-muted);
    color: var(--accent);
}

.nav-icon {
    flex-shrink: 0;
    opacity: 0.9;
}

.nav-item--logout {
    color: var(--danger);
}

.nav-item--logout:hover {
    background: rgba(248, 113, 113, 0.1);
    color: var(--danger-hover);
}

.sidebar-footer {
    padding: 0.75rem;
    border-top: 1px solid var(--border);
}

.sidebar-footer .nav-item {
    margin-bottom: 0;
}

/* Main content */
.content {
    flex: 1;
    min-width: 0;
    padding: 2rem;
    overflow-y: auto;
}

/* Dashboard */
.page-dashboard .page-header {
    margin-bottom: 2rem;
}

.page-title {
    font-size: 1.75rem;
    font-weight: 600;
    margin: 0 0 0.5rem;
    color: var(--text-primary);
}

.page-title strong {
    color: var(--accent);
}

.page-subtitle {
    color: var(--text-secondary);
    margin: 0;
    font-size: 1rem;
}

.section-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0 0 1.25rem;
    color: var(--text-primary);
}

/* Configurações */
.page-settings .page-header {
    margin-bottom: 1.5rem;
}

.settings-alert {
    padding: 1rem 1.25rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
}

.settings-alert--success {
    background: rgba(34, 197, 94, 0.15);
    color: #4ade80;
    border: 1px solid rgba(34, 197, 94, 0.3);
}

.settings-alert--error {
    background: rgba(248, 113, 113, 0.15);
    color: var(--danger);
    border: 1px solid rgba(248, 113, 113, 0.3);
}

.settings-sections {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.settings-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
}

.settings-section-title {
    font-size: 1.15rem;
    font-weight: 600;
    margin: 0 0 1rem;
    color: var(--text-primary);
}

.settings-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-width: 400px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.form-label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-input {
    padding: 0.7rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: var(--accent);
}

.form-select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.25rem;
}

.form-group--checkbox {
    gap: 0.25rem;
}

.form-checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.form-checkbox {
    width: 1.15rem;
    height: 1.15rem;
    accent-color: var(--accent);
    cursor: pointer;
}

.form-group .form-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 0;
}

.settings-desc {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin: 0 0 1rem;
}

.settings-dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.5rem 1.5rem;
    margin: 0 0 1rem;
    font-size: 0.95rem;
}

.settings-dl dt {
    color: var(--text-muted);
    font-weight: 500;
}

.settings-dl dd {
    margin: 0;
    color: var(--text-primary);
}

.settings-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 0;
    line-height: 1.5;
}

.settings-hint code {
    background: var(--bg-tertiary);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.8em;
}

.agents-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.5rem;
}

.agent-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    position: relative;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.agent-card:hover:not(.agent-card--disabled) {
    border-color: var(--accent);
    box-shadow: var(--shadow);
}

.agent-card--disabled {
    opacity: 0.85;
    cursor: not-allowed;
}

.agent-card--disabled .agent-card-cta {
    display: none;
}

.agent-card-badge {
    position: absolute;
    top: 1rem;
    right: 1rem;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
}

.agent-card-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    background: var(--accent-muted);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
}

.agent-card-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0 0 0.5rem;
    color: var(--text-primary);
}

.agent-card-desc {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin: 0 0 1rem;
    line-height: 1.5;
}

.agent-card-cta {
    display: inline-block;
    color: var(--accent);
    font-weight: 500;
    text-decoration: none;
    font-size: 0.95rem;
    transition: color 0.2s;
}

.agent-card-cta:hover {
    color: var(--accent-hover);
}

/* Agent page (chat) */
.page-agent {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 4rem);
    max-height: calc(100vh - 4rem);
    padding: 0;
}

.page-agent .agent-header {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 1rem 0;
    margin-bottom: 1rem;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border);
}

.btn-back {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.95rem;
    padding: 0.5rem 0;
    transition: color 0.2s;
}

.btn-back:hover {
    color: var(--accent);
}

.agent-header-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1;
}

.agent-header-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    background: var(--accent-muted);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.agent-header-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0 0 0.15rem;
    color: var(--text-primary);
}

.agent-header-desc {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin: 0;
}

.btn-new-chat {
    padding: 0.6rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    background: var(--accent);
    color: #0f1419;
    white-space: nowrap;
    transition: background 0.2s;
}

.btn-new-chat:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn-new-chat:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.badge-coming-soon {
    font-size: 0.8rem;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
}

/* Chat layout: histórico + área do chat */
.chat-layout {
    display: flex;
    gap: 1rem;
    flex: 1;
    min-height: 0;
}

.chat-history-panel {
    width: 220px;
    min-width: 220px;
    flex-shrink: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
}

.chat-history-title {
    margin: 0 0 0.75rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.chat-history-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.chat-history-item-wrap {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-bottom: 0.25rem;
}

.chat-history-item-wrap .chat-history-item {
    flex: 1;
    min-width: 0;
}

.chat-history-delete {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}

.chat-history-delete:hover:not(:disabled) {
    background: rgba(248, 113, 113, 0.2);
    color: var(--danger);
}

.chat-history-delete:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-history-item {
    display: block;
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    transition: background 0.2s, color 0.2s;
}

.chat-history-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.chat-history-item--active {
    background: var(--accent-muted);
    color: var(--accent);
}

.chat-history-empty {
    padding: 0.75rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* Chat container */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.chat-message {
    max-width: 85%;
    padding: 0.9rem 1.1rem;
    border-radius: 16px;
    font-size: 0.95rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

.chat-message--agent {
    align-self: flex-start;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.chat-message--user {
    align-self: flex-end;
    background: var(--accent-muted);
    color: var(--accent);
    border-bottom-right-radius: 4px;
}

.chat-message__content {
    margin: 0;
}

.chat-message__content p {
    margin: 0 0 0.5em;
}

.chat-message__content p:last-child {
    margin-bottom: 0;
}

/* Markdown-like: negrito */
.chat-message__content strong {
    font-weight: 600;
}

.chat-message__content a {
    color: var(--accent);
    text-decoration: none;
}

.chat-message__content a:hover {
    text-decoration: underline;
}

.chat-form {
    display: flex;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    padding: 0.85rem 1.1rem;
    border-radius: 24px;
    border: 1px solid var(--border);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}

.chat-input::placeholder {
    color: var(--text-muted);
}

.chat-input:focus {
    border-color: var(--accent);
}

.chat-send {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: #0f1419;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}

.chat-send:hover:not(:disabled) {
    background: var(--accent-hover);
}

.chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-placeholder .chat-messages {
    justify-content: center;
    align-items: center;
}

.placeholder-message {
    color: var(--text-secondary);
    margin: 0;
}

.placeholder-message a {
    color: var(--accent);
    text-decoration: none;
}

.placeholder-message a:hover {
    text-decoration: underline;
}

/* Auth */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
}

.auth-box {
    width: 100%;
    max-width: 400px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
}

.auth-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.auth-logo .logo-icon {
    width: 40px;
    height: 40px;
    font-size: 1.25rem;
}

.auth-logo .logo-text {
    font-size: 1.5rem;
}

.auth-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0 0 1.5rem;
    text-align: center;
    color: var(--text-primary);
}

.auth-error {
    background: rgba(248, 113, 113, 0.15);
    color: var(--danger);
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.auth-success {
    background: rgba(34, 211, 238, 0.15);
    color: var(--accent);
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.auth-link {
    color: var(--accent);
    text-decoration: none;
}

.auth-link:hover {
    text-decoration: underline;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.auth-label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.auth-input {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
}

.auth-input::placeholder {
    color: var(--text-muted);
}

.auth-input:focus {
    outline: none;
    border-color: var(--accent);
}

.btn-primary {
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-sm);
    border: none;
    background: var(--accent);
    color: #0f1419;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn-block {
    width: 100%;
    margin-top: 0.5rem;
}

.auth-hint {
    margin: 1.25rem 0 0;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
}

/* Loading / typing indicator */
.chat-typing {
    align-self: flex-start;
    padding: 0.9rem 1.1rem;
    background: var(--bg-tertiary);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
}

.chat-typing span {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    margin: 0 2px;
    animation: typing 1.4s infinite ease-in-out;
}

.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* Scroll automático */
.chat-messages {
    scroll-behavior: smooth;
}
