/*
  Design tokens
  ─────────────
  Color   : --void (#06 0504, true warm black, not grey) / --panel (glass) /
            --gold (ghevar syrup) / --gold-deep / --lattice (pale ghevar base,
            used sparingly) / --chili (destructive red) / --leaf (status-good) /
            --ink (warm off-white text) / --dust (warm muted text)
  Type    : Sora for display/headings, Inter for UI/body, JetBrains Mono for
            anything that is literally data (ids, codes, logs, file contents).
  Layout  : fixed glass sidebar + fluid content. Stat tiles are sharp (8px),
            panels are soft (20px), primary actions are pills, destructive
            actions are sharp rectangles - the shape itself signals intent.
  Motion  : one orchestrated reveal on the verification screen; small
            state-confirm pulses on actions; nothing fades in on scroll.
*/

@import url('https://fonts.googleapis.com/css2?family=Sora:wght@500;600;700;800&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --void: #07050a;
  --void-2: #0c0a10;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-border: rgba(232, 179, 76, 0.14);
  --panel-border-strong: rgba(232, 179, 76, 0.32);
  --gold: #e8b34c;
  --gold-soft: #f0c877;
  --gold-deep: #b9822a;
  --lattice: #f4e4c6;
  --chili: #d6483c;
  --chili-soft: rgba(214, 72, 60, 0.14);
  --leaf: #8faf5f;
  --ink: #f2ecdf;
  --dust: #948a78;
  --dust-dim: #5f584a;
  --radius-panel: 14px;
  --radius-tile: 8px;
  --radius-pill: 999px;
  --shadow-panel: 0 16px 40px -20px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--void);
  color: var(--ink);
  font-family: 'Inter', system-ui, sans-serif;
  min-height: 100vh;
}

body {
  background:
    radial-gradient(1200px 700px at 12% -10%, rgba(232, 179, 76, 0.08), transparent 60%),
    radial-gradient(900px 600px at 100% 0%, rgba(232, 179, 76, 0.05), transparent 55%),
    var(--void);
}

h1, h2, h3, h4 {
  font-family: 'Sora', sans-serif;
  margin: 0;
  color: var(--ink);
  font-weight: 700;
  letter-spacing: -0.01em;
}

p { margin: 0; color: var(--dust); line-height: 1.5; }

a { color: var(--gold); }

code, .mono, input.mono, textarea.mono, .code-view {
  font-family: 'JetBrains Mono', monospace;
}

button {
  font-family: inherit;
  cursor: pointer;
}

::selection { background: rgba(232, 179, 76, 0.35); color: #fff; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(232, 179, 76, 0.2); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(232, 179, 76, 0.35); }

/* ─── glass panel primitive ─────────────────────────────────────────── */

.glass {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-panel);
  backdrop-filter: blur(10px) saturate(120%);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  box-shadow: var(--shadow-panel);
}

/* ─── buttons ────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink);
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  font-size: 14px;
  font-weight: 600;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}
.btn:hover { border-color: var(--panel-border-strong); background: rgba(255, 255, 255, 0.06); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--gold), var(--gold-deep));
  color: #241a05;
  border: none;
}
.btn-primary:hover { filter: brightness(1.08); }

.btn-danger {
  border-radius: 8px;
  background: var(--chili-soft);
  border: 1px solid rgba(214, 72, 60, 0.4);
  color: #ffb3ab;
}
.btn-danger:hover { background: rgba(214, 72, 60, 0.22); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--dust);
}
.btn-ghost:hover { color: var(--ink); background: rgba(255, 255, 255, 0.04); }

.btn-sm { padding: 6px 12px; font-size: 13px; }

.pulse-ok {
  animation: pulseOk 0.6s ease;
}
@keyframes pulseOk {
  0% { box-shadow: 0 0 0 0 rgba(143, 175, 95, 0.55); }
  100% { box-shadow: 0 0 0 14px rgba(143, 175, 95, 0); }
}

/* ─── app shell ──────────────────────────────────────────────────────── */

.shell {
  display: grid;
  grid-template-columns: 250px 1fr;
  min-height: 100vh;
}

.sidebar {
  margin: 16px 0 16px 16px;
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px 20px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--panel-border);
}
.brand-mark {
  width: 34px; height: 34px; flex-shrink: 0;
}
.brand-text h1 { font-size: 16px; }
.brand-text span { font-size: 12px; color: var(--dust); }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  color: var(--dust);
  font-size: 14px;
  font-weight: 500;
  border-left: 2px solid transparent;
  transition: color 0.12s ease, background 0.12s ease;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.8; }
.nav-item:hover { color: var(--ink); background: rgba(255, 255, 255, 0.03); }
.nav-item.active {
  color: var(--ink);
  background: rgba(232, 179, 76, 0.08);
  border-left-color: var(--gold);
}

.nav-spacer { flex: 1; }

