:root {
    --bg-main: #0a0a1a;
    --bg-card: rgba(18, 18, 42, 0.7);
    --bg-surface: rgba(255, 255, 255, 0.05);
    --bg-surface-hover: rgba(255, 255, 255, 0.08);
    
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    
    --grad-primary: linear-gradient(135deg, #7c3aed, #3b82f6, #06b6d4);
    --accent-glow: rgba(124, 58, 237, 0.3);
    
    --color-success: #10b981;
    --color-error: #ef4444;
    --color-warning: #f59e0b;
    
    --border-light: rgba(255, 255, 255, 0.1);
    --blur-glass: blur(20px);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Glassmorphism */
.glass {
    background: var(--bg-card);
    backdrop-filter: var(--blur-glass);
    -webkit-backdrop-filter: var(--blur-glass);
    border: 1px solid var(--border-light);
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--bg-card);
    backdrop-filter: var(--blur-glass);
    border-right: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
}

.brand {
    padding: 2rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.brand-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--grad-primary);
}

.nav-menu {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0 1rem;
    gap: 0.5rem;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.3s ease;
    gap: 1rem;
}

.nav-item:hover, .nav-item.active {
    background: var(--bg-surface);
    color: var(--text-primary);
}

.nav-item.active {
    border-left: 4px solid #7c3aed;
    background: rgba(124, 58, 237, 0.1);
}

.connection-status {
    padding: 1.5rem;
    border-top: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--color-error);
}

.status-indicator.online {
    background-color: var(--color-success);
    animation: pulse 2s infinite;
}

/* Main Content */
.main-content {
    margin-left: 260px;
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
}

.section {
    display: none;
    animation: fadeInUp 0.4s ease forwards;
}

.section.active {
    display: block;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

/* Cards */
.card {
    background: var(--bg-card);
    backdrop-filter: var(--blur-glass);
    border: 1px solid var(--border-light);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    backdrop-filter: var(--blur-glass);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    position: relative;
    overflow: hidden;
}

.stat-card::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 3px;
    background: var(--grad-primary);
}

.stat-card .label {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.stat-card .value {
    font-size: 2rem;
    font-weight: 700;
}

.grid-2col {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
}

/* Buttons */
.btn {
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.3s ease;
    font-family: inherit;
    font-size: 0.9rem;
}

.btn-primary {
    background: var(--grad-primary);
    color: white;
    box-shadow: 0 4px 15px var(--accent-glow);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--accent-glow);
}

.btn-outline {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-light);
}

.btn-outline:hover {
    background: var(--bg-surface);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--color-error);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
    background: var(--color-error);
    color: white;
}

/* Forms */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.input, .select, .textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    color: var(--text-primary);
    font-family: inherit;
    transition: all 0.3s ease;
}

.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: #7c3aed;
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.textarea {
    min-height: 100px;
    resize: vertical;
}

/* Tables */
.table-responsive {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

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

.table th {
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.9rem;
}

/* Badges & Switches */
.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.8rem;
    font-weight: 500;
}

.badge-ai { background: rgba(124, 58, 237, 0.2); color: #c4b5fd; }
.badge-template { background: rgba(59, 130, 246, 0.2); color: #93c5fd; }
.badge-success { background: rgba(16, 185, 129, 0.2); color: #6ee7b7; }
.badge-warning { background: rgba(245, 158, 11, 0.2); color: #fcd34d; }

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--bg-surface);
    transition: .4s;
    border-radius: 34px;
    border: 1px solid var(--border-light);
}
.slider:before {
    position: absolute;
    content: "";
    height: 16px; width: 16px;
    left: 3px; bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}
input:checked + .slider { background: var(--grad-primary); border-color: transparent; }
input:checked + .slider:before { transform: translateX(20px); }

/* Activity Feed */
.activity-feed {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-height: 400px;
    overflow-y: auto;
}

.activity-item {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-surface);
    border-radius: 8px;
    animation: fadeInUp 0.3s ease;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
    animation: fadeIn 0.2s ease;
}

.modal-content {
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

/* Toasts */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: var(--bg-card);
    backdrop-filter: var(--blur-glass);
    border: 1px solid var(--border-light);
    color: var(--text-primary);
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    animation: slideInRight 0.3s ease forwards;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Animations */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(100%); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); }
    70% { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Master control panel */
.control-panel {
    margin-bottom: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.control-main {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.control-hint {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 0.35rem;
}
.control-hint.ok { color: #6ee7b7; }
.control-hint.warn { color: #fcd34d; }

.switch-lg { width: 60px; height: 32px; flex-shrink: 0; }
.switch-lg .slider:before { height: 24px; width: 24px; left: 3px; bottom: 3px; }
.switch-lg input:checked + .slider:before { transform: translateX(28px); }

.control-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    padding: 1rem;
    background: var(--bg-surface);
    border-radius: 12px;
}

.control-item { display: flex; flex-direction: column; gap: 0.35rem; }
.control-label { font-weight: 600; font-size: 0.95rem; }
.control-value { color: var(--text-secondary); font-size: 0.85rem; }
.control-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.live-dot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--color-success);
    animation: pulse 2s infinite;
    margin-right: 4px;
}

/* Readiness checklist */
.checklist {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 0.75rem;
}

.check-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: 10px;
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    font-size: 0.88rem;
    cursor: pointer;
    transition: all 0.25s ease;
}
.check-item:hover { background: var(--bg-surface-hover); transform: translateY(-1px); }
.check-item.ok { border-color: rgba(16, 185, 129, 0.35); }
.check-item.bad { border-color: rgba(245, 158, 11, 0.4); }

.check-icon {
    width: 22px; height: 22px;
    flex-shrink: 0;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 0.75rem;
    font-weight: 700;
}
.check-item.ok .check-icon { background: rgba(16, 185, 129, 0.2); color: #6ee7b7; }
.check-item.bad .check-icon { background: rgba(245, 158, 11, 0.2); color: #fcd34d; }

/* Settings */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
    gap: 1.5rem;
    align-items: start;
}

.token-status {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.85rem 1rem;
    border-radius: 10px;
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    font-size: 0.88rem;
    margin-bottom: 1.25rem;
    line-height: 1.5;
}
.token-status .dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--text-secondary);
}
.token-status.ok { border-color: rgba(16, 185, 129, 0.35); }
.token-status.ok .dot { background: var(--color-success); }
.token-status.bad { border-color: rgba(239, 68, 68, 0.35); }
.token-status.bad .dot { background: var(--color-error); }
.token-status.checking .dot { background: var(--color-warning); }

.hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.4rem;
    line-height: 1.6;
}
.hint code {
    background: var(--bg-surface);
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    font-size: 0.9em;
}

.req { color: var(--color-error); }

.key-state { font-size: 0.75rem; margin-left: 0.35rem; }
.key-state.set { color: #6ee7b7; }
.key-state.unset { color: var(--text-secondary); }

.form-actions-inline { display: flex; gap: 0.75rem; align-items: flex-start; }
.form-actions-inline .input { flex: 1; }

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.divider {
    border: none;
    border-top: 1px solid var(--border-light);
    margin: 1.5rem 0;
}

/* Logged-in user in the sidebar */
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-light);
}
.user-avatar {
    width: 36px; height: 36px;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--grad-primary);
    background-size: cover;
    background-position: center;
    display: grid;
    place-items: center;
    font-weight: 700;
    text-transform: uppercase;
}
.user-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.user-info strong {
    font-size: 0.87rem;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-info span { font-size: 0.72rem; color: var(--text-secondary); }

.btn-logout {
    background: transparent;
    border: 1px solid var(--border-light);
    color: var(--text-secondary);
    border-radius: 6px;
    padding: 0.3rem 0.6rem;
    font-size: 0.75rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.25s ease;
}
.btn-logout:hover { background: var(--color-error); border-color: transparent; color: #fff; }

.user-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 0;
    border-bottom: 1px solid var(--border-light);
}
.user-row:last-child { border-bottom: none; }
.user-row strong { margin-right: 0.4rem; }

/* Facebook login */
.btn-fb {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.75rem 1.4rem;
    border-radius: 8px;
    background: #1877f2;
    color: #fff;
    font-weight: 600;
    font-size: 0.95rem;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: all 0.25s ease;
    box-shadow: 0 4px 15px rgba(24, 119, 242, 0.3);
}
.btn-fb::before {
    content: 'f';
    display: grid;
    place-items: center;
    width: 22px; height: 22px;
    border-radius: 50%;
    background: #fff;
    color: #1877f2;
    font-weight: 800;
    font-family: Georgia, serif;
}
.btn-fb:hover { background: #166fe5; transform: translateY(-2px); }
.btn-fb.disabled {
    background: var(--bg-surface);
    color: var(--text-secondary);
    box-shadow: none;
    pointer-events: none;
    opacity: 0.6;
}
.btn-fb.disabled::before { background: var(--text-secondary); color: var(--bg-main); }

.redirect-uri-box {
    margin-top: 1.25rem;
    padding: 1rem;
    border-radius: 10px;
    background: var(--bg-surface);
    border: 1px solid rgba(245, 158, 11, 0.35);
}
.redirect-uri-box code {
    display: block;
    padding: 0.6rem 0.75rem;
    margin: 0.5rem 0;
    background: var(--bg-main);
    border-radius: 6px;
    font-size: 0.85rem;
    word-break: break-all;
    color: #fcd34d;
}

.manual-connect { margin-top: 1.5rem; }
.manual-connect summary {
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.85rem;
    padding: 0.5rem 0;
}
.manual-connect summary:hover { color: var(--text-primary); }

/* Result boxes (AI test / rule test) */
.result-box {
    margin-top: 1rem;
    padding: 1rem;
    border-radius: 10px;
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    font-size: 0.9rem;
    line-height: 1.6;
}
.result-label { color: var(--text-secondary); font-size: 0.82rem; margin-bottom: 0.5rem; }
.result-text { white-space: pre-wrap; }
.muted { color: var(--text-secondary); }

/* Rules */
.rules-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 1.25rem;
}
.rule-card { display: flex; flex-direction: column; gap: 1rem; }
.rule-card.inactive { opacity: 0.55; }
.rule-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.rule-head h3 { margin-bottom: 0.5rem; font-size: 1rem; display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.rule-keywords { font-size: 0.82rem; color: var(--text-secondary); }
.rule-preview {
    font-size: 0.85rem;
    color: var(--text-secondary);
    background: var(--bg-surface);
    padding: 0.75rem;
    border-radius: 8px;
    border-left: 3px solid rgba(124, 58, 237, 0.5);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.badge-priority { background: rgba(148, 163, 184, 0.15); color: var(--text-secondary); }
.badge-error { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }

/* Backlog */
.backlog-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
}
.backlog-stats div { display: flex; flex-direction: column; gap: 0.25rem; }
.backlog-stats .label { color: var(--text-secondary); font-size: 0.82rem; }
.backlog-stats strong { font-size: 1.35rem; }

.backlog-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 0.85rem 1rem;
    background: var(--bg-card);
    backdrop-filter: var(--blur-glass);
    border: 1px solid var(--border-light);
    border-radius: 12px;
}
.backlog-toolbar > div { display: flex; gap: 0.5rem; }

.backlog-item { margin-bottom: 1rem; display: flex; flex-direction: column; gap: 0.75rem; }
.backlog-item.unanswerable { opacity: 0.55; }

.backlog-head { display: flex; align-items: flex-start; gap: 0.85rem; }
.backlog-meta { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }

.backlog-check { position: relative; display: inline-flex; flex-shrink: 0; padding-top: 2px; }
.backlog-check input { width: 20px; height: 20px; cursor: pointer; accent-color: #7c3aed; }
.backlog-check input:disabled { cursor: not-allowed; }

.backlog-comment {
    padding: 0.75rem 1rem;
    background: var(--bg-surface);
    border-radius: 8px;
    font-size: 0.92rem;
    line-height: 1.6;
}

.backlog-reply {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    border-left: 3px solid var(--color-success);
    background: rgba(16, 185, 129, 0.07);
}
.backlog-reply.needs-text {
    border-left-color: var(--color-warning);
    background: rgba(245, 158, 11, 0.07);
}
.backlog-reply p { margin-top: 0.5rem; font-size: 0.92rem; line-height: 1.6; }
.backlog-reply-text {
    margin-top: 0.6rem;
    min-height: 0;
    resize: none;
    overflow: hidden;
    font-size: 0.92rem;
    line-height: 1.6;
    background: rgba(0, 0, 0, 0.2);
}

.bulk-card { margin-bottom: 1.5rem; }
.bulk-card h2 { margin-bottom: 0.5rem; }

.toolbar-right { display: flex; align-items: center; gap: 1rem; }
.warn-text { color: var(--color-warning); font-size: 0.82rem; }

.backlog-skip {
    padding: 0.6rem 1rem;
    border-radius: 8px;
    border-left: 3px solid var(--color-warning);
    background: rgba(245, 158, 11, 0.07);
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Misc */
.empty-state {
    padding: 3rem 1rem;
    text-align: center;
    color: var(--text-secondary);
    grid-column: 1 / -1;
}

.quick-actions { display: flex; flex-direction: column; gap: 0.75rem; }

.reply-cell { max-width: 320px; color: #6ee7b7; font-size: 0.88rem; }

.ext-link { color: #93c5fd; font-size: 0.8rem; text-decoration: none; white-space: nowrap; }
.ext-link:hover { text-decoration: underline; }

.log-row { padding: 1rem; border-bottom: 1px solid var(--border-light); }
.log-row p { color: var(--text-secondary); margin-top: 0.25rem; font-size: 0.9rem; }
.log-time { color: var(--text-secondary); font-size: 0.78rem; margin-left: 0.5rem; }

.toast-success { border-left: 3px solid var(--color-success); }
.toast-error { border-left: 3px solid var(--color-error); }
.toast-info { border-left: 3px solid #3b82f6; }

@media (max-width: 900px) {
    .grid-2col { grid-template-columns: 1fr; }
    .settings-grid { grid-template-columns: 1fr; }
    .main-content { padding: 1.25rem; }
}

.skeleton {
    background: linear-gradient(90deg, var(--bg-surface) 25%, var(--bg-surface-hover) 50%, var(--bg-surface) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
}

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}
