/* Oqtrix Operator Console - self-contained styles (no @import, no external assets) */

:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  /* Light theme (default) */
  --bg: #f1f5f9;
  --content-bg: #f8fafc;
  --card-bg: #ffffff;
  --card-border: #e2e8f0;
  --text: #0f172a;
  --text-dim: #475569;
  --text-faint: #94a3b8;
  --sidebar-bg: #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-text-dim: #94a3b8;
  --sidebar-active: #1e293b;
  --sidebar-border: #1e293b;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --accent-text: #4338ca;
  --input-bg: #ffffff;
  --input-border: #cbd5e1;
  --row-hover: #f1f5f9;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);

  --green-bg: #dcfce7; --green-text: #166534;
  --amber-bg: #fef3c7; --amber-text: #92400e;
  --red-bg: #fee2e2; --red-text: #991b1b;
  --slate-bg: #e2e8f0; --slate-text: #334155;
  --blue-bg: #dbeafe; --blue-text: #1e40af;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #020617;
    --content-bg: #0b1120;
    --card-bg: #0f172a;
    --card-border: #1e293b;
    --text: #e2e8f0;
    --text-dim: #94a3b8;
    --text-faint: #64748b;
    --sidebar-bg: #020617;
    --sidebar-text: #cbd5e1;
    --sidebar-text-dim: #64748b;
    --sidebar-active: #1e293b;
    --sidebar-border: #1e293b;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --accent-soft: #1e1b4b;
    --accent-text: #a5b4fc;
    --input-bg: #0b1120;
    --input-border: #334155;
    --row-hover: #131c31;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);

    --green-bg: #14532d; --green-text: #bbf7d0;
    --amber-bg: #78350f; --amber-text: #fde68a;
    --red-bg: #7f1d1d; --red-text: #fecaca;
    --slate-bg: #1e293b; --slate-text: #cbd5e1;
    --blue-bg: #1e3a8a; --blue-text: #bfdbfe;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#root { height: 100%; }

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

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(79, 70, 229, 0.12), transparent),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 32px;
  box-shadow: var(--shadow);
}
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.login-brand .logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 16px;
}
.login-title { font-size: 18px; font-weight: 700; margin: 0; }
.login-sub { color: var(--text-dim); margin: 2px 0 22px; font-size: 13px; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; }
.field.inline { display: flex; align-items: center; gap: 8px; }
input, select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--input-border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input.code-input {
  font-family: var(--font-mono);
  letter-spacing: 8px;
  text-align: center;
  font-size: 22px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  background: var(--card-bg);
  color: var(--text);
  border-color: var(--card-border);
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--row-hover); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--red-text); border-color: var(--red-bg); }
.btn.danger:hover { background: var(--red-bg); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Layout shell ---------- */
.shell { display: flex; height: 100%; }
.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--sidebar-border);
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 18px;
  border-bottom: 1px solid var(--sidebar-border);
}
.sidebar .brand .logo {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 15px;
}
.sidebar .brand .name { font-weight: 700; color: #fff; font-size: 15px; }
.sidebar .brand .env { font-size: 11px; color: var(--sidebar-text-dim); }

.nav { padding: 12px 10px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border: none;
  background: transparent;
  color: var(--sidebar-text);
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px; font-weight: 500;
  font-family: inherit;
  text-align: left;
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--sidebar-active); color: #fff; }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-item .nav-ico { width: 18px; display: inline-flex; justify-content: center; }
.nav-item .nav-badge {
  margin-left: auto;
  background: var(--red-bg); color: var(--red-text);
  border-radius: 999px; padding: 1px 7px; font-size: 11px; font-weight: 700;
}
.nav-item.active .nav-badge { background: rgba(255,255,255,.25); color: #fff; }

.sidebar .user-box {
  border-top: 1px solid var(--sidebar-border);
  padding: 12px 14px;
  font-size: 12px;
}
.sidebar .user-box .email { color: #fff; font-weight: 600; word-break: break-all; }
.sidebar .user-box .role { color: var(--sidebar-text-dim); text-transform: capitalize; }

/* ---------- Main / topbar ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--content-bg); }
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--card-border);
  background: var(--card-bg);
}
.topbar h1 { font-size: 16px; margin: 0; font-weight: 700; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: 12px; color: var(--text-dim); text-align: right; }
.topbar .who .email { color: var(--text); font-weight: 600; }
.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 700; text-transform: capitalize;
  background: var(--accent-soft); color: var(--accent-text);
}
.content { padding: 24px; overflow-y: auto; flex: 1; }

/* ---------- Cards / sections ---------- */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.section { margin-bottom: 24px; }
.section-head {
  display: flex; align-items: center; gap: 12px; margin-bottom: 12px;
}
.section-head h2 { font-size: 15px; margin: 0; font-weight: 700; }
.section-head .spacer { flex: 1; }

/* stat cards */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}
.stat {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat .label { font-size: 12px; color: var(--text-dim); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 28px; font-weight: 800; margin-top: 6px; line-height: 1; }
.stat .sub { font-size: 12px; color: var(--text-faint); margin-top: 6px; }
.stat.accent { border-left: 3px solid var(--accent); }
.stat.warn .value { color: var(--amber-text); }
.stat.danger .value { color: var(--red-text); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border-radius: 12px; border: 1px solid var(--card-border); background: var(--card-bg); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; padding: 11px 14px;
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-dim); font-weight: 700;
  border-bottom: 1px solid var(--card-border);
  background: var(--content-bg);
  white-space: nowrap;
}
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--card-border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--row-hover); }
td.mono, .mono { font-family: var(--font-mono); font-size: 12.5px; }
td.actions { white-space: nowrap; }
td.actions .btn { margin-right: 6px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 700; text-transform: capitalize; white-space: nowrap;
}
.badge.green { background: var(--green-bg); color: var(--green-text); }
.badge.amber { background: var(--amber-bg); color: var(--amber-text); }
.badge.red { background: var(--red-bg); color: var(--red-text); }
.badge.slate { background: var(--slate-bg); color: var(--slate-text); }
.badge.blue { background: var(--blue-bg); color: var(--blue-text); }

