/* ============================================
   TG Grid Automator — Dashboard Styles v2
   Modern ChatPlace-inspired design system
   ============================================ */

/* ── FOUC prevention handled via inline script in <head> ── */

/* ── Design Tokens: Dark Theme (default) ── */
:root {
    /* Backgrounds */
    --bg: #0f1117;
    --bg-card: #1a1d27;
    --bg-input: #252830;
    --bg-hover: #1e2230;
    --bg-elevated: #22253a;

    /* Borders */
    --border: #2d3040;

    /* Text */
    --text: #e4e6ed;
    --text-muted: #8b8fa3;
    --text-secondary: #a0a3b5;

    /* Brand */
    --primary: #5b6ef5;
    --primary-hover: #4a5cd4;
    --primary-light: rgba(91, 110, 245, 0.15);

    /* Semantic */
    --success: #22c55e;
    --success-light: rgba(34, 197, 94, 0.15);
    --warning: #f59e0b;
    --warning-light: rgba(245, 158, 11, 0.15);
    --danger: #ef4444;
    --danger-light: rgba(239, 68, 68, 0.15);
    --info: #3b82f6;
    --info-light: rgba(59, 130, 246, 0.15);

    /* Shapes */
    --radius: 8px;
    --radius-lg: 12px;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4);

    /* Sidebar */
    --sidebar-width: 260px;
    --sidebar-bg: #13151f;
    --sidebar-border: #232638;
    --sidebar-item-hover: rgba(91, 110, 245, 0.08);

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-base: 0.25s ease;

    /* Aliases used in templates */
    --card-bg: var(--bg-card);
    --card: var(--bg-card);
}

/* ── Light Theme ── */
[data-theme="light"] {
    --bg: #f5f6fa;
    --bg-card: #ffffff;
    --bg-input: #f0f1f5;
    --bg-hover: #ebedf3;
    --bg-elevated: #ffffff;

    --border: #e0e2ea;

    --text: #1a1d2e;
    --text-muted: #6b7085;
    --text-secondary: #4a4e68;

    --primary: #5b6ef5;
    --primary-hover: #4a5cd4;
    --primary-light: rgba(91, 110, 245, 0.1);

    --success-light: rgba(34, 197, 94, 0.1);
    --warning-light: rgba(245, 158, 11, 0.1);
    --danger-light: rgba(239, 68, 68, 0.1);
    --info-light: rgba(59, 130, 246, 0.1);

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.1);

    --sidebar-bg: #ffffff;
    --sidebar-border: #e0e2ea;
    --sidebar-item-hover: rgba(91, 110, 245, 0.06);

    --card-bg: var(--bg-card);
    --card: var(--bg-card);
}

/* ── Reset ── */
* { margin: 0; padding: 0; box-sizing: border-box; }

/* ── Typography ── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 22px; font-weight: 700; margin-bottom: 20px; letter-spacing: -0.3px; }
h2 { font-size: 17px; font-weight: 600; margin: 25px 0 15px; color: var(--text-muted); }
h3 { font-size: 15px; font-weight: 600; }

.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }
.caption { font-size: 12px; color: var(--text-muted); }

/* ══════════════════════════════════════
   SIDEBAR
   ══════════════════════════════════════ */

.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform var(--transition-base);
}

/* Logo area */
.sidebar-header {
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text);
}

.sidebar-logo:hover { text-decoration: none; }

.sidebar-logo-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #5b6ef5 0%, #8b5cf6 100%);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-logo-icon svg { width: 20px; height: 20px; color: #fff; }

.sidebar-logo-text {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.sidebar-logo-sub {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 400;
}

/* Navigation groups */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.nav-group {
    margin-bottom: 4px;
}

.nav-group-label {
    padding: 12px 20px 6px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    opacity: 0.7;
}

.nav-list {
    list-style: none;
    padding: 0;
}

.nav-list li a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 20px;
    color: var(--text-muted);
    font-size: 13.5px;
    font-weight: 500;
    transition: all var(--transition-fast);
    border-left: 3px solid transparent;
    text-decoration: none;
}

.nav-list li a svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.7;
}

.nav-list li a:hover {
    color: var(--text);
    background: var(--sidebar-item-hover);
    text-decoration: none;
}

.nav-list li a:hover svg { opacity: 1; }

.nav-list li a.active {
    color: var(--primary);
    background: var(--primary-light);
    border-left-color: var(--primary);
    font-weight: 600;
}

.nav-list li a.active svg {
    opacity: 1;
    color: var(--primary);
}

/* Theme toggle */
.sidebar-theme-toggle {
    padding: 8px 20px;
    margin: 4px 0;
}

.theme-toggle-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: inherit;
}

.theme-toggle-btn:hover {
    border-color: var(--primary);
    color: var(--text);
}

.theme-toggle-btn svg { width: 16px; height: 16px; }

.theme-icon-dark,
.theme-icon-light { display: none; }

/* Dark theme: show moon icon (switch to light) */
:root .theme-icon-light { display: inline; }
:root .theme-icon-dark { display: none; }

[data-theme="light"] .theme-icon-light { display: none; }
[data-theme="light"] .theme-icon-dark { display: inline; }

/* Sidebar footer */
.sidebar-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-user-avatar {
    width: 32px;
    height: 32px;
    background: var(--primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}

.sidebar-user-info {
    flex: 1;
    min-width: 0;
}

.sidebar-user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.sidebar-user-role {
    font-size: 11px;
    color: var(--text-muted);
}

.sidebar-logout {
    padding: 4px 10px;
    font-size: 12px;
}

.sidebar-version {
    font-size: 10px;
    color: var(--text-muted);
    opacity: 0.5;
    text-align: center;
    letter-spacing: 0.5px;
}

/* Hamburger (mobile) */
.hamburger-btn {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 200;
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
}

.hamburger-btn svg { width: 20px; height: 20px; }

/* Overlay (mobile) */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
}

.sidebar-overlay.active {
    display: block;
}

/* ══════════════════════════════════════
   MAIN CONTENT
   ══════════════════════════════════════ */

main.with-sidebar {
    margin-left: var(--sidebar-width);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 28px 30px;
}

/* ── Headers ── */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.page-header h1 { margin-bottom: 0; }

.page-header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* ══════════════════════════════════════
   COMPONENTS
   ══════════════════════════════════════ */

/* ── Stats Grid ── */
.stats-grid { margin-bottom: 28px; }

#stats-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 14px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition-fast), transform var(--transition-fast);
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.stat-card.success { border-color: var(--success); }
.stat-card.warning { border-color: var(--warning); }
.stat-card.error { border-color: var(--danger); }

.stat-value {
    font-size: 30px;
    font-weight: 700;
    color: var(--text);
}

.stat-card.success .stat-value { color: var(--success); }
.stat-card.warning .stat-value { color: var(--warning); }
.stat-card.error .stat-value { color: var(--danger); }

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
    font-weight: 500;
}

.stat-sub {
    font-size: 11px;
    color: var(--text-muted);
}

/* ── Tables ── */
.table-container {
    overflow-x: auto;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    padding: 12px 15px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

td {
    padding: 10px 15px;
    border-bottom: 1px solid var(--border);
    font-size: 13.5px;
}

tr:last-child td { border-bottom: none; }
tr:hover { background: var(--bg-hover); }

.text-preview {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.empty {
    text-align: center;
    color: var(--text-muted);
    padding: 30px !important;
}

/* ── Badges ── */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11.5px;
    font-weight: 600;
    background: var(--bg-input);
    color: var(--text-muted);
}

.badge-success, .badge-published { background: var(--success-light); color: var(--success); }
.badge-warning, .badge-pending, .badge-pending_review { background: var(--warning-light); color: var(--warning); }
.badge-error, .badge-publish_error, .badge-rewrite_error, .badge-failed { background: var(--danger-light); color: var(--danger); }
.badge-inactive, .badge-rejected { background: rgba(107, 114, 128, 0.15); color: #6b7280; }
.badge-queued, .badge-processing { background: var(--info-light); color: var(--info); }
.badge-completed { background: var(--success-light); color: var(--success); }

.badge-log-warning { background: var(--warning-light); color: var(--warning); }
.badge-log-error, .badge-log-critical { background: var(--danger-light); color: var(--danger); }
.badge-log-info { background: var(--info-light); color: var(--info); }

.log-error td, .log-critical td { background: rgba(239, 68, 68, 0.03); }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text);
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
    font-family: inherit;
    line-height: 1.4;
}

