/* --- Design System & CSS Variables --- */
:root {
    --bg-main: #0b0f17;
    --bg-surface: #121824;
    --bg-surface-elevated: #1a2332;
    --bg-glass: rgba(18, 24, 36, 0.75);
    
    --border-color: rgba(255, 255, 255, 0.08);
    --border-focus: #3b82f6;

    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --color-primary: #3b82f6;
    --color-primary-hover: #2563eb;
    --color-primary-glow: rgba(59, 130, 246, 0.25);
    
    --color-accent: #06b6d4;
    --color-success: #10b981;
    --color-warning: #f59e0b;
    --color-danger: #ef4444;
    --color-purple: #8b5cf6;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    --font-sans: 'Vazirmatn', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
    --shadow-glow: 0 0 25px rgba(59, 130, 246, 0.2);
}

/* --- Base & Reset --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    font-family: var(--font-sans);
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    position: relative;
    background-image: 
        radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.08) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(139, 92, 246, 0.08) 0px, transparent 50%);
    background-attachment: fixed;
}

/* Glass Panels */
.glass-panel {
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

/* --- Typography & Badges --- */
h1, h2, h3, h4 {
    color: var(--text-primary);
    font-weight: 700;
}

.brand-badge {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-icon {
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    border-radius: var(--radius-md);
    box-shadow: 0 0 16px rgba(59, 130, 246, 0.4);
}

.brand-title {
    font-size: 1.35rem;
    font-weight: 800;
    background: linear-gradient(135deg, #60a5fa, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    font-size: 0.78rem;
    font-weight: 600;
    border-radius: var(--radius-full);
}

.badge-primary { background: rgba(59, 130, 246, 0.15); color: #60a5fa; border: 1px solid rgba(59, 130, 246, 0.3); }
.badge-accent { background: rgba(6, 182, 212, 0.15); color: #22d3ee; border: 1px solid rgba(6, 182, 212, 0.3); }
.badge-success { background: rgba(16, 185, 129, 0.15); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.3); }
.badge-warning { background: rgba(245, 158, 11, 0.15); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.3); }

/* --- Buttons & Inputs --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: var(--font-sans);
    font-size: 0.92rem;
    font-weight: 600;
    padding: 10px 18px;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: var(--transition);
}

.btn:active { transform: scale(0.98); }

.btn-primary {
    background: linear-gradient(135deg, var(--color-primary), #2563eb);
    color: white;
    box-shadow: 0 4px 14px var(--color-primary-glow);
}
.btn-primary:hover {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    box-shadow: 0 6px 20px var(--color-primary-glow);
}

.btn-secondary {
    background: var(--bg-surface-elevated);
    color: var(--text-primary);
    border-color: var(--border-color);
}
.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}
.btn-ghost:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.btn-icon {
    width: 38px;
    height: 38px;
    padding: 0;
    border-radius: var(--radius-md);
}

.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 0.82rem; }

.icon {
    width: 18px;
    height: 18px;
    stroke-width: 2;
}

input, select, textarea {
    font-family: var(--font-sans);
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: var(--transition);
    outline: none;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-glow);
}

input::placeholder, textarea::placeholder {
    color: var(--text-muted);
}

.form-group {
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-row {
    display: flex;
    gap: 12px;
}
.flex-1 { flex: 1; }
.flex-2 { flex: 2; }

/* --- Login Screen --- */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 420px;
    padding: 36px 32px;
}

.login-header {
    text-align: center;
    margin-bottom: 28px;
}
.login-header .brand-badge {
    justify-content: center;
    margin-bottom: 16px;
}
.login-header h2 { font-size: 1.5rem; margin-bottom: 6px; }
.login-header p { font-size: 0.9rem; color: var(--text-muted); }

/* --- Main Layout --- */
.app-layout {
    display: flex;
    min-height: 100vh;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    position: relative;
}

.sidebar {
    width: 260px;
    height: 100vh;
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    border-radius: 0;
    border-left: 1px solid var(--border-color);
    border-top: none;
    border-bottom: none;
    border-right: none;
    z-index: 50;
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid var(--border-color);
}
.brand-text h3 { font-size: 1.15rem; }

.sidebar-nav {
    flex: 1;
    padding: 20px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 0.92rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    text-align: right;
    width: 100%;
}

.nav-item:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.nav-item.active {
    color: #60a5fa;
    background: rgba(59, 130, 246, 0.12);
    font-weight: 600;
}
.nav-item.active .icon { stroke: #60a5fa; }
.nav-item .badge { margin-right: auto; }

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

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}
.avatar {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #3b82f6, #06b6d4);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
}
.user-meta { display: flex; flex-direction: column; }
.user-name { font-size: 0.88rem; font-weight: 600; }
.user-status { font-size: 0.72rem; color: var(--color-success); }

/* --- Topbar --- */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
}

.topbar {
    padding: 14px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-top: none;
    z-index: 10;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 14px;
}
.page-title { font-size: 1.35rem; font-weight: 700; }

.topbar-right {
    display: flex;
    align-items: center;
    gap: 14px;
}

.api-status-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.25);
    border-radius: var(--radius-full);
    font-size: 0.82rem;
    color: #34d399;
}
.ping-dot {
    width: 8px;
    height: 8px;
    background-color: #10b981;
    border-radius: 50%;
    box-shadow: 0 0 8px #10b981;
}

