:root {
  --bg: #070b0f;
  --panel: #0d1318;
  --panel-2: #111a20;
  --line: #24313a;
  --line-soft: #172229;
  --text: #edf4f5;
  --muted: #83939c;
  --acid: #b7ff3c;
  --cyan: #54e4dc;
  --danger: #ff6b68;
  --radius: 18px;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
dialog { width: min(540px, 92vw); max-height: 90dvh; overflow: auto; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 26px; }
dialog::backdrop { background: rgba(0,0,0,.7); }
dialog form { display: grid; gap: 12px; }
dialog p { color: var(--muted); font-size: 13px; line-height: 1.6; }
dialog textarea { border: 1px solid var(--line); border-radius: 8px; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 78% -10%, rgba(84, 228, 220, .12), transparent 36%),
    linear-gradient(135deg, #070b0f 0%, #081015 55%, #070b0f 100%);
}
button, input, select, textarea { font: inherit; }
button, select, input { min-height: 42px; }
button { cursor: pointer; }

.shell { height: 100dvh; min-height: 0; display: grid; grid-template-columns: 300px minmax(0,1fr); overflow: hidden; }
.rail {
  min-height: 0;
  overflow-y: auto;
  padding: 30px 24px;
  border-right: 1px solid var(--line);
  background: rgba(7, 12, 16, .78);
  backdrop-filter: blur(18px);
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark { width: 48px; height: 48px; border: 1px solid #3f535c; display: grid; place-content: center; gap: 3px; transform: rotate(45deg); }
.brand-mark span { width: 19px; height: 3px; background: var(--acid); display: block; }
.brand-mark span:nth-child(2) { width: 12px; background: var(--cyan); }
.brand-mark span:nth-child(3) { width: 7px; }
.eyebrow { margin: 0 0 5px; color: var(--cyan); font: 600 11px/1.2 ui-monospace, monospace; letter-spacing: .16em; }
h1, h2 { margin: 0; letter-spacing: -.04em; }
h1 { font-size: 27px; }
h2 { font-size: clamp(28px, 4vw, 46px); }

.status-card, .route-card { border: 1px solid var(--line); background: linear-gradient(145deg, rgba(20, 31, 37, .85), rgba(10, 16, 20, .85)); border-radius: var(--radius); padding: 16px; }
.status-heading { display: flex; align-items: center; gap: 9px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #ffbc42; box-shadow: 0 0 16px #ffbc42; }
.status-dot.online { background: var(--acid); box-shadow: 0 0 16px var(--acid); }
.status-dot.offline { background: var(--danger); box-shadow: 0 0 16px var(--danger); }
.status-card p, .hint { color: var(--muted); font-size: 12px; line-height: 1.55; margin: 8px 0 0; }
.control-block { display: grid; gap: 9px; }
.control-block label { color: #b9c7cd; font-size: 12px; font-weight: 600; }
.control-block input, .control-block select {
  width: 100%; color: var(--text); border: 1px solid var(--line); background: #0b1115; border-radius: 10px; padding: 0 12px; outline: none;
}
.control-block input:focus, .control-block select:focus, textarea:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(84, 228, 220, .1); }
.secret-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.icon-button, .secondary { color: #cad5d9; border: 1px solid var(--line); background: #10181d; border-radius: 10px; padding: 0 13px; }
.two-column { grid-template-columns: 1fr 90px; align-items: center; }
.rail-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.route-card { margin-top: auto; }
.route-card span { color: var(--acid); font: 600 10px/1 ui-monospace, monospace; letter-spacing: .15em; }
.route-card code { display: block; color: var(--muted); white-space: normal; font-size: 11px; line-height: 1.6; margin-top: 8px; }

.workspace { min-width: 0; min-height: 0; height: 100dvh; display: grid; grid-template-rows: auto minmax(0,1fr) auto; }
.topbar { padding: 28px clamp(22px, 5vw, 72px) 20px; display: flex; justify-content: space-between; align-items: end; border-bottom: 1px solid var(--line-soft); }
.metric-strip { display: flex; gap: 9px; }
.metric-strip div { min-width: 86px; border-left: 1px solid var(--line); padding-left: 12px; }
.metric-strip span { display: block; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .12em; }
.metric-strip strong { display: block; font: 600 14px/1.5 ui-monospace, monospace; margin-top: 3px; }
.chat { overflow-y: auto; padding: 32px clamp(20px, 7vw, 110px); scroll-behavior: smooth; }
.message { display: grid; grid-template-columns: 36px minmax(0, 760px); gap: 13px; margin: 0 auto 24px; max-width: 900px; }
.message.user { grid-template-columns: minmax(0, 760px) 36px; justify-content: end; }
.message.user .avatar { order: 2; background: #223039; color: var(--text); }
.message.user .bubble { order: 1; background: #152027; }
.avatar { width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; background: var(--acid); color: #101508; font: 800 11px/1 ui-monospace, monospace; }
.bubble { border: 1px solid var(--line); background: #0e161b; border-radius: 4px 16px 16px 16px; padding: 16px 18px; line-height: 1.72; overflow-wrap: anywhere; white-space: pre-wrap; }
.user .bubble { border-radius: 16px 4px 16px 16px; }
.message-role { margin: 0 0 8px; color: var(--cyan); font: 600 10px/1 ui-monospace, monospace; letter-spacing: .13em; }
.bubble p:last-child { margin-bottom: 0; }
.streaming::after { content: '▋'; color: var(--acid); animation: blink .8s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.composer { margin: 0 clamp(18px, 5vw, 72px) 24px; border: 1px solid #35464f; border-radius: var(--radius); background: rgba(14, 21, 26, .94); box-shadow: 0 24px 80px rgba(0,0,0,.35); }
textarea { width: 100%; resize: none; border: 0; outline: 0; color: var(--text); background: transparent; padding: 18px; line-height: 1.5; }
.composer-footer { border-top: 1px solid var(--line-soft); padding: 10px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.left-actions, .send-actions { display: flex; align-items: center; gap: 10px; }
.left-actions span { color: var(--muted); font-size: 11px; }
.attach-button { color: #c8d3d8; border: 1px solid var(--line); border-radius: 9px; padding: 8px 11px; cursor: pointer; font-size: 12px; }
.primary { min-width: 105px; border: 0; border-radius: 10px; color: #0b1006; background: var(--acid); font-weight: 800; }
.primary:hover { filter: brightness(1.07); }
.primary:disabled, button:disabled { opacity: .45; cursor: not-allowed; }
.danger { color: #ffc3c1; }
.attachment-bar { padding: 10px 14px 0; }
.attachment-chip { display: flex; align-items: center; justify-content: space-between; gap: 12px; border: 1px solid var(--line); background: #111b20; border-radius: 10px; padding: 8px 10px; color: #c9d5d9; font-size: 12px; }
.attachment-chip button { min-height: 28px; color: var(--danger); border: 0; background: transparent; }

@media (max-width: 860px) {
  .shell { height: auto; overflow: visible; grid-template-columns: 1fr; }
  .rail { min-height: auto; border-right: 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr 1fr; padding: 18px; }
  .brand, .route-card { grid-column: 1 / -1; }
  .route-card { margin-top: 0; }
  .workspace { height: auto; min-height: 100vh; }
  .chat { min-height: 55vh; max-height: 65vh; }
  .topbar { align-items: start; gap: 18px; }
}
@media (max-width: 600px) {
  .rail { grid-template-columns: 1fr; }
  .brand, .route-card { grid-column: auto; }
  .topbar { padding: 22px 18px 16px; display: block; }
  .metric-strip { margin-top: 18px; }
  .metric-strip div { min-width: 0; flex: 1; }
  .composer { margin: 0 10px 10px; }
  .composer-footer { align-items: stretch; flex-direction: column; }
  .left-actions, .send-actions { justify-content: space-between; }
}
