:root {
    --brand: #1d9bf0;
    --brand-dark: #0b7fcc;
    --brand-grad: linear-gradient(135deg, #1d9bf0 0%, #6c63ff 100%);
    --sidebar-bg: #ffffff;
    --sidebar-bg2: #fafbfd;
    --sidebar-text: #475569;
    --sidebar-active: #1d9bf0;
    --content-bg: #f7f8fa;
    --card-shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.06);
    --radius: 12px;
}

html, body {
    font-family: 'Inter', 'Segoe UI', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    background: var(--content-bg);
    color: #1f2937;
}

a, .btn-link { color: var(--brand-dark); text-decoration: none; }
a:hover { color: var(--brand); }

h1:focus { outline: none; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.app-sidebar {
    width: 248px;
    background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg2) 100%);
    color: var(--sidebar-text);
    border-right: 1px solid #e6e9f0;
    display: flex; flex-direction: column;
    position: fixed; top: 0; bottom: 0; left: 0;
    overflow-y: auto;
    transition: transform .2s ease;
    z-index: 100;
}
body.sidebar-collapsed .app-sidebar { transform: translateX(-248px); }
body.sidebar-collapsed .app-main { margin-left: 0; }

.app-main { flex: 1; margin-left: 248px; display: flex; flex-direction: column; transition: margin .2s ease; }

