@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700&display=swap');

/* Design tokens lifted from sparked-ignition-app so both products read as one
   brand. Light values are its exact index.css variables; the dark set is
   derived from the same palette (the reference app is light-only). */
:root {
  --background: 30 33% 97%;
  --foreground: 0 0% 10%;
  --card: 0 0% 100%;
  --card-foreground: 0 0% 10%;
  --primary: 26 96% 54%;
  --primary-strong: 13 80% 51%;
  --primary-foreground: 0 0% 100%;
  --secondary: 30 33% 94%;
  --muted: 30 20% 92%;
  --muted-foreground: 0 0% 45%;
  --border: 30 15% 88%;
  --input: 30 15% 92%;
  --ring: 26 96% 54%;
  --radius: 0.625rem;
  --destructive: 0 72% 51%;

  --sparked-yellow: #FFDC64;
  --sparked-cream: #F5E9DE;
  --sparked-blue: #64A6C8;

  --font: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
}

:root[data-theme='dark'] {
  --background: 0 0% 9%;
  --foreground: 30 20% 94%;
  --card: 0 0% 13%;
  --card-foreground: 30 20% 94%;
  --primary: 26 96% 54%;
  --primary-strong: 13 80% 51%;
  --primary-foreground: 0 0% 100%;
  --secondary: 0 0% 17%;
  --muted: 0 0% 17%;
  --muted-foreground: 30 8% 62%;
  --border: 0 0% 22%;
  --input: 0 0% 20%;
  --destructive: 0 72% 60%;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --background: 0 0% 9%;
    --foreground: 30 20% 94%;
    --card: 0 0% 13%;
    --card-foreground: 30 20% 94%;
    --secondary: 0 0% 17%;
    --muted: 0 0% 17%;
    --muted-foreground: 30 8% 62%;
    --border: 0 0% 22%;
    --input: 0 0% 20%;
    --destructive: 0 72% 60%;
    }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: var(--font);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  /* Stop iOS inflating text in landscape. */
  -webkit-text-size-adjust: 100%;
}

body {
  /* Nothing should ever scroll sideways on a phone. */
  overflow-x: hidden;
  overscroll-behavior-y: none;
}

[hidden] { display: none !important; }

/* No invert filter: brands ship a real dark-mode logo, swapped by
   theme-init.js. invert() turned Ecomstat's navy wordmark pale yellow. */
.logo { display: block; }

/* ---------- Login / splash ---------- */

.login-screen {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, hsl(var(--primary) / 0.13), transparent 70%),
    hsl(var(--background));
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: 16px;
  padding: 40px 32px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 1px 2px hsl(0 0% 0% / 0.04), 0 12px 32px hsl(0 0% 0% / 0.07);
}

.login-logo { width: 148px; margin: 0 auto 8px; }

.login-sub {
  color: hsl(var(--muted-foreground));
  text-align: center;
  margin: 10px 0 28px;
  font-size: 14px;
  line-height: 1.55;
}

.login-card label {
  font-size: 12px;
  font-weight: 600;
  color: hsl(var(--muted-foreground));
  margin-bottom: 7px;
  letter-spacing: 0.01em;
}

.login-card input {
  background: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 12px 14px;
  color: hsl(var(--foreground));
  font: inherit;
  margin-bottom: 18px;
  width: 100%;
}

.login-card input::placeholder { color: hsl(var(--muted-foreground) / 0.7); }

.login-card input:focus,
.composer textarea:focus {
  outline: none;
  border-color: hsl(var(--ring));
  box-shadow: 0 0 0 3px hsl(var(--ring) / 0.16);
}

