:root {
  color-scheme: dark;
  --bg: #0b1020;
  --surface: #121a30;
  --surface-2: #182342;
  --border: #26355d;
  --text: #e8eefc;
  --muted: #93a4cc;
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --scrollbar-thumb: #334678;
  --scrollbar-track: #0f162a;

  accent-color: var(--accent);
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

@supports not (scrollbar-color: auto) {
  * {
    scrollbar-width: auto;
  }
  ::-webkit-scrollbar {
    width: 10px;
    height: 10px;
  }
  ::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 6px;
  }
  ::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.mono {
  font-family: "Cascadia Code", Consolas, "Courier New", monospace;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-dot {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  font-size: 1.2rem;
}

.brand-title {
  margin: 0;
  font-size: 1.08rem;
  letter-spacing: 0.2px;
}

.brand-sub {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  padding: 0.48rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.88rem;
}

.tab:hover {
  color: var(--text);
  background: var(--surface-2);
}

.tab.active {
  color: #031525;
  background: var(--accent);
}

.controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.badge {
  font-size: 0.78rem;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.badge-ok {
  border-color: var(--ok);
  color: var(--ok);
}

.badge-err {
  border-color: var(--danger);
  color: var(--danger);
}

.main {
  flex: 1;
  padding: 1rem 1.25rem;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.panel {
  display: none;
  flex: 1;
  flex-direction: column;
  gap: 0.9rem;
}

.panel.active {
  display: flex;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.85rem;
  padding: 0.7rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.88rem;
}

.field-col {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  font-size: 0.88rem;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.88rem;
  cursor: pointer;
}

input[type="text"],
select,
textarea {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  font-size: 0.9rem;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 0.52rem 1rem;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.88rem;
}

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

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

.btn-primary:hover:not(:disabled) {
  background: var(--accent-strong);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-danger {
  background: rgba(248, 113, 113, 0.16);
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.4);
}

.chat-feed {
  flex: 1;
  min-height: 360px;
  max-height: 62vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.msg {
  padding: 0.8rem 1rem;
  border-radius: 10px;
  max-width: 86%;
  white-space: pre-wrap;
  line-height: 1.55;
  font-size: 0.94rem;
}

.msg-user {
  align-self: flex-end;
  background: #1d3566;
  border: 1px solid #30559c;
}

.msg-assistant {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.msg-meta {
  font-size: 0.75rem;
  color: var(--accent);
  margin-bottom: 0.35rem;
  display: block;
}

.chat-input-bar {
  display: flex;
  gap: 0.6rem;
}

.chat-input-bar textarea {
  flex: 1;
  resize: vertical;
}

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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.card h2 {
  margin: 0;
  font-size: 1rem;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.grow {
  flex: 1;
}

.sep {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.25rem 0;
}

.status-line {
  margin: 0;
  font-size: 0.85rem;
  color: var(--ok);
  min-height: 1.2em;
}

.results-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-height: 360px;
  overflow-y: auto;
}

.result-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.8rem;
  font-size: 0.86rem;
}

.result-head {
  display: flex;
  justify-content: space-between;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 0.3rem;
}

.workspace-grid {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1rem;
  min-height: 520px;
}

@media (max-width: 820px) {
  .workspace-grid {
    grid-template-columns: 1fr;
  }
}

.file-tree {
  overflow-y: auto;
  max-height: 64vh;
  gap: 0.2rem;
}

.tree-item {
  display: block;
  width: 100%;
  text-align: start;
  background: transparent;
  color: var(--text);
  border: none;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}

.tree-item:hover {
  background: var(--surface-2);
}

.tree-dir {
  color: var(--warn);
  font-weight: 600;
  cursor: default;
}

.editor-pane {
  min-height: 520px;
}

.code-editor {
  flex: 1;
  min-height: 400px;
  width: 100%;
  resize: vertical;
  line-height: 1.45;
}

.terminal-out {
  background: #060913;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.8rem;
  min-height: 320px;
  max-height: 56vh;
  overflow: auto;
  margin: 0;
  font-size: 0.84rem;
  white-space: pre-wrap;
}

.terminal-out-sm {
  background: #060913;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem;
  min-height: 110px;
  max-height: 220px;
  overflow: auto;
  margin: 0;
  font-size: 0.8rem;
  white-space: pre-wrap;
}

.ver-pill {
  font-size: 0.72rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.18);
  color: var(--accent);
  vertical-align: middle;
}

.hidden {
  display: none !important;
}

.wrap {
  flex-wrap: wrap;
}

.models-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 0.85rem;
}

.model-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.model-card.running {
  border-color: var(--ok);
  box-shadow: 0 0 0 1px rgba(52, 211, 153, 0.25);
}

.pill {
  font-size: 0.72rem;
  padding: 0.18rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
}

.pill-ok {
  border-color: var(--ok);
  color: var(--ok);
}

.pill-accent {
  border-color: var(--accent);
  color: var(--accent);
}

input[type="number"] {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  font-size: 0.9rem;
}

/* ---------- Voice conversation ---------- */
.voice-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.8rem;
  margin: 0.4rem 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
}
.voice-bar.hidden { display: none; }
.voice-state { font-weight: 600; }
.voice-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}
.voice-bar[data-state="listening"] .voice-dot { background: var(--ok); animation: voice-pulse 1.6s ease-in-out infinite; }
.voice-bar[data-state="hearing"] .voice-dot { background: var(--danger); animation: voice-pulse 0.6s ease-in-out infinite; }
.voice-bar[data-state="transcribing"] .voice-dot,
.voice-bar[data-state="thinking"] .voice-dot { background: var(--warn); animation: voice-pulse 1s ease-in-out infinite; }
.voice-bar[data-state="speaking"] .voice-dot { background: var(--accent); animation: voice-pulse 0.8s ease-in-out infinite; }
.voice-bar[data-state="error"] { border-color: var(--danger); }
.voice-bar[data-state="error"] .voice-dot { background: var(--danger); }
.voice-switch { font-size: 1.05rem; font-weight: 600; }
@keyframes voice-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.45); opacity: 0.55; }
}
@media (prefers-reduced-motion: reduce) {
  .voice-dot { animation: none !important; }
}

