:root {
  --bg: #122018;
  --fg: #f2efe6;
  --muted: #a8b5ad;
  --accent: #d9c7a3;
  --panel: #1c2f27;
  --line: #2f463c;
  --danger: #e07a5f;
  --ok: #7cb58a;
  --user: #2a4638;
  --assistant: #24352d;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  color: var(--fg);
  background: var(--bg);
}

.hidden { display: none !important; }

.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #0f1a15;
  border-right: 1px solid var(--line);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.sidebar-head .eyebrow {
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-size: 0.72rem;
  color: var(--muted);
  margin: 0;
}
.sidebar-head h1 { margin: 0.35rem 0 0; font-size: 1.35rem; }
.sidebar-nav { display: grid; gap: 0.35rem; }
.nav-item {
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: var(--fg);
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  cursor: pointer;
  font: inherit;
}
.nav-item.active, .nav-item:hover { background: var(--panel); border-color: var(--line); }
.nav-item.danger { color: var(--danger); }
.sidebar-meta { color: var(--muted); font-size: 0.85rem; margin-top: auto; }

.main {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
  max-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 90%, black);
}
.topbar-title { display: flex; flex-direction: column; gap: 0.15rem; }
.activity-state { color: var(--muted); font-size: 0.85rem; }
.icon-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--fg);
  border-radius: 8px;
  width: 2.25rem;
  height: 2.25rem;
  cursor: pointer;
}

.chat-panel {
  display: grid;
  grid-template-rows: 1fr auto auto;
  min-height: 0;
  height: calc(100vh - 56px);
}
.message-log {
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.message { display: flex; }
.message.user { justify-content: flex-end; }
.message.assistant { justify-content: flex-start; }
.bubble {
  max-width: min(720px, 88%);
  padding: 0.75rem 0.95rem;
  border-radius: 16px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.message.user .bubble { background: var(--user); border-bottom-right-radius: 4px; }
.message.assistant .bubble { background: var(--assistant); border-bottom-left-radius: 4px; }
.message.pending .bubble { opacity: 0.7; }
.message.failed .bubble { border: 1px solid var(--danger); }
.attachments { margin-top: 0.35rem; font-size: 0.85rem; }
.attachments a { color: var(--accent); }

.offline-banner {
  background: #4a2f24;
  color: #ffd8cc;
  padding: 0.5rem 1rem;
  text-align: center;
  font-size: 0.9rem;
}

.composer {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.5rem;
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: #0f1a15;
  align-items: end;
}
.composer textarea {
  font: inherit;
  resize: none;
  min-height: 44px;
  max-height: 160px;
  padding: 0.65rem 0.8rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
}
.composer button, .panel button, .attach-btn {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 999px;
  padding: 0.7rem 1rem;
  background: var(--accent);
  color: #152019;
}
.attach-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--fg);
}

.pending-attachments {
  list-style: none;
  margin: 0;
  padding: 0 1rem 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.panel, .auth-panel {
  padding: 1.5rem;
  max-width: 520px;
}
.panel h2 { margin-top: 0; }
.panel label { display: grid; gap: 0.35rem; margin-bottom: 0.75rem; }
.panel input {
  font: inherit;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
}
.error { color: var(--danger); }
.composer-error { margin: 0 1rem 0.5rem; font-size: 0.9rem; }
.host-hint {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
  margin: 0 0 1rem;
}
.host-hint a { color: var(--accent); }
.host-hint-footer {
  margin: 0.35rem 1rem 0.75rem;
  padding-top: 0.35rem;
  border-top: 1px solid var(--line);
}
.devices { list-style: none; padding: 0; display: grid; gap: 0.5rem; }
.devices li { border: 1px solid var(--line); border-radius: 10px; padding: 0.75rem; }
.devices button.danger { margin-top: 0.5rem; background: var(--danger); color: #1a100e; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(85vw, 300px);
    z-index: 20;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }
  .sidebar.open { transform: translateX(0); }
  #menu-toggle { display: inline-flex; align-items: center; justify-content: center; }
}

@media (min-width: 861px) {
  #menu-toggle { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}
