:root {
  --bg: #0b0e14;
  --bg-2: #11151c;
  --bg-3: #171c25;
  --ink: #e8edf5;
  --muted: #8b95a8;
  --line: rgba(232, 237, 245, 0.08);
  --accent: #3d8bfd;
  --accent-soft: rgba(61, 139, 253, 0.16);
  --user: rgba(61, 139, 253, 0.14);
  --bot: #1a2030;
  --ok: #3dd68c;
  --radius: 14px;
  --font: "Sora", system-ui, sans-serif;
  --rail: 56px;
  --sidebar: 280px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  min-height: 100%;
  overflow: hidden;
}

.app {
  display: grid;
  grid-template-columns: var(--rail) var(--sidebar) 1fr;
  height: 100vh;
  height: 100dvh;
}

/* —— Rail —— */
.rail {
  background: #080a0f;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.85rem 0;
  gap: 0.75rem;
}
.rail-logo {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(145deg, #3d8bfd, #1f4f9c);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.rail-nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.5rem;
}
.rail-btn {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.rail-btn:hover { background: var(--bg-3); color: var(--ink); }
.rail-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}

/* —— Sidebar —— */
.sidebar {
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 1rem 0.9rem;
}
.sidebar-head { margin-bottom: 0.85rem; }
.sidebar-brand {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.sidebar-ver {
  margin: 0.15rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}
.btn-new-chat {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 0.7rem 0.9rem;
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.btn-new-chat:hover { opacity: 0.92; }
.btn-new-chat:active { transform: scale(0.98); }

.sidebar-search { margin: 0.85rem 0 0.5rem; }
.sidebar-search input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--ink);
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  font: inherit;
  font-size: 0.85rem;
  outline: none;
}
.sidebar-search input:focus { border-color: rgba(61, 139, 253, 0.45); }
.sidebar-search input::placeholder { color: var(--muted); }

.sidebar-label {
  margin: 0.65rem 0.35rem 0.35rem;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.project-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.project-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.88rem;
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.12s ease;
}
.project-item:hover { background: rgba(255, 255, 255, 0.04); }
.project-item.active {
  background: var(--accent-soft);
  color: #fff;
}
.project-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}
.project-item.configured .project-dot { background: var(--ok); }
.project-item .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* —— Main —— */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background:
    radial-gradient(ellipse 70% 40% at 50% -10%, rgba(61, 139, 253, 0.12), transparent 55%),
    var(--bg);
}
.main-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.5rem;
  border-bottom: 1px solid var(--line);
}
.main-head h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.main-sub {
  margin: 0.25rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}
.btn-icon {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-3);
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.btn-icon:hover { color: var(--ink); }

.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0 1.25rem 1rem;
}
.chat-panel.hidden,
.settings-panel.hidden,
.approval.hidden { display: none !important; }

.chat-scroll {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.25rem 0.25rem 1rem;
}

.day-pill {
  align-self: center;
  font-size: 0.75rem;
  color: var(--muted);
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
}

.msg {
  display: grid;
  gap: 0.35rem;
  max-width: min(720px, 92%);
  animation: rise 0.3s ease both;
}
.msg.bot { align-self: flex-start; }
.msg.user { align-self: flex-end; }
.msg.meta {
  align-self: center;
  max-width: 100%;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}
.msg-who {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
}
.msg.user .msg-who { justify-content: flex-end; }
.avatar {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  font-size: 0.65rem;
  font-weight: 700;
  color: #fff;
  background: #2a3344;
}
.avatar.harpia {
  background: linear-gradient(145deg, #3d8bfd, #1f4f9c);
}
.avatar.you { background: #3a4558; }
.bubble {
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  line-height: 1.5;
  font-size: 0.92rem;
  white-space: pre-wrap;
  border: 1px solid var(--line);
}
.msg.bot .bubble { background: var(--bot); }
.msg.user .bubble {
  background: var(--user);
  border-color: rgba(61, 139, 253, 0.28);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.approval {
  border: 1px solid var(--line);
  background: var(--bg-3);
  border-radius: var(--radius);
  padding: 1rem;
  display: grid;
  gap: 0.85rem;
  margin-bottom: 0.75rem;
  max-width: 720px;
  width: 100%;
  align-self: center;
}
.approval h2 {
  margin: 0 0 0.45rem;
  font-size: 1rem;
  font-weight: 600;
}
.approval pre {
  margin: 0;
  white-space: pre-wrap;
  font-family: var(--font);
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.5;
}
.approval-actions {
  display: flex;
  gap: 0.55rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.composer {
  border: 1px solid var(--line);
  background: var(--bg-3);
  border-radius: 16px;
  padding: 0.75rem 0.85rem;
  display: grid;
  gap: 0.55rem;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}
.composer textarea {
  width: 100%;
  resize: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  outline: none;
  min-height: 2.4rem;
  max-height: 8rem;
}
.composer textarea::placeholder { color: var(--muted); }
.composer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.file {
  font-size: 0.82rem;
  color: var(--muted);
  cursor: pointer;
}
.file:hover { color: var(--ink); }
.file input { display: none; }

.btn {
  border: 0;
  border-radius: 10px;
  padding: 0.55rem 1rem;
  font: inherit;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

/* —— Settings —— */
.settings-panel {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  max-width: 560px;
}
.settings-panel h2 {
  margin: 0 0 0.4rem;
  font-size: 1.2rem;
}
.settings-hint {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.45;
}
.settings-form {
  display: grid;
  gap: 0.9rem;
}
.settings-form label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
}
.settings-form input,
.settings-form textarea {
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--ink);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  font: inherit;
  font-size: 0.92rem;
  outline: none;
}
.settings-form input:focus,
.settings-form textarea:focus {
  border-color: rgba(61, 139, 253, 0.45);
}
.settings-form input[readonly] {
  opacity: 0.7;
  cursor: default;
}
.settings-actions {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
  margin-top: 0.35rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (max-width: 900px) {
  .app { grid-template-columns: var(--rail) 1fr; }
  .sidebar {
    position: fixed;
    left: var(--rail);
    top: 0;
    bottom: 0;
    width: min(var(--sidebar), calc(100vw - var(--rail)));
    z-index: 20;
    transform: translateX(-110%);
    transition: transform 0.2s ease;
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.35);
  }
  .sidebar.open { transform: none; }
}

@media (max-width: 520px) {
  .main-head, .chat-panel { padding-left: 0.85rem; padding-right: 0.85rem; }
  .msg { max-width: 100%; }
}