.model-badge {
    padding: 6px 12px;
    background: rgba(139, 92, 246, 0.15);
    border: 1px solid rgba(139, 92, 246, 0.3);
    border-radius: var(--radius-md);
    font-size: 0.82rem;
    color: #c084fc;
    font-weight: 600;
}

.content-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.tab-pane { display: none; }
.tab-pane.active { display: block; animation: fadeIn 0.25s ease-out; }

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

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

.stat-card {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
}
.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
}
.stat-icon svg { width: 24px; height: 24px; }

.icon-primary { background: rgba(59, 130, 246, 0.15); color: #60a5fa; }
.icon-success { background: rgba(16, 185, 129, 0.15); color: #34d399; }
.icon-warning { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.icon-purple { background: rgba(139, 92, 246, 0.15); color: #c084fc; }

.stat-label { font-size: 0.85rem; color: var(--text-muted); display: block; margin-bottom: 4px; }
.stat-value { font-size: 1.7rem; font-weight: 800; }
.stat-value-sm { font-size: 1.15rem; }

.dashboard-columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
    gap: 20px;
}

.card {
    padding: 24px;
}
.card-header {
    margin-bottom: 18px;
}
.card-header h3 { font-size: 1.15rem; }
.card-subtitle { font-size: 0.85rem; color: var(--text-muted); margin-top: 4px; }

.breakdown-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    margin-bottom: 8px;
    background: var(--bg-surface-elevated);
    border-radius: var(--radius-md);
    font-size: 0.92rem;
}

.quick-actions-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

/* --- Toolbar & Table --- */
.toolbar {
    padding: 16px 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    align-items: center;
    justify-content: space-between;
}

.toolbar-search {
    position: relative;
    flex: 1;
    min-width: 260px;
}
.toolbar-search input { padding-right: 38px; }
.search-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: var(--text-muted);
}

/* Enhanced Toolbar & Filters */
.toolbar {
    padding: 14px 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.toolbar-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.toolbar-search {
    position: relative;
    flex: 1;
    min-width: 280px;
}

.toolbar-search input {
    width: 100%;
    padding-right: 40px;
    padding-left: 36px;
}

.clear-search-btn {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.2s;
}

.clear-search-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.1);
}

.toolbar-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

