:root {
  color-scheme: light;
  --bg: #f6f7f5;
  --surface: #ffffff;
  --surface-2: #eef1ee;
  --text: #17201c;
  --muted: #5d6b65;
  --border: #dde3df;
  --accent: #1f6f5c;
  --accent-soft: #e2f0eb;
  --on-accent: #ffffff;
  --ok: #1f7a4a;
  --ok-soft: #e3f3ea;
  --warn: #9a4a06;
  --warn-soft: #fdf0e1;
  --danger: #b42318;
  --danger-soft: #fdeceb;
  --code-bg: #f0f2ef;
  --shadow: 0 8px 28px rgb(15 20 18 / 0.14);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "Roboto Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0f1412;
    --surface: #161d1a;
    --surface-2: #1d2622;
    --text: #e7ece9;
    --muted: #93a29b;
    --border: #2a3530;
    --accent: #4cc29f;
    --accent-soft: #173229;
    --on-accent: #06261d;
    --ok: #47cd89;
    --ok-soft: #12291d;
    --warn: #fdb022;
    --warn-soft: #2e2410;
    --danger: #f97066;
    --danger-soft: #2f1615;
    --code-bg: #111816;
    --shadow: 0 10px 32px rgb(0 0 0 / 0.5);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg circle[r="1.6"] { fill: currentColor; stroke: none; }

/* ---- Felső sáv ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex: none;
}
.topbar-title {
  flex: 1;
  min-width: 0;
  font-weight: 650;
  font-size: 17px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-left: 4px;
}
.icon-btn {
  border: 0;
  background: transparent;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex: none;
}
.icon-btn:active { background: var(--surface-2); }

.status-pill {
  font-size: 12.5px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
  max-width: 46vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status-pill.busy { background: var(--accent-soft); color: var(--accent); }
.status-pill.busy::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  margin-right: 6px;
  vertical-align: 1px;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.25; } }

/* ---- Nézetek ---- */
.view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.container {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 16px;
}

/* ---- Gombok, mezők ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 8px 16px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 600;
  font-size: 15px;
  text-decoration: none;
  color: var(--text);
  cursor: pointer;
}
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--danger); }
.btn.primary.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.btn.small { min-height: 34px; padding: 4px 12px; font-size: 14px; border-radius: 9px; }
.btn svg { width: 18px; height: 18px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.field small { display: block; color: var(--muted); font-size: 13px; margin-top: 4px; }
.input, .textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 11px;
  padding: 10px 12px;
  outline: none;
}
.textarea { resize: vertical; min-height: 96px; }
.input:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---- Bejelentkezés ---- */
.login {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 16px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 22px;
}
.login-card img { width: 56px; height: 56px; border-radius: 14px; display: block; margin-bottom: 14px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 20px; color: var(--muted); font-size: 14.5px; }
.login-card .btn { width: 100%; }
.form-error { color: var(--danger); font-size: 14px; margin: -4px 0 12px; }

/* ---- Projektlista ---- */
.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.list-head h2 { margin: 0; font-size: 20px; }
.cards { display: grid; gap: 10px; }
.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-decoration: none;
  color: inherit;
}
.card-row { display: flex; align-items: center; gap: 12px; }
.card-main { flex: 1; min-width: 0; }
.card-title { font-weight: 650; font-size: 16.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-sub { color: var(--muted); font-size: 13.5px; margin-top: 2px; }
.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.fail { background: var(--danger-soft); color: var(--danger); }
.badge.busy { background: var(--accent-soft); color: var(--accent); }
.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 16px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty strong { display: block; color: var(--text); font-size: 17px; margin-bottom: 6px; }

/* ---- Projekt nézet ---- */
.project-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex: none;
}
.project-bar .container { padding-top: 10px; padding-bottom: 0; }
.install-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.install-row .meta { flex: 1; min-width: 0; color: var(--muted); font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs { display: flex; gap: 4px; }
.tab {
  flex: 1;
  text-align: center;
  padding: 9px 4px 11px;
  font-weight: 600;
  font-size: 14.5px;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 2.5px solid transparent;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---- Chat ---- */
.messages { display: flex; flex-direction: column; gap: 10px; padding-bottom: 24px; }
.msg { max-width: 100%; overflow-wrap: anywhere; }
.msg.user {
  align-self: flex-end;
  max-width: 88%;
  background: var(--accent);
  color: var(--on-accent);
  padding: 9px 14px;
  border-radius: 18px 18px 6px 18px;
  white-space: pre-wrap;
}
.msg.assistant {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: 6px 18px 18px 18px;
}
.msg.assistant > :first-child, .markdown > :first-child { margin-top: 0; }
.msg.assistant > :last-child, .markdown > :last-child { margin-bottom: 0; }
.msg.assistant p, .msg.assistant ul, .msg.assistant ol,
.markdown p, .markdown ul, .markdown ol { margin: 0.5em 0; }
.msg.assistant ul, .msg.assistant ol, .markdown ul, .markdown ol { padding-left: 1.3em; }
.msg.assistant h1, .msg.assistant h2, .msg.assistant h3,
.markdown h1, .markdown h2, .markdown h3 { font-size: 1.05em; margin: 0.8em 0 0.3em; }
.msg.assistant code, .markdown code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 1px 5px;
  border-radius: 5px;
}
.msg.assistant pre, .markdown pre {
  background: var(--code-bg);
  padding: 10px 12px;
  border-radius: 10px;
  overflow-x: auto;
  font-size: 13px;
}
.msg.assistant pre code, .markdown pre code { background: none; padding: 0; }
.msg.assistant table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 14px; }
.msg.assistant th, .msg.assistant td { border: 1px solid var(--border); padding: 4px 8px; }

