:root {
  --bg: #070b12;
  --bg2: #0b1220;
  --panel: #0f172a;
  --panel2: #111c31;
  --line: #1e2b45;
  --line2: #2a3b5c;
  --text: #e6edf7;
  --muted: #8b9bb4;
  --accent: #22d3ee;
  --accent2: #38bdf8;
  --green: #34d399;
  --red: #f87171;
  --amber: #fbbf24;
  --radius: 12px;
  --font: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", "Consolas", "SFMono-Regular", monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(34, 211, 238, .09), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(56, 189, 248, .07), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
a { color: var(--accent); }

/* ---------- buttons & inputs ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--line2);
  background: var(--panel2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 9px;
  cursor: pointer;
  font: inherit;
  font-weight: 550;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: #17233c; border-color: #38507c; }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(180deg, #0ea5b7, #0891b2);
  border-color: #22d3ee66;
  color: #06222a;
  text-shadow: 0 0 0 transparent;
}
.btn.primary:hover { background: linear-gradient(180deg, #22c6dd, #0aa2c4); }
.btn.danger { color: #fecaca; border-color: #7f1d1d; background: #2a1114; }
.btn.danger:hover { background: #3a171b; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 9px; font-size: 12px; }
.btn.icon { padding: 7px 11px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.on { border-color: var(--accent); color: var(--accent); box-shadow: inset 0 0 0 1px #22d3ee33; }

input[type="text"], input[type="password"], textarea, select {
  width: 100%;
  background: #0a1424;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 9px;
  padding: 9px 11px;
  font: inherit;
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: #22d3ee88; box-shadow: 0 0 0 3px #22d3ee14; }
select { padding: 7px 9px; }
label { font-size: 12.5px; color: var(--muted); display: grid; gap: 6px; }
textarea { resize: vertical; font-family: var(--mono); font-size: 12.5px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--muted); }
input[type="checkbox"] { accent-color: #0891b2; width: 15px; height: 15px; }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(400px, 100%);
  background: linear-gradient(180deg, #0e1729, #0b1220);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px;
  display: grid;
  gap: 16px;
  box-shadow: 0 24px 60px -30px #000;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(140deg, #22d3ee, #0e7490);
  position: relative;
  flex: none;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 8px;
  border: 2px solid #06222a; border-radius: 3px;
}
.brand h1 { font-size: 20px; }
.brand p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.brand.small .brand-mark { width: 28px; height: 28px; border-radius: 8px; }
.brand.small .brand-mark::after { inset: 6px; }
.brand-text { display: grid; line-height: 1.2; }
.brand-text strong { font-size: 15px; }
.conn-state { font-size: 11px; color: var(--muted); font-family: var(--mono); }
.form-error { min-height: 18px; color: var(--red); font-size: 12.5px; }

/* ---------- topbar ---------- */
.topbar {
  height: 58px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 11, 18, .75);
  backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 30;
}
.topbar-right { display: flex; align-items: center; gap: 12px; }
.user-label { color: var(--muted); font-size: 12.5px; font-family: var(--mono); }

