/* ============================================
   Telegram Bot Manager — Premium UI v2.0
   Modern Dark Theme · Glassmorphism · RTL-First
   ============================================ */

/* ---- Design Tokens ---- */
:root {
    --bg-base: #06080f;
    --bg-surface: #0d1117;
    --bg-elevated: #161b22;
    --bg-card: rgba(22, 27, 34, 0.75);
    --bg-card-hover: rgba(33, 38, 45, 0.9);
    --bg-glass: rgba(255, 255, 255, 0.04);
    --bg-glass-hover: rgba(255, 255, 255, 0.07);
    --border: rgba(255, 255, 255, 0.06);
    --border-hover: rgba(255, 255, 255, 0.12);
    --border-focus: rgba(99, 102, 241, 0.5);
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #484f58;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --accent-subtle: rgba(99, 102, 241, 0.12);
    --accent-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a78bfa 100%);
    --accent-glow: 0 0 20px rgba(99, 102, 241, 0.25), 0 0 60px rgba(99, 102, 241, 0.1);
    --green: #3fb950;
    --green-subtle: rgba(63, 185, 80, 0.12);
    --yellow: #d29922;
    --yellow-subtle: rgba(210, 153, 34, 0.12);
    --red: #f85149;
    --red-subtle: rgba(248, 81, 73, 0.12);
    --blue: #58a6ff;
    --blue-subtle: rgba(88, 166, 255, 0.12);
    --sidebar-w: 260px;
    --radius-xs: 6px;
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);
    --shadow-xl: 0 20px 60px rgba(0, 0, 0, 0.6);
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ---- Reset ---- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 15px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Tajawal', -apple-system, sans-serif;
    background: var(--bg-base);
    color: var(--text-primary);
    min-height: 100vh;
    direction: rtl;
    line-height: 1.6;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color 0.2s var(--ease);
}

a:hover {
    color: var(--accent-hover);
}

img {
    max-width: 100%;
}

::selection {
    background: var(--accent);
    color: #fff;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: var(--sidebar-w);
    height: 100vh;
    background: var(--bg-surface);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform 0.3s var(--ease);
}

.sidebar-header {
    padding: 18px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.15rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.logo i {
    font-size: 1.4rem;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.logo span {
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.sidebar-close {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-xs);
    transition: all 0.2s var(--ease);
}

.sidebar-close:hover {
    background: var(--bg-glass);
    color: var(--text-primary);
}

/* Nav Groups */
.sidebar-nav {
    flex: 1;
    padding: 8px;
    overflow-y: auto;
    overflow-x: hidden;
}

.nav-group {
    margin-bottom: 4px;
}

.nav-group-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-xs);
    transition: all 0.2s var(--ease);
    user-select: none;
}

.nav-group-toggle:hover {
    color: var(--text-secondary);
    background: var(--bg-glass);
}

.nav-group-toggle i.chevron {
    font-size: 0.6rem;
    transition: transform 0.25s var(--ease);
}

.nav-group.collapsed .chevron {
    transform: rotate(-90deg);
}

.nav-group.collapsed .nav-group-items {
    display: none;
}

.nav-group-label {
    display: block;
    padding: 10px 10px 4px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.88rem;
    font-weight: 500;
    transition: all 0.15s var(--ease);
    position: relative;
}

.nav-item:hover {
    background: var(--bg-glass-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--accent-subtle);
    color: var(--accent-hover);
    font-weight: 600;
}

.nav-item.active::before {
    content: '';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 18px;
    background: var(--accent);
    border-radius: 0 3px 3px 0;
}

