:root {
  --bg: #fafaf7;
  --fg: #1a1a1a;
  --muted: #555;
  --border: #d4d4d0;
  --user-bg: #eef1f4;
  --ward-bg: #f6f3ed;
  --accent: #2a4a3a;
  --error: #8b1a1a;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

/* PLAT-177 — In chat mode, the viewport itself becomes the layout
   frame: header at top, conversation scrolls, input pinned at bottom.
   The :has() check leaves the login view's padded centered layout
   untouched. 100dvh tracks the visual-viewport so the input row stays
   above the on-screen keyboard on mobile. */
main:has(#chat:not([hidden])) {
  max-width: none;
  padding: 0;
  height: 100dvh;
}

h1 {
  font-size: 1.4rem;
  font-weight: 600;
  margin: 0 0 1rem;
}

label {
  display: block;
  margin-bottom: 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
}

input,
textarea {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.5rem 0.6rem;
  font: inherit;
  color: var(--fg);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
}

textarea {
  resize: vertical;
  min-height: 3.5rem;
}

button {
  font: inherit;
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#login-error {
  margin-top: 0.75rem;
  color: var(--error);
  font-size: 0.9rem;
}

/* PLAT-177 — #chat is a viewport-height flex column. The header is the
   non-shrinking top item, #chat-messages is the flex-grow scroll
   container, and #chat-form is the non-shrinking pinned bottom item. */
#chat {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 1.5rem 1rem 0;
}

/* PLAT-177 follow-up — the id-selector `#chat` above (specificity
   0,1,0,0) overrides the user-agent `[hidden] { display: none }` rule
   (specificity 0,0,1,0), so without this rule `els.chat.hidden = true`
   flips the attribute but leaves the chat surface visible. Restore the
   `[hidden]` semantics locally with a higher-specificity override. */
#chat[hidden] {
  display: none;
}

.chat-header {
  flex: 0 0 auto;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
  margin-bottom: 1rem;
}

.chat-header button {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 0.3rem 0.7rem;
  font-size: 0.85rem;
}

#chat-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-bottom: 0.75rem;
}

.message-user,
.message-ward,
.message-system {
  padding: 0.6rem 0.8rem;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.message-user {
  background: var(--user-bg);
  align-self: flex-end;
  max-width: 85%;
}

.message-ward {
  background: var(--ward-bg);
  align-self: flex-start;
  max-width: 95%;
}

.message-system {
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  align-self: center;
}

.message-user pre,
.message-ward pre {
  margin: 0;
  font: inherit;
  white-space: pre-wrap;
  word-wrap: break-word;
}

#chat-form {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  /* PLAT-177 — hard horizontal edge between the scrolling conversation
     area and the pinned input row. Solid background prevents any
     conversation content showing through. */
  border-top: 1px solid var(--border);
  background: var(--bg);
  padding: 0.75rem 0 1rem;
}

.chat-form-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  justify-content: flex-end;
}

.chat-form-actions .attach-button {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
}

.chat-form-actions .attach-button:hover {
  color: var(--fg);
  border-color: var(--accent);
}

/* PLAT-190 — Summarize control. A neutral, low-emphasis affordance in
   the form-actions row (same register as Add file), with an inline
   two-state confirm that drops below the row rather than overlaying. */
.summarize-control {
  display: flex;
  align-items: center;
}

/* The `display: flex` author rule above (specificity 0,1,0) ties the
   UA `[hidden] { display: none }` rule and wins on author-origin, so
   `els.summarizeControl.hidden = true` would not hide it. Restore the
   `[hidden]` semantics locally — same fix as `#chat[hidden]` (PLAT-177). */
.summarize-control[hidden] {
  display: none;
}

.summarize-button {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
}

.summarize-button:not(:disabled):hover {
  color: var(--fg);
  border-color: var(--accent);
}

.summarize-confirm {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
}

/* Same author-origin-beats-UA-`[hidden]` fix as `.summarize-control`
   above: this panel carries visible content, so the override is
   load-bearing, not cosmetic. */
.summarize-confirm[hidden] {
  display: none;
}

.summarize-notice {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  max-width: 22rem;
}

.summarize-confirm-actions {
  display: flex;
  gap: 0.4rem;
}

.summarize-confirm-actions .summarize-cancel {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.summarize-confirm-actions button {
  padding: 0.3rem 0.7rem;
  font-size: 0.85rem;
}

.summarize-ack {
  color: var(--accent);
  font-size: 0.85rem;
}

.staged-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.5rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
  color: var(--fg);
  max-width: 18rem;
}

.attachment-chip .chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-chip .chip-remove {
  background: transparent;
  color: var(--muted);
  border: 0;
  padding: 0 0.2rem;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.attachment-chip .chip-remove:hover {
  color: var(--error);
}

/* Past-turn chips inside a user message bubble — display-only, no
   remove control (PLAT-119 §2.5). */
.message-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.5rem;
}

.message-attachments .attachment-chip-readonly {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--muted);
  max-width: 18rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-error {
  margin: 0;
  color: var(--error);
  font-size: 0.85rem;
}

/* PLAT-180 — consent interstitial. Lives in the login-style centered
   layout (the PLAT-177 chat-mode viewport rule keys on #chat only).
   The text panel is the scroll container the §3.3 gate watches. */
.consent-intro {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 0.75rem;
}

.consent-version {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 0.5rem;
}

.consent-text {
  white-space: pre-wrap;
  word-wrap: break-word;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 0.9rem;
  max-height: 55vh;
  overflow-y: auto;
  font-size: 0.95rem;
  line-height: 1.5;
}

.consent-text:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.consent-error {
  color: var(--error);
  font-size: 0.9rem;
}

.consent-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
