/* =========================================================
   MeuTerminal - design system
   Tokens ported from the tweakcn/shadcn theme supplied by the owner
   (purple primary, Inter + JetBrains Mono, hard offset shadows, 2rem radius)
   to plain CSS custom properties: this app has no Tailwind/React build.
   ========================================================= */

/* Fonts are self-hosted (public/assets/fonts) so the PWA works offline.
   JetBrains Mono = terminal, Inter = interface. Latin subset (covers pt-BR). */
@font-face {
    font-family: 'JetBrains Mono';
    src: url('/assets/fonts/JetBrainsMono-Regular.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: block; /* xterm measures the font once: avoid measuring a fallback */
}
@font-face {
    font-family: 'JetBrains Mono';
    src: url('/assets/fonts/JetBrainsMono-Bold.woff2') format('woff2');
    font-weight: 700;
    font-style: normal;
    font-display: block;
}
@font-face {
    font-family: 'JetBrains Mono';
    src: url('/assets/fonts/JetBrainsMono-Italic.woff2') format('woff2');
    font-weight: 400;
    font-style: italic;
    font-display: swap;
}
@font-face {
    font-family: 'Inter';
    src: url('/assets/fonts/Inter-Regular.woff2') format('woff2');
    font-weight: 400;
    font-display: swap;
}
@font-face {
    font-family: 'Inter';
    src: url('/assets/fonts/Inter-Medium.woff2') format('woff2');
    font-weight: 500;
    font-display: swap;
}
@font-face {
    font-family: 'Inter';
    src: url('/assets/fonts/Inter-SemiBold.woff2') format('woff2');
    font-weight: 600;
    font-display: swap;
}
@font-face {
    font-family: 'Inter';
    src: url('/assets/fonts/Inter-Bold.woff2') format('woff2');
    font-weight: 700;
    font-display: swap;
}

/* Nerd Font stays as fallback so Starship/powerline glyphs keep rendering */
@font-face {
    font-family: 'FiraCode Nerd Font';
    src: url('/assets/fonts/FiraCodeNerdFontMono-Regular.ttf') format('truetype');
    font-weight: 400;
    font-display: block;
}
@font-face {
    font-family: 'FiraCode Nerd Font';
    src: url('/assets/fonts/FiraCodeNerdFontMono-Bold.ttf') format('truetype');
    font-weight: 700;
    font-display: block;
}

/* ---------- tokens: dark (default) ---------- */
:root,
[data-theme="dark"] {
    color-scheme: dark;

    /* theme: .dark */
    --bg: #121212;              /* --background  oklch(0.1822 0 0) */
    --surface: #1F1F1F;         /* --card        oklch(0.2393 0 0) */
    --surface-2: #2A2A2A;       /* --muted       oklch(0.2850 0 0) */
    --surface-3: #333333;       /* hover / pressed */
    --border: #333333;          /* --border      oklch(0.3211 0 0) */
    --border-strong: #4A4A4A;
    --divider: #333333;         /* hairlines between items */
    --text: #F2F0E3;            /* --foreground  oklch(0.9559 0.0146 102) */
    --text-2: #A0A0A0;          /* --muted-foreground oklch(0.7058 0 0) */
    --text-3: #7A7A7A;
    --accent: #A855F7;          /* --primary     oklch(0.6268 0.2325 304) */
    --accent-hover: #9A3FEF;
    --accent-soft: rgba(168, 85, 247, 0.16);
    --accent-fg: #FFFFFF;
    --success: #5CEB91;         /* --chart-2     oklch(0.8836 0.2053 155) */
    --warning: #F5B83D;
    --danger: #F25C54;          /* --destructive (light value: readable on dark) */
    --danger-bg: #8F1D17;       /* --destructive oklch(0.3767 0.1546 29) */
    --popover: #1F1F1F;
    --input-bg: #1F1F1F;
    --key-bg: #2A2A2A;
    --key-bg-pressed: #3A3A3A;
    --backdrop: rgba(0, 0, 0, 0.6);

    /* hard offset shadows from the theme */
    --shadow-color: #000000;
    --shadow-sm: 4px 4px 0 0 var(--shadow-color);
    --shadow: 4px 4px 0 0 var(--shadow-color);
    --shadow-lg: 6px 6px 0 0 var(--shadow-color);

    /* session identity colors */
    --c-green: #5CEB91;
    --c-blue: #60A5FA;
    --c-purple: #C084FC;
    --c-orange: #FB923C;
    --c-pink: #F472B6;
    --c-cyan: #22D3EE;
    --c-yellow: #FACC15;

    /* terminal */
    --term-bg: #121212;
    --term-fg: #F2F0E3;
    --term-cursor: #F2F0E3;
    --term-selection: rgba(168, 85, 247, 0.35);
    --search-match: #6B3FA0;
    --search-active: #A855F7;
}

/* ---------- tokens: light ---------- */
[data-theme="light"] {
    color-scheme: light;
    --bg: #F2F0E3;              /* --background oklch(0.9559 0.0146 102) */
    --surface: #F2F0E3;         /* --card */
    --surface-2: #E8E6D8;       /* --muted      oklch(0.9255 0.016 103) */
    --surface-3: #DDDBCB;
    --border: #000000;          /* --border     oklch(0 0 0) */
    --border-strong: #000000;
    --divider: rgba(0, 0, 0, 0.16);
    --text: #000000;
    --text-2: #4D4D4D;
    --text-3: #666666;          /* --muted-foreground oklch(0.5103 0 0) */
    --accent: #9333EA;          /* slightly deeper than #A855F7 for text contrast on cream */
    --accent-hover: #7E22CE;
    --accent-soft: rgba(147, 51, 234, 0.14);
    --accent-fg: #FFFFFF;
    --success: #15803D;
    --warning: #A16207;
    --danger: #C9302C;
    --danger-bg: #F25C54;
    --popover: #FFFFFF;         /* --popover */
    --input-bg: #FFFFFF;        /* --input */
    --key-bg: #FFFFFF;
    --key-bg-pressed: #E8E6D8;
    --backdrop: rgba(0, 0, 0, 0.35);
    --shadow-color: #000000;

    --c-green: #15803D;
    --c-blue: #1D4ED8;
    --c-purple: #9333EA;
    --c-orange: #C2410C;
    --c-pink: #BE185D;
    --c-cyan: #0E7490;
    --c-yellow: #A16207;

    --term-bg: #F7F5EA;
    --term-fg: #111111;
    --term-cursor: #111111;
    --term-selection: rgba(147, 51, 234, 0.22);
    --search-match: #E9D5FF;
    --search-active: #C084FC;
}

:root {
    --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', 'FiraCode Nerd Font', ui-monospace, Menlo, Consolas, monospace;
    --radius: 2rem;                         /* theme --radius */
    --radius-sm: 0.5rem;                    /* small controls inside dense bars */
    --radius-md: 0.75rem;
    --radius-lg: var(--radius);
    --tracking: -0.01em;
    --ease: cubic-bezier(0.2, 0, 0, 1);
    --dur: 140ms;

    /* layout */
    --topbar-h: 52px;
    --status-h: 30px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 14px;
    letter-spacing: var(--tracking);
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
    overscroll-behavior: none;      /* no pull-to-refresh / rubber band */
}
body { overflow: hidden; }

button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; background: none; border: none; -webkit-tap-highlight-color: transparent; }
.mono { font-family: var(--font-mono); letter-spacing: 0; }
.icon { flex-shrink: 0; display: block; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.xterm-helper-textarea:focus-visible { outline: none; }

/* =========================================================
   App shell: fills the *visible* viewport (see ui/viewport.js)
   ========================================================= */
.app {
    position: fixed;
    left: 0;
    right: 0;
    top: var(--vvtop, 0px);
    height: var(--vvh, 100dvh);
    display: flex;
    flex-direction: column;
    padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
    background: var(--bg);
}
/* Keyboard covers the home indicator: no bottom inset while it is open */
[data-keyboard] .app { padding-bottom: 0; }

/* ---------- top bar ---------- */
.topbar {
    flex-shrink: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "tabs actions";
    align-items: stretch;
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.brand { grid-area: brand; display: none; align-items: center; gap: 10px; padding: 0 14px; min-width: 0; }
.brand-icon {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: var(--accent-fg);
    border: 1.5px solid var(--shadow-color);
    box-shadow: 2px 2px 0 0 var(--shadow-color);
    flex-shrink: 0;
}
.brand-title { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-conn { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex-shrink: 0; }
.brand-conn[data-state="connected"] { background: var(--success); }
.brand-conn[data-state="connecting"],
.brand-conn[data-state="reconnecting"] { background: var(--warning); animation: pulse 1.2s ease-in-out infinite; }
.brand-conn[data-state="error"] { background: var(--danger); }

.tabstrip { grid-area: tabs; display: flex; align-items: stretch; min-width: 0; }
.new-tab {
    align-self: center;
    margin: 0 8px 0 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.topbar-actions { grid-area: actions; display: flex; align-items: center; gap: 2px; padding: 0 8px; }
.topbar-divider { width: 1px; height: 22px; background: var(--divider); margin: 0 8px 0 4px; }

/* ---------- icon buttons ---------- */
.icon-btn {
    width: 36px;
    height: 36px;
    display: inline-grid;
    place-items: center;
    border-radius: var(--radius-sm);
    color: var(--text-2);
    transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { transform: scale(0.94); background: var(--surface-3); }
.icon-btn[aria-pressed="true"] { color: var(--accent); }
.icon-btn:disabled { opacity: 0.4; pointer-events: none; }

/* ---------- tabs ---------- */
.tab-list {
    display: flex;
    align-items: stretch;
    gap: 2px;
    min-width: 0;
    flex: 1;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    padding-top: 6px;
}
.tab-list::-webkit-scrollbar { display: none; }

.tab {
    --c: var(--c-green);
    position: relative;
    flex: 0 1 230px;
    min-width: 150px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 6px 0 14px;
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    color: var(--text-2);
    cursor: default;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active {
    background: var(--bg);
    border-color: var(--border);
    color: var(--text);
}
/* active tab melts into the terminal; accent underline marks it */
.tab.active::after {
    content: '';
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: 0;
    height: 2px;
    border-radius: 2px 2px 0 0;
    background: var(--accent);
}
.tab.active::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1px;
    height: 1px;
    background: var(--bg);
}
.tab:focus-visible { outline-offset: -2px; }

.tab[data-color="green"] { --c: var(--c-green); }
.tab[data-color="blue"] { --c: var(--c-blue); }
.tab[data-color="purple"] { --c: var(--c-purple); }
.tab[data-color="orange"] { --c: var(--c-orange); }
.tab[data-color="pink"] { --c: var(--c-pink); }
.tab[data-color="cyan"] { --c: var(--c-cyan); }
.tab[data-color="yellow"] { --c: var(--c-yellow); }

.tab-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--c);
    flex-shrink: 0;
    transition: box-shadow var(--dur) var(--ease);
}
/* connection state on the identity dot */
.tab[data-state="connecting"] .tab-dot,
.tab[data-state="reconnecting"] .tab-dot { animation: pulse 1.2s ease-in-out infinite; }
.tab[data-state="disconnected"] .tab-dot,
.tab[data-state="exited"] .tab-dot { background: transparent; box-shadow: inset 0 0 0 2px var(--c); opacity: 0.7; }
.tab[data-state="error"] .tab-dot { background: var(--danger); }
/* background tab produced output */
.tab.activity .tab-dot { box-shadow: 0 0 0 3px var(--accent-soft), 0 0 0 1.5px var(--accent); }

.tab-text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.25; }
.tab-name { font-size: 13.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tab-sub { font-size: 11.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tab.active .tab-sub { color: var(--text-2); }
.tab-sub:empty { display: none; }

.tab-close {
    width: 26px;
    height: 26px;
    display: grid;
    place-items: center;
    border-radius: var(--radius-sm);
    color: var(--text-3);
    flex-shrink: 0;
}
.tab-close:hover { background: var(--surface-3); color: var(--text); }
.tab-pin { display: none; color: var(--text-3); padding-right: 6px; }

.tab.pinned { flex: 0 0 auto; min-width: 0; max-width: 170px; padding-right: 10px; }
.tab.pinned .tab-close { display: none; }
.tab.pinned .tab-pin { display: block; order: -1; padding: 0; margin-left: -4px; }
.tab.pinned .tab-sub { display: none; }

.tab.dragging { opacity: 0.5; }

.tab-rename {
    min-width: 0;
    width: 100%;
    height: 26px;
    padding: 0 6px;
    border: 1px solid var(--accent);
    border-radius: 6px;
    background: var(--input-bg);
    font-size: 13px;
    outline: none;
}

/* =========================================================
   Workspace / terminal
   ========================================================= */
.demo-banner {
    flex-shrink: 0;
    padding: 4px 12px;
    text-align: center;
    font-size: 12px;
    font-weight: 500;
    background: var(--accent-soft);
    color: var(--text);
    border-bottom: 1px solid var(--border);
}

.workspace {
    position: relative;
    flex: 1;
    min-height: 0;          /* lets the terminal shrink instead of overflowing */
    background: var(--term-bg);
    overflow: hidden;
}
.terminal-panels { position: absolute; inset: 0; }
.terminal-panel {
    position: absolute;
    inset: 0;
    padding: 10px 2px 2px 16px;
    visibility: hidden;     /* keeps size so inactive terminals don't refit to 0 */
    background: var(--term-bg);
    touch-action: none;     /* vertical drags are handled by ui/touchScroll.js */
}
.terminal-panel.active { visibility: visible; }
.terminal-panel .xterm { height: 100%; }
.terminal-panel .xterm-viewport { background: var(--term-bg) !important; scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
.terminal-panel .xterm-viewport::-webkit-scrollbar { width: 10px; }
.terminal-panel .xterm-viewport::-webkit-scrollbar-track { background: transparent; }
.terminal-panel .xterm-viewport::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 10px;
    border: 3px solid var(--term-bg);
}

/* ---------- search ---------- */
.search-bar {
    position: absolute;
    top: 10px;
    right: 18px;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 2px;
    width: min(440px, calc(100% - 28px));
    height: 42px;
    padding: 0 4px 0 14px;
    background: var(--popover);
    border: 1.5px solid var(--shadow-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    color: var(--text-2);
}
.search-bar input {
    flex: 1;
    min-width: 0;
    height: 100%;
    padding: 0 8px;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 13.5px;
}
.search-bar input::-webkit-search-cancel-button { display: none; }
.search-count { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; padding: 0 6px; }
.search-bar .icon-btn { width: 32px; height: 32px; border-radius: 50%; }

/* ---------- new session page ---------- */
/* Fixed to the real viewport (not just .workspace): must sit above the topbar/tab strip too,
   with no tabs visible behind it, same as a full-screen page. */
.new-session {
    position: fixed;
    inset: 0;
    z-index: 20;
    overflow-y: auto;
    background: var(--bg);
    padding: calc(clamp(24px, 8vh, 88px) + var(--safe-top)) calc(20px + var(--safe-right)) calc(32px + var(--safe-bottom)) calc(20px + var(--safe-left));
    animation: fade-in var(--dur) var(--ease);
}
.new-session-inner { width: 100%; max-width: 480px; margin: 0 auto; }
.ns-close { position: fixed; top: calc(16px + var(--safe-top)); right: calc(16px + var(--safe-right)); z-index: 21; }
.ns-settings { position: fixed; top: calc(16px + var(--safe-top)); right: calc(16px + 44px + var(--safe-right)); z-index: 21; }
.new-session-mark {
    width: 48px;
    height: 48px;
    margin: 0 auto 14px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    background: var(--accent);
    color: var(--accent-fg);
    border: 2px solid var(--shadow-color);
    box-shadow: var(--shadow-sm);
}
.new-session-title { text-align: center; font-size: 22px; font-weight: 600; margin-bottom: 24px; letter-spacing: -0.02em; }
.new-session-form { display: flex; flex-direction: column; gap: 16px; }
.new-session-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

/* App grid: the home screen shown while no tab is open, like a phone's springboard */
.app-grid-title { text-align: center; font-size: 15px; font-weight: 600; color: var(--text-3); margin: 0 0 20px; letter-spacing: -0.01em; }
.app-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; width: 100%; max-width: 400px; margin: 0 auto; }
.app-tile {
    display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 16px 6px 12px;
    border-radius: 20px; background: var(--surface); border: 1.5px solid var(--border);
    transition: transform var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.app-tile[hidden] { display: none; }
.app-tile:hover { border-color: var(--border-strong); transform: translateY(-2px); }
.app-tile:active { transform: translateY(0) scale(0.96); }
.app-tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.app-tile-icon {
    width: 56px; height: 56px; display: grid; place-items: center; border-radius: 18px;
    background: color-mix(in srgb, var(--tc) 18%, var(--surface));
    border: 1.5px solid color-mix(in srgb, var(--tc) 42%, transparent);
    color: var(--tc);
}
.app-tile-label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.app-tile[data-color="green"] { --tc: var(--c-green); }
.app-tile[data-color="blue"] { --tc: var(--c-blue); }
.app-tile[data-color="orange"] { --tc: var(--c-orange); }
.app-tile[data-color="yellow"] { --tc: var(--c-yellow); }
.app-tile[data-color="purple"] { --tc: var(--c-purple); }
.app-tile[data-color="cyan"] { --tc: var(--c-cyan); }

.ns-back {
    display: inline-flex; align-items: center; gap: 6px; margin-bottom: 16px; padding: 4px 2px;
    font-size: 13px; font-weight: 600; color: var(--text-3);
}
.ns-back:hover { color: var(--text-2); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12.5px; font-weight: 500; color: var(--text-2); }
.field-help { font-size: 12px; color: var(--text-3); }
.field input, .login-card input:not(.pin-input) {
    height: 44px;
    padding: 0 16px;
    background: var(--input-bg);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    outline: none;
    transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.field input::placeholder, .login-card input::placeholder { color: var(--text-3); }
.field input:focus, .login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.recent { margin-top: 36px; }
.section-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-3);
    margin: 0 0 8px 4px;
}
.recent-list { list-style: none; display: flex; flex-direction: column; gap: 2px; }
.recent-item { display: flex; align-items: center; gap: 4px; }
.recent-open {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    text-align: left;
    transition: background-color var(--dur) var(--ease);
}
.recent-open:hover { background: var(--surface-2); }
.recent-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }
.recent-text { display: flex; flex-direction: column; min-width: 0; gap: 2px; }
.recent-name { font-size: 13.5px; font-weight: 500; }
.recent-meta { display: flex; gap: 10px; font-size: 12px; color: var(--text-3); min-width: 0; }
.recent-cwd { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-time { white-space: nowrap; }
.recent-forget { width: 32px; height: 32px; border-radius: 50%; }

/* ---------- buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 42px;
    padding: 0 20px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    border: 1.5px solid var(--shadow-color);
    transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.btn-primary { background: var(--accent); color: var(--accent-fg); box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: translate(4px, 4px); box-shadow: 0 0 0 0 var(--shadow-color); }
.btn-primary:disabled { opacity: 0.6; cursor: progress; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }

/* =========================================================
   Status bar
   ========================================================= */
.statusbar {
    flex-shrink: 0;
    height: var(--status-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 10px 0 14px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-2);
    overflow: hidden;
    white-space: nowrap;
}
.status-group { display: flex; align-items: center; min-width: 0; }
.status-left { flex: 1; }
.status-item { display: inline-flex; align-items: center; gap: 6px; min-width: 0; padding: 0 12px; }
.status-item span { overflow: hidden; text-overflow: ellipsis; }
.status-left .status-item:first-child { padding-left: 0; }
.status-left .status-item + .status-item { border-left: 1px solid var(--divider); }
.status-cwd { flex-shrink: 1; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex-shrink: 0; }
.status-conn[data-state="connected"] { color: var(--success); }
.status-conn[data-state="connected"] .status-dot { background: var(--success); }
.status-conn[data-state="connecting"] .status-dot,
.status-conn[data-state="reconnecting"] .status-dot { background: var(--warning); animation: pulse 1.2s ease-in-out infinite; }
.status-conn[data-state="error"] { color: var(--danger); }
.status-conn[data-state="error"] .status-dot { background: var(--danger); }
.status-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 22px;
    padding: 0 10px;
    margin: 0 6px;
    border-radius: var(--radius);
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
}
.status-size { color: var(--text-3); font-size: 11.5px; }
.status-clock time { font-variant-numeric: tabular-nums; }
.status-sessions { display: none; }

/* =========================================================
   Mobile shortcut bar (sits right above the native keyboard)
   ========================================================= */
.shortcut-bar {
    flex-shrink: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 7px 0;
}
.shortcut-scroll {
    display: flex;
    gap: 7px;
    padding: 0 max(10px, var(--safe-left)) 0 max(10px, var(--safe-left));
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}
.shortcut-scroll::-webkit-scrollbar { display: none; }
.shortcut-key {
    flex: 0 0 auto;
    min-width: 46px;
    height: 42px;
    padding: 0 10px;
    border-radius: var(--radius-md);
    background: var(--key-bg);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 15px;
    font-weight: 500;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    transition: background-color 80ms linear, transform 80ms linear;
}
.shortcut-key.wide { padding: 0 14px; font-size: 13.5px; font-weight: 600; }
.shortcut-key.pressed { background: var(--key-bg-pressed); transform: scale(0.95); }
.shortcut-key.active {
    background: var(--accent);
    color: var(--accent-fg);
    border-color: var(--shadow-color);
    box-shadow: 2px 2px 0 0 var(--shadow-color);
}
.shortcut-key.icon-key { display: grid; place-items: center; color: var(--text-2); }
.shortcut-key.icon-key.recording {
    background: var(--danger);
    color: #fff;
    border-color: var(--shadow-color);
    animation: pulse 1.2s ease-in-out infinite;
}
.dictation-preview {
    margin: 0 10px 7px;
    padding: 8px 14px;
    border-radius: var(--radius);
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text);
    overflow-wrap: anywhere;
    line-height: 1.4;
}
.shortcut-key.extra { display: none; }
.shortcut-bar.expanded .shortcut-key.extra { display: block; }
.shortcut-key[data-key="more"][aria-expanded="true"] { background: var(--surface-3); }

/* =========================================================
   Menus, toasts, dialogs (floating layers: hard shadow + border)
   ========================================================= */
.menu {
    position: fixed;
    z-index: 100;
    min-width: 230px;
    max-width: min(320px, calc(100vw - 16px));
    max-height: calc(var(--vvh, 100dvh) - 16px);
    overflow-y: auto;
    padding: 6px;
    background: var(--popover);
    border: 1.5px solid var(--shadow-color);
    border-radius: 1.25rem;
    box-shadow: var(--shadow);
    animation: pop-in 120ms var(--ease);
}
.menu-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    height: 36px;
    padding: 0 12px;
    border-radius: 0.8rem;
    font-size: 13.5px;
    text-align: left;
    color: var(--text);
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); outline: none; }
.menu-item:disabled { color: var(--text-3); cursor: default; }
.menu-item.danger { color: var(--danger); }
.menu-item[aria-checked="true"] .menu-label { color: var(--accent); font-weight: 600; }
.menu-icon { width: 16px; display: grid; place-items: center; color: var(--text-2); }
.menu-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-hint {
    font-family: var(--font-sans);
    font-size: 11.5px;
    color: var(--text-3);
    max-width: 45%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.menu-separator { height: 1px; margin: 6px 8px; background: var(--divider); }

.toast-region {
    position: fixed;
    z-index: 90;
    left: 50%;
    bottom: calc(var(--safe-bottom) + var(--status-h) + 16px);
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: max-content;
    max-width: calc(100vw - 24px);
    pointer-events: none;
}
.toast {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 10px 10px 18px;
    min-height: 44px;
    background: var(--popover);
    border: 1.5px solid var(--shadow-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    font-size: 13.5px;
    pointer-events: auto;
    animation: toast-in 160ms var(--ease);
}
.toast-error { border-color: var(--danger); }
.toast-error::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); flex-shrink: 0; }
.toast.leaving { opacity: 0; transition: opacity 150ms linear; }
.toast-action {
    height: 30px;
    padding: 0 14px;
    border-radius: var(--radius);
    background: var(--accent);
    color: var(--accent-fg);
    font-weight: 600;
    font-size: 13px;
}