/* ---------- Toggle switch ---------- */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--slate-bg); border-radius: 999px; transition: .18s;
}
.switch .slider:before {
  content: ""; position: absolute; height: 16px; width: 16px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .18s;
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider:before { transform: translateX(18px); }
.switch input:disabled + .slider { opacity: .5; cursor: not-allowed; }

/* ---------- Alerts / notices ---------- */
.alert {
  padding: 11px 14px; border-radius: 9px; font-size: 13px; margin-bottom: 14px;
  border: 1px solid transparent;
}
.alert.error { background: var(--red-bg); color: var(--red-text); border-color: var(--red-text); }
.alert.info { background: var(--blue-bg); color: var(--blue-text); }
.alert.warn { background: var(--amber-bg); color: var(--amber-text); }
.alert.success { background: var(--green-bg); color: var(--green-text); }

.secret-box {
  border: 1px dashed var(--accent);
  background: var(--accent-soft);
  border-radius: 9px;
  padding: 14px;
  margin: 12px 0;
}
.secret-box .label { font-size: 12px; font-weight: 700; color: var(--accent-text); margin-bottom: 6px; }
.secret-box .value {
  font-family: var(--font-mono); font-size: 15px; font-weight: 600;
  word-break: break-all; user-select: all;
  padding: 8px 10px; background: var(--card-bg); border-radius: 6px; border: 1px solid var(--card-border);
}
.secret-box .otpauth { font-family: var(--font-mono); font-size: 11px; color: var(--text-dim); word-break: break-all; margin-top: 8px; user-select: all; }
.secret-box small { color: var(--text-dim); }

.chain-ok { color: var(--green-text); font-weight: 700; }
.chain-bad { color: var(--red-text); font-weight: 700; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--card-border); margin-bottom: 16px; }
.tab {
  padding: 9px 14px; border: none; background: transparent; cursor: pointer;
  font-size: 13px; font-weight: 600; color: var(--text-dim); font-family: inherit;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent-text); border-bottom-color: var(--accent); }

