*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #111113; --bg2: #1A1A1F; --bg3: #23232B; --border: #2A2A32;
  --fg: #E8E8EE; --fg2: #C8C8D2; --muted: #8A8A9A;
  --accent: #9E8FB2; --accent-h: #B8A8CC;
  --error: #C0624A; --success: #6A9E7F; --warn: #B89A4A;
}

html, body { height: 100%; background: var(--bg); color: var(--fg); font-family: 'Inter', 'Geist', -apple-system, system-ui, sans-serif; font-size: 14px; overflow: hidden; -webkit-font-smoothing: antialiased; }
.screen { position: fixed; inset: 0; }
.hidden { display: none !important; }

/* ── Animations ─────────────────────────────────────────────────────── */
@keyframes ps-spin  { to { transform: rotate(360deg); } }
@keyframes ps-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

/* ── Auth ───────────────────────────────────────────────────────────── */
.auth-container { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; gap: 12px; padding: 24px; }
.logo { font-size: 26px; font-weight: 500; margin-bottom: 8px; letter-spacing: -.01em; }
.logo span { color: var(--muted); font-weight: 400; }
.fallback { width: 100%; max-width: 320px; color: var(--muted); }
.fallback summary { cursor: pointer; padding: 8px 0; font-size: 13px; }
.fallback input { width: 100%; padding: 10px 12px; background: var(--bg2); border: 1px solid var(--border); border-radius: 6px; color: var(--fg); margin: 8px 0; font-family: inherit; outline: none; }
.fallback input:focus { border-color: var(--accent); }

/* ── Buttons ────────────────────────────────────────────────────────── */
.btn-primary {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 38%, transparent);
  color: var(--accent);
  border-radius: 8px; padding: 0 20px; height: 42px;
  font-family: inherit; font-size: 14px; font-weight: 500; cursor: pointer;
  width: 100%; max-width: 320px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: all 150ms;
}
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.btn-primary:disabled { background: var(--bg3); border-color: var(--border); color: var(--muted); cursor: default; }
.btn-secondary { background: transparent; color: var(--fg); border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; font-family: inherit; font-size: 11px; cursor: pointer; }
.btn-secondary:hover { border-color: var(--accent); color: var(--fg); }
.btn-danger { background: var(--error); color: #fff; border: none; border-radius: 6px; height: 40px; padding: 0 16px; font-family: inherit; font-size: 13px; font-weight: 500; cursor: pointer; flex: 1; }
.btn-cancel { background: transparent; color: var(--fg); border: 1px solid var(--border); border-radius: 6px; height: 40px; padding: 0 16px; font-family: inherit; font-size: 13px; font-weight: 500; cursor: pointer; flex: 1; }

/* ── App shell ──────────────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100%; overflow: hidden; }
#screens-wrapper { display: flex; width: 200%; height: 100%; transition: transform 250ms cubic-bezier(.2,.7,.3,1); }
.pane { width: 50%; height: 100%; overflow: hidden; position: relative; }

/* ── Page dots ──────────────────────────────────────────────────────── */
#page-dots { position: fixed; left: 0; right: 0; bottom: 42px; display: flex; justify-content: center; gap: 6px; pointer-events: none; z-index: 5; }
.page-dot { height: 6px; border-radius: 3px; transition: all 200ms; }
.page-dot.active  { width: 18px; background: var(--accent); opacity: .95; }
.page-dot.inactive { width: 6px; background: var(--muted); opacity: .4; }

/* ── Status dots ────────────────────────────────────────────────────── */
.status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: var(--muted); }
.status-dot.sm { width: 6px; height: 6px; }
.status-dot.online   { background: var(--success); box-shadow: 0 0 6px color-mix(in srgb, var(--success) 67%, transparent); }
.status-dot.sleeping { background: var(--muted); }
.status-dot.offline  { background: var(--error); }
.status-dot.waking   { background: var(--warn); animation: ps-pulse 1.2s ease-in-out infinite; }

/* ── Status badges ──────────────────────────────────────────────────── */
.badge { font-size: 10px; letter-spacing: .04em; text-transform: uppercase; padding: 3px 7px; border-radius: 4px; font-weight: 500; }
.badge.online  { background: color-mix(in srgb, var(--success) 13%, transparent); color: var(--success); }
.badge.standby { background: var(--bg3); color: var(--muted); }
.badge.waking  { background: color-mix(in srgb, var(--warn) 13%, transparent); color: var(--warn); }

/* ── Spinner ────────────────────────────────────────────────────────── */
.spinner { display: inline-block; width: 12px; height: 12px; border: 1.5px solid color-mix(in srgb, currentColor 20%, transparent); border-top-color: currentColor; border-radius: 50%; animation: ps-spin .7s linear infinite; flex-shrink: 0; }

/* ── Cards ──────────────────────────────────────────────────────────── */
.card { background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; padding: 16px; margin-bottom: 10px; box-shadow: 0 2px 8px rgba(0,0,0,.25); }
.card-row { display: flex; align-items: flex-start; justify-content: space-between; }
.card-identity { display: flex; align-items: center; gap: 10px; }
.card-name { font-size: 15px; font-weight: 500; color: var(--fg); }
.card-sub { font-size: 12px; color: var(--muted); margin-top: 1px; font-family: 'JetBrains Mono', monospace; }
.card-status { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }

/* ── Meters ─────────────────────────────────────────────────────────── */
.meters-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.meter-header { display: flex; justify-content: space-between; align-items: baseline; }
.meter-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 500; }
.meter-pct { font-size: 11px; color: var(--fg2); font-family: 'JetBrains Mono', monospace; font-variant-numeric: tabular-nums; }
.meter-track { height: 4px; background: var(--bg3); border-radius: 2px; margin-top: 5px; overflow: hidden; }
.meter-fill { height: 100%; border-radius: 2px; background: var(--accent); transition: width 400ms; }
.meter-fill.warn { background: var(--warn); }
.meter-sub { font-size: 10px; color: var(--muted); font-family: 'JetBrains Mono', monospace; margin-top: 4px; }

/* ── Dashboard ──────────────────────────────────────────────────────── */
.dashboard { overflow-y: auto; height: 100%; background: var(--bg); padding: 0 16px 64px; }
.dashboard-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 4px 12px; }
.dashboard-title { font-size: 22px; font-weight: 500; color: var(--fg); }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 4px; }
.stat { background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; }
.stat label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; display: block; margin-bottom: 4px; }
.stat span { font-size: 13px; font-family: 'JetBrains Mono', monospace; color: var(--fg2); }
.conn-list { background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.conn-item { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-top: 1px solid var(--border); cursor: pointer; }
.conn-item:first-child { border-top: none; }
.conn-item-info { flex: 1; }
.conn-item-name { font-size: 14px; font-weight: 500; color: var(--fg); }
.conn-item-host { font-size: 12px; color: var(--muted); font-family: 'JetBrains Mono', monospace; }
.section-label { font-size: 11px; letter-spacing: .08em; color: var(--muted); text-transform: uppercase; font-weight: 500; padding: 4px 4px 8px; }

/* ── Terminal screen ────────────────────────────────────────────────── */
#screen-terminal { display: flex; flex-direction: column; }
#terminal-container { flex: 1; overflow: hidden; }
.xterm { height: 100% !important; }

/* ── Key bar ────────────────────────────────────────────────────────── */
#key-bar { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; background: var(--bg2); border-top: 1px solid var(--border); padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); }
#key-bar::-webkit-scrollbar { display: none; }
#key-bar button { background: var(--bg3); border: none; border-radius: 6px; color: var(--fg); height: 42px; min-width: 38px; padding: 0 10px; font-family: 'JetBrains Mono', monospace; font-size: 12px; font-weight: 500; cursor: pointer; white-space: nowrap; flex-shrink: 0; transition: all 100ms; }
#key-bar button.ctrl-active { background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
#font-slider-wrap { padding: 8px 16px; background: var(--bg2); border-top: 1px solid var(--border); }
#font-slider { width: 100%; accent-color: var(--accent); }

/* ── Drawer ─────────────────────────────────────────────────────────── */
.drawer { position: fixed; bottom: 0; left: 0; right: 0; background: var(--bg2); border-radius: 16px 16px 0 0; border: 1px solid var(--border); border-bottom: none; box-shadow: 0 -8px 24px rgba(0,0,0,.5); z-index: 9; display: flex; flex-direction: column; overflow: hidden; max-height: 70vh; }
.drawer-handle { display: flex; justify-content: center; padding: 8px 0 4px; cursor: pointer; }
.drawer-content { flex: 1; overflow-y: auto; padding: 12px 16px 16px; }
.snippet-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 6px; background: var(--bg); border: 1px solid var(--border); margin-bottom: 4px; }
.snippet-item span { flex: 1; font-size: 13px; color: var(--fg); }
.toggle-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; }
.toggle-row span { flex: 1; font-size: 13px; color: var(--fg); }
.toggle-switch { width: 36px; height: 22px; border-radius: 11px; background: var(--bg3); border: 1px solid var(--border); position: relative; cursor: pointer; flex-shrink: 0; }
.toggle-switch.on { background: var(--accent); border-color: transparent; }
.toggle-thumb { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 8px; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform 150ms; }
.toggle-switch.on .toggle-thumb { transform: translateX(14px); }

/* ── Danger modal ───────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 200; padding: 20px; }
.modal-box { background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 20px; max-width: 320px; width: 100%; box-shadow: 0 16px 48px rgba(0,0,0,.6); }
.modal-box h3 { font-size: 15px; font-weight: 600; color: var(--error); margin-bottom: 12px; }
.modal-box pre { background: var(--bg); padding: 10px 12px; border-radius: 6px; border: 1px solid var(--border); font-size: 12px; font-family: 'JetBrains Mono', monospace; color: var(--fg); margin-bottom: 16px; word-break: break-all; white-space: pre-wrap; }
.modal-actions { display: flex; gap: 8px; }
.danger-icon { width: 28px; height: 28px; border-radius: 6px; background: color-mix(in srgb, var(--error) 13%, transparent); color: var(--error); display: flex; align-items: center; justify-content: center; font-size: 16px; font-weight: 700; flex-shrink: 0; }
