/* EClawbot Web Portal - Dark Theme */
:root {
    --bg: #0D0D1A;
    --bg-secondary: #151528;
    --card: #1A1A2E;
    --card-bg: #1A1A2E;
    --card-border: #333355;
    --input-bg: #252540;
    --primary: #6C63FF;
    --primary-rgb: 108, 99, 255;
    --primary-hover: #5A52E0;
    --danger: #F44336;
    --success: #4CAF50;
    --warning: #FFD23F;
    --info: #2196F3;
    --accent-cyan: #4FC3F7;
    --accent-gold: #FFD700;
    --danger-hover: #D32F2F;
    --warning-hover: #F57C00;
    --text: #ffffff;
    --text-secondary: #AAAAAA;
    --text-muted: #999999;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-pill: 20px;

    /* Entity character colors */
    --entity-lobster: #FF6B6B;
    --entity-pig: #FFB6C1;

    /* Status badge colors */
    --status-active: rgba(76, 175, 80, 0.15);
    --status-active-text: #4CAF50;
    --status-paused: rgba(255, 210, 63, 0.15);
    --status-paused-text: #FFD23F;
    --status-error: rgba(244, 67, 54, 0.15);
    --status-error-text: #F44336;

    /* Category badge colors */
    --cat-bug-bg: rgba(244, 67, 54, 0.15);
    --cat-bug-text: #F44336;
    --cat-feature-bg: rgba(33, 150, 243, 0.15);
    --cat-feature-text: #2196F3;
    --cat-question-bg: rgba(156, 39, 176, 0.15);
    --cat-question-text: #9C27B0;

    /* Channel badge */
    --badge-channel-bg: #1a3a2a;
    --badge-channel-text: #4ade80;
    --badge-channel-border: #2d6a4a;

    /* XP gradient */
    --xp-from: #FFD700;
    --xp-to: #FFA500;

    /* Code syntax (screen-control) */
    --code-keyword: #569cd6;
    --code-string: #ce9178;
    --code-comment: #888888;
}

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

html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

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

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ==========================================
   Navigation - Logo + Mobile Hamburger
   ========================================== */
.nav {
    background: var(--card);
    border-bottom: 1px solid var(--card-border);
    padding: 0 16px;
    display: flex;
    align-items: center;
    height: 56px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    margin-right: 24px;
    flex-shrink: 0;
}

.nav-brand:hover { text-decoration: none; }

.nav-logo {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    filter: drop-shadow(0 0 6px rgba(108, 99, 255, 0.5));
    animation: logoPulse 3s ease-in-out infinite;
}

@keyframes logoPulse {
    0%, 100% { filter: drop-shadow(0 0 6px rgba(108, 99, 255, 0.3)); }
    50% { filter: drop-shadow(0 0 12px rgba(108, 99, 255, 0.7)); }
}

.nav-logo-text {
    font-size: 18px;
    font-weight: 800;
    background: linear-gradient(135deg, #6C63FF 0%, #FF6584 50%, #FFD23F 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
}

.nav-hamburger {
    display: none;
    flex-direction: column;
    gap: 4px;
    padding: 8px;
    background: none;
    border: none;
    cursor: pointer;
    margin-left: auto;
}

.nav-hamburger span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text-secondary);
    border-radius: 1px;
    transition: all 0.3s;
}