.nav-item i {
    font-size: 0.95rem;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

/* Badge */
.badge {
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 10px;
    background: var(--accent-subtle);
    color: var(--accent-hover);
    margin-right: auto;
    margin-left: 0;
}

.badge-new {
    background: var(--green-subtle);
    color: var(--green);
}

.badge-danger {
    background: var(--red-subtle);
    color: var(--red);
}

.badge-warn {
    background: var(--yellow-subtle);
    color: var(--yellow);
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.user-details {
    flex: 1;
    overflow: hidden;
}

.user-name {
    display: block;
    font-weight: 600;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-email {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.logout-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border-radius: var(--radius-xs);
    color: var(--red);
    font-size: 0.8rem;
    transition: all 0.2s var(--ease);
    width: 100%;
}

.logout-btn:hover {
    background: var(--red-subtle);
}

/* ============================================
   MAIN CONTENT
   ============================================ */
.main-content {
    margin-right: var(--sidebar-w);
    min-height: 100vh;
    transition: margin 0.3s var(--ease);
}

.top-bar {
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    background: rgba(6, 8, 15, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 50;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px;
}

.page-title {
    font-size: 1.15rem;
    font-weight: 700;
    flex: 1;
    letter-spacing: -0.01em;
}

.greeting {
    color: var(--text-muted);
    font-size: 0.82rem;
}

.content-wrapper {
    padding: 20px 24px;
    max-width: 1400px;
}

/* ============================================
   STATS
   ============================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    display: flex;
    align-items: center;
    gap: 14px;
    transition: all 0.25s var(--ease);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: var(--accent-gradient);
    opacity: 0;
    transition: opacity 0.3s var(--ease);
}

.stat-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.stat-card:hover::before {
    opacity: 0.03;
}

.stat-icon {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    color: #fff;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

.stat-info {
    position: relative;
    z-index: 1;
}

.stat-info h3 {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.stat-info p {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* ============================================
   CARDS & SECTIONS
   ============================================ */
.section-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: border-color 0.2s var(--ease);
}

.section-card:hover {
    border-color: var(--border-hover);
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 12px;
    flex-wrap: wrap;
}

.section-header h2 {
    font-size: 1.05rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
    letter-spacing: -0.01em;
}

.section-header h2 i {
    color: var(--accent);
    font-size: 0.95rem;
}

.section-desc {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 14px;
    line-height: 1.6;
}

/* ============================================
   BUTTONS
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s var(--ease);
    font-family: inherit;
    white-space: nowrap;
    text-decoration: none;
    line-height: 1.4;
}

.btn i {
    font-size: 0.8rem;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    box-shadow: var(--accent-glow);
    transform: translateY(-1px);
    color: #fff;
}

.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border);
}

.btn-outline:hover {
    background: var(--bg-glass-hover);
    color: var(--text-primary);
    border-color: var(--border-hover);
}

.btn-danger {
    background: var(--red);
    color: #fff;
    border-color: var(--red);
}

.btn-danger:hover {
    background: #da3633;
    box-shadow: 0 0 15px rgba(248, 81, 73, 0.25);
    color: #fff;
}

.btn-success {
    background: var(--green);
    color: #fff;
    border-color: var(--green);
}

.btn-success:hover {
    background: #2ea043;
    color: #fff;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 0.78rem;
}

.btn-lg {
    padding: 10px 24px;
    font-size: 0.95rem;
}

.btn-block {
    width: 100%;
    justify-content: center;
}

.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
    justify-content: center;
    border-radius: var(--radius-xs);
}

/* ============================================
   FORMS
   ============================================ */
.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="url"],
input[type="search"],
input[type="tel"],
input[type="date"],
input[type="datetime-local"],
textarea,
select {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.88rem;
    transition: all 0.2s var(--ease);
    line-height: 1.5;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-subtle);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-muted);
}

textarea {
    resize: vertical;
    min-height: 80px;
}

select {
    cursor: pointer;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
}

.form-row {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.form-row .form-group {
    flex: 1;
}

small {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: block;
    margin-top: 3px;
}

/* Toggle */
.toggle-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 0.88rem;
}

.toggle-label input[type="checkbox"] {
    display: none;
}

.toggle-switch {
    width: 38px;
    height: 20px;
    background: var(--text-muted);
    border-radius: 10px;
    position: relative;
    transition: background 0.2s var(--ease);
    flex-shrink: 0;
}

.toggle-switch::after {
    content: '';
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    position: absolute;
    top: 2px;
    right: 2px;
    transition: transform 0.2s var(--ease);
}

.toggle-label input:checked+.toggle-switch {
    background: var(--accent);
}

.toggle-label input:checked+.toggle-switch::after {
    transform: translateX(-18px);
}

/* ============================================
   TABLES
   ============================================ */
.table-responsive {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

thead th {
    padding: 10px 12px;
    text-align: right;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    color: var(--text-secondary);
}

tbody tr {
    transition: background 0.15s var(--ease);
}

tbody tr:hover {
    background: var(--bg-glass);
}

tbody tr:last-child td {
    border-bottom: none;
}

/* ============================================
   ALERTS
   ============================================ */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid;
}

.alert-success {
    background: var(--green-subtle);
    color: var(--green);
    border-color: rgba(63, 185, 80, 0.2);
}

.alert-error {
    background: var(--red-subtle);
    color: var(--red);
    border-color: rgba(248, 81, 73, 0.2);
}

.alert-warning {
    background: var(--yellow-subtle);
    color: var(--yellow);
    border-color: rgba(210, 153, 34, 0.2);
}

.alert-info {
    background: var(--blue-subtle);
    color: var(--blue);
    border-color: rgba(88, 166, 255, 0.2);
}

