/* ================================================================
   میزبان (Host) - Stylesheet
   طراحی مدرن، راست‌چین، تاریک/روشن، واکنش‌گرا
   ================================================================ */

:root {
    --bg:           #0f1117;
    --bg-soft:      #161922;
    --bg-card:      #1c2030;
    --bg-hover:     #232838;
    --border:       #2a2f42;
    --text:         #e8eaf2;
    --text-soft:    #9ca3b8;
    --text-muted:   #6b7283;
    --primary:      #10b981;
    --primary-soft: #0d9668;
    --primary-glow: rgba(16, 185, 129, .15);
    --warn:         #f59e0b;
    --error:        #ef4444;
    --info:         #3b82f6;
    --purple:       #8b5cf6;
    --radius:       14px;
    --radius-sm:    8px;
    --shadow:       0 4px 24px rgba(0,0,0,.35);
    --shadow-sm:    0 2px 8px rgba(0,0,0,.2);
    --font: 'Vazirmatn', 'Segoe UI', Tahoma, system-ui, -apple-system, sans-serif;
    --mono: 'Fira Code', 'Courier New', monospace;
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    font-size: 14px;
    min-height: 100vh;
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-soft); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

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

.sidebar {
    width: 250px;
    background: var(--bg-soft);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; right: 0; bottom: 0;
    z-index: 100;
    transition: transform .3s ease;
}

.main {
    flex: 1;
    margin-right: 250px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-width: 0;
}

.content {
    flex: 1;
    padding: 24px;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
}

/* ================================================================
   Sidebar
   ================================================================ */
.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 18px;
    border-bottom: 1px solid var(--border);
}
.logo-icon {
    width: 44px; height: 44px;
    background: linear-gradient(135deg, var(--primary), var(--primary-soft));
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px; font-weight: 800; color: #fff;
    box-shadow: 0 4px 12px var(--primary-glow);
}
.logo-title { font-size: 18px; font-weight: 700; }
.logo-sub { font-size: 11px; color: var(--text-muted); }

.nav {
    flex: 1;
    padding: 16px 10px;
    overflow-y: auto;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    color: var(--text-soft);
    text-decoration: none;
    border-radius: var(--radius-sm);
    margin-bottom: 4px;
    font-size: 14px;
    font-weight: 500;
    transition: all .15s;
    cursor: pointer;
}
.nav-item span { font-size: 18px; width: 22px; text-align: center; }
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active {
    background: var(--primary-glow);
    color: var(--primary);
    border-left: 3px solid var(--primary);
    padding-right: 11px;
}

.sidebar-footer {
    padding: 14px;
    border-top: 1px solid var(--border);
}
.status-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: var(--text-soft);
    margin-top: 8px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot-ok { background: var(--primary); box-shadow: 0 0 8px var(--primary); }

/* ================================================================
   Topbar
   ================================================================ */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: var(--bg-soft);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
    backdrop-filter: blur(8px);
}
.topbar h1 { font-size: 20px; font-weight: 700; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.time {
    font-family: var(--mono);
    font-size: 13px;
    color: var(--text-soft);
    background: var(--bg-card);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
}
.menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text);
    font-size: 22px;
    cursor: pointer;
}

/* ================================================================
   Views
   ================================================================ */
.view { display: none; animation: fadeIn .25s ease; }
.view.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* Login */
.view-login {
    max-width: 420px;
    margin: 80px auto;
    padding: 0 16px;
}
.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px 32px;
    box-shadow: 0 8px 32px rgba(0,0,0,.4);
}
.login-icon {
    font-size: 56px;
    text-align: center;
    margin-bottom: 16px;
    width: 80px;
    height: 80px;
    margin-left: auto;
    margin-right: auto;
    background: linear-gradient(135deg, var(--primary), var(--primary-soft));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px var(--primary-glow);
}
.login-card h2 {
    text-align: center;
    margin-bottom: 8px;
    font-size: 20px;
    font-weight: 700;
}
.login-card .muted { text-align: center; margin-bottom: 20px; }
.login-card .field { margin-bottom: 18px; }
.login-card .field label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    color: var(--text-soft);
    font-weight: 500;
}
.login-card .field input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-size: 15px;
    font-family: var(--font);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.login-card .field input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}
.login-card .field input::placeholder { color: var(--text-muted); }
.login-card .btn-primary {
    width: 100%;
    padding: 12px;
    font-size: 15px;
    margin-top: 8px;
}
.login-card .alert {
    margin-top: 16px;
    text-align: center;
    font-size: 12px;
    padding: 10px 14px;
}

