:root {
  --bg: #0a0a0f;
  --panel: #111118;
  --elev: #16161f;
  --hover: #1c1c28;
  --border: rgba(255, 255, 255, 0.08);
  --border-2: rgba(255, 255, 255, 0.14);
  --text: #f0f0f6;
  --text-2: #c4c4d4;
  --muted: #8b8b9e;
  --accent: #8b5cf6;
  --accent-2: #22d3ee;
  --accent-soft: rgba(139, 92, 246, 0.16);
  --accent-glow: rgba(139, 92, 246, 0.35);
  --danger: #f87171;
  --ok: #34d399;
  --user: linear-gradient(135deg, #5b21b6, #6d28d9);
  --radius: 14px;
  --sidebar: 280px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
.muted { color: var(--muted); }
.tiny { font-size: 0.72rem; display: block; }

/* ── Auth ── */
.auth-page {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse 70% 50% at 50% -10%, rgba(139, 92, 246, 0.25), transparent 55%),
    radial-gradient(ellipse 40% 30% at 100% 100%, rgba(34, 211, 238, 0.08), transparent 50%),
    var(--bg);
}
.auth-card {
  width: min(400px, 100%);
  background: rgba(17, 17, 24, 0.9);
  border: 1px solid var(--border-2);
  border-radius: 20px;
  padding: 36px 32px;
  box-shadow: 0 24px 60px rgba(0,0,0,.45);
}
.brand { text-align: center; margin-bottom: 28px; }
.brand h1 { margin: 0 0 8px; font-size: 1.45rem; letter-spacing: -0.03em; }
.brand p { margin: 0; color: var(--muted); font-size: 0.9rem; line-height: 1.45; }
.logo {
  width: 48px; height: 48px; border-radius: 14px;
  display: grid; place-items: center;
  font-weight: 800; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 28px var(--accent-glow);
  margin: 0 auto 14px;
}
.logo.sm { width: 34px; height: 34px; font-size: 0.9rem; border-radius: 10px; margin: 0; box-shadow: 0 4px 14px var(--accent-glow); }
.auth-card label { display: block; font-size: 0.8rem; color: var(--text-2); margin-bottom: 14px; }
.auth-card input {
  width: 100%; margin-top: 6px; padding: 12px 14px;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--elev); outline: none;
}
.auth-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.auth-card button {
  width: 100%; margin-top: 6px; padding: 12px;
  border-radius: 10px; font-weight: 600; color: #fff;
  background: linear-gradient(135deg, #8b5cf6, #6d28d9);
  box-shadow: 0 4px 16px var(--accent-glow);
}
.auth-card button:disabled { opacity: .55; cursor: wait; }
.error {
  color: var(--danger); font-size: 0.88rem; margin: 12px 0 0;
  padding: 10px; background: rgba(248,113,113,.1);
  border: 1px solid rgba(248,113,113,.25); border-radius: 8px;
}

/* ── Shell layout ── */
.shell {
  display: flex;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(ellipse 50% 40% at 80% 0%, rgba(139, 92, 246, 0.07), transparent 50%),
    var(--bg);
}

.sidebar {
  width: var(--sidebar);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 14px;
  gap: 12px;
  z-index: 40;
}
.sidebar-head { display: flex; flex-direction: column; gap: 12px; }
.brand-row { display: flex; align-items: center; gap: 10px; padding: 4px; }
.brand-row strong { font-size: 0.95rem; letter-spacing: -0.02em; }

.sidebar-section { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
select#cwd {
  width: 100%;
  appearance: none;
  background: var(--elev) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b8b9e' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 30px 9px 10px;
  font-size: 0.82rem;
  outline: none;
  cursor: pointer;
}
select#cwd:focus { border-color: var(--accent); }

.conv-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
  padding-right: 2px;
}
.conv-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  text-align: left;
  color: var(--text-2);
  font-size: 0.85rem;
  transition: background .12s, border-color .12s;
  width: 100%;
}
.conv-item:hover { background: var(--hover); }
.conv-item.active {
  background: var(--accent-soft);
  border-color: rgba(139, 92, 246, 0.35);
  color: var(--text);
}
.conv-item .title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-item .meta { font-size: 0.68rem; color: var(--muted); white-space: nowrap; }

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.user-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px; border-radius: 10px;
  background: var(--elev); border: 1px solid var(--border);
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center;
  font-size: 0.75rem; font-weight: 700; color: #fff;
}
.user-meta { min-width: 0; flex: 1; }
.user-meta strong { display: block; font-size: 0.85rem; }

