:root {
  --bg: #0b0f14;
  --bg-elev: #111821;
  --surface: #151d28;
  --surface2: #1c2633;
  --surface3: #243041;
  --text: #e8eef6;
  --muted: #8b9bb0;
  --accent: #2dd4bf;
  --accent-dim: #14b8a6;
  --accent-soft: rgba(45, 212, 191, 0.12);
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --border: rgba(148, 163, 184, 0.14);
  --border-strong: rgba(148, 163, 184, 0.28);
  --sidebar: #080c11;
  --radius: 6px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "Consolas", monospace;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background:
    radial-gradient(1000px 600px at 85% -10%, rgba(45, 212, 191, 0.07), transparent 55%),
    radial-gradient(800px 500px at -10% 100%, rgba(56, 189, 248, 0.05), transparent 50%),
    linear-gradient(180deg, #0e141c 0%, var(--bg) 40%);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: #5eead4; }

.wrap { max-width: 1280px; margin: 0 auto; padding: 1.5rem 1.75rem 2.5rem; }

/* ── Shell ── */
.shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  padding: 1.5rem 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar .brand {
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--text);
  text-decoration: none;
  padding: 0 0.65rem;
}
.sidebar .brand:hover { color: var(--accent); }
.brand-sub {
  margin: 0 0.65rem 1.5rem;
  font-size: 0.68rem;
  font-family: var(--mono);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.14em;
}
.side-nav { display: flex; flex-direction: column; gap: 0.2rem; flex: 1; }
.side-nav a {
  color: var(--muted);
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  border: 1px solid transparent;
  transition: background 0.15s var(--ease), color 0.15s var(--ease), border-color 0.15s var(--ease);
}
.side-nav a:hover {
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}
.side-nav a.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: rgba(45, 212, 191, 0.25);
}
.side-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  padding: 1rem 0.65rem 0.25rem;
  margin-top: 1rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
}
.side-foot a { color: var(--muted); font-size: 0.8rem; }
.side-foot a:hover { color: var(--accent); }

.shell-main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.75rem;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 15, 20, 0.82);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.status-chips { display: flex; flex-wrap: wrap; gap: 0.45rem; align-items: center; }
.chip {
  font-size: 0.7rem;
  font-family: var(--mono);
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  letter-spacing: 0.02em;
}
.chip.ok {
  color: var(--ok);
  border-color: rgba(52, 211, 153, 0.35);
  background: rgba(52, 211, 153, 0.08);
}
.topbar-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-shrink: 0;
}
.shell-content { flex: 1; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.35rem;
}
.page-head h1 { margin: 0 0 0.2rem; }
.page-head .page-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

header.appbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 15, 20, 0.9);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}
header .brand {
  font-weight: 700;
  letter-spacing: -0.03em;
  font-size: 1.25rem;
  color: var(--text);
}
header nav { display: flex; gap: 1rem; align-items: center; color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.35rem;
  margin-bottom: 1rem;
}
.card.quiet { padding: 0.85rem 1.1rem; background: var(--bg-elev); }
.table-card { padding: 0; overflow: hidden; }

h1, h2, h3 { margin: 0 0 0.75rem; font-weight: 600; letter-spacing: -0.02em; }
h1 { font-size: 1.65rem; }
h2 { font-size: 0.78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 0.85rem; }

.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 0.88em; }
.tiny { font-size: 0.72rem; }
.log-list {
  margin: 0.65rem 0 0;
  padding-left: 1.1rem;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.55;
}