/* ================================================================
   Cards
   ================================================================ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 20px;
    overflow: hidden;
}
.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 12px;
}
.card-head h3 { font-size: 16px; font-weight: 600; }
.card-body { padding: 20px; }

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

/* ================================================================
   Stats
   ================================================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}
.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: transform .15s, box-shadow .15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.stat-icon {
    width: 46px; height: 46px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px;
    background: var(--bg-hover);
}
.stat-label { font-size: 12px; color: var(--text-muted); }
.stat-value { font-size: 26px; font-weight: 800; font-family: var(--mono); }
.stat-queued .stat-icon { background: rgba(245,158,11,.15); }
.stat-processing .stat-icon { background: rgba(59,130,246,.15); }
.stat-completed .stat-icon { background: rgba(16,185,129,.15); }
.stat-failed .stat-icon { background: rgba(239,68,68,.15); }
.stat-total .stat-icon { background: rgba(139,92,246,.15); }

/* ================================================================
   Forms
   ================================================================ */
.field { margin-bottom: 16px; }
.field label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    color: var(--text-soft);
    font-weight: 500;
}
.input, .select {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 14px;
    font-family: var(--font);
    transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}
textarea.input { resize: vertical; min-height: 80px; font-family: var(--font); }

/* ================================================================
   Buttons
   ================================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: all .15s;
    text-decoration: none;
    white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 8px var(--primary-glow);
}
.btn-primary:hover:not(:disabled) { background: var(--primary-soft); transform: translateY(-1px); }
.btn-ghost {
    background: transparent;
    border-color: var(--border);
    color: var(--text-soft);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-block { width: 100%; }

/* ================================================================
   Tables
   ================================================================ */
.table-wrap { overflow-x: auto; max-height: 540px; overflow-y: auto; }
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.table th {
    text-align: right;
    padding: 12px 14px;
    background: var(--bg-soft);
    color: var(--text-soft);
    font-weight: 600;
    font-size: 12px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 1;
    white-space: nowrap;
}
.table td {
    padding: 11px 14px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}
.table tr:hover td { background: var(--bg-hover); }
.table .loading, .table .empty { text-align: center; padding: 40px; color: var(--text-muted); }

/* ================================================================
   Badges & Chips
   ================================================================ */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}
.badge-ok { background: rgba(16,185,129,.15); color: var(--primary); }
.badge-warn { background: rgba(245,158,11,.15); color: var(--warn); }
.badge-error { background: rgba(239,68,68,.15); color: var(--error); }
.badge-info { background: rgba(59,130,246,.15); color: var(--info); }
.badge-muted { background: var(--bg-hover); color: var(--text-muted); }

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}
.status-pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; }
.sp-queued { background: rgba(245,158,11,.15); color: var(--warn); }
.sp-queued::before { background: var(--warn); }
.sp-processing { background: rgba(59,130,246,.15); color: var(--info); }
.sp-processing::before { background: var(--info); animation: pulse 1.2s infinite; }
.sp-running { background: rgba(59,130,246,.15); color: var(--info); }
.sp-running::before { background: var(--info); animation: pulse 1.2s infinite; }
.sp-dead { background: rgba(107,114,128,.18); color: #6b7283; }
.sp-dead::before { background: #6b7283; }
.sp-retry { background: rgba(245,158,11,.18); color: var(--warn); }
.sp-retry::before { background: var(--warn); animation: pulse 1.5s infinite; }
.sp-delayed { background: rgba(139,92,246,.15); color: #8b5cf6; }
.sp-delayed::before { background: #8b5cf6; }
.sp-completed { background: rgba(16,185,129,.15); color: var(--primary); }
.sp-completed::before { background: var(--primary); }
.sp-failed { background: rgba(239,68,68,.15); color: var(--error); }
.sp-failed::before { background: var(--error); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }

.chip {
    display: inline-block;
    padding: 4px 10px;
    background: var(--bg-hover);
    border-radius: var(--radius-sm);
    font-size: 12px;
    margin: 2px;
    border: 1px solid var(--border);
    font-family: var(--mono);
}

.priority-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    padding: 2px 8px;
    border-radius: 6px;
    font-weight: 700;
    font-size: 12px;
    font-family: var(--mono);
}
.p-low { background: rgba(107,114,131,.2); color: var(--text-muted); }
.p-mid { background: rgba(59,130,246,.15); color: var(--info); }
.p-high { background: rgba(245,158,11,.15); color: var(--warn); }
.p-max { background: rgba(239,68,68,.15); color: var(--error); }

/* ================================================================
   Worker items
   ================================================================ */
.worker-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    background: var(--bg-soft);
}
.worker-name { font-weight: 600; }
.worker-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.worker-detail {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-bottom: 16px;
    background: var(--bg-soft);
}
.worker-detail-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.worker-meta-row { margin: 8px 0; font-size: 13px; }
.worker-meta-row code { font-family: var(--mono); background: var(--bg); padding: 2px 6px; border-radius: 4px; font-size: 12px; }
.actions-list { margin-top: 6px; }

/* ================================================================
   Logs
   ================================================================ */
.log-list {
    max-height: 600px;
    overflow-y: auto;
    font-family: var(--mono);
    font-size: 12px;
}
.log-entry {
    display: flex;
    gap: 10px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    align-items: flex-start;
}
.log-time { color: var(--text-muted); white-space: nowrap; flex-shrink: 0; }
.log-level {
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 10px;
    flex-shrink: 0;
    min-width: 44px;
    text-align: center;
}
.log-level.info { background: rgba(59,130,246,.15); color: var(--info); }
.log-level.warn { background: rgba(245,158,11,.15); color: var(--warn); }
.log-level.error { background: rgba(239,68,68,.15); color: var(--error); }
.log-msg { flex: 1; word-break: break-word; }
.log-ctx { color: var(--text-muted); font-size: 11px; }

/* ================================================================
   Code blocks
   ================================================================ */
.code {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    font-family: var(--mono);
    font-size: 12px;
    overflow-x: auto;
    direction: ltr;
    text-align: left;
    white-space: pre;
    color: #a5d6ff;
    margin: 8px 0;
}

/* ================================================================
   Result box
   ================================================================ */
.result-box {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    font-family: var(--mono);
    font-size: 12px;
    min-height: 200px;
    max-height: 500px;
    overflow: auto;
    direction: ltr;
    text-align: left;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ================================================================
   Alerts
   ================================================================ */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    border: 1px solid;
}
.alert-warn { background: rgba(245,158,11,.1); border-color: rgba(245,158,11,.3); color: var(--warn); }
.alert-info { background: rgba(59,130,246,.1); border-color: rgba(59,130,246,.3); color: var(--info); }
.alert code { font-family: var(--mono); background: rgba(255,255,255,.08); padding: 1px 5px; border-radius: 3px; }

.muted { color: var(--text-muted); }
.loading { text-align: center; padding: 30px; color: var(--text-muted); }

/* ================================================================
   Filter bar
   ================================================================ */
.filter-bar { display: flex; gap: 8px; align-items: center; }
.filter-bar .select { width: auto; min-width: 130px; padding: 6px 10px; font-size: 12px; }

/* ================================================================
   Modal
   ================================================================ */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.65);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal.active { display: flex; animation: fadeIn .2s; }
.modal-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
}
.modal-lg { max-width: 760px; }
.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 16px; }
.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    width: 32px; height: 32px;
    border-radius: 6px;
}
.modal-close:hover { background: var(--bg-hover); color: var(--text); }
.modal-body { padding: 20px; overflow-y: auto; }