.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 14px; border-radius: 10px; font-weight: 600; font-size: 0.9rem;
  color: #fff;
  background: linear-gradient(135deg, #8b5cf6, #6d28d9);
  box-shadow: 0 4px 14px var(--accent-glow);
  transition: transform .12s, opacity .12s;
}
.btn-primary:hover { transform: translateY(-1px); }
.btn-primary.full, .btn-ghost.full { width: 100%; }
.btn-ghost {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--border); color: var(--text-2);
  font-size: 0.85rem; font-weight: 500;
  transition: background .12s, border-color .12s;
}
.btn-ghost:hover { background: var(--hover); border-color: var(--border-2); color: var(--text); }

/* Main */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
}
.topbar {
  height: 56px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 10, 15, 0.75);
  backdrop-filter: blur(14px);
}
.topbar-title { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
.topbar-title h1 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pill {
  flex-shrink: 0;
  font-size: 0.68rem;
  font-weight: 650;
  padding: 3px 9px;
  border-radius: 999px;
  color: #c4b5fd;
  background: var(--accent-soft);
  border: 1px solid rgba(139, 92, 246, 0.35);
  white-space: nowrap;
}
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.cwd-chip {
  font-size: 0.72rem;
  font-family: var(--mono);
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.icon-btn {
  display: none;
  width: 38px; height: 38px;
  place-items: center;
  border-radius: 10px;
  border: 1px solid var(--border);
  color: var(--text);
}

.chat {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: min(860px, 100%);
  margin: 0 auto;
  scroll-behavior: smooth;
}
.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 3px; }

/* Empty */
.empty {
  margin: auto;
  text-align: center;
  max-width: 560px;
  padding: 32px 12px;
}
.empty-icon {
  width: 60px; height: 60px; border-radius: 16px; margin: 0 auto 16px;
  display: grid; place-items: center;
  font-weight: 800; font-size: 1.4rem; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 12px 36px var(--accent-glow);
}
.empty h2 { margin: 0 0 8px; font-size: 1.4rem; letter-spacing: -0.03em; }
.empty p { margin: 0 0 22px; color: var(--muted); line-height: 1.55; font-size: 0.95rem; }
.suggestions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  text-align: left;
}
.suggestion {
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--elev);
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
  text-align: left;
  transition: border-color .12s, background .12s, transform .12s;
}
.suggestion:hover {
  border-color: rgba(139, 92, 246, 0.45);
  background: var(--hover);
  color: var(--text);
  transform: translateY(-1px);
}
.suggestion strong { display: block; color: var(--text); margin-bottom: 3px; font-size: 0.84rem; }

