/* ═══════════════════════════════════════════════════════
   JURIS AI — Design System v2.0
   Inspirado em: IBM Carbon + Apple HIG + Disney Magic
   ═══════════════════════════════════════════════════════ */

/* ── CSS Variables (Design Tokens) ── */
:root {
    /* Cores Base (Dark Mode Premium) */
    --bg-base: #0a0d14;
    --bg-elevated: #111827;
    --bg-surface: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    /* Accent (White-Label Ready — substituídas via JS) */
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --accent-glow: rgba(99, 102, 241, 0.35);
    --secondary: #ec4899;
    --secondary-glow: rgba(236, 72, 153, 0.2);

    /* Status */
    --success: #22c55e;
    --warning: #f59e0b;
    --error: #ef4444;

    /* Glass */
    --glass-bg: rgba(17, 24, 39, 0.65);
    --glass-border: rgba(255, 255, 255, 0.06);
    --glass-hover: rgba(255, 255, 255, 0.04);

    /* Chat */
    --ai-bubble: rgba(30, 41, 59, 0.75);
    --user-bubble: rgba(99, 102, 241, 0.6);

    /* Radii (IBM 8px grid) */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    /* Sidebar */
    --sidebar-width: 260px;
    --sidebar-collapsed: 68px;

    /* Transitions (Disney smooth) */
    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --duration-fast: 0.2s;
    --duration-normal: 0.35s;
    --duration-slow: 0.5s;
}

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

html { font-size: 16px; }

body {
    background: var(--bg-base);
    color: var(--text-primary);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    min-height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ── Animated Background Glows (Disney Magic) ── */
.glow-bg {
    position: fixed;
    border-radius: 50%;
    filter: blur(140px);
    z-index: 0;
    pointer-events: none;
    animation: drift 20s ease-in-out infinite alternate;
}
.glow-1 {
    width: 500px; height: 500px;
    background: var(--accent-glow);
    top: -150px; left: -100px;
}
.glow-2 {
    width: 400px; height: 400px;
    background: var(--secondary-glow);
    bottom: -100px; right: -100px;
    animation-delay: -7s;
}
.glow-3 {
    width: 350px; height: 350px;
    background: var(--accent-glow);
    top: 50%; right: -150px;
    animation-delay: -3s;
}

@keyframes drift {
    0%   { transform: translate(0, 0) scale(1); }
    100% { transform: translate(60px, 40px) scale(1.1); }
}

/* ── Glass Panel (Apple HIG) ── */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
}

/* ── View System (SPA Router) ── */
.view {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1;
}
.active-view { display: flex; }

/* ═══════════════════════════════════════════════════════
   LOGIN PAGE
   ═══════════════════════════════════════════════════════ */
.login-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 24px;
    gap: 16px;
    z-index: 1;
}

.login-card {
    width: 100%;
    max-width: 400px;
    padding: 40px 32px;
    animation: slideUp 0.6s var(--ease-out) forwards;
    opacity: 0;
    transform: translateY(20px);
}

@keyframes slideUp {
    to { opacity: 1; transform: translateY(0); }
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo {
    width: 64px; height: 64px;
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--accent), var(--secondary));
    border-radius: var(--radius-lg);
    color: #fff;
    box-shadow: 0 8px 24px var(--accent-glow);
    animation: breathe 3s ease-in-out infinite;
}
.login-logo i { width: 32px; height: 32px; }

@keyframes breathe {
    0%, 100% { box-shadow: 0 8px 24px var(--accent-glow); }
    50%      { box-shadow: 0 12px 40px var(--accent-glow), 0 0 60px var(--secondary-glow); }
}

.login-title {
    font-family: 'Outfit', sans-serif;
    font-size: 1.8rem;
    font-weight: 700;
    background: linear-gradient(135deg, #fff 30%, var(--text-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.login-subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 4px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.input-group {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 0 16px;
    transition: border-color var(--duration-fast) ease;
}
.input-group:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}
.input-group i { color: var(--text-muted); width: 18px; height: 18px; flex-shrink: 0; }
.input-group input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: inherit;
    padding: 14px 0;
    outline: none;
}
.input-group input::placeholder { color: var(--text-muted); }

.login-error {
    color: var(--error);
    font-size: 0.85rem;
    min-height: 20px;
    text-align: center;
}

/* Buttons */
.btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    padding: 14px 24px;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
    box-shadow: 0 4px 12px var(--accent-glow);
}
.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px var(--accent-glow);
}
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}
.btn-full { width: 100%; }
.btn-primary i { width: 18px; height: 18px; }

.login-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 24px;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.backend-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    animation: slideUp 0.6s var(--ease-out) 0.2s forwards;
    opacity: 0;
}

.status-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--warning);
    animation: pulse 2s infinite;
}
.status-dot.online { background: var(--success); }
.status-dot.offline { background: var(--error); animation: none; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.4; }
}