.nav-links {
    display: flex;
    gap: 4px;
    flex: 1;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.nav-link:hover {
    background: var(--input-bg);
    color: var(--text);
    text-decoration: none;
}

.nav-link.active {
    background: var(--primary);
    color: var(--text);
}

.nav-link-icon {
    font-size: 16px;
    display: none;
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.nav-user .email {
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (min-width: 769px) and (max-width: 1440px) {
    .nav {
        padding: 0 10px;
        gap: 4px;
    }

    .nav-brand {
        margin-right: 10px;
    }

    .nav-links {
        min-width: 0;
        overflow: hidden;
    }

    .nav-link {
        padding: 8px 9px;
        font-size: 13px;
    }

    .nav-user {
        gap: 8px;
        min-width: 0;
    }

    .nav-user .email {
        max-width: 96px;
    }
}

/* ==========================================
   Notification Bell + Dropdown
   ========================================== */
/* ── e-coin balance badge (nav bar) ── */
.ecoin-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px 4px 6px;
    border-radius: 16px;
    background: linear-gradient(135deg, rgba(109, 40, 217, 0.2), rgba(16, 185, 129, 0.15));
    border: 1px solid rgba(109, 40, 217, 0.3);
    text-decoration: none;
    color: #a78bfa;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.3px;
    transition: all 0.2s;
    cursor: pointer;
    white-space: nowrap;
    margin-right: 4px;
}
.ecoin-badge:hover {
    background: linear-gradient(135deg, rgba(109, 40, 217, 0.35), rgba(16, 185, 129, 0.25));
    border-color: rgba(109, 40, 217, 0.5);
    color: #c4b5fd;
    transform: translateY(-1px);
}
.ecoin-icon { color: #10b981; flex-shrink: 0; }
.ecoin-amount { font-variant-numeric: tabular-nums; }

.notif-bell {
    position: relative;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    transition: background 0.2s;
}
.notif-bell:hover { background: rgba(108, 99, 255, 0.15); }
.bell-icon { color: var(--text-secondary); }
.notif-bell:hover .bell-icon { color: var(--primary); }

.notif-badge {
    position: absolute;
    top: 4px;
    right: 2px;
    background: var(--danger);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    line-height: 1;
}

.notif-dropdown {
    position: absolute;
    top: 52px;
    right: 0;
    width: 360px;
    max-height: 480px;
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    z-index: 200;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.notif-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--card-border);
    font-weight: 600;
    font-size: 14px;
}
.notif-mark-all {
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    font-size: 12px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
}
.notif-mark-all:hover { background: rgba(108, 99, 255, 0.1); }

.notif-list {
    overflow-y: auto;
    max-height: 420px;
    scrollbar-width: thin;
}

.notif-item {
    display: flex;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid rgba(51, 51, 85, 0.3);
    transition: background 0.15s;
}
.notif-item:hover { background: rgba(108, 99, 255, 0.05); }
.notif-item.notif-unread { background: rgba(108, 99, 255, 0.08); }
.notif-item.notif-unread::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--primary);
}
.notif-item { position: relative; }

.notif-item-icon {
    font-size: 20px;
    flex-shrink: 0;
    width: 28px;
    text-align: center;
}
.notif-item-content { flex: 1; min-width: 0; }
.notif-item-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.notif-item-body {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.notif-item-time {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

.notif-empty, .notif-loading {
    padding: 32px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* ==========================================
   Layout
   ========================================== */
.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 24px 16px;
}

.page-title {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 20px;
}

/* ==========================================
   Cards
   ========================================== */
.card {
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}

.card-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* ==========================================
   Buttons
   ========================================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    min-height: 44px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text);
}

