/* AMC Mini App — OpenCode-style compact dark UI */
:root {
  color-scheme: dark;
  --bg: #080808;
  --bg-1: #0e0e0e;
  --bg-2: #161616;
  --bg-3: #242424;
  --text: #fafafa;
  --muted: #8b8b8b;
  --faint: #5c5c5c;
  --line: rgba(255, 255, 255, .10);
  --line-strong: rgba(255, 255, 255, .18);
  --accent: #3b5cf6;
  --accent-text: #fff;
  --ok: #46c46a;
  --warn: #d9a441;
  --danger: #ef5350;
  --radius: 10px;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 13px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  min-height: var(--tg-viewport-stable-height, 100vh);
  padding-bottom: calc(56px + env(safe-area-inset-bottom));
}
.hidden { display: none !important; }
.app { max-width: 960px; margin: 0 auto; padding: 0 12px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.meta { color: var(--muted); font-size: 11px; }
.note { color: var(--muted); font-size: 11px; line-height: 1.5; }
.label { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .07em; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: 52px; display: flex; align-items: center; justify-content: space-between;
  background: #080808; border-bottom: 1px solid var(--line);
  margin: 0 -12px; padding: 0 12px;
}
.identity { display: flex; align-items: baseline; gap: 7px; min-width: 0; }
.wordmark { font: 500 13px/1 var(--mono); letter-spacing: .04em; }
.slash { color: var(--faint); font: 12px var(--mono); }
.crumb { color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.conn { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); flex: 0 0 auto; }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.err { background: var(--danger); }

/* controls */
.btn, .icon-btn {
  border: 1px solid var(--line); background: var(--bg-2); color: var(--text);
  border-radius: 8px; height: 30px; padding: 0 10px;
  font: 500 12px/1 var(--sans); cursor: pointer;
  transition: transform .06s ease;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.btn:hover, .icon-btn:hover { background: var(--bg-3); border-color: var(--line-strong); }
.btn:active, .icon-btn:active { transform: translateY(1px); }
.btn:disabled, .icon-btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: #4b6aff; border-color: #4b6aff; }
.btn.danger { color: #ff8a87; }
.btn.danger:hover { border-color: rgba(239, 83, 80, .45); background: rgba(239, 83, 80, .08); }
.btn.small { height: 26px; padding: 0 8px; font-size: 11px; border-radius: 7px; }
.icon-btn { width: 30px; padding: 0; display: inline-grid; place-items: center; color: var(--muted); font-size: 15px; }
.icon-btn svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
a.btn { display: inline-flex; align-items: center; text-decoration: none; }

/* page */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 18px 0 12px; }
.page-head h1 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -.02em; }
.section-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 20px 0 8px; }
.section-row h2 { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.stat { border: 1px solid var(--line); background: var(--bg-1); border-radius: var(--radius); padding: 10px; min-width: 0; }
.stat .k { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .07em; }
.stat .v { margin-top: 3px; font: 600 17px/1.2 var(--mono); font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat .s { margin-top: 4px; color: var(--muted); font: 10px/1.3 var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 0; }

/* agents */
.slots { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.slot { border: 1px solid var(--line); background: var(--bg-1); border-radius: var(--radius); padding: 11px; min-width: 0; }
.slot-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.slot-id { font: 600 12px/1 var(--mono); }
.slot-state { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .06em; }
.slot-meta { color: var(--muted); font: 11px/1.6 var(--mono); margin-top: 7px; min-height: 18px; overflow-wrap: anywhere; }
.slot-meta strong { color: var(--text); font-weight: 500; }
.slot-actions { display: flex; gap: 5px; margin-top: 9px; flex-wrap: wrap; }

/* drawers */
.drawer { border-top: 1px solid var(--line); margin-top: 10px; padding-top: 8px; }
.drawer:first-of-type { margin-top: 16px; }
.drawer summary { cursor: pointer; color: var(--muted); font-size: 12px; list-style: none; display: flex; justify-content: space-between; }
.drawer summary::after { content: "+"; font-family: var(--mono); color: var(--faint); }
.drawer[open] summary::after { content: "−"; }
.drawer[open] summary { margin-bottom: 8px; }
.events, .claims { max-height: 320px; overflow: auto; overscroll-behavior: contain; }
.event { display: grid; grid-template-columns: 56px 1fr; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); content-visibility: auto; contain-intrinsic-size: 44px; }
.event:last-child, .claim:last-child { border-bottom: 0; }
.event time { color: var(--faint); font: 10px/1.5 var(--mono); }
.event .kind { color: var(--faint); font: 9px/1.4 var(--mono); text-transform: uppercase; }
.event .msg { color: var(--text); font-size: 11px; overflow-wrap: anywhere; }
.claim { padding: 7px 0; border-bottom: 1px solid var(--line); content-visibility: auto; contain-intrinsic-size: 42px; }
.claim .row { display: flex; justify-content: space-between; gap: 10px; }
.claim .slug { font: 500 11px var(--mono); overflow-wrap: anywhere; }
.claim .scope { color: var(--muted); font-size: 11px; margin-top: 2px; overflow-wrap: anywhere; }
.badge { font: 10px var(--mono); color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 2px 7px; }
.badge.ok { color: var(--ok); border-color: rgba(70,196,106,.35); }
.badge.warn { color: var(--warn); border-color: rgba(217,164,65,.35); }
.badge.err { color: var(--danger); border-color: rgba(239,83,80,.35); }
.kv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 20px; }
.kv div { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 11px; }
.kv span:first-child { color: var(--muted); }
.kv span:last-child { font-family: var(--mono); text-align: right; overflow-wrap: anywhere; }

/* chats */
.chat-list { border-top: 1px solid var(--line); overscroll-behavior: contain; }
.chat-item { padding: 11px 2px; border-bottom: 1px solid var(--line); cursor: pointer; content-visibility: auto; contain-intrinsic-size: 64px; touch-action: manipulation; }
.chat-item:hover { background: rgba(255,255,255,.02); }
.chat-item .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.chat-item .name { font-size: 12px; font-weight: 500; overflow-wrap: anywhere; }
.chat-item .preview { color: var(--muted); font: 10px/1.5 var(--mono); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .stats { display: flex; gap: 10px; color: var(--faint); font: 10px var(--mono); margin-top: 4px; }
.chat-head { display: flex; align-items: center; gap: 8px; margin: 12px 0 4px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.chat-head-text { min-width: 0; }
.chat-title { font: 600 14px/1.3 var(--mono); overflow-wrap: anywhere; }
.chat-messages { display: flex; flex-direction: column; gap: 10px; padding: 12px 0; max-height: calc(var(--tg-viewport-stable-height, 100vh) - 230px); overflow: auto; overscroll-behavior: contain; }
.msg { font-size: 12px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .role { display: block; color: var(--faint); font: 9px/1.5 var(--mono); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 3px; }
.msg.assistant { border-left: 2px solid var(--line-strong); padding-left: 9px; }
.msg.user { background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; align-self: flex-end; max-width: 92%; }
.msg.tool { color: var(--muted); font: 10px/1.5 var(--mono); border-left: 2px solid transparent; padding-left: 9px; }
.msg.tool .name { color: var(--accent); }
.msg.system { color: var(--faint); font: 10px/1.5 var(--mono); text-align: center; }
.chat-inputbar { position: sticky; bottom: calc(56px + env(safe-area-inset-bottom)); display: flex; gap: 6px; align-items: end; padding: 8px 0; background: var(--bg); border-top: 1px solid var(--line); }
.chat-inputbar textarea { flex: 1; min-height: 34px; max-height: 120px; resize: none; background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; color: var(--text); padding: 8px 10px; font: 12px/1.4 var(--sans); }
.chat-inputbar textarea:focus, .btn:focus, .icon-btn:focus { outline: 1px solid var(--accent); outline-offset: 1px; }
.chat-inputbar textarea:disabled { opacity: .4; }

/* model picker sheet */
.sheet { position: fixed; inset: 0; z-index: 80; display: flex; align-items: flex-end; }
.sheet.hidden { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .58); }
.sheet-panel { position: relative; width: 100%; max-height: 84vh; background: var(--bg-1); border-top: 1px solid var(--line-strong); border-radius: 14px 14px 0 0; padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; box-shadow: 0 -10px 40px rgba(0, 0, 0, .35); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sheet-head h2 { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
#model-search { background: var(--bg-2); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 8px 10px; font: 12px var(--sans); }
#model-search:focus { outline: 1px solid var(--accent); outline-offset: 1px; }
.model-providers { display: flex; gap: 5px; overflow-x: auto; padding-bottom: 2px; }
.model-provider { flex: 0 0 auto; border: 1px solid var(--line); background: transparent; color: var(--faint); border-radius: 999px; padding: 4px 8px; font: 10px var(--mono); cursor: pointer; }
.model-provider.active { color: var(--text); border-color: var(--accent); }
.model-list { overflow-y: auto; max-height: 58vh; border-top: 1px solid var(--line); }
.model-item { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--text); padding: 10px 2px; text-align: left; cursor: pointer; }
.model-item:hover { background: var(--bg-2); }
.model-item.selected { background: var(--bg-2); }
.model-name { font: 12px/1.35 var(--sans); }
.model-meta { color: var(--faint); font: 9px/1.4 var(--mono); margin-top: 2px; }
.model-check { color: var(--accent); font: 12px var(--mono); }
#chat-note { padding-top: 8px; }

/* accounts */
.accounts { border-top: 1px solid var(--line); margin-bottom: 14px; }
.account { padding: 12px 2px; border-bottom: 1px solid var(--line); }
.account .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.account .name { font-size: 13px; font-weight: 500; }
.account .id { color: var(--faint); font: 10px var(--mono); margin-top: 2px; }
.account .meta { color: var(--muted); font: 10px var(--mono); margin-top: 3px; }
.account .actions { display: flex; gap: 5px; margin-top: 8px; flex-wrap: wrap; }
.panel { border: 1px solid var(--line); background: var(--bg-1); border-radius: var(--radius); padding: 12px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.panel-head h2 { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.login-result { margin-top: 12px; display: flex; flex-direction: column; align-items: start; gap: 9px; }
.code-row { display: flex; align-items: center; gap: 8px; }
.login-code { font: 600 18px/1 var(--mono); letter-spacing: .12em; color: var(--text); }
.welcome { text-align: center; padding: 22vh 20px 0; }
.welcome-icon { color: var(--accent); font: 28px var(--mono); }
.welcome h1 { margin: 10px 0 4px; font-size: 18px; }
.welcome p { margin: 0; color: var(--muted); font-size: 12px; }
.toast { position: fixed; left: 50%; bottom: calc(68px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50; max-width: min(92vw, 560px); background: var(--bg-2); color: var(--text); border: 1px solid var(--line-strong); padding: 8px 11px; border-radius: 8px; font-size: 11px; white-space: pre-wrap; overflow-wrap: anywhere; }
.spin { display: inline-block; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* nav */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; height: calc(56px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: #080808; border-top: 1px solid var(--line);
}
.bottom-nav button {
  flex: 1; border: 0; background: transparent; color: var(--faint);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font: 500 9px/1 var(--sans); position: relative; cursor: pointer; min-width: 0;
}
.bottom-nav button svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.4; }
.bottom-nav button.active { color: var(--text); }
.bottom-nav button.active::before { content: ""; position: absolute; top: 0; width: 22px; height: 1px; background: var(--accent); }


/* settings */
.settings-group { border: 1px solid var(--line); background: var(--bg-1); border-radius: var(--radius); margin-bottom: 8px; overflow: hidden; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 12px; border-bottom: 1px solid var(--line); min-height: 44px; }
.setting:last-child { border-bottom: 0; }
.setting-label { font-size: 12px; color: var(--text); }
.setting-control { display: flex; flex-direction: column; gap: 5px; width: min(230px, 52vw); flex: 0 0 auto; }
.setting select, .setting input[type="text"], .setting input[type="number"] {
  background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 7px; padding: 6px 8px; font: 11px/1.4 var(--sans); min-width: 0;
}
.setting select { width: 100%; }
.setting select.compact, .setting input.compact { width: 72px; }
.setting input[type="text"] { width: 100%; }
.setting input:focus, .setting select:focus { outline: 1px solid var(--accent); outline-offset: 1px; }
.input-suffix { display: flex; align-items: center; gap: 6px; color: var(--muted); font: 10px var(--mono); }
.input-suffix input { width: 68px; }
.checks { display: flex; gap: 12px; align-items: center; }
.checks label { display: flex; align-items: center; gap: 4px; color: var(--muted); font: 11px var(--mono); }
.checks input { accent-color: var(--accent); }
.toggle-row { cursor: pointer; }
.setting-stack { display: flex; flex-direction: column; align-items: stretch; gap: 8px; }
.setting-stack .toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 2px 0; }
.head-actions { display: flex; align-items: center; gap: 6px; }
.model-pill { border: 1px solid var(--line); background: var(--bg-2); color: var(--muted); border-radius: 999px; padding: 4px 9px; font: 10px/1.3 var(--mono); max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.model-pill:hover { color: var(--text); border-color: var(--line-strong); }
.mission-model-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--muted); font: 10px var(--mono); }
.mission-prompt { width: 100%; min-height: 150px; resize: vertical; background: var(--bg-2); border: 1px solid var(--line); border-radius: 7px; color: var(--text); padding: 8px; font: 11px/1.45 var(--mono); }
.mission-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.mission-row label { display: flex; align-items: center; gap: 6px; color: var(--muted); font: 10px var(--mono); }
.mission-row input[type="number"] { width: 88px; }
.quiet-input { width: 58px; }
.mission-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.toggle { position: relative; display: inline-flex; flex: 0 0 auto; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle span { width: 34px; height: 20px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--bg-2); position: relative; display: inline-block; }
.toggle span::after { content: ""; position: absolute; width: 14px; height: 14px; left: 2px; top: 2px; border-radius: 50%; background: var(--faint); transform: translateX(0); transition: transform .15s, background .15s; }
.toggle input:checked + span { background: var(--accent); border-color: var(--accent); }
.toggle input:checked + span::after { transform: translateX(14px); background: #fff; }
.savebar { position: sticky; bottom: calc(56px + env(safe-area-inset-bottom)); z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; margin-top: 8px; background: var(--bg); border-top: 1px solid var(--line); }
.savebar .note { max-width: 60%; }

@media (max-width: 720px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .slots { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
  .crumb { max-width: 32vw; }
}