.btn:hover {
    background: var(--bg-hover);
    text-decoration: none;
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { background: #1aab4f; border-color: #1aab4f; color: #fff; }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; transform: translateY(-1px); }
.btn-warning { background: var(--warning); border-color: var(--warning); color: #000; }
.btn-warning:hover { background: #d97706; border-color: #d97706; color: #000; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-sm.btn-warning { color: #000; }
.btn-full { width: 100%; text-align: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; box-shadow: none !important; }

/* ── Forms ── */
.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-group small {
    display: block;
    margin-top: 4px;
    font-size: 11px;
    color: var(--text-muted);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    justify-content: flex-end;
}

.checkbox-label {
    display: flex !important;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: auto;
}

/* ── Cards Grid ── */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.channel-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition-fast), transform var(--transition-fast);
}

.channel-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.channel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.channel-header h3 { font-size: 15px; }

.channel-info p {
    font-size: 13px;
    margin-bottom: 4px;
    color: var(--text-muted);
}

.channel-info strong { color: var(--text); }
.channel-info code {
    background: var(--bg-input);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
}

.channel-keywords {
    margin: 10px 0;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.keyword-tag {
    padding: 2px 8px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 10px;
    font-size: 12px;
}

.channel-rewrite {
    margin: 10px 0;
    font-size: 12px;
    color: var(--text-muted);
}

.channel-actions {
    margin-top: 15px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

/* ── Modals ── */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 30px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-lg { max-width: 700px; }
.modal-content h2 { margin-bottom: 20px; }

/* ── Review ── */
.review-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.review-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 15px;
}

.review-panel h3 {
    margin-bottom: 10px;
    font-size: 14px;
    color: var(--text-muted);
}

.text-block {
    white-space: pre-wrap;
    font-size: 14px;
    line-height: 1.6;
}

textarea.text-block.editable {
    width: 100%;
    min-height: 200px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 10px;
    font-family: inherit;
    font-size: 14px;
    resize: vertical;
}

textarea.text-block.editable:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.review-meta {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 15px;
    margin-bottom: 20px;
    font-size: 13px;
}

.review-meta p { margin-bottom: 5px; }

.review-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

/* ── Settings ── */
.settings-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 25px;
    max-width: 600px;
    box-shadow: var(--shadow-sm);
}

/* ── Login ── */
.login-page {
    display: flex;
    min-height: 100vh;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}

.login-container { width: 100%; max-width: 400px; padding: 20px; }

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 40px 30px;
    text-align: center;
    box-shadow: var(--shadow-lg);
}

.login-card h1 { font-size: 22px; margin-bottom: 5px; }
.login-card .subtitle { color: var(--text-muted); margin-bottom: 25px; font-size: 14px; }

.login-card .form-group { text-align: left; }

.login-logo {
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, #5b6ef5 0%, #8b5cf6 100%);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
}

.login-logo svg { width: 28px; height: 28px; color: #fff; }

/* ── Alerts ── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 15px;
    font-size: 13.5px;
    font-weight: 500;
}

.alert-error { background: var(--danger-light); border: 1px solid rgba(239, 68, 68, 0.3); color: var(--danger); }
.alert-success { background: var(--success-light); border: 1px solid rgba(34, 197, 94, 0.3); color: var(--success); }
.alert-info { background: var(--info-light); border: 1px solid rgba(59, 130, 246, 0.3); color: var(--info); }
.alert-warning { background: var(--warning-light); border: 1px solid rgba(245, 158, 11, 0.3); color: var(--warning); }

/* ── Empty State ── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

/* ── Health Bar ── */
.health-bar {
    position: fixed;
    bottom: 20px;
    right: 20px;
    font-size: 12px;
    color: var(--text-muted);
}

/* ── Notifications ── */
#notifications {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
}

.notification {
    background: var(--bg-card);
    border: 1px solid var(--success);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 8px;
    font-size: 13px;
    animation: fadeIn 0.3s ease;
    box-shadow: var(--shadow-md);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Header Actions ── */
.header-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

/* ── Actions Cell ── */
.actions-cell {
    white-space: nowrap;
    display: flex;
    gap: 5px;
}

/* ── Spinner ── */
.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 10px auto;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ── Presets Section ── */
.presets-section {
    margin-bottom: 30px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.section-header h2 {
    margin: 0;
    font-size: 16px;
    color: var(--text-muted);
}

.presets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
}

.preset-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 15px;
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-sm);
}

.preset-card:hover {
    border-color: var(--primary);
    background: var(--primary-light);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.preset-inactive {
    opacity: 0.5;
}

.preset-icon {
    font-size: 28px;
    margin-bottom: 8px;
}

.preset-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}

.preset-description {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.preset-meta {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    font-size: 11px;
    color: var(--text-muted);
}

.preset-temp, .preset-fmt {
    background: var(--bg-input);
    padding: 2px 6px;
    border-radius: 4px;
}

/* ── Preset Selector (Add Channel modal) ── */
.preset-selector {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
    margin-top: 5px;
}

.preset-option {
    background: var(--bg-input);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 10px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.preset-option:hover {
    border-color: var(--primary);
}

.preset-option.selected {
    border-color: var(--primary);
    background: var(--primary-light);
}

.preset-option-icon {
    display: block;
    font-size: 22px;
    margin-bottom: 4px;
}

.preset-option-name {
    font-size: 12px;
    color: var(--text);
}

/* ── Preset Badge on Channel Card ── */
.channel-presets {
    margin: 8px 0;
}

.preset-badge {
    display: inline-block;
    background: var(--primary-light);
    color: var(--primary);
    border: 1px solid rgba(91, 110, 245, 0.3);
    border-radius: 12px;
    padding: 2px 10px;
    font-size: 12px;
    margin: 2px 4px 2px 0;
}

/* ── Preview Box ── */
.preview-box {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    font-size: 12px;
    color: var(--text-muted);
    max-height: 120px;
    overflow-y: auto;
    white-space: pre-wrap;
    font-family: monospace;
}

/* ── Range Slider ── */
input[type="range"] {
    width: 100%;
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: none;
}

/* ============================================
   Аналитика — Страница /analytics
   ============================================ */

.analytics-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.analytics-header h1 { margin: 0; }

.analytics-controls {
    display: flex;
    gap: 0.75rem;
}

.analytics-controls select {
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 0.9rem;
}

/* Карточки-сводка */
.analytics-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.analytics-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.2rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    box-shadow: var(--shadow-sm);
}

.analytics-card-icon {
    font-size: 1.8rem;
    opacity: 0.9;
}

.analytics-card-data {
    display: flex;
    flex-direction: column;
}

.analytics-card-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}

.analytics-card-value.positive { color: var(--success); }
.analytics-card-value.negative { color: var(--danger); }

.analytics-card-label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Графики */
.analytics-charts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.chart-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
}

.chart-container h3 {
    margin: 0 0 1rem 0;
    font-size: 1rem;
    color: var(--text);
}

.chart-container.chart-wide {
    margin-bottom: 1.5rem;
}

.chart-empty {
    color: var(--text-muted);
    text-align: center;
    padding: 2rem;
    font-size: 0.9rem;
}

/* Секция */
.analytics-section {
    margin-bottom: 1.5rem;
}

.analytics-section h3 {
    margin: 0 0 1rem;
}

