* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #1a1915; --panel: #24221c; --panel2: #2e2b23;
  --fg: #e8e4da; --muted: #98927f; --accent: #d97757; --accent2: #b45f43;
  --ok: #7fb069; --bad: #d06b5d; --border: #3a362c;
  --radius: 14px;
}
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--bad); margin-top: 12px; }

/* ---- login ---- */
#login { display: flex; align-items: center; justify-content: center; min-height: 100dvh; padding: 24px; }
.login-card { text-align: center; max-width: 340px; width: 100%; }
.login-icon { width: 84px; height: 84px; border-radius: 20px; margin-bottom: 16px; }
.login-card h1 { font-size: 24px; margin-bottom: 6px; }
.login-card p { margin-bottom: 18px; }
#tg-widget { display: flex; justify-content: center; min-height: 46px; }
.login-sep { color: var(--muted); margin: 16px 0; font-size: 13px; }
.btn {
  background: var(--panel2); color: var(--fg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 18px; font-size: 16px; cursor: pointer;
  width: 100%;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
#login-note { margin-top: 14px; }

/* ---- app shell ---- */
#app { display: flex; flex-direction: column; height: 100dvh; }
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  background: var(--panel); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.hdr-title { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); display: inline-block; }
.dot.busy { background: var(--accent); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.hdr-btns { display: flex; gap: 4px; }
.hbtn {
  background: none; border: none; font-size: 20px; padding: 6px 8px;
  cursor: pointer; border-radius: 8px; color: var(--fg);
}
.hbtn:active { background: var(--panel2); }
.hbtn.on { filter: none; }
.hbtn.off { filter: grayscale(1) opacity(.5); }

main#log { flex: 1; overflow-y: auto; padding: 14px; scroll-behavior: smooth; }

/* ---- messages ---- */
.msg { max-width: 92%; margin-bottom: 12px; padding: 10px 14px; border-radius: var(--radius); word-wrap: break-word; }
.msg.user { background: var(--accent2); color: #fff; margin-left: auto; white-space: pre-wrap; }
.msg.user .origin { display: block; font-size: 11px; opacity: .7; margin-bottom: 2px; }
.msg.assistant { background: var(--panel); border: 1px solid var(--border); }
.msg.note { background: none; color: var(--muted); font-size: 13px; text-align: center; max-width: 100%; padding: 4px; }
.msg .status { color: var(--muted); font-size: 12px; margin-top: 6px; }

.msg.assistant pre {
  background: #12110d; border: 1px solid var(--border); border-radius: 8px;
  padding: 10px; overflow-x: auto; margin: 8px 0; font-size: 13px;
}
.msg.assistant code { font-family: ui-monospace, Menlo, monospace; font-size: 14px; }
.msg.assistant :not(pre) > code { background: #12110d; padding: 1px 6px; border-radius: 5px; }
.msg.assistant p { margin: 6px 0; }
.msg.assistant h1, .msg.assistant h2, .msg.assistant h3 { margin: 10px 0 6px; font-size: 1.05em; }
.msg.assistant ul, .msg.assistant ol { margin: 6px 0 6px 22px; }
.msg.assistant blockquote { border-left: 3px solid var(--accent); padding-left: 10px; color: var(--muted); margin: 6px 0; }
.msg.assistant a { color: var(--accent); }
.msg.assistant table { border-collapse: collapse; margin: 8px 0; font-size: 14px; }
.msg.assistant td, .msg.assistant th { border: 1px solid var(--border); padding: 4px 8px; }

/* ---- approval card ---- */
.approval {
  background: var(--panel2); border: 1px solid var(--accent); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 12px;
}
.approval .tool { font-weight: 700; margin-bottom: 6px; }
.approval .summary {
  font-family: ui-monospace, Menlo, monospace; font-size: 13px;
  background: #12110d; border-radius: 8px; padding: 8px; margin-bottom: 10px;
  white-space: pre-wrap; word-break: break-all; max-height: 160px; overflow-y: auto;
}
.approval .abtns { display: flex; gap: 10px; }
.approval .abtns button {
  flex: 1; padding: 10px; border-radius: 10px; border: none; font-size: 15px;
  cursor: pointer; font-weight: 600;
}
.approval .allow { background: var(--ok); color: #14210f; }
.approval .deny { background: var(--bad); color: #fff; }
.approval .verdict { color: var(--muted); font-size: 14px; }

/* ---- composer ---- */
footer {
  flex-shrink: 0; padding: 10px 12px calc(env(safe-area-inset-bottom) + 10px);
  background: var(--panel); border-top: 1px solid var(--border);
}
.composer { display: flex; align-items: flex-end; gap: 8px; }
#input {
  flex: 1; resize: none; background: var(--panel2); color: var(--fg);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 11px 14px; font: inherit; max-height: 160px; outline: none;
}
#input:focus { border-color: var(--accent); }
.send {
  background: var(--accent); color: #fff; border: none; border-radius: 50%;
  width: 42px; height: 42px; font-size: 18px; cursor: pointer; flex-shrink: 0;
}
.send:disabled { opacity: .4; }

/* ---- toast ---- */
#toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: var(--panel2); border: 1px solid var(--border); color: var(--fg);
  padding: 10px 18px; border-radius: 12px; font-size: 14px; z-index: 10;
  max-width: 88%;
}
