/* Richi terminal page: full-height, dark, thumb-friendly key row on phones. */
:root { color-scheme: dark; --bg: #141311; --bar: #191714; --line: rgba(255, 255, 255, .08); --text: #f0ece6; --muted: #a69c90;
  --accent: #be9772; --accent-ink: #21180f; --ok: #91a18a; --warn: #c5a16c; --error: #d09084;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif; font-size: 14px; }
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); }
body { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.bar { display: flex; align-items: center; gap: 10px; flex: none; height: calc(52px + env(safe-area-inset-top)); padding: 0 12px; padding-top: env(safe-area-inset-top);
  background: var(--bar); border-bottom: 1px solid var(--line); }
.back { display: inline-grid; place-items: center; flex: none; width: 38px; height: 38px; border-radius: 10px; color: var(--text); text-decoration: none; font-size: 18px; }
.back:hover { background: rgba(255, 255, 255, .06); }
.title { font-weight: 650; font-size: 15px; }
.state { display: inline-flex; align-items: center; gap: 7px; margin-left: auto; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line);
  font-size: 12px; color: var(--muted); white-space: nowrap; --tone: var(--muted); }
.state[data-state="on"] { --tone: var(--ok); color: var(--text); }
.state[data-state="wait"] { --tone: var(--warn); }
.state[data-state="error"] { --tone: var(--error); }
.state .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--tone); box-shadow: 0 0 0 3px color-mix(in srgb, var(--tone) 18%, transparent); }
.btn { min-height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid transparent; font: inherit; font-weight: 600; cursor: pointer; }
.btn.primary { width: 100%; min-height: 46px; background: var(--accent); color: var(--accent-ink); font-size: 15px; }
.btn.primary:disabled { opacity: .5; cursor: wait; }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.screen { position: relative; flex: 1; min-height: 0; overflow: clip; }
/* clip, not hidden: xterm's input textarea follows the cursor and focusing it must never scroll the page. */
.term { position: absolute; inset: 0; padding: 6px 4px 4px 8px; overflow: clip; }
.term .xterm { height: 100%; }
.terminal-surface { height: 100%; width: 100%; }
.terminal-session-bar { display: flex; align-items: center; gap: 4px; padding: 4px 8px; flex: none; min-width: 0; }
#terminal-tabs { display: flex; gap: 4px; overflow-x: auto; min-width: 0; flex: 1; }
.terminal-tab { display: inline-flex; flex: none; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.terminal-tab button { min-height: 40px; min-width: 40px; border: 0; background: var(--bar); color: var(--text); font: inherit; cursor: pointer; }
.terminal-tab [aria-selected="true"] { color: var(--accent); background: #382b20; }
/* Text/links reader floats over the screen: opening it never resizes the terminal or tmux. */
.terminal-tools { position: absolute; z-index: 3; left: 0; right: 0; bottom: 0; max-height: 70%; overflow: auto; overscroll-behavior: contain;
  padding: 0 12px 12px; background: var(--bar); border-top: 1px solid var(--line); box-shadow: 0 -18px 40px -24px #000; }
.terminal-tools-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 4px; min-height: 48px; background: var(--bar); }
.terminal-tools-head strong { margin-right: auto; font-size: 13px; }
.terminal-tools-head .btn { min-width: 40px; padding: 0 10px; font-size: 18px; }
.terminal-tools-head .copy-status:not(:empty) { bottom: auto; top: 100%; } /* the overlay clips anything above its header */
.terminal-tools-part h2 { margin: 10px 0 4px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.terminal-tools-part .note { margin-top: 0; padding-top: 0; border-top: 0; }
.terminal-tools a { color: var(--accent); overflow-wrap: anywhere; }
#terminal-tools-toggle { flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; }
#terminal-tools-toggle[aria-expanded="true"] { color: var(--accent); background: #382b20; }
#terminal-tools-toggle .count { min-width: 18px; padding: 0 5px; border-radius: 9px; background: #382b20; color: var(--accent); font-size: 11px; line-height: 18px; text-align: center; }
.terminal-link { padding: 6px 0; word-break: break-word; }
.terminal-output-block { border-top: 1px solid var(--line); padding: 8px 0; }
.terminal-output-block > .text-copy { float: right; }
.terminal-output-block pre { white-space: pre-wrap; overflow-wrap: anywhere; user-select: text; margin: 4px 0; }
.terminal-output-block .rich-message-text { white-space: pre-wrap; overflow-wrap: anywhere; user-select: text; }
.message-code { position: relative; padding: 8px; margin: 8px 0; border: 1px solid var(--line); border-radius: 8px; }
.message-code > .text-copy { position: absolute; top: 4px; right: 4px; }
.message-code pre { padding-top: 32px; }
.text-copy { position: relative; display: inline-flex; align-items: center; justify-content: center; min-height: 36px; min-width: 36px; padding: 6px; border: 0; border-radius: 8px; color: var(--muted); background: transparent; cursor: pointer; vertical-align: middle; touch-action: manipulation; }
.text-copy:hover { background: var(--bar); color: var(--text); }
.text-copy svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.copy-status:not(:empty) { position: absolute; bottom: 100%; right: 0; padding: 5px 8px; border-radius: 6px; white-space: nowrap; background: #3b332a; color: var(--text); font-size: 12px; z-index: 5; }
.clipboard-buffer { position: fixed; left: 0; top: 0; width: 1px; height: 1px; opacity: 0; font-size: 16px; }
.gate { position: absolute; inset: 0; display: grid; place-items: safe center; overflow-y: auto; padding: 16px; background: radial-gradient(60% 50% at 50% 0%, rgba(196, 242, 122, .07), transparent 70%), var(--bg); }
.gate-card { width: min(100%, 400px); padding: 26px; border-radius: 20px; border: 1px solid rgba(255, 255, 255, .11); background: linear-gradient(180deg, #27231e, #201d19); }
.gate-icon { display: inline-grid; place-items: center; width: 48px; height: 48px; border-radius: 14px; background: rgba(196, 242, 122, .12);
  color: var(--accent); font-family: "JetBrains Mono", ui-monospace, monospace; font-weight: 700; }
.gate-card h1 { margin: 16px 0 6px; font-size: 22px; letter-spacing: -.02em; }
.muted { margin: 0 0 20px; color: var(--muted); line-height: 1.5; }
#terminal-context { overflow-wrap: anywhere; }
.message { min-height: 20px; margin: 12px 0 0; color: var(--warn); font-size: 13px; line-height: 1.5; }
.note { margin: 14px 0 0; padding-top: 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; line-height: 1.55; }
.note code { font-family: "JetBrains Mono", ui-monospace, monospace; color: var(--text); }
.keys { display: flex; gap: 6px; flex: none; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); overflow-x: auto; background: var(--bar); border-top: 1px solid var(--line); scrollbar-width: none; }
.keys button { flex: none; min-width: 44px; height: 40px; padding: 0 10px; border-radius: 9px; border: 1px solid var(--line); background: #27231e; color: var(--text);
  font: 600 14px "JetBrains Mono", ui-monospace, monospace; touch-action: manipulation; }
.keys button:active, .keys button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.terminal-toolbar { display: flex; gap: 6px; padding: 6px 8px; background: var(--bar); border-top: 1px solid var(--line); flex: none; }
.terminal-toolbar button, .terminal-nav-panel button { min-height: 44px; min-width: 44px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; background: #27231e; color: var(--text); font: inherit; touch-action: manipulation; }
.terminal-toolbar button[aria-pressed="true"], .terminal-nav-panel button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
#terminal-hide-controls { margin-left: auto; }
.terminal-nav-panel { display: grid; grid-template-columns: repeat(auto-fit, minmax(48px, 1fr)); gap: 6px; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); max-height: 42dvh; overflow: auto; }
#terminal-controls { flex: none; min-height: 0; max-height: 45dvh; overflow-y: auto; }
.terminal-text-panel { padding: 10px; display: grid; gap: 8px; }
.terminal-text-panel textarea, .terminal-text-panel input[type="password"] { width: 100%; border: 1px solid var(--line); border-radius: 9px; background: #201d19; color: var(--text); font: 14px ui-monospace, monospace; padding: 10px; resize: vertical; }
.terminal-text-panel > label { color: var(--muted); font-size: 12px; }
.terminal-input-options { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.terminal-input-options label { display: flex; align-items: center; gap: 6px; font-size: 12px; min-height: 36px; }
.terminal-input-options button { margin-left: auto; }
/* Rich dock: its header is the only title bar; state and disconnect live in the tab row. */
.embedded .bar { display: none; }
.embedded .terminal-session-bar { gap: 6px; border-bottom: 1px solid var(--line); }
.embedded .terminal-session-bar .state { margin-left: 0; flex: none; }
.embedded #disconnect { flex: none; padding: 0 12px; }
@media (max-width: 480px) {
  .state { flex: none; width: 28px; height: 28px; padding: 0; justify-content: center; }
  #state-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .terminal-text-panel textarea, .terminal-text-panel input[type="password"] { font-size: 16px; }
}
@media (max-width: 390px) { .terminal-toolbar { gap: 4px; }.terminal-toolbar button { padding: 8px 6px; font-size: 12px; } }
@media (max-width: 360px) {
  .terminal-toolbar { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #terminal-hide-controls { grid-column: 1 / -1; margin-left: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media (max-height: 500px) {
  #terminal-controls, .terminal-nav-panel { max-height: 26dvh; }
}
@media (max-height: 360px) {
  /* An embedded terminal on a landscape phone can be shorter than its two
     toolbars. Let the login gate scroll without clipping the passkey button. */
  body:has(#gate:not([hidden])) { overflow-y: auto; }
  .screen:has(#gate:not([hidden])) { min-height: 140px; flex: none; }
  .gate { padding: 8px; display: block; }
  .gate-card { margin: auto; padding: 12px; }
  .gate-icon, .gate-card h1, .gate-card .note { display: none; }
  .gate-card .muted { margin-bottom: 8px; font-size: 12px; }
  #message:empty { display: none; }
}

/* RichCLI shares the bronze palette; terminal I/O and connection behavior stay intact. */
.btn.primary { background: #6b4a32; color: #fff9f2; border-radius: 14px; }
.gate-card { border-radius: 26px; background: #201d19; }

/* Phone: one top row, stable scrolling tabs, one compact input strip. */
#terminal-tabs { position: relative; scrollbar-width: thin; }
.terminal-tab button[role="tab"]::before { content: "Сессия "; }
.terminal-tab[data-state="on"] button[role="tab"] { box-shadow: inset 0 -2px var(--ok); }
@media (max-width: 640px) {
  body { display: grid; grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: calc(44px + env(safe-area-inset-top)) minmax(0, 1fr) auto auto; }
  .bar { grid-row: 1; grid-column: 1; height: 100%; gap: 4px; padding: env(safe-area-inset-top) 4px 0; }
  .bar .title { display: none; }
  .bar .back { width: 30px; height: 36px; }
  .bar .state { width: 12px; min-width: 12px; height: 28px; padding: 0; border: 0; justify-content: center; }
  #state-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .bar #disconnect { min-width: 32px; min-height: 36px; padding: 0; font-size: 0; }
  .bar #disconnect::after { content: "⏻"; font-size: 18px; }
  .terminal-session-bar { grid-row: 1; grid-column: 2; min-width: 0; padding: calc(4px + env(safe-area-inset-top)) 4px 4px;
    border-bottom: 1px solid var(--line); overflow: hidden; }
  .embedded .terminal-session-bar { grid-column: 1 / -1; }
  .terminal-session-bar > .btn { min-width: 34px; min-height: 36px; padding: 0 8px; font-size: 12px; }
  #terminal-tools-toggle { padding: 0 8px; }
  #terminal-tabs { gap: 4px; }
  .terminal-tab button { min-height: 34px; min-width: 32px; font-size: 13px; }
  .terminal-tab button[role="tab"] { min-width: 38px; padding: 0 8px; }
  .terminal-tab button[role="tab"]::before { content: ""; }
  .screen { grid-column: 1 / -1; grid-row: 2; }
  .terminal-toolbar { grid-column: 1 / -1; grid-row: 3; display: flex; gap: 4px; padding: 4px 6px; }
  .terminal-toolbar button { min-height: 36px; min-width: 40px; padding: 6px 12px; font-size: 13px; }
  #terminal-hide-controls { grid-column: auto; margin-left: auto; }
  #terminal-controls { grid-column: 1 / -1; grid-row: 4; }
  .keys { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 4px; padding: 4px 6px calc(4px + env(safe-area-inset-bottom)); overflow: visible; }
  .keys button { min-width: 0; height: 38px; padding: 0; font-size: 12px; }
  .terminal-text-panel { padding: 6px; gap: 4px; }
  .terminal-text-panel textarea { resize: none; max-height: 20dvh; overflow-y: auto; }
}