/* === NAWAT Model Evaluation & 13-Column Telemetry === */
.eval-controls-card {
  margin-bottom: 1rem;
}
.eval-picker-block {
  margin-top: 0.75rem;
}
.eval-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}
.eval-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.32rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 0.84rem;
  cursor: pointer;
}
.eval-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.eval-summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem 1rem;
}
.eval-kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.4rem;
  margin-top: 0.65rem;
  font-size: 0.84rem;
}
.eval-kpi-row > div {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.eval-table-wrap {
  width: 100%;
  overflow-x: auto;
}
.eval-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  white-space: nowrap;
}
.eval-table th,
.eval-table td {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  text-align: start;
}
.eval-table th {
  color: var(--muted);
  font-weight: 600;
  background: var(--surface-2);
  position: sticky;
  top: 0;
}
.eval-table tbody tr:hover {
  background: rgba(56, 189, 248, 0.06);
}
.eval-table td.num {
  text-align: end;
}
.eval-pill {
  display: inline-block;
  padding: 0.16rem 0.5rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.eval-st-pass {
  background: rgba(52, 211, 153, 0.16);
  color: var(--ok);
  border: 1px solid rgba(52, 211, 153, 0.4);
}
.eval-st-warn {
  background: rgba(251, 191, 36, 0.16);
  color: var(--warn);
  border: 1px solid rgba(251, 191, 36, 0.4);
}
.eval-st-fail {
  background: rgba(248, 113, 113, 0.16);
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.4);
}
.eval-capture-btn {
  padding: 0.22rem 0.55rem;
  font-size: 0.78rem;
}
.eval-modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 18, 0.78);
  display: grid;
  place-items: center;
  z-index: 1000;
  padding: 1rem;
}
.eval-modal.hidden {
  display: none;
}
.eval-modal-box {
  width: min(820px, 95vw);
  max-height: 88vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.eval-modal-section pre {
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 220px;
  overflow-y: auto;
}


/* ===== NAWAT Smart Engine v2.1 — Right Sidebar Dedicated Pages Layout ===== */
.studio-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: calc(100vh - 72px);
}
html[dir="rtl"] .studio-shell {
  direction: rtl;
}
.right-sidebar {
  background: rgba(10, 15, 28, 0.92);
  border-inline-end: 1px solid var(--border);
  padding: 1rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.sidebar-heading {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0 0.4rem;
}
.sidebar-tabs {
  display: flex !important;
  flex-direction: column !important;
  gap: 0.4rem !important;
  width: 100%;
}
.sidebar-tabs .tab {
  width: 100%;
  text-align: start;
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
  padding: 0.65rem 0.85rem;
  border-radius: 12px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.02);
  transition: all 0.16s ease;
}
.sidebar-tabs .tab:hover {
  border-color: rgba(56, 189, 248, 0.35);
  background: rgba(56, 189, 248, 0.08);
}
.sidebar-tabs .tab.active {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.16);
  box-shadow: 0 0 18px rgba(56, 189, 248, 0.14);
}
.sidebar-tabs .tab .tab-en {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
  opacity: 0.9;
  direction: ltr;
  text-align: start;
}
.sidebar-tabs .tab .tab-ar {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text);
}
.sidebar-footer {
  margin-top: auto;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.sidebar-ext-link {
  display: block;
  padding: 0.5rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 600;
}
.sidebar-ext-link:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.eval-action-stack {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-top: 0.85rem;
}
.eval-big-btn {
  width: 100%;
  padding: 0.72rem 1rem !important;
  font-size: 0.95rem !important;
  font-weight: 700 !important;
}
.eval-result-drawer {
  margin-top: 0.85rem;
  padding: 0.9rem;
  border-radius: 14px;
  border: 1px solid rgba(56, 189, 248, 0.45);
  background: rgba(15, 23, 42, 0.75);
}
.eval-result-drawer.hidden { display: none; }
@media (max-width: 900px) {
  .studio-shell { grid-template-columns: 1fr; }
  .right-sidebar { border-inline-end: none; border-bottom: 1px solid var(--border); }
  .sidebar-tabs { flex-direction: row !important; flex-wrap: wrap; }
  .sidebar-tabs .tab { width: auto; }
}


/* ===== Advanced Organized Pill Controls for Chat & Multi-Model Bar ===== */
#panel-chat .toolbar {
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.7rem 0.9rem;
  gap: 0.65rem;
}
#panel-chat .checkbox-field {
  padding: 0.42rem 0.78rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.16s ease;
}
#panel-chat .checkbox-field:has(input:checked) {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.16);
  color: #e0f2fe;
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.18);
}


