/* ── Base ── */
:root {
    --bg: #0f1117;
    --bg2: #1a1d27;
    --bg3: #242836;
    --border: #2d3148;
    --text: #e4e6f0;
    --text2: #9498b0;
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;
    --radius: 8px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

/* ── Layout ── */
.app {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background: var(--bg2);
    border-right: 1px solid var(--border);
    padding: 20px 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-header {
    padding: 0 20px 20px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 10px;
}

.sidebar-header h1 {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
}

.sidebar-header small {
    color: var(--text2);
    font-size: 12px;
}

.nav-section {
    padding: 8px 12px;
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text2);
    letter-spacing: 1px;
    margin-top: 12px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: var(--text2);
    cursor: pointer;
    transition: all 0.15s;
    border-left: 3px solid transparent;
}

.nav-item:hover, .nav-item.active {
    background: var(--bg3);
    color: var(--text);
    border-left-color: var(--primary);
}

.main {
    flex: 1;
    margin-left: 260px;
    padding: 24px 32px;
}

/* ── Cards ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.stat-card .label {
    font-size: 13px;
    color: var(--text2);
    margin-bottom: 6px;
}

.stat-card .value {
    font-size: 28px;
    font-weight: 700;
}

/* ── Tables ── */
.table-container {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

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

thead { background: var(--bg3); }

th, td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    font-size: 12px;
    text-transform: uppercase;
    color: var(--text2);
    letter-spacing: 0.5px;
    font-weight: 600;
}

td { font-size: 14px; }

tr:hover { background: rgba(99, 102, 241, 0.05); }

/* ── Forms ── */
.form-group {
    margin-bottom: 16px;
}

label {
    display: block;
    font-size: 13px;
    color: var(--text2);
    margin-bottom: 6px;
    font-weight: 500;
}

input, select, textarea {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
}

textarea {
    min-height: 120px;
    resize: vertical;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { opacity: 0.85; }
.btn-success { background: var(--success); color: white; }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

/* ── Badges ── */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}

.badge-success { background: rgba(34,197,94,0.15); color: var(--success); }
.badge-danger { background: rgba(239,68,68,0.15); color: var(--danger); }
.badge-warning { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-info { background: rgba(59,130,246,0.15); color: var(--info); }

/* ── Toolbar ── */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    gap: 12px;
    flex-wrap: wrap;
}

.search-box {
    max-width: 300px;
}

/* ── Modal ── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 100;
    justify-content: center;
    align-items: center;
}

.modal-overlay.active { display: flex; }

.modal {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal h2 {
    margin-bottom: 16px;
    font-size: 18px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
}

/* ── Code / Result ── */
.result-box {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    white-space: pre-wrap;
    max-height: 400px;
    overflow-y: auto;
    margin-top: 12px;
}

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

.login-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
}

.login-card h1 {
    text-align: center;
    margin-bottom: 8px;
    color: var(--primary);
}

.login-card p {
    text-align: center;
    color: var(--text2);
    margin-bottom: 24px;
    font-size: 14px;
}

/* ── Toast ── */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 14px;
    animation: slideIn 0.3s ease;
    max-width: 400px;
}

.toast-success { background: var(--success); color: white; }
.toast-error { background: var(--danger); color: white; }
.toast-info { background: var(--info); color: white; }

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

/* ── Pagination ── */
.pagination {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 16px;
}

.pagination button {
    padding: 6px 14px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
}

.pagination button.active {
    background: var(--primary);
    border-color: var(--primary);
}

/* ── Progress Bar ── */
.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--bg);
    border-radius: 4px;
    overflow: hidden;
    margin: 8px 0;
}

.progress-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.progress-bar-fill.success { background: var(--success); }
.progress-bar-fill.error { background: var(--danger); }

/* ── Model Card ── */
.model-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 12px;
    transition: border-color 0.15s;
}

.model-card:hover { border-color: var(--primary); }

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

.model-card-header h4 { font-size: 16px; font-weight: 600; }

.model-card-info {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    font-size: 13px;
    color: var(--text2);
    margin-bottom: 12px;
}

.model-card-info span { display: flex; align-items: center; gap: 4px; }

.model-card-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.btn-warning { background: var(--warning); color: #000; }
.btn-warning:hover { opacity: 0.85; }

.model-status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
}

.model-status-dot.running { background: var(--success); box-shadow: 0 0 6px var(--success); }
.model-status-dot.ready { background: var(--info); }
.model-status-dot.downloading { background: var(--warning); animation: pulse 1.5s infinite; }
.model-status-dot.loading { background: var(--warning); animation: pulse 1s infinite; }
.model-status-dot.error { background: var(--danger); }
.model-status-dot.not_downloaded { background: var(--text2); }
.model-status-dot.stopping { background: var(--warning); }

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

.ollama-banner {
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.tab-bar {
    display: flex;
    gap: 4px;
    background: var(--bg3);
    border-radius: var(--radius);
    padding: 4px;
    margin-bottom: 20px;
}

.tab-bar button {
    padding: 8px 20px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text2);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}

.tab-bar button.active {
    background: var(--primary);
    color: white;
}

.tab-bar button:hover:not(.active) {
    color: var(--text);
    background: rgba(99, 102, 241, 0.1);
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .main { margin-left: 0; padding: 16px; }
}
