:root {
  --bg: #0e0e10;
  --panel: #141416;
  --panel2: #18181b;
  --line: #26262b;
  --text: #e9e7e2;
  --muted: #8b8b94;
  --accent: #e2a13c;
  --accent-dim: #9c7028;
  --accent-soft: rgba(226, 161, 60, 0.12);
  --danger: #e05d5d;
  --ok: #68b06a;
  --fh: 'Space Grotesk', sans-serif;
  --fb: 'Inter', sans-serif;
  --fm: 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--fb);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.mono { font-family: var(--fm); }
.only-mobile { display: none; }

button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; color: var(--text); }

::selection { background: var(--accent-soft); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2a2a2f; border-radius: 5px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

.mark { width: 22px; height: 22px; flex: none; }
.mark path { fill: var(--accent); }
.mark.big { width: 42px; height: 42px; opacity: 0.9; }

.brand { display: flex; align-items: center; gap: 10px; }
.wordmark { font-family: var(--fh); font-weight: 700; font-size: 19px; letter-spacing: -0.02em; }
.wm-ai { color: var(--accent); }

.errline {
  color: var(--danger);
  font-size: 13.5px;
  padding: 8px 0;
}

/* ---------- Auth ---------- */

.auth { min-height: 100dvh; display: grid; grid-template-columns: 1fr 1fr; }

.auth-left {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 44px 48px;
}

.tagline {
  font-family: var(--fh);
  font-weight: 600;
  font-size: clamp(30px, 3.4vw, 46px);
  line-height: 1.14;
  letter-spacing: -0.02em;
}

.tagsub { color: var(--muted); margin-top: 16px; max-width: 380px; font-size: 15px; }

.tiersline {
  font-family: var(--fm);
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.08em;
}

.auth-right { display: flex; align-items: center; justify-content: center; padding: 32px 20px; }

.auth-card { width: 100%; max-width: 360px; }

.atabs { display: flex; border-bottom: 1px solid var(--line); margin-bottom: 24px; }

.atabs button {
  flex: 1;
  background: none;
  border: none;
  color: var(--muted);
  font-family: var(--fh);
  font-weight: 600;
  font-size: 15px;
  padding: 12px 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 150ms, border-color 150ms;
}

.atabs button.on { color: var(--text); border-bottom-color: var(--accent); }

.auth-card label {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
  margin: 14px 0 6px;
}

.auth-card input {
  width: 100%;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 14.5px;
  outline: none;
  transition: border-color 150ms;
}

.auth-card input:focus { border-color: var(--accent-dim); }

.primary {
  width: 100%;
  margin-top: 20px;
  background: var(--accent);
  color: #131313;
  border: none;
  border-radius: 7px;
  padding: 11px 0;
  font-family: var(--fh);
  font-weight: 600;
  font-size: 15px;
  transition: filter 150ms;
}

.primary:hover { filter: brightness(1.08); }

.finehint { color: var(--muted); font-size: 12px; margin-top: 12px; text-align: center; }

/* ---------- App layout ---------- */

.app { display: flex; height: 100dvh; overflow: hidden; }

.side {
  width: 248px;
  flex: none;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  gap: 18px;
}

.newchat {
  background: none;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 7px;
  padding: 9px 12px;
  font-size: 14px;
  text-align: left;
  transition: border-color 150ms, background 150ms;
}

.newchat:hover { border-color: var(--accent-dim); background: var(--accent-soft); }

.side-sec { border-top: 1px solid var(--line); padding-top: 16px; }

.side-label {
  font-family: var(--fm);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  margin-bottom: 10px;
}

.uline { font-family: var(--fm); font-size: 13px; font-variant-numeric: tabular-nums; }
.uline.sub { color: var(--muted); font-size: 12px; margin-top: 8px; }

.bar { height: 3px; background: var(--panel2); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 300ms; }

.side-spacer { flex: 1; }

.side-user { border-top: 1px solid var(--line); padding-top: 14px; }

.uname { font-family: var(--fh); font-weight: 600; font-size: 15px; }
.urole { color: var(--muted); font-size: 12.5px; margin-bottom: 10px; }

.side-links { display: flex; gap: 14px; }

.linkbtn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  padding: 0;
  transition: color 150ms;
}