.btn-primary { background: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); }
.btn-success { background: var(--success); }
.btn-warning { background: var(--warning); color: #000; }
.btn-warning:hover { background: var(--warning-hover); }
.btn-outline {
    background: transparent;
    border: 1px solid var(--card-border);
    color: var(--text-secondary);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-ghost {
    background: transparent;
    border: 1px solid var(--card-border);
    color: var(--text);
}
.btn-ghost:hover { background: var(--card-border); color: var(--text); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; background: var(--card-border); }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Focus indicators for all interactive elements */
.nav-link:focus-visible,
.entity-card:focus-visible,
.chip:focus-visible,
.notif-bell:focus-visible,
.toggle-switch:focus-within,
.form-input:focus-visible,
.auth-tab:focus-visible,
.dialog .btn:focus-visible,
.ai-chat-fab:focus-visible,
.ai-chat-close-btn:focus-visible,
.ai-chat-clear-btn:focus-visible,
.ai-chat-send-btn:focus-visible,
.ai-chat-action-btn:focus-visible,
.notif-mark-all:focus-visible,
.notif-item:focus-visible,
.badge:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: var(--radius-sm); }

/* ==========================================
   Inputs
   ========================================== */
.form-group { margin-bottom: 16px; }
.form-label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--input-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.form-input:focus { border-color: var(--primary); }
.form-input::placeholder { color: var(--text-muted); }

/* ==========================================
   Badges
   ========================================== */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-free { background: var(--card-border); color: var(--text-secondary); }
.badge-premium { background: linear-gradient(135deg, #FFD700, #FFA500); color: #000; }
.badge-idle { background: #2E7D32; }
.badge-busy { background: #E65100; }
.badge-sleeping { background: #1565C0; }
.badge-excited { background: #AD1457; }

/* ==========================================
   Entity Card
   ========================================== */
.entity-card {
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 0;
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
}

.entity-card-body {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 16px;
}

.entity-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-top: 1px solid var(--card-border);
}

.entity-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--input-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 2px solid transparent;
}

.entity-avatar:hover {
    transform: scale(1.1);
    border-color: var(--primary);
    box-shadow: 0 0 12px rgba(108, 99, 255, 0.3);
}

.entity-avatar-img {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
}

.avatar-upload-area {
    position: relative;
    width: 100%;
    margin-bottom: 16px;
    border: 2px dashed var(--border-color);
    border-radius: 12px;
    background: var(--input-bg);
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
    overflow: hidden;
}
.avatar-upload-area:hover {
    border-color: var(--primary);
    background: rgba(108, 99, 255, 0.06);
}
.avatar-upload-area.dragover {
    border-color: var(--primary);
    background: rgba(108, 99, 255, 0.12);
    box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.15);
}
.avatar-upload-area.uploading {
    pointer-events: none;
    opacity: 0.7;
}
.avatar-upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 20px 10px;
    color: var(--text-secondary);
}
.avatar-upload-placeholder .upload-icon {
    font-size: 28px;
    line-height: 1;
}
.avatar-upload-placeholder .upload-text {
    font-size: 13px;
}
.avatar-upload-placeholder .upload-hint {
    font-size: 11px;
    opacity: 0.6;
}
/* Preview state */
.avatar-upload-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px;
    gap: 12px;
}
.avatar-upload-preview img {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--primary);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.avatar-upload-preview .preview-actions {
    display: flex;
    gap: 8px;
}
/* Spinner overlay */
.avatar-upload-spinner {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.4);
    border-radius: 12px;
}
.avatar-upload-spinner::after {
    content: '';
    width: 32px;
    height: 32px;
    border: 3px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
/* Remove photo link */
.avatar-remove-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    margin-bottom: 12px;
    transition: color 0.15s;
}
.avatar-remove-link:hover {
    color: var(--danger, #e74c3c);
}

.entity-info { flex: 1; min-width: 0; }
.entity-name { font-weight: 600; font-size: 15px; margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entity-message {
    font-size: 13px;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-top: 6px;
    line-height: 1.4;
}

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

.entity-badges {
    display: flex;
    gap: 6px;
    align-items: center;
}

.badge-id {
    background: var(--input-bg);
    color: var(--text-secondary);
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}

.entity-meta {
    display: flex;
    gap: 8px;
    margin-top: 4px;
    align-items: center;
}

/* ==========================================
   Chat
   ========================================== */
.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 56px);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.chat-msg {
    margin-bottom: 12px;
    max-width: 80%;
}

.chat-msg.sent { margin-left: auto; text-align: right; }
.chat-msg.received { margin-right: auto; }

.chat-bubble {
    display: inline-block;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    word-break: break-word;
    text-align: left;
}

.chat-msg.sent .chat-bubble { background: var(--primary); }
.chat-msg.received .chat-bubble { background: var(--card); border: 1px solid var(--card-border); }

.chat-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

.chat-source {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.chat-msg.sent .chat-source { text-align: right; }

.chat-input-bar {
    padding: 12px 16px;
    background: var(--card);
    border-top: 1px solid var(--card-border);
    display: flex;
    gap: 8px;
}

.chat-input-bar input {
    flex: 1;
    padding: 10px 14px;
    background: var(--input-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 14px;
    outline: none;
}

.chat-input-bar input:focus {
    border-color: var(--primary);
}

/* ==========================================
   Chips
   ========================================== */
.chip-group {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.chip {
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
    background: var(--input-bg);
    border: 1px solid var(--card-border);
    color: var(--text-secondary);
    transition: all 0.2s;
    white-space: nowrap;
}

.chip.active, .chip:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--text);
}

/* ==========================================
   Toast
   ========================================== */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    z-index: 1000;
    animation: slideIn 0.3s ease;
    max-width: 90vw;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--primary); }
.toast-warning { background: #e67e22; }

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

/* ==========================================
   Auth page
   ========================================== */
.auth-container {
    max-width: 400px;
    margin: 60px auto;
    padding: 0 16px;
}

.auth-logo {
    text-align: center;
    margin-bottom: 32px;
}

.auth-logo h1 {
    font-size: 32px;
    background: linear-gradient(135deg, #6C63FF, #FF6584, #FFD23F);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.auth-logo .auth-logo-icon {
    font-size: 48px;
    display: block;
    margin-bottom: 8px;
    filter: drop-shadow(0 0 8px rgba(108, 99, 255, 0.5));
}

.auth-logo p {
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: 8px;
}

.auth-tabs {
    display: flex;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--card-border);
}

.auth-tab {
    flex: 1;
    padding: 12px;
    text-align: center;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.auth-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.password-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.error-text {
    color: var(--danger);
    font-size: 13px;
    margin-top: 8px;
}

.success-text {
    color: var(--success);
    font-size: 13px;
    margin-top: 8px;
}

/* ==========================================
   Progress bar
   ========================================== */
.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--input-bg);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 8px;
}

.progress-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s;
}