/* ================================================================
   Toast
   ================================================================ */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(120px);
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 12px 22px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    z-index: 2000;
    transition: transform .3s;
    font-size: 13px;
    font-weight: 500;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.success { border-color: var(--primary); }
.toast.error { border-color: var(--error); }

/* ================================================================
   Footer
   ================================================================ */
.footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    background: var(--bg-soft);
    margin-top: auto;
}

/* ================================================================
   Docs
   ================================================================ */
.docs h4 { margin: 18px 0 8px; color: var(--primary); font-size: 15px; }
.docs h4:first-child { margin-top: 0; }
.docs p { margin-bottom: 8px; color: var(--text-soft); }
.docs ol, .docs ul { margin: 8px 20px; color: var(--text-soft); }
.docs li { margin: 4px 0; }
.docs code { font-family: var(--mono); background: var(--bg); padding: 2px 6px; border-radius: 4px; font-size: 12px; color: #a5d6ff; }

/* ================================================================
   Responsive
   ================================================================ */
@media (max-width: 1024px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
    .sidebar { transform: translateX(100%); }
    .sidebar.open { transform: translateX(0); }
    .main { margin-right: 0; }
    .menu-toggle { display: block; }
    .stats-grid { grid-template-columns: 1fr; }
    .content { padding: 16px; }
    .topbar { padding: 12px 16px; }
    .topbar h1 { font-size: 16px; }
}

@media (max-width: 480px) {
    .card-head { flex-direction: column; align-items: flex-start; }
    .filter-bar { width: 100%; }
}

/* Animation utilities */
.spin { display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.copy-btn {
    background: var(--bg-hover);
    border: 1px solid var(--border);
    color: var(--text-soft);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11px;
    cursor: pointer;
    font-family: var(--font);
}
.copy-btn:hover { background: var(--bg-card); color: var(--text); }

/* ================================================================
   Switch Toggle (for enable/disable)
   ================================================================ */
.switch {
    position: relative;
    display: inline-block;
    width: 42px;
    height: 22px;
    flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    transition: .2s;
    border-radius: 22px;
}
.slider::before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    right: 3px;
    top: 2px;
    background: var(--text-muted);
    transition: .2s;
    border-radius: 50%;
}
.switch input:checked + .slider {
    background: var(--primary-glow);
    border-color: var(--primary);
}
.switch input:checked + .slider::before {
    transform: translateX(-20px);
    background: var(--primary);
}

/* ================================================================
   Provider / Model cards
   ================================================================ */
.provider-card, .model-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    margin-bottom: 10px;
    background: var(--bg-soft);
}
.provider-head, .model-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    gap: 12px;
}
.provider-name, .model-name { font-weight: 600; font-size: 15px; }
.provider-meta, .model-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.provider-url { font-size: 13px; }
.provider-actions, .model-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.key-group {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    margin-bottom: 14px;
    background: var(--bg-soft);
}
.key-group h4 { margin-bottom: 10px; font-size: 14px; }

.req-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    gap: 10px;
}
