:root {
  --bg: #0b0d10;
  --panel: #12151a;
  --panel-2: #1a1e26;
  --border: #23262d;
  --text: #e7e9ee;
  --muted: #8a90a0;
  --accent: #18a0fb;
  --accent-2: #2fb1ff;
  --success: #46d69f;
  --danger: #ef5a5a;
  --warning: #f5a524;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
button { font-family: inherit; }
input, textarea { font-family: inherit; font-size: 16px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.brand {
  font-weight: 700;
  letter-spacing: -0.01em;
}
.brand-dot {
  display: inline-block; width: 8px; height: 8px; background: var(--accent);
  border-radius: 50%; margin-right: 8px; vertical-align: middle;
}

/* ============ LOGIN / TESTAR ============ */
.center-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px 16px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  width: 100%;
  max-width: 420px;
}
.card h1 { margin: 0 0 6px; font-size: 22px; }
.card .sub { color: var(--muted); font-size: 14px; margin: 0 0 20px; }
.card label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
.card input {
  width: 100%; padding: 12px 14px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  outline: none;
}
.card input:focus { border-color: var(--accent); }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px;
  background: var(--accent); color: #001529;
  border: none; border-radius: 10px;
  padding: 12px 16px; font-weight: 700; cursor: pointer;
  width: 100%;
  margin-top: 14px;
  transition: filter .12s;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.secondary {
  background: transparent; color: var(--text);
  border: 1px solid var(--border);
}
.msg { margin-top: 12px; font-size: 13px; min-height: 18px; }
.msg.err { color: var(--danger); }
.msg.ok { color: var(--success); }
.footer-note { margin-top: 18px; font-size: 12px; color: var(--muted); text-align: center; }
.footer-note a { color: var(--muted); text-decoration: underline; }

/* ============ APP (chat) ============ */
.app-shell {
  display: flex; flex-direction: column;
  min-height: 100vh; min-height: 100dvh;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  gap: 12px;
}
.topbar .left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar .brand-txt {
  font-weight: 700; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar .brand-txt .sub { color: var(--muted); font-weight: 500; margin-left: 6px; font-size: 12px; }
.pill {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border);
  padding: 4px 10px; border-radius: 999px; font-size: 12px;
}
.pill.warning { color: var(--warning); border-color: #4d3a12; }
.pill.danger { color: var(--danger); border-color: #4a1a1a; }
.topbar .right { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; cursor: pointer;
  font-size: 13px;
}
.icon-btn:hover { color: var(--text); }

.tabs {
  display: flex; gap: 6px;
  padding: 8px 8px 0;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tab {
  background: transparent; border: none; color: var(--muted);
  padding: 10px 12px;
  border-radius: 10px 10px 0 0;
  cursor: pointer;
  font-size: 14px; font-weight: 600;
  white-space: nowrap;
  position: relative;
}
.tab.active { color: var(--text); background: var(--bg); box-shadow: inset 0 -2px 0 var(--accent); }
.tab .lock { font-size: 11px; margin-left: 4px; color: var(--muted); }

.chat {
  flex: 1;
  display: flex; flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.bubble {
  max-width: 82%;
  padding: 10px 13px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  font-size: 15px;
  line-height: 1.5;
}
.bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: #001529;
  border-bottom-right-radius: 4px;
}
.bubble.assistant {
  align-self: flex-start;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.bubble.assistant.system {
  background: transparent; border-style: dashed; color: var(--muted);
}
.bubble.exercise {
  align-self: stretch;
  max-width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
}
.bubble.exercise h4 { margin: 0 0 8px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.bubble.exercise .stem { margin-bottom: 12px; font-size: 15px; }
.bubble.exercise .options { display: flex; flex-direction: column; gap: 6px; }
.bubble.exercise .options button {
  text-align: left; background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 10px 12px; border-radius: 10px; cursor: pointer;
}
.bubble.exercise .options button:hover { border-color: var(--accent); }
.bubble.exercise .options button:disabled { opacity: .5; cursor: default; }
.bubble.correction { border-color: var(--success); }
.bubble.correction.wrong { border-color: var(--danger); }
.bubble .cv-actions { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }

.composer {
  display: flex; gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--border);
  background: var(--panel);
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
}
.composer textarea {
  flex: 1;
  resize: none;
  min-height: 44px; max-height: 140px;
  padding: 12px 14px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
  outline: none;
  font-size: 15px;
}
.composer textarea:focus { border-color: var(--accent); }
.composer button {
  align-self: stretch;
  background: var(--accent); color: #001529;
  border: none; border-radius: 12px;
  padding: 0 18px; font-weight: 700; cursor: pointer;
  min-width: 68px;
}
.composer button:disabled { opacity: .5; cursor: not-allowed; }

.lock-panel {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.lock-card {
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: 14px;
  padding: 22px;
  max-width: 480px;
  text-align: center;
}
.lock-card h3 { margin: 0 0 10px; }
.lock-card p { color: var(--muted); margin: 0 0 14px; }

.limit-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: #2a1512; border: 1px solid #4a1a1a; color: #ffbdbd;
  padding: 12px; border-radius: 10px; margin: 10px 14px; font-size: 14px;
}
.limit-banner .actions { display: flex; gap: 6px; }
.limit-banner a { color: #ffbdbd; text-decoration: underline; }
.dot-typing { display: inline-flex; gap: 4px; padding: 4px; }
.dot-typing span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--muted);
  animation: bounce 1.2s infinite ease-in-out;
}
.dot-typing span:nth-child(2) { animation-delay: .15s; }
.dot-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); opacity: .4 } 40% { transform: translateY(-4px); opacity: 1 } }

@media (max-width: 480px) {
  .tabs { padding-left: 6px; padding-right: 6px; }
  .tab { padding: 10px 10px; font-size: 13px; }
  .topbar .brand-txt .sub { display: none; }
  .bubble { max-width: 90%; }
}
