/* ==================== CSS Variables ==================== */
:root {
    /* Dark theme (default) */
    --bg-primary: #0a0e1a;
    --bg-secondary: #13161f;
    --bg-tertiary: #1a1e2e;
    --bg-card: #1e2433;
    --accent-primary: #3b82f6;
    --accent-secondary: #8b5cf6;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: #2d3748;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1);
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==================== Light Theme ==================== */
html[data-theme="light"] {
    --bg-primary: #f0f4f8;
    --bg-secondary: #e4eaf2;
    --bg-tertiary: #d8e2ed;
    --bg-card: #ffffff;
    --accent-primary: #2563eb;
    --accent-secondary: #7c3aed;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --border-color: #c5d0de;
    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.04);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.07);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.08);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.08);
}

/* ==================== Base Styles ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
}

/* ==================== Layout ==================== */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 260px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h1 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 4px;
}

.version {
    font-size: 12px;
    color: var(--text-muted);
}

.sidebar-nav {
    flex: 1;
    padding: 16px 0;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: var(--transition);
    cursor: pointer;
    gap: 12px;
}

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

.nav-item.active {
    background: var(--bg-tertiary);
    color: var(--accent-primary);
    border-left: 3px solid var(--accent-primary);
    padding-left: 17px;
}

.nav-item .icon {
    font-size: 18px;
}

.badge {
    margin-left: auto;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}

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

.system-status {
    display: flex;
    align-items: center;
    gap: 10px;
}

.footer-status-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logout-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.logout-btn:hover {
    background: rgba(239, 68, 68, 0.08);
    border-color: rgba(239, 68, 68, 0.35);
    color: #ef4444;
}

.theme-toggle-label {
    font-size: 12px;
    color: var(--text-muted);
}

.theme-toggle-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 5px 10px;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    transition: var(--transition);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 4px;
}

.theme-toggle-btn:hover {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
    transform: scale(1.05);
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--success);
    animation: pulse 2s infinite;
}

.status-indicator.offline {
    background: var(--danger);
    animation: none;
}

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

.main-content {
    margin-left: 260px;
    padding: 32px;
    min-height: 100vh;
}

/* ==================== Pages ==================== */
.page {
    display: none;
}

.page.active {
    display: block;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 32px;
}

.page-header h2 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 4px;
}

.subtitle {
    color: var(--text-muted);
    font-size: 14px;
}

.section-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-primary);
}

/* ==================== System Control ==================== */
.system-control-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 32px;
    margin-bottom: 24px;
}

.system-control-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.system-control-header h3 {
    font-size: 20px;
    margin: 0;
}

/* ==================== Stats Grid ==================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    border-color: var(--accent-primary);
}

.stat-icon {
    font-size: 32px;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
}

.stat-content {
    flex: 1;
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 4px;
}

.stat-label {
    font-size: 13px;
    color: var(--text-muted);
}

/* ==================== Bot Detail Cards (System Page) ==================== */
.bot-detail-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 16px;
    transition: var(--transition);
}

.bot-detail-card:hover {
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-md);
}

.bot-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.bot-detail-header h4 {
    font-size: 18px;
    margin: 0;
}

.bot-status-badge {
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 600;
    margin-left: 12px;
}

.bot-status-badge.active {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.bot-status-badge.inactive {
    background: rgba(100, 116, 139, 0.1);
    color: var(--text-muted);
}

.bot-detail-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 16px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
}

.stat-item .stat-label {
    font-size: 13px;
    color: var(--text-muted);
}

.stat-item .stat-value {
    font-size: 18px;
    font-weight: 600;
    color: var(--accent-primary);
}

/* stat-sub: small enabled/disabled line under stat value */
.stat-sub {
    font-size: 11px;
    margin-top: 2px;
    min-height: 14px;
}

/* per-category breakdown inside bot-detail-card */
.sys-cat-breakdown {
    margin-top: 14px;
    border-top: 1px solid var(--border-color);
    padding-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.sys-cat-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    padding: 3px 4px;
    border-radius: var(--radius-sm);
}

.sys-cat-row:hover { background: var(--bg-tertiary); }

.sys-cat-name {
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: capitalize;
    flex: 1;
}

.sys-cat-topics {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ==================== Create Bot Card ==================== */
.create-bot-card {
    background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-tertiary) 100%);
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    padding: 32px;
    margin-bottom: 32px;
}

.create-bot-card h3 {
    font-size: 20px;
    margin-bottom: 20px;
    color: var(--accent-primary);
}