/* Export Dropdown & Split Button */
.export-dropdown-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.export-split-btn {
    display: inline-flex;
    align-items: stretch;
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.export-main-btn {
    border-top-left-radius: 0 !important;
    border-bottom-left-radius: 0 !important;
    border-left: 1px solid rgba(255, 255, 255, 0.1) !important;
    padding: 8px 14px !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 8px !important;
    font-size: 0.88rem !important;
    white-space: nowrap !important;
}

.export-toggle-btn {
    border-top-right-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
    padding: 0 8px !important;
    width: 32px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.export-toggle-btn .icon {
    width: 14px;
    height: 14px;
    transition: transform 0.2s ease;
}

.export-dropdown-wrapper.open .export-toggle-btn .icon {
    transform: rotate(180deg);
}

.export-menu {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    min-width: 250px;
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    padding: 6px;
    z-index: 120;
    display: flex;
    flex-direction: column;
    gap: 3px;
    animation: fadeInDown 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

.export-menu.hidden {
    display: none !important;
}

.export-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 9px 12px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    text-align: right;
    cursor: pointer;
    transition: var(--transition);
}

.export-menu-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

.export-menu-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
    line-height: 1;
}

.export-menu-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    text-align: right;
}

.export-menu-info strong {
    font-size: 0.86rem;
    font-weight: 600;
    color: var(--text-primary);
}

.export-menu-info small {
    font-size: 0.74rem;
    color: var(--text-secondary);
}

.export-menu-divider {
    height: 1px;
    background: var(--border-color);
    margin: 4px 6px;
}

.toolbar-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.toolbar-filters select {
    font-size: 0.84rem;
    padding: 8px 12px;
    border-radius: 8px;
    min-width: 130px;
    max-width: 190px;
}

.btn-reset-filters {
    font-size: 0.82rem;
    padding: 7px 12px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(239, 68, 68, 0.1);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-reset-filters:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.4);
    color: #fca5a5;
}

.table-card { padding: 0; overflow: hidden; }
.table-responsive { overflow-x: auto; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    text-align: right;
    font-size: 0.92rem;
}

.data-table th {
    background: rgba(255, 255, 255, 0.03);
    padding: 14px 18px;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.sortable-th {
    cursor: pointer;
    user-select: none;
    transition: all 0.2s;
}

.sortable-th:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
}

.sort-indicator {
    display: inline-block;
    margin-right: 6px;
    font-size: 0.72rem;
    opacity: 0.4;
    transition: opacity 0.2s;
}

.sortable-th.active-sort .sort-indicator {
    opacity: 1;
    color: #60a5fa;
    font-weight: bold;
}

.data-table td {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

.data-table tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

.code-cell {
    font-family: var(--font-mono);
    color: #60a5fa;
    font-weight: 600;
}

.td-value {
    display: block;
}

.service-loc-badge {
    font-size: 11px;
    color: #60a5fa;
    background: rgba(59, 130, 246, 0.12);
    border: 1px solid rgba(59, 130, 246, 0.25);
    border-radius: 6px;
    padding: 2px 8px;
    margin-top: 3px;
    display: inline-block;
    font-weight: 600;
}

/* Enhanced Pagination System */
.table-pagination {
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px;
    font-size: 0.86rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border-color);
}

.pagination-info {
    font-size: 0.86rem;
    color: var(--text-secondary);
}

.pagination-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.pagination-numbers {
    display: flex;
    align-items: center;
    gap: 4px;
}

.pagination-btn {
    min-width: 32px;
    height: 32px;
    padding: 0 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    border-radius: 7px;
    color: var(--text-secondary);
    font-size: 0.84rem;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
}

.pagination-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.2);
}

.pagination-btn.active {
    background: var(--accent-gradient, linear-gradient(135deg, #6366f1, #3b82f6));
    color: #fff;
    border-color: transparent;
    font-weight: 700;
    box-shadow: 0 0 12px rgba(99, 102, 241, 0.4);
}

.pagination-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.pagination-ellipsis {
    padding: 0 4px;
    color: var(--text-muted);
    font-weight: bold;
}

.page-size-selector-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
}

.page-size-selector-wrap select {
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 0.82rem;
}

/* --- Gemini Playground --- */
.playground-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.filter-row {
    display: flex;
    gap: 12px;
}

.playground-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 20px;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
}
.empty-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state h4 { font-size: 1.2rem; margin-bottom: 6px; }
.empty-state p { font-size: 0.9rem; color: var(--text-muted); max-width: 380px; margin: 0 auto; }