.login-card button[type='submit'] {
  background: linear-gradient(135deg, hsl(var(--primary)), hsl(var(--primary-strong)));
  color: hsl(var(--primary-foreground));
  border: 0;
  border-radius: var(--radius);
  padding: 13px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.login-card button[type='submit']:hover:not(:disabled) { filter: brightness(1.07); }
.login-card button[type='submit']:disabled { opacity: 0.6; cursor: default; }

.error {
  color: hsl(var(--destructive));
  font-size: 13px;
  margin: 16px 0 0;
  text-align: center;
  line-height: 1.5;
}

.sent-mark { font-size: 36px; text-align: center; margin: 16px 0 12px; }
.sent-title { font-size: 19px; font-weight: 600; text-align: center; margin: 0 0 10px; }

.sent-body {
  color: hsl(var(--muted-foreground));
  font-size: 14px;
  text-align: center;
  margin: 0 0 22px;
  line-height: 1.6;
}

.sent-body strong { color: hsl(var(--foreground)); word-break: break-all; }
.link-btn.centred { display: block; margin: 0 auto; }

/* ---------- App shell ---------- */

/* 100% of <html> is the *layout* viewport, which on mobile sits behind the
   browser chrome and does not shrink when the keyboard opens — the composer
   ends up under the keyboard. dvh tracks the visible area; the 100% line is
   the fallback for browsers without it. */
.app { display: flex; height: 100%; height: 100dvh; }

.sidebar {
  width: 264px;
  flex: 0 0 264px;
  background: hsl(var(--secondary));
  border-right: 1px solid hsl(var(--border));
  display: flex;
  flex-direction: column;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 14px;
  border-bottom: 1px solid hsl(var(--border));
}

.sidebar-logo { width: 104px; }

.ghost-btn {
  background: transparent;
  border: 1px solid hsl(var(--border));
  color: hsl(var(--muted-foreground));
  border-radius: 8px;
  width: 32px;
  height: 32px;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  flex: 0 0 32px;
}

.ghost-btn:hover {
  color: hsl(var(--primary));
  border-color: hsl(var(--primary));
  background: hsl(var(--primary) / 0.07);
}

.conv-list { flex: 1; overflow-y: auto; padding: 8px; }

.conv-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  font-size: 14px;
  margin-bottom: 2px;
}

.conv-item:hover { background: hsl(var(--card)); color: hsl(var(--foreground)); }

.conv-item.active {
  background: hsl(var(--card));
  color: hsl(var(--foreground));
  font-weight: 500;
  box-shadow: inset 2px 0 0 hsl(var(--primary));
}

.conv-item span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.conv-del {
  background: none;
  border: 0;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  opacity: 0;
  font-size: 17px;
  padding: 0 2px;
}

.conv-item:hover .conv-del { opacity: 1; }
.conv-del:hover { color: hsl(var(--destructive)); }

/* Three rows: email, then controls, then the build stamp.
   The email gets a row to itself because it cannot share one — a full address
   plus three controls needs more than the ~280px sidebar has, so any
   single-row layout ends in an ellipsis ("jon.trevor@ecoms…"). Stacking is
   what makes the address readable in full. */
.sidebar-foot {
  border-top: 1px solid hsl(var(--border));
  padding: 10px 14px 12px;
  display: grid;
  /* auto / auto / 1fr: the elastic track sits between the icon toggles and
     Sign out, so the slack becomes the gap that separates them. */
  grid-template-columns: auto auto minmax(0, 1fr);
  align-items: center;
  gap: 6px 10px;
  font-size: 13px;
}

/* The two icon toggles sit together on the left; Sign out is pushed to the far
   right by the 1fr gap between them. Previously the theme toggle was adjacent
   to Sign out, which put a harmless control one slip away from a destructive
   one. */
.sidebar-foot #notify-toggle { grid-area: 2 / 1; justify-self: start; }
.sidebar-foot #theme-toggle { grid-area: 2 / 2; justify-self: start; }
.sidebar-foot #logout { grid-area: 2 / 3; justify-self: end; }