label {
  display: block;
  margin: 0.85rem 0 0.35rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

input:not([type]),
input[type="text"],
input[type="password"],
input[type="number"],
input[type="email"],
input[type="search"],
input[type="url"],
select,
textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 0.7rem 0.85rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  transition: border-color 0.15s var(--ease);
}
input:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { min-height: 160px; font-family: var(--mono); font-size: 0.82rem; }
select {
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  background-color: var(--bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='%238b9bb0'%3E%3Cpath d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  padding-right: 2rem;
}

.user-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  max-width: 720px;
}
.form-section h2 {
  margin-bottom: 0.35rem;
}
.form-section .field {
  min-width: 0;
}
.form-section .field > label:first-child {
  margin-top: 0.55rem;
}
.form-section .grid-2 > .field:first-child > label:first-child,
.form-section > .field:first-of-type > label:first-child {
  margin-top: 0.15rem;
}
.field-with-hint {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.field-hint {
  font-size: 0.72rem;
  color: var(--muted);
  font-family: var(--mono);
  letter-spacing: 0.01em;
}
.form-actions {
  margin-top: 1rem;
}

.row { display: flex; gap: 0.45rem; flex-wrap: wrap; align-items: center; }
.row > * { margin: 0; }
.inline-form { display: inline; }

/* Action clusters — power buttons + More menu */
.actions-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  max-width: none;
}
.cell-controls { min-width: 12rem; }
.actions-row .btn,
.actions-row .inline-form .btn {
  border-radius: var(--radius);
  margin: 0;
}
.actions-more {
  position: relative;
}
.actions-more > summary {
  list-style: none;
  cursor: pointer;
}
.actions-more > summary::-webkit-details-marker { display: none; }
.actions-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 40;
  min-width: 9rem;
  padding: 0.35rem;
  background: var(--surface2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: 0 12px 28px rgba(0,0,0,0.45);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.actions-menu a,
.actions-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.45rem 0.65rem;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  text-decoration: none;
}
.actions-menu a:hover,
.actions-menu button:hover {
  background: var(--surface3);
}
.actions-menu .action-danger button {
  color: var(--err);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface2);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease);
  white-space: nowrap;
}
.btn:hover {
  background: var(--surface3);
  border-color: rgba(148, 163, 184, 0.4);
  text-decoration: none;
  color: var(--text);
}
.btn:disabled { opacity: 0.45; cursor: wait; }
.btn-primary {
  background: var(--accent-dim);
  border-color: var(--accent-dim);
  color: #042f2e;
  font-weight: 600;
}
.btn-primary:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #042f2e;
}
.btn-danger {
  background: transparent;
  border-color: rgba(248, 113, 113, 0.4);
  color: var(--err);
}
.btn-danger:hover {
  background: rgba(248, 113, 113, 0.12);
  border-color: var(--err);
  color: var(--err);
}
.btn-ok {
  background: rgba(52, 211, 153, 0.1);
  border-color: rgba(52, 211, 153, 0.35);
  color: var(--ok);
}
.btn-ok:hover {
  background: rgba(52, 211, 153, 0.18);
  color: var(--ok);
}
.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
}
.btn-ghost:hover { color: var(--text); background: var(--surface2); }
.btn-sm { padding: 0.38rem 0.7rem; font-size: 0.78rem; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td {
  text-align: left;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: var(--bg-elev);
}
tbody tr { transition: background 0.12s var(--ease); }
tbody tr:hover { background: rgba(45, 212, 191, 0.04); }
tbody tr:last-child td { border-bottom: 0; }

.badge {
  display: inline-block;
  padding: 0.18rem 0.5rem;
  border-radius: 4px;
  font-size: 0.68rem;
  font-family: var(--mono);
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--muted);
  text-transform: lowercase;
}
.badge.running, .badge.ok {
  color: var(--ok);
  border-color: rgba(52, 211, 153, 0.35);
  background: rgba(52, 211, 153, 0.1);
}
.badge.starting, .badge.installing_apps, .badge.warn {
  color: var(--warn);
  border-color: rgba(251, 191, 36, 0.35);
  background: rgba(251, 191, 36, 0.1);
}
.badge.error, .badge.err {
  color: var(--err);
  border-color: rgba(248, 113, 113, 0.35);
  background: rgba(248, 113, 113, 0.1);
}
.badge.stopped { color: var(--muted); }