/* ═══════════════════════════════════════════════════════
   APP SHELL (Sidebar + Main)
   ═══════════════════════════════════════════════════════ */
.app-shell {
    display: flex;
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 16px;
    gap: 8px;
    border-radius: 0;
    border-right: 1px solid var(--glass-border);
    border-top: none;
    border-bottom: none;
    border-left: none;
    transition: width var(--duration-normal) var(--ease-out);
    flex-shrink: 0;
    overflow: hidden;
    z-index: 10;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed);
}
.sidebar.collapsed .sidebar-title,
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .user-details,
.sidebar.collapsed .logout-btn span {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px;
    margin-bottom: 8px;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--accent);
    overflow: hidden;
}
.sidebar-brand i { width: 24px; height: 24px; flex-shrink: 0; }
.sidebar-title {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 1.15rem;
    white-space: nowrap;
    transition: opacity var(--duration-fast) ease;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: color var(--duration-fast) ease;
}
.sidebar-toggle:hover { color: var(--text-primary); }
.sidebar-toggle i { width: 20px; height: 20px; }

.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--duration-fast) var(--ease-out);
}
.nav-item i { width: 20px; height: 20px; flex-shrink: 0; }
.nav-item span { transition: opacity var(--duration-fast) ease; }
.nav-item:hover {
    background: var(--glass-hover);
    color: var(--text-primary);
}
.nav-item.active {
    background: rgba(99, 102, 241, 0.12);
    color: var(--accent);
    font-weight: 500;
}

.nav-separator {
    height: 1px;
    background: var(--glass-border);
    margin: 8px 0;
}

.nav-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    padding: 4px 12px;
    white-space: nowrap;
    transition: opacity var(--duration-fast) ease;
}

.sidebar-footer {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-top: 12px;
    border-top: 1px solid var(--glass-border);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    overflow: hidden;
}
.user-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 600;
    font-size: 0.9rem;
    flex-shrink: 0;
}
.user-details {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity var(--duration-fast) ease;
}
.user-name {
    font-weight: 500;
    font-size: 0.88rem;
    color: var(--text-primary);
    white-space: nowrap;
}
.user-role {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: capitalize;
}

.logout-btn { color: var(--error) !important; }

/* ── Main Content Area ── */
.main-content {
    flex: 1;
    height: 100vh;
    overflow: hidden;
    position: relative;
}

.page {
    display: none;
    height: 100%;
    overflow-y: auto;
    animation: fadeIn 0.3s ease;
}
.active-page { display: flex; flex-direction: column; }

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

/* Page Header */
.page-header {
    padding: 32px 32px 16px;
}
.page-header h2 {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: 'Outfit', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
}
.page-header h2 i { width: 24px; height: 24px; color: var(--accent); }
.page-header p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 4px;
}

/* ═══════════════════════════════════════════════════════
   CHAT PAGE
   ═══════════════════════════════════════════════════════ */
.chat-layout {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    border-radius: 0;
    border-bottom: 1px solid var(--glass-border);
    border-top: none;
    border-left: none;
    border-right: none;
    flex-shrink: 0;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}
.header-icon { color: var(--accent); width: 24px; height: 24px; }
.chat-header-left h2 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.1rem;
    font-weight: 600;
}
.header-meta {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
}
.mobile-menu-btn i { width: 22px; height: 22px; }

.settings-group {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(0, 0, 0, 0.25);
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid var(--glass-border);
}
.settings-group i { width: 14px; height: 14px; color: var(--text-muted); }

select {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
    outline: none;
}
select option { background: var(--bg-elevated); }

/* Chat Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scrollbar-width: thin;
    scrollbar-color: var(--accent) transparent;
}
.chat-messages::-webkit-scrollbar { width: 5px; }
.chat-messages::-webkit-scrollbar-thumb {
    background: var(--accent);
    border-radius: 10px;
}

.message-wrapper {
    display: flex;
    gap: 12px;
    max-width: 80%;
    animation: msgIn 0.4s var(--ease-out) forwards;
    opacity: 0;
}
@keyframes msgIn {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

.user-wrapper { align-self: flex-end; flex-direction: row-reverse; }
.ai-wrapper   { align-self: flex-start; }

.avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: 1px solid var(--glass-border);
}
.avatar i { width: 18px; height: 18px; }
.ai-avatar  { color: var(--secondary); background: rgba(236, 72, 153, 0.1); }
.user-avatar-chat { color: #fff; background: var(--accent); }

.chat-bubble {
    padding: 14px 18px;
    border-radius: var(--radius-md);
    line-height: 1.6;
    font-size: 0.93rem;
}
.ai-bubble {
    background: var(--ai-bubble);
    border: 1px solid var(--glass-border);
    border-top-left-radius: 4px;
}
.user-bubble {
    background: var(--user-bubble);
    border-top-right-radius: 4px;
    color: #fff;
}

/* AI Bubble Markdown */
.ai-bubble p { margin-bottom: 0.7em; }
.ai-bubble p:last-child { margin-bottom: 0; }
.ai-bubble code {
    background: rgba(0, 0, 0, 0.35);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.88em;
}
.ai-bubble strong { color: #fff; }
.ai-bubble ul, .ai-bubble ol { padding-left: 20px; margin: 8px 0; }
.ai-bubble li { margin-bottom: 4px; }

/* Document Badge */
.doc-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}
.doc-badge i { width: 12px; height: 12px; }

