/* Claude Remoto — mobile-first, tema escuro roxo */
:root {
  --bg: #1a1028;
  --bg2: #221434;
  --bg3: #2d1c44;
  --bg4: #382450;
  --acc: #8e6fd8;
  --acc2: #6c4bc4;
  --txt: #ece6f7;
  --dim: #9d8fbd;
  --line: #3a2857;
  --ok: #4ade80;
  --warn: #fbbf24;
  --err: #f87171;
  --done: #7d7592;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { height: 100%; }
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--txt);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--txt); }
[hidden] { display: none !important; }

/* ---------- botões ---------- */
.btn {
  border-radius: 14px;
  padding: 12px 18px;
  font-weight: 600;
  transition: transform .12s ease, opacity .2s ease;
}
.btn:active { transform: scale(.97); }
.btn.primary {
  background: linear-gradient(135deg, var(--acc), var(--acc2));
  color: #fff;
  box-shadow: 0 4px 18px rgba(142, 111, 216, .35);
}
.btn.ghost { color: var(--dim); border: 1px solid var(--line); }
.btn:disabled { opacity: .5; pointer-events: none; }

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  color: var(--dim);
  flex-shrink: 0;
  transition: background .15s ease, color .15s ease;
}
.icon-btn:hover { background: var(--bg3); color: var(--txt); }
.icon-btn:disabled { opacity: .35; pointer-events: none; }
.icon-btn.danger { color: var(--err); }

/* ---------- status dots ---------- */
.dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; background: var(--done); }
.st-running { background: var(--ok); box-shadow: 0 0 8px rgba(74, 222, 128, .7); animation: pulse 1.6s ease-in-out infinite; }
.st-waiting { background: var(--warn); box-shadow: 0 0 8px rgba(251, 191, 36, .5); }
.st-error   { background: var(--err); }
.st-done, .st-killed { background: var(--done); }
@keyframes pulse { 50% { opacity: .55; } }

/* ---------- login ---------- */
#view-login {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; height: 100dvh;
  padding: 24px;
  padding-top: calc(24px + env(safe-area-inset-top));
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}
.login-card {
  width: 100%; max-width: 340px;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  text-align: center;
}
.login-card .logo { width: 84px; height: 84px; border-radius: 22px; box-shadow: 0 12px 40px rgba(142, 111, 216, .35); }
.login-card h1 { margin: 4px 0 0; font-size: 24px; }
.login-card .sub { margin: 0 0 8px; color: var(--dim); font-size: 14px; }
.login-card input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px 16px;
  font-size: 16px;
  text-align: center;
  outline: none;
}
.login-card input:focus { border-color: var(--acc); }
.login-card .btn { width: 100%; }
.err-msg { color: var(--err); font-size: 13px; margin: 0; }

/* ---------- layout do app ---------- */
#view-app { display: flex; height: 100vh; height: 100dvh; }

/* drawer */
.drawer {
  position: fixed; top: 0; bottom: 0; left: 0;
  width: 302px; max-width: 86vw;
  background: var(--bg2);
  z-index: 40;
  display: flex; flex-direction: column;
  transform: translateX(-103%);
  transition: transform .28s cubic-bezier(.2, .8, .2, 1);
  will-change: transform;
  padding-top: env(safe-area-inset-top);
  box-shadow: 8px 0 40px rgba(0, 0, 0, .45);
}
body.drawer-open .drawer { transform: translateX(0); }
.scrim {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, .5);
  z-index: 35;
  opacity: 0; pointer-events: none;
  transition: opacity .28s ease;
}
body.drawer-open .scrim { opacity: 1; pointer-events: auto; }

.drawer-head { display: flex; align-items: center; gap: 10px; padding: 16px 16px 10px; font-size: 16px; }
.drawer-head .logo-sm { width: 32px; height: 32px; border-radius: 9px; }
.new-btn { margin: 4px 14px 10px; }
.drawer-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.drawer-foot .btn { padding: 8px 14px; border-radius: 11px; font-size: 13px; }
.bridge { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--dim); }