.results-ranking-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ranking-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: var(--bg-surface-elevated);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    animation: fadeIn 0.3s ease-out;
}
.ranking-rank {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(59, 130, 246, 0.2);
    color: #60a5fa;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    margin-left: 12px;
}
.ranking-details { flex: 1; }
.ranking-title { font-weight: 600; font-size: 0.95rem; }
.ranking-uni { font-size: 0.82rem; color: var(--text-muted); }
.ranking-code {
    font-family: var(--font-mono);
    padding: 4px 10px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: var(--radius-sm);
    color: #34d399;
    font-weight: 600;
}

/* --- Code Box & Alerts --- */
.code-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #06090e;
    border: 1px solid var(--border-color);
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: #60a5fa;
    margin-top: 10px;
}

.alert {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 0.88rem;
    line-height: 1.5;
}
.alert-info {
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.25);
    color: #93c5fd;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
    gap: 24px;
}

/* --- Modals --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 100;
}

.modal-dialog {
    width: 100%;
    max-width: 580px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 28px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}
.modal-close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.8rem;
    cursor: pointer;
}
.modal-close-btn:hover { color: var(--text-primary); }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
}

.drop-zone {
    border: 2px dashed rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-md);
    padding: 30px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
}
.drop-zone:hover {
    border-color: var(--color-primary);
    background: rgba(59, 130, 246, 0.05);
}
.drop-icon { width: 36px; height: 36px; margin: 0 auto 10px; color: var(--text-muted); }

.radio-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 8px;
}
.radio-label, .checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 0.9rem;
}
.radio-label input, .checkbox-label input { width: auto; margin: 0; }

/* --- Toast Notifications --- */
.toast-container {
    position: fixed;
    top: 24px;
    left: 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 9999;
}