.tools {
  font-size: 13.5px;
  color: var(--muted);
  border-left: 2px solid var(--border);
  padding-left: 10px;
}
.tools summary { cursor: pointer; list-style: none; }
.tools summary::-webkit-details-marker { display: none; }
.tools summary::before { content: "▸ "; }
.tools[open] summary::before { content: "▾ "; }
.tools ul { list-style: none; margin: 6px 0 2px; padding: 0; display: grid; gap: 3px; }
.tool-label { font-weight: 600; }
.tool-detail { font-family: var(--mono); font-size: 12.5px; overflow-wrap: anywhere; }

.note { font-size: 13.5px; text-align: center; color: var(--muted); padding: 0 8px; }
.note.ok { color: var(--ok); }
.note.warn { color: var(--warn); }
.note.error { color: var(--danger); }
.result { font-size: 12.5px; color: var(--muted); }
.result.error { color: var(--danger); font-size: 13.5px; white-space: pre-wrap; }
.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12.5px;
  margin: 6px 0;
}
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }

.build-card {
  border-radius: var(--radius);
  padding: 12px 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  display: grid;
  gap: 8px;
}
.build-card.ok { border-color: color-mix(in srgb, var(--ok) 40%, var(--border)); background: var(--ok-soft); }
.build-card.fail { border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); background: var(--danger-soft); }
.build-card .head { font-weight: 650; }
.build-card.ok .head { color: var(--ok); }
.build-card.fail .head { color: var(--danger); }
.build-card .sub { font-size: 13.5px; color: var(--muted); }
.build-card .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- Beviteli sáv ---- */
.composer {
  flex: none;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.composer .container { padding-top: 10px; padding-bottom: 10px; }
.progress {
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 8px;
  display: flex;
  gap: 8px;
  align-items: baseline;
  min-width: 0;
}
.progress .task { color: var(--muted); font-family: var(--mono); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.chip-row { display: flex; margin-bottom: 8px; min-width: 0; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 12px 4px 9px;
  font-size: 13px;
  cursor: pointer;
}
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip svg { width: 16px; height: 16px; flex: none; }
select.input { appearance: auto; }
select.input:disabled { opacity: 0.55; }
.check { display: flex; gap: 10px; align-items: center; font-size: 14.5px; margin: 4px 0 6px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.composer textarea {
  flex: 1;
  resize: none;
  min-height: 44px;
  max-height: 40dvh;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 14px;
  padding: 10px 12px;
  outline: none;
  line-height: 1.4;
}
.composer textarea:focus { border-color: var(--accent); }
.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: var(--on-accent);
  display: grid;
  place-items: center;
  flex: none;
  cursor: pointer;
}
.send-btn:disabled { opacity: 0.4; cursor: default; }
.send-btn.stop { background: var(--danger); color: #fff; }
.send-btn.stop svg rect { fill: currentColor; stroke: none; }

/* ---- Listák (APK-k, verziók) ---- */
.rows { display: grid; gap: 8px; }
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
}
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; font-size: 15px; overflow-wrap: anywhere; }
.row .sub { color: var(--muted); font-size: 13px; }
.hash { font-family: var(--mono); font-size: 12px; }
.row-actions { display: flex; gap: 6px; align-items: center; flex: none; }
.badge.inline { margin-left: 8px; vertical-align: 1px; }
.markdown { line-height: 1.55; }

/* ---- Menü, modal, toast ---- */
.menu {
  position: fixed;
  top: calc(56px + env(safe-area-inset-top));
  right: 10px;
  z-index: 20;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  min-width: 220px;
  padding: 6px;
}
.menu button {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  padding: 11px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.menu button:active, .menu button:hover { background: var(--surface-2); }
.menu button.danger { color: var(--danger); }

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgb(0 0 0 / 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
@media (min-width: 640px) { .backdrop { align-items: center; } }
.modal {
  width: 100%;
  max-width: 560px;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(16px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow);
}
@media (min-width: 640px) { .modal { border-radius: 18px; } }
.modal h3 { margin: 0 0 12px; font-size: 18px; }
.modal-body { overflow-y: auto; min-height: 0; }
.modal-body p { margin: 0 0 12px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.modal-actions .btn { flex: 1; }
@media (min-width: 640px) { .modal-actions .btn { flex: none; } }
.log {
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.45;
  background: var(--code-bg);
  border-radius: 10px;
  padding: 10px;
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 40;
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 14.5px;
  max-width: calc(100vw - 32px);
  box-shadow: var(--shadow);
}
.toast.error { background: var(--danger); color: #fff; }

.loading { color: var(--muted); text-align: center; padding: 32px 0; }