/* ============================================
   AUTH PAGES
   ============================================ */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background:
        radial-gradient(ellipse at 30% 20%, rgba(99, 102, 241, 0.1) 0%, transparent 50%),
        radial-gradient(ellipse at 70% 80%, rgba(139, 92, 246, 0.08) 0%, transparent 50%),
        var(--bg-base);
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: var(--shadow-xl);
    animation: authSlideUp 0.5s var(--ease-spring);
}

@keyframes authSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.auth-logo {
    text-align: center;
    margin-bottom: 24px;
}

.auth-logo i {
    font-size: 2.5rem;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
    display: block;
}

.auth-logo h2 {
    font-size: 1.3rem;
    font-weight: 800;
    margin-bottom: 4px;
}

.auth-logo p {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.auth-form .form-group {
    margin-bottom: 16px;
}

.auth-form .btn-block {
    margin-top: 8px;
    padding: 11px;
    font-size: 0.95rem;
}

.auth-footer {
    text-align: center;
    margin-top: 18px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ============================================
   DASHBOARD SPECIFIC
   ============================================ */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 10px;
}

.quick-action-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s var(--ease);
    text-decoration: none;
}

.quick-action-btn:hover {
    background: var(--bg-glass-hover);
    color: var(--text-primary);
    border-color: var(--border-hover);
    transform: translateY(-1px);
}

.quick-action-btn i {
    color: var(--accent);
    font-size: 1rem;
    width: 20px;
    text-align: center;
}

/* Activity sparkline chart */
.chart-wrapper {
    position: relative;
    height: 200px;
    margin-top: 10px;
}

.chart-wrapper canvas {
    width: 100% !important;
    height: 100% !important;
}