/* Row 3, under the controls. */
.build-stamp {
  grid-area: 3 / 1 / 3 / -1;
  font-family: var(--mono);
  font-size: 10px;
  color: hsl(var(--muted-foreground) / 0.7);
  text-decoration: none;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.build-stamp:hover { color: hsl(var(--primary)); }

/* Full width, and allowed to wrap rather than ellipse — a truncated address
   is useless for telling which account you are signed in as. overflow-wrap
   (not word-break) so it breaks between characters only when a single run is
   genuinely wider than the sidebar. */
.who {
  grid-area: 1 / 1 / 1 / -1;
  color: hsl(var(--muted-foreground));
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.35;
}

.link-btn {
  background: none;
  border: 0;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  font: inherit;
  padding: 0;
  white-space: nowrap;
}

.link-btn:hover { color: hsl(var(--primary)); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 20px;
  border-bottom: 1px solid hsl(var(--border));
  background: hsl(var(--card));
}

.conv-title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  font-size: 14px;
}

.pill {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  background: hsl(var(--destructive) / 0.13);
  color: hsl(var(--destructive));
  border: 1px solid hsl(var(--destructive) / 0.3);
  white-space: nowrap;
}

/* ---------- Messages ----------
   Full-bleed rows with an alternating tint, so the transcript uses the whole
   width instead of a narrow centred column. */

.messages { flex: 1; overflow-y: auto; }

.msg {
  display: flex;
  gap: 14px;
  padding: 22px 32px;
  border-bottom: 1px solid hsl(var(--border) / 0.6);
}

.msg.assistant { background: hsl(var(--card)); }

.msg .role {
  flex: 0 0 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  margin-top: 1px;
}

.msg.user .role {
  background: hsl(var(--muted));
  color: hsl(var(--muted-foreground));
}

.msg.assistant .role {
  background: linear-gradient(135deg, hsl(var(--primary)), hsl(var(--primary-strong)));
  color: hsl(var(--primary-foreground));
  font-size: 14px;
}

.msg .body {
  flex: 1;
  min-width: 0;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  padding-top: 3px;
}

.msg .body pre {
  background: hsl(var(--muted));
  border: 1px solid hsl(var(--border));
  border-radius: 8px;
  padding: 13px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 13px;
  white-space: pre;
  line-height: 1.5;
}

.msg .body code {
  font-family: var(--mono);
  font-size: 13px;
  background: hsl(var(--muted));
  padding: 1.5px 5px;
  border-radius: 4px;
}

.msg .body pre code { background: none; padding: 0; }
.msg.error .body { color: hsl(var(--destructive)); }
.msg.error .role { background: hsl(var(--destructive)); color: #fff; }

.cursor {
  display: inline-block;
  width: 7px;
  height: 15px;
  background: hsl(var(--primary));
  vertical-align: -2px;
  animation: blink 1s steps(2) infinite;
}

@keyframes blink { 50% { opacity: 0; } }

.empty { text-align: center; color: hsl(var(--muted-foreground)); margin-top: 16vh; padding: 0 24px; }
.empty-logo { width: 132px; margin: 0 auto 20px; opacity: 0.9; }
.empty h2 { margin: 0 0 8px; font-size: 19px; color: hsl(var(--foreground)); font-weight: 600; }
.empty p { margin: 0; font-size: 14px; }

/* ---------- Attachments ---------- */

.composer-wrap { border-top: 1px solid hsl(var(--border)); background: hsl(var(--card)); }

.tray {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 32px 0;
}

.thumb {
  position: relative;
  width: 68px;
  height: 68px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--muted));
  flex: 0 0 auto;
}

.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.thumb.uploading img { opacity: 0.4; }

.thumb .spin {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 11px;
  color: hsl(var(--muted-foreground));
}

