:root {
  --bg: #0b0d12;
  --bg-grad: radial-gradient(1200px 600px at 80% -10%, #1a2740 0%, transparent 55%),
             radial-gradient(900px 500px at -10% 110%, #241a3a 0%, transparent 50%);
  --panel: #12151d;
  --panel-2: #1a1e28;
  --panel-3: #222734;
  --border: #272d3a;
  --border-soft: #1e2430;
  --text: #eef1f7;
  --muted: #8891a3;
  --muted-2: #5f6675;
  --accent: #5b8dff;
  --accent-2: #7c5bff;
  --green: #34d399;
  --red: #f26d6d;
  --amber: #f3b04a;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Inter", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

#app { display: flex; height: 100vh; overflow: hidden; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 320px; min-width: 320px;
  background: rgba(18,21,29,.85);
  backdrop-filter: blur(12px);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 18px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  font-size: 20px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand-name { font-size: 16px; font-weight: 700; letter-spacing: .3px; }

.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); cursor: pointer; transition: .15s;
}
.icon-btn:hover { border-color: var(--accent); background: var(--panel-3); }

.search-box { position: relative; padding: 0 14px 12px; }
.search-icon { position: absolute; left: 26px; top: 9px; color: var(--muted-2); width: 16px; height: 16px; }
.search-box input { width: 100%; padding-left: 34px; }

.list-meta { padding: 4px 20px; color: var(--muted-2); font-size: 11px; text-transform: uppercase; letter-spacing: .8px; }

.profile-list { list-style: none; margin: 0; padding: 6px 10px; overflow-y: auto; flex: 1; }
.profile-item {
  padding: 11px 12px; border-radius: 10px; cursor: pointer;
  display: flex; align-items: center; gap: 11px; margin-bottom: 4px;
  border: 1px solid transparent; transition: .12s;
}
.profile-item:hover { background: var(--panel-2); }
.profile-item.active { background: var(--panel-2); border-color: var(--accent); }
.profile-item .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted-2); flex: none; position: relative; }
.profile-item.running .dot { background: var(--green); box-shadow: 0 0 0 3px rgba(52,211,153,.2); }
.profile-item .meta { overflow: hidden; flex: 1; }
.profile-item .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-item .tags { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.profile-item .state { font-size: 10px; padding: 2px 7px; border-radius: 20px; background: var(--panel-3); color: var(--muted); flex: none; }
.profile-item.running .state { background: rgba(52,211,153,.15); color: var(--green); }

.sidebar-footer { padding: 12px 14px; border-top: 1px solid var(--border); }
.token-row { display: flex; align-items: center; gap: 8px; }
.token-row .key-icon { color: var(--muted-2); width: 16px; flex: none; }
.token-row input { flex: 1; }

/* ---------- Main ---------- */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
  background: rgba(18,21,29,.6); backdrop-filter: blur(8px);
}
.tabs { display: flex; gap: 6px; }
.tab {
  display: flex; align-items: center; gap: 8px;
  background: transparent; border: 1px solid transparent; color: var(--muted);
  padding: 8px 14px; cursor: pointer; border-radius: 10px; font-size: 14px; font-weight: 500;
}
.tab svg { width: 16px; height: 16px; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); background: var(--panel-2); border-color: var(--border); }

.topbar-right { display: flex; align-items: center; gap: 12px; }
.sel-name { color: var(--muted); font-size: 13px; }
.pill {
  font-size: 12px; padding: 5px 12px; border-radius: 20px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
}
.pill.ok { color: var(--green); border-color: rgba(52,211,153,.4); background: rgba(52,211,153,.1); }
.pill.err { color: var(--red); border-color: rgba(242,109,109,.4); background: rgba(242,109,109,.1); }
.pill.busy { color: var(--amber); border-color: rgba(243,176,74,.4); background: rgba(243,176,74,.1); }

.tab-panel { display: none; flex: 1; overflow: auto; padding: 22px; }
.tab-panel.active { display: block; }

