/* MTR AI Panel: MTR Panel palette (same as the "Claude · MTR" terminal profile). */
:root {
  --bg: #081522; --surface: #0D2031; --surface-2: #102B41; --line: #214458; --line-soft: #173449;
  --text: #E4F2F9; --muted: #8FB3C9; --accent: #38DAF5; --accent-ink: #062030; --blue: #3B8CF0;
  --danger: #FF6B81; --warn: #F5B53F; --ok: #4ADE80; --purple: #A596EB;
  --radius: 12px; --mono: Consolas, "Cascadia Mono", "SFMono-Regular", monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 "Segoe UI", system-ui, sans-serif; display: flex; flex-direction: column; overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; min-height: 36px; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.link { background: none; border: 0; padding: 0 4px; min-height: 0; color: var(--accent); font-size: .85em; }
input, select, textarea { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-height: 36px; width: 100%; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
code, pre { font-family: var(--mono); font-size: .9em; }
[hidden] { display: none !important; }
.hint, .muted, .meta { color: var(--muted); font-size: .88em; }
.error-text { color: var(--danger); font-size: .9em; }
.error-text.note { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 14px; padding: 10px 18px; border-bottom: 1px solid var(--line); background: linear-gradient(180deg, #0D2031, #081522); flex: none; }
.logo { height: 22px; }
.product { font-family: var(--mono); color: var(--accent); letter-spacing: .14em; font-size: .78em; }
.project { display: flex; align-items: center; gap: 8px; margin-left: auto; color: var(--muted); font-size: .88em; }
.project select { width: auto; min-width: 220px; }
.connection { font-size: .82em; color: var(--muted); }
.connection.ok::before { content: "● "; color: var(--ok); }
.connection.bad::before { content: "● "; color: var(--danger); }
.mobile-tabs { display: none; gap: 6px; }

/* layout */
.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 290px minmax(0, 1fr) 340px; }
.side, .actions { border-right: 1px solid var(--line); padding: 14px; overflow: auto; overflow-x: hidden; min-height: 0; }
.actions { border-right: 0; border-left: 1px solid var(--line); display: flex; flex-direction: column; }
.side h2, .actions h2 { font-size: .8em; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); margin: 18px 0 8px; display: flex; align-items: center; justify-content: space-between; }
.actions h2 { margin-top: 0; }

.engine-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.engine-tabs [aria-selected="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.new-chat { margin-top: 12px; display: grid; gap: 8px; }
.new-chat label { display: grid; gap: 4px; font-size: .85em; color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.list .item { width: 100%; text-align: left; background: transparent; border-color: transparent; padding: 6px 8px; font-size: .9em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .item:hover { background: var(--surface); }
.list .item.active { background: var(--surface-2); border-color: var(--line); }
.when { color: var(--muted); font-size: .82em; margin-right: 4px; }
.badge { font-size: .72em; padding: 1px 6px; border-radius: 999px; border: 1px solid var(--line); }
.badge.claude { color: var(--accent); border-color: var(--accent); }
.badge.codex { color: var(--purple); border-color: var(--purple); }
.list .item .proj { color: var(--muted); font-size: .85em; }
.wait { font-size: .72em; padding: 1px 6px; border-radius: 999px; background: var(--warn); color: var(--accent-ink); font-weight: 600; }
body.opening [data-resume], body.opening .new-chat [type=submit] { cursor: progress; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--warn); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

/* chat */
.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-head { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--line-soft); }
.chat-title { min-width: 0; flex: 1 1 260px; }
.chat-title h1 { font-size: 1.05rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-title .meta { margin: 2px 0 0; }
.chat-tools { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.chat-tools select { width: auto; max-width: 190px; }
.transcript { flex: 1; overflow: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.transcript:focus-visible, .console:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.empty { margin: auto; max-width: 560px; color: var(--muted); text-align: center; }
.entry { max-width: 920px; width: 100%; margin: 0 auto; }
.entry.user { display: flex; justify-content: flex-end; }
.entry.user .bubble { background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px 14px 4px 14px; padding: 8px 12px; max-width: 80%; white-space: pre-wrap; overflow-wrap: anywhere; }
.entry.old { opacity: .62; }
.entry.sub { padding-left: 22px; border-left: 2px solid var(--line-soft); }
.entry.streaming .md { opacity: .9; }
.entry.cut .cut-note { margin: 4px 0 0; color: var(--muted); font-size: .8em; }
.entry.thinking details, .entry.tool details { border: 1px solid var(--line-soft); border-radius: 8px; background: var(--surface); }
.entry.thinking summary { color: var(--muted); font-size: .85em; padding: 4px 10px; cursor: pointer; }
.entry.thinking .md { padding: 0 12px 6px; color: var(--muted); font-size: .92em; }
.entry.tool summary { padding: 5px 10px; cursor: pointer; display: flex; gap: 8px; align-items: baseline; min-width: 0; }
.tool-name { color: var(--accent); font-weight: 600; font-size: .88em; flex: none; }
.tool-sum { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }
.tool-state { font-size: .78em; color: var(--muted); flex: none; }
.tool-state.ok { color: var(--ok); } .tool-state.bad { color: var(--danger); }
.tool-in, .tool-out, .entry pre { margin: 0; padding: 8px 10px; border-top: 1px solid var(--line-soft); max-height: 340px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; font-size: .82em; }
.tool-out { color: var(--muted); }
.entry.status p, .entry.divider p { color: var(--muted); font-size: .85em; margin: 0; text-align: center; }
.entry.divider p { border-top: 1px dashed var(--line); padding-top: 6px; }
.entry.error p { color: var(--danger); margin: 0; white-space: pre-wrap; }
.entry.result p { color: var(--muted); font-size: .8em; margin: 0; font-family: var(--mono); }
.entry.result.bad p { color: var(--danger); }

/* markdown */
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md p { margin: .5em 0; overflow-wrap: anywhere; }
.md h3, .md h4, .md h5, .md h6 { margin: .9em 0 .4em; font-size: 1em; color: var(--accent); }
.md h3 { font-size: 1.12em; }
.md code { background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: 5px; padding: 0 4px; }
.md pre.code { background: #06111C; border: 1px solid var(--line-soft); border-radius: 8px; padding: 10px 12px; overflow: auto; max-height: 480px; }
.md pre.code code { background: none; border: 0; padding: 0; }
.md ul, .md ol { margin: .4em 0; padding-left: 1.4em; }
.md blockquote { margin: .5em 0; padding: 2px 12px; border-left: 3px solid var(--line); color: var(--muted); }
.md a { color: var(--accent); } .md .ref { color: var(--accent); border-bottom: 1px dotted var(--accent); }
.md hr { border: 0; border-top: 1px solid var(--line); }
.table-wrap { overflow: auto; margin: .6em 0; }
.md table { border-collapse: collapse; font-size: .92em; }
.md th, .md td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; vertical-align: top; }
.md th { background: var(--surface-2); }

/* permission card */
.entry.permission { border: 1px solid var(--warn); background: rgba(245, 181, 63, .07); border-radius: var(--radius); padding: 10px 14px; }
.entry.permission.resolved { border-color: var(--line); background: transparent; opacity: .8; }
.perm-title { margin: 0 0 6px; overflow-wrap: anywhere; }
.perm-title code { white-space: pre-wrap; }
.perm-status { margin: 6px 0 0; color: var(--muted); font-size: .88em; }
.perm-rules { margin: 6px 0 0; color: var(--muted); font-size: .85em; overflow-wrap: anywhere; }
.perm-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.perm-actions .deny-reason { flex: 1; min-width: 160px; width: auto; }
.entry.permission details summary { cursor: pointer; color: var(--muted); font-size: .85em; }
.entry.permission fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 6px 0; }
.entry.permission legend { padding: 0 6px; font-weight: 600; }
.opt { display: flex; gap: 8px; align-items: flex-start; padding: 4px 0; }
.opt input[type=radio], .opt input[type=checkbox] { width: auto; min-height: 0; margin-top: 4px; }
.opt.other { flex-direction: column; gap: 4px; }
.plan { background: var(--surface); border-radius: 8px; padding: 8px 12px; }

/* composer */
.composer { border-top: 1px solid var(--line-soft); padding: 12px 18px; display: grid; gap: 8px; }
.composer-target { margin: 0; padding: 2px 8px; border-left: 3px solid var(--accent); color: var(--muted); font-size: .85em; overflow-wrap: anywhere; }
.composer-target b { color: var(--text); }
.composer textarea { resize: vertical; min-height: 64px; max-height: 40vh; }
.composer-row { display: flex; align-items: center; gap: 12px; }
.composer-row .error-text { flex: 1; }
.busy { color: var(--warn); font-size: .88em; }
.busy::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--warn); margin-right: 6px; animation: pulse 1.2s infinite; }
#send { margin-left: auto; min-width: 110px; }

/* actions */
.action-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 10px 0; }
.console-head { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .85em; margin-top: 6px; }
.console-head span { flex: 1; }
.console { flex: 1; min-height: 200px; margin: 6px 0 0; background: #050E17; border: 1px solid var(--line-soft); border-radius: 8px; padding: 8px 10px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; font-size: .8em; }
.console .meta { color: var(--accent); } .console .err { color: var(--warn); } .console .done.ok { color: var(--ok); } .console .done.bad { color: var(--danger); }

/* narrow screens: one column at a time */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 260px minmax(0, 1fr); }
  .layout .actions { display: none; }
  .layout[data-view="actions"] .actions { display: flex; grid-column: 2; }
  .layout[data-view="actions"] .chat { display: none; }
  .mobile-tabs { display: flex; }
  .mobile-tabs [data-view="side"] { display: none; }
  .mobile-tabs [aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
}
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; padding: 8px 12px; gap: 8px; }
  .project { margin-left: 0; width: 100%; } .project select { flex: 1; min-width: 0; }
  .mobile-tabs { width: 100%; } .mobile-tabs button { flex: 1; } .mobile-tabs [data-view="side"] { display: block; }
  .layout { grid-template-columns: 1fr; }
  .layout .side, .layout .chat, .layout .actions { display: none; border: 0; }
  .layout[data-view="side"] .side { display: block; }
  .layout[data-view="chat"] .chat { display: flex; }
  .layout[data-view="actions"] .actions { display: flex; grid-column: 1; }
  .transcript, .composer, .chat-head { padding-left: 12px; padding-right: 12px; }
  .action-buttons { grid-template-columns: 1fr; }
}

/* pairing with MTR windows, context chip, embedded mode (the AI window inside panel.mtrtrade.pl) */
.pair-banner { padding: 10px 18px; background: rgba(245, 181, 63, .1); border-bottom: 1px solid var(--warn); display: grid; gap: 8px; }
.pair-item p { margin: 0 0 4px; }
.pair-item .code, .pairing .code { font-family: var(--mono); letter-spacing: .12em; }
.pairing .code { font-size: 2.2rem; color: var(--accent); margin: 0 0 8px; }
.window-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; font-size: .88em; padding: 4px 8px; }
.context-chip { display: flex; align-items: center; gap: 6px; font-size: .8em; color: var(--muted); }
.context-chip input { width: auto; min-height: 0; }
.context-chip { align-items: flex-start; }
.context-chip span { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: normal; overflow-wrap: anywhere; }
.entry.user .ctx { font-size: .78em; color: var(--muted); border-bottom: 1px dashed var(--line); margin-bottom: 4px; padding-bottom: 3px; }
body.embed .local-only { display: none; }
body.embed .topbar { padding: 6px 10px; gap: 6px; }
body.embed .logo { height: 16px; }
body.embed .product { display: none; }
body.embed .project { font-size: .8em; }
body.embed .transcript { padding: 10px; }
body.embed .composer { padding: 8px 10px; }
body.embed .composer textarea { min-height: 52px; }
body.embed .composer-target { font-size: .78em; }
body.embed .chat-head { padding: 6px 10px; gap: 6px; }
body.embed .chat-title h1 { font-size: .92rem; }
body.embed .chat-tools select { max-width: 132px; min-height: 30px; padding: 3px 6px; font-size: .82em; }
body.embed .chat-tools button { min-height: 30px; padding: 3px 8px; font-size: .82em; }
body.pairing .composer, body.pairing .topbar .project, body.pairing .mobile-tabs, body.pairing .chat-head { display: none; }

/* online (server mode): second factor screen */
.twofa { display: grid; gap: 10px; max-width: 360px; text-align: left; }
.twofa h2 { margin: 0; font-size: 1.1rem; }
.twofa label { display: grid; gap: 4px; color: var(--muted); font-size: .9em; }
.twofa input[name=code] { font-family: var(--mono); font-size: 1.4rem; letter-spacing: .2em; text-align: center; }
.twofa .secret { font-size: 1.05rem; word-break: break-all; color: var(--accent); }