.linkbtn:hover { color: var(--accent); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.top {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
}

.menubtn {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 19px;
  padding: 2px 6px;
}

.toptier {
  font-family: var(--fh);
  font-weight: 600;
  font-size: 14.5px;
  color: var(--muted);
  flex: 1;
}

.pill {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 12px 7px;
  min-width: 130px;
}

.pill span {
  font-family: var(--fm);
  font-size: 11.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.pbar { height: 2px; background: var(--panel2); margin-top: 5px; border-radius: 1px; overflow: hidden; }
.pbar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 300ms; }

/* ---------- Chat ---------- */

.scroll { flex: 1; overflow-y: auto; }

.inner { max-width: 800px; margin: 0 auto; padding: 0 24px; }

.welcome { text-align: center; padding: 110px 20px 60px; }

.welcome h1 {
  font-family: var(--fh);
  font-weight: 700;
  font-size: 27px;
  letter-spacing: -0.02em;
  margin-top: 18px;
}

.welcome p { color: var(--muted); margin-top: 8px; font-size: 14.5px; }

.msg { padding: 20px 0 22px; border-bottom: 1px solid var(--line); }

.who {
  font-family: var(--fm);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  color: var(--muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
}

.msg.ai .who { color: var(--accent); }

.tick { width: 7px; height: 7px; background: var(--accent); margin-right: 8px; flex: none; }

.mbody { font-size: 15px; line-height: 1.65; overflow-wrap: break-word; }

.msg.user .mbody { color: #d6d4ce; white-space: pre-wrap; }

.mbody p { margin: 0 0 12px; }
.mbody p:last-child { margin-bottom: 0; }
.mbody ul, .mbody ol { margin: 0 0 12px 22px; }
.mbody li { margin-bottom: 4px; }

.mbody h1, .mbody h2, .mbody h3, .mbody h4 {
  font-family: var(--fh);
  letter-spacing: -0.01em;
  margin: 20px 0 10px;
}

.mbody h1 { font-size: 21px; }
.mbody h2 { font-size: 18px; }
.mbody h3 { font-size: 16px; }
.mbody h4 { font-size: 15px; }

.mbody a { color: var(--accent); }

.mbody blockquote {
  border-left: 2px solid var(--accent-dim);
  padding-left: 14px;
  color: var(--muted);
  margin: 0 0 12px;
}

.mbody table { border-collapse: collapse; margin: 0 0 12px; font-size: 13.5px; }
.mbody th, .mbody td { border: 1px solid var(--line); padding: 6px 10px; }
.mbody th { font-family: var(--fh); font-weight: 600; }

.mbody code {
  font-family: var(--fm);
  font-size: 13px;
  background: #1c1c20;
  border-radius: 4px;
  padding: 1.5px 6px;
}

.mbody pre { margin: 0; }

.mbody pre code {
  display: block;
  background: #131316;
  padding: 14px 16px;
  overflow-x: auto;
  border-radius: 0;
  line-height: 1.55;
}

.codewrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  margin: 14px 0;
}

.codehead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #1a1a1e;
  border-bottom: 1px solid var(--line);
  padding: 6px 12px;
}

.fname { font-family: var(--fm); font-size: 12px; color: var(--muted); }

.facts { display: flex; gap: 4px; }

.facts button {
  background: none;
  border: none;
  color: var(--muted);
  font-family: var(--fm);
  font-size: 11.5px;
  padding: 3px 8px;
  border-radius: 4px;
  transition: color 150ms, background 150ms;
}

.facts button:hover { color: var(--accent); background: var(--accent-soft); }

.ftag {
  display: inline-block;
  font-family: var(--fm);
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 3px 10px;
  margin-top: 10px;
}

.cursor {
  display: inline-block;
  width: 8px;
  height: 15px;
  background: var(--accent);
  vertical-align: -2px;
  animation: blink 1s steps(2) infinite;
}

@keyframes blink { 50% { opacity: 0; } }

.genimg { max-width: min(480px, 100%); border: 1px solid var(--line); border-radius: 8px; display: block; }

.imgdl {
  margin-top: 10px;
  background: none;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 16px;
  font-size: 13px;
  transition: border-color 150ms;
}

.imgdl:hover { border-color: var(--accent-dim); }

.imgload { color: var(--muted); font-size: 14px; }

.agents { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

.agent {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  min-width: 0;
}

.agent.done { border-color: #2e3c2e; }
.agent.err { border-color: #43292b; }

.ahead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #1a1a1e;
  border-bottom: 1px solid var(--line);
  padding: 6px 12px;
  font-family: var(--fm);
  font-size: 11.5px;
}

.astat { color: var(--muted); }
.agent.done .astat { color: var(--ok); }
.agent.err .astat { color: var(--danger); }

.abody { padding: 12px; font-size: 13px; max-height: 420px; overflow-y: auto; }
.abody pre code { font-size: 12px; }

/* ---------- Bottom / composer ---------- */

.bottom { border-top: 1px solid var(--line); }

.zipbar, .chips, .composer { max-width: 800px; margin: 0 auto; padding-left: 24px; padding-right: 24px; }

.zipbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  padding-top: 8px;
  padding-bottom: 8px;
  border-left: 2px solid var(--accent);
  background: var(--accent-soft);
}

.zipbar span { font-family: var(--fm); font-size: 12.5px; color: var(--muted); }

.zipbar button {
  background: var(--accent);
  color: #131313;
  border: none;
  border-radius: 6px;
  padding: 6px 14px;
  font-family: var(--fh);
  font-weight: 600;
  font-size: 13px;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 12px; }

.chips button {
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 13.5px;
  transition: border-color 150ms, background 150ms;
}

.chips button:hover { border-color: var(--accent-dim); background: var(--accent-soft); }

.composer { padding-top: 12px; padding-bottom: 16px; }

.tiers { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }

.seg { display: flex; gap: 2px; border: 1px solid var(--line); border-radius: 7px; padding: 2px; }

.seg button {
  background: none;
  border: none;
  color: var(--muted);
  font-family: var(--fm);
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 5px;
  transition: color 150ms, background 150ms;
}

.seg button.on { color: var(--accent); background: var(--accent-soft); }

.tier-hint { color: var(--muted); font-size: 12px; }

.filepill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--accent-dim);
  border-radius: 6px;
  padding: 4px 10px;
  margin-bottom: 10px;
  font-family: var(--fm);
  font-size: 12px;
}