/* Экспорт */
.analytics-export {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

/* ============================================
   Аналитика — Виджеты на дашборде
   ============================================ */

.dashboard-analytics {
    margin: 1.5rem 0;
    padding: 1.25rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.analytics-mini-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.mini-card {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.75rem;
    background: var(--bg-input);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.mini-card-icon {
    font-size: 1.5rem;
}

.mini-card-value {
    display: block;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}

.mini-card-value.positive { color: var(--success); }
.mini-card-value.negative { color: var(--danger); }

.mini-card-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.dashboard-chart-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

.dashboard-chart-box {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
}

.dashboard-chart-box h3 {
    margin: 0 0 0.75rem;
    font-size: 0.95rem;
    color: var(--text);
}

.dashboard-chart-box h3 small {
    color: var(--text-muted);
    font-weight: 400;
}

/* Топ постов на дашборде */
.dash-top-posts {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.dash-post-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}

.dash-post-row:last-child { border-bottom: none; }

.dash-post-rank {
    font-weight: 700;
    color: var(--primary);
    min-width: 2rem;
}

.dash-post-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text);
}

.dash-post-views {
    font-weight: 600;
    color: var(--success);
    white-space: nowrap;
}

.dash-post-views small {
    color: var(--text-muted);
    font-weight: 400;
}

.analytics-link {
    text-align: center;
    margin-top: 0.5rem;
}

.analytics-link .btn {
    font-size: 0.9rem;
}

/* ================================================================
   Рассылки (Broadcasts)
   ================================================================ */

.bot-users-info {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.bot-users-count strong {
    color: var(--primary);
}

.broadcasts-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.broadcast-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.2rem;
    box-shadow: var(--shadow-sm);
}

.broadcast-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.broadcast-header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.broadcast-text {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 0.8rem;
    line-height: 1.4;
}

.broadcast-stats {
    display: flex;
    gap: 1.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.8rem;
    flex-wrap: wrap;
}

.broadcast-stats strong {
    color: var(--text);
}

.broadcast-progress {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    margin-bottom: 0.8rem;
}

.progress-bar {
    flex: 1;
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
    transition: width 0.3s;
}

.progress-text {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--primary);
    min-width: 3rem;
    text-align: right;
}