/* ==========================================
   Dialog overlay
   ========================================== */
.dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    width: 100dvw;
    height: 100vh;
    height: 100dvh;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 600;
}

.dialog {
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 24px;
    min-width: 300px;
    max-width: 480px;
    width: 90vw;
    max-height: 90vh;
    max-height: 90dvh;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.dialog-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
    flex-shrink: 0;
}

.dialog-body {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.dialog-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 20px;
    flex-shrink: 0;
}

/* Danger button (destructive actions) */
.btn-danger {
    background: #e53e3e;
    color: #fff;
    border: none;
}
.btn-danger:hover {
    background: #c53030;
}

/* ==========================================
   Loading spinner
   ========================================== */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--card-border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 32px;
    color: var(--text-muted);
    font-size: 14px;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--input-bg);
    border-radius: 12px;
    transition: 0.3s;
}
.toggle-slider::before {
    content: '';
    position: absolute;
    height: 18px; width: 18px;
    left: 3px; bottom: 3px;
    background: var(--text-secondary);
    border-radius: 50%;
    transition: 0.3s;
}
.toggle-switch input:checked + .toggle-slider { background: var(--primary); }
.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
    background: white;
}

/* ==========================================
   Mobile Responsive
   ========================================== */
@media (max-width: 768px) {
    /* Nav becomes hamburger menu */
    .nav {
        flex-wrap: wrap;
        height: auto;
        min-height: 56px;
        padding: 0 12px;
    }

    .nav-hamburger {
        display: flex;
    }

    .nav-links {
        display: none;
        width: 100%;
        flex-direction: column;
        gap: 2px;
        padding: 8px 0;
        border-top: 1px solid var(--card-border);
    }

    .nav-open .nav-links {
        display: flex;
    }

    .nav-link {
        padding: 12px 16px;
        border-radius: var(--radius-sm);
    }

    .nav-link-icon {
        display: inline;
    }

    .nav-user {
        display: none;
        width: 100%;
        padding: 8px 0;
        border-top: 1px solid var(--card-border);
        justify-content: space-between;
    }

    .nav-open .nav-user {
        display: flex;
    }

    .nav-user .email {
        display: inline;
        max-width: none;
    }

    .notif-dropdown {
        position: fixed;
        top: 56px;
        left: 0;
        right: 0;
        width: 100%;
        max-height: calc(100vh - 56px);
        border-radius: 0;
    }

    /* Hamburger animation when open */
    .nav-open .nav-hamburger span:nth-child(1) {
        transform: translateY(6px) rotate(45deg);
    }
    .nav-open .nav-hamburger span:nth-child(2) {
        opacity: 0;
    }
    .nav-open .nav-hamburger span:nth-child(3) {
        transform: translateY(-6px) rotate(-45deg);
    }

    /* Layout */
    .container { padding: 16px 12px; }
    .page-title { font-size: 20px; }

    /* Entity cards */
    .entity-card-body { padding: 12px; gap: 10px; }
    .entity-card-footer { padding: 8px 12px; }
    .entity-avatar { width: 40px; height: 40px; font-size: 20px; }

    /* Chat */
    .chat-msg { max-width: 90%; }
    .chat-input-bar { padding: 8px 12px; }

    /* Dialog — mobile bottom-sheet */
    .dialog-overlay { align-items: flex-end; }
    .dialog { padding: 16px; min-width: auto; max-height: 85vh; max-height: 85dvh; border-radius: var(--radius) var(--radius) 0 0; width: 100%; max-width: 100%; }
    .dialog-actions { flex-direction: column; }
    .dialog-actions .btn { width: 100%; justify-content: center; }

    /* Auth */
    .auth-container { margin: 40px auto; }
}

