:root {
  --bg: #050506;
  --panel: #0a0a0c;
  --panel-2: #101013;
  --panel-3: #151519;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #f6f6f7;
  --muted: #9a9aa3;
  --muted-2: #6b6b74;
  --accent: #ffffff;
  --link: #8ab4ff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(1100px 520px at 75% -12%, rgba(255, 255, 255, 0.055), transparent 60%),
    radial-gradient(900px 480px at -10% 110%, rgba(255, 255, 255, 0.035), transparent 60%),
    var(--bg);
}

.hidden { display: none !important; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.09); border-radius: 999px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.16); background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ==== LOGIN ==== */
.login { height: 100%; display: grid; place-items: center; }
.login-card {
  width: 360px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.01)), var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 34px 30px 30px;
  text-align: center;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.login-card .mark {
  width: 46px; height: 46px;
  margin: 0 auto 14px;
  display: grid; place-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  font-weight: 700;
  font-size: 19px;
  letter-spacing: 0.02em;
  background: linear-gradient(180deg, #1a1a1e, #0e0e11);
}
.login-card h1 {
  font-size: 15px;
  letter-spacing: 0.34em;
  font-weight: 600;
  margin: 0 0 6px;
  text-indent: 0.34em;
}
.login-card .tagline { color: var(--muted); font-size: 12px; margin: 0 0 22px; letter-spacing: 0.04em; }
.login-card input {
  width: 100%;
  padding: 12px 13px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  margin-bottom: 12px;
  outline: none;
}
.login-card input:focus { border-color: var(--border-strong); box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.05); }
.login-card button {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 12px;
  background: #fff;
  color: #0a0a0a;
  font-weight: 650;
  cursor: pointer;
  letter-spacing: 0.02em;
}
.login-card button:hover { background: #e7e7ea; }
.login-card .error { color: #f87171; font-size: 12px; min-height: 16px; margin-top: 8px; }

/* ==== LAYOUT ==== */
.app { display: flex; height: 100%; }

.sidebar {
  width: 284px;
  min-width: 284px;
  background: rgba(255, 255, 255, 0.016);
  border-right: 1px solid var(--border);
  padding: 18px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand { display: flex; align-items: center; gap: 11px; padding: 2px 8px 18px; }
.brand .mark {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 11px;
  font-weight: 700; font-size: 15px;
  background: linear-gradient(180deg, #1b1b1f, #0d0d10);
}
.brand-text { display: flex; flex-direction: column; }
.wordmark { font-size: 13px; font-weight: 650; letter-spacing: 0.30em; }
.brand-sub { font-size: 9px; letter-spacing: 0.30em; color: var(--muted-2); text-transform: uppercase; margin-top: 1px; }

.section-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--muted-2);
  padding: 16px 10px 8px;
}

.bot {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.bot:hover { background: rgba(255, 255, 255, 0.04); }
.bot.active {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--border);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}
.avatar {
  width: 36px; height: 36px;
  border-radius: 12px;
  border: 1px solid;
  display: grid;
  place-items: center;
  font-size: 17px;
}
.avatar.small { width: 32px; height: 32px; font-size: 15px; border-radius: 10px; }
.bot-meta { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.bot-name { font-weight: 600; font-size: 13.5px; letter-spacing: 0.01em; }
.bot-role { color: var(--muted); font-size: 11px; letter-spacing: 0.03em; }
.dot { width: 7px; height: 7px; border-radius: 50%; }
.dot.on { background: #34d399; box-shadow: 0 0 10px rgba(52, 211, 153, 0.55); }
.dot.err { background: #fbbf24; }
.dot.off { background: #3f3f46; }

.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav button {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px;
  border: none; border-radius: 12px;
  background: transparent; color: var(--text);
  font-size: 13px; cursor: pointer; text-align: left;
  letter-spacing: 0.01em;
}
.sidebar nav button:hover { background: rgba(255, 255, 255, 0.04); }
.sidebar .foot {
  margin-top: auto;
  color: var(--muted-2);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  padding: 12px 10px 6px;
  border-top: 1px solid var(--border);
  line-height: 1.7;
}

/* ==== MAIN ==== */
main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  gap: 14px;
  backdrop-filter: blur(12px);
}
.topbar-left { display: flex; align-items: center; gap: 13px; min-width: 0; }
.topbar-title { font-weight: 620; font-size: 14.5px; letter-spacing: 0.01em; }
.topbar-sub { color: var(--muted); font-size: 11.5px; letter-spacing: 0.02em; }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.status { font-size: 11px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; letter-spacing: 0.04em; }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #3f3f46; }
.status.on::before { background: #34d399; box-shadow: 0 0 8px rgba(52, 211, 153, 0.6); }
.status.off::before { background: #fbbf24; }

.ghost {
  background: transparent; color: var(--text);
  border: 1px solid var(--border); border-radius: 11px;
  padding: 7px 13px; font-size: 12.5px; cursor: pointer;
}
.ghost:hover { background: rgba(255, 255, 255, 0.05); border-color: var(--border-strong); }

.messages { flex: 1; overflow-y: auto; padding: 26px 24px 12px; display: flex; flex-direction: column; gap: 16px; }
.msg { display: flex; flex-direction: column; max-width: 860px; width: 100%; margin: 0 auto; }
.msg.user { align-items: flex-end; }
.bubble {
  padding: 12px 15px;
  border-radius: 16px;
  max-width: 78%;
  overflow-wrap: anywhere;
  font-size: 13.8px;
}
.msg.user .bubble { background: #17171b; border: 1px solid var(--border); }
.msg.assistant .bubble { background: rgba(255, 255, 255, 0.022); border: 1px solid var(--border); }
.bubble pre {
  background: #0b0b0e; border: 1px solid var(--border);
  padding: 12px; border-radius: 12px; overflow-x: auto; font-size: 12.5px;
}
.bubble code { background: rgba(255, 255, 255, 0.06); padding: 1px 6px; border-radius: 6px; font-size: 12.5px; }
.bubble pre code { background: none; padding: 0; }
.bubble a { color: var(--link); text-decoration: none; }
.bubble a:hover { text-decoration: underline; }
.bubble { line-height: 1.5; }
.bubble p { margin: 0 0 9px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble h2, .bubble h3, .bubble h4 { margin: 16px 0 7px; line-height: 1.28; font-weight: 650; }
.bubble h2:first-child, .bubble h3:first-child, .bubble h4:first-child { margin-top: 0; }
.bubble h2 { font-size: 16.5px; color: #ffffff; }
.bubble h3 { font-size: 14.5px; color: #f0f0f3; }
.bubble h4 { font-size: 13.5px; color: #e6e6ea; }
.bubble ul, .bubble ol { margin: 5px 0 11px; padding-left: 21px; display: flex; flex-direction: column; gap: 6px; }
.bubble li { line-height: 1.52; }
.bubble li::marker { color: var(--muted); }
.bubble hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.bubble blockquote { margin: 9px 0; padding: 7px 13px; border-left: 2px solid var(--border-strong); color: var(--muted); }
.bubble table { border-collapse: collapse; margin: 9px 0 13px; width: 100%; font-size: 12.8px; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
.bubble th { background: rgba(255, 255, 255, 0.045); font-weight: 600; color: #ffffff; }
.bubble img { max-width: 100%; height: auto; border-radius: 10px; margin: 9px 0; border: 1px solid var(--border); display: block; }
.bubble strong { color: #ffffff; }
.msg.delivery { align-items: stretch; max-width: 1060px; }
.msg.delivery .bubble {
  max-width: 100%;
  background: #131317;
  border-color: var(--border-strong);
  border-left: 3px solid var(--border-strong);
}
.msg.delivery .bubble img { width: 100%; height: auto; }

.thinking-line {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 12.5px;
  letter-spacing: 0.03em;
  padding: 4px 2px;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
}
.dots { display: inline-flex; gap: 4px; }
.dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.35;
  animation: jb-dot 1.2s infinite ease-in-out;
}
.dots i:nth-child(2) { animation-delay: 0.18s; }
.dots i:nth-child(3) { animation-delay: 0.36s; }
@keyframes jb-dot {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

.tools { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.pill {
  font-size: 10.5px; color: var(--muted);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 3px 10px; background: rgba(255, 255, 255, 0.02);
  letter-spacing: 0.03em;
}

/* ==== COMPOSER ==== */
.composer {
  display: flex; gap: 10px; align-items: flex-end;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
}
.composer textarea {
  flex: 1; resize: none;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 14px;
  padding: 12px 14px; font: inherit; outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.composer textarea:focus { border-color: var(--border-strong); box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.05); }
.composer > button:not(.attach-btn) {
  background: #fff; color: #0a0a0a; border: none;
  border-radius: 14px; padding: 12px 20px; font-weight: 650; cursor: pointer;
  min-height: 46px; letter-spacing: 0.02em;
}
.composer > button:not(.attach-btn):hover { background: #e7e7ea; }
.composer button:disabled { opacity: 0.45; }

.attach-btn {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 14px;
  width: 48px;
  min-height: 46px;
  font-size: 17px;
  cursor: pointer;
}
.attach-btn:hover { background: #17171b; border-color: var(--border-strong); }
.attach-strip { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 14px 24px 0; }
.attach-item { position: relative; display: inline-flex; }
.attach-item img, .thumb-img {
  height: 66px; width: auto;
  border-radius: 10px;
  border: 1px solid var(--border);
  cursor: zoom-in;
}
.attach-item .remove {
  position: absolute; top: -7px; right: -7px;
  background: #17171b; color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 50%;
  width: 20px; height: 20px; font-size: 10.5px; cursor: pointer; line-height: 1;
}
.vision-hint { font-size: 11px; color: var(--link); letter-spacing: 0.03em; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; max-width: 78%; }
.msg.user .thumbs { justify-content: flex-end; margin-left: auto; }

.model-select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 8px 11px;
  font-size: 12.5px;
  max-width: 360px;
  outline: none;
  letter-spacing: 0.01em;
}
.model-select:hover { border-color: var(--border-strong); }

/* ==== ROUTINES ==== */
.routines { flex: 1; overflow-y: auto; padding: 24px; }
.routines table { width: 100%; border-collapse: collapse; }
.routines th, .routines td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
.routines th { color: var(--muted-2); font-weight: 500; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.14em; }
.routines code { background: rgba(255, 255, 255, 0.06); padding: 2px 7px; border-radius: 6px; font-size: 12px; }
.muted { color: var(--muted); }
.routine-form input {
  flex: 1; min-width: 0;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 11px 13px; font: inherit; outline: none;
}
.routine-form input:focus { border-color: var(--border-strong); }
.routine-form input.grow { flex: 2; }

/* ==== RIGHT RAIL (routines) ==== */
.main-row { display: flex; flex: 1; min-height: 0; }
.chat-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.rail {
  width: 304px;
  min-width: 304px;
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px 14px 20px;
  background: rgba(255, 255, 255, 0.012);
  position: relative;
}
.rail-resizer {
  position: absolute;
  left: -3px;
  top: 0;
  bottom: 0;
  width: 7px;
  cursor: col-resize;
  z-index: 5;
}
.rail-resizer:hover, body.resizing .rail-resizer { background: rgba(255, 255, 255, 0.09); }
body.resizing { cursor: col-resize; user-select: none; }
.rail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 4px 12px 8px;
}
.rail-head-text { display: flex; flex-direction: column; gap: 2px; }
.rail-collapse {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  width: 26px;
  height: 26px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  flex: none;
}
.rail-collapse:hover { color: var(--text); border-color: var(--border-strong); background: rgba(255, 255, 255, 0.05); }
.ghost.active { background: rgba(255, 255, 255, 0.08); border-color: var(--border-strong); }
.rail-title { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.18em; color: var(--muted-2); }
.rail-sub { font-size: 10.5px; color: var(--muted-2); }
.rail-list { display: flex; flex-direction: column; gap: 3px; }
.rail-item { display: flex; align-items: center; gap: 10px; padding: 9px 9px; border-radius: 12px; }
.rail-item:hover { background: rgba(255, 255, 255, 0.035); }
.rail-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; box-shadow: 0 0 8px rgba(255, 255, 255, 0.12); }
.rail-meta { flex: 1; min-width: 0; }
.rail-name { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: 0.01em; }
.rail-sched { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rail-state { font-size: 9.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted-2); flex: none; }
.rail-state.active { color: #34d399; }
.rail-state.paused { color: #fbbf24; }

@media (max-width: 1100px) {
  .rail { display: none; }
}

@media (max-width: 860px) {
  .sidebar { width: 76px; min-width: 76px; }
  .bot-meta, .section-label, .sidebar .foot, .brand-text { display: none; }
  .bubble { max-width: 92%; }
  .model-select { max-width: 160px; }
}