.broadcast-actions {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.broadcast-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Статусы рассылок */
.badge-draft { background: var(--text-muted); color: #fff; }
.badge-scheduled { background: var(--warning); color: #fff; }
.badge-sending { background: var(--primary); color: #fff; animation: pulse 1.5s infinite; }
.badge-cancelled { background: #666; color: #fff; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* ================================================================
   Воронки (Funnels)
   ================================================================ */

.funnels-list {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.funnel-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.2rem;
    box-shadow: var(--shadow-sm);
}

.funnel-card.funnel-inactive {
    opacity: 0.6;
}

.funnel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.8rem;
}

.funnel-header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.funnel-header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.funnel-trigger {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.funnel-trigger-label {
    color: var(--text-muted);
}

.funnel-trigger code {
    background: var(--bg);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.85rem;
    color: var(--primary);
}

.funnel-steps {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.8rem;
}

.funnel-no-steps {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-style: italic;
    padding: 0.5rem 0;
}

.funnel-step {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.6rem 0.8rem;
    background: var(--bg);
    border-radius: 8px;
    border-left: 3px solid var(--primary);
}

.funnel-step-number {
    width: 28px;
    height: 28px;
    background: var(--primary);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.funnel-step-content {
    flex: 1;
    min-width: 0;
}

.funnel-step-delay {
    font-size: 0.75rem;
    color: var(--warning);
    font-weight: 600;
    margin-bottom: 0.15rem;
}

.funnel-step-text {
    font-size: 0.85rem;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.funnel-step-actions {
    display: flex;
    gap: 0.3rem;
    flex-shrink: 0;
}

.btn-icon {
    width: 28px;
    height: 28px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    border-radius: 4px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    cursor: pointer;
}

.btn-icon:hover {
    background: var(--primary);
    color: #fff;
}

.btn-icon.btn-danger:hover {
    background: var(--danger);
}

.btn-add-step {
    align-self: flex-start;
    margin-top: 0.3rem;
}

.badge-sm {
    font-size: 0.7rem;
    padding: 0.1rem 0.3rem;
}

/* ================================================================
   Модалы v2
   ================================================================ */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

/* Override for templates using .modal as overlay+container */
.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.2rem;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    margin: 0;
    font-size: 1.2rem;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0 0.3rem;
}

.modal-close:hover {
    color: var(--danger);
}

.modal-body {
    padding: 1.2rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 1rem 1.2rem;
    border-top: 1px solid var(--border);
}

/* Формы — дублирование для .form-input / .form-textarea */
.form-input,
.form-textarea {
    width: 100%;
    padding: 0.5rem 0.7rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.9rem;
    font-family: inherit;
    box-sizing: border-box;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-input:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-textarea {
    resize: vertical;
}

.form-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
    display: block;
}

.form-checkbox {
    display: flex !important;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.form-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
}

/* Кнопки — дополнения (for modal templates) */
.btn-primary {
    background: var(--primary) !important;
    color: #fff !important;
}

.btn-danger {
    background: var(--danger) !important;
    color: #fff !important;
}

.btn-warning {
    background: var(--warning) !important;
    color: #fff !important;
}

/* ============================================
   Контент-план / Календарь
   ============================================ */

.calendar-view-tabs {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.tab-btn {
    padding: 6px 16px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all var(--transition-fast);
}
.tab-btn.active, .tab-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.calendar-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}
.calendar-title {
    font-size: 1.1rem;
    font-weight: 600;
    min-width: 180px;
    text-align: center;
}

.calendar-grid {
    min-height: 400px;
}

/* ── Месяц ── */
.calendar-month {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    background: var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.cal-header {
    padding: 8px;
    background: var(--bg-card);
    text-align: center;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.cal-day {
    min-height: 100px;
    padding: 6px;
    background: var(--bg);
    cursor: pointer;
    transition: background var(--transition-fast);
}
.cal-day:hover {
    background: var(--bg-input);
}
.cal-today {
    background: var(--primary-light) !important;
}
.cal-other {
    opacity: 0.4;
}
.cal-day-num {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}
.cal-today .cal-day-num {
    color: var(--primary);
}
.cal-events {
    margin-top: 4px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.cal-event {
    padding: 2px 5px;
    border-radius: 3px;
    font-size: 0.75rem;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: grab;
}
.cal-event:active { cursor: grabbing; }
.cal-event-time {
    font-weight: 600;
    margin-right: 4px;
}
.cal-more {
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 2px 5px;
}

/* ── Неделя ── */
.calendar-week {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.cal-week-header {
    display: flex;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}
.cal-week-header .cal-time-col {
    width: 60px;
    min-width: 60px;
}
.cal-week-day-header {
    flex: 1;
    padding: 8px;
    text-align: center;
    font-weight: 600;
    font-size: 0.85rem;
    border-left: 1px solid var(--border);
}
.cal-week-day-header.cal-today {
    color: var(--primary);
    background: var(--primary-light);
}
.cal-week-body {
    max-height: 600px;
    overflow-y: auto;
}
.cal-hour-row {
    display: flex;
    min-height: 48px;
    border-bottom: 1px solid var(--border);
}
.cal-time-col {
    width: 60px;
    min-width: 60px;
    padding: 4px 8px;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: right;
    border-right: 1px solid var(--border);
}
.cal-week-cell {
    flex: 1;
    padding: 2px;
    border-left: 1px solid var(--border);
    cursor: pointer;
    transition: background var(--transition-fast);
    min-height: 48px;
}
.cal-week-cell:first-of-type { border-left: none; }
.cal-week-cell:hover { background: var(--bg-input); }
.cal-week-event {
    padding: 2px 5px;
    border-radius: 3px;
    font-size: 0.75rem;
    color: #fff;
    margin-bottom: 2px;
    cursor: grab;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── День ── */
.calendar-day-view {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.cal-day-hour-row {
    display: flex;
    min-height: 60px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background var(--transition-fast);
}
.cal-day-hour-row:hover { background: var(--bg-input); }
.cal-day-events {
    flex: 1;
    padding: 4px;
}
.cal-day-event {
    padding: 8px 12px;
    margin-bottom: 4px;
    background: var(--bg-card);
    border-radius: var(--radius);
    cursor: grab;
}
.cal-day-event-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}
.cal-day-event-text {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.4;
}
.cal-day-event-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Drag-over */
.drag-over {
    background: var(--primary-light) !important;
    outline: 2px dashed var(--primary);
    outline-offset: -2px;
}

/* ── Модал увеличенный ── */
.modal-lg { max-width: 900px; width: 95%; }

/* ── Post editor layout ── */
.post-editor-layout {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: 20px;
}

.editor-column, .settings-column {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.editor-toggle {
    text-align: right;
    margin-top: 4px;
}

/* ── Quill dark theme overrides ── */
.quill-container {
    background: var(--bg-input);
    border-radius: var(--radius);
}
.ql-toolbar.ql-snow {
    background: var(--bg-card) !important;
    border-color: var(--border) !important;
    border-radius: var(--radius) var(--radius) 0 0;
}
.ql-container.ql-snow {
    border-color: var(--border) !important;
    border-radius: 0 0 var(--radius) var(--radius);
    min-height: 150px;
}
.ql-editor {
    color: var(--text) !important;
    background: var(--bg-input) !important;
    min-height: 150px;
    font-size: 0.95rem;
}
.ql-editor.ql-blank::before {
    color: var(--text-muted) !important;
}
.ql-snow .ql-stroke { stroke: var(--text-muted) !important; }
.ql-snow .ql-fill { fill: var(--text-muted) !important; }
.ql-snow .ql-picker-label { color: var(--text-muted) !important; }
.ql-snow .ql-picker-options {
    background: var(--bg-card) !important;
    border-color: var(--border) !important;
}
.ql-toolbar button:hover .ql-stroke,
.ql-toolbar button.ql-active .ql-stroke { stroke: var(--primary) !important; }
.ql-toolbar button:hover .ql-fill,
.ql-toolbar button.ql-active .ql-fill { fill: var(--primary) !important; }

/* ── Telegram Preview ── */
.telegram-preview {
    background: #0e1621;
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 12px;
}
.tg-preview-header {
    font-size: 0.8rem;
    color: #67768a;
    margin-bottom: 8px;
    text-align: center;
}
.tg-preview-bubble {
    background: #182533;
    border-radius: 12px;
    padding: 10px 14px;
    max-height: 200px;
    overflow-y: auto;
}
.tg-preview-text {
    color: #e1e3e6;
    font-size: 0.9rem;
    line-height: 1.5;
    word-wrap: break-word;
}

/* ── Media Upload Zone ── */
.media-upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
    transition: all var(--transition-fast);
}
.media-upload-zone:hover, .media-upload-zone.drag-over {
    border-color: var(--primary);
    background: var(--primary-light);
}
.media-upload-text {
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
}
.media-preview {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
}
.media-preview img {
    max-height: 60px;
    max-width: 80px;
    border-radius: 4px;
    object-fit: cover;
}

/* ── Channel Selector ── */
.channel-selector {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 150px;
    overflow-y: auto;
    padding: 8px;
    background: var(--bg-input);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}
.channel-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.9rem;
}
.channel-checkbox input[type="checkbox"] {
    accent-color: var(--primary);
}

/* ── Color Picker ── */
.form-input-color {
    padding: 4px;
    height: 36px;
    cursor: pointer;
}

/* ── Recurring Section ── */
.recurring-section {
    margin-top: 24px;
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}
.recurring-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
}
.recurring-header h3 {
    font-size: 1rem;
    font-weight: 600;
}
.recurring-list {
    padding: 0 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.recurring-card {
    background: var(--bg);
    border-radius: var(--radius);
    padding: 10px 14px;
    border: 1px solid var(--border);
}
.recurring-inactive {
    opacity: 0.5;
}
.recurring-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}
.recurring-card-actions {
    display: flex;
    gap: 6px;
}
.recurring-card-info {
    display: flex;
    gap: 12px;
    font-size: 0.85rem;
    color: var(--text-muted);
    flex-wrap: wrap;
}

/* ── Weekday Selector ── */
.weekday-selector {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}
.weekday-selector label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.9rem;
    cursor: pointer;
}
.weekday-selector input {
    accent-color: var(--primary);
}

/* ── Post View Modal ── */
.post-view-status {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    font-size: 0.9rem;
    color: var(--text-muted);
}
.post-view-text {
    background: var(--bg-input);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 12px;
    line-height: 1.6;
    max-height: 300px;
    overflow-y: auto;
}
.post-view-media {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}
.post-view-error {
    background: var(--danger-light);
    color: var(--danger);
    border-radius: var(--radius);
    padding: 8px 12px;
    font-size: 0.85rem;
}

/* Badges for scheduled post statuses */
.badge-draft { background: var(--text-muted); color: #fff; }
.badge-scheduled { background: var(--info); color: #fff; }
.badge-pending_review { background: var(--warning); color: #000; }
.badge-approved { background: var(--success); color: #fff; }
.badge-publishing { background: var(--primary); color: #fff; }
.badge-published { background: var(--success); color: #fff; }
.badge-publish_error { background: var(--danger); color: #fff; }
.badge-cancelled { background: #555; color: #fff; }

/* ── Form small input ── */
.form-input-sm {
    padding: 4px 10px;
    font-size: 0.85rem;
    height: 32px;
}

/* ============================================
   AI-генерация
   ============================================ */

/* ── Секция AI в редакторе ── */
.ai-generate-section {
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-top: 12px;
    overflow: hidden;
}

.ai-generate-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: var(--primary-light);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
}

.ai-generate-header:hover {
    background: rgba(91, 110, 245, 0.15);
}

.toggle-icon {
    font-size: 0.8rem;
    color: var(--text-muted);
}

#aiGenerateBody {
    padding: 12px 14px;
}

/* ── Кнопки генерации ── */
.ai-generate-buttons {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.ai-generate-btn {
    background: linear-gradient(135deg, #5b6ef5 0%, #8b5cf6 100%);
    color: #fff;
    border: none;
    font-weight: 600;
    font-size: 0.85rem;
    padding: 8px 16px;
    flex: 1;
}

.ai-generate-btn:hover {
    background: linear-gradient(135deg, #4a5de4 0%, #7a4be5 100%);
    color: #fff;
}

.ai-generate-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ai-generate-btn-img {
    background: linear-gradient(135deg, #f59e0b 0%, #ef4444 100%);
}

.ai-generate-btn-img:hover {
    background: linear-gradient(135deg, #e48e0a 0%, #dc2626 100%);
}

/* ── Загрузка ── */
.ai-loading {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 0;
    color: var(--primary);
    font-size: 0.9rem;
}

.spinner-sm {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top: 2px solid var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ── Мета результата ── */
.ai-result-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding: 8px 0;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.ai-result-meta span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

/* ── Карточки шаблонов промптов ── */
.prompt-template-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 8px;
}

.prompt-template-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.prompt-template-icon {
    font-size: 1.3rem;
}

.prompt-template-info {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.prompt-template-actions {
    display: flex;
    gap: 6px;
}

/* ── Бейджи категорий ── */
.category-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 500;
    background: var(--border);
    color: var(--text-muted);
}

.category-news { background: #1d4ed8; color: #fff; }
.category-promo { background: #d97706; color: #fff; }
.category-educational { background: #059669; color: #fff; }
.category-entertainment { background: #dc2626; color: #fff; }
.category-general { background: #6b7280; color: #fff; }

/* ══════════════════════════════════════════
   Sources Tabs (RSS / Web)
   ══════════════════════════════════════════ */

.source-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 0;
    border-bottom: 2px solid var(--border);
    padding-bottom: 0;
}

.source-tab {
    padding: 10px 20px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.95rem;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    transition: all var(--transition-fast);
    border-radius: 6px 6px 0 0;
    font-family: inherit;
}

.source-tab:hover {
    background: var(--bg-card);
    color: var(--text);
}

.source-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: var(--bg-card);
    font-weight: 600;
}

.tab-count {
    display: inline-block;
    background: var(--border);
    color: var(--text-muted);
    font-size: 0.75rem;
    padding: 1px 7px;
    border-radius: 10px;
    margin-left: 4px;
}

.source-tab.active .tab-count {
    background: var(--primary);
    color: #fff;
}

.source-panel {
    display: none;
    padding-top: 16px;
}

.source-panel.active {
    display: block;
}

.panel-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.url-cell {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.url-cell a {
    color: var(--primary);
    text-decoration: none;
}

.url-cell a:hover {
    text-decoration: underline;
}

.fetch-error {
    color: #ef4444;
    font-size: 0.8rem;
    margin-top: 4px;
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.text-muted {
    color: var(--text-muted);
    font-style: italic;
}

.btn-info {
    background: #3b82f6;
    color: #fff;
    border: none;
}

.btn-info:hover {
    background: #2563eb;
}

/* ══════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════ */

@media (max-width: 768px) {
    .hamburger-btn {
        display: flex;
    }

    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    main.with-sidebar {
        margin-left: 0;
        padding-top: 56px;
    }

    .container {
        padding: 16px;
    }

    .review-grid { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
    #stats-container { grid-template-columns: repeat(2, 1fr); }
    .presets-grid { grid-template-columns: repeat(2, 1fr); }
    .preset-selector { grid-template-columns: repeat(3, 1fr); }
    .analytics-charts { grid-template-columns: 1fr; }
    .analytics-summary { grid-template-columns: repeat(2, 1fr); }
    .dashboard-chart-row { grid-template-columns: 1fr; }
    .analytics-mini-cards { grid-template-columns: repeat(2, 1fr); }
    .broadcast-stats { gap: 0.5rem; }
    .funnel-step { flex-wrap: wrap; }
    .page-header { flex-direction: column; align-items: flex-start; }
    .calendar-nav { margin-left: 0; margin-top: 8px; }
    .calendar-title { min-width: auto; font-size: 0.95rem; }
    .cal-day { min-height: 70px; padding: 3px; }
    .cal-event { font-size: 0.7rem; }
    .post-editor-layout { grid-template-columns: 1fr; }
    .ai-generate-buttons { flex-direction: column; }
    .source-tabs { flex-wrap: wrap; }
    .source-tab { font-size: 0.85rem; padding: 8px 12px; }
    .cards-grid { grid-template-columns: 1fr; }
    .health-grid { grid-template-columns: repeat(2, 1fr); }
    .metrics-summary { grid-template-columns: repeat(2, 1fr); }
    .alert-rule-card { flex-direction: column; gap: 8px; }
    .alert-rule-actions { justify-content: flex-start; }
}

/* ═══════════════════════════════════════════════════ */
/* Мониторинг                                         */
/* ═══════════════════════════════════════════════════ */

.monitoring-section {
    margin-bottom: 32px;
}
.monitoring-section h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text);
}
.monitoring-section .section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.monitoring-section .section-header h2 {
    margin-bottom: 0;
}

.monitoring-countdown {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-right: 8px;
}

/* Health Grid */
.health-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
}
.health-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    transition: var(--transition-fast);
}
.health-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-sm);
}
.health-card.loading {
    opacity: 0.5;
}
.health-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.health-card-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text);
}
.health-card-detail {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Status Dot */
.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--text-muted);
}
.status-dot.status-ok {
    background: #22c55e;
    box-shadow: 0 0 6px rgba(34, 197, 94, 0.4);
}
.status-dot.status-warning {
    background: #f59e0b;
    box-shadow: 0 0 6px rgba(245, 158, 11, 0.4);
}
.status-dot.status-error {
    background: #ef4444;
    box-shadow: 0 0 6px rgba(239, 68, 68, 0.4);
}

/* Pipeline Metrics Summary */
.metrics-summary {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
}
.metric-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px 16px;
    text-align: center;
    transition: var(--transition-fast);
}
.metric-card:hover {
    border-color: var(--primary);
}
.metric-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--primary);
    line-height: 1.2;
}
.metric-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Chart Container */
.chart-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
}
.chart-container h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text);
}

/* Alert Rules */
.alert-rules-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.alert-rule-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    transition: var(--transition-fast);
}
.alert-rule-card:hover {
    border-color: var(--primary);
}
.alert-rule-card.rule-inactive {
    opacity: 0.5;
}
.alert-rule-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text);
}
.alert-rule-meta {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 2px;
}
.alert-rule-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

/* Alert History */
.alert-history {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.alert-event {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-left: 4px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 12px 16px;
}
.alert-event.alert-severity-info {
    border-left-color: #3b82f6;
}
.alert-event.alert-severity-warning {
    border-left-color: #f59e0b;
}
.alert-event.alert-severity-critical {
    border-left-color: #ef4444;
}
.alert-event-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
    flex-wrap: wrap;
}
.alert-event-severity {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 4px;
    color: #fff;
}
.alert-severity-info .alert-event-severity { background: #3b82f6; }
.alert-severity-warning .alert-event-severity { background: #f59e0b; }
.alert-severity-critical .alert-event-severity { background: #ef4444; }
.alert-event-rule {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text);
}
.alert-event-time {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-left: auto;
}
.alert-event-message {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.alert-event-actions {
    display: flex;
    gap: 6px;
}

/* Text color helpers */
.text-success { color: #22c55e; }
.text-warning { color: #f59e0b; }
.text-error { color: #ef4444; }

/* Badge */
.badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    text-transform: uppercase;
}
.badge-success {
    background: rgba(34, 197, 94, 0.15);
    color: #22c55e;
}
.badge-warning {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
}
.badge-error {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

/* ============================================
   A/B Testing
   ============================================ */

.ab-tests-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
    margin-top: 16px;
}

.ab-test-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    transition: border-color 0.2s;
}
.ab-test-card:hover {
    border-color: var(--primary);
}
.ab-test-card[data-status="active"] {
    border-left: 3px solid var(--success);
}
.ab-test-card[data-status="paused"] {
    border-left: 3px solid var(--warning);
}
.ab-test-card[data-status="completed"] {
    border-left: 3px solid var(--text-muted);
    opacity: 0.8;
}

.ab-test-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.ab-test-header h3 {
    margin: 0;
    font-size: 1.05em;
}
.ab-test-info p {
    margin: 4px 0;
    font-size: 0.88em;
    color: var(--text-secondary);
}
.ab-test-configs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 10px 0;
}
.ab-config-badge {
    font-size: 0.78em;
    padding: 3px 8px;
    border-radius: 4px;
    background: var(--primary-light);
    color: var(--primary);
}
.ab-test-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

/* Variant Groups */
.ab-variant-group {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 16px;
}
.ab-variant-group.ab-decided {
    opacity: 0.7;
}
.ab-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.ab-group-id {
    font-size: 0.82em;
    color: var(--text-muted);
    font-family: monospace;
}

.ab-variants-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.ab-variant-card {
    flex: 1;
    min-width: 280px;
    background: var(--bg-input);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.ab-variant-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-sm);
}
.ab-variant-card.ab-winner {
    border-color: var(--success);
    background: var(--success-light);
}
.ab-variant-card.ab-loser {
    border-color: var(--danger);
    opacity: 0.6;
}

.ab-variant-label {
    font-weight: 700;
    font-size: 1.1em;
    margin-bottom: 8px;
    color: var(--primary);
}
.ab-variant-meta {
    font-size: 0.8em;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.ab-variant-text {
    font-size: 0.88em;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg-card);
    border-radius: 6px;
    padding: 12px;
    margin: 10px 0;
    max-height: 200px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

.ab-pick-btn {
    width: 100%;
    margin-top: 8px;
}

.ab-original-toggle {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}
.ab-original-toggle a {
    font-size: 0.85em;
    color: var(--primary);
    text-decoration: none;
}
.ab-original-toggle a:hover {
    text-decoration: underline;
}
.ab-original-text {
    margin-top: 8px;
    padding: 12px;
    background: var(--bg-input);
    border-radius: 6px;
    font-size: 0.85em;
    color: var(--text-muted);
    white-space: pre-wrap;
    word-break: break-word;
}

/* Results */
.ab-results-summary {
    display: flex;
    gap: 24px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.ab-results-stat {
    padding: 12px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.92em;
}
.ab-results-table {
    overflow-x: auto;
}
.ab-results-bar-container {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 120px;
}
.ab-results-bar {
    height: 8px;
    background: var(--primary);
    border-radius: 4px;
    min-width: 2px;
    transition: width 0.3s;
}
.ab-results-bar-container span {
    font-size: 0.85em;
    white-space: nowrap;
}

/* Create modal variant configs */
.ab-variant-config {
    border-left: 3px solid var(--primary);
    padding-left: 12px;
    margin-bottom: 12px;
}
.ab-variant-selector {
    display: flex;
    gap: 8px;
}

/* ── Media Gallery ── */
.media-stats {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.stat-chip {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.stat-chip-label {
    color: var(--text-muted);
    font-size: 0.85rem;
}
.stat-chip-value {
    font-weight: 600;
    color: var(--text);
}
.media-filter {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.filter-chip {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 6px 16px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}
.filter-chip:hover {
    border-color: var(--primary);
    color: var(--text);
}
.filter-chip.active {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}
.media-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
}
.media-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s;
}
.media-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}
.media-card-thumb {
    width: 100%;
    aspect-ratio: 1;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-input);
}
.media-card-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.media-card-video,
.media-card-doc {
    color: var(--text-muted);
}
.media-card-info {
    padding: 10px 12px;
}
.media-card-name {
    font-size: 0.8rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.media-card-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}
.media-preview-modal {
    max-width: 700px;
}
.media-preview-container {
    display: flex;
    justify-content: center;
    margin-bottom: 16px;
}
.media-preview-info {
    display: grid;
    gap: 8px;
}
.info-row {
    display: flex;
    gap: 8px;
    font-size: 0.85rem;
}
.info-label {
    color: var(--text-muted);
    min-width: 80px;
}
.info-path {
    font-family: monospace;
    font-size: 0.8rem;
    color: var(--text-secondary);
    word-break: break-all;
}
.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 60px 0;
    color: var(--text-muted);
    grid-column: 1 / -1;
}
.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 60px 0;
    color: var(--text-muted);
    text-align: center;
}
.empty-state h3 {
    color: var(--text-secondary);
    margin: 0;
}
.empty-state p {
    color: var(--text-muted);
    max-width: 400px;
}

/* ═══════════════════════════════════════════════════ */
/* UI Polish — Global Enhancements                    */
/* ═══════════════════════════════════════════════════ */

/* Smooth scrolling */
html { scroll-behavior: smooth; }

/* Focus-visible for accessibility */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: var(--radius);
}
button:focus:not(:focus-visible),
a:focus:not(:focus-visible),
input:focus:not(:focus-visible),
select:focus:not(:focus-visible),
textarea:focus:not(:focus-visible) {
    outline: none;
}

/* Custom scrollbar (dark theme) */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Notification animation */
.notification {
    animation: slideInRight 0.3s ease-out;
}
@keyframes slideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Selection color */
::selection {
    background: var(--primary);
    color: #fff;
}

/* Tablet breakpoint — sidebar overlay */
@media (max-width: 1024px) and (min-width: 769px) {
    :root { --sidebar-width: 220px; }
    .nav-list li a { font-size: 12.5px; padding: 8px 16px; }
    .nav-group-label { font-size: 9px; padding: 10px 16px 5px; }
    .sidebar-header { padding: 16px 16px 12px; }
}

/* Small mobile */
@media (max-width: 480px) {
    #stats-container { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .stat-card { padding: 14px 10px; }
    .stat-value { font-size: 24px; }
    h1 { font-size: 18px; }
    .btn-sm { padding: 3px 8px; font-size: 11px; }
}

/* ================================================================
   Plan badges
   ================================================================ */
.badge-plan-start { background: #3b82f6; color: #fff; font-size: 10px; padding: 2px 8px; border-radius: 10px; }
.badge-plan-advanced { background: #8b5cf6; color: #fff; font-size: 10px; padding: 2px 8px; border-radius: 10px; }
.badge-plan-pro { background: #f59e0b; color: #1a1a2e; font-size: 10px; padding: 2px 8px; border-radius: 10px; }
.badge-plan-pro_plus { background: linear-gradient(135deg, #f59e0b, #ef4444); color: #fff; font-size: 10px; padding: 2px 8px; border-radius: 10px; }

/* ================================================================
   Profile page
   ================================================================ */
.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 768px) { .profile-grid { grid-template-columns: 1fr; } }
.profile-info { display: flex; flex-direction: column; gap: 12px; }
.info-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.info-label { color: var(--text-muted); font-size: 13px; }
.info-value { font-weight: 500; }
.limit-bar { width: 100%; height: 8px; background: var(--bg-dark); border-radius: 4px; overflow: hidden; }
.limit-bar-fill { height: 100%; background: var(--accent); border-radius: 4px; transition: width 0.3s; }
.limit-text { font-size: 12px; color: var(--text-muted); margin-top: 4px; text-align: right; }

/* ================================================================
   Users page
   ================================================================ */
.actions-cell { white-space: nowrap; }
.actions-cell .btn { margin-right: 4px; }
.btn-xs { padding: 2px 8px; font-size: 11px; border-radius: 4px; }
.btn-warning { background: #f59e0b; color: #1a1a2e; border: none; cursor: pointer; }
.btn-warning:hover { background: #d97706; }

/* ================================================================
   Bots page
   ================================================================ */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.card-header { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.card-icon { font-size: 20px; }
.card-title { font-weight: 600; flex: 1; }
.card-body { padding: 12px 16px; }
.card-meta { display: flex; gap: 16px; font-size: 12px; color: var(--text-muted); }
.card-actions { padding: 8px 16px; display: flex; gap: 8px; justify-content: flex-end; border-top: 1px solid var(--border); }

/* ================================================================
   Top Bar (search + bell)
   ================================================================ */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}
.topbar-search-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 16px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.88rem;
    transition: border-color var(--transition-fast), background var(--transition-fast);
    min-width: 220px;
}
.topbar-search-btn:hover {
    border-color: var(--primary);
    background: var(--bg-hover);
}
.topbar-search-btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}
.topbar-search-btn span { flex: 1; text-align: left; }
.topbar-search-btn kbd {
    font-size: 0.72rem;
    padding: 2px 6px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-muted);
    font-family: inherit;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ================================================================
   Notification Bell
   ================================================================ */
.notif-bell-wrap {
    position: relative;
}
.notif-bell-btn {
    background: none;
    border: 1px solid transparent;
    border-radius: var(--radius);
    padding: 8px;
    cursor: pointer;
    color: var(--text-muted);
    transition: all var(--transition-fast);
    position: relative;
}
.notif-bell-btn:hover {
    color: var(--text);
    background: var(--bg-hover);
    border-color: var(--border);
}
.notif-bell-btn svg {
    width: 20px;
    height: 20px;
}
.notif-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--danger);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    border-radius: 9px;
    padding: 0 4px;
    line-height: 1;
}

/* Notification Dropdown */
.notif-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 360px;
    max-height: 420px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 200;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.notif-dropdown-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 0.92rem;
}
.notif-mark-all {
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    font-size: 0.8rem;
    padding: 0;
}
.notif-mark-all:hover { text-decoration: underline; }

.notif-dropdown-list {
    overflow-y: auto;
    max-height: 360px;
    flex: 1;
}
.notif-empty {
    padding: 40px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.88rem;
}

.notif-item {
    display: flex;
    gap: 10px;
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background var(--transition-fast);
}
.notif-item:hover { background: var(--bg-hover); }
.notif-item:last-child { border-bottom: none; }
.notif-item-read { opacity: 0.6; }

.notif-item-icon {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.1rem;
}
.notif-item-body { flex: 1; min-width: 0; }
.notif-item-title {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text);
    line-height: 1.3;
}
.notif-item-msg {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.notif-item-time {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Severity left-border */
.notif-sev-success { border-left: 3px solid var(--success); }
.notif-sev-warning { border-left: 3px solid var(--warning); }
.notif-sev-error   { border-left: 3px solid var(--danger); }
.notif-sev-info    { border-left: 3px solid var(--info); }

/* ================================================================
   Global Search Modal (Ctrl+K)
   ================================================================ */
.search-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 12vh;
}
.search-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
}
.search-modal-content {
    position: relative;
    width: 580px;
    max-width: 92vw;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}
.search-modal-input-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}
.search-modal-input-wrap svg {
    width: 20px;
    height: 20px;
    color: var(--text-muted);
    flex-shrink: 0;
}
.search-modal-input-wrap input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 1rem;
}
.search-modal-input-wrap input::placeholder { color: var(--text-muted); }
.search-modal-input-wrap kbd {
    font-size: 0.72rem;
    padding: 2px 6px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-muted);
    font-family: inherit;
}

.search-modal-results {
    max-height: 400px;
    overflow-y: auto;
    padding: 8px 0;
}
.search-modal-hint {
    padding: 32px 18px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.88rem;
}

.search-group { margin-bottom: 4px; }
.search-group-label {
    padding: 8px 18px 4px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}
.search-result-item {
    display: block;
    padding: 10px 18px;
    text-decoration: none;
    color: var(--text);
    transition: background var(--transition-fast);
    cursor: pointer;
}
.search-result-item:hover {
    background: var(--bg-hover);
}
.search-result-title {
    font-size: 0.88rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.search-result-sub {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ================================================================
   Sidebar Search Trigger
   ================================================================ */
.sidebar-search-trigger {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 8px 16px;
    padding: 9px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.85rem;
    transition: border-color var(--transition-fast), color var(--transition-fast);
}
.sidebar-search-trigger:hover {
    border-color: var(--primary);
    color: var(--text);
}
.sidebar-search-trigger svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}
.sidebar-search-trigger span { flex: 1; }
.sidebar-search-trigger kbd {
    font-size: 0.68rem;
    padding: 1px 5px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 3px;
    font-family: inherit;
}

/* ================================================================
   Dashboard Suggestions
   ================================================================ */
.suggestions-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 20px;
    margin-bottom: 20px;
}
.suggestions-title {
    font-size: 0.92rem;
    font-weight: 600;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.suggestion-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.suggestion-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--bg-input);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    font-size: 0.85rem;
    transition: background var(--transition-fast), transform var(--transition-fast);
}
.suggestion-item:hover {
    background: var(--bg-hover);
    transform: translateX(4px);
}
.suggestion-icon {
    font-size: 1.2rem;
    width: 28px;
    text-align: center;
    flex-shrink: 0;
}
.suggestion-text { flex: 1; }
.suggestion-arrow {
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* ================================================================
   Clickable Stat Cards (Dashboard)
   ================================================================ */
a.stat-card-link {
    text-decoration: none;
    color: inherit;
    display: block;
    border-radius: var(--radius-lg);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
}
a.stat-card-link:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}
a.stat-card-link:hover .stat-card {
    border-color: var(--primary);
}

/* ================================================================
   Provider Health Pills
   ================================================================ */
.provider-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}
.provider-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 0.78rem;
    color: var(--text-secondary);
}
.provider-pill-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.provider-pill-dot.green  { background: var(--success); }
.provider-pill-dot.yellow { background: var(--warning); }
.provider-pill-dot.red    { background: var(--danger); }
.provider-pill-dot.gray   { background: var(--text-muted); }
.provider-pill-rate {
    font-weight: 600;
    font-size: 0.72rem;
}

/* ================================================================
   Mobile responsive for topbar + notifications
   ================================================================ */
@media (max-width: 768px) {
    .topbar {
        padding: 8px 12px;
    }
    .topbar-search-btn {
        min-width: 0;
        flex: 1;
    }
    .topbar-search-btn span { display: none; }
    .topbar-search-btn kbd { display: none; }
    .notif-dropdown {
        width: calc(100vw - 24px);
        right: -8px;
    }
    .search-modal-content { width: 96vw; }
    .sidebar-search-trigger kbd { display: none; }
}

/* ================================================================
   System Logs Viewer
   ================================================================ */
.logs-filters {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: 20px;
}
.logs-filters .filter-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: flex-end;
}
.logs-filters .filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 140px;
}
.logs-filters .filter-group label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.logs-filters .filter-group select,
.logs-filters .filter-group input {
    padding: 8px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.85rem;
}
.logs-filters .filter-group-search {
    flex: 1;
    min-width: 200px;
}
.logs-filters .filter-group-search input {
    width: 100%;
}
.logs-filters .filter-group-btn {
    min-width: auto;
}
.logs-summary {
    margin-top: 10px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Logs table */
.logs-table-wrap {
    overflow-x: auto;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}
.logs-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.logs-table thead th {
    background: var(--bg-input);
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    font-size: 0.78rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 1;
}
.logs-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background var(--transition-fast);
}
.logs-table tbody tr:last-child { border-bottom: none; }
.logs-table tbody tr:hover { background: var(--bg-hover); }
.logs-table td {
    padding: 8px 12px;
    vertical-align: top;
}