.thumb .rm {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  border: 0;
  background: hsl(0 0% 0% / 0.62);
  color: #fff;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}

/* Documents have nothing to preview, so the chip carries the information:
   type, name, and what the server extracted ("12 pages", "3 sheets"). */
.thumb.doc {
  width: auto;
  min-width: 130px;
  max-width: 220px;
  height: auto;
  min-height: 68px;
  background: hsl(var(--card));
}

.doc-face {
  padding: 9px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  height: 100%;
}

.doc-ext {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: hsl(var(--primary));
}

.doc-name {
  font-size: 12px;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.doc-sum { font-size: 10.5px; color: hsl(var(--muted-foreground)); }

.msg-docs { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 8px; }

.doc-chip {
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  background: hsl(var(--muted));
  border: 1px solid hsl(var(--border));
  color: hsl(var(--muted-foreground));
}

.thumb.failed { border-color: hsl(var(--destructive)); }
.thumb.failed .spin { color: hsl(var(--destructive)); font-size: 10px; text-align: center; padding: 2px; }

/* Images inside the transcript. */
.msg-images { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 8px; }

.msg-images img {
  max-width: min(320px, 100%);
  max-height: 260px;
  border-radius: 10px;
  border: 1px solid hsl(var(--border));
  cursor: zoom-in;
  display: block;
}

/* Full-size viewer. */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: hsl(0 0% 0% / 0.88);
  display: grid;
  place-items: center;
  padding: 24px;
  cursor: zoom-out;
}

.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

.drop-hint {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: hsl(var(--primary) / 0.12);
  border: 3px dashed hsl(var(--primary));
  display: grid;
  place-items: center;
  font-weight: 600;
  color: hsl(var(--primary-strong));
  pointer-events: none;
}

/* ---------- Composer ---------- */

/* Border and background live on .composer-wrap so the attachment tray sits
   inside the same surface. */
.composer {
  padding: 14px 32px 18px;
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.composer textarea {
  flex: 1;
  background: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  border-radius: 12px;
  padding: 12px 15px;
  color: hsl(var(--foreground));
  font: inherit;
  resize: none;
  max-height: 220px;
  line-height: 1.5;
}

/* Submit only — the attach button sits in the same row but must stay a quiet
   outline, or the composer shows two identical filled squares that mean
   different things. */
.composer button[type='submit'] {
  background: linear-gradient(135deg, hsl(var(--primary)), hsl(var(--primary-strong)));
  color: hsl(var(--primary-foreground));
  border: 0;
  border-radius: 11px;
  width: 42px;
  height: 42px;
  font-size: 17px;
  cursor: pointer;
  flex: 0 0 42px;
}

.composer #attach-btn {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  font-size: 19px;
  border-radius: 11px;
}

.composer button:hover:not(:disabled) { filter: brightness(1.07); }
.composer button:disabled { opacity: 0.45; cursor: default; }

/* ---------- Admin console ---------- */

.console {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(460px, 100vw);
  z-index: 30;
  background: hsl(var(--card));
  border-left: 1px solid hsl(var(--border));
  box-shadow: -8px 0 40px hsl(0 0% 0% / 0.18);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.22s ease;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.console.open { transform: none; }
.console[hidden] { display: flex !important; visibility: hidden; }
.console.open[hidden] { visibility: visible; }

.console-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 18px;
  border-bottom: 1px solid hsl(var(--border));
  font-size: 15px;
}

.console-body { flex: 1; overflow-y: auto; padding: 6px 18px 24px; }

.console-section { padding: 16px 0; border-bottom: 1px solid hsl(var(--border) / 0.7); }
.console-section:last-child { border-bottom: 0; }

.console-section h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: hsl(var(--muted-foreground));
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.count {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 11px;
  letter-spacing: 0;
}

.op-form { display: flex; flex-direction: column; gap: 6px; }

.op-form label {
  font-size: 12px;
  font-weight: 600;
  color: hsl(var(--muted-foreground));
  margin-top: 6px;
}

.op-form select,
.op-form input {
  background: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 10px 12px;
  color: hsl(var(--foreground));
  font: inherit;
  font-size: 16px; /* 16px: stops iOS zooming the page on focus */
  width: 100%;
}

.op-form button {
  margin-top: 14px;
  background: linear-gradient(135deg, hsl(var(--primary)), hsl(var(--primary-strong)));
  color: hsl(var(--primary-foreground));
  border: 0;
  border-radius: var(--radius);
  padding: 12px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.op-form button:disabled { opacity: 0.5; cursor: default; }
.op-hint { font-size: 12px; color: hsl(var(--muted-foreground)); margin: 10px 0 0; line-height: 1.5; }
.op-hint.err { color: hsl(var(--destructive)); }
/* Success needs to be distinguishable from failure at a glance — and an
   invite link shown here may be the only copy, so it must be selectable. */
.op-hint.ok { color: hsl(142 55% 40%); user-select: all; word-break: break-all; }

/* --- Admin: clients, people, groups --- */

.admin-list { display: flex; flex-direction: column; gap: 8px; }

.admin-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid hsl(var(--border));
  border-radius: 10px;
  background: hsl(var(--background));
  font-size: 13px;
}

.admin-row-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.admin-meta {
  color: hsl(var(--muted-foreground));
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: hsl(var(--muted));
  color: hsl(var(--muted-foreground));
  white-space: nowrap;
}
.tag-pending  { background: hsl(38 92% 50% / 0.15); color: hsl(38 92% 38%); }
.tag-accepted { background: hsl(142 55% 40% / 0.15); color: hsl(142 55% 34%); }
.tag-revoked,
.tag-expired  { background: hsl(var(--destructive) / 0.12); color: hsl(var(--destructive)); }

.link-btn.danger { color: hsl(var(--destructive)); font-size: 12px; }

/* <details> keeps the forms out of the way until wanted — three stacked forms
   would otherwise dominate the panel. */
.admin-add { margin-top: 10px; }
.admin-add > summary {
  cursor: pointer;
  font-size: 13px;
  color: hsl(var(--primary));
  padding: 4px 0;
  user-select: none;
}
.admin-add[open] > summary { margin-bottom: 6px; }

.group-card {
  border: 1px solid hsl(var(--border));
  border-radius: 10px;
  background: hsl(var(--background));
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.group-card .admin-row { border: 0; padding: 0; background: none; }

.policy-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.policy-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: hsl(var(--muted-foreground));
  white-space: nowrap;
}

.policy-select {
  flex: 1;
  min-width: 0;
  padding: 7px 9px;
  border: 1px solid hsl(var(--border));
  border-radius: 8px;
  background: hsl(var(--card));
  color: hsl(var(--foreground));
  font: inherit;
  font-size: 12px;
}
/* A brief confirmation, because the change saves on select with no button. */
.policy-select.saved { border-color: hsl(142 55% 40%); }

.policy-obligations { display: flex; flex-direction: column; gap: 6px; }

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  cursor: pointer;
  line-height: 1.4;
}
.check-row input { flex: none; margin: 0; accent-color: hsl(var(--primary)); }