@media (max-width: 640px) {
    .entity-grid { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
    .footer-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
    .nav-logo-text { display: none; }
    .chip { padding: 4px 10px; font-size: 11px; }
    .entity-grid { grid-template-columns: 1fr; }
}

/* ==========================================
   Site Footer
   ========================================== */
.site-footer {
    margin-top: 48px;
    border-top: 1px solid var(--card-border);
    background: var(--card);
}

.footer-inner {
    max-width: 960px;
    margin: 0 auto;
    padding: 32px 16px 20px;
}

.footer-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 24px;
    margin-bottom: 24px;
}

.footer-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.footer-logo {
    font-size: 20px;
    filter: drop-shadow(0 0 4px rgba(108, 99, 255, 0.4));
}

.footer-brand-text {
    font-size: 16px;
    font-weight: 800;
    background: linear-gradient(135deg, #6C63FF 0%, #FF6584 50%, #FFD23F 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.footer-desc {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.6;
}

.footer-col-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.footer-link {
    display: block;
    font-size: 13px;
    color: var(--text-muted);
    padding: 3px 0;
    transition: color 0.2s;
    text-decoration: none;
}

.footer-link:hover {
    color: var(--primary);
    text-decoration: none;
}

.footer-bottom {
    border-top: 1px solid var(--card-border);
    padding-top: 16px;
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
}

@media (max-width: 640px) {
    .footer-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
}

/* ==========================================
   AI Chat Widget
   ========================================== */
.ai-chat-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(108, 99, 255, 0.4);
    z-index: 500;
    transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s;
}
.ai-chat-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(108, 99, 255, 0.6);
}
.ai-chat-fab-icon { font-size: 24px; line-height: 1; }
.ai-chat-fab-hidden { opacity: 0; pointer-events: none; transform: scale(0.5); }

.ai-chat-panel {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 380px;
    height: 520px;
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    z-index: 500;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: aiChatSlideUp 0.25s ease;
}
@keyframes aiChatSlideUp {
    from { opacity: 0; transform: translateY(20px) scale(0.95); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    background: var(--input-bg);
    border-bottom: 1px solid var(--card-border);
    flex-shrink: 0;
}
.ai-chat-header-left { display: flex; align-items: center; gap: 8px; }
.ai-chat-header-icon { font-size: 20px; }
.ai-chat-header-title { font-size: 15px; font-weight: 700; }
.ai-chat-header-right { display: flex; gap: 4px; }
.ai-chat-clear-btn,
.ai-chat-close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 18px;
    padding: 4px 6px;
    border-radius: 4px;
    transition: background 0.15s;
}
.ai-chat-clear-btn:hover,
.ai-chat-close-btn:hover { background: var(--card-border); color: var(--text); }

.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.ai-chat-messages::-webkit-scrollbar { width: 5px; }
.ai-chat-messages::-webkit-scrollbar-track { background: transparent; }
.ai-chat-messages::-webkit-scrollbar-thumb { background: var(--card-border); border-radius: 3px; }

.ai-chat-welcome { text-align: center; padding: 32px 16px; color: var(--text-secondary); }
.ai-chat-welcome-icon { font-size: 40px; margin-bottom: 12px; filter: drop-shadow(0 0 6px rgba(108,99,255,0.4)); }
.ai-chat-welcome-text { font-size: 14px; line-height: 1.5; }

.ai-chat-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.5;
    word-break: break-word;
}
.ai-chat-msg-user {
    align-self: flex-end;
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 4px;
    white-space: pre-wrap;
}
.ai-chat-msg-assistant {
    align-self: flex-start;
    background: var(--input-bg);
    color: var(--text);
    border: 1px solid var(--card-border);
    border-bottom-left-radius: 4px;
}
.ai-chat-msg-assistant pre {
    background: var(--bg);
    border: 1px solid var(--card-border);
    border-radius: 6px;
    padding: 8px 10px;
    margin: 6px 0;
    overflow-x: auto;
    font-size: 12px;
}
.ai-chat-msg-assistant code { font-family: 'Courier New', monospace; font-size: 12px; }
.ai-chat-inline-code { background: var(--bg); padding: 1px 5px; border-radius: 3px; font-size: 12px; }
.ai-chat-msg-assistant a { color: var(--primary); text-decoration: underline; }

