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

:root {
  --bg:         #0d1117;
  --surface:    #161b22;
  --border:     #30363d;
  --text:       #c9d1d9;
  --muted:      #8b949e;
  --accent:     #58a6ff;
  --green:      #3fb950;
  --red:        #f85149;
  --yellow:     #d29922;
  --radius:     8px;
  --sidebar-w:  220px;
  --sidebar-collapsed: 52px;
  --transition: 240ms ease;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  height: 100dvh;
  overflow: hidden;
  display: flex;
}

/* ══════════════════════════════════════════
   SIDEBAR
══════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width var(--transition), min-width var(--transition);
  flex-shrink: 0;
  z-index: 100;
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed);
  min-width: var(--sidebar-collapsed);
}

/* Header */
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow: hidden;
  min-height: 52px;
}

.sidebar-toggle {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 5px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color var(--transition), background var(--transition);
}
.sidebar-toggle:hover { color: var(--text); background: var(--border); }

.sidebar-brand {
  font-weight: 700;
  font-size: 14px;
  color: var(--accent);
  white-space: nowrap;
  opacity: 1;
  transition: opacity var(--transition);
  overflow: hidden;
}
.sidebar.collapsed .sidebar-brand { opacity: 0; width: 0; }

/* Nav */
.sidebar-nav {
  flex: 1;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 8px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--muted);
  border: none;
  background: none;
  font-size: 13px;
  text-decoration: none;
  white-space: nowrap;
  width: 100%;
  text-align: left;
  transition: color var(--transition), background var(--transition);
  overflow: hidden;
  min-width: 0;
}
.sidebar-item:hover:not(.no-hover) { color: var(--text); background: var(--border); }
.sidebar-item.active { color: var(--accent); background: rgba(88,166,255,.12); }
.sidebar-item.no-hover { cursor: default; }

.item-icon {
  font-size: 15px;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
  line-height: 1;
}

.item-label {
  opacity: 1;
  transition: opacity var(--transition);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar.collapsed .item-label { opacity: 0; width: 0; }

/* Action buttons (start/stop) */
.sidebar-action.green { color: var(--green); }
.sidebar-action.green:hover { background: rgba(63,185,80,.12); }
.sidebar-action.red   { color: var(--red); }
.sidebar-action.red:hover   { background: rgba(248,81,73,.12); }

/* Footer */
.sidebar-footer {
  padding: 8px 6px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
}

.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

/* Status dot */
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
  transition: background .3s;
}
.status-dot.running { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.stopped { background: var(--red); }

/* Topbar dot (mobile) */
.topbar-dot {
  margin-left: auto;
  flex-shrink: 0;
}

/* ══════════════════════════════════════════
   MAIN WRAP
══════════════════════════════════════════ */
.main-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* Mobile top bar (hidden on desktop) */
.topbar-mobile {
  display: none;
  height: 48px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  align-items: center;
  padding: 0 12px;
  gap: 12px;
  flex-shrink: 0;
}

.topbar-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--accent);
  flex: 1;
}

.sidebar-toggle-mobile {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 5px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition), background var(--transition);
}
.sidebar-toggle-mobile:hover { color: var(--text); background: var(--border); }

/* ══════════════════════════════════════════
   MOBILE OVERLAY
══════════════════════════════════════════ */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 99;
}
.sidebar-overlay.active { display: block; }

/* ══════════════════════════════════════════
   CONTENT & TAB PANELS
══════════════════════════════════════════ */
#content {
  flex: 1;
  overflow: hidden;
  position: relative;
  min-height: 0;
}

.tab-panel {
  display: none;
  height: 100%;
  width: 100%;
}
.tab-panel.active { display: flex; flex-direction: column; }

.tab-panel iframe {
  flex: 1;
  border: none;
  width: 100%;
  background: var(--bg);
}

.iframe-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 6px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* ══════════════════════════════════════════
   CONFIG PANEL
══════════════════════════════════════════ */
.config-panel {
  padding: 1rem;
  overflow-y: auto;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.card h2 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text);
}

.toggles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}

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

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.toggle-label { font-size: 13px; color: var(--text); }

.toggle-switch {
  position: relative;
  width: 40px; height: 22px;
  flex-shrink: 0;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--border);
  border-radius: 22px;
  cursor: pointer;
  transition: background .2s;
}
.toggle-slider::before {
  content: "";
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
}
.toggle-switch input:checked + .toggle-slider { background: var(--green); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(18px); }

#config-editor {
  width: 100%;
  min-height: 260px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: "Cascadia Code", "Fira Code", monospace;
  font-size: 12px;
  padding: 12px;
  resize: vertical;
}
#config-editor:focus { outline: none; border-color: var(--accent); }

.config-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 12px;
}

#save-msg {
  font-size: 13px;
  color: var(--green);
  display: none;
}

/* ══════════════════════════════════════════
   LOG PANEL
══════════════════════════════════════════ */
.log-panel {
  padding: 1rem;
  overflow-y: auto;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.log-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

#log-content {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  font-family: "Cascadia Code", "Fira Code", monospace;
  font-size: 11px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text);
  line-height: 1.6;
}