.req-list { display: flex; flex-direction: column; gap: 10px; }
.req-empty { color: hsl(var(--muted-foreground)); font-size: 13px; margin: 0; }

.req {
  border: 1px solid hsl(var(--border));
  border-radius: 10px;
  padding: 12px;
  background: hsl(var(--background));
  font-size: 13px;
}

/* A pending prod action is the one thing in here that should catch the eye. */
.req.pending { border-color: hsl(var(--primary) / 0.55); }
.req.pending.prod { border-color: hsl(var(--destructive) / 0.6); }

.req-top { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.req-op { font-weight: 600; }

.tag {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid hsl(var(--border));
  color: hsl(var(--muted-foreground));
}

.tag.prod { background: hsl(var(--destructive) / 0.14); color: hsl(var(--destructive)); border-color: transparent; }
.tag.dev { background: hsl(var(--muted)); }
.tag.done { background: hsl(140 60% 40% / 0.16); color: hsl(140 50% 34%); border-color: transparent; }
.tag.failed, .tag.denied { background: hsl(var(--destructive) / 0.14); color: hsl(var(--destructive)); border-color: transparent; }
.tag.pending { background: hsl(var(--primary) / 0.16); color: hsl(var(--primary-strong)); border-color: transparent; }

.req-meta { color: hsl(var(--muted-foreground)); font-size: 12px; }

.req-actions { display: flex; gap: 8px; margin-top: 10px; }

.req-actions button {
  flex: 1;
  border-radius: 8px;
  padding: 9px;
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--card));
  color: hsl(var(--foreground));
  min-height: 40px;
}

