:root {
  --bg: #0b0d10;
  --bg-soft: #0f1216;
  --panel: #12161b;
  --panel-2: #171c23;
  --panel-3: #1d242d;
  --line: #242c36;
  --line-soft: #1b222a;
  --text: #e9eef5;
  --muted: #8e9aaa;
  --muted-2: #667180;
  --accent: #7c9cff;
  --accent-strong: #5b7dff;
  --green: #59d6a6;
  --orange: #f5a65b;
  --red: #ff6f78;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 18px 60px rgba(0, 0, 0, .45);
  --mono: ui-monospace, SFMono-Regular, "Cascadia Code", Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(124, 156, 255, .12), transparent 60%),
    radial-gradient(700px 420px at 100% 0%, rgba(89, 214, 166, .07), transparent 55%);
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.only-mobile { display: none !important; }
.error { color: var(--red); font-size: 13px; margin: 8px 0 0; }
.muted { color: var(--muted); }

.boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 14px;
  text-align: center;
  background: var(--bg);
  z-index: 30;
}
.boot-mark, .empty-mark {
  width: 58px;
  height: 58px;
  margin: 0 auto;
  border-radius: 18px;
  display: grid;
  place-items: center;
  font-weight: 800;
  letter-spacing: -.04em;
  color: #0a0c10;
  background: linear-gradient(145deg, #a9bdff, #5b7dff);
  box-shadow: 0 10px 40px rgba(91, 125, 255, .35);
}
.boot-text { color: var(--muted); }

.login {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 20;
}
.login-card {
  width: min(420px, 100%);
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(23, 28, 35, .96), rgba(15, 18, 22, .96));
  box-shadow: var(--shadow);
}
.login-lead { color: var(--muted); margin: 18px 0 24px; }
.login-form { display: grid; gap: 9px; }
.login-form label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.login-hint { color: var(--muted-2); font-size: 12px; margin: 16px 0 0; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 800;
  color: #0a0c10;
  background: linear-gradient(145deg, #a9bdff, #5b7dff);
}
.brand-name { font-weight: 650; letter-spacing: -.02em; }
.brand-lg .brand-mark { width: 44px; height: 44px; border-radius: 14px; font-size: 14px; }
.brand-lg strong { display: block; font-size: 18px; letter-spacing: -.02em; }
.brand-lg small { display: block; color: var(--muted); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; }

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  color: var(--text);
  padding: 10px 12px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
  border-color: rgba(124, 156, 255, .7);
  box-shadow: 0 0 0 3px rgba(124, 156, 255, .12);
}
textarea { resize: none; }
button {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  padding: 9px 13px;
  transition: background .15s, border-color .15s, transform .05s;
}
button:hover { background: var(--panel-3); border-color: #303a47; }
button:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary {
  border-color: transparent;
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  color: #081020;
  font-weight: 650;
}
button.primary:hover { filter: brightness(1.06); background: linear-gradient(180deg, var(--accent), var(--accent-strong)); }
button.ghost { background: transparent; }
button.danger { color: var(--red); border-color: rgba(255, 111, 120, .35); background: rgba(255, 111, 120, .08); }
button.wide { width: 100%; padding: 11px 14px; }
.icon-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  display: grid;
  place-items: center;
  background: transparent;
  color: var(--muted);
  font-size: 17px;
}

.app { height: 100%; display: grid; grid-template-rows: 62px 1fr; position: relative; z-index: 1; }
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(11, 13, 16, .72);
  backdrop-filter: blur(18px);
}
.conn { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; min-width: 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted-2); flex: none; }
.dot.ok { background: var(--green); box-shadow: 0 0 0 4px rgba(89, 214, 166, .12); }
.dot.bad { background: var(--red); box-shadow: 0 0 0 4px rgba(255, 111, 120, .12); }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.shell { min-height: 0; display: grid; grid-template-columns: 330px minmax(0, 1fr); }
.sidebar {
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line-soft);
  background: rgba(15, 18, 22, .55);
}
.sidebar-tools { display: flex; gap: 8px; padding: 14px 14px 8px; }
.sidebar-tools input { padding: 9px 11px; font-size: 13px; }
.segment {
  display: flex;
  gap: 4px;
  padding: 0 14px 8px;
}
.segment button {
  flex: 1;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted-2);
  padding: 6px 8px;
  font-size: 11px;
}
.segment button.active {
  color: var(--text);
  background: rgba(255, 255, 255, .055);
  border-color: var(--line-soft);
}
.segment button span {
  display: inline-block;
  min-width: 16px;
  border-radius: 99px;
  background: rgba(89, 214, 166, .14);
  color: var(--green);
  font-size: 10px;
  padding: 0 4px;
  margin-left: 3px;
}
.session-list { flex: 1; overflow: auto; padding: 6px 10px 14px; }
.sidebar-foot {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--line-soft);
  color: var(--muted-2);
  font-size: 11px;
}