.sidebar-foot {
  padding: 10px;
  font-size: 12px;
  color: var(--dust-dim);
  border-top: 1px solid var(--panel-border);
  margin-top: 8px;
}

.main {
  padding: 16px 24px 40px 16px;
  overflow-x: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  margin-bottom: 20px;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--dust);
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--panel-border);
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dust-dim); }
.status-dot.on { background: var(--leaf); box-shadow: 0 0 10px var(--leaf); }
.status-dot.off { background: var(--chili); box-shadow: 0 0 10px var(--chili); }

.view { display: none; }
.view.active { display: block; }

.view-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}
.view-head p { margin-top: 4px; font-size: 13px; }

/* ─── stat tiles ─────────────────────────────────────────────────────── */

.tile-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.tile {
  padding: 16px 18px;
  border-radius: var(--radius-tile);
}
.tile .num {
  font-family: 'Sora', sans-serif;
  font-size: 28px;
  font-weight: 800;
  color: var(--gold-soft);
  display: block;
}
.tile .label { font-size: 12.5px; color: var(--dust); margin-top: 2px; }

/* ─── generic panel/card ─────────────────────────────────────────────── */

.panel {
  padding: 20px 22px;
  margin-bottom: 18px;
}
.panel h3 { font-size: 15px; margin-bottom: 14px; }
.panel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
@media (max-width: 720px) { .control-grid { grid-template-columns: 1fr; } }

/* ─── tables ─────────────────────────────────────────────────────────── */

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left;
  color: var(--dust);
  font-weight: 500;
  font-size: 12px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--panel-border);
}
tbody td { padding: 10px; border-bottom: 1px solid rgba(255, 255, 255, 0.04); }
tbody tr:hover { background: rgba(255, 255, 255, 0.02); }
.uid { color: var(--dust); }

/* ─── inputs ─────────────────────────────────────────────────────────── */

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; color: var(--dust); }
input[type=text], input[type=password], input[type=number], input[type=search], textarea, select {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--panel-border);
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  width: 100%;
  transition: border-color 0.12s ease;
}
input:focus, textarea:focus, select:focus { border-color: var(--gold); }
textarea { resize: vertical; min-height: 90px; }

.search-row { display: flex; gap: 10px; margin-bottom: 14px; }
.search-row input { flex: 1; }

/* ─── files / code editor ────────────────────────────────────────────── */

.files-layout { display: grid; grid-template-columns: 260px 1fr; gap: 14px; }
@media (max-width: 900px) { .files-layout { grid-template-columns: 1fr; } }
.file-tree { padding: 10px; max-height: 560px; overflow-y: auto; }
.file-row {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: 8px; font-size: 13px; color: var(--dust);
}
.file-row:hover { background: rgba(255, 255, 255, 0.04); color: var(--ink); }
.file-row.selected { background: rgba(232, 179, 76, 0.1); color: var(--gold-soft); }
.file-row .fname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor-pane { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.editor-pane textarea {
  min-height: 460px;
  white-space: pre;
  overflow: auto;
}

.log-view {
  padding: 16px;
  max-height: 520px;
  overflow-y: auto;
  font-size: 12.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  color: var(--dust);
}

/* ─── owner commands ─────────────────────────────────────────────────── */

.owner-cmd {
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(214, 72, 60, 0.06);
  border: 1px solid rgba(214, 72, 60, 0.22);
  margin-bottom: 8px;
}
.owner-cmd .head { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink); }
.owner-cmd .meta { font-size: 12px; color: var(--dust); margin-top: 4px; }

/* ─── redeem codes ───────────────────────────────────────────────────── */

.code-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border-radius: 8px;
  background: rgba(232, 179, 76, 0.08);
  border: 1px solid var(--panel-border);
  font-size: 13px;
  color: var(--gold-soft);
}

/* ─── toast ──────────────────────────────────────────────────────────── */