.req-actions .approve {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  border-color: transparent;
}

.req-actions button:disabled { opacity: 0.5; cursor: default; }

.req-out {
  margin: 10px 0 0;
  background: hsl(var(--muted));
  border-radius: 8px;
  padding: 9px;
  font-family: var(--mono);
  font-size: 11.5px;
  max-height: 200px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 16px;
  height: 16px;
  border-radius: 999px;
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  font-size: 10px;
  font-weight: 700;
  display: grid;
  place-items: center;
  padding: 0 4px;
}

#console-btn { position: relative; overflow: visible; }

.mobile-only { display: none; }

/* Dims the page behind the drawer and gives a tap-anywhere-to-close target. */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 19;
  background: hsl(0 0% 0% / 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.scrim.open { opacity: 1; pointer-events: auto; }

@media (max-width: 860px) {
  .mobile-only { display: grid; place-items: center; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: min(84vw, 300px);
    flex-basis: auto;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: 0 0 40px hsl(0 0% 0% / 0.3);
    /* Clear the notch and the home indicator. */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .sidebar.open { transform: none; }

  .topbar { padding: 11px 14px; padding-top: calc(11px + env(safe-area-inset-top)); }
  .conv-title { font-size: 15px; }

  .msg { padding: 16px 14px; gap: 10px; }
  .msg .body { line-height: 1.6; }

  /* Long code lines must scroll inside the block, not widen the page. */
  .msg .body pre { font-size: 12.5px; padding: 11px; max-width: 100%; }

  .composer {
    padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    gap: 8px;
  }

  /* 16px minimum: anything smaller makes iOS Safari zoom the page on focus,
     and it never zooms back out. This is the single most important mobile
     rule in the file — do not "tidy" it to match the desktop 15px. */
  .composer textarea,
  .login-card input {
    font-size: 16px;
    max-height: 140px;
  }

  /* Only the submit button gets the filled treatment. Without this selector
     the attach button inherits it too and the composer shows two identical
     orange squares with different meanings. */
  .composer button[type='submit'] { width: 44px; height: 44px; flex-basis: 44px; }
  .composer #attach-btn { width: 44px; height: 44px; flex-basis: 44px; font-size: 20px; }

  /* The tray must share the composer's horizontal padding, or thumbnails sit
     inset from the controls below them. */
  .tray { padding: 10px 12px 0; gap: 8px; }

  .thumb { width: 60px; height: 60px; }
  .thumb.doc { width: auto; min-width: 116px; max-width: 62vw; height: auto; min-height: 60px; }
  .doc-name { font-size: 11.5px; }

  /* Cap image height so one tall screenshot does not fill the whole screen
     and push the conversation out of view. */
  .msg-images img { max-width: 100%; max-height: 200px; }
  .doc-chip { font-size: 11.5px; padding: 4px 9px; }

  /* Full-bleed viewer with room for a thumb to dismiss. */
  .lightbox { padding: 12px; }

  .login-screen { padding: 16px; align-items: flex-start; padding-top: 8vh; }
  .login-card { padding: 32px 22px; }
  .login-logo { width: 132px; }

  .empty { margin-top: 8vh; }
  .empty-logo { width: 112px; }

  /* Conversation rows: comfortable thumb targets, and the delete button
     always visible since there is no hover on touch. */
  .conv-item { padding: 12px 10px; }
  .conv-del { opacity: 0.55; padding: 4px 6px; }

  /* flex-wrap was here and did nothing — the footer is a grid. */
  .sidebar-foot { padding: 12px 14px; gap: 6px 12px; }
}

/* Short landscape phones: reclaim the vertical space the splash wastes. */
@media (max-height: 500px) and (orientation: landscape) {
  .login-screen { padding-top: 3vh; }
  .login-card { padding: 20px 22px; }
  .login-logo { width: 108px; margin-bottom: 2px; }
  .login-sub { margin: 6px 0 14px; }
  .empty { margin-top: 3vh; }
  .empty-logo { width: 88px; margin-bottom: 10px; }
}