.session-item {
  width: 100%;
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr);
  gap: 10px;
  text-align: left;
  padding: 11px 10px;
  margin-bottom: 3px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
}
.session-item:hover { background: rgba(255, 255, 255, .03); }
.session-item.selected { background: linear-gradient(180deg, rgba(124, 156, 255, .12), rgba(124, 156, 255, .05)); border-color: rgba(124, 156, 255, .25); }
.session-item .dot { margin-top: 6px; }
.session-title { display: block; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-sub { display: block; color: var(--muted-2); font-size: 11px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-empty { padding: 30px 14px; text-align: center; color: var(--muted-2); }

.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.empty { flex: 1; display: grid; align-content: start; justify-items: stretch; gap: 12px; text-align: left; padding: 30px clamp(16px, 4vw, 54px); overflow: auto; }
.empty h1 { margin: 8px 0 0; font-size: 24px; letter-spacing: -.03em; }
.empty p { max-width: 440px; color: var(--muted); margin: 0 0 8px; }
.chat { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
.chat-head {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(11, 13, 16, .4);
}
.chat-title-wrap { min-width: 0; flex: 1; }
.chat-head h1 { margin: 0; font-size: 16px; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-meta { color: var(--muted-2); font-size: 11px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-actions { display: flex; gap: 7px; flex: none; }
.chat-actions button { padding: 7px 11px; font-size: 12px; }

.messages { flex: 1; min-height: 0; overflow: auto; padding: 22px clamp(16px, 4vw, 48px) 18px; }
.composer {
  margin: 0 clamp(12px, 3vw, 34px) 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(23, 28, 35, .98), rgba(15, 18, 22, .98));
  box-shadow: 0 14px 40px rgba(0, 0, 0, .25);
  padding: 10px;
}
.composer textarea { border: 0; background: transparent; padding: 6px 8px; max-height: 180px; min-height: 40px; box-shadow: none; }
.composer textarea:focus { box-shadow: none; }
.composer-row { display: flex; align-items: center; gap: 8px; padding: 4px 4px 0; }
.composer-row .icon-btn { font-size: 16px; }
.compose-hint { color: var(--muted-2); font-size: 11px; margin-right: auto; }
.sidebar-backdrop { display: none; }
.conn-banner {
  position: fixed;
  z-index: 15;
  top: 62px;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 18px;
  border-bottom: 1px solid rgba(255, 111, 120, .25);
  background: #2a1519;
  color: #ffc2c6;
  font-size: 12px;
}
.conn-banner button { margin-left: auto; border-color: rgba(255, 111, 120, .3); color: #ffc2c6; padding: 5px 9px; font-size: 11px; }
.attachments { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 4px 6px; }
.attachments:empty { display: none; }
.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid rgba(124, 156, 255, .3);
  background: rgba(124, 156, 255, .1);
  color: #c7d4ff;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 11px;
}
.attach-chip button { border: 0; background: transparent; padding: 0 2px; color: var(--muted); }

@media (max-width: 900px) {
  .only-mobile { display: grid !important; }
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: absolute;
    z-index: 10;
    top: 62px;
    bottom: 0;
    left: 0;
    width: min(86vw, 340px);
    transform: translateX(-102%);
    transition: transform .22s ease;
    background: #0e1216;
    box-shadow: var(--shadow);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 62px 0 0;
    z-index: 9;
    background: rgba(0, 0, 0, .45);
  }
  body.sidebar-open .sidebar-backdrop { display: block; }
  .topbar { gap: 10px; padding: 0 12px; }
  .brand-name, #conn-text { display: none; }
  .top-actions { gap: 4px; }
  .top-actions .primary { padding: 8px 10px; font-size: 12px; }
  .chat-head { padding: 12px 14px; align-items: flex-start; }
  .chat-actions { flex-wrap: wrap; justify-content: flex-end; }
  .chat-actions button { padding: 6px 8px; }
  .messages { padding: 16px 12px 12px; }
  .composer { margin: 0 8px calc(8px + env(safe-area-inset-bottom)); }
  .compose-hint { display: none; }
}
