:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel2: #1c2230;
  --border: #262d3a;
  --text: #e6edf3;
  --muted: #8b98a9;
  --accent: #38bdf8;
  --accent2: #0ea5e9;
  --danger: #f87171;
  --ok: #34d399;
  --tool: #fbbf24;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }

/* login */
.login {
  height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-box {
  width: 100%; max-width: 340px; text-align: center;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px 22px;
}
.logo { font-size: 34px; font-weight: 800; letter-spacing: 1px; color: var(--accent); }
.sub { color: var(--muted); margin: 4px 0 20px; font-size: 13px; }
.login input {
  width: 100%; padding: 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--panel2); color: var(--text);
  font-size: 15px; margin-bottom: 12px; outline: none;
}
.login input:focus { border-color: var(--accent); }

/* app layout */
.app { display: flex; flex-direction: column; height: 100vh; }
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 800; font-size: 17px; flex: 1; }
.tag {
  font-size: 11px; font-weight: 500; color: var(--muted);
  background: var(--panel2); border: 1px solid var(--border);
  padding: 2px 7px; border-radius: 20px; margin-left: 4px; vertical-align: middle;
}

.btn {
  border: 1px solid var(--border); background: var(--panel2); color: var(--text);
  border-radius: 10px; padding: 10px 16px; font-size: 14px; cursor: pointer;
}
.btn.primary { background: var(--accent2); border-color: var(--accent2); color: #04121a; font-weight: 700; }
.btn.sm { padding: 7px 13px; font-size: 13px; }
.btn:active { opacity: 0.85; }

.icon-btn {
  background: transparent; border: none; color: var(--text);
  font-size: 22px; cursor: pointer; padding: 4px 8px; border-radius: 8px;
}
.icon-btn:active { background: var(--panel2); }

/* sidebar */
.scrim {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 20; opacity: 0;
  pointer-events: none; transition: opacity .2s;
}
.scrim.on { opacity: 1; pointer-events: auto; }
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: min(320px, 85vw);
  background: var(--panel); border-right: 1px solid var(--border); z-index: 30;
  transform: translateX(-100%); transition: transform .2s; overflow-y: auto;
  display: flex; flex-direction: column;
}
.sidebar.on { transform: translateX(0); }
.side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px; border-bottom: 1px solid var(--border);
  font-weight: 700; font-size: 14px;
}
.side-brand { font-size: 17px; font-weight: 800; }
.side-sub { font-size: 11px; color: var(--muted); font-weight: 500; }
.side-actions { display: flex; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.side-actions .btn { flex: 1; text-align: center; }
.plus { font-size: 26px; font-weight: 700; color: var(--accent); }
.status-note { color: var(--muted); font-size: 12px; margin-top: 8px; font-style: italic; }
.conv-list { padding: 8px; }
.conv {
  padding: 10px 12px; border-radius: 10px; cursor: pointer;
  border: 1px solid transparent; margin-bottom: 4px;
}
.conv:hover { background: var(--panel2); }
.conv.active { background: var(--panel2); border-color: var(--border); }
.conv .t { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .p { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .del { float: right; color: var(--muted); font-size: 14px; background: none; border: none; }

/* main */
.main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.msgs {
  flex: 1; overflow-y: auto; padding: 14px 12px 8px;
  display: flex; flex-direction: column; gap: 10px;
}

.msg { max-width: 92%; }
.msg.user { align-self: flex-end; }
.msg.assistant { align-self: flex-start; width: 100%; max-width: 100%; }
.bubble {
  padding: 10px 13px; border-radius: 14px; line-height: 1.5;
  white-space: normal; word-break: break-word; overflow-wrap: break-word;
}
.msg.user .bubble { background: var(--accent2); color: #04121a; border-bottom-right-radius: 4px; }
.msg.assistant .bubble { background: var(--panel); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.assistant .bubble pre { background: #0a0d12; padding: 10px; border-radius: 8px; overflow-x: auto; }
.msg.assistant .bubble code { background: var(--panel2); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.msg.assistant .bubble pre code { background: none; padding: 0; }
.msg.assistant .bubble table { border-collapse: collapse; width: 100%; font-size: 13px; }
.msg.assistant .bubble th, .msg.assistant .bubble td { border: 1px solid var(--border); padding: 6px 8px; text-align: left; }
.msg.assistant .bubble h1, .msg.assistant .bubble h2, .msg.assistant .bubble h3 { margin: 14px 0 6px; }
.msg.assistant .bubble a { color: var(--accent); }
.msg.assistant .bubble blockquote { border-left: 3px solid var(--accent); margin: 8px 0; padding-left: 10px; color: var(--muted); }
.msg.assistant .bubble hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

.toolcard {
  background: #151a23; border: 1px solid #2b2f3a; border-left: 3px solid var(--tool);
  border-radius: 8px; margin: 6px 0; padding: 8px 10px; font-size: 13px;
}
.toolcard .tn { font-weight: 700; color: var(--tool); }
.toolcard .ts { color: var(--muted); font-size: 12px; margin-top: 2px; }
.toolcard summary { cursor: pointer; outline: none; }
.toolcard pre { max-height: 220px; overflow: auto; background: #0a0d12; padding: 8px; border-radius: 6px; font-size: 12px; margin-top: 6px; }
.toolcard img { max-width: 100%; border-radius: 8px; margin-top: 6px; border: 1px solid var(--border); }
.toolcard.standalone { width: 100%; }

.err-banner {
  background: rgba(248,113,113,0.12); border: 1px solid var(--danger); color: var(--danger);
  border-radius: 10px; padding: 10px 13px; font-size: 13px; align-self: stretch;
  white-space: pre-wrap; word-break: break-word;
}
.cursor { display: inline-block; width: 7px; height: 15px; background: var(--accent); margin-left: 2px; animation: blink 1s steps(1) infinite; vertical-align: -2px; }
@keyframes blink { 50% { opacity: 0; } }

/* composer */
.composer {
  border-top: 1px solid var(--border); background: var(--panel); padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
}
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.attach { font-size: 20px; }
.composer textarea {
  flex: 1; resize: none; max-height: 160px;
  background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  border-radius: 12px; padding: 11px 13px; font-size: 15px; font-family: inherit;
  outline: none; line-height: 1.4;
}
.composer textarea:focus { border-color: var(--accent); }
.send { border-radius: 12px; padding: 11px 16px; font-size: 16px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip {
  background: var(--panel2); border: 1px solid var(--border); border-radius: 20px;
  padding: 4px 11px; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px;
}
.chip b { color: var(--text); font-weight: 600; }
.chip button { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px; padding: 0; }

.err { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 16px; }
.empty { color: var(--muted); text-align: center; margin: 40px 16px; font-size: 14px; }

/* browser interativo */
.browser {
  position: fixed; inset: 0; z-index: 40; background: #05070a;
  display: flex; flex-direction: column;
}
.browser-head {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  background: var(--panel); border-bottom: 1px solid var(--border);
}
.btitle { font-weight: 700; font-size: 14px; }
.burl { flex: 1; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bcap { font-size: 11px; color: #04121a; background: var(--tool); border-radius: 20px; padding: 2px 8px; font-weight: 700; }
.browser-body {
  flex: 1; overflow: auto; background: #000; position: relative;
  display: flex; align-items: flex-start; justify-content: center; padding: 8px;
}
.browser-body img {
  max-width: 100%; height: auto; cursor: crosshair; display: block;
  border: 1px solid var(--border); border-radius: 4px;
}
.browser-controls {
  display: flex; align-items: center; gap: 6px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--border); flex-wrap: wrap;
}
.browser-controls input[type=text] {
  background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 7px 9px; font-size: 13px; outline: none; flex: 1; min-width: 100px;
}
.browser-controls input[type=text]:focus { border-color: var(--accent); }
.live { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; }

/* reports */
.reports { position: fixed; inset: 0; z-index: 40; background: var(--bg); display: flex; flex-direction: column; }
.reports-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: var(--panel); border-bottom: 1px solid var(--border); }
.rtitle { font-weight: 700; font-size: 14px; flex: 1; }
.reports-body { flex: 1; display: flex; min-height: 0; }
.reports-list { width: 280px; border-right: 1px solid var(--border); overflow-y: auto; padding: 8px; background: var(--panel); }
.rep { padding: 10px 12px; border-radius: 10px; cursor: pointer; margin-bottom: 4px; border: 1px solid transparent; }
.rep:hover { background: var(--panel2); }
.rep.active { background: var(--panel2); border-color: var(--border); }
.rep .t { font-size: 13px; font-weight: 600; }
.rep .d { font-size: 11px; color: var(--muted); margin-top: 2px; }
.reports-view { flex: 1; overflow-y: auto; padding: 16px; line-height: 1.6; }
.reports-view pre { background: var(--panel2); padding: 10px; border-radius: 8px; overflow-x: auto; }
.reports-view code { background: var(--panel2); padding: 1px 5px; border-radius: 5px; }
.reports-view table { border-collapse: collapse; width: 100%; font-size: 13px; }
.reports-view th, .reports-view td { border: 1px solid var(--border); padding: 6px 8px; text-align: left; }
.reports-view h1, .reports-view h2, .reports-view h3 { margin: 14px 0 6px; }
.reports-view a { color: var(--accent); }
.reports-view blockquote { border-left: 3px solid var(--accent); margin: 8px 0; padding-left: 10px; color: var(--muted); }
@media (max-width: 640px) {
  .reports-body { flex-direction: column; }
  .reports-list { width: 100%; max-height: 40%; border-right: none; border-bottom: 1px solid var(--border); }
}