.create-bot-form {
    display: flex;
    gap: 12px;
    max-width: 600px;
}

.create-bot-form .input {
    flex: 1;
}

/* ==================== Bot Config Cards ==================== */
.bot-config-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    margin-bottom: 24px;
    overflow: hidden;
    transition: var(--transition);
}

.bot-config-card:hover {
    box-shadow: var(--shadow-lg);
}

.bot-config-header {
    padding: 24px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.bot-config-title {
    display: flex;
    align-items: center;
    gap: 16px;
}

.bot-config-title h3 {
    font-size: 20px;
    margin: 0;
}

.bot-config-actions {
    display: flex;
    gap: 8px;
}

.bot-config-body {
    padding: 0;
}

/* ==================== Collapsible Sections ==================== */
.collapsible-section {
    border-bottom: 1px solid var(--border-color);
    transition: var(--transition);
}

.collapsible-section:last-child {
    border-bottom: none;
}

.collapsible-section.open {
    background: rgba(59, 130, 246, 0.02);
}

.collapsible-header {
    padding: 20px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    transition: var(--transition);
    background: var(--bg-card);
}

.collapsible-header:hover {
    background: var(--bg-tertiary);
}

.collapsible-header:active {
    transform: scale(0.99);
}

.collapsible-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.collapsible-title .icon {
    font-size: 18px;
    transition: var(--transition);
}

.collapsible-section.open .collapsible-title .icon {
    color: var(--accent-primary);
}

.collapsible-toggle {
    color: var(--text-muted);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), color 0.2s;
    font-size: 14px;
}

.collapsible-section.open > * .collapsible-toggle,
.collapsible-section.open > .collapsible-toggle {
    transform: rotate(180deg);
    color: var(--accent-primary);
}

.collapsible-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.collapsible-section.open > .collapsible-content {
    max-height: 8000px;
}

.collapsible-body {
    padding: 24px;
    background: var(--bg-secondary);
    animation: fadeIn 0.3s ease-out;
}

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

/* ==================== Summary Blocks (IMPROVED SPACING) ==================== */
.summary-block {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-left: 3px solid var(--success);
    border-radius: var(--radius-md);
    padding: 16px 20px;
    margin-bottom: 12px;
    transition: var(--transition);
}

.summary-block:hover {
    border-left-width: 4px;
    box-shadow: var(--shadow-sm);
    transform: translateX(2px);
}

.summary-block:last-child {
    margin-bottom: 0;
}

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

.summary-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.summary-title strong {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.summary-details {
    display: flex;
    gap: 20px;
    font-size: 12px;
    color: var(--text-muted);
    padding-left: 42px;
}

.summary-details span {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-card);
    padding: 4px 10px;
    border-radius: 12px;
}

/* ==================== Category & Topic Boxes (IMPROVED UI) ==================== */
.category-box {
    background: var(--bg-tertiary);
    border: 2px solid var(--accent-primary);
    border-radius: var(--radius-lg);
    padding: 0;
    margin-bottom: 24px;  /* More spacing */
}

.category-box.collapsible-section > .collapsible-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.category-box.collapsible-section.open > .collapsible-content {
    max-height: 5000px;
}

.category-box .collapsible-toggle {
    color: var(--text-muted);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), color 0.2s;
    font-size: 14px;
    display: inline-block;
}

.category-box.collapsible-section.open .collapsible-toggle {
    transform: rotate(180deg);
    color: var(--accent-primary);
}