/* Loading Dots */
.loading-indicator {
    display: flex;
    gap: 5px;
    align-items: center;
    height: 22px;
}
.loading-indicator span {
    width: 7px; height: 7px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}
.loading-indicator span:nth-child(1) { animation-delay: -0.32s; }
.loading-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); opacity: 0.4; }
    40%           { transform: scale(1); opacity: 1; }
}

/* Chat Input */
.chat-input-area {
    padding: 16px 24px;
    border-radius: 0;
    border-top: 1px solid var(--glass-border);
    border-bottom: none;
    border-left: none;
    border-right: none;
    flex-shrink: 0;
}
.input-wrapper {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 6px 8px 6px 18px;
    transition: border-color var(--duration-fast) ease;
}
.input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.08);
}

#user-input {
    flex: 1;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 0.95rem;
    font-family: inherit;
    resize: none;
    outline: none;
    padding: 10px 0;
    max-height: 140px;
    line-height: 1.5;
}
#user-input::placeholder { color: var(--text-muted); }

#send-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    width: 40px; height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
    flex-shrink: 0;
}
#send-btn i { width: 18px; height: 18px; }
#send-btn:hover { background: var(--accent-hover); transform: scale(1.05); }
#send-btn:disabled {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-muted);
    cursor: not-allowed;
    transform: none;
}

/* ═══════════════════════════════════════════════════════
   HEALTH PAGE
   ═══════════════════════════════════════════════════════ */
.health-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    padding: 0 32px 32px;
}

.health-card {
    padding: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    text-align: center;
    transition: transform var(--duration-fast) var(--ease-out);
}
.health-card:hover { transform: translateY(-2px); }

.health-icon {
    width: 48px; height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.health-icon i { width: 22px; height: 22px; }
.health-icon.cpu       { background: rgba(99, 102, 241, 0.15); color: var(--accent); }
.health-icon.ram       { background: rgba(236, 72, 153, 0.15); color: var(--secondary); }
.health-icon.disk      { background: rgba(34, 197, 94, 0.15);  color: var(--success); }
.health-icon.status    { background: rgba(99, 102, 241, 0.15); color: var(--accent); }
.health-icon.db        { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.health-icon.pinecone  { background: rgba(34, 197, 94, 0.15);  color: var(--success); }

.health-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.health-value {
    font-family: 'Outfit', sans-serif;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* ═══════════════════════════════════════════════════════
   HISTORY / EMPTY STATE
   ═══════════════════════════════════════════════════════ */
.card-grid {
    padding: 0 32px 32px;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 64px 0;
    color: var(--text-muted);
}
.empty-state i { width: 48px; height: 48px; opacity: 0.4; }

.coming-soon {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 48px;
    color: var(--text-muted);
    justify-content: center;
}
.coming-soon i { width: 20px; height: 20px; }

/* Users & Whitelabel placeholder */
.users-table-wrapper, .whitelabel-form {
    margin: 0 32px 32px;
    min-height: 200px;
}

/* ═══════════════════════════════════════════════════════
   MODAL
   ═══════════════════════════════════════════════════════ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 24px;
}

.modal {
    width: 100%;
    max-width: 420px;
    padding: 32px;
    animation: slideUp 0.4s var(--ease-spring) forwards;
}

.modal-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}
.modal-header i { color: var(--accent); width: 24px; height: 24px; }
.modal-header h3 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.2rem;
}

.modal-desc {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 20px;
}

.modal form { display: flex; flex-direction: column; gap: 12px; }

/* ═══════════════════════════════════════════════════════
   RESPONSIVE (Mobile First)
   ═══════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        height: 100vh;
        z-index: 50;
        transition: left var(--duration-normal) var(--ease-out);
    }
    .sidebar.open { left: 0; }

    .mobile-menu-btn { display: flex; }

    .message-wrapper { max-width: 92%; }

    .health-grid { grid-template-columns: repeat(2, 1fr); }

    .page-header { padding: 24px 20px 12px; }
    .health-grid, .card-grid { padding: 0 20px 20px; }
    .users-table-wrapper, .whitelabel-form { margin: 0 20px 20px; }

    .chat-input-area { padding: 12px 16px; }
}

@media (max-width: 480px) {
    .health-grid { grid-template-columns: 1fr; }
    .login-card { padding: 32px 24px; }
}
