: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;
}

/* PLAT-201 (spec amendment) — the account-home header reuses the
   chat-header layout and its low-emphasis sign-out button styling. */
.chat-header,
.account-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,
.account-header button {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 0.3rem 0.7rem;
  font-size: 0.85rem;
}

/* PLAT-204 — group the chat header's back/home and sign-out controls on
   the right so the title stays left-aligned under the header's
   space-between layout. */
.chat-header-actions {
  display: flex;
  gap: 0.5rem;
}

#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;
}

/* PLAT-201 — account-home landing surface. Lives in the login-style
   centered layout (the PLAT-177 chat-mode viewport rule keys on #chat
   only). The "Chat with {persona}" control is prominent and above the
   fold; the read-only log view window is the hero; Download and the
   Maintain link sit below it. */
.chat-entry-button {
  display: block;
  width: 100%;
  padding: 0.8rem 1rem;
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 1.25rem;
}

/* PLAT-216 — renew affordance shown beside the greyed chat-entry button on an
   `expired` fresh load. A quiet contact stub, not a call-to-action button. */
.renew-link {
  display: block;
  color: var(--accent);
  font-size: 0.9rem;
  margin-top: -0.75rem;
  margin-bottom: 1.25rem;
}

/* Same author-origin-beats-UA-`[hidden]` fix as `#chat[hidden]` (PLAT-177):
   the `display: block` above outranks the UA `[hidden] { display: none }`, so
   restore the hidden semantics locally. */
.renew-link[hidden] {
  display: none;
}

.account-log-view {
  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;
  word-wrap: break-word;
}

.account-log-view:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.account-log-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.account-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
}

.account-download-button {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border);
  padding: 0.4rem 0.9rem;
  font-size: 0.9rem;
}

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

.account-maintain-link {
  color: var(--accent);
  font-size: 0.9rem;
}

.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;
}

/* PLAT-125 — Maintain surface. Shares the account-home centered layout
   (the PLAT-177 chat-mode viewport rule keys on #chat only, so this view
   is unaffected). Reuses .account-header for the title + return control.
   The editor is the hero; the toolbar sits above it, the save control
   below. */
.maintain-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.6rem;
}

.maintain-tool {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.3rem 0.6rem;
  font-size: 0.85rem;
  min-width: 2.2rem;
}

.maintain-tool:hover {
  color: var(--fg);
  border-color: var(--accent);
}

.maintain-editor {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 0.9rem;
  min-height: 40vh;
  max-height: 60vh;
  overflow-y: auto;
  font-size: 0.95rem;
  line-height: 1.5;
  word-wrap: break-word;
}

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

.maintain-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
}

.maintain-save-button {
  padding: 0.5rem 1.1rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.maintain-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* The save-confirmation dialog (spec §Save friction): a single-click
   confirm overlaying the surface. The `#maintain-dialog` id selector
   (specificity 1,0,0) overrides the UA `[hidden]` rule, so restore the
   hidden semantics locally — the same pattern as #chat[hidden]. */
.maintain-dialog {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(26, 26, 26, 0.4);
}

.maintain-dialog[hidden] {
  display: none;
}

.maintain-dialog-panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem 1.4rem;
  max-width: 30rem;
  width: 100%;
}

.maintain-dialog-body {
  margin: 0 0 0.6rem;
  font-size: 1rem;
  line-height: 1.5;
}

.maintain-dialog-reminder {
  margin: 0 0 1.1rem;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.45;
}

.maintain-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
}

.maintain-dialog-actions button {
  padding: 0.45rem 1rem;
  font-size: 0.9rem;
}

#maintain-dialog-cancel {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