/* ---------- Empty state ---------- */
.empty-state { max-width: 420px; margin: 8vh auto; text-align: center; color: var(--muted); }
.empty-illus {
  font-size: 56px; margin-bottom: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.empty-state h2 { color: var(--text); margin: 0 0 8px; font-size: 20px; }
.empty-state p { margin: 0 0 18px; line-height: 1.5; }

/* ---------- Form ---------- */
.profile-form { max-width: 760px; margin: 0 auto; }
.form-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.form-head h2 { margin: 0; font-size: 20px; }
.form-head-actions { display: flex; gap: 8px; }

.card {
  background: var(--panel); border: 1px solid var(--border-soft); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.card-title { font-size: 12px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted-2); margin-bottom: 14px; }
.form-row { margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.form-row:last-child { margin-bottom: 0; }
.form-row label { color: var(--muted); font-size: 12px; }
.form-two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.proxy-grid { display: grid; grid-template-columns: 120px 1fr 90px; gap: 10px; }
.proxy-grid input:nth-child(4) { grid-column: 1 / 3; }
.proxy-grid input:nth-child(5) { grid-column: 3 / 4; }

input, textarea, select {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 10px 12px; border-radius: 10px; font-size: 14px; font-family: inherit; outline: none;
  transition: .12s; width: 100%;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91,141,255,.15); }
textarea { resize: vertical; }

.form-actions { display: flex; align-items: center; gap: 12px; }
.form-actions.sticky {
  position: sticky; bottom: 0; padding: 14px 0;
  background: linear-gradient(transparent, var(--bg) 40%);
}
.save-hint { color: var(--green); font-size: 13px; opacity: 0; transition: opacity .2s; }
.save-hint.show { opacity: 1; }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  padding: 10px 16px; border-radius: 10px; cursor: pointer; font-size: 13px; font-weight: 500;
  transition: .12s; white-space: nowrap;
}
.btn:hover { filter: brightness(1.12); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.sm { padding: 8px 12px; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: none; color: #fff; }
.btn-success { background: rgba(52,211,153,.15); border-color: rgba(52,211,153,.4); color: var(--green); }
.btn-warn { background: rgba(243,176,74,.12); border-color: rgba(243,176,74,.4); color: var(--amber); }
.btn-danger { background: rgba(242,109,109,.12); border-color: rgba(242,109,109,.4); color: var(--red); }
.btn-ghost { background: transparent; }
.ghost-danger { }

.hidden { display: none !important; }

/* ---------- Live: nav bar ---------- */
.nav-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.nav-btn {
  width: 38px; height: 38px; display: grid; place-items: center; flex: none;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); cursor: pointer; transition: .12s;
}
.nav-btn:hover { border-color: var(--accent); background: var(--panel-3); }
.url-field { position: relative; flex: 1; display: flex; align-items: center; }
.url-field .lock { position: absolute; left: 12px; color: var(--muted-2); width: 15px; height: 15px; }
.url-field input { padding-left: 34px; height: 38px; }

/* ---------- Live: stage ---------- */
.live-wrap { display: flex; justify-content: center; }
.live-stage {
  position: relative; background: #000; border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  max-width: 100%; line-height: 0;
}
#screen { display: block; max-width: 100%; height: auto; cursor: crosshair; outline: none; }
.live-overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 14px;
  align-items: center; justify-content: center; background: rgba(8,10,15,.82);
  color: var(--muted); font-size: 14px; text-align: center; padding: 20px; line-height: 1.4;
}
.live-overlay.hidden { display: none; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--panel-3); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Keyboard ---------- */
.kbd-bar { display: flex; align-items: center; gap: 16px; margin: 16px 0 10px; flex-wrap: wrap; }
.kbd-bar .hint { color: var(--muted); font-size: 12px; }
.kbd-bar .hint b { color: var(--accent); font-weight: 600; }
.chk { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; cursor: pointer; }
.chk input { width: auto; }

.virtual-keyboard { display: flex; flex-direction: column; gap: 6px; user-select: none; max-width: 900px; }
.vk-row { display: flex; gap: 6px; flex-wrap: wrap; }
.vk-key {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 9px; padding: 9px 13px; min-width: 42px; text-align: center; cursor: pointer;
  font-size: 13px; transition: .1s; position: relative;
}
.vk-key:hover { border-color: var(--accent); }
.vk-key.modifier { background: var(--panel-3); }
.vk-key.latched { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; color: #fff; box-shadow: 0 0 12px rgba(91,141,255,.5); }
.vk-key.pressed { background: rgba(52,211,153,.2); border-color: var(--green); color: var(--green); }
.vk-key .sub { display: block; font-size: 9px; color: var(--muted-2); margin-top: 1px; height: 10px; }
.vk-key.latched .sub { color: #dfe8ff; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--panel-3); border: 1px solid var(--border); color: var(--text);
  padding: 12px 20px; border-radius: 12px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: .25s; font-size: 14px; z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { border-color: rgba(52,211,153,.5); }
.toast.err { border-color: rgba(242,109,109,.5); }

/* ---------- Scrollbars ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--panel-3); border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--border); background-clip: content-box; }

@media (max-width: 820px) {
  .sidebar { width: 240px; min-width: 240px; }
  .form-two, .proxy-grid { grid-template-columns: 1fr; }
}