.dialog {
    margin: auto;
    width: min(560px, calc(100vw - 32px));
    max-height: min(84dvh, 760px);
    padding: 0;
    background: var(--surface);
    color: var(--text);
    border: 1.5px solid var(--shadow-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    flex-direction: column;
}
.dialog[open] { display: flex; animation: pop-in 160ms var(--ease); }
.dialog::backdrop { background: var(--backdrop); }
.dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 14px 12px 24px;
    border-bottom: 1px solid var(--border);
}
.dialog-title { font-size: 16px; font-weight: 600; }
.dialog-body { padding: 4px 24px 24px; overflow-y: auto; }
.dialog-note { margin-top: 16px; font-size: 12.5px; color: var(--text-3); line-height: 1.5; }

.settings-section { margin-top: 18px; }
.setting {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 52px;
    padding: 8px 0;
    border-bottom: 1px solid var(--divider);
}
.settings-section .setting:last-child { border-bottom: none; }
.setting-stack { flex-direction: column; align-items: stretch; gap: 8px; }
.setting-text { font-size: 13.5px; display: flex; flex-direction: column; gap: 2px; }
.setting-help { font-size: 12px; color: var(--text-3); line-height: 1.4; }
.setting-control { display: flex; align-items: center; gap: 10px; }
.setting-value { min-width: 44px; text-align: right; font-size: 12.5px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.setting-readonly { font-size: 13px; color: var(--text-2); }
.setting select, .setting input[type="text"] {
    height: 36px;
    padding: 0 14px;
    background: var(--input-bg);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    outline: none;
}
.setting select:focus, .setting input[type="text"]:focus { border-color: var(--accent); }
.setting input[type="range"] { width: 140px; accent-color: var(--accent); }

.switch {
    appearance: none;
    -webkit-appearance: none;
    flex-shrink: 0;
    width: 42px;
    height: 24px;
    border-radius: 999px;
    background: var(--surface-3);
    border: 1.5px solid var(--border-strong);
    position: relative;
    cursor: pointer;
    transition: background-color var(--dur) var(--ease);
}
.switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 17px;
    height: 17px;
    border-radius: 50%;
    background: var(--text);
    transition: transform var(--dur) var(--ease);
}
.switch:checked { background: var(--accent); border-color: var(--shadow-color); }
.switch:checked::after { transform: translateX(18px); background: #fff; }

.shortcut-list { display: grid; grid-template-columns: 1fr auto; gap: 10px 20px; margin-top: 16px; align-items: center; }
.shortcut-list dt { font-size: 13.5px; }
.shortcut-list dd { font-size: 12px; color: var(--text-3); text-align: right; }
kbd {
    display: inline-block;
    min-width: 22px;
    padding: 2px 7px;
    margin: 0 2px;
    border: 1px solid var(--border-strong);
    border-bottom-width: 2px;
    border-radius: 6px;
    background: var(--surface-2);
    font-family: var(--font-sans);
    font-size: 11.5px;
    color: var(--text);
    text-align: center;
}

/* =========================================================
   Focus mode / fullscreen: the terminal takes everything
   ========================================================= */
[data-expanded] .statusbar,
[data-expanded] .demo-banner { display: none; }
[data-expanded] .tab-sub { display: none; }
[data-expanded] { --topbar-h: 40px; }
[data-expanded] .tab-list { padding-top: 4px; }

/* =========================================================
   Responsive
   ========================================================= */

/* Phones & narrow windows: brand row + scrolling tab row */
@media (max-width: 719px) {
    :root { --status-h: 38px; }
    .topbar {
        height: auto;
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-rows: 50px 52px;
        grid-template-areas: "brand actions" "tabs tabs";
    }
    .brand { display: flex; }
    .topbar-divider { display: none; }
    .topbar-actions { padding-right: 6px; }
    .tabstrip { border-top: 1px solid var(--border); }
    .new-tab { margin: 0 6px 0 8px; }
    .tab-list { padding-top: 5px; }
    .tab { flex: 0 0 auto; min-width: 150px; max-width: 220px; }

    .statusbar { font-size: 13px; padding-right: 4px; }
    .status-item { padding: 0 10px; }
    .status-right .status-item,
    .status-branch,
    .status-shell { display: none !important; }
    .status-sessions { display: inline-grid; }
    .terminal-panel { padding: 8px 0 0 10px; }

    .new-session-actions .btn { flex: 1; }
    .app-grid { max-width: 320px; gap: 10px; }
    .app-tile-icon { width: 50px; height: 50px; }

    /* dialogs become bottom sheets */
    .dialog {
        width: 100%;
        max-width: none;
        max-height: 88dvh;
        margin: auto 0 0;
        border-radius: var(--radius) var(--radius) 0 0;
        border-bottom: none;
        box-shadow: none;
        padding-bottom: var(--safe-bottom);
    }
    .setting input[type="range"] { width: 110px; }
}

/* Focus mode on phones collapses the brand row */
@media (max-width: 719px) {
    [data-expanded] .topbar { grid-template-rows: 46px; grid-template-areas: "tabs actions"; }
    [data-expanded] .brand { display: none; }
    [data-expanded] .tabstrip { border-top: none; }
}

/* Touch devices: 44px targets */
@media (pointer: coarse) {
    .icon-btn { width: 44px; height: 44px; }
    .new-tab { width: 40px; height: 40px; }
    .tab-close { width: 32px; height: 32px; }
    .menu-item { height: 46px; font-size: 14.5px; }
    .search-bar .icon-btn { width: 38px; height: 38px; }
}

/* Keyboard open on a phone: give the height to the terminal */
@media (max-width: 719px) {
    [data-keyboard] .topbar { grid-template-rows: 44px 46px; }
    [data-keyboard] .tab-sub { display: none; }
    [data-keyboard] { --status-h: 34px; }
}

/* Landscape phones: every pixel of height counts - one compact row */
@media (pointer: coarse) and (max-height: 500px) and (orientation: landscape) {
    :root { --topbar-h: 44px; --status-h: 28px; }
    .topbar { height: var(--topbar-h); grid-template-rows: none; grid-template-areas: "tabs actions"; }
    .brand { display: none !important; }
    .tabstrip { border-top: none; }
    .tab-sub { display: none; }
    .tab { min-width: 120px; }
    [data-keyboard] .statusbar { display: none; }
}

/* =========================================================
   Motion
   ========================================================= */
@keyframes pulse { 50% { opacity: 0.35; } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: scale(0.97); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
[data-reduced-motion] *, [data-reduced-motion] *::before, [data-reduced-motion] *::after {
    animation: none !important;
    transition: none !important;
}

/* =========================================================
   Login page
   ========================================================= */
.page-login .login {
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
}
body.page-login { overflow: auto; }
.login-card {
    width: min(400px, 100%);
    padding: 36px 28px 30px;
    background: var(--surface);
    border: 1.5px solid var(--shadow-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    text-align: center;
}
.login-card .brand-icon { width: 52px; height: 52px; margin: 0 auto 16px; border-radius: 16px; border-width: 2px; box-shadow: var(--shadow-sm); }
.login-title { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.login-subtitle { margin-top: 6px; font-size: 13.5px; color: var(--text-2); }
.login-form { display: flex; flex-direction: column; gap: 14px; margin-top: 26px; text-align: left; }
.login-form .btn { width: 100%; margin-top: 8px; height: 46px; }
.login-error {
    min-height: 20px;
    font-size: 13px;
    color: var(--danger);
    text-align: center;
}
.demo-banner-login { margin-bottom: 16px; border-radius: var(--radius); border: 1px solid var(--border); }

/* PIN inputs (legacy mode) */
.pin-input-container { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin: 8px 0; }
.pin-input-container input.pin-input {
    width: 44px;
    height: 52px;
    text-align: center;
    font-size: 20px;
    font-weight: 600;
    background: var(--input-bg);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    outline: none;
    -webkit-appearance: none;
    -moz-appearance: textfield;
}
.pin-input-container input.pin-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.pin-input-container input.pin-input.has-value { background: var(--accent); color: var(--accent-fg); border-color: var(--shadow-color); }
.pin-error { font-size: 13px; color: var(--danger); margin-top: 10px; text-align: center; display: none; }
.pin-error[aria-hidden="false"] { display: block; }
@media (max-width: 360px) {
    .pin-input-container { gap: 6px; }
    .pin-input-container input.pin-input { width: 38px; height: 46px; }
}

/* =========================================================
   List popover (quick commands, recently copied)
   ========================================================= */
.popover {
    position: fixed;
    z-index: 95;
    display: flex;
    flex-direction: column;
    background: var(--popover);
    border: 1.5px solid var(--shadow-color);
    border-radius: 1.25rem;
    box-shadow: var(--shadow);
    overflow: hidden;
    animation: pop-in 120ms var(--ease);
}
.popover-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 6px 4px 16px;
}
.popover-title { font-size: 13.5px; font-weight: 600; }
.popover-close { width: 34px; height: 34px; border-radius: 50%; }
.popover-note, .popover-empty { padding: 0 16px 8px; font-size: 12px; color: var(--text-3); line-height: 1.4; }
.popover-empty { padding: 12px 16px 16px; }
.popover-list { list-style: none; overflow-y: auto; padding: 0 6px 6px; min-height: 0; flex: 1; }
.popover-item { display: flex; align-items: center; gap: 2px; }
.popover-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    column-gap: 8px;
    row-gap: 2px;
    min-height: 48px;
    padding: 8px 12px;
    border-radius: 0.9rem;
    text-align: left;
}
.popover-main:hover, .popover-main:focus-visible { background: var(--surface-2); }
.popover-main:active { background: var(--surface-3); }
.popover-primary {
    font-size: 14px;
    font-weight: 500;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.popover-secondary {
    flex-basis: 100%;
    font-size: 12px;
    color: var(--text-3);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.popover-badge {
    font-size: 10.5px;
    font-weight: 600;
    padding: 1px 7px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    white-space: nowrap;
}
.popover-remove { width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0; }
.popover-actions { display: flex; gap: 6px; padding: 8px 10px 10px; border-top: 1px solid var(--divider); }
.popover-action {
    flex: 1;
    height: 38px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    background: var(--surface-2);
    border: 1px solid var(--border);
}
.popover-action:hover { background: var(--surface-3); }
.popover-action.danger { color: var(--danger); }

/* ---------- quick commands admin (settings) ---------- */
.commands-help { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin: 0 4px 10px; }
.commands-help .icon { display: inline-block; }
.commands-list { list-style: none; display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.commands-empty { font-size: 13px; color: var(--text-3); padding: 6px 4px; }
.command-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 6px 8px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--input-bg);
}
.command-text { display: flex; flex-direction: column; min-width: 0; flex: 1; gap: 2px; }
.command-label { font-size: 13.5px; font-weight: 500; }
.command-code { font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.command-badge {
    font-size: 10.5px;
    font-weight: 600;
    padding: 1px 7px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
}
.commands-form { display: flex; flex-direction: column; gap: 12px; }
.commands-form textarea {
    min-height: 64px;
    padding: 10px 16px;
    background: var(--input-bg);
    border: 1.5px solid var(--border);
    border-radius: 1.25rem;
    font-size: 13px;
    resize: vertical;
    outline: none;
}
.commands-form textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.setting-inline { border-bottom: none; padding: 0; min-height: 0; }
.commands-error { min-height: 0; font-size: 12.5px; color: var(--danger); }
.commands-error:empty { display: none; }
.commands-actions { display: flex; justify-content: flex-end; gap: 8px; }
/* Shortcut bar: scrolling keys + pinned action buttons (quick commands, paste) */
.shortcut-row { display: flex; align-items: center; min-width: 0; }
.shortcut-row .shortcut-scroll { flex: 1; min-width: 0; }
.shortcut-pinned {
    display: flex;
    gap: 7px;
    flex-shrink: 0;
    padding: 0 max(10px, var(--safe-right)) 0 8px;
    border-left: 1px solid var(--divider);
}
/* =========================================================
   Browser tabs (page from the server's Chromium, streamed as images)
   ========================================================= */
.terminal-panel.browser-panel {
    padding: 0;
    display: flex;
    flex-direction: column;
    touch-action: auto;
}
.browser-toolbar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 6px 8px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.browser-toolbar .icon-btn { flex-shrink: 0; }
.browser-toolbar .icon-btn:disabled { opacity: 0.35; }
.browser-address { flex: 1; min-width: 0; margin: 0 4px; }
.browser-address input {
    width: 100%;
    height: 36px;
    padding: 0 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    background: var(--input-bg);
    color: var(--text);
    font-size: 14px;          /* 16px on phones: below that iOS zooms on focus */
    outline: none;
}
.browser-address input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.browser-kbd-btn { display: none; }
.browser-progress {
    flex-shrink: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    background-size: 50% 100%;
    animation: browser-progress 1s linear infinite;
}
@keyframes browser-progress { from { background-position: -50% 0; } to { background-position: 150% 0; } }
.browser-viewer {
    position: relative;
    flex: 1;
    min-height: 0;
    display: grid;
    place-items: center;
    overflow: hidden;
    background: var(--bg);
}
.browser-surface {
    position: relative;
    background: #fff;
    touch-action: none;       /* taps, drags and 2-finger taps are handled in JS */
    outline: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}
.browser-surface:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.browser-surface canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }
.browser-status {
    position: absolute;
    left: 50%;
    bottom: 14px;
    transform: translateX(-50%);
    max-width: calc(100% - 24px);
    padding: 8px 16px;
    border-radius: var(--radius);
    background: var(--popover);
    border: 1.5px solid var(--shadow-color);
    box-shadow: var(--shadow-sm);
    font-size: 13px;
    pointer-events: none;
}
.browser-status:empty { display: none; }
/* Off-screen but focusable: focusing it opens the phone keyboard */
.browser-kbd {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 1px;
    height: 1px;
    opacity: 0;
    font-size: 16px;
    resize: none;
    border: 0;
    pointer-events: none;
}

/* Browser tabs: square identity dot */
.tab.browser .tab-dot { border-radius: 3px; }

/* New tab page: Terminal | Navegador */
.kind-toggle {
    display: flex;
    gap: 4px;
    padding: 4px;
    border-radius: var(--radius);
    background: var(--surface-2);
    border: 1px solid var(--border);
}
.kind-toggle button {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 40px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    color: var(--text-2);
}
.kind-toggle button[aria-checked="true"] {
    background: var(--accent);
    color: var(--accent-fg);
    border: 1.5px solid var(--shadow-color);
    box-shadow: 2px 2px 0 0 var(--shadow-color);
}
.port-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.port-chips:empty { display: none; }
.port-chip {
    height: 34px;
    padding: 0 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface-2);
    font-family: var(--font-mono);
    font-size: 13px;
}
.port-chip:hover { border-color: var(--accent); }

/* Phones: compact toolbar, bigger touch targets, keyboard button */
@media (pointer: coarse) {
    .browser-kbd-btn { display: inline-grid; }
    .browser-address input { height: 40px; font-size: 16px; }
    .port-chip { height: 40px; }
}
@media (max-width: 719px) {
    .browser-toolbar { padding: 4px; gap: 0; }
    .browser-address { margin: 0 2px; }
    /* Forward is the least used button: drop it on narrow screens */
    .browser-toolbar [data-act="forward"] { display: none; }
}
@media (max-width: 360px) {
    .browser-toolbar [data-act="ports"] { display: none; }
}
/* Landscape phones / keyboard open: every pixel of height goes to the page */
@media (pointer: coarse) and (max-height: 500px) {
    .browser-toolbar { padding: 2px 4px; }
    .browser-address input { height: 34px; }
}
/* Two-factor code field (login) */
.login-card input.code-input {
    font-family: var(--font-mono);
    font-size: 24px;
    letter-spacing: 0.4em;
    text-align: center;
}
/* Login fields never push the card wider than the screen (the code field has a
   large, spaced font whose intrinsic width is wider than a phone) */
.login-card .field { min-width: 0; }
.login-card .field input { width: 100%; min-width: 0; }
/* Settings: MCP for agents */
.mcp-help { margin: 0 4px 10px; }
.mcp-command {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 8px 8px 14px;
    margin-bottom: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--input-bg);
}
.mcp-command code {
    flex: 1;
    min-width: 0;
    font-size: 12px;
    line-height: 1.5;
    overflow-wrap: anywhere;
    user-select: all;
}
.mcp-command .btn { height: 36px; padding: 0 14px; flex-shrink: 0; }
.mcp-section code.mono { font-size: 12px; overflow-wrap: anywhere; }
/* =========================================================
   Small modals (prompt.js) + button variants
   ========================================================= */
.btn-sm { height: 34px; padding: 0 14px; font-size: 13px; display: inline-flex; align-items: center; gap: 6px; }
.btn-primary.btn-sm:active { transform: translate(2px, 2px); }
.btn-danger { background: var(--danger); color: #fff; box-shadow: var(--shadow-sm); }
.btn-danger:active { transform: translate(4px, 4px); box-shadow: 0 0 0 0 var(--shadow-color); }
.icon-btn.danger { color: var(--danger); }
.prompt-dialog { width: min(440px, calc(100vw - 32px)); }
.prompt-form { display: flex; flex-direction: column; min-height: 0; }
.prompt-dialog .dialog-body { padding-top: 16px; }
.prompt-dialog .field input { width: 100%; font-size: 16px; }
.prompt-error { min-height: 1em; margin-top: 8px; font-size: 13px; color: var(--danger); }
.prompt-error:empty { display: none; }
.prompt-message { line-height: 1.55; color: var(--text-2); }
.prompt-details { margin: 12px 0 0; padding-left: 18px; font-family: var(--font-mono); font-size: 12.5px; color: var(--text-2); }
.prompt-details li { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prompt-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 0 24px 22px; flex-wrap: wrap; }
.info-list { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 10px 16px; margin: 0; font-size: 14px; }
.info-list dt { color: var(--text-3); }
.info-list dd { margin: 0; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; overflow-wrap: anywhere; }

/* =========================================================
   Files tab (file manager)
   ========================================================= */
.terminal-panel.files-panel { padding: 0; touch-action: auto; background: var(--bg); }
.tab.files .tab-dot { border-radius: 2px; transform: rotate(45deg) scale(0.85); }
.fm { position: absolute; inset: 0; display: flex; overflow: hidden; }
.fm-main { position: relative; flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* sidebar: fixed column on desktop, drawer on small screens */
.fm-side {
    width: 248px; flex-shrink: 0; overflow-y: auto; padding: 10px 10px 24px;
    background: var(--surface); border-right: 1px solid var(--border);
}
.fm.side-closed .fm-side { display: none; }
.fm-side ul { list-style: none; margin: 0 0 6px; padding: 0; }
.fm-side li { position: relative; display: flex; align-items: center; }
.fm-side-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 10px 6px;
    font-size: 11.5px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-3); }
.fm-side-head:first-child { padding-top: 4px; }
.fm-side-close { display: none; }
.fm-side-item {
    flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 6px 10px;
    border-radius: var(--radius-md); color: var(--text-2); text-align: left;
}
.fm-side-item:hover { background: var(--surface-2); color: var(--text); }
.fm-side-item.current { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.fm-side-item .icon { flex-shrink: 0; }
.fm-side-text { min-width: 0; display: flex; flex-direction: column; }
.fm-side-text span, .fm-side-text small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fm-side-text small { font-size: 11.5px; color: var(--text-3); font-weight: 400; font-family: var(--font-mono); }
.fm-side-remove { width: 30px; height: 30px; opacity: 0; }
.fm-side li:hover .fm-side-remove, .fm-side-remove:focus-visible { opacity: 1; }
.fm-side-hint { margin: 2px 10px 8px; font-size: 12.5px; line-height: 1.5; color: var(--text-3); }
.fm-side-hint code { font-family: var(--font-mono); font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 6px; }
.fm-scrim { position: absolute; inset: 0; z-index: 20; background: var(--backdrop); }

/* toolbar + breadcrumbs */
.fm-toolbar {
    flex-shrink: 0; display: flex; align-items: center; gap: 2px; padding: 6px 8px;
    background: var(--surface); border-bottom: 1px solid var(--border);
}
.fm-toolbar .icon-btn { flex-shrink: 0; }
.fm-toolbar .icon-btn:disabled { opacity: 0.35; }
.fm-crumbs {
    flex: 1; min-width: 0; display: flex; align-items: center; gap: 0; margin: 0 4px; overflow-x: auto;
    scrollbar-width: none; -webkit-mask-image: linear-gradient(to right, transparent 0, #000 12px);
    mask-image: linear-gradient(to right, transparent 0, #000 12px); padding-left: 8px;
}
.fm-crumbs::-webkit-scrollbar { display: none; }
.fm-crumb {
    flex-shrink: 0; display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 8px;
    border-radius: var(--radius-sm); font-size: 13.5px; color: var(--text-2); white-space: nowrap; max-width: 220px;
}
.fm-crumb span { overflow: hidden; text-overflow: ellipsis; }
.fm-crumb:hover { background: var(--surface-2); color: var(--text); }
.fm-crumb[aria-current="page"] { color: var(--text); font-weight: 600; }
.fm-crumb.drop-target { background: var(--accent-soft); color: var(--accent); outline: 1.5px dashed var(--accent); }
.fm-crumb-sep { flex-shrink: 0; color: var(--text-3); display: inline-grid; }
.fm-progress { position: relative; height: 2px; flex-shrink: 0; overflow: hidden; background: var(--accent-soft); }
.fm-progress::after { content: ''; position: absolute; inset: 0; width: 40%; background: var(--accent); animation: fm-load 1s var(--ease) infinite; }
@keyframes fm-load { from { transform: translateX(-100%); } to { transform: translateX(250%); } }

/* search */
.fm-search {
    flex-shrink: 0; display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 16px;
    background: var(--surface); border-bottom: 1px solid var(--border); color: var(--text-3);
}
.fm-search input {
    flex: 1; min-width: 0; height: 38px; padding: 0 14px; border: 1.5px solid var(--border); border-radius: var(--radius);
    background: var(--input-bg); color: var(--text); font-size: 14px; outline: none;
}
.fm-search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.fm-results-bar {
    flex-shrink: 0; display: flex; align-items: center; gap: 10px; padding: 8px 12px 8px 16px;
    background: var(--accent-soft); color: var(--text); font-size: 13.5px;
}
.fm-results-bar span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* list header (desktop list view) */
.fm-head {
    flex-shrink: 0; display: grid; grid-template-columns: 1fr 110px 150px 40px; gap: 8px; padding: 0 12px 0 60px;
    border-bottom: 1px solid var(--divider); font-size: 12px; color: var(--text-3);
}
.fm-head button { height: 30px; text-align: left; color: inherit; font-weight: 500; }
.fm-head button:hover, .fm-head button.sorted { color: var(--text); }
.fm[data-view="grid"] .fm-head { display: none; }

/* rows */
.fm-list {
    flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 4px 6px 120px; outline: none;
    overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
    scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent;
}
.fm-row {
    position: relative; display: grid; grid-template-columns: 0 28px 1fr 110px 150px 40px; align-items: center; gap: 8px;
    min-height: 44px; padding: 3px 6px 3px 12px; border-radius: var(--radius-md); cursor: default; user-select: none;
    -webkit-user-select: none; -webkit-touch-callout: none; color: var(--text);
}
.fm-row:hover { background: var(--surface-2); }
.fm-row.selected { background: var(--accent-soft); }
.fm-row.cursor { box-shadow: inset 0 0 0 1.5px var(--accent); }
.fm-list:not(:focus-visible) .fm-row.cursor:not(.selected) { box-shadow: none; }
.fm-row.cut { opacity: 0.5; }
.fm-row.dotfile .fm-title { color: var(--text-2); }
.fm-row.drop-target { background: var(--accent-soft); outline: 1.5px dashed var(--accent); }
.fm-check { display: inline-grid; visibility: hidden; overflow: hidden; color: var(--text-3); }
.fm-row.selected .fm-check { color: var(--accent); }
.fm-list.selecting .fm-row { grid-template-columns: 26px 28px 1fr 110px 150px 40px; }
.fm-list.selecting .fm-check { visibility: visible; }
.fm-icon { display: grid; place-items: center; color: var(--text-2); }
.fm-icon.kind-dir { color: var(--accent); }
.fm-icon.kind-image { color: var(--c-pink); }
.fm-icon.kind-video { color: var(--c-orange); }
.fm-icon.kind-audio { color: var(--c-cyan); }
.fm-icon.kind-code, .fm-icon.kind-json { color: var(--c-blue); }
.fm-icon.kind-archive { color: var(--c-yellow); }
.fm-icon.kind-key { color: var(--c-green); }
.fm-name { min-width: 0; display: flex; flex-direction: column; }
.fm-title { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fm-link { color: var(--text-3); font-size: 12px; }
.fm-sub { display: none; font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fm-size, .fm-date { font-size: 12.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.fm-more { width: 34px; height: 34px; opacity: 0; }
.fm-row:hover .fm-more, .fm-row.selected .fm-more, .fm-more:focus-visible { opacity: 1; }
.fm-note { padding: 12px; text-align: center; font-size: 12.5px; color: var(--text-3); }

/* grid view */
.fm[data-view="grid"] .fm-list {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); align-content: start; gap: 8px; padding: 10px 8px 120px;
}
@media (min-width: 480px) {
    .fm[data-view="grid"] .fm-list { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; padding: 10px 10px 120px; }
}
@media (min-width: 768px) {
    .fm[data-view="grid"] .fm-list { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
}
@media (min-width: 1024px) {
    .fm[data-view="grid"] .fm-list { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; }
}
.fm[data-view="grid"] .fm-row,
.fm[data-view="grid"] .fm-list.selecting .fm-row {
    grid-template-columns: 1fr; grid-template-rows: auto auto; justify-items: center; text-align: center; gap: 6px;
    padding: 8px 4px 10px; min-height: 0;
}
.fm[data-view="grid"] .fm-icon { width: 100%; height: auto; aspect-ratio: 1; border-radius: var(--radius-md); background: var(--surface); overflow: hidden; }
.fm[data-view="grid"] .fm-icon img { width: 100%; height: 100%; object-fit: cover; }
.fm[data-view="grid"] .fm-name { width: 100%; min-width: 0; }
.fm[data-view="grid"] .fm-title { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; font-size: clamp(11px, 2.5vw, 13px); overflow-wrap: anywhere; word-break: break-word; }
.fm[data-view="grid"] .fm-sub { display: block; font-size: 10.5px; color: var(--text-3); }
.fm[data-view="grid"] .fm-size, .fm[data-view="grid"] .fm-date { display: none; }
.fm[data-view="grid"] .fm-list:not(.selecting) .fm-check { display: none; }
.fm[data-view="grid"] .fm-check { position: absolute; top: 6px; left: 6px; z-index: 1; background: var(--surface); border-radius: 4px; width: 18px; height: 18px; }
.fm[data-view="grid"] .fm-more { position: absolute; top: 6px; right: 6px; background: var(--surface); border-radius: 50%; width: 24px; height: 24px; }

/* empty / error */
.fm-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 56px 24px;
    text-align: center; color: var(--text-3); grid-column: 1 / -1; }
.fm-empty p { max-width: 420px; line-height: 1.5; color: var(--text-2); }
.fm-empty-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* floating bars (selection / paste), FAB, uploads */
.fm-bars { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 6; display: flex; flex-direction: column;
    gap: 8px; width: max-content; max-width: calc(100% - 24px); pointer-events: none; }
.fm-selbar, .fm-pastebar {
    pointer-events: auto; display: flex; align-items: center; gap: 2px; padding: 5px 6px; overflow-x: auto; scrollbar-width: none;
    background: var(--popover); border: 1.5px solid var(--shadow-color); border-radius: var(--radius); box-shadow: var(--shadow);
}
.fm-selbar[hidden], .fm-pastebar[hidden] { display: none; }
.fm-selbar .icon-btn { flex-shrink: 0; border-radius: 50%; }
.fm-sel-count { padding: 0 8px 0 2px; font-size: 13.5px; font-weight: 600; white-space: nowrap; }
.fm-pastebar { gap: 10px; padding: 5px 6px 5px 16px; font-size: 13.5px; color: var(--text-2); }
.fm-paste-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 42vw; }
.fm-fab {
    position: absolute; right: 18px; bottom: 18px; z-index: 5; width: 56px; height: 56px; display: grid; place-items: center;
    border-radius: 50%; background: var(--accent); color: var(--accent-fg); border: 1.5px solid var(--shadow-color); box-shadow: var(--shadow);
    transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.fm-fab:active { transform: translate(4px, 4px); box-shadow: 0 0 0 0 var(--shadow-color); }
.fm.has-bars .fm-fab { bottom: 84px; }
.fm-uploads {
    position: absolute; right: 16px; bottom: 86px; z-index: 7; width: min(360px, calc(100% - 32px)); max-height: 46%;
    display: flex; flex-direction: column; background: var(--popover); border: 1.5px solid var(--shadow-color);
    border-radius: var(--radius-md); box-shadow: var(--shadow); overflow: hidden;
}
.fm-uploads[hidden] { display: none; }
.fm-up-head { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 14px; font-size: 13px; font-weight: 600; border-bottom: 1px solid var(--divider); }
.fm-up-head span { flex: 1; }
.fm-up-head .icon-loader, .fm-empty .icon-loader { animation: fm-spin 1s linear infinite; }
@keyframes fm-spin { to { transform: rotate(360deg); } }
.fm-up-list { list-style: none; margin: 0; padding: 4px 0; overflow-y: auto; }
.fm-up { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 8px; padding: 6px 8px 8px 14px; }
.fm-up-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fm-up-meta { grid-column: 1; font-size: 11.5px; color: var(--text-3); }
.fm-up .icon-btn { grid-row: 1 / span 2; grid-column: 2; width: 30px; height: 30px; }
.fm-up.error .fm-up-meta { color: var(--danger); }
.fm-up-bar { grid-column: 1 / -1; height: 3px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.fm-up-bar span { display: block; height: 100%; background: var(--accent); transition: width 150ms linear; }
.fm-up.done .fm-up-bar span { background: var(--success); }
.fm-up.error .fm-up-bar span { background: var(--danger); }
.fm-drop { position: absolute; inset: 8px; z-index: 8; display: grid; place-items: center; pointer-events: none;
    border: 2px dashed var(--accent); border-radius: var(--radius-md); background: color-mix(in srgb, var(--accent-soft) 60%, var(--bg)); }
.fm-drop[hidden] { display: none; }
.fm-drop div { display: flex; flex-direction: column; align-items: center; gap: 10px; color: var(--accent); font-weight: 600; text-align: center; padding: 16px; }

/* viewer / editor */
.fm-viewer { position: absolute; inset: 0; z-index: 30; display: flex; flex-direction: column; background: var(--bg); }
.fm-viewer[hidden] { display: none; }
.fm-viewer-bar { flex-shrink: 0; display: flex; align-items: center; gap: 4px; padding: 6px 8px; background: var(--surface); border-bottom: 1px solid var(--border); }
.fm-viewer-bar .icon-btn { flex-shrink: 0; }
.fm-viewer-bar .icon-btn.on { color: var(--accent); background: var(--accent-soft); }
.fm-viewer-title { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 0 6px; }
.fm-viewer-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fm-viewer-meta { font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fm-viewer.dirty .fm-viewer-name::after { content: ' •'; color: var(--accent); }
.fm-save { flex-shrink: 0; }
.fm-viewer-body { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: auto; }
.fm-media { max-width: 100%; max-height: 100%; }
img.fm-media { cursor: zoom-in; }
img.fm-media.fit { object-fit: contain; width: 100%; height: 100%; }
img.fm-media:not(.fit) { max-width: none; max-height: none; cursor: zoom-out; align-self: flex-start; }
.fm-viewer-body:has(img.fm-media:not(.fit)) { align-items: flex-start; justify-content: flex-start; }
video.fm-media { width: 100%; height: 100%; background: #000; }
audio.fm-media { width: min(520px, 90%); }
.fm-pdf { width: 100%; height: 100%; border: 0; background: #fff; }
.fm-editor {
    width: 100%; height: 100%; resize: none; border: 0; outline: none; padding: 14px 16px 40vh; background: var(--term-bg); color: var(--term-fg);
    font-size: 13.5px; line-height: 1.55; tab-size: 4; white-space: pre; overflow: auto;
}
.fm-editor[wrap="soft"] { white-space: pre-wrap; overflow-wrap: anywhere; }
.fm-nav {
    position: absolute; top: 50%; z-index: 2; width: 44px; height: 64px; margin-top: -32px; display: grid; place-items: center;
    background: color-mix(in srgb, var(--surface) 80%, transparent); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-md);
}
.fm-nav.prev { left: 10px; }
.fm-nav.next { right: 10px; }
.fm-nav[hidden] { display: none; }

@media (max-width: 899px) {
    .fm-side {
        position: absolute; top: 0; bottom: 0; left: 0; z-index: 25; width: min(300px, 84vw); display: block;
        transform: translateX(-105%); transition: transform 200ms var(--ease); box-shadow: var(--shadow-lg);
    }
    .fm.side-closed .fm-side { display: block; }
    .fm.side-open .fm-side { transform: none; }
    .fm-side-close { display: inline-grid; }
}
@media (max-width: 719px), (pointer: coarse) {
    .fm-wide { display: none; }
    .fm-head { display: none; }
    .fm-row, .fm-list.selecting .fm-row { grid-template-columns: 0 34px 1fr 40px; min-height: 56px; gap: 10px; }
    .fm-list.selecting .fm-row { grid-template-columns: 26px 34px 1fr 40px; }
    .fm-size, .fm-date { display: none; }
    .fm-sub { display: block; }
    .fm-more { opacity: 1; width: 40px; height: 40px; }
    .fm-title { font-size: 15px; }
    .fm-row:hover { background: transparent; }
    .fm-row.selected { background: var(--accent-soft); }
    .fm-row:active { background: var(--surface-2); }
    .fm-search input { font-size: 16px; }
    .fm-search .btn { display: none; }
    .fm-editor { font-size: 14px; }
    .fm[data-view="grid"] .fm-icon { aspect-ratio: 1; }
    .fm[data-view="grid"] .fm-title { font-size: 12px; }
    .fm-selbar .icon-btn { width: 40px; height: 40px; }
    .fm-selbar [data-sel="all"], .fm-selbar [data-sel="rename"] { display: none; }
    .fm-uploads { right: 12px; left: 12px; width: auto; }
    .fm-nav { display: none; }
}
@media (min-width: 720px) and (pointer: fine) {
    .fm-fab { display: none; }
    .fm-search .btn { display: inline-flex; }
}

/* =========================================================
   Split view: two tabs side by side (row) or stacked (col, phones)
   ========================================================= */
.terminal-panels.split .terminal-panel.pane-a,
.terminal-panels.split .terminal-panel.pane-b { visibility: visible; }
.terminal-panels.split.row .pane-a { right: calc((1 - var(--split, .5)) * 100% + 3px); }
.terminal-panels.split.row .pane-b { left: calc(var(--split, .5) * 100% + 3px); }
.terminal-panels.split.col .pane-a { bottom: calc((1 - var(--split, .5)) * 100% + 3px); }
.terminal-panels.split.col .pane-b { top: calc(var(--split, .5) * 100% + 3px); }
.terminal-panels.split .pane-focused::after {
    content: ''; position: absolute; left: 0; right: 0; top: 0; height: 2px; z-index: 4;
    background: var(--accent); pointer-events: none;
}
.split-divider {
    position: absolute; z-index: 6; background: var(--border); touch-action: none;
    display: grid; place-items: center; outline: none;
}
.split-divider[hidden] { display: none; }
.split-divider::before { content: ''; position: absolute; inset: -8px; } /* bigger hit area */
.terminal-panels.row .split-divider { top: 0; bottom: 0; width: 6px; left: calc(var(--split, .5) * 100% - 3px); cursor: col-resize; }
.terminal-panels.col .split-divider { left: 0; right: 0; height: 6px; top: calc(var(--split, .5) * 100% - 3px); cursor: row-resize; }
.split-grip { width: 4px; height: 36px; border-radius: 4px; background: var(--text-3); }
.terminal-panels.col .split-grip { width: 36px; height: 4px; }
.split-divider:hover, .split-divider:focus-visible, .terminal-panels.resizing .split-divider { background: var(--accent); }
.split-divider:hover .split-grip, .split-divider:focus-visible .split-grip,
.terminal-panels.resizing .split-grip { background: var(--accent-fg); }
.terminal-panels.resizing { user-select: none; -webkit-user-select: none; }
.terminal-panels.resizing .terminal-panel { pointer-events: none; }
/* Tabs of the pair: the one in view (not focused) is highlighted too */
.tab.in-view { background: var(--surface-2); }
.tab.paired .tab-dot { box-shadow: 0 0 0 2px var(--accent-soft); }
@media (pointer: coarse) {
    .terminal-panels.col .split-divider { height: 10px; top: calc(var(--split, .5) * 100% - 5px); }
    .terminal-panels.col .split-grip { width: 44px; height: 5px; }
    .terminal-panels.split.col .pane-a { bottom: calc((1 - var(--split, .5)) * 100% + 5px); }
    .terminal-panels.split.col .pane-b { top: calc(var(--split, .5) * 100% + 5px); }
}

/* Live reload badge on browser tabs */
.browser-live {
    flex-shrink: 0; display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 9px;
    border-radius: 99px; font-size: 11.5px; font-weight: 600; letter-spacing: .02em;
    background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent);
}
.browser-live[hidden] { display: none; }
.browser-live::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: live-pulse 1.6s infinite; }
@keyframes live-pulse { 50% { opacity: .3; } }
@media (max-width: 480px) { .browser-live span { display: none; } }

/* Notifications (settings) */
.push-status { margin: 10px 0; font-size: 13.5px; color: var(--text-2); }
.push-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* Vibecoding form */
.vibe-dialog { width: min(560px, calc(100vw - 24px)); }
.vibe-form { display: flex; flex-direction: column; min-height: 0; }
.vibe-form .dialog-body { display: flex; flex-direction: column; gap: 14px; padding-top: 16px; }
.vibe-lead { color: var(--text-2); font-size: 14px; line-height: 1.5; margin: 0; }
.vibe-form .field input, .vibe-form .field select, .vibe-form .field textarea { width: 100%; font-size: 16px; }
.vibe-form .field select, .vibe-form .field textarea {
    padding: 10px 14px; background: var(--input-bg); color: var(--text); border: 1.5px solid var(--border);
    border-radius: var(--radius-md); font-family: inherit; outline: none;
}
.vibe-form .field select { height: 44px; border-radius: var(--radius); }
.vibe-form .field textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
.vibe-form .field select:focus, .vibe-form .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.vibe-kinds { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.vibe-kind {
    display: flex; align-items: center; gap: 8px; padding: 10px 12px; border: 1.5px solid var(--border);
    border-radius: var(--radius-md); cursor: pointer; font-size: 14px; background: var(--surface);
}
.vibe-kind:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); box-shadow: 2px 2px 0 var(--shadow-color); }
.vibe-kind input { accent-color: var(--accent); margin: 0; }
.vibe-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .vibe-row { grid-template-columns: 1fr; } }
.vibe-check { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--text-2); }
.vibe-check input { width: 18px; height: 18px; accent-color: var(--accent); }
.vibe-from-agent { font-size: 13px; padding: 10px 12px; border-radius: var(--radius-md); background: var(--accent-soft); color: var(--text); }

/* "Abrir projeto anterior" */
.vibe-previous-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow-y: auto; }
.vibe-prev-open {
    width: 100%; display: flex; flex-direction: column; gap: 2px; text-align: left; padding: 10px 12px;
    border: 1.5px solid var(--border); border-radius: var(--radius-md); background: var(--surface);
}
.vibe-prev-open:hover { border-color: var(--border-strong); background: var(--surface-2); }
.vibe-prev-open:disabled { opacity: 0.6; cursor: default; }
.vibe-prev-name { font-weight: 600; font-size: 14px; color: var(--text); }
.vibe-prev-meta { font-size: 12.5px; color: var(--text-2); }
.vibe-prev-path { font-size: 11.5px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vibe-divider { display: flex; align-items: center; gap: 10px; color: var(--text-3); font-size: 12.5px; }
.vibe-divider::before, .vibe-divider::after { content: ''; flex: 1; height: 1px; background: var(--divider); }

.vibe-form .vibe-kind input[type="radio"] { width: 18px; height: 18px; min-width: 18px; padding: 0; flex: none; border: 0; box-shadow: none; }
.vibe-form .vibe-check input[type="checkbox"] { width: 18px; height: 18px; flex: none; }


/* ---------- agent UI tab (public/managers/agentSession.js, public/agent/) ---------- */
.tab.agent .tab-dot { border-radius: 50% 50% 2px 50%; }
.terminal-panel.agent-panel {
    padding: 0; display: flex; flex-direction: column; touch-action: auto; background: var(--bg); color: var(--text);
}

/* header */
.ag-head {
    flex-shrink: 0; display: flex; align-items: center; gap: 4px; min-height: 52px; padding: 6px 8px 6px 14px;
    border-bottom: 1px solid var(--border); background: var(--surface);
}
.ag-head-icon { flex-shrink: 0; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); }
.ag-head-text { flex: 1; min-width: 0; margin: 0 6px; }
.ag-head-title { font-size: 14.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-head-sub { font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-status {
    flex-shrink: 0; padding: 3px 10px; margin-right: 4px; border-radius: 999px; font-size: 12px; font-weight: 500;
    background: var(--surface-2); color: var(--text-2);
}
.ag-status[data-tone="busy"] { background: var(--accent-soft); color: var(--accent); }
.ag-status[data-tone="warn"] { background: color-mix(in srgb, var(--c-orange) 18%, transparent); color: var(--c-orange); }
.ag-status[data-tone="bad"] { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.ag-publish { flex-shrink: 0; gap: 6px; white-space: nowrap; }
.ag-publish.loading .icon { animation: ag-spin 0.9s linear infinite; }
.ag-head .icon-btn { width: 40px; height: 40px; flex-shrink: 0; position: relative; }
.ag-head .icon-btn.has-activity::after {
    content: ""; position: absolute; top: 9px; right: 9px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
}

/* banners: reconnecting, stopped, bypass mode */
.ag-banner { flex-shrink: 0; }
.ag-banner-row {
    display: flex; align-items: center; flex-wrap: wrap; gap: 8px 10px; padding: 8px 16px; font-size: 13px;
    border-bottom: 1px solid var(--border);
}
.ag-banner-row.info { background: var(--accent-soft); color: var(--text); }
.ag-banner-row.bad { background: color-mix(in srgb, var(--danger) 12%, var(--bg)); color: var(--text); }
.ag-banner-row .btn { min-height: 36px; }

/* body: conversation | side panel */
.ag-body { flex: 1; min-height: 0; display: flex; position: relative; }
.ag-main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.ag-log {
    flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 16px 16px 28px;
    overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; outline: none;
}
.ag-log > * { max-width: 860px; margin-left: auto; margin-right: auto; }
.ag-turn { display: flex; flex-direction: column; gap: 10px; padding-bottom: 18px; content-visibility: auto; contain-intrinsic-size: auto 400px; }
.ag-turn:last-child { content-visibility: visible; }
.ag-empty { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 64px 16px; color: var(--text-3); text-align: center; }
.ag-jump {
    /* floats above the message box; the box grows, so it sits well above its usual height */
    position: absolute; right: 16px; bottom: 150px; z-index: 3; width: 40px; height: 40px; border-radius: 50%;
    display: grid; place-items: center; background: var(--surface); border: 1px solid var(--border); color: var(--text);
    box-shadow: var(--shadow-lg, 0 4px 16px rgba(0,0,0,.3));
}
.ag-jump[hidden] { display: none; }

/* messages */
.ag-user {
    align-self: flex-end; max-width: min(85%, 640px); padding: 10px 14px; border-radius: 16px 16px 4px 16px;
    background: var(--accent-soft); white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14.5px; line-height: 1.5;
}
.ag-attach { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); margin-bottom: 4px; }
.ag-assistant { font-size: 14.5px; line-height: 1.6; overflow-wrap: anywhere; }
.ag-note { font-size: 12.5px; color: var(--text-3); text-align: center; white-space: pre-wrap; }
.ag-note.error { display: block; text-align: left; padding: 10px 12px; border-radius: var(--radius-md); color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }
.ag-note.error pre { margin: 6px 0 0; font-size: 12px; white-space: pre-wrap; color: var(--text-2); }
.ag-note.help { display: block; text-align: left; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); color: var(--text-2); font-family: var(--font-mono, ui-monospace, monospace); font-size: 12.5px; line-height: 1.6; }
.ag-muted { color: var(--text-3); font-size: 12.5px; display: inline-flex; align-items: center; gap: 6px; }
.ag-link { color: var(--accent); background: none; border: 0; padding: 0; font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }

/* markdown */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 10px; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 22px; }
.md li { margin: 3px 0; }
.md li.md-nested { margin-left: 18px; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }
.md-task.done { color: var(--c-green); }

/* reasoning */
.ag-thought summary { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-3); cursor: pointer; list-style: none; min-height: 28px; }
.ag-thought summary::-webkit-details-marker { display: none; }
.ag-thought-body { margin-top: 4px; padding-left: 12px; border-left: 2px solid var(--border); color: var(--text-3); font-size: 13px; font-style: italic; white-space: pre-wrap; max-height: 320px; overflow-y: auto; }

/* tool cards */
.ag-tool { border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); overflow: hidden; }
.ag-tool.flash { box-shadow: 0 0 0 2px var(--accent); }
.ag-tool > summary {
    display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 12px; cursor: pointer; list-style: none; font-size: 13px;
}
.ag-tool > summary::-webkit-details-marker { display: none; }
.ag-tool-icon { flex-shrink: 0; display: inline-grid; color: var(--text-2); }
.ag-tool-verb { flex-shrink: 0; font-weight: 600; color: var(--text-2); }
.ag-tool-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-mono, monospace); font-size: 12.5px; }
.ag-tool-stats { flex-shrink: 0; font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.ag-tool-state { flex-shrink: 0; display: inline-grid; }
.ag-tool[data-status="running"] .ag-tool-state { color: var(--accent); animation: ag-spin 1s linear infinite; }
.ag-tool[data-status="completed"] .ag-tool-state { color: var(--c-green); }
.ag-tool[data-status="failed"] .ag-tool-state, .ag-tool[data-status="cancelled"] .ag-tool-state { color: var(--danger); }
@keyframes ag-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .ag-tool[data-status="running"] .ag-tool-state { animation: none; } }
.ag-tool-body { border-top: 1px solid var(--border); padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.ag-tool-body[hidden] { display: none; }
.ag-cmd { font-family: var(--font-mono, monospace); font-size: 12.5px; white-space: pre-wrap; overflow-wrap: anywhere; }
.ag-cmd span { color: var(--accent); user-select: none; }
.ag-output, .ag-input {
    margin: 0; max-height: 360px; overflow: auto; padding: 8px 10px; border-radius: 8px; background: var(--bg);
    font-size: 12px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere;
}
.ag-output.md { font-family: inherit; font-size: 13px; }
.ag-sub-prompt { font-size: 12.5px; color: var(--text-2); white-space: pre-wrap; max-height: 140px; overflow-y: auto; }
.ag-sub-children { display: flex; flex-direction: column; gap: 6px; padding: 0 10px 10px 22px; border-left: 2px solid var(--accent-soft); margin-left: 12px; }
.ag-sub-children:empty { display: none; }
.ag-tool.kind-task { border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }
.ag-tool.async .ag-tool-verb::after { content: ""; }
.add { color: var(--c-green); }
.del { color: var(--danger); }
.ag-badge { margin-left: 6px; padding: 1px 6px; border-radius: 999px; font-size: 11px; background: color-mix(in srgb, var(--c-green) 18%, transparent); color: var(--c-green); }
.ag-diff-file { font-size: 12.5px; }

/* diff */
.diff { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); max-height: 480px; overflow-y: auto; }
.diff table { border-collapse: collapse; width: 100%; font-family: var(--font-mono, monospace); font-size: 12px; line-height: 1.5; }
.diff td { padding: 0 8px; vertical-align: top; }
.diff .ln { width: 1%; color: var(--text-3); text-align: right; user-select: none; }
.diff .sign { width: 1%; user-select: none; padding: 0 4px; }
.diff .txt { white-space: pre-wrap; overflow-wrap: anywhere; }
.diff tr.add { background: color-mix(in srgb, var(--c-green) 13%, transparent); }
.diff tr.add .sign { color: var(--c-green); }
.diff tr.del { background: color-mix(in srgb, var(--danger) 13%, transparent); }
.diff tr.del .sign { color: var(--danger); }
.diff tr.gap td { color: var(--text-3); font-family: inherit; font-size: 11.5px; padding: 3px 12px; background: var(--surface); }

