:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #2a2f3a;
  --text: #e7e9ee;
  --muted: #9aa3b2;
  --accent: #6ea8fe;
  --accent-2: #3b82f6;
  --think: #8b94a7;
  --search: #f0b86e;
  --good: #4ade80;
  --bad: #f87171;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(1200px 600px at 70% -10%, #1a2030 0%, var(--bg) 55%);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
}

/* ---- status light ---- */
.statuslight { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #555; box-shadow: 0 0 0 0 transparent; transition: all .3s; }
.dot.online { background: var(--good); box-shadow: 0 0 10px 1px rgba(74,222,128,.6); }
.dot.offline { background: var(--bad); box-shadow: 0 0 10px 1px rgba(248,113,113,.5); }

/* ---- gate ---- */
.gate-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.gate-card {
  position: relative;
  width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 32px 28px; box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.lang-toggle { position: absolute; top: 14px; right: 14px; }
.gate-card h1 { font-size: 20px; margin: 0 0 4px; }
.gate-card p { color: var(--muted); margin: 0 0 22px; font-size: 13px; }
.gate-card .statuslight { margin-bottom: 18px; }
.field { display: flex; gap: 8px; }
input[type=text], input[type=password] {
  flex: 1; background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 12px 14px; font-size: 15px; outline: none;
}
input:focus { border-color: var(--accent-2); }
button {
  background: var(--accent-2); color: white; border: 0; border-radius: 10px;
  padding: 12px 18px; font-size: 15px; font-weight: 600; cursor: pointer;
}
button:hover { background: #2f74e0; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; margin-top: 12px; }
.shake { animation: shake .4s; }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-6px)} 75%{transform:translateX(6px)} }

/* ---- chat layout ---- */
.app { display: grid; grid-template-rows: auto 1fr; height: 100vh; }
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid var(--line); background: rgba(15,17,21,.7);
  backdrop-filter: blur(6px);
}
header .title { font-weight: 600; letter-spacing: .2px; }
header .title .sub { color: var(--muted); font-weight: 400; font-size: 13px; margin-left: 8px; }

.cols { display: grid; grid-template-columns: 1fr 360px; min-height: 0; }
@media (max-width: 820px) { .cols { grid-template-columns: 1fr; } .think-col { display: none; } }

/* chat column */
.chat-col { display: flex; flex-direction: column; min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.msg { max-width: 760px; }
.msg .role { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin-bottom: 5px; }
.msg .bubble { padding: 13px 17px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; font-size: 16.5px; line-height: 1.6; }
.msg.user { align-self: flex-end; }
.msg.user .bubble { background: var(--accent-2); color: white; border-bottom-right-radius: 4px; }
.msg.user .role { text-align: right; }
.msg.assistant .bubble { background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; }

.chat-col { position: relative; }
.composer-wrap { border-top: 1px solid var(--line); background: var(--bg); padding: 12px 20px; }
.composer { display: flex; gap: 10px; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 12px 14px; font: inherit; font-size: 16px; max-height: 160px; outline: none;
}
.composer textarea:focus { border-color: var(--accent-2); }

/* thinking column */
.think-col { background: #12141a; border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.think-head { padding: 12px 16px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .8px; }
.think-body { flex: 1; overflow-y: auto; padding: 14px 16px; font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--think); white-space: pre-wrap; word-wrap: break-word; }
.think-body .search { color: var(--search); }
.think-body .sep { color: var(--line); margin: 10px 0; }
.think-body:empty::before { content: attr(data-empty); color: #4b5263; }

.cursor::after { content: "▋"; color: var(--accent); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* header right group + ghost button */
.header-right { display: flex; align-items: center; gap: 16px; }
button.ghost {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  padding: 6px 12px; font-size: 13px; font-weight: 500; border-radius: 8px;
}
button.ghost:hover { background: var(--panel-2); color: var(--text); }

/* attach button + chip */
.attach-btn {
  display: grid; place-items: center; width: 42px; height: 42px; flex: 0 0 auto;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px;
  cursor: pointer; font-size: 18px; user-select: none;
}
.attach-btn:hover { border-color: var(--accent-2); }
.attach-row:empty { display: none; }
.attach-row { margin-bottom: 8px; display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; max-width: 100%;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 999px; padding: 6px 6px 6px 12px; font-size: 12.5px;
}
.chip b { font-weight: 600; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip span { color: var(--muted); }
.chip.warn { color: var(--search); border-color: var(--search); padding-right: 12px; }
.chip-x {
  background: transparent; border: 0; color: var(--muted); cursor: pointer;
  font-size: 16px; line-height: 1; padding: 2px 6px; border-radius: 50%;
}
.chip-x:hover { color: var(--text); background: var(--line); }

/* drag-and-drop overlay */
.drop-overlay {
  position: absolute; inset: 0; display: none; place-items: center;
  background: rgba(59,130,246,.12); border: 2px dashed var(--accent-2);
  color: var(--accent); font-size: 16px; font-weight: 600; z-index: 5; pointer-events: none;
}
.drop-overlay.show { display: grid; }