.alert {
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  font-size: 0.9rem;
}
.alert-error {
  background: rgba(248, 113, 113, 0.1);
  border-color: rgba(248, 113, 113, 0.35);
  color: #fecaca;
}
.alert-ok {
  background: rgba(52, 211, 153, 0.1);
  border-color: rgba(52, 211, 153, 0.35);
  color: #a7f3d0;
}

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(700px 400px at 50% 0%, rgba(45, 212, 191, 0.12), transparent 60%),
    var(--bg);
}
.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  padding: 2rem 1.75rem;
}
.login-brand {
  font-size: 2.1rem;
  font-weight: 700;
  letter-spacing: -0.05em;
  margin-bottom: 0.35rem;
  color: var(--text);
}

.iframe-wrap {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: #0a0e13;
  min-height: 70vh;
}
.iframe-wrap iframe { width: 100%; height: 70vh; border: 0; }
.session-wrap { max-width: 420px; }
.session-desktop {
  /* Portrait canvas matching Xvfb 720x1280 (noVNC resize=scale fills it) */
  aspect-ratio: 720 / 1280;
  width: min(100%, 420px);
  min-height: 0;
  height: auto;
  max-height: calc(100vh - 8rem);
  margin: 0 auto;
  background: #000;
  position: relative;
  overflow: hidden;
}
.session-desktop iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  display: block;
  border: 0;
}
.phone-view-page {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  background: #0a0e13;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.phone-view-bar {
  flex: 0 0 auto;
  width: min(100%, 420px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.65rem 0.75rem;
  color: #94a3b8;
  font-size: 0.85rem;
}
.phone-view-bar a { color: #2dd4bf; }
.phone-view-frame {
  flex: 1 1 auto;
  aspect-ratio: 720 / 1280;
  width: min(100vw - 1.5rem, calc((100vh - 3.5rem) * 720 / 1280), 420px);
  height: auto;
  max-height: calc(100vh - 3.5rem);
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid #1f2937;
  box-shadow: 0 20px 50px rgba(0,0,0,0.45);
  /* Contain noVNC's internal scroll when canvas briefly exceeds frame */
  position: relative;
}
.phone-view-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  overflow: hidden;
}

.check {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-top: 0.85rem;
  color: var(--muted);
  font-size: 0.9rem;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
}
.check input { width: auto; accent-color: var(--accent); }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

/* Proxies pool */
.proxy-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
}
.proxy-toolbar .px-bulk-actions { gap: 0.35rem; }
.proxy-table .th-sort {
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
  padding: 0;
  cursor: pointer;
  text-align: left;
}
.proxy-table .th-sort:hover { color: var(--accent); }
.proxy-table .col-check { width: 2rem; }
.table-scroll { overflow-x: auto; }
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.toast {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  padding: 0.75rem 1.1rem;
  border-radius: var(--radius);
  background: var(--surface3);
  border: 1px solid var(--border-strong);
  color: var(--text);
  z-index: 50;
  font-size: 0.88rem;
  font-family: var(--mono);
}
.toast.err { border-color: rgba(248, 113, 113, 0.5); color: #fecaca; }
.toast.ok { border-color: rgba(52, 211, 153, 0.5); color: #a7f3d0; }

.stat-line {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  margin: 0.15rem 0 0.55rem;
  font-variant-numeric: tabular-nums;
}
.metric-card .stat-line { color: var(--text); }

.cell-desktop {
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 500;
}

@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: relative;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
  }
  .side-nav { flex-direction: row; flex-wrap: wrap; flex: 1; }
  .side-foot { border: 0; padding: 0; width: 100%; margin: 0; }
  .brand-sub { display: none; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .actions-row { flex-wrap: wrap; gap: 0.35rem; }
  .actions-row .btn,
  .actions-row .inline-form .btn { border-radius: var(--radius) !important; }
  table { font-size: 0.8rem; }
  th, td { padding: 0.65rem 0.7rem; }
}
