/* Xtron — single stylesheet, no framework, no webfont, no CDN.
   System fonts keep first paint instant; one file keeps it to one request. */

:root {
  --bg: #0a0c10;
  --bg-soft: #11151c;
  --panel: #151a23;
  --line: #232b38;
  --line-soft: #1b2230;
  --text: #e8edf5;
  --muted: #8b98ad;
  --accent: #4c8dff;
  --accent-2: #7aa2ff;
  --ok: #2fd08a;
  --warn: #ffb648;
  --bad: #ff5f6d;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(76, 141, 255, .10), transparent 60%),
    radial-gradient(900px 500px at 0% 0%, rgba(122, 162, 255, .06), transparent 55%),
    var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

a { color: var(--accent-2); text-decoration: none; }
h1, h2, h3 { margin: 0; letter-spacing: -.02em; font-weight: 650; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1.05rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.hidden { display: none !important; }
.ok { color: var(--ok); }

/* ---------- auth ---------- */
body.auth { display: grid; place-items: center; padding: 24px; }

.auth-card {
  width: min(400px, 100%);
  background: linear-gradient(180deg, rgba(255,255,255,.03), transparent), var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 30px;
  box-shadow: var(--shadow);
}

.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.brand strong { font-size: 1.05rem; letter-spacing: -.01em; }

.brand-mark {
  display: grid; place-items: center;
  width: 36px; height: 36px; flex: 0 0 36px;
  border-radius: 10px;
  background: var(--text); color: #0a0c10;
  font-weight: 800; font-size: 19px; letter-spacing: -.03em;
}

.brand p { margin: 2px 0 0; font-size: .82rem; }

/* ---------- form controls ---------- */
.stack { display: grid; gap: 14px; }

.field { display: grid; gap: 6px; }
.field > span { font-size: .8rem; color: var(--muted); font-weight: 550; letter-spacing: .01em; }

input, select {
  width: 100%;
  padding: 11px 13px;
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  outline: none;
  transition: border-color .12s ease, box-shadow .12s ease;
}
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(76, 141, 255, .18);
}
input::placeholder { color: #5b667a; }

.btn {
  -webkit-appearance: none;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  font: inherit;
  font-weight: 560;
  cursor: pointer;
  transition: transform .08s ease, background .12s ease, border-color .12s ease;
}
.btn:hover { border-color: #33405a; background: #1a2230; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #06121f; font-weight: 650; }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.ghost { background: transparent; }
.btn.danger { border-color: rgba(255, 95, 109, .35); color: var(--bad); background: transparent; }
.btn.danger:hover { background: rgba(255, 95, 109, .1); border-color: rgba(255, 95, 109, .65); }
.btn.danger:disabled { opacity: .4; }
.btn.block { width: 100%; }

.alert {
  background: rgba(255, 95, 109, .12);
  border: 1px solid rgba(255, 95, 109, .35);
  color: #ffc2c6;
  padding: 10px 13px;
  border-radius: 10px;
  font-size: .88rem;
  margin: 0 0 16px;
}

.fineprint { margin: 18px 0 0; font-size: .76rem; }

/* ---------- app shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px clamp(14px, 3vw, 32px);
  background: rgba(10, 12, 16, .82);
  backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line-soft);
}
.topbar .brand { margin: 0; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.pill {
  font-size: .74rem; padding: 3px 9px; border-radius: 999px;
  background: var(--bg-soft); border: 1px solid var(--line); color: var(--muted);
}

.wrap { padding: clamp(16px, 3vw, 32px); max-width: 1400px; margin: 0 auto; }

.stats {
  display: grid; gap: 12px; margin-bottom: 26px;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}
.stat {
  background: var(--panel); border: 1px solid var(--line-soft);
  border-radius: var(--radius); padding: 14px 16px;
  display: grid; gap: 3px;
}
.stat-k { font-size: .74rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.stat-v { font-size: 1.5rem; font-weight: 660; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }

.fleet-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }

.grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}

/* ---------- phone card ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 16px;
  display: grid; gap: 12px;
  transition: border-color .14s ease, transform .14s ease;
}
.card:hover { border-color: var(--line); transform: translateY(-1px); }
.card.busy { border-color: rgba(76, 141, 255, .5); }

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-name { font-weight: 640; font-size: 1rem; letter-spacing: -.01em; }

.badge {
  font-size: .71rem; font-weight: 620; letter-spacing: .04em;
  padding: 3px 8px; border-radius: 999px; text-transform: uppercase;
  border: 1px solid transparent;
}
.badge.running { background: rgba(47, 208, 138, .13); color: var(--ok); border-color: rgba(47, 208, 138, .3); }
.badge.stopped { background: rgba(139, 152, 173, .12); color: var(--muted); border-color: rgba(139, 152, 173, .25); }
.badge.missing { background: rgba(255, 95, 109, .12); color: var(--bad); border-color: rgba(255, 95, 109, .3); }
.badge.building { background: rgba(76, 141, 255, .14); color: var(--accent-2); border-color: rgba(76, 141, 255, .35); }

.meta { display: grid; gap: 6px; font-size: .84rem; }
.meta-row { display: flex; justify-content: space-between; gap: 12px; }
.meta-row dt { color: var(--muted); margin: 0; }
.meta-row dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; }

.card-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.card-actions .btn { padding: 8px 12px; font-size: .84rem; }
.empty {
  grid-column: 1 / -1; text-align: center; padding: 44px 20px;
  border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted);
}

/* ---------- job panel ---------- */
.panel {
  margin-top: 26px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
}
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 12px; }
.panel-head p { margin: 3px 0 0; }
.panel-actions { display: flex; flex-wrap: wrap; align-items: end; gap: 8px; }
.job-picker { display: grid; gap: 3px; min-width: 160px; }
.job-picker select { padding: 8px 10px; font-size: .85rem; }

.progress { height: 6px; background: var(--bg-soft); border-radius: 999px; overflow: hidden; margin-bottom: 12px; }
.progress-bar { height: 100%; width: 0%; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .5s ease; }

.job-eta { margin: 0 0 12px; }

/* Build plan. The script's free-form log is unreadable as a progress signal, so
   the ordered steps are the primary display and the log is the evidence. */
.steps {
  list-style: none; margin: 0 0 12px; padding: 0;
  display: grid; gap: 2px;
  max-height: 260px; overflow: auto;
}
.steps:empty { display: none; }
.step {
  display: grid; grid-template-columns: 20px 1fr auto; align-items: baseline;
  gap: 10px; padding: 7px 10px; border-radius: 9px; font-size: .85rem;
  border: 1px solid transparent; color: var(--muted);
}
.step-dot { font-size: .8rem; line-height: 1; text-align: center; }
.step-time { font-variant-numeric: tabular-nums; font-size: .78rem; color: var(--muted); }
.step.pending { opacity: .5; }
.step.active {
  color: var(--text); background: rgba(76, 141, 255, .08);
  border-color: rgba(76, 141, 255, .28);
}
.step.active .step-dot { color: var(--accent-2); animation: pulse 1.2s ease-in-out infinite; }
.step.done { color: #b9c4d4; }
.step.done .step-dot { color: var(--ok); }
.step.failed { color: var(--bad); background: rgba(255, 95, 109, .08); border-color: rgba(255, 95, 109, .3); }
.step.failed .step-dot { color: var(--bad); }
.step.skipped { opacity: .38; }
@keyframes pulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }

.log {
  margin: 0; max-height: 280px; overflow: auto;  background: #0b0e13; border: 1px solid var(--line-soft); border-radius: 10px;
  padding: 12px; font-size: .78rem; line-height: 1.5;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: #b9c4d4; white-space: pre-wrap; word-break: break-word;
}

/* ---------- dialog ---------- */
.dialog {
  border: 1px solid var(--line); border-radius: 18px;
  background: var(--panel); color: var(--text);
  padding: 24px; width: min(480px, calc(100vw - 32px));
  box-shadow: var(--shadow);
}
.dialog.wide { width: min(560px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(4, 6, 10, .72); backdrop-filter: blur(3px); }
.dialog form { display: grid; gap: 14px; }
.dialog h3 { margin-bottom: 2px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.screen-stage {
  display: flex; align-items: center; justify-content: center;
  min-height: 160px; max-height: 68vh; overflow: hidden;
  background: #080a0e; border: 1px solid var(--line); border-radius: 12px;
}
#screen-canvas {
  display: block; max-width: 100%; max-height: 68vh; width: auto; height: auto;
  touch-action: none; cursor: crosshair; outline: none;
}
#screen-canvas:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.screen-controls { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.screen-controls .btn { padding: 8px 12px; font-size: .85rem; }
.screen-controls .btn.bypass { border-color: rgba(255, 182, 72, .35); color: var(--warn); }
.screen-controls .btn.bypass:hover { background: rgba(255, 182, 72, .1); border-color: rgba(255, 182, 72, .6); }
.screen-bypass-status { margin: 8px 0 0; }
.screen-bypass-status:empty { display: none; }
.screen-text-form { display: flex !important; gap: 8px; margin-top: 10px; }
.screen-text-form input { min-width: 0; }
.screen-help { margin: 8px 0 0; }

@media (max-width: 560px) {
  .topbar { flex-wrap: wrap; }
  .grid { grid-template-columns: 1fr; }
  .stat-v { font-size: 1.3rem; }
  .dialog { padding: 18px; }
}