.app-topbar {
    height: 60px; background: #fff; border-bottom: 1px solid #e6e9f0;
    display: flex; align-items: center; gap: 16px; padding: 0 24px;
    position: sticky; top: 0; z-index: 50;
}
.sidebar-toggle { background: none; border: none; font-size: 1.3rem; cursor: pointer; color: #6b7280; }
.topbar-title { font-weight: 600; font-size: 1.1rem; flex: 1; }
.topbar-user { display: flex; align-items: center; gap: 10px; }
.user-avatar {
    width: 38px; height: 38px; border-radius: 50%; background: var(--brand-grad);
    color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600;
}
.user-info { line-height: 1.15; }
.user-name { font-weight: 600; font-size: .9rem; }
.user-role { font-size: .72rem; color: #9ca3af; }
.btn-logout { background: none; border: 1px solid #e6e9f0; border-radius: 6px; font-size: .85rem; padding: 4px 10px; color: #9ca3af; cursor: pointer; margin-left: 12px; white-space: nowrap; }
.btn-logout:hover { color: #ef4444; border-color: #ef4444; }

.app-content { padding: 24px; flex: 1; }

.impersonation-bar {
    background: #b45309; color: #fff; padding: 8px 16px; font-size: .9rem;
    display: flex; align-items: center; gap: 6px;
}

.app-loading { display: flex; align-items: center; justify-content: center; height: 100vh; }
.spinner {
    width: 42px; height: 42px; border: 4px solid #e6e9f0; border-top-color: var(--brand);
    border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Sidebar nav ---------- */
.nav-brand {
    display: flex; align-items: center; gap: 10px; padding: 20px 22px; color: #0f172a;
    font-size: 1.25rem; font-weight: 700; border-bottom: 1px solid #eef1f6;
}
.brand-logo { font-size: 1.5rem; }
.nav-sections { padding: 14px 12px; }
.nav-group { margin-bottom: 18px; }
.nav-group-title {
    font-size: .68rem; text-transform: uppercase; letter-spacing: .08em;
    color: #94a3b8; padding: 4px 12px 8px; font-weight: 600;
    display: flex; align-items: center; justify-content: space-between; width: 100%;
    background: none; border: 0; cursor: pointer; text-align: left;
}
.nav-group-title:hover { color: #475569; }
.nav-group-title { list-style: none; user-select: none; }
.nav-group-title::-webkit-details-marker { display: none; }
.nav-group-chevron { font-size: .7rem; transition: transform .15s; }
details.nav-group:not([open]) .nav-group-chevron { transform: rotate(-90deg); }
.nav-item {
    display: flex; align-items: center; gap: 12px; padding: 7px 10px; margin: 2px 0;
    border-radius: 10px; color: var(--sidebar-text); font-size: .9rem; font-weight: 500;
    cursor: pointer; transition: background .15s, color .15s;
}
.nav-item:hover { background: #f1f5f9; color: #0f172a; }
.nav-item.active { background: rgba(29,155,240,.12); color: var(--brand-dark); font-weight: 600; }
.nav-icon {
    width: 20px; flex: 0 0 20px; text-align: center; font-size: 1rem;
}

/* ---------- Buttons ---------- */
.btn-primary { background: var(--brand); border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn { border-radius: 8px; }
.btn:focus, .form-control:focus, .form-select:focus, .form-check-input:focus {
    box-shadow: 0 0 0 .2rem rgba(29,155,240,.2);
    border-color: var(--brand);
}

/* ---------- Cards / tables ---------- */
.card { border: 1px solid #e9edf5; border-radius: var(--radius); box-shadow: var(--card-shadow); }
.table { --bs-table-hover-bg: #f0f6ff; }
.table > thead th { font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: #6b7280; border-bottom: 2px solid #eef1f6; }
.modal-content { border: none; border-radius: 14px; box-shadow: 0 20px 50px rgba(16,24,40,.2); }
.form-control, .form-select { border-radius: 8px; border-color: #d8dee9; }
.badge { font-weight: 600; }

h4 { font-weight: 700; }

/* ---------- Login ---------- */
.login-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: var(--brand-grad); padding: 20px;
}
.login-card {
    background: #fff; border-radius: 18px; box-shadow: 0 24px 60px rgba(0,0,0,.25);
    width: 100%; max-width: 400px; padding: 40px 36px;
}
.login-logo { text-align: center; font-size: 2.6rem; margin-bottom: 6px; }
.login-title { text-align: center; font-weight: 700; font-size: 1.5rem; margin-bottom: 2px; }
.login-sub { text-align: center; color: #9ca3af; font-size: .9rem; margin-bottom: 26px; }

/* ---------- Misc ---------- */
.conv-item:hover { background: #f6f8fc; }
.quick-item:hover { background: #f0f6ff; }
.chat-scroll { background: #f7f7f7; }

/* ---------- Botão de tema (topbar) ---------- */
.btn-theme {
    background: none; border: 1px solid #e6e9f0; border-radius: 8px;
    font-size: 1rem; padding: 4px 10px; cursor: pointer; line-height: 1.4;
}
.btn-theme:hover { border-color: var(--brand); }

/* ---------- DARK MODE ----------
   Ativado por body.dark (superfícies próprias) + data-bs-theme="dark" no <html>
   (componentes Bootstrap: cards, tabelas, forms, modais). */
body.dark {
    --content-bg: #0f1522;
    --sidebar-bg: #131a2a;
    --sidebar-bg2: #0e1422;
    --sidebar-text: #aab4c8;
    color: #e5e7eb;
}
body.dark .app-sidebar { border-right-color: #1f2937; }
body.dark .nav-brand { color: #fff; border-bottom-color: rgba(255,255,255,.08); }
body.dark .nav-group-title { color: #64748b; }
body.dark .nav-group-title:hover { color: #94a3b8; }
body.dark .nav-item { color: var(--sidebar-text); }
body.dark .nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
body.dark .nav-item.active { background: rgba(29,155,240,.22); color: #7cc7f8; }
body.dark .app-topbar { background: #131a2a; border-bottom-color: #1f2937; }
body.dark .topbar-title, body.dark .user-name { color: #e5e7eb; }
body.dark .sidebar-toggle { color: #9ca3af; }
body.dark .btn-logout, body.dark .btn-theme { border-color: #374151; color: #9ca3af; }
body.dark .conv-item:hover { background: #1a2333; }
body.dark .quick-item:hover { background: #1a2333; }
body.dark .chat-scroll { background: #0b101b; }
body.dark .bg-white { background-color: #1e293b !important; color: #e5e7eb; }
body.dark .bg-light { background-color: #111827 !important; color: #cbd5e1; }
body.dark .text-muted { color: #94a3b8 !important; }
body.dark .border, body.dark .border-bottom, body.dark .border-end, body.dark .border-top { border-color: #1f2937 !important; }
body.dark .table { --bs-table-hover-bg: #1a2333; }
body.dark .mg-card, body.dark .co-card { background: #131a2a; border-color: #1f2937; }
body.dark .mg-chip { background: #1e293b; border-color: #334155; color: #cbd5e1; }
body.dark .mg-tenant-list { border-color: #334155; }
body.dark .mg-tenant-row { border-bottom-color: #1f2937; }
body.dark .mg-tenant-row:hover { background: #1a2333; }
body.dark .mg-tenant-row.sel { background: #0d2a1e; }
body.dark .co-empty, body.dark .mg-empty { background: #131a2a; border-color: #334155; }

#blazor-error-ui {
    background: #fff3cd; bottom: 0; box-shadow: 0 -1px 2px rgba(0,0,0,.2);
    display: none; left: 0; padding: .6rem 1.25rem; position: fixed; width: 100%; z-index: 1000;
}
.blazor-error-boundary { background: #b32121; padding: 1rem; color: white; }
.validation-message { color: #e50000; }

@media (max-width: 768px) {
    .app-sidebar { transform: translateX(-248px); }
    .app-main { margin-left: 0; }
    body:not(.sidebar-collapsed) .app-sidebar { transform: translateX(0); }
}