/* ===== UNIFIED NAWAT MODEL DROPDOWN WITH CHECKBOXES (ALL PAGES) ===== */
.nawat-dd-wrap {
  position: relative;
  display: inline-block;
  min-width: 310px;
  max-width: 100%;
}
.nawat-dd-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.58rem 0.9rem;
  border-radius: 12px;
  border: 1.5px solid rgba(56, 189, 248, 0.55);
  background: #0f1b2e;
  color: #f8fafc;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.14);
}
.nawat-dd-trigger:hover {
  border-color: #38bdf8;
  background: #14243d;
}
.nawat-dd-menu {
  position: absolute;
  top: calc(100% + 6px);
  inset-inline-start: 0;
  width: min(420px, 92vw);
  max-height: 360px;
  background: #132136;
  border: 1px solid rgba(56, 189, 248, 0.45);
  border-radius: 12px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.65);
  z-index: 1200;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.nawat-dd-menu.hidden { display: none; }
.nawat-dd-head {
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  gap: 0.4rem;
  align-items: center;
  background: #0d1726;
}
.nawat-dd-head input {
  flex: 1;
  padding: 0.35rem 0.55rem;
  font-size: 0.8rem;
  border-radius: 8px;
}
.nawat-dd-list {
  overflow-y: auto;
  max-height: 295px;
  padding: 0.25rem 0;
}
.nawat-dd-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  padding: 0.46rem 0.8rem;
  cursor: pointer;
  font-size: 0.84rem;
  color: #e2e8f0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  transition: background 0.12s;
}
.nawat-dd-item:hover {
  background: rgba(56, 189, 248, 0.14);
}
.nawat-dd-item.checked {
  background: rgba(56, 189, 248, 0.2);
  color: #ffffff;
}
.nawat-dd-item input[type="checkbox"] {
  width: 17px;
  height: 17px;
  accent-color: #38bdf8;
  cursor: pointer;
  flex-shrink: 0;
}
.nawat-dd-label {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  direction: ltr;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
}
.nawat-dd-ghn {
  color: #38bdf8;
  font-weight: 800;
  white-space: nowrap;
}


/* ===== LIVE MODEL READINESS TRAY (Status Dots: Waiting / Loading / Green Ready) ===== */
.eval-warmup-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 0.75rem;
  padding: 0.7rem 0.85rem;
  border-radius: 12px;
  border: 1px dashed rgba(56, 189, 248, 0.35);
  background: rgba(10, 17, 32, 0.65);
}
.warmup-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.42rem 0.78rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  font-size: 0.82rem;
  font-weight: 700;
}
.warmup-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #64748b;
  box-shadow: 0 0 6px rgba(100, 116, 139, 0.6);
}
.warmup-pill.loading .warmup-dot {
  background: #facc15;
  box-shadow: 0 0 10px #facc15;
  animation: pulseDot 1s infinite;
}
.warmup-pill.ready .warmup-dot {
  background: #22c55e;
  box-shadow: 0 0 12px #22c55e;
}
.warmup-pill.ready {
  border-color: rgba(34, 197, 94, 0.55);
  background: rgba(34, 197, 94, 0.12);
}
.warmup-pill.testing .warmup-dot {
  background: #38bdf8;
  box-shadow: 0 0 12px #38bdf8;
  animation: pulseDot 0.7s infinite;
}
.warmup-pill.error .warmup-dot {
  background: #f43f5e;
  box-shadow: 0 0 10px #f43f5e;
}
@keyframes pulseDot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.35); opacity: 0.65; }
}