/* permission */
.ag-perm { padding: 12px; border: 1.5px solid var(--c-orange); border-radius: var(--radius-md); background: var(--surface); display: flex; flex-direction: column; gap: 10px; }
.ag-perm.risky { border-color: var(--danger); }
.ag-perm.answered { border-color: var(--border); }
.ag-perm-head { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }
.ag-risk { display: flex; gap: 6px; align-items: flex-start; padding: 8px 10px; border-radius: 8px; font-size: 13px; color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }
.ag-perm-detail { max-height: 300px; overflow: auto; }
.ag-perm-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.ag-perm-actions .btn { min-height: 44px; }

/* plan */
.ag-plan { padding: 10px 12px; border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: var(--radius-md); background: var(--surface); font-size: 13.5px; }
.ag-plan-head { display: flex; align-items: center; gap: 6px; font-weight: 600; margin-bottom: 6px; }
.ag-plan ol { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; }
.ag-plan li { display: flex; gap: 8px; align-items: flex-start; }
.ag-plan li > span { display: inline-grid; margin-top: 2px; color: var(--text-3); }
.ag-plan li.completed { color: var(--text-3); text-decoration: line-through; }
.ag-plan li.completed > span { color: var(--c-green); }
.ag-plan li.in_progress > span { color: var(--accent); }