.category-header-row {
    padding: 20px 24px;
    background: rgba(59, 130, 246, 0.1);
    border-bottom: 1px solid var(--accent-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    transition: var(--transition);
}

.category-header-row:hover {
    background: rgba(59, 130, 246, 0.15);
}

.category-header-row:active {
    transform: scale(0.99);
}

.category-title-group {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 1;
}

.category-title-group h4 {
    font-size: 17px;
    margin: 0;
    color: var(--accent-primary);
}

.category-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topics-container {
    padding: 20px 24px 20px 48px;  /* Indented! */
    background: var(--bg-secondary);
}

.topic-box {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-left: 3px solid var(--accent-secondary);
    border-radius: var(--radius-md);
    padding: 0;
    margin-bottom: 16px;
    transition: var(--transition);
}

.topic-box:hover {
    border-left-width: 4px;
    box-shadow: var(--shadow-md);
}

.topic-box:last-child {
    margin-bottom: 0;
}

.topic-box.category-disabled {
    opacity: 0.5;
    pointer-events: auto;
}

.topic-box.category-disabled .topic-header-row {
    background: var(--bg-card);
}

.topic-box.category-disabled:hover {
    border-left-width: 3px;
    box-shadow: none;
}

.disabled-badge {
    background: var(--warning);
    color: var(--bg-primary);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

/* Topic uses general collapsible rules, just customize the toggle arrow */
.topic-box .collapsible-toggle {
    color: var(--text-muted);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), color 0.2s;
    font-size: 14px;
    display: inline-block;
}

.topic-box.collapsible-section.open .collapsible-toggle {
    transform: rotate(180deg);
    color: var(--accent-secondary);
}

.topic-header-row {
    padding: 16px 20px;
    background: var(--bg-tertiary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    transition: var(--transition);
}

.topic-header-row:hover {
    background: rgba(139, 92, 246, 0.05);
}

.topic-header-row:active {
    transform: scale(0.99);
}

.topic-title-group {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.topic-title-group strong {
    font-size: 15px;
    color: var(--text-primary);
}

.schedule-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: rgba(139, 92, 246, 0.1);
    border-radius: 12px;
    font-size: 12px;
    color: var(--accent-secondary);
    font-weight: 600;
}

.topic-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topic-body {
    padding: 24px;
    background: var(--bg-secondary);
}

.add-category-section {
    margin-top: 24px;
    padding: 20px 0;
    border-top: 2px dashed var(--border-color);
}

/* ==================== Buttons ==================== */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: var(--accent-primary);
    color: white;
}

.btn-primary:hover {
    background: #2563eb;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-card);
    border-color: var(--accent-primary);
}

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

.btn-danger:hover {
    background: #dc2626;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

.btn-icon {
    padding: 8px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 20px;
    transition: var(--transition);
}

.btn-icon:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
}

/* ==================== Forms ==================== */
.input, .select, .textarea {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 14px;
    transition: var(--transition);
}

.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.textarea {
    min-height: 100px;
    resize: vertical;
    font-family: 'Courier New', monospace;
}

.multi-select {
    padding: 8px;
    min-height: 120px;
}

.multi-select option {
    padding: 8px 12px;
    margin: 2px 0;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.multi-select option:hover {
    background: rgba(59, 130, 246, 0.2);
}

.multi-select option:checked {
    background: var(--accent-primary);
    color: var(--text-primary);
}

.form-hint {
    display: block;
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
}

.text-warning {
    color: var(--warning);
    padding: 12px;
    background: rgba(245, 158, 11, 0.1);
    border-radius: var(--radius-md);
    margin-bottom: 16px;
}

.text-warning a {
    color: var(--accent-primary);
    text-decoration: underline;
    cursor: pointer;
}

.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    margin-bottom: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.text-muted {
    color: var(--text-muted);
    font-size: 13px;
}

.d-block { display: block; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mt-4 { margin-top: 32px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }

/* ==================== Toggle Switch ==================== */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 24px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--bg-tertiary);
    transition: var(--transition);
    border-radius: 24px;
    border: 1px solid var(--border-color);
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 2px;
    background-color: var(--text-muted);
    transition: var(--transition);
    border-radius: 50%;
}

.toggle-switch input:checked + .toggle-slider {
    background-color: var(--accent-primary);
    border-color: var(--accent-primary);
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(23px);
    background-color: white;
}

.toggle-large {
    width: 70px;
    height: 36px;
}

.toggle-large .toggle-slider:before {
    height: 28px;
    width: 28px;
}

.toggle-large input:checked + .toggle-slider:before {
    transform: translateX(34px);
}

/* ==================== Tags ==================== */
.tags-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    min-height: 46px;
    transition: var(--transition);
}

.tags-container:focus-within {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--accent-primary);
    color: white;
    border-radius: 16px;
    font-size: 13px;
    font-weight: 500;
    transition: var(--transition);
    animation: slideIn 0.2s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.tag:hover {
    background: var(--accent-secondary);
    transform: scale(1.05);
}

.tag-remove {
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s;
    font-weight: bold;
}

.tag-remove:hover {
    opacity: 1;
    transform: scale(1.2);
}

.tag-input {
    flex: 1;
    min-width: 120px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
}

/* ==================== Modal ==================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 20px;
    animation: fadeIn 0.2s;
}

.modal-dialog {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-xl);
    animation: modalSlideIn 0.3s;
}

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

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 20px;
    margin: 0;
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 20px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* ==================== Collections ==================== */
.collection-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 20px;
    transition: var(--transition);
}

.collection-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    border-color: var(--accent-primary);
}