/* lista de sessões */
.sess-list {
  list-style: none; margin: 0; padding: 6px 10px;
  flex: 1; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.sess {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  padding: 11px 12px; border-radius: 14px;
  transition: background .15s ease;
}
.sess:hover, .sess:active { background: var(--bg3); }
.sess.active { background: var(--bg4); }
.sess-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.sess-title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sess-prev { color: var(--dim); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sess-meta { color: var(--dim); font-size: 11px; flex-shrink: 0; }
.sess-empty { color: var(--dim); font-size: 13px; text-align: center; padding: 24px 8px; }

/* ---------- chat ---------- */
.chat { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  padding-top: calc(10px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: rgba(26, 16, 40, .92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 5;
}
.titles { flex: 1; min-width: 0; }
#chat-title { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#chat-sub { color: var(--dim); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.banner { padding: 7px 12px; font-size: 12.5px; text-align: center; }
.banner.warn { background: rgba(251, 191, 36, .14); color: var(--warn); }
.banner.err  { background: rgba(248, 113, 113, .14); color: var(--err); }

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px 10px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.row { display: flex; margin: 7px 0; animation: msg-in .18s ease-out; }
@keyframes msg-in { from { opacity: 0; transform: translateY(4px); } }
.row.me { justify-content: flex-end; }
.bubble {
  max-width: 84%;
  padding: 10px 14px;
  border-radius: 18px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.row.me .bubble {
  background: linear-gradient(135deg, var(--acc), var(--acc2));
  color: #fff;
  border-bottom-right-radius: 6px;
}
.row.agent .bubble { background: var(--bg3); border-bottom-left-radius: 6px; }
.bubble.error { border: 1px solid rgba(248, 113, 113, .5); }
.row.pending { opacity: .55; }
.row.failed .bubble { border: 1px solid var(--err); }

/* linha de ferramenta (kind: tool) */
details.tool {
  margin: 5px 0 5px 4px;
  max-width: 92%;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 11.5px;
  color: var(--dim);
}
details.tool summary {
  cursor: pointer;
  list-style: none;
  display: flex; align-items: center; gap: 6px;
  padding: 3px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .04);
}
details.tool summary::-webkit-details-marker { display: none; }
details.tool summary::before { content: "\25B8"; flex-shrink: 0; transition: transform .15s ease; }
details.tool[open] summary::before { transform: rotate(90deg); }
details.tool .tsum { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
details.tool pre {
  margin: 4px 0 0;
  padding: 8px 10px;
  background: rgba(0, 0, 0, .3);
  border-radius: 10px;
  overflow-x: auto; overflow-y: auto;
  max-height: 40vh;
  white-space: pre-wrap;
  word-break: break-word;
}

/* estado vazio */
.empty {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
}
.empty p { margin: 2px 0; }
.empty .dim { color: var(--dim); font-size: 13px; }
.chat.no-session #messages, .chat.no-session .composer { display: none; }
.chat:not(.no-session) #chat-empty { display: none; }

/* composer */
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--bg2);
}
#input {
  flex: 1;
  resize: none;
  background: var(--bg3);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 11px 15px;
  font-size: 16px;
  line-height: 1.4;
  outline: none;
  min-height: 44px;
  max-height: 132px;
}
#input:focus { border-color: var(--acc); }
#input:disabled { opacity: .5; }
.send-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--acc), var(--acc2));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(142, 111, 216, .4);
  transition: transform .12s ease, opacity .2s ease;
}
.send-btn:active { transform: scale(.92); }
.send-btn:disabled { opacity: .4; pointer-events: none; }

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0, 0, 0, .55);
  animation: fade .2s ease;
}
.modal-card {
  width: 100%; max-width: 420px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 22px 22px 0 0;
  padding: 20px 18px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 14px;
  animation: rise .25s cubic-bezier(.2, .8, .2, 1);
}
.modal-card h2 { margin: 0; font-size: 18px; }
.modal-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--dim); }
.modal-card input, .modal-card select {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 13px;
  font-size: 15px;
  font-weight: 400;
  color: var(--txt);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.modal-card input:focus, .modal-card select:focus { border-color: var(--acc); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }
@keyframes rise { from { transform: translateY(30px); opacity: .6; } }
@keyframes fade { from { opacity: 0; } }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(12px);
  background: #0d0817;
  border: 1px solid var(--line);
  color: var(--txt);
  padding: 10px 16px;
  border-radius: 14px;
  font-size: 13.5px;
  max-width: 88vw;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- desktop ---------- */
@media (min-width: 900px) {
  .drawer {
    position: static;
    transform: none;
    box-shadow: none;
    border-right: 1px solid var(--line);
    width: 320px; max-width: none;
  }
  .scrim { display: none; }
  #btn-menu { display: none; }
  .modal { align-items: center; }
  .modal-card { border-radius: 22px; padding-bottom: 20px; }
  .bubble { max-width: 70%; }
}
