:root {
  --bg0: #0e0f12;
  --bg1: #16181e;
  --bg2: #1f222b;
  --border: #2a2e3a;
  --text0: #f2f4f8;
  --text1: #c5cad6;
  --text2: #82899b;
  --accent: #5e8cff;
  --ok: #38c976;
  --warn: #f0ad4e;
  --err: #ef5b5b;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%; width: 100%;
  background: var(--bg0); color: var(--text0);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px; line-height: 1.45;
  overscroll-behavior: none;
}

#app {
  display: flex; flex-direction: column; height: 100dvh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.hidden { display: none !important; }

.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; background: var(--bg1); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text2); }
.status-dot.online { background: var(--ok); }
.status-dot.connecting { background: var(--warn); }
.status-dot.error { background: var(--err); }

.machine-select {
  flex: 1; min-width: 0; background: var(--bg2); color: var(--text0);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; font-size: 13px;
}

.icon-btn {
  background: transparent; color: var(--text1); border: 1px solid var(--border);
  border-radius: 8px; width: 34px; height: 34px; font-size: 18px; cursor: pointer;
}

.panel { flex: 1; display: flex; align-items: center; justify-content: center; padding: 16px; }
.card {
  width: 100%; max-width: 420px; background: var(--bg1); border: 1px solid var(--border);
  border-radius: 14px; padding: 20px;
}
.card h2 { margin: 0 0 8px; font-size: 18px; }
.muted { color: var(--text2); font-size: 13px; margin: 0 0 14px; }
.field-label { display: block; font-size: 12px; color: var(--text2); margin: 10px 0 4px; }
input[type="text"], input[type="password"] {
  width: 100%; background: var(--bg2); color: var(--text0);
  border: 1px solid var(--border); border-radius: 8px; padding: 10px; font-size: 14px;
}
.btn-primary {
  margin-top: 14px; width: 100%; background: var(--accent); color: #fff;
  border: none; border-radius: 9px; padding: 11px 14px; font-weight: 600; font-size: 14px; cursor: pointer;
}
.btn-small {
  background: var(--bg2); color: var(--text0); border: 1px solid var(--border);
  border-radius: 7px; padding: 6px 10px; font-size: 12px; cursor: pointer;
}
.btn-small.danger { border-color: rgba(239, 91, 91, 0.5); color: var(--err); }
.status-msg { margin-top: 10px; font-size: 13px; color: var(--warn); min-height: 18px; }

.drawer {
  position: fixed; inset: 0; z-index: 40; background: var(--bg0);
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);
}
.drawer-head, .drawer-foot {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  background: var(--bg1); border-bottom: 1px solid var(--border);
}
.drawer-head strong { flex: 1; }
.drawer-foot { border-bottom: none; border-top: 1px solid var(--border); justify-content: space-between; }
.chat-list { flex: 1; overflow-y: auto; padding: 8px; }
.chat-item {
  padding: 10px 12px; border-radius: 9px; margin-bottom: 6px;
  background: var(--bg1); border: 1px solid var(--border); cursor: pointer;
}
.chat-item.active { border-color: var(--accent); background: var(--bg2); }
.chat-item-title { font-weight: 600; font-size: 14px; }
.chat-item-meta { font-size: 12px; color: var(--text2); margin-top: 2px; }

.chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; background: var(--bg1); border-bottom: 1px solid var(--border);
}
.chat-title { font-size: 13px; font-weight: 600; color: var(--text1); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.messages {
  flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px;
}
.msg {
  padding: 10px 12px; border-radius: 12px; max-width: 92%; white-space: pre-wrap; word-break: break-word;
}
.msg.user { align-self: flex-end; background: #22345c; color: var(--text0); }
.msg.assistant { align-self: flex-start; background: var(--bg1); border: 1px solid var(--border); max-width: 100%; }
.msg code { background: var(--bg2); padding: 1px 4px; border-radius: 4px; font-family: ui-monospace, monospace; font-size: 13px; }
.msg pre { background: var(--bg0); padding: 10px; border-radius: 8px; overflow-x: auto; font-size: 12px; }

.question-dock {
  padding: 10px 12px; background: var(--bg1); border-top: 1px solid var(--accent);
}
.composer {
  display: flex; gap: 8px; padding: 10px 12px; background: var(--bg1);
  border-top: 1px solid var(--border); align-items: flex-end;
}
.composer textarea {
  flex: 1; resize: none; max-height: 120px; background: var(--bg2); color: var(--text0);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px; font-size: 15px; font-family: inherit;
}
.composer .btn-primary { margin-top: 0; width: auto; padding: 9px 16px; }