/* Column widths */
.logs-col-time { width: 150px; white-space: nowrap; }
.logs-col-level { width: 90px; }
.logs-col-component { width: 120px; }
.logs-col-message { min-width: 200px; }
.logs-col-actions { width: 40px; text-align: center; }

/* Time cell */
.log-time {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* Level badges */
.log-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.log-level-critical {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
}
.log-level-error {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.2);
}
.log-level-warning {
    background: rgba(245, 158, 11, 0.15);
    color: #fbbf24;
    border: 1px solid rgba(245, 158, 11, 0.2);
}
.log-level-info {
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
    border: 1px solid rgba(59, 130, 246, 0.2);
}
.log-level-debug {
    background: rgba(107, 114, 128, 0.15);
    color: #9ca3af;
    border: 1px solid rgba(107, 114, 128, 0.2);
}

/* Row tinting for severity */
.log-row-critical { background: rgba(239, 68, 68, 0.06); }
.log-row-error { background: rgba(239, 68, 68, 0.03); }
.log-row-critical:hover { background: rgba(239, 68, 68, 0.1) !important; }
.log-row-error:hover { background: rgba(239, 68, 68, 0.06) !important; }

/* Component code */
.log-component {
    font-size: 0.78rem;
    padding: 2px 6px;
    background: var(--bg-input);
    border-radius: 4px;
    color: var(--primary);
}

