/* Terminal page: bar on top, session tabs, 1/2/4 windows, extra keys at the bottom (touch screens). */

html, body.term-page { height: 100%; overflow: hidden; }
body.term-page {
  display: flex; flex-direction: column;
  /* Follows the visible area when the phone keyboard opens (set by terminal.js). */
  height: var(--vvh, 100dvh);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

.term-bar {
  display: flex; align-items: center; gap: 8px;
  height: var(--nav-h); padding: 0 10px; flex-shrink: 0;
}
.term-title { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 17px; min-width: 0; }
.term-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.term-traffic { font-weight: 400; font-size: 12px; color: var(--subtle); font-variant-numeric: tabular-nums; white-space: nowrap; }
.term-tools { display: flex; gap: 4px; margin-left: auto; }
.term-tools .glass:hover { background: rgba(60, 60, 66, .6); }

.term-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--subtle); transition: background .3s; }
.term-dot[data-state="open"] { background: var(--ok); }
.term-dot[data-state="connecting"] { background: #ffd60a; animation: term-pulse 1s ease-in-out infinite alternate; }
.term-dot[data-state="closed"] { background: var(--danger); }
@keyframes term-pulse { to { opacity: .3; } }

.term-tabs {
  display: flex; gap: 4px; padding: 0 10px 6px; flex-shrink: 0;
  overflow-x: auto; scrollbar-width: none;
}
.term-tabs::-webkit-scrollbar { display: none; }
.term-tab {
  display: flex; align-items: center; flex-shrink: 0; max-width: 200px;
  border-radius: 9px; background: var(--fill); color: var(--muted);
  border: .5px solid transparent;
}
.term-tab.shown { color: var(--text); }
.term-tab.current { background: var(--fill-2); border-color: var(--hairline); }
.term-tab.dead .term-tab-name { text-decoration: line-through; color: var(--subtle); }
.term-tab button { border: 0; background: none; color: inherit; font: 500 13px var(--font); touch-action: manipulation; }
.term-tab-name { padding: 6px 4px 6px 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; -webkit-user-select: none; user-select: none; }
.term-tab-close { padding: 6px 9px 6px 4px; color: var(--subtle) !important; font-size: 15px !important; }
.term-tab-close:hover { color: var(--danger) !important; }
.term-new {
  flex-shrink: 0; width: 32px; border: 0; border-radius: 9px;
  background: var(--fill); color: var(--text); font: 400 18px var(--font);
}
.term-new:disabled { opacity: .35; }

.term-wrap {
  flex: 1; min-height: 0; padding: 0 6px 6px 10px;
  display: grid; gap: 6px; grid-template: 1fr / 1fr;
}
.term-wrap[data-layout="2"] { grid-template: 1fr / 1fr 1fr; }
.term-wrap[data-layout="4"] { grid-template: 1fr 1fr / 1fr 1fr; }
/* Tall screens split top/bottom rather than into two narrow columns. */
@media (max-aspect-ratio: 1/1) { .term-wrap[data-layout="2"] { grid-template: 1fr 1fr / 1fr; } }
.term-pane { position: relative; min-width: 0; min-height: 0; border-radius: 8px; }
.term-wrap:not([data-layout="1"]) .term-pane { padding: 4px; outline: 1px solid var(--hairline); }
.term-wrap:not([data-layout="1"]) .term-pane.active { outline: 1px solid var(--accent); }
.term { width: 100%; height: 100%; }
.term .xterm { height: 100%; }
.term .xterm-viewport { background: transparent !important; }
.term .xterm-viewport::-webkit-scrollbar { width: 6px; }
.term .xterm-viewport::-webkit-scrollbar-thumb { background: var(--fill-2); border-radius: 3px; }

.term-overlay {
  position: absolute; inset: 0; z-index: 5;
  display: grid; place-items: center; padding: 20px;
  background: rgba(0, 0, 0, .55);
}
.term-msg {
  max-width: 340px; padding: 20px; border-radius: 18px;
  display: grid; gap: 14px; text-align: center; line-height: 1.45;
}
#term-overlay { position: fixed; z-index: 10; }
.term-msg-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.term-msg code { font-family: var(--mono); font-size: 13px; color: var(--text); }

.term-keys {
  display: none;
  gap: 6px; padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  overflow-x: auto; scrollbar-width: none; flex-shrink: 0;
  background: var(--fill);
  border-top: .5px solid var(--hairline);
}
.term-keys::-webkit-scrollbar { display: none; }
@media (pointer: coarse) { .term-keys { display: flex; } }
.term-keys button {
  flex: 1 0 auto; min-width: 42px; height: 38px; padding: 0 10px;
  border: 0; border-radius: 9px;
  background: var(--fill-2); color: var(--text);
  font: 500 15px var(--mono);
  touch-action: manipulation;
}
.term-keys button:active { background: rgba(118, 118, 128, .45); }
.term-keys button.on { background: var(--accent); color: #fff; }

@media (max-width: 420px) {
  .term-traffic { display: none; }
}
/* Phones get a single window (terminal.js), so no layout button. */
@media (max-width: 699px) { .term-wide { display: none; } }

/* Cheat sheet over the terminal: the same list as `cmds` in the shell. */
.cheat {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, .55);
}
.cheat[hidden] { display: none; }
.cheat-box {
  width: min(640px, 100%); height: min(720px, 100%);
  display: flex; flex-direction: column; gap: 10px; padding: 14px; border-radius: 18px;
}
.cheat-head { display: flex; gap: 8px; align-items: center; }
/* 16px: smaller makes iOS zoom the page on focus. */
.cheat-head input {
  flex: 1; min-width: 0; height: 38px; padding: 0 12px; border: 0; border-radius: 10px;
  background: var(--fill); color: var(--text); font: 400 16px var(--font); outline: none;
}
.cheat-list { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.cheat-list h3 {
  margin: 14px 6px 4px; font: 600 12px var(--font); color: var(--subtle);
  text-transform: uppercase; letter-spacing: .04em;
}
.cheat-list h3:first-child { margin-top: 2px; }
.cheat-row {
  display: grid; gap: 2px; width: 100%; padding: 8px 10px; border: 0; border-radius: 10px;
  background: none; color: var(--text); text-align: left; font: 400 14px var(--font);
}
button.cheat-row { cursor: pointer; touch-action: manipulation; }
button.cheat-row:hover, button.cheat-row:focus-visible { background: var(--fill); outline: none; }
.cheat-row code { font: 500 13px var(--mono); color: #ffd60a; overflow-wrap: anywhere; }
.cheat-row span { color: var(--subtle); line-height: 1.35; }
.cheat-hint, .cheat-empty { margin: 0; font-size: 12px; color: var(--subtle); text-align: center; }
.cheat-empty { padding: 24px 0; font-size: 14px; }
