:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f232c;
  --line: #2a2f3a;
  --text: #e6e6e6;
  --muted: #9aa3b2;
  --accent: #f5a524;
  --danger: #ff6b6b;
  --ok: #5ccf8a;
  --app-h: 100dvh;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; }
button { font: inherit; color: inherit; }

/* ── Вход ─────────────────────────────────────────────── */

.login-page { display: grid; place-items: center; padding: 16px; overflow: auto; }
.login-card {
  width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 24px; display: flex; flex-direction: column; gap: 8px;
}
.login-logo { align-self: center; }
.login-card h1 { margin: 4px 0 0; text-align: center; font-size: 22px; }
.login-card .muted { margin: 0 0 12px; text-align: center; color: var(--muted); font-size: 14px; }
.login-card label { font-size: 14px; color: var(--muted); margin-top: 6px; }
.login-card input {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; color: var(--text);
  padding: 12px; font-size: 17px;
}
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.password-wrap { position: relative; display: flex; }
.password-wrap input { flex: 1; padding-right: 48px; min-width: 0; }
.eye {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 40px; height: 40px;
  display: grid; place-items: center; border: 0; background: transparent; color: var(--muted); cursor: pointer; border-radius: 8px;
}
.eye:hover, .eye:focus-visible { color: var(--text); }
.eye[aria-pressed="false"] .eye-slash { display: none; }
#code { letter-spacing: 4px; font-variant-numeric: tabular-nums; }
.login-card button[type="submit"] {
  margin-top: 12px; padding: 13px; border: 0; border-radius: 10px; background: var(--accent);
  color: #111; font-weight: 600; font-size: 16px; cursor: pointer;
}
.login-card button:disabled { opacity: .6; }
.error { color: var(--danger); margin: 4px 0 0; font-size: 14px; }

/* ── Приложение ───────────────────────────────────────── */

#app {
  height: var(--app-h); display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

.topbar {
  display: flex; align-items: center; gap: 4px; padding: 6px; background: var(--panel);
  border-bottom: 1px solid var(--line); flex: none;
}
.tabs { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: transparent; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.tab small { margin-left: 6px; font-size: 11px; color: var(--muted); opacity: .8; }
.tab.active { background: var(--panel-2); color: var(--text); border-color: var(--accent); }
.icon-btn {
  flex: none; width: 38px; height: 36px; border-radius: 8px; border: 1px solid var(--line);
  background: transparent; cursor: pointer; font-size: 17px;
}

#terminal-wrap { flex: 1; min-height: 0; position: relative; padding: 4px 2px 0 6px; }
#terminal { height: 100%; }
.status {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 14px; font-size: 13px; color: var(--muted); white-space: nowrap;
}

.keybar {
  flex: none; display: flex; gap: 5px; overflow-x: auto; padding: 6px;
  padding-bottom: calc(6px + env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--line); scrollbar-width: none;
}
.keybar::-webkit-scrollbar { display: none; }
.keybar button {
  flex: none; min-width: 44px; height: 40px; padding: 0 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel-2); cursor: pointer;
  font-size: 15px; touch-action: manipulation; user-select: none;
}
.keybar button:active { background: var(--line); }
.keybar button.armed { background: var(--accent); color: #111; border-color: var(--accent); }

/* ── Нижний лист ──────────────────────────────────────── */

.sheet { position: fixed; inset: 0; background: rgb(0 0 0 / .5); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet[hidden] { display: none; }
.sheet-card {
  width: 100%; max-width: 520px; max-height: 80dvh; overflow: auto; background: var(--panel);
  border: 1px solid var(--line); border-radius: 16px 16px 0 0; padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 8px; }
.sheet-head h2 { font-size: 17px; margin: 0; }
.sheet-item {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; text-align: left;
  padding: 12px; margin-bottom: 6px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel-2); cursor: pointer;
}
.sheet-item small { color: var(--muted); }
.sheet-item.danger strong { color: var(--danger); }
.login-row { font: 13px/1.5 ui-monospace, monospace; padding: 4px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; overflow-x: auto; }
.login-row.fail { color: var(--danger); }
.link-row { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 8px; background: var(--panel-2); }
.link-text { font: 12px/1.45 ui-monospace, monospace; word-break: break-all; color: var(--muted); max-height: 7.5em; overflow: auto; }
.link-actions { display: flex; gap: 8px; margin-top: 8px; }
.link-actions button { flex: 1; padding: 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; }
.link-actions button:first-child { background: var(--accent); color: #111; border-color: var(--accent); font-weight: 600; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: 14px; color: var(--muted); }
.field input { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; color: var(--text); padding: 11px; font-size: 16px; }
.field input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.field small { font-size: 12px; }
.check { display: flex; align-items: center; gap: 8px; margin: 4px 0 12px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.primary { width: 100%; padding: 13px; border: 0; border-radius: 10px; background: var(--accent); color: #111; font-weight: 600; cursor: pointer; }
.primary:disabled { opacity: .7; }
.muted-note { color: var(--muted); font-size: 14px; margin: 0 4px 10px; }