#toast-stack {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 999;
}
.toast {
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 13.5px;
  max-width: 340px;
  animation: toastIn 0.18s ease;
}
.toast.ok { border-color: rgba(143, 175, 95, 0.4); }
.toast.err { border-color: rgba(214, 72, 60, 0.5); color: #ffb3ab; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ─── modal ──────────────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 998;
}
.modal-backdrop.active { display: flex; }
.modal {
  width: min(560px, 92vw);
  max-height: 84vh;
  overflow-y: auto;
  padding: 22px;
}
.modal h3 { margin-bottom: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* ─── schema banner ──────────────────────────────────────────────────── */

.schema-banner {
  display: none;
  padding: 12px 16px;
  border-radius: 12px;
  background: rgba(214, 72, 60, 0.1);
  border: 1px solid rgba(214, 72, 60, 0.35);
  color: #ffb3ab;
  font-size: 13px;
  margin-bottom: 18px;
}
.schema-banner.show { display: block; }
.schema-banner ul { margin: 8px 0 0; padding-left: 18px; }

/* ═══════════════════════════════════════════════════════════════════════
   AUTH SCREENS (login / verify)
   ═══════════════════════════════════════════════════════════════════════ */

.auth-stage {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
}

.auth-card {
  width: min(420px, 100%);
  padding: 36px 32px;
  text-align: center;
  position: relative;
  z-index: 1;
}

.auth-mark { width: 58px; height: 58px; margin: 0 auto 18px; }

.auth-card h2 { font-size: 21px; margin-bottom: 6px; }
.auth-card .sub { font-size: 13.5px; margin-bottom: 26px; }

.auth-card form { display: flex; flex-direction: column; gap: 14px; text-align: left; }

.auth-error {
  background: rgba(214, 72, 60, 0.12);
  border: 1px solid rgba(214, 72, 60, 0.35);
  color: #ffb3ab;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  text-align: left;
}

.auth-submit { margin-top: 4px; justify-content: center; width: 100%; }

/* verify screen specifics */

.ghevar-wrap {
  width: 190px;
  height: 190px;
  margin: 0 auto 22px;
  animation: ghevarSettle 0.9s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes ghevarSettle {
  0% { opacity: 0; transform: translateY(-14px) scale(0.85) rotate(-6deg); }
  60% { opacity: 1; }
  100% { opacity: 1; transform: translateY(0) scale(1) rotate(0deg); }
}

.ghevar-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  border: 2px solid var(--panel-border-strong);
  box-shadow: 0 0 0 6px rgba(232, 179, 76, 0.08), var(--shadow-panel);
}

.oath-text {
  font-family: 'Sora', sans-serif;
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 24px;
  line-height: 1.45;
}
.oath-text .name { color: var(--gold-soft); }

.oath-actions { display: flex; gap: 12px; }
.oath-actions .btn { flex: 1; justify-content: center; }

/* ─── responsive ─────────────────────────────────────────────────────── */

@media (max-width: 880px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    margin: 0;
    border-radius: 0;
    flex-direction: row;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 8px 10px;
    position: sticky;
    top: 0;
    z-index: 20;
    gap: 2px;
  }
  .brand { display: none; }
  .nav-item {
    flex-direction: column;
    gap: 3px;
    padding: 8px 12px;
    min-width: 60px;
    min-height: 44px;
    justify-content: center;
    border-left: none;
    border-bottom: 2px solid transparent;
    border-radius: 10px;
    flex-shrink: 0;
  }
  .nav-item span { display: block; font-size: 10px; white-space: nowrap; }
  .nav-item.active { border-left-color: transparent; border-bottom-color: var(--gold); }
  .sidebar-foot { display: none; }
  .nav-spacer { display: none; }
  .main { padding: 12px; }
  .topbar { padding: 12px 14px; flex-wrap: wrap; gap: 10px; }
  .tile-row { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  table { font-size: 13px; }
  .row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
  .terminal-shell { height: min(60vh, 420px); padding: 8px; }
  .auth-card { padding: 26px 20px; }
}

@media (max-width: 480px) {
  .preloader-mark { font-size: 40px; }
  .view-head { flex-direction: column; align-items: flex-start; }
  .tile-row { grid-template-columns: repeat(2, 1fr); }
  .tile { padding: 12px 14px; }
  .tile .num { font-size: 20px; }
  .oath-text { font-size: 16px; }
  .files-layout .file-tree { max-height: 160px; }
  .editor-pane textarea { min-height: 260px; }
}

/* Keep tap targets comfortable and inputs from triggering mobile zoom */
@media (max-width: 880px) {
  input, select, textarea, button { font-size: 16px; }
  .btn, .btn-sm { min-height: 38px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

/* ─── terminal ───────────────────────────────────────────────────────── */

.terminal-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--dust);
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--panel-border);
}
.terminal-status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--chili);
  box-shadow: 0 0 8px var(--chili);
}
.terminal-status.connected::before {
  background: var(--leaf);
  box-shadow: 0 0 8px var(--leaf);
}

.terminal-warning {
  padding: 12px 16px;
  margin-bottom: 14px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--gold-soft);
  border-color: var(--panel-border-strong);
}

.terminal-shell {
  padding: 14px;
  height: 520px;
}
#terminalContainer {
  width: 100%;
  height: 100%;
}
.xterm .xterm-viewport { background: transparent !important; }

/* ─── preloader ──────────────────────────────────────────────────────── */

.preloader {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--void);
  transition: opacity 0.5s ease, visibility 0.5s ease;
}
.preloader.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.preloader-mark {
  font-family: 'Sora', sans-serif;
  font-weight: 800;
  font-size: 56px;
  letter-spacing: 0.02em;
  color: var(--ink);
  background: linear-gradient(120deg, var(--gold-soft), var(--gold), var(--gold-deep), var(--gold));
  background-size: 300% auto;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: preloader-shimmer 1.8s ease-in-out infinite;
}
@keyframes preloader-shimmer {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}