.chip-row { display: flex; flex-wrap: wrap; gap: 4px; }

.code-pre {
  font-family: var(--font-mono); font-size: 12.5px; line-height: 1.5;
  background: var(--content-bg); border: 1px solid var(--card-border);
  border-radius: 8px; padding: 12px 14px; margin: 0;
  white-space: pre; overflow: auto; max-height: 440px;
}
.code-ta {
  font-family: var(--font-mono); font-size: 12.5px; line-height: 1.5;
  white-space: pre; overflow: auto; width: 100%; resize: vertical;
}

.bulk-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; margin-bottom: 12px;
  background: var(--accent-soft); border: 1px solid var(--card-border);
  border-radius: 10px; font-size: 13px;
}
.bulk-bar .count { font-weight: 700; margin-right: 4px; }
.bulk-bar .link {
  background: none; border: none; cursor: pointer;
  color: var(--accent-text); font: inherit; font-weight: 600; padding: 0;
}
.bulk-bar .link:hover { text-decoration: underline; }

.muted { color: var(--text-faint); }
.empty { padding: 28px; text-align: center; color: var(--text-faint); font-size: 13px; }
.spinner-wrap { padding: 40px; text-align: center; color: var(--text-faint); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(2, 6, 23, 0.55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; z-index: 50; overflow-y: auto;
}
.modal {
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: 14px; width: 100%; max-width: 560px;
  box-shadow: 0 20px 50px rgba(2,6,23,.4);
}
.modal-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--card-border); }
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 700; }
.modal-head .close { margin-left: auto; background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-dim); line-height: 1; }
.modal-body { padding: 20px; }
.modal-body.wide { max-width: 720px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--card-border); display: flex; justify-content: flex-end; gap: 8px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 14px; font-size: 13px; margin-bottom: 4px; }
.kv .k { color: var(--text-dim); font-weight: 600; }

