@font-face { font-family: "CR Mono"; src: url(/fonts/mono.woff2) format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "CR Mono"; src: url(/fonts/mono-bold.woff2) format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "CR Symbols"; src: url(/fonts/symbols.ttf) format("truetype"); font-display: swap; }

:root {
  --bg: #0f1115; --bg2: #0b0d11; --surface: #171a21; --surface2: #1e222b; --border: #2a2f3a;
  --text: #e8e8ea; --muted: #8b93a1; --faint: #5c6370;
  --accent: #d97757; --accent-press: #c2633f;
  --ok: #3ecf8e; --warn: #f5a524; --danger: #ef5350; --info: #5aa9f5;
  --r: 12px; --appbar: 52px;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden;
  font: 15px/1.4 -apple-system, system-ui, Roboto, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 8px 0 0; }
button { font: inherit; color: inherit; cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg circle { fill: currentColor; stroke: none; }

/* ---------------------------------------------------------------- buttons & inputs */
.btn { background: var(--surface2); border: 1px solid var(--border); border-radius: 10px; padding: 11px 14px;
  font-weight: 600; transition: transform .08s, filter .15s; }
.btn:active { transform: scale(.97); filter: brightness(1.2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:active { background: var(--accent-press); }
.btn.ok { background: #1f7a52; border-color: #1f7a52; color: #fff; }
.btn.danger { background: transparent; border-color: #5b2a2a; color: #ff8a80; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.sm { padding: 7px 11px; font-size: 13px; }
.btn.block { width: 100%; margin-top: 10px; }
.icon-btn { background: none; border: 0; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px;
  position: relative; color: var(--text); flex: none; }
.icon-btn:active { background: var(--surface2); }
.input, textarea { width: 100%; background: var(--bg2); color: var(--text); border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 12px; font: 16px/1.35 inherit; font-family: inherit; outline: none; }
.input:focus, textarea:focus { border-color: var(--accent); }
.label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 2px 6px; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 2px 0; min-height: 18px; }

/* ---------------------------------------------------------------- layout */
.view { position: fixed; inset: 0; display: flex; flex-direction: column; padding-top: var(--safe-top); }
#view-login { align-items: center; justify-content: center; padding: 24px; }
.login { width: 100%; max-width: 380px; text-align: center; }
.login h1 { margin: 10px 0 4px; font-size: 24px; }
.logo { width: 64px; height: 64px; margin: 0 auto; border-radius: 18px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font: 700 26px "CR Mono", monospace; }
.login .input { margin-top: 18px; text-align: center; }

.appbar { height: var(--appbar); display: flex; align-items: center; gap: 4px; padding: 0 4px; background: var(--bg);
  border-bottom: 1px solid var(--border); flex: none; touch-action: pan-y; }
.titles { flex: 1; min-width: 0; padding: 0 4px; }
.title { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.subtitle { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; }
.subtitle span:last-child { overflow: hidden; text-overflow: ellipsis; }
.badge { position: absolute; top: 6px; right: 5px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px;
  background: var(--warn); color: #111; font: 700 11px/17px system-ui; text-align: center; }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 7px 8px; border-bottom: 1px solid var(--border); flex: none;
  scrollbar-width: none; background: var(--bg); }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; display: flex; align-items: center; gap: 7px; max-width: 190px; padding: 6px 11px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); font-size: 13px; color: var(--muted); }
.tab span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab.on { background: var(--surface2); border-color: var(--accent); color: var(--text); }
.tab.add { color: var(--accent); font-weight: 700; }

.banner { flex: none; font-size: 13px; padding: 7px 12px; background: #3a2a10; color: #ffd08a; display: flex; align-items: center; gap: 8px; }
.banner .spinner { width: 14px; height: 14px; border-width: 2px; }

.stage { flex: 1; min-height: 0; position: relative; display: flex; }
.term-wrap { flex: 1; min-width: 0; position: relative; background: var(--bg2); padding: 4px 0 0 6px; }
#term { position: absolute; inset: 4px 2px 0 6px; }
.xterm .xterm-viewport { scrollbar-width: none; }
.fab { position: absolute; right: 14px; bottom: 14px; width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface2); color: var(--text); font-size: 18px; box-shadow: 0 4px 14px #0008; }
.term-loading { position: absolute; inset: 0; display: grid; place-items: center; background: #0b0d11cc; }

/* ---------------------------------------------------------------- status dots */
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.busy { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.dot.perm { background: var(--warn); box-shadow: 0 0 0 3px #f5a52433; animation: pulse 0.9s ease-in-out infinite; }
.dot.done { background: var(--ok); }
.dot.idle { background: var(--faint); }
.dot.shell { background: var(--info); }
.dot.offline { background: var(--danger); }
@keyframes pulse { 50% { opacity: .35; } }

/* ---------------------------------------------------------------- home / session list */
.home { flex: 1; overflow-y: auto; padding: 12px 12px calc(24px + var(--safe-bottom)); }
.group { margin: 6px 0 18px; }
.group-title { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 0 4px 8px;
  display: flex; justify-content: space-between; align-items: center; }
.card { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  padding: 12px 12px 12px 14px; margin-bottom: 8px; width: 100%; text-align: left; }
.card:active { background: var(--surface2); }
.card.current { border-color: var(--accent); }
.card .info { flex: 1; min-width: 0; }
.card .name { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .meta { color: var(--muted); font-size: 12.5px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .meta b { font-weight: 600; }
.card .meta .s-busy { color: var(--accent); } .card .meta .s-perm { color: var(--warn); } .card .meta .s-done { color: var(--ok); }
.card .chev { color: var(--faint); font-size: 20px; }
.empty { text-align: center; color: var(--muted); padding: 34px 20px 10px; }
.empty .big { font-size: 40px; margin-bottom: 6px; }
.cta { display: flex; gap: 8px; margin: 4px 0 18px; }
.cta .btn { flex: 1; }

/* ---------------------------------------------------------------- permission bar */
.perm-bar { flex: none; background: #2b2110; border-top: 1px solid #5a4314; padding: 10px 10px 8px; animation: slideup .18s ease-out; }
.perm-msg { display: flex; gap: 8px; align-items: center; font-size: 13.5px; color: #ffd08a; margin-bottom: 8px; }
.perm-msg span:last-child { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.perm-actions { display: grid; grid-template-columns: 1.1fr 1.2fr 1fr; gap: 8px; }
.perm-actions .btn { padding: 12px 6px; font-size: 14px; }
@keyframes slideup { from { transform: translateY(100%); } }

/* ---------------------------------------------------------------- dock: keys + composer */
.dock { flex: none; background: var(--bg); border-top: 1px solid var(--border); padding-bottom: var(--safe-bottom); }
.keys { display: flex; gap: 5px; overflow-x: auto; padding: 6px 8px 2px; scrollbar-width: none; }
.keys::-webkit-scrollbar { display: none; }
.keys button { flex: none; min-width: 42px; height: 36px; padding: 0 10px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); font: 600 13.5px "CR Mono", ui-monospace, monospace; color: var(--text); }
.keys button:active { background: var(--accent); border-color: var(--accent); }
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 6px 8px 8px; }
.composer textarea { resize: none; max-height: 132px; min-height: 44px; border-radius: 22px; padding: 11px 16px; }
.send { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; }
.send:active { background: var(--accent-press); transform: scale(.95); }

/* ---------------------------------------------------------------- sheets */
.backdrop { position: fixed; inset: 0; background: #000a; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20; }
.backdrop.show { opacity: 1; pointer-events: auto; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: 88dvh; display: flex; flex-direction: column;
  background: var(--surface); border-radius: 18px 18px 0 0; border: 1px solid var(--border); border-bottom: 0;
  transform: translateY(105%); transition: transform .24s cubic-bezier(.2,.8,.2,1); padding-bottom: var(--safe-bottom);
  max-width: 640px; margin: 0 auto; }
.sheet.open { transform: none; }
.sheet.small { max-height: 60dvh; }
.grip { width: 100%; height: 22px; flex: none; display: grid; place-items: center; }
.grip::after { content: ""; width: 38px; height: 4px; border-radius: 2px; background: var(--border); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 0 16px 8px; flex: none; }
.sheet-head h2 { margin: 0; font-size: 18px; }
.sheet-body { overflow-y: auto; padding: 4px 14px 18px; }
.confirm-title { margin: 4px 2px 8px; font-size: 18px; }
.confirm-text { color: var(--muted); margin: 0 2px 10px; white-space: pre-line; }
.confirm-warn { color: var(--warn); background: #2b2110; border-radius: 10px; padding: 10px 12px; font-size: 13.5px; margin: 0 0 10px; }
.confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }

.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; background: var(--bg2); border-radius: 12px; padding: 4px; }
.seg button { border: 0; background: none; padding: 9px 2px; border-radius: 9px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--surface2); color: var(--text); box-shadow: 0 1px 0 #0006; }
.dir-current { background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
  font: 13.5px "CR Mono", ui-monospace, monospace; word-break: break-all; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.chip { border: 1px solid var(--border); background: var(--surface2); border-radius: 999px; padding: 6px 11px; font-size: 12.5px;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.on { border-color: var(--accent); color: var(--accent); }
.dir-browser { border: 1px solid var(--border); border-radius: 10px; max-height: 32dvh; overflow-y: auto; }
.dir-row { display: flex; gap: 10px; align-items: center; width: 100%; padding: 10px 12px; border: 0; border-bottom: 1px solid var(--border);
  background: none; text-align: left; font-size: 14px; }
.dir-row:last-child { border-bottom: 0; }
.dir-row:active { background: var(--surface2); }
.dir-row .ico { color: var(--muted); width: 18px; text-align: center; }

.menu-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.menu-grid .btn { padding: 12px 4px; font: 600 13px "CR Mono", ui-monospace, monospace; }
.menu-list .row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 13px 6px; border: 0; border-bottom: 1px solid var(--border);
  background: none; text-align: left; font-size: 15px; }
.menu-list .row:last-child { border-bottom: 0; }
.menu-list .row .ico { width: 24px; text-align: center; }
.menu-list .row.danger { color: #ff8a80; }
.menu-list .row .right { margin-left: auto; display: flex; gap: 6px; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 6px 2px 8px; }

/* ---------------------------------------------------------------- copy view */
.copy-view { position: fixed; inset: 0; z-index: 30; background: var(--bg); display: flex; flex-direction: column; padding-top: var(--safe-top); }
.copy-text { flex: 1; margin: 0; overflow: auto; padding: 12px 12px calc(20px + var(--safe-bottom)); font: 12.5px/1.45 "CR Mono", ui-monospace, monospace;
  white-space: pre-wrap; word-break: break-word; user-select: text; -webkit-user-select: text; }

/* ---------------------------------------------------------------- toast & misc */
.toast { position: fixed; left: 50%; bottom: calc(150px + var(--safe-bottom)); transform: translate(-50%, 20px); z-index: 40;
  background: #2a2f3a; color: var(--text); border-radius: 12px; padding: 10px 14px; display: flex; gap: 12px; align-items: center;
  box-shadow: 0 8px 24px #000a; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); font-size: 14px; }
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast.ok { border-left: 3px solid var(--ok); } .toast.warn { border-left: 3px solid var(--warn); } .toast.err { border-left: 3px solid var(--danger); }
.toast-action { background: none; border: 0; color: var(--accent); font-weight: 700; padding: 0; white-space: nowrap; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (orientation: landscape) and (max-height: 500px) {
  :root { --appbar: 44px; }
  .tabs { display: none; }
  .composer textarea { min-height: 38px; padding: 8px 14px; }
  .send { width: 38px; height: 38px; }
}