/* Messages */
.msg {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  animation: in .2s ease-out;
  max-width: 100%;
}
@keyframes in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
.msg.user { flex-direction: row-reverse; }
.msg-avatar {
  width: 30px; height: 30px; border-radius: 9px;
  flex-shrink: 0; display: grid; place-items: center;
  font-size: 0.68rem; font-weight: 700; color: #fff; margin-top: 2px;
}
.msg.user .msg-avatar { background: linear-gradient(135deg, #6d28d9, #4c1d95); border-radius: 50%; }
.msg.assistant .msg-avatar { background: linear-gradient(135deg, var(--accent), var(--accent-2)); }

.msg-col { max-width: min(720px, calc(100% - 42px)); min-width: 0; }
.msg-label {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 650; margin-bottom: 5px;
}
.msg.user .msg-label { text-align: right; }

.bubble {
  padding: 12px 15px;
  border-radius: 16px;
  line-height: 1.55;
  font-size: 0.94rem;
  word-break: break-word;
}
.msg.user .bubble {
  background: var(--user);
  color: #faf5ff;
  border-bottom-right-radius: 5px;
  white-space: pre-wrap;
  box-shadow: 0 4px 16px rgba(109, 40, 217, 0.22);
}
.msg.assistant .bubble {
  background: var(--elev);
  border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
  color: var(--text-2);
}

/* Tools */
.tool-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}
.tool-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,.25);
  font-size: 0.78rem;
}
.tool-item .tool-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--text-2);
}
.tool-item.running .tool-head { color: #c4b5fd; }
.tool-item.done .tool-head { color: var(--ok); }
.tool-item.failed .tool-head { color: var(--danger); }
.tool-item .tool-detail {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-left: 18px;
}
.status-line {
  font-size: 0.82rem;
  color: var(--muted);
  font-style: italic;
  margin-bottom: 8px;
}

/* Markdown */
.md p { margin: 0 0 0.7em; }
.md p:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3 { color: var(--text); margin: 0.85em 0 0.4em; line-height: 1.3; }
.md h1 { font-size: 1.15rem; }
.md h2 { font-size: 1.05rem; }
.md h3 { font-size: 1rem; }
.md ul, .md ol { margin: 0.4em 0 0.7em; padding-left: 1.3em; }
.md li { margin: 0.2em 0; }
.md code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: rgba(255,255,255,.06);
  padding: 0.12em 0.35em;
  border-radius: 4px;
  color: #e9d5ff;
}
.md pre {
  margin: 0.7em 0;
  padding: 12px 14px;
  background: #0c0c12;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow-x: auto;
}
.md pre code { background: none; padding: 0; color: #e2e8f0; font-size: 0.84rem; line-height: 1.5; }
.md strong { color: var(--text); }
.md a { color: var(--accent-2); }

.stream-body:empty::after {
  content: "●";
  color: var(--accent);
  animation: blink 1s ease-in-out infinite;
}
@keyframes blink { 50% { opacity: 0.3; } }

.msg.error-bubble .bubble {
  background: rgba(248,113,113,.1);
  border: 1px solid rgba(248,113,113,.3);
  color: #fca5a5;
}

/* Composer */
.composer-wrap {
  flex-shrink: 0;
  width: min(860px, 100%);
  margin: 0 auto;
  padding: 0 16px 14px;
}
.composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 10px 10px 10px 16px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--elev);
  box-shadow: 0 8px 28px rgba(0,0,0,.3);
  transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within {
  border-color: rgba(139, 92, 246, 0.5);
  box-shadow: 0 0 0 3px var(--accent-soft), 0 8px 28px rgba(0,0,0,.3);
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 180px;
  min-height: 44px;
  padding: 10px 0;
  border: none;
  background: transparent;
  outline: none;
  line-height: 1.45;
  font-size: 0.95rem;
}
.composer textarea::placeholder { color: var(--muted); }
.btn-send {
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center; flex-shrink: 0;
  color: #fff;
  background: linear-gradient(135deg, #8b5cf6, #6d28d9);
  box-shadow: 0 4px 14px var(--accent-glow);
  transition: transform .12s, opacity .12s;
}
.btn-send:hover:not(:disabled) { transform: scale(1.05); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }

/* Media attachments */
.composer-wrap { position: relative; }
.composer.drag-over {
  border-color: rgba(34, 211, 238, 0.7) !important;
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.18), 0 8px 28px rgba(0,0,0,.3) !important;
  background: rgba(34, 211, 238, 0.06);
}
.btn-attach {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center; flex-shrink: 0;
  color: var(--muted);
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.03);
  transition: color .15s, border-color .15s, background .15s;
}
.btn-attach:hover {
  color: var(--accent-2);
  border-color: rgba(34, 211, 238, 0.4);
  background: rgba(34, 211, 238, 0.08);
}
.attach-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 10px;
  padding: 0 2px;
}
.attach-preview[hidden] { display: none !important; }
.attach-card {
  position: relative;
  width: 92px;
  border-radius: 12px;
  border: 1px solid var(--border-2);
  background: var(--elev);
  overflow: hidden;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
.attach-card img,
.attach-card video {
  display: block;
  width: 100%;
  height: 72px;
  object-fit: cover;
  background: #000;
}
.attach-card .attach-audio {
  display: grid;
  place-items: center;
  height: 72px;
  font-size: 1.4rem;
  color: var(--accent-2);
  background: linear-gradient(145deg, rgba(139,92,246,.15), rgba(34,211,238,.1));
}
.attach-card .attach-meta {
  padding: 4px 6px 6px;
  font-size: 0.62rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attach-card .attach-remove {
  position: absolute;
  top: 4px; right: 4px;
  width: 22px; height: 22px;
  border-radius: 999px;
  background: rgba(0,0,0,.7);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.15);
}
.attach-card .attach-remove:hover { background: rgba(248,113,113,.85); }
.drop-hint {
  position: absolute;
  inset: 0 16px 40px;
  display: grid;
  place-items: center;
  border: 2px dashed rgba(34, 211, 238, 0.55);
  border-radius: 18px;
  background: rgba(10, 14, 28, 0.88);
  color: var(--accent-2);
  font-weight: 700;
  font-size: 0.95rem;
  pointer-events: none;
  z-index: 5;
}
.drop-hint[hidden] { display: none !important; }

.msg-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 8px;
}
.msg-att {
  border-radius: 12px;
  border: 1px solid var(--border-2);
  overflow: hidden;
  background: rgba(0,0,0,.25);
  max-width: 240px;
}
.msg-att img,
.msg-att video {
  display: block;
  max-width: 240px;
  max-height: 180px;
  width: auto;
  height: auto;
}
.msg-att audio {
  display: block;
  width: 240px;
  margin: 8px;
}
.msg-att .msg-att-name {
  padding: 4px 8px 6px;
  font-size: 0.68rem;
  color: var(--muted);
}