.toast {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    border-radius: var(--radius-md);
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    min-width: 300px;
    max-width: 420px;
    font-size: 0.9rem;
    animation: slideInLeft 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideInLeft {
    from { opacity: 0; transform: translateX(-40px); }
    to { opacity: 1; transform: translateX(0); }
}

.toast-success { border-color: rgba(16, 185, 129, 0.4); color: #34d399; }
.toast-error { border-color: rgba(239, 68, 68, 0.4); color: #f87171; }
.toast-info { border-color: rgba(59, 130, 246, 0.4); color: #60a5fa; }

/* Utilities */
.hidden { display: none !important; }
.text-center { text-align: center; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 14px; }
.mt-4 { margin-top: 20px; }
.py-4 { padding-top: 16px; padding-bottom: 16px; }
.items-center { align-items: center; }
.error-text { color: #f87171; font-size: 0.85rem; margin-top: 10px; }
.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Desktop / Mobile Visibility Defaults */
.mobile-only {
    display: none !important;
}

/* Base Mobile Bottom Nav and Overlay Styles */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 62px;
    background: rgba(13, 19, 33, 0.94);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border-color);
    z-index: 900;
    display: none;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.45);
    padding: 0 6px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.mobile-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 6px 4px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: var(--font-sans);
    font-size: 0.74rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: 8px;
    -webkit-tap-highlight-color: transparent;
}

.mobile-nav-item .icon {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    transition: all 0.2s ease;
}

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

.mobile-nav-item.active {
    color: #60a5fa;
    font-weight: 700;
}

.mobile-nav-item.active .icon {
    stroke: #60a5fa;
    filter: drop-shadow(0 0 8px rgba(96, 165, 250, 0.5));
    transform: translateY(-1px);
}

.mobile-fab {
    position: fixed;
    bottom: 76px;
    left: 18px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-primary), #2563eb);
    color: white;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 20px var(--color-primary-glow);
    z-index: 850;
    border: 1px solid rgba(255, 255, 255, 0.2);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.mobile-fab:active {
    transform: scale(0.92);
}

.mobile-fab svg {
    width: 24px;
    height: 24px;
}

/* ========================================================
   Responsive Media Queries (Mobile & Tablet)
   ======================================================== */

@media (max-width: 900px) {
    .mobile-only {
        display: inline-flex !important;
    }

    .mobile-bottom-nav {
        display: flex !important;
    }

    .mobile-fab {
        display: flex !important;
    }

    .app-layout {
        position: relative;
        overflow-x: hidden;
        width: 100%;
        max-width: 100vw;
    }

    /* Off-Canvas Drawer Sidebar for Mobile (RTL: right side) */
    .sidebar {
        position: fixed !important;
        top: 0 !important;
        right: 0 !important;
        width: 280px !important;
        max-width: 82vw !important;
        height: 100vh !important;
        z-index: 1000 !important;
        background: rgba(13, 19, 33, 0.98) !important;
        backdrop-filter: blur(20px) !important;
        -webkit-backdrop-filter: blur(20px) !important;
        box-shadow: -6px 0 30px rgba(0, 0, 0, 0.7) !important;
        transform: translateX(100%);
        transition: transform 0.32s cubic-bezier(0.16, 1, 0.3, 1);
        border-left: 1px solid var(--border-color) !important;
        border-right: none !important;
    }

    .sidebar.mobile-open {
        transform: translateX(0) !important;
    }

    .main-content {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        height: 100vh;
        overflow: hidden; /* Avoid double scrolling! Only content-scroll scrolls */
    }

    .content-scroll {
        padding: 14px 12px 84px 12px !important; /* Clearance for Mobile Bottom Nav */
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        overflow-x: hidden !important;
    }

    .playground-grid,
    .settings-grid,
    .dashboard-columns {
        grid-template-columns: 1fr !important;
        gap: 14px;
        width: 100% !important;
        max-width: 100% !important;
    }

    .card, .glass-panel {
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
}

@media (max-width: 768px) {
    /* Topbar compact */
    .topbar {
        padding: 10px 14px;
        min-height: 52px;
        height: auto;
        gap: 8px;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    .topbar-left {
        gap: 8px;
        min-width: 0;
        flex: 1;
        overflow: hidden;
    }

    .topbar-left .page-title {
        font-size: 1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .topbar-right {
        gap: 6px;
        flex-shrink: 0;
    }

    .api-status-chip {
        padding: 4px 8px;
        font-size: 0.72rem;
        max-width: 130px;
    }

    .api-status-chip .status-label {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .model-badge {
        display: none !important; /* Hide model badge on small screens */
    }

    /* Compact 2x2 Stats Grid */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
        width: 100% !important;
        box-sizing: border-box !important;
        margin-bottom: 14px;
    }

    .stat-card {
        padding: 10px 10px !important;
        gap: 8px !important;
        border-radius: var(--radius-md);
        min-width: 0 !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
    }

    .stat-icon {
        width: 34px !important;
        height: 34px !important;
        border-radius: 8px;
        flex-shrink: 0 !important;
    }

    .stat-icon svg {
        width: 18px !important;
        height: 18px !important;
    }

    .stat-content {
        min-width: 0 !important;
        flex: 1 !important;
        overflow: hidden !important;
    }

    .stat-label {
        font-size: 0.72rem !important;
        line-height: 1.3;
        margin-bottom: 2px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        display: block;
        width: 100%;
    }

    .stat-value {
        font-size: 1.25rem !important;
        line-height: 1.2;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .stat-value-sm {
        font-size: 0.85rem !important;
    }

    /* Toolbar Actions & Collapsible Filters */
    .toolbar {
        padding: 10px 12px;
        gap: 8px;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    .toolbar-top {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        width: 100%;
    }

    .toolbar-search {
        min-width: 0;
        width: 100%;
    }

    .toolbar-search input {
        font-size: 0.88rem;
        padding-right: 36px;
        padding-left: 32px;
        text-overflow: ellipsis;
    }

    .toolbar-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        width: 100%;
    }

    .toolbar-actions .btn:not(.btn-icon),
    .toolbar-actions .btn-reset-filters {
        flex: 1 1 calc(50% - 6px);
        min-width: 110px;
        padding: 7px 8px;
        font-size: 0.78rem;
        justify-content: center;
        text-align: center;
        height: 36px;
        box-sizing: border-box;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .toolbar-actions .btn-icon {
        flex: 0 0 36px;
        height: 36px;
        padding: 0;
    }

    .export-dropdown-wrapper {
        flex: 1 1 calc(50% - 6px);
        min-width: 125px;
        height: 36px;
    }

    .export-split-btn {
        width: 100%;
        height: 36px;
    }

    .export-main-btn {
        flex: 1;
        height: 36px !important;
        font-size: 0.78rem !important;
        padding: 6px 8px !important;
        justify-content: center !important;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .export-toggle-btn {
        height: 36px !important;
        padding: 0 6px !important;
        width: 28px !important;
        flex-shrink: 0;
    }

    .export-menu {
        right: 0;
        left: auto;
        min-width: 210px;
        max-width: 280px;
    }

    .toolbar-filters {
        display: none;
        grid-template-columns: 1fr 1fr;
        gap: 6px;
        padding-top: 8px;
        width: 100%;
        box-sizing: border-box;
    }

    .toolbar-filters.mobile-expanded {
        display: grid;
        animation: fadeIn 0.2s ease-out;
    }

    .toolbar-filters select {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        font-size: 0.82rem;
        padding: 8px 10px;
        box-sizing: border-box;
    }

    /* Card Mode for Programs Table on Mobile */
    .table-card {
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        max-width: 100% !important;
    }

    .table-responsive {
        overflow: visible !important;
        width: 100% !important;
    }

    .data-table {
        display: block !important;
        width: 100% !important;
        background: transparent;
    }

    .data-table thead {
        display: none !important; /* Table headers hidden in card view */
    }

    .data-table tbody {
        display: block !important;
        width: 100% !important;
    }

    .data-table tr {
        display: block !important;
        width: 100% !important;
        box-sizing: border-box !important;
        margin-bottom: 12px !important;
        background: var(--bg-surface-elevated) !important;
        border: 1px solid var(--border-color) !important;
        border-radius: var(--radius-md) !important;
        padding: 12px 14px !important;
        box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25) !important;
        overflow: hidden !important;
    }

    .data-table tr:hover td {
        background: transparent !important;
    }

    .data-table td {
        display: flex !important;
        justify-content: space-between !important;
        align-items: flex-start !important;
        gap: 8px !important;
        padding: 7px 0 !important;
        border-bottom: 1px dashed rgba(255, 255, 255, 0.08) !important;
        font-size: 0.86rem !important;
        width: 100% !important;
        box-sizing: border-box !important;
        min-width: 0 !important;
    }

    .data-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary);
        font-size: 0.78rem;
        text-align: right;
        flex-shrink: 0;
        min-width: 80px;
        max-width: 105px;
        padding-top: 1px;
    }

    .data-table td .td-value {
        flex: 1;
        min-width: 0;
        text-align: left;
        display: flex;
        flex-direction: column;
        align-items: flex-end;
        word-break: break-word;
        overflow-wrap: break-word;
    }

    /* Program Title: Prominent Card Header */
    .data-table td.title-cell {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 2px !important;
        padding-top: 2px !important;
        padding-bottom: 8px !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.15) !important;
    }

    .data-table td.title-cell::before {
        display: none !important;
    }

    .data-table td.title-cell .td-value {
        align-items: flex-start !important;
        text-align: right !important;
        font-size: 1rem !important;
        font-weight: 700 !important;
        color: #ffffff !important;
        line-height: 1.4 !important;
    }

    /* University Stack */
    .data-table td.uni-cell .td-value {
        align-items: flex-end;
    }

    .data-table td.uni-cell .uni-name {
        font-weight: 600;
        color: #e2e8f0;
    }

    /* Operations Buttons */
    .data-table td.actions-cell {
        border-bottom: none !important;
        padding-top: 10px !important;
        padding-bottom: 2px !important;
        justify-content: flex-end !important;
        align-items: center !important;
    }

    .data-table td.actions-cell::before {
        display: none !important;
    }

    .data-table td.actions-cell .td-value {
        flex-direction: row !important;
        align-items: center !important;
        justify-content: flex-end !important;
        gap: 8px !important;
    }

    /* Table Pagination on Mobile */
    .table-pagination {
        flex-direction: column;
        align-items: center;
        gap: 10px;
        padding: 12px 10px;
        width: 100%;
        box-sizing: border-box;
    }

    .pagination-info {
        font-size: 0.8rem;
        text-align: center;
        width: 100%;
    }

    .pagination-controls {
        flex-wrap: wrap;
        justify-content: center;
        gap: 4px;
        width: 100%;
        max-width: 100%;
    }

    .pagination-numbers {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 3px;
    }

    .pagination-btn {
        min-width: 28px;
        height: 28px;
        padding: 0 6px;
        font-size: 0.78rem;
    }

    .page-size-selector-wrap {
        width: 100%;
        justify-content: center;
        font-size: 0.8rem;
    }

    /* Dashboard & Quick Actions */
    .card {
        padding: 16px 14px;
        max-width: 100%;
        box-sizing: border-box;
    }

    .breakdown-item {
        padding: 8px 10px;
        font-size: 0.85rem;
    }

    .breakdown-item span:first-child {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .quick-actions-bar {
        display: grid;
        grid-template-columns: 1fr;
        gap: 8px;
        width: 100%;
    }

    .quick-actions-bar .btn {
        width: 100%;
        justify-content: flex-start;
        padding: 9px 12px;
        font-size: 0.85rem;
    }

    /* Playground & Settings on Mobile */
    .filter-row {
        flex-direction: column;
        gap: 8px;
        width: 100%;
    }

    .playground-buttons {
        flex-direction: column;
        width: 100%;
        gap: 8px;
    }

    .playground-buttons .btn {
        width: 100%;
    }

    .ranking-card {
        gap: 8px;
        padding: 12px;
        width: 100%;
        box-sizing: border-box;
    }

    .ranking-details {
        min-width: 0;
        flex: 1;
        overflow: hidden;
    }

    .ranking-title {
        word-break: break-word;
        overflow-wrap: break-word;
    }

    .code-box {
        max-width: 100%;
        overflow: hidden;
        gap: 8px;
        padding: 10px 12px;
    }

    .code-box code {
        word-break: break-all;
        overflow-wrap: anywhere;
        min-width: 0;
        font-size: 0.82rem;
    }

    .alert {
        word-break: break-word;
        overflow-wrap: anywhere;
        max-width: 100%;
        padding: 10px 12px;
        font-size: 0.82rem;
    }

    /* Modals Responsive */
    .modal-overlay {
        padding: 10px;
    }

    .modal-dialog {
        width: calc(100vw - 20px) !important;
        max-width: 100% !important;
        max-height: 88vh;
        padding: 16px 14px;
        margin: 0;
        border-radius: var(--radius-md);
        box-sizing: border-box;
    }

    .form-row {
        flex-direction: column;
        gap: 8px;
    }

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

    .form-group label {
        font-size: 0.8rem;
    }

    input, select, textarea {
        font-size: 16px; /* Prevents auto-zoom in mobile Safari */
        padding: 9px 11px;
    }

    .modal-footer {
        flex-direction: column-reverse;
        gap: 8px;
    }

    .modal-footer .btn {
        width: 100%;
    }

    /* Toast on mobile */
    .toast-container {
        top: 10px;
        left: 10px;
        right: 10px;
    }

    .toast {
        min-width: 0;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
}

@media (max-width: 440px) {
    .toolbar-filters {
        grid-template-columns: 1fr !important;
    }

    .toolbar-actions .btn:not(.btn-icon),
    .toolbar-actions .btn-reset-filters {
        flex: 1 1 100%;
    }
}