/* ---------- Terminal ---------- */
.term-note { font-size: 12px; color: var(--text-dim); margin-bottom: 10px; }
.term-panel {
  background: #000; color: #d1d5db;
  font-family: var(--font-mono); font-size: 13px; line-height: 1.4;
  border-radius: 10px; border: 1px solid #1e293b;
  height: 420px; overflow: hidden;
  position: relative;
  outline: none;
}
.term-panel:focus { border-color: var(--accent); }
.term-scroll { height: 100%; overflow-y: auto; padding: 12px 14px; }
.term-scroll pre { margin: 0; white-space: pre-wrap; word-break: break-word; color: #e5e7eb; }
.term-status { font-size: 11px; color: var(--text-faint); margin-top: 6px; }
.term-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }
.term-dot.on { background: #22c55e; }
.term-dot.off { background: #ef4444; }

@media (max-width: 820px) {
  .sidebar { width: 68px; flex: 0 0 68px; }
  .sidebar .brand .name, .sidebar .brand .env, .nav-item span.nav-label, .sidebar .user-box .email, .sidebar .user-box .role { display: none; }
  .nav-item { justify-content: center; }
  .nav-item .nav-badge { position: absolute; }
  .form-grid { grid-template-columns: 1fr; }
  .content { padding: 16px; }
}

/* ============================================================
 * Manual theme override (data-theme wins over OS preference)
 * ========================================================== */
:root[data-theme="light"] {
  --bg: #f1f5f9;
  --content-bg: #f8fafc;
  --card-bg: #ffffff;
  --card-border: #e2e8f0;
  --text: #0f172a;
  --text-dim: #475569;
  --text-faint: #94a3b8;
  --sidebar-bg: #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-text-dim: #94a3b8;
  --sidebar-active: #1e293b;
  --sidebar-border: #1e293b;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --accent-text: #4338ca;
  --input-bg: #ffffff;
  --input-border: #cbd5e1;
  --row-hover: #f1f5f9;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --green-bg: #dcfce7; --green-text: #166534;
  --amber-bg: #fef3c7; --amber-text: #92400e;
  --red-bg: #fee2e2; --red-text: #991b1b;
  --slate-bg: #e2e8f0; --slate-text: #334155;
  --blue-bg: #dbeafe; --blue-text: #1e40af;
}

:root[data-theme="dark"] {
  --bg: #020617;
  --content-bg: #0b1120;
  --card-bg: #0f172a;
  --card-border: #1e293b;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --text-faint: #64748b;
  --sidebar-bg: #020617;
  --sidebar-text: #cbd5e1;
  --sidebar-text-dim: #64748b;
  --sidebar-active: #1e293b;
  --sidebar-border: #1e293b;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-soft: #1e1b4b;
  --accent-text: #a5b4fc;
  --input-bg: #0b1120;
  --input-border: #334155;
  --row-hover: #131c31;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --green-bg: #14532d; --green-text: #bbf7d0;
  --amber-bg: #78350f; --amber-text: #fde68a;
  --red-bg: #7f1d1d; --red-text: #fecaca;
  --slate-bg: #1e293b; --slate-text: #cbd5e1;
  --blue-bg: #1e3a8a; --blue-text: #bfdbfe;
}

/* ============================================================
 * Compact density (~30% tighter)
 * ========================================================== */
body.compact .content { padding: 16px; }
body.compact .card { padding: 12px; }
body.compact .section { margin-bottom: 16px; }
body.compact .section-head { margin-bottom: 8px; }
body.compact .stat { padding: 11px 12px; }
body.compact .stat .value { font-size: 22px; }
body.compact thead th { padding: 7px 10px; }
body.compact tbody td { padding: 7px 10px; }
body.compact .field { margin-bottom: 9px; }
body.compact input, body.compact select, body.compact textarea { padding: 6px 9px; }

/* ============================================================
 * Collapsed sidebar
 * ========================================================== */
.sidebar.collapsed { width: 68px; flex: 0 0 68px; }
.sidebar.collapsed .brand .name,
.sidebar.collapsed .brand .env,
.sidebar.collapsed .nav-item span.nav-label,
.sidebar.collapsed .user-box .email,
.sidebar.collapsed .user-box .role { display: none; }
.sidebar.collapsed .nav-item { justify-content: center; }
.sidebar.collapsed .nav-item .nav-badge { position: absolute; }

/* ============================================================
 * Preferences controls
 * ========================================================== */
.pref-row {
  display: grid; grid-template-columns: 200px 1fr; gap: 12px 18px;
  align-items: center; padding: 12px 0;
  border-bottom: 1px solid var(--card-border);
}
.pref-row:last-child { border-bottom: none; }
.pref-label { font-size: 13px; font-weight: 600; color: var(--text-dim); }
.pref-control { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }

.swatch-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.swatch {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--card-border); cursor: pointer; padding: 0;
  transition: transform .1s, box-shadow .1s;
}
.swatch:hover { transform: scale(1.1); }
.swatch.active { border-color: var(--text); box-shadow: 0 0 0 3px var(--accent-soft); }

.color-field { display: flex; align-items: center; gap: 8px; }
.color-picker { width: 42px; height: 34px; padding: 2px; border-radius: 8px; cursor: pointer; }

/* ============================================================
 * Toast
 * ========================================================== */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(12px);
  background: var(--text); color: var(--card-bg);
  padding: 10px 18px; border-radius: 999px; font-size: 13px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(2,6,23,.35);
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 820px) {
  .pref-row { grid-template-columns: 1fr; gap: 8px; }
}
