:root {
  --bg: #0b0d12; --panel: #141821; --panel2: #1b2030; --line: #262c3d;
  --text: #e7eaf0; --muted: #8b93a7; --accent: #7c5cff; --ok: #3ecf8e; --warn: #f5a524; --bad: #ff5c5c;
  --vh: 100dvh;
  --st: env(safe-area-inset-top); --sb: env(safe-area-inset-bottom);
  --sl: env(safe-area-inset-left); --sr: env(safe-area-inset-right);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  overscroll-behavior: none; }
body { position: fixed; inset: 0; overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, textarea, select { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; width: 100%; font-size: 16px; /* 16px stops iOS zoom */ }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--bad); min-height: 1.4em; }

#app { height: var(--vh); display: flex; flex-direction: column; padding-left: var(--sl); padding-right: var(--sr); }
.screen { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* login */
#login { align-items: center; justify-content: center; padding: 24px; }
.login-box { text-align: center; max-width: 320px; width: 100%; }
.logo { font: 700 44px ui-monospace, Menlo, monospace; color: var(--accent); }
.login-box h1 { margin: 8px 0 4px; font-size: 26px; }

.btn { padding: 8px 14px; border-radius: 10px; background: var(--panel2); border: 1px solid var(--line); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.big { width: 100%; padding: 14px; font-size: 17px; margin-top: 18px; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:active, .row:active { opacity: .6; }

/* header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(var(--st) + 8px) 16px 8px; border-bottom: 1px solid var(--line); background: var(--bg); }
.top h2 { margin: 0; font-size: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 6px; flex-shrink: 0; }

.views { flex: 1; min-height: 0; position: relative; }
.view { position: absolute; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 16px 24px; display: none; }
.view.active { display: block; }
.term-view { padding: 0; overflow: hidden; }
.term-view.active { display: flex; }
.term { flex: 1; min-width: 0; padding: 4px 2px 0 6px; background: #000; }
.term .xterm { height: 100%; }
.term .xterm-viewport { overscroll-behavior: contain; }

h3 { margin: 22px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }

/* stat cards */
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.card .k { font-size: 12px; color: var(--muted); }
.card .v { font-size: 22px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.card .s { font-size: 12px; color: var(--muted); }
.bar { height: 5px; background: var(--panel2); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--ok); border-radius: 3px; transition: width .4s; }
.bar i.warn { background: var(--warn); } .bar i.bad { background: var(--bad); }

/* lists */
.list { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.row { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 12px 14px;
  border-bottom: 1px solid var(--line); min-height: 48px; }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .d { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row.danger { color: var(--bad); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.dot.on { background: var(--ok); box-shadow: 0 0 6px var(--ok); } .dot.off { background: var(--bad); }
.pill { font-size: 11px; padding: 2px 7px; border-radius: 99px; background: var(--panel2); color: var(--muted); flex-shrink: 0; }
.pill.y { color: var(--warn); } .pill.g { color: var(--ok); }
.empty { padding: 16px; color: var(--muted); text-align: center; }

/* files / code */
.crumbs { display: flex; flex-wrap: wrap; gap: 2px; font-size: 13px; margin-bottom: 10px; }
.crumbs button { color: var(--accent); padding: 2px 4px; }
pre.code, textarea.code { font: 12px/1.45 ui-monospace, Menlo, monospace; white-space: pre; overflow: auto;
  background: #000; border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin: 0; tab-size: 2; }
textarea.code { min-height: 60vh; resize: vertical; }
.diff .a { color: var(--ok); } .diff .r { color: var(--bad); } .diff .h { color: #5cc8ff; } .diff .m { color: var(--muted); }
.seg { display: flex; background: var(--panel2); border-radius: 10px; padding: 3px; margin-bottom: 12px; }
.seg button { flex: 1; padding: 7px; border-radius: 8px; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--panel); color: var(--text); font-weight: 600; }
.formrow { display: flex; gap: 8px; margin: 10px 0; }

/* key bar above keyboard */
.keybar { display: flex; gap: 4px; overflow-x: auto; padding: 6px 6px; background: var(--panel);
  border-top: 1px solid var(--line); scrollbar-width: none; flex-shrink: 0; }
.keybar::-webkit-scrollbar { display: none; }
.keybar button { flex-shrink: 0; min-width: 40px; height: 36px; padding: 0 9px; border-radius: 8px;
  background: var(--panel2); border: 1px solid var(--line); font: 600 14px ui-monospace, Menlo, monospace; }
.keybar button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.keybar button:active { background: var(--accent); }

/* tabs */
.tabs { display: flex; border-top: 1px solid var(--line); background: var(--panel); padding-bottom: var(--sb); flex-shrink: 0; }
.tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 7px 0 5px;
  font-size: 10.5px; color: var(--muted); }
.tabs button span { font-size: 21px; filter: grayscale(1) opacity(.7); }
.tabs button.active { color: var(--text); }
.tabs button.active span { filter: none; }
body.kbd-open .tabs { display: none; }

/* sheet */
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 20; display: flex; align-items: flex-end; }
.sheet-panel { background: var(--bg); width: 100%; height: calc(var(--vh) - var(--st) - 20px); border-radius: 16px 16px 0 0;
  display: flex; flex-direction: column; border-top: 1px solid var(--line); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); gap: 10px; }
.sheet-head b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-body { flex: 1; overflow: auto; padding: 12px 16px calc(var(--sb) + 16px); -webkit-overflow-scrolling: touch; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); top: calc(var(--st) + 10px); z-index: 30;
  background: var(--panel2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; max-width: 90vw;
  box-shadow: 0 6px 24px rgba(0,0,0,.5); }
.conn { font-size: 12px; padding: 4px 8px; border-radius: 8px; background: var(--panel2); color: var(--muted); }
.conn.on { color: var(--ok); } .conn.off { color: var(--bad); }
