:root {
  color-scheme: dark;
  --bg: #16161a;
  --panel: #1e1e24;
  --border: #2c2c34;
  --text: #eee;
  --muted: #8a8a94;
  --accent: #d97757;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

.hidden { display: none !important; }

.screen {
  height: 100dvh;
  width: 100%;
}

/* Login */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
}
#login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(320px, 90vw);
}
#login-form h1 {
  text-align: center;
  margin: 0 0 4px;
  font-weight: 500;
}
.subheading {
  text-align: center;
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 14px;
}
#login-form input, #login-form button {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 16px;
}
#login-form button {
  background: var(--accent);
  border: none;
  color: #1a1008;
  font-weight: 600;
  cursor: pointer;
}
.error { color: #e88; text-align: center; margin: 0; }

/* App shell */
#app {
  display: flex;
  flex-direction: column;
}

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: env(safe-area-inset-top, 10px) 12px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#topbar button {
  background: none;
  border: none;
  color: var(--text);
  font-size: 20px;
  padding: 8px 12px;
  cursor: pointer;
}
#topbar-title { font-weight: 600; }

#drawer {
  position: fixed;
  top: 0; bottom: 0; left: 0;
  width: min(280px, 80vw);
  background: var(--panel);
  border-right: 1px solid var(--border);
  z-index: 20;
  overflow-y: auto;
  padding-top: env(safe-area-inset-top, 0);
  transition: transform 0.2s ease;
}
#drawer.hidden { transform: translateX(-100%); display: block !important; visibility: hidden; }
#drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 10;
}

.session-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.session-item.active { background: rgba(217,119,87,0.15); }
.session-item .title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.session-item .del {
  color: var(--muted);
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.4;
}
.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #1a1008;
}
.msg.assistant {
  align-self: flex-start;
  background: var(--panel);
  border: 1px solid var(--border);
}
.msg.tool {
  align-self: flex-start;
  background: none;
  border: 1px dashed var(--border);
  color: var(--muted);
  font-size: 13px;
  font-family: ui-monospace, monospace;
}
.msg.system {
  align-self: center;
  color: var(--muted);
  font-size: 13px;
}

#composer {
  display: flex;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
#input {
  flex: 1;
  resize: none;
  max-height: 140px;
  padding: 10px 14px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
}
#send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #1a1008;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}
#send-btn:disabled { opacity: 0.5; }