/* Bot selector */
.bot-selector {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.bot-select-btn {
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.82rem;
    font-weight: 600;
    background: var(--bg-glass);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    transition: all 0.2s var(--ease);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.bot-select-btn:hover {
    border-color: var(--border-hover);
    color: var(--text-primary);
}

.bot-select-btn.active {
    background: var(--accent-subtle);
    color: var(--accent-hover);
    border-color: var(--accent);
}

/* ============================================
   FLOW BUILDER
   ============================================ */
.flow-canvas {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-height: 500px;
    position: relative;
    overflow: hidden;
}

.flow-node {
    position: absolute;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    min-width: 180px;
    cursor: grab;
    transition: box-shadow 0.2s var(--ease), border-color 0.2s var(--ease);
    z-index: 5;
}

.flow-node:hover {
    border-color: var(--accent);
    box-shadow: var(--accent-glow);
}

.flow-node.selected {
    border-color: var(--accent);
    box-shadow: var(--accent-glow);
}

.flow-node-header {
    font-weight: 600;
    font-size: 0.82rem;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.flow-node-body {
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* ============================================
   LIVE CHAT
   ============================================ */
.chat-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 0;
    height: calc(100vh - 120px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg-card);
}

.chat-sidebar {
    border-left: 1px solid var(--border);
    overflow-y: auto;
    background: var(--bg-surface);
}

.chat-user-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s var(--ease);
}

.chat-user-item:hover,
.chat-user-item.active {
    background: var(--bg-glass-hover);
}

.chat-user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 0.8rem;
    font-weight: 700;
    flex-shrink: 0;
}

.chat-user-info {
    flex: 1;
    overflow: hidden;
}

.chat-user-name {
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-user-last {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-unread {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 0.65rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.chat-main {
    display: flex;
    flex-direction: column;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-bubble {
    max-width: 70%;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    line-height: 1.5;
    position: relative;
}

.chat-bubble.incoming {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    align-self: flex-start;
    border-bottom-right-radius: 2px;
}

.chat-bubble.outgoing {
    background: var(--accent-subtle);
    border: 1px solid rgba(99, 102, 241, 0.2);
    color: var(--accent-hover);
    align-self: flex-end;
    border-bottom-left-radius: 2px;
}

.chat-bubble-time {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 3px;
}

.chat-input-area {
    padding: 12px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
}

.chat-input-area input {
    flex: 1;
    border-radius: 20px;
    padding: 9px 16px;
}

.chat-input-area button {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    color: #fff;
    font-size: 0.95rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s var(--ease);
}

.chat-input-area button:hover {
    background: var(--accent-hover);
    box-shadow: var(--accent-glow);
}

/* ============================================
   CALENDAR
   ============================================ */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    background: var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.calendar-header-cell {
    background: var(--bg-elevated);
    padding: 8px;
    text-align: center;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
}

.calendar-cell {
    background: var(--bg-card);
    padding: 6px 8px;
    min-height: 80px;
    font-size: 0.8rem;
    position: relative;
}

.calendar-cell.today {
    background: var(--accent-subtle);
}

.calendar-cell.other-month {
    opacity: 0.3;
}

.calendar-day {
    font-weight: 700;
    font-size: 0.78rem;
    margin-bottom: 4px;
    color: var(--text-secondary);
}

.calendar-event {
    font-size: 0.68rem;
    padding: 2px 5px;
    border-radius: 3px;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
}

/* ============================================
   MODALS
   ============================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.2s var(--ease);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal-content {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 520px;
    max-height: 80vh;
    overflow-y: auto;
    padding: 24px;
    box-shadow: var(--shadow-xl);
    animation: modalSlide 0.3s var(--ease-spring);
}

@keyframes modalSlide {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.modal-header h3 {
    font-size: 1.05rem;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-xs);
    transition: all 0.2s var(--ease);
}

.modal-close:hover {
    background: var(--bg-glass);
    color: var(--text-primary);
}

/* ============================================
   MISC COMPONENTS
   ============================================ */
/* Progress bar */
.progress-bar {
    height: 6px;
    background: var(--bg-glass);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s var(--ease);
}

/* Tag/Chip */
.tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 600;
    background: var(--bg-glass);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

/* Status indicator */
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.status-dot.online {
    background: var(--green);
    box-shadow: 0 0 6px var(--green);
}

.status-dot.offline {
    background: var(--text-muted);
}

.status-dot.warning {
    background: var(--yellow);
    box-shadow: 0 0 6px var(--yellow);
}

.status-dot.danger {
    background: var(--red);
    box-shadow: 0 0 6px var(--red);
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 2.5rem;
    margin-bottom: 12px;
    display: block;
    opacity: 0.4;
}

.empty-state p {
    font-size: 0.9rem;
    margin-bottom: 14px;
}

/* Code block */
.code-block {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    font-family: 'Courier New', monospace;
    font-size: 0.82rem;
    overflow-x: auto;
    direction: ltr;
    text-align: left;
    color: var(--text-secondary);
}

/* Tabs */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
}

.tab-btn {
    padding: 8px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s var(--ease);
    font-family: inherit;
}

.tab-btn:hover {
    color: var(--text-secondary);
}

.tab-btn.active {
    color: var(--accent-hover);
    border-bottom-color: var(--accent);
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    gap: 4px;
    justify-content: center;
    margin-top: 16px;
}

.pagination a,
.pagination span {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-xs);
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all 0.2s var(--ease);
    border: 1px solid transparent;
}

.pagination a:hover {
    background: var(--bg-glass);
    border-color: var(--border);
}

.pagination .active {
    background: var(--accent-subtle);
    color: var(--accent-hover);
    border-color: var(--accent);
}

/* Tooltip */
[data-tooltip] {
    position: relative;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 8px;
    border-radius: var(--radius-xs);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 0.72rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s var(--ease);
    z-index: 50;
}

[data-tooltip]:hover::after {
    opacity: 1;
}

/* ============================================
   TEMPLATE CARDS / GRID
   ============================================ */
.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 14px;
}

.template-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    transition: all 0.25s var(--ease);
}

.template-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.skeleton {
    background: linear-gradient(90deg, var(--bg-glass) 25%, var(--bg-glass-hover) 50%, var(--bg-glass) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: var(--radius-xs);
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

/* Page load animation */
.content-wrapper {
    animation: contentFade 0.3s var(--ease);
}

@keyframes contentFade {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(100%);
        width: 280px;
        box-shadow: var(--shadow-xl);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-close {
        display: block;
    }

    .menu-toggle {
        display: block;
    }

    .main-content {
        margin-right: 0;
    }

    .content-wrapper {
        padding: 14px;
    }

    .top-bar {
        padding: 10px 14px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .stat-card {
        padding: 14px;
    }

    .stat-info h3 {
        font-size: 1.2rem;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .quick-actions {
        grid-template-columns: repeat(2, 1fr);
    }

    .template-grid {
        grid-template-columns: 1fr;
    }

    .chat-layout {
        grid-template-columns: 1fr;
        height: auto;
    }

    .chat-sidebar {
        max-height: 200px;
        border-left: none;
        border-bottom: 1px solid var(--border);
    }

    .calendar-cell {
        min-height: 50px;
    }

    .form-row {
        flex-direction: column;
    }

    .modal-content {
        padding: 18px;
        max-width: 100%;
    }

    table {
        font-size: 0.78rem;
    }

    thead th,
    tbody td {
        padding: 8px;
    }

    .section-card {
        padding: 14px;
    }

    .page-title {
        font-size: 1rem;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .stat-card {
        gap: 10px;
    }

    .quick-actions {
        grid-template-columns: 1fr;
    }

    .bot-selector {
        flex-direction: column;
    }

    .bot-select-btn {
        justify-content: center;
    }
}