/* ---------- dashboard ---------- */
.dashboard { padding: 26px 22px 60px; max-width: 1400px; margin: 0 auto; }
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; margin-bottom: 20px;
}
.page-head h2 { font-size: 20px; }
.page-head p { margin: 4px 0 0; font-size: 12.5px; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(285px, 1fr));
  gap: 14px;
}
.card {
  background: linear-gradient(180deg, #0f1929, #0c1422);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
  transition: border-color .15s, transform .15s;
}
.card:hover { border-color: #2b436b; transform: translateY(-1px); }
.card-head { display: flex; align-items: center; gap: 10px; }
.card-icon {
  width: 38px; height: 38px; border-radius: 10px; flex: none;
  background: #0b2233; border: 1px solid #164e63;
  display: grid; place-items: center;
  color: var(--accent); font-family: var(--mono); font-size: 12px; font-weight: 700;
}
.card-name { font-weight: 620; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { font-size: 11.5px; color: var(--muted); font-family: var(--mono); margin-top: 2px; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; margin-right: 6px; background: #475569; }
.dot.on { background: var(--green); box-shadow: 0 0 0 3px #34d39922; }
.dot.off { background: #64748b; }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card-actions .btn { flex: 1; min-width: 84px; }
.card-sub { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 10px; }
.empty {
  text-align: center; padding: 60px 20px; border: 1px dashed var(--line2);
  border-radius: 14px; color: var(--muted);
}
.empty h3 { color: var(--text); margin-bottom: 6px; }

/* ---------- viewer ---------- */
.viewer { height: calc(100vh - 58px); display: flex; flex-direction: column; }
.vbar {
  display: flex; align-items: center; gap: 14px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg2);
  flex-wrap: wrap;
}
.vtitle { display: grid; min-width: 120px; line-height: 1.25; }
.vtitle strong { font-size: 14px; }
.vtitle span { font-size: 11.5px; }
.vcontrols { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.ctl { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--muted); }
.ctl select { width: auto; padding: 5px 7px; font-size: 12px; }
.vbody { flex: 1; display: flex; min-height: 0; background: #000; }
.stage {
  position: relative; flex: 1; min-width: 0;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  background:
    linear-gradient(0deg, #000 0%, #000 100%);
  touch-action: none;
}
#screen {
  max-width: 100%; max-height: 100%;
  display: block;
  cursor: crosshair;
  outline: none;
  image-rendering: auto;
}
.voverlay {
  position: absolute; inset: 0;
  display: none;
  place-items: center;
  background: rgba(3, 6, 12, .72);
  color: var(--muted);
  text-align: center;
  padding: 24px;
  font-size: 13px;
}
.voverlay.show { display: grid; }
.voverlay strong { color: var(--text); display: block; font-size: 16px; margin-bottom: 6px; }
.voverlay .btn { margin-top: 14px; }
.stats {
  position: absolute; left: 10px; bottom: 10px;
  background: rgba(5, 10, 18, .82);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 9px;
  font-family: var(--mono); font-size: 11px; color: var(--muted);
  pointer-events: none;
}
.stats b { color: var(--accent); font-weight: 600; }

/* ---------- side panels ---------- */
.side-panel {
  width: 330px; flex: none;
  background: var(--bg2);
  border-left: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 12px;
  gap: 10px;
  min-height: 0;
}
.side-panel.wide-panel { width: 420px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; font-weight: 600; font-size: 13px; }
.panel-close { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; font-size: 12px; }
.panel-close:hover { color: var(--text); }
.fs-bar { display: flex; align-items: center; gap: 8px; }
.fs-path {
  flex: 1; font-family: var(--mono); font-size: 11.5px; color: var(--accent2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  background: #0a1424; border: 1px solid var(--line); border-radius: 7px; padding: 5px 8px;
}
.fs-actions { display: flex; gap: 8px; }
.fs-list {
  flex: 1; overflow: auto; border: 1px solid var(--line); border-radius: 9px;
  background: #0a1424; min-height: 120px;
}
.fs-row {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px;
  border-bottom: 1px solid #131e31;
  cursor: pointer;
  font-size: 12.5px;
}
.fs-row:hover { background: #0f1c31; }
.fs-row .fs-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fs-row .fs-size { font-family: var(--mono); font-size: 10.5px; color: var(--muted); }
.fs-row.dir .fs-name { color: var(--accent2); }
.fs-row .fs-del {
  background: none; border: 0; color: #7f1d1d; cursor: pointer; font: inherit; font-size: 11px;
  padding: 2px 4px; border-radius: 4px;
}
.fs-row .fs-del:hover { color: var(--red); background: #2a1114; }
.fs-mode { padding: 5px 10px; font-size: 11px; color: var(--amber); font-family: var(--mono); }
.fs-progress { font-size: 11.5px; color: var(--accent); font-family: var(--mono); }

/* ---------- modal & toast ---------- */
.modal {
  position: fixed; inset: 0; z-index: 80;
  display: grid; place-items: center;
  background: rgba(2, 5, 10, .7);
  padding: 20px;
}
.modal-card {
  width: min(560px, 100%);
  max-height: 85vh; overflow: auto;
  background: #0d1626;
  border: 1px solid var(--line2);
  border-radius: 14px;
  padding: 22px;
  display: grid; gap: 14px;
  box-shadow: 0 30px 80px -30px #000;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.code {
  font-family: var(--mono); font-size: 12px;
  background: #060d18; border: 1px solid var(--line);
  border-radius: 9px; padding: 10px 12px;
  word-break: break-all; color: #b6f4ff;
  user-select: all;
}
.field-row { display: flex; gap: 8px; }
.field-row .code { flex: 1; }
.note {
  font-size: 12px; color: var(--amber);
  background: #2a2007; border: 1px solid #4a3a0a;
  border-radius: 9px; padding: 10px 12px;
}
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 90; display: grid; gap: 8px; }
.toast {
  background: #0f1c31; border: 1px solid var(--line2); border-left: 3px solid var(--accent);
  padding: 10px 14px; border-radius: 9px; font-size: 12.5px;
  animation: toastin .18s ease-out;
  max-width: 360px;
}
.toast.err { border-left-color: var(--red); }
@keyframes toastin { from { opacity: 0; transform: translateY(6px); } }

/* ---------- mobile ---------- */
@media (max-width: 860px) {
  .topbar { padding: 0 14px; }
  .dashboard { padding: 18px 14px 40px; }
  .viewer { height: calc(100vh - 58px); }
  .vbody { position: relative; }
  .vcontrols { width: 100%; margin-left: 0; }
  .side-panel {
    position: fixed; right: 0; top: 58px; bottom: 0; z-index: 40;
    width: min(92vw, 420px);
    box-shadow: -20px 0 50px -20px #000;
  }
  .side-panel.wide-panel { width: min(94vw, 460px); }
  .vtitle { flex: 1; }
}

/* touch help */
.touch-hint {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  background: rgba(5, 10, 18, .8); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 12px; font-size: 11px; color: var(--muted);
  pointer-events: none;
}