/* ══════════════════════════════════════════
   BUTTONS
══════════════════════════════════════════ */
.btn {
  padding: 6px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
  transition: background .15s, border-color .15s;
  text-decoration: none;
  display: inline-block;
}
.btn:hover { background: var(--border); }
.btn-green { border-color: var(--green); color: var(--green); }
.btn-green:hover { background: rgba(63,185,80,.15); }
.btn-red   { border-color: var(--red);   color: var(--red);   }
.btn-red:hover   { background: rgba(248,81,73,.15); }
.btn-accent { background: var(--accent); color: #000; border-color: var(--accent); }
.btn-accent:hover { opacity: .85; }

/* ══════════════════════════════════════════
   LOGIN / VERIFY OTP
══════════════════════════════════════════ */
.login-wrap {
  min-height: 100dvh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 1rem;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
}

.login-card h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: .25rem;
}

.login-card .subtitle {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 1.5rem;
}

.field { margin-bottom: 1rem; }
.field label { display: block; font-size: 13px; margin-bottom: 4px; color: var(--muted); }
.field input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
}
.field input:focus { outline: none; border-color: var(--accent); }

.error-msg {
  background: rgba(248,81,73,.1);
  border: 1px solid var(--red);
  border-radius: 6px;
  padding: 8px 12px;
  color: var(--red);
  font-size: 13px;
  margin-bottom: 1rem;
}

/* ══════════════════════════════════════════
   ADMIN USERS
══════════════════════════════════════════ */

/* Used in admin_users.html (standalone page, no sidebar) */
nav {
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  gap: 8px;
  flex-shrink: 0;
}

.nav-brand {
  font-weight: 700;
  font-size: 15px;
  color: var(--accent);
  white-space: nowrap;
  flex-shrink: 0;
}

.nav-tabs {
  display: flex;
  gap: 2px;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  min-width: 0;
}
.nav-tabs::-webkit-scrollbar { display: none; }

.nav-tab {
  padding: 6px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--muted);
  border: none;
  background: none;
  font-size: 13px;
  white-space: nowrap;
  flex-shrink: 0;
  transition: color .15s, background .15s;
}
.nav-tab:hover { color: var(--text); background: var(--border); }

.nav-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.nav-user {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

.admin-wrap {
  padding: 1rem;
  max-width: 960px;
  margin: 0 auto;
}

.admin-wrap h1 { font-size: 18px; margin-bottom: 1.5rem; }

.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  min-width: 560px;
}

th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  white-space: nowrap;
}

td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.badge-admin { background: rgba(88,166,255,.15); color: var(--accent); }
.badge-user  { background: var(--border); color: var(--muted); }

/* ══════════════════════════════════════════
   EVALUATE TAB
══════════════════════════════════════════ */

/* ── Scrollbar globale dark theme ── */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
*::-webkit-scrollbar-thumb:hover { background: var(--muted); }

.eval-panel {
  padding: 20px;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-sizing: border-box;
}

/* Upload grid ─────────────────────────── */
.eval-upload-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 12px;
}
@media (max-width: 700px) {
  .eval-upload-grid { grid-template-columns: 1fr; }
}

.eval-upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 22px 12px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: center;
  transition: border-color var(--transition), background var(--transition);
  background: var(--bg);
  user-select: none;
}
.eval-upload-zone:hover,
.eval-upload-zone.drag-over { border-color: var(--accent); background: rgba(88,166,255,.06); }
.eval-upload-zone.has-file  { border-color: var(--green);  background: rgba(63,185,80,.06); }
.eval-upload-zone input[type="file"] { display: none; }

.eval-tool-icon { font-size: 26px; line-height: 1; }
.eval-tool-name { font-weight: 600; font-size: 13px; }
.eval-file-name { font-size: 11px; color: var(--muted); word-break: break-all; max-width: 100%; }
.eval-upload-zone.has-file .eval-file-name { color: var(--green); }

/* Result cards ────────────────────────── */
.eval-result-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 4px;
}

.eval-section-label {
  margin: 18px 0 8px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  font-weight: 500;
}

/* Accuracy table ──────────────────────── */
.eval-table-wrap { overflow-x: auto; border-radius: 6px; border: 1px solid var(--border); }
.eval-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 0;
}
.eval-table th {
  padding: 7px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.eval-table td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.eval-table tr:last-child td { border-bottom: none; }

/* Pattern cards ───────────────────────── */
.eval-patterns { display: flex; flex-direction: column; gap: 8px; }
.eval-pattern-card {
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.eval-pattern-header { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.eval-pattern-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  color: #fff;
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* Report box ──────────────────────────── */
.eval-report-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.eval-report-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.eval-report-pre {
  max-height: 340px;
  overflow-y: auto;
  padding: 14px;
  font-size: 12px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.create-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-top: 1.5rem;
}

.create-form h2 { font-size: 14px; margin-bottom: 1rem; }

.form-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.form-row .field { margin-bottom: 0; flex: 1; min-width: 130px; }

@media (max-width: 600px) {
  .form-row { flex-direction: column; }
  .form-row .field { min-width: 0; width: 100%; }
}

/* ══════════════════════════════════════════
   MOBILE RESPONSIVE
══════════════════════════════════════════ */
@media (max-width: 768px) {
  /* Hide desktop sidebar, show mobile topbar */
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100dvh;
    width: var(--sidebar-w) !important;
    min-width: var(--sidebar-w) !important;
    transform: translateX(-100%);
    transition: transform var(--transition);
    z-index: 200;
  }
  .sidebar.mobile-open {
    transform: translateX(0);
  }
  /* Labels always visible when sidebar opens on mobile */
  .sidebar .item-label { opacity: 1 !important; width: auto !important; }
  .sidebar .sidebar-brand { opacity: 1 !important; width: auto !important; }

  .topbar-mobile { display: flex; }

  .nav-user { display: none; }
  .nav-brand { font-size: 13px; }
}