/* Message */
.log-message {
    word-break: break-word;
    line-height: 1.4;
}

/* Detail modal */
.log-detail-row {
    margin-bottom: 10px;
    font-size: 0.88rem;
}
.log-detail-message {
    background: var(--bg-input);
    padding: 12px;
    border-radius: var(--radius);
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.82rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    margin-bottom: 12px;
}
.log-detail-json {
    background: var(--bg-input);
    padding: 12px;
    border-radius: var(--radius);
    font-size: 0.8rem;
    line-height: 1.4;
    overflow-x: auto;
    max-height: 400px;
    overflow-y: auto;
    color: var(--text-secondary);
}

/* Pagination */
.logs-pagination {
    margin-top: 16px;
    display: flex;
    justify-content: center;
}
.pagination {
    display: flex;
    gap: 4px;
    align-items: center;
}
.pagination-dots {
    padding: 0 4px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Auto-refresh active button */
.btn-active {
    background: var(--primary) !important;
    color: #fff !important;
    border-color: var(--primary) !important;
}

/* Btn icon (small icon-only button) */
.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    font-size: 0.85rem;
    opacity: 0.6;
    transition: opacity var(--transition-fast);
}
.btn-icon:hover { opacity: 1; }

/* Modal sizes */
.modal-lg { max-width: 700px; }
.modal-sm { max-width: 400px; }