.filepill button { background: none; border: none; color: var(--muted); font-size: 15px; padding: 0 2px; }
.filepill button:hover { color: var(--danger); }

.box {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  transition: border-color 150ms;
}

.box:focus-within { border-color: var(--accent-dim); }

.tool {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 15px;
  padding: 7px 8px;
  border-radius: 6px;
  line-height: 1;
  transition: color 150ms, background 150ms;
}

.tool:hover { color: var(--accent); background: var(--accent-soft); }

#input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  resize: none;
  font-size: 15px;
  line-height: 1.5;
  padding: 7px 4px;
  max-height: 200px;
}

#input::placeholder { color: #5c5c64; }

.send {
  background: var(--accent);
  color: #131313;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 8px 18px;
  font-family: var(--fh);
  font-weight: 600;
  font-size: 14px;
  transition: filter 150ms;
}

.send:hover { filter: brightness(1.08); }

.send.stop { background: none; border-color: var(--danger); color: var(--danger); }

/* ---------- Admin modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 60;
}

.modal-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  width: 100%;
  max-width: 980px;
  max-height: 86dvh;
  overflow-y: auto;
  padding: 20px 22px;
}

.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }

.modal-head h2 { font-family: var(--fh); font-size: 19px; }

.modal-head button {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 22px;
  padding: 0 6px;
}

.modal-head button:hover { color: var(--text); }

.create-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }

.create-row input {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13.5px;
  outline: none;
  flex: 1;
  min-width: 120px;
}

.create-row input:focus { border-color: var(--accent-dim); }

.create-row .primary { width: auto; margin: 0; padding: 8px 16px; font-size: 13.5px; flex: none; }

.table-wrap { overflow-x: auto; }

#uTable { width: 100%; border-collapse: collapse; font-size: 13px; }

#uTable th {
  font-family: var(--fm);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

#uTable td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.role { font-family: var(--fm); font-size: 11.5px; padding: 2px 8px; border-radius: 4px; }
.r-free { background: var(--panel2); color: var(--muted); }
.r-premium { background: var(--accent-soft); color: var(--accent); }
.r-admin { background: #2a2331; color: #b48ede; }

.acts { display: flex; gap: 2px; }

.acts button {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 12px;
  padding: 3px 7px;
  border-radius: 4px;
  transition: color 150ms, background 150ms;
}

.acts button:hover { color: var(--accent); background: var(--accent-soft); }
.acts button.del:hover { color: var(--danger); background: rgba(224, 93, 93, 0.1); }

/* ---------- Responsive ---------- */

@media (max-width: 920px) {
  .only-mobile { display: flex; margin-bottom: 22px; }

  .auth { grid-template-columns: 1fr; }
  .auth-left { display: none; }

  .side {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 200ms;
    box-shadow: 8px 0 30px rgba(0, 0, 0, 0.4);
  }

  .side.open { transform: none; }

  .menubtn { display: block; }

  .inner, .zipbar, .chips, .composer { padding-left: 16px; padding-right: 16px; }

  .agents { grid-template-columns: 1fr; }

  .tier-hint { display: none; }

  .pill { min-width: 100px; }

  .welcome { padding-top: 70px; }
}