.composer-hint {
  text-align: center;
  font-size: 0.7rem;
  color: var(--muted);
  margin: 8px 0 0;
}

.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 30;
}

@media (max-width: 820px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.5);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show { display: block; }
  .icon-btn { display: grid; }
  .suggestions { grid-template-columns: 1fr; }
  .cwd-chip { display: none; }
  .pill { display: none; }
}

.queue-badge {
  margin: 0 0 8px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-2);
  background: rgba(34, 211, 238, 0.1);
  border: 1px solid rgba(34, 211, 238, 0.28);
  width: fit-content;
}
.queue-badge[hidden] { display: none !important; }
.msg-label { opacity: 0.9; }

/* Weekly quota bars (top of main) — Real = site oficial; Estim. = local rápido */
.quota-bars {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 8px 16px 7px;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 10, 15, 0.92);
  backdrop-filter: blur(10px);
}
.quota-row {
  display: grid;
  grid-template-columns: 42px 1fr 44px;
  align-items: center;
  gap: 10px;
}
.quota-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.quota-track {
  height: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.quota-track > i {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #8b5cf6, #22d3ee);
  transition: width 0.4s ease;
}
.quota-track.est > i {
  background: linear-gradient(90deg, #6366f1, #a78bfa);
  opacity: 0.9;
}
.quota-track.warn > i { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.quota-track.crit > i { background: linear-gradient(90deg, #ef4444, #f87171); }
.quota-pct {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-2);
  text-align: right;
}
.quota-pct.hot { color: #fbbf24; }
.quota-pct.crit { color: #f87171; }