@media (max-width: 768px) {
    .logs-filters .filter-row {
        flex-direction: column;
    }
    .logs-filters .filter-group {
        min-width: 100%;
    }
    .logs-col-time { width: auto; }
    .logs-col-component { display: none; }
    .logs-col-actions { display: none; }
}

/* ================================================================
   Collapsible Sidebar
   ================================================================ */
.sidebar-collapse-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius);
    transition: color var(--transition-fast), background var(--transition-fast);
    flex-shrink: 0;
}
.sidebar-collapse-btn:hover {
    color: var(--text);
    background: var(--bg-hover);
}
.sidebar-collapse-btn svg { width: 18px; height: 18px; }

@media (min-width: 769px) {
    .sidebar-collapse-btn { display: flex; }
    .sidebar-header { display: flex; align-items: center; justify-content: space-between; }

    /* Collapsed state */
    .sidebar.collapsed {
        width: 60px;
        min-width: 60px;
    }
    .sidebar.collapsed .sidebar-logo-texts,
    .sidebar.collapsed .nav-group-label,
    .sidebar.collapsed .sidebar-search-trigger span,
    .sidebar.collapsed .sidebar-search-trigger kbd,
    .sidebar.collapsed .theme-label,
    .sidebar.collapsed .sidebar-user-info,
    .sidebar.collapsed .sidebar-logout,
    .sidebar.collapsed .sidebar-version {
        display: none;
    }
    .sidebar.collapsed .sidebar-logo {
        justify-content: center;
    }
    .sidebar.collapsed .nav-list a {
        justify-content: center;
        padding: 10px;
    }
    .sidebar.collapsed .nav-list a svg {
        margin-right: 0;
    }
    .sidebar.collapsed .sidebar-search-trigger {
        justify-content: center;
        padding: 10px;
    }
    .sidebar.collapsed .sidebar-theme-toggle button {
        justify-content: center;
    }
    .sidebar.collapsed .sidebar-user {
        justify-content: center;
    }
    .sidebar.collapsed .sidebar-user-avatar {
        margin-right: 0;
    }
    .sidebar.collapsed .sidebar-collapse-btn svg {
        transform: rotate(180deg);
    }
    .sidebar.collapsed .sidebar-footer {
        padding: 8px;
    }

    /* Main content shifts */
    .sidebar-is-collapsed main.with-sidebar {
        margin-left: 60px;
    }
}

/* ================================================================
   Breadcrumbs
   ================================================================ */
.breadcrumbs {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 0;
    margin-bottom: 8px;
    font-size: 0.82rem;
    color: var(--text-muted);
}
.breadcrumbs a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color var(--transition-fast);
}
.breadcrumbs a:hover { color: var(--primary); }
.breadcrumbs .bc-sep { color: var(--text-muted); opacity: 0.5; }
.breadcrumbs .bc-current { color: var(--text); font-weight: 500; }

