@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --paper: #eef0f3;
  --paper-raised: #ffffff;
  --ink: #1c2430;
  --ink-soft: #5b6472;
  --line: #d7dce3;
  --accent: #b5661f;
  --accent-soft: #f1e1ce;
  --danger: #a3372f;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #15181d;
    --paper-raised: #1d2128;
    --ink: #e7e9ec;
    --ink-soft: #929aa6;
    --line: #2b3038;
    --accent: #e0a357;
    --accent-soft: #332a1c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ---------- Login screen ---------- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 32px 28px;
}

.login-card h1 {
  font-size: 1.3rem;
  margin: 0 0 6px;
}

.login-card .hint {
  color: var(--ink-soft);
  margin: 0 0 20px;
  font-size: 0.92rem;
}

.login-card input[type="password"] {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper);
  color: var(--ink);
  font-size: 1rem;
  margin-bottom: 14px;
}

.login-card button {
  width: 100%;
  padding: 11px;
  border: none;
  border-radius: 7px;
  background: var(--accent);
  color: #1c1208;
  font-weight: 600;
  font-size: 0.98rem;
  cursor: pointer;
}

.login-error {
  color: var(--danger);
  font-size: 0.88rem;
  margin-bottom: 12px;
}

/* ---------- Chat screen ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.topbar-title {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.86rem;
  color: var(--ink-soft);
}

.logout-link {
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 0.86rem;
  border: 1px solid var(--line);
  padding: 5px 11px;
  border-radius: 6px;
}
.logout-link:hover { color: var(--ink); border-color: var(--ink-soft); }

.log {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 16px 140px;
  overflow-x: auto;
}

.msg {
  margin-bottom: 22px;
  max-width: 100%;
}

.msg .who {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  color: var(--ink-soft);
  margin-bottom: 4px;
}

.msg.user {
  margin-left: 12%;
}
.msg.user .bubble {
  background: var(--accent-soft);
  border-radius: 10px;
  padding: 10px 14px;
  display: inline-block;
}

.msg.assistant .bubble {
  padding: 0;
}

.msg .bubble p:first-child { margin-top: 0; }
.msg .bubble p:last-child { margin-bottom: 0; }

.msg .bubble pre {
  overflow-x: auto;
  border-radius: 8px;
  padding: 14px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.86rem;
}

.msg .bubble code:not(pre code) {
  background: var(--line);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.88em;
}

.attachment-chip, .download-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.78rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 9px;
  margin: 4px 6px 0 0;
  color: var(--ink-soft);
  text-decoration: none;
}
.download-chip {
  color: var(--accent);
  border-color: var(--accent);
}

.typing {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.82rem;
  color: var(--ink-soft);
}

/* ---------- Composer ---------- */
.composer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--paper);
  border-top: 1px solid var(--line);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
}

.file-chips {
  max-width: 720px;
  margin: 0 auto;
}
.file-chips:not(:empty) { margin-bottom: 8px; }

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 0.8rem;
  margin: 2px 6px 2px 0;
}
.file-chip button {
  border: none;
  background: none;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
}

.composer-row {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.attach-btn {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.1rem;
}

#message-input {
  flex: 1 1 auto;
  resize: none;
  max-height: 160px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-raised);
  color: var(--ink);
  font-family: inherit;
  font-size: 1rem;
}

#send-btn {
  flex: 0 0 auto;
  padding: 0 16px;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #1c1208;
  font-weight: 600;
  cursor: pointer;
}
#send-btn:disabled { opacity: 0.5; cursor: default; }

@media (max-width: 520px) {
  .msg.user { margin-left: 4%; }
}