.ai-chat-typing { display: flex; gap: 4px; padding: 12px 14px; }
.ai-chat-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--text-muted);
    animation: aiDotBounce 1.4s ease-in-out infinite;
}
.ai-chat-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-chat-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes aiDotBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

.ai-chat-action-bar {
    padding: 8px 14px;
    border-top: 1px solid var(--card-border);
    background: var(--bg);
    flex-shrink: 0;
}
.ai-chat-action-btn {
    width: 100%;
    padding: 8px 12px;
    background: var(--input-bg);
    border: 1px solid var(--card-border);
    border-radius: 6px;
    color: var(--text);
    cursor: pointer;
    font-size: 12px;
    text-align: left;
    transition: border-color 0.15s;
}
.ai-chat-action-btn:hover { border-color: var(--primary); }

.ai-chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 14px;
    border-top: 1px solid var(--card-border);
    background: var(--input-bg);
    flex-shrink: 0;
}
.ai-chat-input {
    flex: 1;
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: 6px;
    color: var(--text);
    padding: 10px 14px;
    font-size: 13px;
    font-family: inherit;
    resize: none;
    max-height: 100px;
    outline: none;
    transition: border-color 0.15s;
}
.ai-chat-input:focus { border-color: var(--primary); }
.ai-chat-input::placeholder { color: var(--text-muted); }
.ai-chat-send-btn {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--primary); border: none; color: #fff;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, opacity 0.15s; flex-shrink: 0;
}
.ai-chat-send-btn:disabled { opacity: 0.4; cursor: default; }
.ai-chat-send-btn:not(:disabled):hover { background: var(--primary-hover); }

@media (max-width: 900px) {
    .ai-chat-panel { width: 320px; height: 460px; }
}
@media (max-width: 640px) {
    .ai-chat-panel { width: calc(100vw - 16px); height: calc(100vh - 80px); bottom: 8px; right: 8px; }
    .ai-chat-fab { bottom: 16px; right: 16px; width: 50px; height: 50px; }
}

/* ── Help Popover ───────────────────────────────────────────────────────────── */
.help-popover {
    position: fixed;
    z-index: 9999;
    max-width: 280px;
    min-width: 160px;
    background: var(--card, #1e1e2e);
    border: 1px solid var(--card-border, #333);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    font-size: 13px;
    line-height: 1.5;
    color: var(--text, #e0e0e0);
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.18s ease, transform 0.18s ease;
    pointer-events: none;
}
.help-popover-visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}
.help-popover-inner {
    padding: 12px 14px 14px;
    color: var(--text-secondary, #aaa);
    word-break: break-word;
}
.help-popover-inner strong { color: var(--text, #fff); font-weight: 600; }
.help-popover-inner a { color: var(--primary, #6c63ff); text-decoration: underline; }
.help-popover-inner ul, .help-popover-inner ol {
    margin: 6px 0 6px 18px;
    padding: 0;
}
.help-popover-inner li { margin-bottom: 3px; }
.help-popover-close {
    position: absolute;
    top: 6px; right: 8px;
    background: none;
    border: none;
    color: var(--text-muted, #888);
    font-size: 14px;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    line-height: 1;
    transition: color 0.15s;
}
.help-popover-close:hover { color: var(--text, #fff); }

/* ── Help Icon (use as .help-icon[data-help-content]) ───────────────────────── */
.help-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: rgba(108,99,255,0.15);
    color: var(--primary, #6c63ff);
    cursor: pointer;
    flex-shrink: 0;
    vertical-align: middle;
    margin-left: 3px;
    transition: background 0.15s, color 0.15s;
    border: none;
    padding: 0;
    font-size: 0; /* hide text */
    position: relative; /* anchor the ::after tap-target expansion */
}
/* Invisible expanded hit area — bumps the effective tap target from 16x16
   to 36x36 (Apple HIG 44pt / Material 48dp minimum). Click/tap bubbles
   from ::after to .help-icon so the popover toggler still fires. */
.help-icon::after {
    content: '';
    position: absolute;
    inset: -10px;
}
.help-icon:hover {
    background: rgba(108,99,255,0.3);
}
.help-icon:focus {
    outline: 2px solid var(--primary, #6c63ff);
    outline-offset: 2px;
}
.help-icon svg { width: 12px; height: 12px; }