.collection-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.collection-header h3 {
    margin: 0 0 0 12px;
    font-size: 18px;
}

.collection-actions {
    display: flex;
    gap: 8px;
}

.collection-info {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.info-row {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.info-label {
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 100px;
}

.info-value {
    color: var(--text-primary);
    flex: 1;
}

/* ==================== Utilities ==================== */
.flex-center {
    display: flex;
    align-items: center;
}

/* ==================== Linked Topics Styling ==================== */
.linked-badge {
    font-size: 0.75em;
    color: #4CAF50;
    font-style: italic;
    margin-left: 8px;
    font-weight: 600;
}

.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* ==================== Alert Boxes ==================== */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    border: 1px solid;
    font-size: 14px;
}

.alert p {
    margin: 4px 0;
}

.alert strong {
    display: block;
    margin-bottom: 4px;
    font-size: 15px;
}

.alert a {
    color: inherit;
    text-decoration: underline;
}

.alert-warning {
    background: rgba(245, 158, 11, 0.1);
    border-color: var(--warning);
    color: var(--warning);
}

.alert-info {
    background: rgba(59, 130, 246, 0.1);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.alert-success {
    background: rgba(16, 185, 129, 0.1);
    border-color: var(--success);
    color: var(--success);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

.input-number-sm {
    max-width: 120px;
}

/* ==================== Custom Dialogs ==================== */
.dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: dialogFadeIn 0.15s ease;
}

.dialog-box {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 28px 28px 22px;
    min-width: 300px;
    max-width: 440px;
    width: 90vw;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
    animation: dialogPop 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes dialogPop {
    from { transform: scale(0.82); opacity: 0; }
    to   { transform: scale(1);    opacity: 1; }
}

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

.dialog-icon {
    font-size: 36px;
    display: block;
    text-align: center;
    margin-bottom: 10px;
}

.dialog-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
    margin-bottom: 8px;
}

.dialog-message {
    font-size: 14px;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.55;
    margin-bottom: 22px;
}

.dialog-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.dialog-actions .btn {
    min-width: 82px;
}

/* ==================== Responsive ==================== */
@media (max-width: 768px) {
    .sidebar {
        width: 200px;
    }
    
    .main-content {
        margin-left: 200px;
        padding: 20px;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .create-bot-form {
        flex-direction: column;
    }
}

/* ══════════════════════════════════════════════════
   Dashboard
══════════════════════════════════════════════════ */

/* Stat cards */
.dash-stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.dash-stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 22px 20px;
    transition: var(--transition);
}

.dash-stat-card:hover {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 1px var(--accent-primary);
}

.dash-stat-icon {
    font-size: 22px;
    margin-bottom: 10px;
    line-height: 1;
}

.dash-stat-value {
    font-size: 30px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    line-height: 1.1;
    margin-bottom: 5px;
}

.dash-stat-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

/* Chart rows */
.dash-chart-row {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.dash-chart-row:nth-child(odd) {
    grid-template-columns: 1fr 2fr;
}

.dash-chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
}

.dash-chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.dash-chart-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.dash-chart-sub {
    font-size: 11px;
    color: var(--text-muted);
}

.dash-canvas-wrap {
    position: relative;
    height: 230px;
}

/* Source × topic matrix */
.dash-matrix-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 24px;
}

.dash-matrix-wrap {
    overflow-x: auto;
    margin-top: 4px;
}

.dash-filter-input {
    width: 200px;
    padding: 6px 12px;
    font-size: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    outline: none;
    transition: var(--transition);
}

.dash-filter-input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.dash-matrix-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    white-space: nowrap;
}

.dash-matrix-table th {
    padding: 9px 12px;
    text-align: left;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    font-weight: 500;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.dash-matrix-table th:not(:first-child) {
    text-align: center;
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dash-matrix-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    transition: background 0.1s;
}

.dash-matrix-table tr:last-child td {
    border-bottom: none;
}

.dash-matrix-table tbody tr:hover td {
    background: var(--bg-tertiary);
}

.dash-matrix-src {
    font-size: 12px;
    color: var(--text-secondary);
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dash-matrix-cell {
    text-align: center;
    border-radius: 4px;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    font-size: 12px;
}

.dash-matrix-total {
    text-align: center;
    font-weight: 600;
    color: var(--accent-primary);
    font-variant-numeric: tabular-nums;
}

@media (max-width: 1100px) {
    .dash-stat-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .dash-chart-row,
    .dash-chart-row:nth-child(odd) {
        grid-template-columns: 1fr;
    }
}