/* ================================================================
   Help Modal
   ================================================================ */
.help-modal {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
}
.help-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(3px);
}
.help-modal-content {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 420px;
    max-width: 95vw;
    box-shadow: var(--shadow-lg);
}
.help-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px 12px;
    border-bottom: 1px solid var(--border);
}
.help-modal-header h3 { margin: 0; font-size: 1rem; }
.help-modal-body { padding: 16px 20px; }
.help-section {
    margin-bottom: 16px;
}
.help-section:last-child { margin-bottom: 0; }
.help-section h4 {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin: 0 0 8px;
}
.help-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
    font-size: 0.85rem;
}
.help-row kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 22px;
    padding: 0 6px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.72rem;
    font-family: monospace;
    color: var(--text-secondary);
}
.help-row span { margin-left: auto; color: var(--text-secondary); }
.help-modal-footer {
    padding: 10px 20px;
    border-top: 1px solid var(--border);
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
}

/* Topbar help button */
.topbar-help-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color var(--transition-fast), border-color var(--transition-fast);
}
.topbar-help-btn:hover {
    color: var(--primary);
    border-color: var(--primary);
}

/* ================================================================
   API Keys
   ================================================================ */
.api-key-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 8px;
}
.api-key-row:last-child { margin-bottom: 0; }
.api-key-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}
.api-key-name {
    font-weight: 600;
    font-size: 0.9rem;
}
.api-key-prefix {
    font-family: monospace;
    font-size: 0.8rem;
    color: var(--text-secondary);
    background: rgba(91,110,245,0.08);
    padding: 1px 6px;
    border-radius: 4px;
    display: inline-block;
    width: fit-content;
}
.api-key-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.badge-active {
    background: rgba(34,197,94,0.15);
    color: #22c55e;
    font-size: 0.72rem;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}
.badge-inactive {
    background: rgba(156,163,175,0.15);
    color: #9ca3af;
    font-size: 0.72rem;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}

/* ================================================================
   Toggle Switch
   ================================================================ */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 42px;
    height: 24px;
    flex-shrink: 0;
}
.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--border);
    border-radius: 24px;
    transition: background 0.2s;
}
.toggle-slider::before {
    content: "";
    position: absolute;
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
}
.toggle-switch input:checked + .toggle-slider {
    background: var(--primary);
}
.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(18px);
}

/* ================================================================
   Onboarding Wizard
   ================================================================ */
.onboarding-overlay {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: center;
}
.onboarding-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(6px);
}
.onboarding-wizard {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    width: 480px;
    max-width: 95vw;
    padding: 40px 36px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    text-align: center;
}
.onboarding-emoji {
    font-size: 3rem;
    margin-bottom: 16px;
}
.onboarding-wizard h2 {
    margin: 0 0 8px;
    font-size: 1.4rem;
}
.onboarding-wizard p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin: 0 0 24px;
    line-height: 1.5;
}
.onboarding-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 20px;
}
.onboarding-progress {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin-bottom: 24px;
    overflow: hidden;
}
.onboarding-progress-bar {
    height: 100%;
    background: var(--primary);
    border-radius: 2px;
    transition: width 0.4s ease;
    width: 0%;
}
.onboarding-step-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
}
.onboarding-step-content h3 {
    font-size: 1.1rem;
    margin: 0 0 8px;
}
.onboarding-step-content p {
    margin: 0 0 20px;
}
.onboarding-status {
    padding: 16px;
    border-radius: 10px;
    margin-bottom: 8px;
}
.onboarding-status.done {
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.2);
    color: #22c55e;
    font-weight: 600;
    font-size: 1rem;
}
.onboarding-status.pending {
    background: rgba(91, 110, 245, 0.06);
    border: 1px solid rgba(91, 110, 245, 0.15);
}

/* ================================================================
   Mobile Responsive Polish (Phase 6)
   ================================================================ */

/* ── Tablet (768px) ── */
@media (max-width: 768px) {
    /* Tables → horizontal scroll */
    .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    table { min-width: 600px; }

    /* Modal sizing */
    .modal-box, .help-modal-content {
        width: 95vw !important;
        max-width: 95vw !important;
        margin: 10px;
    }

    /* Section headers */
    .section-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 10px;
    }

    /* Topbar compact */
    .topbar-actions { gap: 6px; }
    .topbar-search { display: none; }

    /* Queue cards */
    .post-card { padding: 12px; }
    .post-card-actions { flex-wrap: wrap; gap: 4px; }

    /* Breadcrumbs */
    .breadcrumbs { font-size: 0.78rem; padding: 6px 16px; }

    /* Health Score row on dashboard */
    .dash-health-row { grid-template-columns: 1fr; }
    .health-score-widget { min-width: auto; }
    .quick-actions-grid { grid-template-columns: repeat(2, 1fr); }

    /* Top Sources table */
    .ts-header, .ts-row { grid-template-columns: 1fr 60px 80px 70px; font-size: 0.78rem; }
    .ts-rank { min-width: 16px; }

    /* Logs viewer */
    .logs-table { overflow-x: auto; }

    /* Settings cards */
    .settings-grid { grid-template-columns: 1fr; }
}

/* ── Small Mobile (480px) ── */
@media (max-width: 480px) {
    .container { padding: 12px; }

    /* Stat cards: stack full width */
    #stats-container { grid-template-columns: 1fr 1fr; gap: 6px; }
    .stat-card { padding: 10px 8px; }
    .stat-value { font-size: 20px; }
    .stat-label { font-size: 0.72rem; }
    .stat-sub { font-size: 0.65rem; }
    .stat-icon svg { width: 18px; height: 18px; }

    /* Quick actions: single col */
    .quick-actions-grid { grid-template-columns: 1fr; }
    .quick-action-card { padding: 8px 12px; }

    /* Health score widget */
    .health-score-widget { flex-direction: column; text-align: center; padding: 16px; }
    .health-score-ring { width: 80px; height: 80px; }
    .health-score-value { font-size: 1.4rem; }
    .health-score-details { justify-content: center; }

    /* Top sources: hide some columns */
    .ts-header, .ts-row { grid-template-columns: 1fr 50px 60px; }
    .ts-col-num:nth-child(4) { display: none; }  /* hide conversion on tiny */

    /* Pipeline row: stack */
    .dash-row { grid-template-columns: 1fr; gap: 12px; }
    .dash-card { padding: 14px; }

    /* Buttons */
    .btn { padding: 7px 12px; font-size: 0.82rem; }
    .btn-sm { padding: 4px 8px; font-size: 0.75rem; }

    /* Forms */
    .form-input, .form-textarea, .form-select { font-size: 16px; } /* Prevent zoom on iOS */

    /* Modals */
    .modal-box, .help-modal-content {
        width: 100vw !important;
        max-width: 100vw !important;
        border-radius: 12px 12px 0 0;
        margin: 0;
        position: fixed;
        bottom: 0;
        left: 0;
        max-height: 85vh;
        overflow-y: auto;
    }

    /* Onboarding */
    .onboarding-wizard {
        width: 100vw;
        border-radius: 12px 12px 0 0;
        padding: 30px 20px;
        position: fixed;
        bottom: 0;
    }
    .onboarding-emoji { font-size: 2rem; }
    .onboarding-wizard h2 { font-size: 1.1rem; }

    /* API keys */
    .api-key-row { flex-direction: column; gap: 8px; align-items: flex-start; }

    /* Activity feed */
    .activity-item { padding: 10px; gap: 10px; }
    .activity-icon { width: 30px; height: 30px; font-size: 1rem; }
    .activity-title { font-size: 0.82rem; }

    /* Notifications prefs */
    .toggle-switch { width: 36px; height: 20px; }
    .toggle-slider::before { width: 14px; height: 14px; }
    .toggle-switch input:checked + .toggle-slider::before { transform: translateX(16px); }

    /* Hide secondary nav elements */
    .sidebar-search-trigger { display: none; }
}

/* ── Landscape Phone (height-aware) ── */
@media (max-height: 500px) and (max-width: 900px) {
    .onboarding-wizard { padding: 20px; max-height: 90vh; overflow-y: auto; }
    .modal-box { max-height: 85vh; overflow-y: auto; }
}