/* raw (unmapped) events */
.ag-raw summary { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-3); cursor: pointer; list-style: none; min-height: 28px; }
.ag-raw summary::-webkit-details-marker { display: none; }
.ag-raw pre { margin: 4px 0 0; padding: 8px 10px; border-radius: 8px; background: var(--surface); font-size: 11.5px; max-height: 260px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }

/* pending permission bar */
.ag-pending {
    flex-shrink: 0; display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; padding: 10px 16px;
    border-top: 2px solid var(--c-orange); background: color-mix(in srgb, var(--c-orange) 10%, var(--surface));
}
.ag-pending[hidden] { display: none; }
.ag-pending-title { flex: 1 1 220px; min-width: 0; display: flex; align-items: center; gap: 8px; background: none; border: 0; color: var(--text); font: inherit; font-weight: 600; font-size: 13.5px; text-align: left; cursor: pointer; padding: 0; }
.ag-pending-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-pending-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.ag-pending-actions .btn { min-height: 44px; }

/* composer */
.ag-composer { flex-shrink: 0; position: relative; border-top: 1px solid var(--border); background: var(--surface); padding: 8px 12px 10px; }
.ag-selectors { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.ag-selectors[hidden] { display: none; }
.ag-select, .ag-toggle {
    display: inline-flex; align-items: center; gap: 4px; height: 32px; padding: 0 4px 0 8px; border: 1px solid var(--border);
    border-radius: 999px; background: var(--bg); color: var(--text-2); font-size: 12.5px; max-width: 100%;
}
.ag-select span { display: inline-grid; }
.ag-select select { min-width: 0; max-width: 200px; height: 30px; border: 0; background: transparent; color: var(--text); font-size: 12.5px; outline: none; }
.ag-toggle { padding: 0 10px; cursor: pointer; }
.ag-input-row { display: flex; align-items: flex-end; gap: 6px; }
.ag-input-row textarea {
    flex: 1; min-width: 0; min-height: 44px; max-height: 200px; padding: 11px 14px; resize: none; overflow-y: hidden;
    border: 1.5px solid var(--border); border-radius: 22px; background: var(--input-bg); color: var(--text);
    font: inherit; font-size: 15px; line-height: 1.4; outline: none;
}
.ag-input-row textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.ag-input-row .icon-btn { width: 44px; height: 44px; flex-shrink: 0; }
.ag-send { background: var(--accent); color: #fff; border-radius: 50%; }
.ag-send:disabled { opacity: 0.4; }
.ag-send[hidden], .ag-stop[hidden], .ag-attach-btn[hidden] { display: none; }
.ag-stop { background: var(--surface-2); border-radius: 50%; color: var(--text); }
.ag-images { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.ag-images[hidden] { display: none; }
.ag-thumb { position: relative; width: 56px; height: 56px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.ag-thumb img { width: 100%; height: 100%; object-fit: cover; }
.ag-thumb button { position: absolute; top: 2px; right: 2px; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: rgba(0,0,0,.65); color: #fff; border: 0; }
.ag-suggest {
    position: absolute; left: 12px; right: 12px; bottom: 100%; margin-bottom: 6px; max-height: 280px; overflow-y: auto; z-index: 5;
    border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--shadow-lg, 0 8px 24px rgba(0,0,0,.35));
}
.ag-suggest[hidden] { display: none; }
.ag-suggest-item { display: flex; align-items: baseline; gap: 10px; min-height: 40px; padding: 9px 12px; cursor: pointer; font-size: 13px; }
.ag-suggest-item.active { background: var(--accent-soft); }
.ag-suggest-item.muted { color: var(--text-3); cursor: default; }
.ag-suggest-hint { flex: 1; min-width: 0; color: var(--text-3); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* side panel */
.ag-side {
    display: none; width: 320px; flex-shrink: 0; overflow-y: auto; border-left: 1px solid var(--border); background: var(--surface);
    padding: 12px 12px 24px; font-size: 13px;
}
.ag-body.side-open .ag-side { display: block; }
.ag-side section { margin-bottom: 18px; }
.ag-side h3 { display: flex; align-items: center; gap: 6px; margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); }
.ag-side h3 span:last-child { margin-left: auto; font-variant-numeric: tabular-nums; }
.sp-plan { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }
.sp-plan li.completed { color: var(--text-3); text-decoration: line-through; }
.sp-plan li.in_progress { color: var(--accent); font-weight: 500; }
.sp-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.sp-list button {
    width: 100%; min-height: 40px; display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 0; border-radius: 8px;
    background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.sp-list button:hover { background: var(--surface-2); }
.sp-main { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-meta { flex-shrink: 0; color: var(--text-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.sp-commands button { flex-direction: column; align-items: flex-start; gap: 2px; }
.sp-desc { color: var(--text-3); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.sp-dot { flex-shrink: 0; width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.sp-dot.running { background: var(--accent); }
.sp-dot.async { background: var(--c-orange); }
.sp-dot.completed { background: var(--c-green); }
.sp-dot.failed { background: var(--danger); }
.sp-meter { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-bottom: 6px; }
.sp-meter span { display: block; height: 100%; background: var(--accent); }
.sp-note { margin: 0 0 4px; color: var(--text-2); }
.sp-empty { color: var(--text-3); line-height: 1.5; }

/* narrow screens: the side panel becomes a sheet over the conversation */
@media (max-width: 1099px) {
    .ag-side {
        position: absolute; inset: 0 0 0 auto; width: min(360px, 88vw); z-index: 6; box-shadow: var(--shadow-lg, -8px 0 24px rgba(0,0,0,.35));
    }
}
@media (max-width: 719px), (pointer: coarse) {
    .ag-head { padding-left: 10px; gap: 0; }
    .ag-head [data-act="files"] { display: none; }
    .ag-publish-label { display: none; }
    .ag-publish { width: 36px; padding: 0; justify-content: center; }
    .ag-status { padding: 3px 8px; }
    .ag-log { padding: 12px 12px 24px; }
    .ag-user { max-width: 92%; }
    .ag-tool-verb { display: none; }
    .ag-input-row textarea { font-size: 16px; } /* no zoom on focus (iOS) */
    .ag-select select { max-width: 42vw; }
    .ag-sub-children { padding-left: 12px; margin-left: 6px; }
}
@media (max-width: 400px) {
    .ag-head-sub { display: none; }
    .ag-head [data-act="terminal"] { display: none; }
}

/* "Deseja usar o modo ... UI?" popup */

.agent-launch-dialog { width: min(460px, calc(100vw - 32px)); }
@media (max-width: 640px) { .agent-launch-dialog { width: 100%; } .agent-launch-dialog .prompt-actions .btn { flex: 1; } }
.agent-launch-lead { margin: 0 0 12px; color: var(--text-2); line-height: 1.5; font-size: 14px; }
.agent-launch-info { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 12px; margin: 0 0 14px; font-size: 13.5px; }
.agent-launch-info dt { color: var(--text-3); }
.agent-launch-info dd { margin: 0; overflow-wrap: anywhere; }
.agent-launch-timer { margin: 10px 0 0; font-size: 12px; color: var(--text-3); }
.agent-launch-dialog .prompt-actions .btn { min-height: 44px; min-width: 96px; }

/* Pairing by QR code (settings) */
.pair-box { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; margin: 12px 0; }
.pair-qr { width: min(240px, 100%); padding: 12px; background: #fff; border: 2px solid var(--shadow-color); border-radius: var(--radius-md); box-shadow: var(--shadow-sm); }
.pair-qr:empty { display: none; }
.pair-qr svg { display: block; width: 100%; height: auto; }


/* =========================================================
   Themed selects (ui/select.js): button + listbox, bottom sheet on phones
   ========================================================= */
.ui-select-native { display: none !important; }
.ui-select {
    display: inline-flex; align-items: center; justify-content: space-between; gap: 8px;
    min-width: 0; max-width: 100%; height: 36px; padding: 0 10px 0 14px;
    background: var(--input-bg); color: var(--text); border: 1.5px solid var(--border); border-radius: var(--radius);
    font-size: 13px; font-weight: 500; text-align: left; cursor: pointer; outline: none;
    transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.ui-select-value { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ui-select-chevron { display: inline-grid; flex-shrink: 0; color: var(--text-3); transition: transform 200ms var(--ease), color var(--dur) var(--ease); }
.ui-select:hover:not(:disabled) { border-color: var(--accent); }
.ui-select:hover:not(:disabled) .ui-select-chevron { color: var(--accent); }
.ui-select:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
/* Open: lifts with the theme's hard shadow */
.ui-select.open { border-color: var(--shadow-color); box-shadow: 3px 3px 0 0 var(--shadow-color); transform: translate(-1px, -1px); }
.ui-select.open .ui-select-chevron { transform: rotate(180deg); color: var(--accent); }
.ui-select:active:not(:disabled) { transform: translate(1px, 1px); box-shadow: none; }
.ui-select:disabled { opacity: .45; cursor: not-allowed; }
.ui-select.changed .ui-select-value { animation: ui-select-flash 600ms var(--ease); }
@keyframes ui-select-flash { 0% { color: var(--accent); } 100% { color: inherit; } }

/* Contexts */
.vibe-form .field .ui-select { width: 100%; height: 44px; font-size: 15px; padding: 0 12px 0 16px; }
.ag-select .ui-select {
    height: 30px; padding: 0 4px 0 2px; border: 0; background: transparent; border-radius: 999px;
    font-size: 12.5px; max-width: 200px; box-shadow: none; transform: none;
}
.ag-select .ui-select.open { box-shadow: none; transform: none; }
.ag-select:has(.ui-select.open), .ag-select:hover:has(.ui-select:not(:disabled)) { border-color: var(--accent); color: var(--accent); }
.ag-select:has(.ui-select.open) { box-shadow: 2px 2px 0 0 var(--shadow-color); }
.ag-select .ui-select:focus-visible { box-shadow: none; }
.ag-select:has(.ui-select:focus-visible) { box-shadow: 0 0 0 3px var(--accent-soft); }
.ag-select { cursor: pointer; transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease); }

/* The list */
.ui-select-menu {
    position: fixed; inset: auto; margin: 0; z-index: 1000; display: flex; flex-direction: column;
    min-width: 180px; max-height: 340px; padding: 6px; overflow: hidden;
    background: var(--popover); color: var(--text);
    border: 1.5px solid var(--shadow-color); border-radius: var(--radius-md); box-shadow: var(--shadow);
    transform-origin: top left; animation: ui-select-in 160ms var(--ease);
}
.ui-select-menu.up { transform-origin: bottom left; animation-name: ui-select-in-up; }
.ui-select-menu.closing { animation: ui-select-out 120ms var(--ease) forwards; pointer-events: none; }
.ui-select-menu::backdrop { background: transparent; }
@keyframes ui-select-in { from { opacity: 0; transform: translateY(-6px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes ui-select-in-up { from { opacity: 0; transform: translateY(6px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes ui-select-out { to { opacity: 0; transform: scale(.97); } }
.ui-select-list { flex: 0 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; outline: none; overscroll-behavior: contain;
    scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
.ui-select-option {
    position: relative; display: flex; align-items: center; gap: 10px; min-height: 38px; padding: 8px 12px 8px 8px;
    border-radius: 10px; font-size: 14px; cursor: pointer; user-select: none; -webkit-user-select: none;
    transition: background-color 120ms var(--ease), color 120ms var(--ease), transform 120ms var(--ease);
}
.ui-select-option.active { background: var(--surface-2); }
.ui-select-option:active:not(.disabled) { transform: scale(.98); }
.ui-select-option[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.ui-select-option[aria-selected="true"].active { background: color-mix(in srgb, var(--accent-soft) 100%, var(--surface-2) 60%); }
.ui-select-option.disabled { opacity: .4; cursor: not-allowed; }
.ui-select-check { display: inline-grid; width: 16px; flex-shrink: 0; color: var(--accent); opacity: 0; transform: scale(.4); transition: opacity 160ms var(--ease), transform 200ms var(--ease); }
.ui-select-option[aria-selected="true"] .ui-select-check { opacity: 1; transform: none; }
.ui-select-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ui-select-group { padding: 10px 10px 4px; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }
.ui-select-group:first-child { padding-top: 4px; }
.ui-select-empty { padding: 14px 10px; font-size: 13px; color: var(--text-3); text-align: center; }
.ui-select-filter {
    display: flex; align-items: center; gap: 8px; margin: 0 0 6px; padding: 0 10px; height: 36px; flex-shrink: 0;
    border: 1.5px solid var(--border); border-radius: 10px; background: var(--input-bg); color: var(--text-3);
}
.ui-select-filter:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.ui-select-filter input { flex: 1; min-width: 0; height: 100%; border: 0; background: transparent; color: var(--text); font-size: 14px; outline: none; }

/* Phones: bottom sheet over a dimmed backdrop */
.ui-select-menu.sheet {
    left: 0; right: 0; bottom: 0; top: auto; width: 100%; max-width: none; min-width: 0; max-height: 72vh; max-height: 72dvh;
    padding: 6px 10px calc(14px + env(safe-area-inset-bottom)); border-radius: 22px 22px 0 0;
    border-width: 1.5px 0 0; box-shadow: 0 -4px 0 0 var(--shadow-color);
    transform-origin: bottom center; animation: ui-sheet-in 240ms cubic-bezier(.2, .9, .3, 1);
}
.ui-select-menu.sheet.closing { animation: ui-sheet-out 160ms var(--ease) forwards; }
.ui-select-menu.sheet::backdrop { background: var(--backdrop); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); animation: ui-fade-in 200ms var(--ease); }
@keyframes ui-sheet-in { from { transform: translateY(100%); } to { transform: none; } }
@keyframes ui-sheet-out { to { transform: translateY(100%); } }
@keyframes ui-fade-in { from { opacity: 0; } }
.ui-select-grabber { width: 40px; height: 4px; margin: 4px auto 8px; border-radius: 4px; background: var(--border-strong); flex-shrink: 0; }
.ui-select-title { padding: 2px 8px 10px; font-size: 15px; font-weight: 600; flex-shrink: 0; }
.ui-select-menu.sheet .ui-select-option { min-height: 50px; font-size: 16px; padding: 10px 14px 10px 10px; border-radius: 14px; }
.ui-select-menu.sheet .ui-select-filter { height: 44px; }
.ui-select-menu.sheet .ui-select-filter input { font-size: 16px; }

@media (prefers-reduced-motion: reduce) {
    .ui-select, .ui-select-chevron, .ui-select-option, .ui-select-check { transition: none; }
    .ui-select-menu, .ui-select-menu.sheet, .ui-select-menu.closing, .ui-select-menu.sheet::backdrop,
    .ui-select.changed .ui-select-value { animation: none; }
}

/* Agent media: images, audio and files the agent produced (or you attached) */
.ag-media { display: flex; flex-wrap: wrap; gap: 10px; margin: 8px 0 4px; align-items: flex-start; }
.ag-media-row { margin: 6px 0; }
.ag-user .ag-media { justify-content: flex-end; margin: 0 0 6px; }
.ag-media-img { margin: 0; display: flex; flex-direction: column; gap: 4px; max-width: min(320px, 100%); }
.ag-media-img button {
    display: block; padding: 0; border: 1.5px solid var(--shadow-color); border-radius: var(--radius-md); overflow: hidden;
    background: repeating-conic-gradient(var(--surface-2) 0% 25%, var(--surface) 0% 50%) 50% / 16px 16px;
    box-shadow: var(--shadow-sm); cursor: zoom-in; transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.ag-media-img button:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 0 var(--shadow-color); }
.ag-media-img button:active { transform: translate(2px, 2px); box-shadow: none; }
.ag-media-img img { display: block; max-width: 100%; max-height: 280px; object-fit: contain; animation: ag-media-in 300ms var(--ease); }
@keyframes ag-media-in { from { opacity: 0; transform: scale(.98); } }
.ag-media-img figcaption { display: flex; gap: 8px; align-items: baseline; font-size: 11.5px; color: var(--text-3); min-width: 0; }
.ag-media-img figcaption span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-media-img.broken button { display: none; }
.ag-media-img.broken figcaption::before { content: 'Imagem indisponível: '; }
.ag-media-audio audio { width: min(360px, 100%); }
.ag-media-file {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 10px; max-width: 100%;
    border: 1.5px solid var(--border); border-radius: var(--radius-md); background: var(--surface); font-size: 13px;
}
.ag-media-file.error { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 50%, transparent); }
.ag-media-file a { text-decoration: none; }
.ag-media-name { min-width: 0; flex: 1; overflow-wrap: anywhere; }
.ag-media-name small { color: var(--text-3); margin-left: 4px; }

.ag-lightbox {
    position: fixed; inset: 0; margin: 0; width: 100%; height: 100%; max-width: none; max-height: none; z-index: 2000;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 16px;
    border: 0; background: rgba(0, 0, 0, .86); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
    animation: ui-fade-in 160ms var(--ease); cursor: zoom-out;
}
.ag-lightbox.closing { animation: ui-select-out 150ms var(--ease) forwards; }
.ag-lightbox img { max-width: 100%; max-height: calc(100% - 64px); object-fit: contain; border-radius: var(--radius-md);
    box-shadow: 6px 6px 0 0 #000; animation: ag-media-in 220ms var(--ease); background: repeating-conic-gradient(#2a2a2a 0% 25%, #1f1f1f 0% 50%) 50% / 16px 16px; }
.ag-lightbox-bar { display: flex; align-items: center; gap: 6px; width: min(900px, 100%); color: #F2F0E3; font-size: 14px; }
.ag-lightbox-bar span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-lightbox-bar .icon-btn { color: #F2F0E3; }
@media (prefers-reduced-motion: reduce) { .ag-media-img img, .ag-lightbox, .ag-lightbox img { animation: none; } }

/* ---------- Agent composer: attached files ---------- */
.ag-file-chip {
    position: relative; display: inline-flex; align-items: center; gap: 8px; max-width: 240px; height: 56px;
    padding: 0 32px 0 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2);
    animation: pop-in 160ms var(--ease);
}
.ag-file-chip-icon { display: grid; place-items: center; width: 32px; height: 32px; flex: none; border-radius: 8px;
    background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.ag-file-chip.uploading .ag-file-chip-icon .icon { animation: ag-spin 0.9s linear infinite; }
.ag-file-chip.error { border-color: color-mix(in srgb, var(--danger) 60%, transparent); }
.ag-file-chip.error .ag-file-chip-icon { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.ag-file-chip-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.ag-file-chip-name { font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-file-chip-meta { font-size: 11px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-file-chip button { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%;
    display: grid; place-items: center; background: transparent; color: var(--text-2); border: 0; cursor: pointer; }
.ag-file-chip button:hover { background: var(--surface-3); color: var(--text); }
.ag-attach-btn[aria-expanded="true"], .ag-attach-btn:focus-visible { color: var(--accent); }

/* ---------- Server file picker ---------- */
.file-picker { width: min(620px, calc(100vw - 24px)); height: min(78dvh, 640px); flex-direction: column; }
.file-picker.closing { animation: ui-select-out 140ms var(--ease) forwards; }
.fp-bar { display: flex; align-items: center; gap: 4px; padding: 10px 14px 6px; }
.fp-path { flex: 1; min-width: 0; padding: 6px 10px; border-radius: 8px; background: var(--surface-2);
    font: 12.5px var(--font-mono, ui-monospace, monospace); color: var(--text-2);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: rtl; text-align: left; }
.fp-filter { display: flex; align-items: center; gap: 8px; margin: 4px 14px 8px; padding: 0 10px; height: 38px;
    border: 1px solid var(--border); border-radius: 10px; background: var(--bg, var(--surface)); color: var(--text-2);
    transition: border-color 140ms, box-shadow 140ms; }
.fp-filter:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.fp-filter input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 15px; }
.fp-list { flex: 1; min-height: 0; overflow-y: auto; padding: 2px 8px 8px; outline: none; }
.fp-item {
    position: relative; display: flex; align-items: center; gap: 12px; width: 100%; min-height: 48px; padding: 6px 10px;
    border: 1px solid transparent; border-radius: 10px; background: transparent; color: var(--text); text-align: left; cursor: pointer;
    transition: background 120ms, border-color 120ms, transform 120ms;
}
.fp-item:hover { background: var(--surface-2); }
.fp-item:active { transform: scale(0.99); }
.fp-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.fp-item.selected { background: color-mix(in srgb, var(--accent) 14%, transparent); border-color: color-mix(in srgb, var(--accent) 55%, transparent); }
.fp-icon { position: relative; display: grid; place-items: center; width: 36px; height: 36px; flex: none; border-radius: 8px;
    background: var(--surface-2); color: var(--text-2); overflow: hidden; }
.fp-item.dir .fp-icon { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.fp-icon img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.fp-name { flex: 1; min-width: 0; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fp-meta { flex: none; font-size: 12px; color: var(--text-2); display: flex; align-items: center; }
.fp-check { display: grid; place-items: center; width: 20px; height: 20px; flex: none; border-radius: 6px;
    border: 1.5px solid var(--border); color: transparent; transition: background 120ms, border-color 120ms, color 120ms, transform 160ms var(--ease); }
.fp-item.selected .fp-check { background: var(--accent); border-color: var(--accent); color: #fff; transform: scale(1.08); }
.fp-empty { padding: 32px 16px; text-align: center; color: var(--text-2); font-size: 13.5px; display: flex; gap: 8px; justify-content: center; align-items: center; }
.fp-empty .icon { animation: ag-spin 0.9s linear infinite; }
.fp-empty.error { color: var(--danger); }
.fp-footer { display: flex; align-items: center; gap: 8px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); }
.fp-count { flex: 1; font-size: 12px; color: var(--text-2); }
@media (max-width: 640px) {
    .file-picker { width: 100vw; max-width: 100vw; height: 86dvh; margin: auto 0 0; border-radius: 16px 16px 0 0; }
}

/* ---------- Agent composer: "modo fila" ---------- */
.ag-queue { margin: 0 0 8px; padding: 8px 8px 6px; border: 1px dashed color-mix(in srgb, var(--accent) 55%, var(--border));
    border-radius: var(--radius-md); background: color-mix(in srgb, var(--accent) 6%, var(--surface)); animation: pop-in 160ms var(--ease); }
.ag-queue-head { display: flex; align-items: center; gap: 6px; padding: 0 4px 6px; font-size: 12px; font-weight: 600; color: var(--accent); }
.ag-queue-head span { margin-left: auto; font-weight: 400; color: var(--text-3); }
.ag-queue-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; max-height: 168px; overflow-y: auto; }
.ag-queue-item { display: flex; align-items: center; gap: 8px; min-height: 36px; padding: 2px 2px 2px 6px; border-radius: 8px; background: var(--surface);
    animation: pop-in 160ms var(--ease); }
.ag-queue-n { display: grid; place-items: center; width: 20px; height: 20px; flex: none; border-radius: 50%;
    background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); font-size: 11px; font-weight: 700; }
.ag-queue-text { flex: 1; min-width: 0; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-queue-text em { font-style: normal; color: var(--text-2); font-size: 12px; display: inline-flex; align-items: center; gap: 2px; }
.ag-queue-item .icon-btn { width: 30px; height: 30px; flex: none; }
.ag-send.queue { background: color-mix(in srgb, var(--accent) 70%, var(--surface-3)); }
.ag-send.queue::after { content: '+'; position: absolute; right: 6px; top: 3px; font-size: 12px; font-weight: 800; }
.ag-send { position: relative; }

/* ---------- Agent chat: Markdown, code blocks, tables, callouts ---------- */
.ag-assistant { font-size: 15px; line-height: 1.65; }
.md p { margin: 0 0 12px; }
.md strong { font-weight: 650; }
.md h3, .md h4, .md h5, .md h6 { margin: 20px 0 8px; line-height: 1.35; font-weight: 650; letter-spacing: -0.005em; }
.md .md-h1 { font-size: 20px; }
.md .md-h2 { font-size: 17.5px; }
.md .md-h3 { font-size: 15.5px; }
.md .md-h4, .md .md-h5, .md .md-h6 { font-size: 14.5px; color: var(--text-2); }
.md ul, .md ol { margin: 0 0 12px; padding-left: 24px; }
.md li { margin: 4px 0; padding-left: 2px; }
.md li::marker { color: var(--text-3); }
.md ol > li::marker { font-variant-numeric: tabular-nums; font-weight: 600; }
.md a { color: var(--accent); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent); text-underline-offset: 3px; transition: text-decoration-color 140ms; }
.md a:hover { text-decoration-color: var(--accent); }
.md a[target="_blank"]::after { content: "\2197"; font-size: 0.75em; margin-left: 2px; opacity: 0.7; }
.md :not(pre) > code {
    padding: 2px 6px; border-radius: 6px; background: var(--surface-2); border: 1px solid color-mix(in srgb, var(--text) 10%, transparent);
    font-family: var(--font-mono, ui-monospace, monospace); font-size: 0.86em; overflow-wrap: anywhere;
}
.md blockquote { margin: 0 0 12px; padding: 4px 14px; border-left: 3px solid color-mix(in srgb, var(--accent) 50%, var(--border)); color: var(--text-2); }
.md hr { border: 0; height: 1px; background: linear-gradient(90deg, transparent, var(--border), transparent); margin: 18px 0; }
.md-task { display: inline-grid; place-items: center; width: 17px; height: 17px; margin-right: 4px; border-radius: 5px; border: 1.5px solid var(--border); font-size: 11px; vertical-align: -3px; color: transparent; cursor: default; }
.md-task.done { background: var(--c-green); border-color: var(--c-green); color: var(--bg, #000); }

/* streaming caret */
.ag-assistant.streaming > :last-child:not(.md-code):not(.md-table)::after,
.ag-assistant.streaming:empty::after {
    content: ""; display: inline-block; width: 8px; height: 1.05em; margin-left: 3px; vertical-align: -0.15em;
    border-radius: 2px; background: var(--accent); animation: md-caret 1s steps(2, start) infinite;
}
@keyframes md-caret { to { visibility: hidden; } }

/* code block */
.md-code {
    position: relative; margin: 4px 0 14px; border: 1px solid var(--border); border-radius: 12px; overflow: clip;
    background: color-mix(in srgb, var(--surface) 70%, var(--bg, #000));
}
.md-code-head {
    position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 6px 0 12px;
    background: color-mix(in srgb, var(--surface-2) 85%, transparent); backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border); font-size: 12px; color: var(--text-2);
}
.md-code-lang { display: inline-flex; align-items: center; gap: 6px; min-width: 0; font-weight: 600; }
.md-code-lang > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-mono, ui-monospace, monospace); font-size: 12px; }
.md-code-lang em { font-style: normal; font-weight: 400; color: var(--text-3); }
.md-code-lang .icon { color: var(--accent); flex: none; }
.md-code-writing { font-size: 11.5px; color: var(--accent); animation: md-pulse 1.4s ease-in-out infinite; }
@keyframes md-pulse { 50% { opacity: 0.35; } }
.md-code-actions { margin-left: auto; display: flex; align-items: center; gap: 2px; }
.md-code-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 5px; height: 28px; min-width: 28px; padding: 0 7px;
    border: 0; border-radius: 7px; background: transparent; color: var(--text-2); font: 600 12px var(--font, inherit); cursor: pointer;
    transition: background 120ms, color 120ms, transform 120ms, opacity 140ms;
}
.md-code-btn:hover { background: var(--surface-3); color: var(--text); }
.md-code-btn:active { transform: scale(0.94); }
.md-code-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.md-code-btn[aria-pressed="true"] { color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.md-code-btn.copied { color: var(--c-green); }
.md-code-btn.copied .icon { animation: md-pop 260ms var(--ease, ease-out); }
.md-code-btn.copy-failed { color: var(--danger); }
@keyframes md-pop { 0% { transform: scale(0.5); } 70% { transform: scale(1.2); } }
.md-code pre { margin: 0; padding: 14px 16px; overflow-x: auto; font-size: 13px; line-height: 1.6; tab-size: 4; }
.md-code code { font-family: var(--font-mono, ui-monospace, monospace); background: none; padding: 0; border: 0; font-size: inherit; }
.md-code.wrap pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.md-code.streaming { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.md-code.long:not(.expanded) pre { max-height: 420px; overflow-y: hidden;
    mask-image: linear-gradient(180deg, #000 70%, transparent); -webkit-mask-image: linear-gradient(180deg, #000 70%, transparent); }
.md-code-more {
    display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%; height: 36px; border: 0; border-top: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface-2) 60%, transparent); color: var(--text-2); font: 600 12.5px var(--font, inherit); cursor: pointer;
}
.md-code-more:hover { color: var(--accent); background: var(--surface-2); }
@media (hover: hover) {
    .md-code .md-code-btn:not(.md-code-copy):not([aria-pressed="true"]) { opacity: 0; }
    .md-code:hover .md-code-btn, .md-code:focus-within .md-code-btn { opacity: 1; }
}
@media (max-width: 600px) { .md-code-copy span { display: none; } .md-code pre { font-size: 12.5px; padding: 12px; } }

/* syntax colors (highlight.js classes) from the theme palette */
.hljs-comment, .hljs-quote { color: var(--text-3); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-doctag { color: var(--c-purple); }
.hljs-string, .hljs-regexp, .hljs-meta .hljs-string { color: var(--c-green); }
.hljs-number, .hljs-symbol, .hljs-bullet, .hljs-variable.constant_ { color: var(--c-orange); }
.hljs-title, .hljs-title.function_, .hljs-section, .hljs-name { color: var(--c-blue); }
.hljs-title.class_, .hljs-type, .hljs-built_in, .hljs-selector-class { color: var(--c-yellow); }
.hljs-attr, .hljs-attribute, .hljs-property, .hljs-selector-id, .hljs-variable, .hljs-template-variable, .hljs-params { color: var(--c-cyan); }
.hljs-tag, .hljs-meta, .hljs-selector-pseudo, .hljs-punctuation { color: var(--text-2); }
.hljs-meta .hljs-keyword { color: var(--c-purple); }
.hljs-addition, .hljs-deletion { display: inline-block; width: 100%; }
.hljs-addition { color: var(--c-green); background: color-mix(in srgb, var(--c-green) 10%, transparent); }
.hljs-deletion { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 700; }
.hljs-link { text-decoration: underline; }

/* tables */
.md-table { position: relative; margin: 4px 0 14px; overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; }
.md table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.md th, .md td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.md th { background: var(--surface-2); font-weight: 650; font-size: 12.5px; color: var(--text-2); white-space: nowrap; }
.md tbody tr:last-child td { border-bottom: 0; }
.md tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--surface) 50%, transparent); }
.md tbody tr:hover td { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.md td + td, .md th + th { border-left: 1px solid color-mix(in srgb, var(--border) 60%, transparent); }
.md-table-copy { position: absolute; top: 5px; right: 6px; z-index: 2; background: var(--surface); box-shadow: 0 0 0 1px var(--border); }
@media (hover: hover) { .md-table-copy { opacity: 0; } .md-table:hover .md-table-copy, .md-table:focus-within .md-table-copy { opacity: 1; } }
.md-table-copy span { display: none; }
.md-table-copy.copied span { display: inline; }

/* GitHub callouts */
.md-callout { --c: var(--c-blue); margin: 4px 0 14px; padding: 10px 14px; border-radius: 10px; border: 1px solid color-mix(in srgb, var(--c) 40%, transparent);
    background: color-mix(in srgb, var(--c) 8%, transparent); }
.md-callout.tip { --c: var(--c-green); }
.md-callout.important { --c: var(--c-purple); }
.md-callout.warning { --c: var(--c-yellow); }
.md-callout.caution { --c: var(--danger); }
.md-callout-title { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; font-size: 13px; font-weight: 700; color: var(--c); }
.md-callout > :last-child { margin-bottom: 0; }

/* images inside answers */
.md-img { display: inline-block; max-width: min(100%, 520px); margin: 4px 0; padding: 0; border: 1px solid var(--border); border-radius: 12px;
    overflow: hidden; background: var(--surface-2); cursor: zoom-in; vertical-align: top; transition: transform 160ms var(--ease, ease-out), box-shadow 160ms; }
.md-img:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25); }
.md-img img { display: block; max-width: 100%; height: auto; }

/* actions under an answer */
.ag-msg-actions { display: flex; gap: 4px; margin-top: -6px; }
.ag-msg-btn { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 9px; border: 0; border-radius: 8px;
    background: transparent; color: var(--text-3); font: 600 12px var(--font, inherit); cursor: pointer; transition: background 120ms, color 120ms; }
.ag-msg-btn:hover { background: var(--surface-2); color: var(--text); }
.ag-msg-btn.copied { color: var(--c-green); }

/* tool output / command copy */
.pre-box { position: relative; }
.pre-box .pre-copy { position: absolute; top: 4px; right: 4px; background: var(--surface); box-shadow: 0 0 0 1px var(--border); }
@media (hover: hover) { .pre-box .pre-copy { opacity: 0; } .pre-box:hover .pre-copy { opacity: 1; } }
.ag-cmd { display: flex; align-items: flex-start; gap: 6px; }
.ag-cmd code { flex: 1; min-width: 0; font: inherit; white-space: pre-wrap; overflow-wrap: anywhere; }
.ag-cmd .md-code-btn { height: 24px; min-width: 24px; margin: -3px -4px 0 0; }

@media (prefers-reduced-motion: reduce) {
    .ag-assistant.streaming > :last-child::after, .md-code-writing, .md-code-btn.copied .icon { animation: none; }
}

/* =========================================================
   Notes tab (public/managers/notesSession.js)
   ========================================================= */
.terminal-panel.notes-panel { padding: 0; touch-action: auto; background: var(--bg); }
.tab.notes .tab-dot { border-radius: 2px; clip-path: polygon(0 0, 100% 0, 100% 70%, 70% 100%, 0 100%); }
.nt { position: absolute; inset: 0; display: flex; overflow: hidden; }
.nt-side {
    width: 320px; flex-shrink: 0; display: flex; flex-direction: column; min-height: 0;
    background: var(--surface); border-right: 1px solid var(--border);
}
/* Narrow desktop/tablet windows (720-980px): the fixed 320px list leaves too little room for the editor */
@media (min-width: 720px) and (max-width: 980px) {
    .nt-side { width: 260px; }
}
.nt-main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }

.nt-toolbar { flex-shrink: 0; display: flex; align-items: center; gap: 2px; padding: 8px; border-bottom: 1px solid var(--border); }
.nt-search { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding-left: 8px; color: var(--text-3); }
.nt-search input {
    flex: 1; min-width: 0; height: 36px; padding: 0 12px; border: 1.5px solid var(--border); border-radius: var(--radius);
    background: var(--input-bg); color: var(--text); font-size: 14px; outline: none;
}
.nt-search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.nt-toolbar .icon-btn.on, .nt-ehead .icon-btn.on { color: var(--accent); background: var(--accent-soft); }

.nt-tags { flex-shrink: 0; display: flex; gap: 6px; padding: 8px 10px; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--divider); }
.nt-tags::-webkit-scrollbar { display: none; }
.nt-tags[hidden], .nt-trashbar[hidden] { display: none; }
.nt-chip {
    flex-shrink: 0; display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 99px;
    border: 1.5px solid var(--border); background: var(--bg); color: var(--text-2); font-size: 12.5px; font-weight: 500;
}
.nt-chip small { color: var(--text-3); font-size: 11.5px; }
.nt-chip:hover { color: var(--text); border-color: var(--border-strong); }
.nt-chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.nt-trashbar {
    flex-shrink: 0; display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 14px;
    background: var(--accent-soft); font-size: 13px; color: var(--text-2);
}
.nt-trashbar span { flex: 1; min-width: 0; }

/* overflow-x: hidden is load-bearing - with only overflow-y set, the CSS spec forces the other axis to
   "auto" too, so the list becomes horizontally scrollable and can get stuck scrolled right (every row's
   text then looks cut off by the same amount on the left, which is what the "vazando pro lado" bug was). */
.nt-list { flex: 1; min-height: 0; margin: 0; padding: 6px; list-style: none; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
/* .nt-row just clips; .nt-row-fg is what actually slides over the swipe actions underneath - its
   background must stay fully opaque for that to work, so "selected" uses an opaque mix instead of
   the translucent --accent-soft (which let the solid pin/trash buttons bleed straight through). */
.nt-row { position: relative; border-radius: var(--radius-md); overflow: hidden; }
.nt-row-fg { position: relative; z-index: 1; display: flex; align-items: stretch; background: var(--surface); border-radius: var(--radius-md); transition: transform 0.2s ease; }
.nt-row-fg.dragging { transition: none; }
.nt-row:hover .nt-row-fg { background: var(--surface-2); }
.nt-row.selected .nt-row-fg { background: color-mix(in srgb, var(--accent) 16%, var(--surface)); }
.nt-item { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; padding: 10px 4px 10px 12px; text-align: left; color: var(--text); }
.nt-item-title { font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nt-item-title em { font-weight: 500; font-style: normal; color: var(--text-3); }
.nt-pin { display: inline-grid; vertical-align: -1px; margin-right: 4px; color: var(--accent); }
.nt-item-preview { font-size: 13px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nt-item-progress { display: flex; align-items: center; gap: 6px; }
.nt-item-bar { flex: 1; height: 4px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.nt-item-bar span { display: block; height: 100%; background: var(--accent); }
.nt-item-progress small { font-size: 10.5px; color: var(--text-3); white-space: nowrap; }
.nt-item-meta { font-size: 11.5px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nt-more { align-self: center; opacity: 0; flex-shrink: 0; }
.nt-row:hover .nt-more, .nt-more:focus-visible, .nt-row.selected .nt-more { opacity: 1; }
.nt-none { padding: 32px 16px; text-align: center; color: var(--text-3); font-size: 14px; list-style: none; }
/* Shown only while the first GET /api/notes of the session is in flight, so a slow network doesn't
   flash "Você ainda não tem anotações" before any response has arrived. */
.nt-skel {
    height: 64px; margin: 4px 6px; border-radius: var(--radius-md); list-style: none;
    background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%);
    background-size: 400% 100%; animation: nt-shimmer 1.4s ease infinite;
}
@keyframes nt-shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
@media (prefers-reduced-motion: reduce) { .nt-skel { animation: none; } }

/* Swipe-to-reveal (phones only - bindSwipe() in notesSession.js no-ops on a mouse pointer) */
.nt-swipe-actions { position: absolute; top: 0; bottom: 0; width: 72px; display: flex; }
.nt-swipe-right { left: 0; justify-content: flex-start; }
.nt-swipe-left { right: 0; justify-content: flex-end; }
.nt-swipe-btn { flex: 1; border: 0; display: flex; align-items: center; justify-content: center; color: #fff; }
.nt-swipe-pin, .nt-swipe-restore { background: var(--accent); }
.nt-swipe-trash, .nt-swipe-purge { background: var(--danger); }

.nt-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 24px; color: var(--text-3); text-align: center; }
.nt-empty[hidden], .nt-editor[hidden], .nt-conflict[hidden] { display: none; }
.nt-empty p { margin: 0; color: var(--text-2); }

.nt-editor { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.nt-ehead { flex-shrink: 0; display: flex; align-items: center; gap: 2px; padding: 6px 8px; border-bottom: 1px solid var(--border); background: var(--surface); }
.nt-back { display: none; }
.nt-status { flex: 1; min-width: 0; padding: 0 8px; font-size: 12.5px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nt-conflict {
    flex-shrink: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 12px;
    background: var(--danger-bg); color: var(--text); font-size: 13.5px;
}
.nt-conflict span { flex: 1 1 200px; }
.nt-title {
    flex-shrink: 0; width: 100%; padding: 16px 20px 6px; border: 0; background: transparent; color: var(--text);
    font-size: 22px; font-weight: 700; outline: none;
}
.nt-title::placeholder, .nt-tags-input::placeholder { color: var(--text-3); font-weight: 400; }
.nt-tagsline { flex-shrink: 0; display: flex; align-items: center; gap: 8px; padding: 0 20px 10px; color: var(--text-3); border-bottom: 1px solid var(--divider); }
.nt-tags-input { flex: 1; min-width: 0; border: 0; background: transparent; color: var(--text-2); font-size: 13.5px; outline: none; padding: 4px 0; }
.nt-title:read-only { opacity: 0.75; }

/* Single Tiptap block: you write where you read, Notion-style (no edit/preview split). */
.nt-write { flex: 1; min-height: 0; min-width: 0; display: flex; overflow-y: auto; overflow-x: hidden; }
.nt-doc-wrap { position: relative; flex: 1; min-width: 0; max-width: 780px; margin: 0 auto; padding: 14px 20px 24px 42px; }
.nt-doc-wrap.readonly { opacity: 0.75; }
.nt-doc .ProseMirror { outline: none; color: var(--text); font-size: 15px; line-height: 1.65; overflow-wrap: anywhere; min-height: 200px; }
.nt-doc .ProseMirror > * + * { margin-top: 10px; }
.nt-doc .ProseMirror h1, .nt-doc .ProseMirror h2, .nt-doc .ProseMirror h3 { font-weight: 650; letter-spacing: -0.005em; line-height: 1.35; }
.nt-doc .ProseMirror h1 { font-size: 22px; }
.nt-doc .ProseMirror h2 { font-size: 19px; }
.nt-doc .ProseMirror h3 { font-size: 16.5px; color: var(--text-2); }
.nt-doc .ProseMirror p { margin: 0; }
.nt-doc .ProseMirror strong { font-weight: 650; }
.nt-doc .ProseMirror ul, .nt-doc .ProseMirror ol { margin: 0; padding-left: 24px; }
.nt-doc .ProseMirror li { margin: 4px 0; padding-left: 2px; }
.nt-doc .ProseMirror li::marker { color: var(--text-3); }
.nt-doc .ProseMirror ol > li::marker { font-variant-numeric: tabular-nums; font-weight: 600; }
.nt-doc .ProseMirror a { color: var(--accent); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent); text-underline-offset: 3px; }
.nt-doc .ProseMirror :not(pre) > code {
    background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px;
    padding: 1px 5px; font: 13px/1.4 var(--font-mono); color: var(--text);
}
.nt-doc .ProseMirror pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 12px 14px; overflow-x: auto; }
.nt-doc .ProseMirror pre code { background: none; border: 0; padding: 0; font: 13px/1.55 var(--font-mono); }
.nt-doc .ProseMirror blockquote { margin: 0; padding: 4px 14px; border-left: 3px solid color-mix(in srgb, var(--accent) 50%, var(--border)); color: var(--text-2); }
.nt-doc .ProseMirror hr { border: 0; height: 1px; background: linear-gradient(90deg, transparent, var(--border), transparent); margin: 6px 0; }
.nt-doc .ProseMirror table { border-collapse: collapse; width: 100%; table-layout: fixed; margin: 0; overflow: hidden; }
.nt-doc .ProseMirror th, .nt-doc .ProseMirror td { border: 1px solid var(--border); padding: 7px 10px; vertical-align: top; text-align: left; position: relative; min-width: 1em; }
.nt-doc .ProseMirror th { background: var(--surface-2); font-weight: 650; }
.nt-doc .ProseMirror td > p, .nt-doc .ProseMirror th > p { margin: 0; }
.nt-doc .ProseMirror .selectedCell::after { content: ""; position: absolute; inset: 0; background: color-mix(in srgb, var(--accent) 18%, transparent); pointer-events: none; }
.nt-doc .ProseMirror .tableWrapper {
    overflow-x: auto;
    /* fade on each edge while there is more to scroll; disappears on its own once fully scrolled (background-attachment:local) */
    background:
        linear-gradient(to right, var(--bg) 0%, transparent 24px) left no-repeat local,
        linear-gradient(to left, var(--bg) 0%, transparent 24px) right no-repeat local;
    background-size: 24px 100%, 24px 100%;
}
.nt-doc .ProseMirror img { max-width: 100%; border-radius: var(--radius-md); display: block; }
.nt-doc .ProseMirror ul[data-type="taskList"] { list-style: none; padding-left: 2px; }
.nt-doc .ProseMirror ul[data-type="taskList"] li { display: flex; align-items: flex-start; gap: 8px; }
.nt-doc .ProseMirror ul[data-type="taskList"] li > label { margin-top: 3px; flex-shrink: 0; }
.nt-doc .ProseMirror ul[data-type="taskList"] li > div { flex: 1; min-width: 0; }
.nt-doc .ProseMirror ul[data-type="taskList"] input[type="checkbox"] { width: 16px; height: 16px; border-radius: 5px; accent-color: var(--accent); cursor: pointer; }
.nt-doc .ProseMirror p.is-editor-empty:first-child::before {
    content: attr(data-placeholder); float: left; height: 0; pointer-events: none; color: var(--text-3);
}
/* A block being dragged, and the block the drag is hovering over */
.nt-doc .ProseMirror .nt-drag-source { opacity: 0.4; }
.nt-doc .ProseMirror .nt-drag-target { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }

/* Grip in the left gutter, tracking whichever line the mouse is over (top/height set in JS). */
.nt-draghandle {
    position: absolute; left: 4px; width: 26px; display: flex; align-items: center; justify-content: center;
    cursor: grab; border-radius: 6px; color: var(--text-3); background: transparent; border: 0;
}
.nt-draghandle:hover { background: var(--surface-2); color: var(--text-2); }
.nt-draghandle:active { cursor: grabbing; }
.nt-draghandle[hidden] { display: none; }

/* Floating formatting bar: a card docked under the write area (desktop), or pinned above the
   on-screen keyboard on mobile (positioned in JS from visualViewport). */
.nt-fbar {
    flex-shrink: 0; margin: 0 20px 14px; padding: 8px; border-radius: var(--radius-md);
    background: var(--surface); border: 1.5px solid var(--border-strong); box-shadow: var(--shadow);
}
.nt-fbar[hidden] { display: none; }
.nt-fbar-row {
    display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none;
    /* fade on each edge while there is more to scroll; disappears on its own once fully scrolled */
    background:
        linear-gradient(to right, var(--surface) 0%, transparent 20px) left no-repeat local,
        linear-gradient(to left, var(--surface) 0%, transparent 20px) right no-repeat local;
    background-size: 20px 100%, 20px 100%;
}
.nt-fbar-row::-webkit-scrollbar { display: none; }
.nt-fbtn { flex-shrink: 0; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; color: var(--text-2); }
.nt-fbtn:hover, .nt-fbtn:focus-visible { background: var(--surface-2); color: var(--text); }
.nt-fbtn:active, .nt-fbtn.on { background: var(--accent-soft); color: var(--accent); }
.nt-fbtn-text { width: 38px; font-size: 13.5px; font-weight: 700; letter-spacing: -0.02em; }
.nt-fsep { margin-left: 6px; position: relative; }
.nt-fsep::before { content: ''; position: absolute; left: -4px; top: 9px; bottom: 9px; width: 1px; background: var(--border); }
.nt-fs { display: none; }
/* Mobile only: the "+" that opens the same "/" insert menu, replacing the headings/quote/table
   buttons that get hidden there (.nt-fbtn-extra) to keep the always-visible row short. */
.nt-fbtn-plus { display: none; }
.nt-tbar { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border); }
.nt-tbar[hidden] { display: none; }
.nt-tbtn { flex-shrink: 0; height: 32px; padding: 0 10px; border-radius: 8px; font-size: 12.5px; white-space: nowrap; color: var(--text-2); background: var(--surface-2); }
.nt-tbtn:hover, .nt-tbtn:focus-visible { color: var(--text); background: var(--accent-soft); }
.nt-tbtn.danger:hover, .nt-tbtn.danger:focus-visible { color: var(--danger, #e5484d); background: color-mix(in srgb, var(--danger, #e5484d) 14%, transparent); }

/* "/" command palette, shown above the toolbar row inside the same floating card */
.nt-slash { list-style: none; margin: 0 0 6px; padding: 4px; max-height: 240px; overflow-y: auto; overflow-x: hidden; border-bottom: 1px solid var(--divider); }
.nt-slash[hidden] { display: none; }
.nt-slash li { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; font-size: 13.5px; color: var(--text); cursor: pointer; }
.nt-slash li .icon { color: var(--text-3); flex-shrink: 0; }
.nt-slash li.active, .nt-slash li:hover { background: var(--accent-soft); color: var(--accent); }
.nt-slash li.active .icon, .nt-slash li:hover .icon { color: var(--accent); }

.nt-fab {
    position: absolute; right: 18px; bottom: 18px; z-index: 5; width: 56px; height: 56px; display: none; place-items: center;
    border-radius: 50%; background: var(--accent); color: var(--accent-fg); border: 1.5px solid var(--shadow-color); box-shadow: var(--shadow);
    transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.nt-fab:active { transform: translate(4px, 4px); box-shadow: 0 0 0 0 var(--shadow-color); }

/* Phones: one pane at a time (list, then the note on top of it) */
@media (max-width: 719px) {
    .nt-side { width: 100%; border-right: 0; }
    .nt-main { position: absolute; inset: 0; z-index: 2; background: var(--bg); }
    .nt[data-pane="list"] .nt-main { display: none; }
    .nt[data-pane="editor"] .nt-side, .nt[data-pane="editor"] .nt-fab { display: none; }
    .nt[data-pane="list"] .nt-fab { display: grid; }
    .nt-back { display: inline-grid; }
    .nt-more { opacity: 1; width: 44px; height: 44px; }
    .nt-toolbar [data-act="new"] { display: none; }
    .nt-search input { font-size: 16px; }
    .nt-title { font-size: 20px; padding: 14px 16px 6px; }
    .nt-tagsline { padding: 0 16px 10px; }
    .nt-tags-input { font-size: 16px; }
    .nt-doc .ProseMirror { font-size: 16px; }
    .nt-fbar {
        position: fixed; left: 0; right: 0; bottom: 0; margin: 0; padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
        border-width: 1.5px 0 0; border-radius: var(--radius-md) var(--radius-md) 0 0; z-index: 30;
    }
    .nt-fbtn { width: 44px; height: 44px; }
    .nt-fbtn-text { width: 46px; }
    .nt-fsep::before { top: 11px; bottom: 11px; }
    .nt-tbar { margin-top: 4px; padding-top: 4px; }
    .nt-tbtn { height: 44px; padding: 0 14px; font-size: 13.5px; }
    .nt-slash { max-height: 34dvh; }
    /* the bar floats over the note: keep the last lines reachable above it */
    .nt-write { padding-bottom: var(--nt-fbar-h, 0px); scroll-padding-bottom: var(--nt-fbar-h, 0px); }
    .nt-doc-wrap { padding: 10px 16px 24px; }
    .nt-ehead { padding: 4px 6px; }
    .nt-fs { display: inline-grid; }
    .nt-fbtn-extra { display: none; }
    .nt-fbtn-plus { display: grid; }
    /* full screen: the note covers the whole screen (tabs and menus included) */
    .nt.nt-full .nt-main { position: fixed; inset: 0; z-index: 80; height: 100dvh; padding-top: env(safe-area-inset-top); }
    /* the formatting bar reserves its own safe-area-bottom (.nt-fbar above) while it's open; only add it
       here when the bar is hidden (no note focused), so the inset isn't counted twice */
    .nt.nt-full:not(.nt-bar-open) .nt-main { padding-bottom: env(safe-area-inset-bottom); }
    .nt.nt-full .nt-tagsline { display: none; }
    .nt.nt-full .nt-title { font-size: 18px; padding: 8px 16px 4px; }
    /* conflict banner: stack full-width, each button a proper touch target, instead of wrapping mid-sentence */
    .nt-conflict { flex-direction: column; align-items: stretch; }
    .nt-conflict .btn-sm { min-height: 44px; width: 100%; justify-content: center; }
    /* tables scroll sideways instead of squeezing the columns */
    .nt-doc .ProseMirror table { table-layout: auto; width: max-content; min-width: 100%; }
    .nt-doc .ProseMirror th, .nt-doc .ProseMirror td { min-width: 110px; }
}

/* =========================================================
   /admin page (public/admin/*)
   ========================================================= */
.page-admin { background: var(--bg); }
/* height (not min-height): .admin-main below must be capped to the viewport to scroll its own
   content - body has overflow:hidden, so letting .admin grow taller than the screen just clips it. */
.admin { height: 100dvh; display: flex; flex-direction: column; }
.admin-topbar {
    flex-shrink: 0; height: 56px; display: flex; align-items: center; gap: 8px; padding: 0 16px;
    border-bottom: 1px solid var(--border); background: var(--surface);
}
.admin-topbar .brand { display: flex; padding: 0; }
.admin-topbar .brand-icon {
    width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; flex: none;
    background: var(--accent); color: var(--accent-fg); border: 1.5px solid var(--shadow-color); box-shadow: 2px 2px 0 0 var(--shadow-color);
}
.admin-nav-toggle { margin-left: auto; }
@media (min-width: 900px) { .admin-nav-toggle { display: none; } }

.admin-body { flex: 1; min-height: 0; display: flex; }
.admin-nav { flex-shrink: 0; width: 240px; border-right: 1px solid var(--border); background: var(--surface); overflow-y: auto; }
.admin-nav ul { list-style: none; margin: 0; padding: 10px; display: flex; flex-direction: column; gap: 2px; }
.admin-nav a {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--radius-md);
    color: var(--text-2); font-size: 14px; font-weight: 500; text-decoration: none;
}
.admin-nav a:hover { background: var(--surface-2); color: var(--text); }
.admin-nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.admin-main { flex: 1; min-width: 0; overflow-y: auto; }
.admin-page { max-width: 640px; margin: 0 auto; padding: 32px 24px 80px; }
.admin-page [data-page] { padding-top: 0; }
.admin-page [data-page][hidden] { display: none; }

@media (max-width: 899px) {
    .admin-nav {
        position: fixed; inset: 56px 0 0 0; z-index: 10; width: auto; transform: translateX(-100%);
        transition: transform var(--dur) var(--ease);
    }
    .admin-nav.open { transform: none; }
    .admin-page { padding: 20px 16px 80px; }
}

/* Backup section (admin-only: scripts/backup-store.js + backup-runner.js) */
.backup-status { margin-top: 16px; font-size: 13px; color: var(--text-2); }
.backup-history { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.backup-history-row {
    display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; padding: 9px 10px; border-radius: var(--radius-md);
    font-size: 12.5px; color: var(--text-2); background: var(--surface-2);
}
.backup-history-row span:last-child { text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.backup-history-row.error span:last-child { color: var(--danger); }
.backup-history-row.ok span:last-child { color: var(--success); }
.backup-history-empty { padding: 10px; color: var(--text-3); font-size: 13px; list-style: none; }

/* Webhooks section (admin-only: scripts/webhook-*.js, public/admin/webhooks.js) */
.wh-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.wh-rows { list-style: none; margin: 16px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.wh-row { display: flex; align-items: center; gap: 4px; border-radius: var(--radius-md); }
.wh-row:hover { background: var(--surface-2); }
.wh-row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; padding: 10px 10px; text-align: left; }
.wh-row-title { font-size: 14px; font-weight: 600; color: var(--text); }
.wh-off { display: inline-block; margin-right: 6px; padding: 1px 6px; border-radius: 999px; background: var(--surface-3); color: var(--text-3); font-size: 10.5px; font-weight: 700; text-transform: uppercase; }
.wh-row-meta { font-size: 12px; color: var(--text-3); }
.wh-preset-list { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.wh-preset { width: 100%; text-align: left; padding: 12px 14px; border-radius: var(--radius-md); background: var(--surface); border: 1.5px solid var(--border); display: flex; flex-direction: column; gap: 2px; }
.wh-preset:hover { border-color: var(--border-strong); background: var(--surface-2); }
.wh-preset b { font-size: 13.5px; }
.wh-preset small { color: var(--text-3); font-size: 12px; }

/* .ns-back is already styled (public/ui/newSession.js's "home" link) - reused here as-is */
.wh-tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--divider); margin-bottom: 18px; }
.wh-tabs::-webkit-scrollbar { display: none; }
.wh-tabs button { flex-shrink: 0; padding: 9px 12px; font-size: 13px; font-weight: 600; color: var(--text-3); border-bottom: 2px solid transparent; }
.wh-tabs button:hover { color: var(--text-2); }
.wh-tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }

.wh-input-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.wh-input-row { padding: 10px; border-radius: var(--radius-md); background: var(--surface-2); display: flex; flex-direction: column; gap: 6px; }
.wh-input-grid { display: grid; grid-template-columns: 1fr 1fr 110px 140px auto auto; gap: 6px; align-items: center; }
.wh-input-grid input, .wh-input-grid select { height: 34px; padding: 0 8px; border: 1.5px solid var(--border); border-radius: 8px; background: var(--input-bg); color: var(--text); font-size: 12.5px; }
.wh-input-check { display: flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--text-3); white-space: nowrap; }
.wh-input-row > input[data-wi="default"], .wh-input-row > input[data-wi="options"] {
    height: 32px; padding: 0 8px; border: 1.5px solid var(--border); border-radius: 8px; background: var(--input-bg); color: var(--text); font-size: 12.5px;
}
@media (max-width: 719px) { .wh-input-grid { grid-template-columns: 1fr 1fr; } }

.wh-token-list { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.wh-hmac-row { display: flex; gap: 8px; margin-top: 8px; }
.wh-hmac-row input { flex: 1; height: 36px; padding: 0 10px; border: 1.5px solid var(--border); border-radius: 8px; background: var(--input-bg); color: var(--text); }

.wh-output {
    margin-top: 14px; padding: 12px 14px; border-radius: var(--radius-md); background: var(--surface-2);
    font: 12.5px/1.6 var(--font-mono); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 320px; overflow-y: auto;
}
