/* ===========================================================================
   دفتر — a document office, not a developer console.

   Palette is drawn from Iranian official stationery rather than the usual
   cream-and-terracotta: blue-black document ink on faintly green security
   paper, with the violet of an official seal reserved for actions.
   =========================================================================== */

@font-face {
  font-family: 'Estedad'; src: url('/fonts/Estedad-Regular.ttf') format('truetype');
  font-weight: 400; font-display: swap;
}
@font-face {
  font-family: 'Estedad'; src: url('/fonts/Estedad-Medium.ttf') format('truetype');
  font-weight: 500; font-display: swap;
}
@font-face {
  font-family: 'Estedad'; src: url('/fonts/Estedad-SemiBold.ttf') format('truetype');
  font-weight: 600; font-display: swap;
}
@font-face {
  font-family: 'Estedad'; src: url('/fonts/Estedad-Bold.ttf') format('truetype');
  font-weight: 700; font-display: swap;
}
/* B Titr is THE Iranian document headline face. Used only for the wordmark
   and the seal — loud enough that restraint is the whole point. */
@font-face {
  font-family: 'BTitr'; src: url('/fonts/BTitr-Bold.ttf') format('truetype');
  font-weight: 700; font-display: swap;
}

/* Every colour is declared once, as light-dark(day, night).
 *
 * `color-scheme: light dark` on the root means those pairs resolve from the OS
 * preference on their own, so an untouched app follows the system. The switch
 * in the sidebar then only has to pin `color-scheme` to one value — which is
 * what the [data-theme] rules below do — instead of restating the palette.
 * A duplicated dark block is how this file used to work, and duplicated
 * palettes drift: the user bubble was already wrong in one of the two. */
:root {
  color-scheme: light dark;

  --ink:        light-dark(#16253A, #E8EDE9);
  --ink-soft:   light-dark(#3A4A5E, #B9C4BD);
  --muted:      light-dark(#66756B, #8B9990);
  --paper:      light-dark(#F6F8F6, #121A17);
  --tint:       light-dark(#E8EEEA, #1B2521);
  --tint-deep:  light-dark(#DBE5DD, #24302B);
  --rule:       light-dark(#CBD6CE, #2E3A34);
  --seal:       light-dark(#7A2E4E, #D98BAE);
  --seal-soft:  light-dark(#9B4268, #E7A9C4);
  --seal-wash:  light-dark(#F3E7ED, #2A1C23);
  /* Text on a seal-coloured fill. In dark mode the seal is a pale pink, so
     white on it is unreadable — near-black is. */
  --on-seal:    light-dark(#FFFFFF, #16110F);

  /* The user's own message. Explicit tokens rather than reusing --ink/--paper:
     the dark-mode override previously set this text to --paper, which in dark
     mode is the near-black page background — 1.29:1 against the bubble, i.e.
     unreadable. A bright bubble also makes "mine" scannable at a glance, and
     it stays bright at night on purpose. */
  --bubble-bg:  light-dark(#EBDCE5, #E4D5DF);
  --bubble-fg:  light-dark(#1B2331, #191019);
  --warn:       light-dark(#8A5A1B, #E0B571);
  --warn-wash:  light-dark(#FBF1E1, #2A2214);
  /* Deliberately not the seal colour: destructive must not look like ordinary. */
  --danger:      light-dark(#9B2C2C, #E08585);
  --danger-soft: light-dark(#B03A3A, #EDA0A0);
  --danger-wash: light-dark(#FBEAEA, #2E1A1A);

  --radius:     14px;
  --radius-sm:  9px;
  --shadow:     0 1px 2px light-dark(rgba(22,37,58,.06), rgba(0,0,0,.4)),
                0 6px 20px light-dark(rgba(22,37,58,.06), rgba(0,0,0,.3));

  /* Generous by default: the reader is not 25. */
  --fs-body:    17px;
  --fs-msg:     17.5px;
  --lh-msg:     1.95;

  /* Wide enough for a chat title, which is the first 40 characters of what he
     asked for — a sentence, not a label. Held between a floor and a ceiling so
     it never crowds a small laptop nor eats a widescreen. */
  --sidebar-w:  clamp(268px, 24vw, 332px);
}


/* ---- role palettes ----------------------------------------------------------
   Lawyer keeps the tokens above exactly (an account with no role shows the
   same). The other roles set five base tokens and derive the rest, so each
   reads as its own room while sharing one structure. --danger is declared only
   above: destructive must look the same in every role. */
:root[data-role="general"], :root[data-role="designer"],
:root[data-role="developer"], :root[data-role="admin"] {
  --ink-soft:  color-mix(in srgb, var(--ink) 80%, var(--paper));
  --muted:     color-mix(in srgb, var(--ink) 68%, var(--paper));
  --tint-deep: color-mix(in srgb, var(--tint) 85%, var(--ink));
  --rule:      color-mix(in srgb, var(--tint) 75%, var(--ink));
  --seal-soft: color-mix(in srgb, var(--seal) 82%, var(--paper));
  --seal-wash: color-mix(in srgb, var(--seal) 10%, var(--paper));
  --warn-wash: color-mix(in srgb, var(--warn) 12%, var(--paper));
}
:root[data-role="general"] {
  --paper:     light-dark(#F7F7F5, #141618);
  --tint:      light-dark(#ECEDE9, #1E2124);
  --ink:       light-dark(#1F2430, #E9EBEA);
  --seal:      light-dark(#0F766E, #5EC8B8);
  --bubble-bg: light-dark(#D7EFEA, #CFEDE7);
}
:root[data-role="designer"] {
  --paper:     light-dark(#FBF7F4, #18121A);
  --tint:      light-dark(#F3EAE3, #231A26);
  --ink:       light-dark(#2A1F24, #F1E8EE);
  --seal:      light-dark(#A21CAF, #E59AF0);
  --bubble-bg: light-dark(#F3DDF5, #EED6F2);
}
:root[data-role="developer"] {
  --paper:     light-dark(#F5F7FB, #0E1320);
  --tint:      light-dark(#E8EDF6, #171E2E);
  --ink:       light-dark(#141B2D, #E6EAF4);
  --seal:      light-dark(#4338CA, #9EA8F7);
  --bubble-bg: light-dark(#DDE1FA, #D9DEFA);
}
:root[data-role="admin"] {
  --paper:     light-dark(#F7F6F2, #151412);
  --tint:      light-dark(#ECEAE2, #211F1B);
  --ink:       light-dark(#1E1E1E, #EDEAE3);
  --seal:      light-dark(#B45309, #F2B866);
  --bubble-bg: light-dark(#F6E5CC, #F1E2C9);
}

/* An explicit choice overrides the OS in BOTH directions. No attribute at all
   means "follow the system", which is the state the app starts in. */
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"]  { color-scheme: dark; }

* { box-sizing: border-box; }

/* The `hidden` attribute only sets `display: none` at user-agent priority, so
   any later `display` rule silently defeats it. `.login` and `.app` both set
   display, which left the sign-in screen and the app rendering on top of each
   other. Make hidden authoritative. */
[hidden] { display: none !important; }

html, body {
  height: 100%; margin: 0;
  font-family: 'Estedad', system-ui, sans-serif;
  font-size: var(--fs-body);
  color: var(--ink);
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
}
body { overflow: hidden; }
/* iPhone, installed on the home screen: after turning to landscape and back,
   WebKit can keep the landscape height or a page scroll offset - the top slid
   out of the window and a blank band showed below. The page itself never
   scrolls (only the thread does): both roots clip, the height follows the live
   viewport (dvh), and app.js puts any leftover offset back to 0 on every
   resize/rotation (settleViewport). */
html { overflow: hidden; overscroll-behavior: none; }
@supports (height: 100dvh) {
  /* --app-h: the installed app's measured height (app.js, measureAppHeight). */
  html, body { height: var(--app-h, 100dvh); }
}
/* viewport-fit=cover draws under the phone's own bars: the notch, the status bar,
   and on Android, where an installed app runs edge to edge, the back/home bar
   at the bottom. Only the sides were kept clear, so the box to type in could sit
   under the phone's buttons. Every edge now; the bottom gives its room back while
   the keyboard is up (it covers that bar anyway). */
.app { padding-inline: constant(safe-area-inset-left) constant(safe-area-inset-right);
  padding-inline: env(safe-area-inset-left) env(safe-area-inset-right);
  padding-block: env(safe-area-inset-top, 0px) env(safe-area-inset-bottom, 0px); box-sizing: border-box; }
:root.kb-open .app { padding-block-end: 0; }

button, input, textarea, select { font: inherit; color: inherit; }
svg { width: 1.25em; height: 1.25em; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

:focus-visible { outline: 2.5px solid var(--seal); outline-offset: 2px; border-radius: 4px; }

/* ------------------------------- the seal -------------------------------- */
/* Signature motif: an official stamp. Appears as the mark, and again on every
   document the assistant produces. */
.seal {
  display: grid; place-items: center;
  width: 40px; height: 40px; flex: none;
  border: 2.5px solid var(--seal);
  border-radius: 50%;
  color: var(--seal);
  font-family: 'BTitr', serif;
  font-size: 15px; line-height: 1;
  transform: rotate(-7deg);
  opacity: .92;
}
.seal-lg { width: 72px; height: 72px; font-size: 20px; border-width: 3px; margin-inline: auto; }

/* -------------------------------- buttons -------------------------------- */
.btn {
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: .62em 1.05em; font-weight: 600; cursor: pointer;
  background: transparent; transition: background .15s, border-color .15s, opacity .15s;
}
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--seal); color: var(--on-seal); }
.btn-primary:hover:not(:disabled) { background: var(--seal-soft); }
.btn-quiet { border-color: var(--rule); color: var(--ink-soft); }
.btn-quiet:hover { background: var(--tint); }
/* Reserved for the one action that cannot be undone. */
.btn-danger { background: var(--danger); color: var(--on-seal); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); }
.btn-block { display: block; width: 100%; }

.icon-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px; flex: none;
  border: none; border-radius: var(--radius-sm);
  background: transparent; color: var(--ink-soft); cursor: pointer;
}
.icon-btn:hover { background: var(--tint); color: var(--ink); }

/* The mic while it is listening: a red dot and a running clock take the place
   of the icon, so there is no doubt it is recording. */
.icon-btn.mic { position: relative; }
.icon-btn.mic[aria-pressed="true"] { color: var(--danger); background: var(--danger-wash); }
.icon-btn.mic[aria-pressed="true"] svg { display: none; }
.mic-time { font-size: .72em; font-variant-numeric: tabular-nums; font-weight: 600; }
.mic-time::before {
  content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: currentColor; margin-inline-end: 4px; animation: mic-blink 1s steps(1) infinite;
}
@keyframes mic-blink { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .mic-time::before { animation: none; } }

.linkish {
  border: none; background: none; padding: 0;
  color: var(--muted); cursor: pointer; text-decoration: underline;
  text-underline-offset: 3px; font-size: .88em;
}
.linkish:hover { color: var(--seal); }

/* --------------------------------- login --------------------------------- */
.login { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; background: var(--paper); }
/* clear of the phone's bars too (see .app) */
.login { padding-block: max(24px, env(safe-area-inset-top, 0px)) max(24px, env(safe-area-inset-bottom, 0px)); }
.login-card {
  width: min(370px, 100%);
  background: var(--paper); border: 1px solid var(--rule);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 34px 30px 30px;
}
.login-title { font-family: 'BTitr', serif; font-size: 30px; margin: 16px 0 2px; text-align: center; letter-spacing: .01em; }
.login-sub { margin: 0 0 26px; text-align: center; color: var(--muted); font-size: .93em; }
.field { display: block; margin-bottom: 15px; }
.field span { display: block; font-size: .87em; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%; padding: .72em .85em;
  border: 1px solid var(--rule); border-radius: var(--radius-sm);
  background: var(--paper);
}
.field input:focus { border-color: var(--seal); outline: none; }
.login-error {
  background: var(--seal-wash); color: var(--seal);
  border-radius: var(--radius-sm); padding: .65em .85em; margin: 0 0 14px; font-size: .9em;
}

/* ---------------------------------- shell -------------------------------- */
.app { display: flex; height: 100%; }

.sidebar {
  width: var(--sidebar-w); flex: none;
  display: flex; flex-direction: column; gap: 14px;
  padding: 18px 14px;
  background: var(--tint);
  border-inline-start: 1px solid var(--rule); /* RTL: sits on the right */
  /* A column flex container whose height is fixed by the viewport. Without
     this the list below cannot be told to shrink, and a long history pushes
     the sign-out row off the bottom of the screen. */
  min-height: 0; overflow: hidden;
}

.brand { display: flex; align-items: center; gap: 11px; }
.brand-text h1 { font-family: 'BTitr', serif; font-size: 21px; margin: 0; line-height: 1.3; }
.brand-text p { margin: 0; font-size: .78em; color: var(--muted); }

/* Day / night, at the far inline-end of the header — the left, in RTL. */
/* Search and day/night sit together at the end of the header. The circle is
   shared so the pair reads as one control group rather than two lookalikes
   that drifted apart. */
.brand-tools { margin-inline-start: auto; flex: none; display: flex; gap: 6px; }
.brand-btn {
  flex: none;
  display: grid; place-items: center;
  width: 34px; height: 34px; padding: 0;
  border: 1px solid var(--rule); border-radius: 50%;
  background: var(--paper); color: var(--ink-soft); cursor: pointer;
  transition: color .15s, border-color .15s, transform .15s;
}
.brand-btn:hover { color: var(--seal); border-color: var(--seal); transform: translateY(-1px); }
/* Stroke, weight and joins come from the global svg rule; only the size differs. */
.brand-btn svg { width: 17px; height: 17px; }
/* One icon shows what you will GET, not where you are: a moon by day. */
.theme-btn .t-sun { display: none; }
.theme-btn .t-moon { display: block; }
:root[data-theme="dark"] .theme-btn .t-sun { display: block; }
:root[data-theme="dark"] .theme-btn .t-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-btn .t-sun { display: block; }
  :root:not([data-theme="light"]) .theme-btn .t-moon { display: none; }
}

/* min-height:0 is the load-bearing line. A flex item defaults to
   min-height:auto, which refuses to shrink below its content — so with enough
   chats the list grew past the sidebar instead of scrolling inside it, and the
   items ran into the footer. */
.chat-list {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 2px;
  margin-inline: -6px; padding-inline: 6px;
  scrollbar-width: thin; scrollbar-color: var(--rule) transparent;
}
.chat-list::-webkit-scrollbar { width: 8px; }
.chat-list::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 99px; }
.chat-list::-webkit-scrollbar-track { background: transparent; }

/* Older chats arrive a page at a time, so the list opens short and readable
   however long the history gets. */
.load-more {
  margin: 6px 0 2px; padding: .5em .7em;
  border: 1px dashed var(--rule); border-radius: var(--radius-sm);
  background: none; color: var(--muted); cursor: pointer;
  font-size: .84em; text-align: center; flex: none;
}
.load-more:hover { border-style: solid; border-color: var(--seal); color: var(--seal); }
.chat-item {
  display: flex; align-items: flex-start; gap: 7px;
  width: 100%; text-align: start;
  border: none; background: none; cursor: pointer;
  padding: .55em .7em; border-radius: var(--radius-sm);
  color: var(--ink-soft); font-size: .93em; line-height: 1.6;
}
/* Two lines, not one. Every title was being cut mid-word at a single line —
   they are sentences, and a 40-character sentence does not fit a sidebar. */
.chat-name {
  flex: 1; min-width: 0;
  display: -webkit-box; -webkit-box-orient: vertical;
  /* At most two lines (the owner's call): a third made the list on a phone
     read as a wall of text. The longest titles end in an ellipsis; the whole
     title is in the row's tooltip. A short title still takes one line. */
  -webkit-line-clamp: 2; line-clamp: 2;
  overflow: hidden; overflow-wrap: anywhere;
}
/* The row is a button plus a bin, side by side — a button cannot contain
   another button — so the hover and selection styling lives on the pair. */
.chat-row { display: flex; align-items: stretch; border-radius: var(--radius-sm); }
.chat-row:hover { background: var(--tint-deep); }
.chat-row:hover .chat-item { color: var(--ink); }
.chat-row:has(.chat-item[aria-current="true"]) {
  background: var(--paper); box-shadow: var(--shadow);
}
.chat-item[aria-current="true"] { color: var(--ink); font-weight: 600; }
.chat-item .dot { flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--seal); margin-top: .5em; }

.chat-del {
  flex: none; align-self: center;
  display: grid; place-items: center;
  width: 30px; height: 30px; margin-inline-end: 4px; padding: 0;
  border: none; border-radius: var(--radius-sm);
  background: none; color: var(--muted); cursor: pointer;
  /* Dim rather than hidden. A hover-only control is undiscoverable, and the
     reader here will not go looking for one. */
  opacity: .38; transition: opacity .12s, color .12s;
}
.chat-del svg { width: 16px; height: 16px; }
.chat-row:hover .chat-del, .chat-del:focus-visible { opacity: 1; }
.chat-del:hover { color: var(--danger); background: var(--danger-wash); }

/* Renaming in place. Sized to sit exactly where the title was, so the row does
   not jump when it turns into a field. */
.chat-rename {
  width: 100%;
  padding: .5em .65em; border-radius: var(--radius-sm);
  border: 1px solid var(--seal); background: var(--paper); color: var(--ink);
  font-size: .93em; line-height: 1.6;
}
.chat-rename:focus { outline: none; }

.sidebar-foot { display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--rule); padding-top: 12px; }
.who { display: flex; justify-content: space-between; align-items: center; font-size: .85em; color: var(--muted); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 16px; border-bottom: 1px solid var(--rule);
  background: var(--paper);
}
.topbar-title { font-size: 1.02em; font-weight: 600; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-state { font-size: .82em; color: var(--muted); }
#menu-btn { display: none; }

/* --------------------------------- thread -------------------------------- */
.thread { flex: 1; overflow-y: auto; padding: 26px 20px 8px; scroll-behavior: smooth; }
.thread-inner, .msg, .doc-card, .notice, .ask { max-width: 720px; margin-inline: auto; }

/* break-word: a long address or path with no spaces wraps instead of pushing
   the thread sideways on a phone; ordinary text breaks exactly as before. */
.msg { margin-bottom: 22px; line-height: var(--lh-msg); font-size: var(--fs-msg); overflow-wrap: break-word; }
.msg p { margin: 0 0 .85em; }
.msg p:last-child { margin-bottom: 0; }
.msg pre {
  background: var(--tint); border: 1px solid var(--rule); border-radius: var(--radius-sm);
  padding: .8em 1em; overflow-x: auto; direction: ltr; text-align: left;
  font-family: ui-monospace, monospace; font-size: .85em; line-height: 1.6;
}
.msg code { font-family: ui-monospace, monospace; font-size: .88em; background: var(--tint); padding: .12em .35em; border-radius: 4px; direction: ltr; display: inline-block; max-width: 100%; box-sizing: border-box; }
.msg pre code { background: none; padding: 0; display: inline; }

/* ---- markdown block elements ---- */
/* h1 is reserved for the wordmark, so assistant headings start at h2. */
.msg h2, .msg h3, .msg h4, .msg h5, .msg h6 {
  font-family: 'BTitr', 'Estedad', serif;
  font-weight: 700; line-height: 1.55;
  margin: 1.5em 0 .5em; color: var(--ink);
}
.msg h2 { font-size: 1.32em; }
.msg h3 { font-size: 1.16em; }
.msg h4 { font-size: 1.04em; font-family: 'Estedad', sans-serif; }
.msg h5, .msg h6 { font-size: 1em; font-family: 'Estedad', sans-serif; color: var(--ink-soft); }
.msg-body > :first-child { margin-top: 0; }
.msg-body > :last-child { margin-bottom: 0; }

.msg hr {
  border: none; height: 1px; background: var(--rule);
  margin: 1.6em 0;
}

.msg ul, .msg ol { margin: 0 0 .9em; padding-inline-start: 1.5em; }
.msg li { margin-bottom: .35em; }
.msg li::marker { color: var(--seal); }
.msg ul ul, .msg ol ol { margin-bottom: 0; }

.msg blockquote {
  margin: 0 0 .9em; padding: .1em 1em;
  border-inline-start: 3px solid var(--seal);
  color: var(--ink-soft); background: var(--tint);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.msg a { color: var(--seal); text-underline-offset: 3px; }
.msg a:hover { text-decoration-thickness: 2px; }

/* Tables scroll inside their own box rather than widening the page. */
.table-wrap { overflow-x: auto; margin: 0 0 1em; border-radius: var(--radius-sm); }
.msg table { border-collapse: collapse; width: 100%; font-size: .93em; }
.msg th, .msg td {
  border: 1px solid var(--rule); padding: .5em .7em; text-align: start;
}
.msg th { background: var(--tint); font-weight: 600; }
.msg tbody tr:nth-child(even) { background: color-mix(in srgb, var(--tint) 45%, transparent); }

/* ---- copy button ---- */
.msg-tools { display: flex; gap: 6px; margin-top: .5em; opacity: 0; transition: opacity .15s; }
.msg-assistant:hover .msg-tools,
.msg-assistant:focus-within .msg-tools { opacity: 1; }
@media (hover: none) { .msg-tools { opacity: 1; } }  /* touch: always visible */

.copy-btn {
  display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid var(--rule); border-radius: var(--radius-sm);
  background: var(--paper); color: var(--muted);
  padding: .3em .7em; font-size: .82em; cursor: pointer;
}
.copy-btn:hover { border-color: var(--seal); color: var(--seal); }
.copy-btn svg { width: 1em; height: 1em; }
.copy-btn.done { color: var(--seal); border-color: var(--seal); }

/* The user's own message sits inside the same 720px reading column as
   everything else, aligned to the inline-end edge (the left, in RTL — the
   mirrored convention Persian messaging apps use). Putting the auto margin on
   the bubble itself cancelled the column centring and let it hug the viewport
   edge on wide screens. */
.row-user { max-width: 720px; margin-inline: auto; display: flex; flex-direction: column; align-items: flex-end; margin-bottom: 22px; }
/* His message's copy button sits under the bubble, shown on hover (always on touch). */
.row-user .msg-tools { margin-top: .3em; }
.row-user:hover .msg-tools, .row-user:focus-within .msg-tools { opacity: 1; }
.msg-user {
  background: var(--bubble-bg); color: var(--bubble-fg);
  padding: .85em 1.15em; border-radius: var(--radius);
  border-end-end-radius: 5px;
  width: fit-content; max-width: min(560px, 85%);
  margin: 0; line-height: var(--lh-msg); font-size: var(--fs-msg);
  /* His own message is inserted with textContent, so the newlines he typed are
     really there — HTML just collapses them into spaces without this. He
     writes numbered lists of corrections; run together they were unreadable.
     The assistant side never showed this because it goes through MD.render. */
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

/* What he attached, above what he wrote, on the same side. Only rows that
   carry attachments change shape; a plain message is laid out as before. */
.row-user.has-att { gap: 8px; }
.att-list {
  display: flex; flex-direction: column; align-items: stretch; gap: 6px;
  width: min(360px, 85%);
}
/* The produced-document card, compact: same paper, rule and seal. */
.att-card {
  display: flex; align-items: center; gap: 10px;
  background: var(--paper); border: 1px solid var(--rule);
  border-radius: var(--radius); padding: 8px 10px;
}
.att-card .doc-seal { width: 34px; height: 34px; font-size: .52em; border-width: 1.5px; }
.att-card .doc-name { font-size: .92em; }
.att-card .btn { padding: .4em .8em; font-size: .88em; }
.att-voice { display: flex; flex-direction: column; gap: 3px; }
.att-voice audio { width: 100%; height: 40px; }
.att-voice-dl {
  align-self: flex-end; font-size: .78em; color: var(--muted);
  max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.att-voice-dl:hover { color: var(--seal); }

.msg-assistant { color: var(--ink); }

.notice {
  font-size: .88em; padding: .6em .9em; border-radius: var(--radius-sm);
  margin-bottom: 18px; border: 1px solid transparent;
}
.notice-warn { background: var(--warn-wash); color: var(--warn); border-color: currentColor; }
.notice-info { background: var(--tint); color: var(--muted); }

/* Live status. One row, pinned above the composer — quiet, but never absent
   while the assistant is working. */
.status {
  display: flex; align-items: center; gap: 8px;
  max-width: 720px; margin: 0 auto 9px;
  color: var(--seal); font-size: .86em;
  background: var(--seal-wash); border-radius: var(--radius-sm);
  padding: .42em .8em;
  animation: status-in .18s ease;
}
.status-elapsed { margin-inline-start: auto; color: var(--muted); font-variant-numeric: tabular-nums; font-size: .92em; flex: none; white-space: nowrap; }
/* A step named in Claude's own words can be long: one line, cut short, whole on hover. */
#status-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; unicode-bidi: plaintext; }
/* Work left running after the turn: quieter than a turn in progress, but alive. */
.status.bg { background: var(--tint); color: var(--ink-soft); }
.status.bg .pulse { animation-duration: 2.8s; }
@media (max-width: 560px) {
  /* A phone has room for the time or the step on one line, not both: the step gets two. */
  #status-text { white-space: normal; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; line-height: 1.35; }
}
.pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--seal); animation: pulse 1.4s ease-in-out infinite; flex: none; }
@keyframes pulse { 0%,100% { opacity: .25; transform: scale(.8); } 50% { opacity: 1; transform: scale(1); } }
@keyframes status-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* Finished: green-free, just calm and unmistakable, then it fades out. */
.status.done { background: var(--tint); color: var(--ink-soft); }
.status.done .pulse { animation: none; background: var(--seal); opacity: .9; }

/* A routine note (a scratch file landing in the right place) is not a warning. */
.notice-routine { background: var(--tint); color: var(--muted); border-color: transparent; font-size: .84em; }

/* ---- typewriter caret ---- */
/* Sits at the end of the text being typed. Inline-block so it rides the last
   line rather than starting a new one. */
.caret {
  display: inline-block; width: 2px; height: 1.05em;
  background: var(--seal); vertical-align: text-bottom;
  margin-inline-start: 2px; border-radius: 1px;
  animation: blink 1.05s step-end infinite;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* ---- jump to newest ---- */
.to-bottom {
  position: absolute; inset-block-end: 152px; inset-inline-start: 50%;
  transform: translateX(50%);
  display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--rule); background: var(--paper); color: var(--ink-soft);
  box-shadow: var(--shadow); cursor: pointer; z-index: 4;
  animation: status-in .18s ease;
}
.to-bottom:hover { color: var(--seal); border-color: var(--seal); }
/* In LTR inline-start is the left edge, so centring pulls the other way. */
:root[dir="ltr"] .to-bottom { transform: translateX(-50%); }
.to-bottom-badge {
  position: absolute; inset-block-start: -5px; inset-inline-end: -5px;
  min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 9px; background: var(--seal); color: var(--on-seal);
  font-size: .68em; line-height: 17px; text-align: center;
}
.main { position: relative; }

/* ------------------------- signature: document card ---------------------- */
/* Every file the assistant produces arrives stamped, like a notarised page. */
.doc-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--paper); border: 1px solid var(--rule);
  border-radius: var(--radius); padding: 13px 15px; margin-bottom: 14px;
  box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
/* the ruled edge of a document */
.doc-card::before {
  content: ''; position: absolute; inset-block: 0; inset-inline-start: 0;
  width: 4px; background: repeating-linear-gradient(
    to bottom, var(--seal) 0 6px, transparent 6px 12px);
  opacity: .5;
}
.doc-seal {
  display: grid; place-items: center; flex: none;
  width: 46px; height: 46px; border-radius: 50%;
  border: 2px solid var(--seal); color: var(--seal);
  font-size: .62em; font-weight: 700; letter-spacing: .04em;
  transform: rotate(-11deg); opacity: .9;
}
.doc-meta { flex: 1; min-width: 0; }
.doc-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-sub { font-size: .82em; color: var(--muted); margin-top: 2px; }
/* An older version of a file whose newer card is further down. Still there,
   still downloadable — the link serves the current bytes — but not the one
   to reach for. */
.doc-card.doc-stale { opacity: .55; }

/* ---------------------------- question card ------------------------------ */
/* Claude asking the user to choose. Options are large, plainly worded targets —
   this is the one moment the app asks him for something. */
.ask-q {
  max-width: 720px; margin: 0 auto 20px;
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--paper); box-shadow: var(--shadow);
  overflow: hidden;
}
.ask-q-head {
  padding: 12px 16px 0;
}
.ask-q-chip {
  display: inline-block; font-size: .74em; font-weight: 600;
  color: var(--seal); background: var(--seal-wash);
  border-radius: 999px; padding: .2em .7em; margin-bottom: 8px;
}
.ask-q-text { font-weight: 600; line-height: 1.75; margin: 0 0 12px; }
.ask-q-body { padding: 0 16px 14px; display: flex; flex-direction: column; gap: 7px; }

.opt {
  display: flex; align-items: flex-start; gap: 10px;
  width: 100%; text-align: start; cursor: pointer;
  border: 1px solid var(--rule); border-radius: var(--radius-sm);
  background: var(--paper); padding: .7em .9em;
  transition: border-color .12s, background .12s;
}
.opt:hover { border-color: var(--seal); background: var(--seal-wash); }
.opt[aria-pressed="true"] { border-color: var(--seal); background: var(--seal-wash); }
.opt-mark {
  flex: none; width: 18px; height: 18px; margin-top: .2em;
  border: 2px solid var(--rule); border-radius: 50%;
  display: grid; place-items: center;
}
.opt[data-multi="1"] .opt-mark { border-radius: 5px; }
.opt[aria-pressed="true"] .opt-mark { border-color: var(--seal); background: var(--seal); }
.opt[aria-pressed="true"] .opt-mark::after {
  content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--paper);
}
.opt-label { font-weight: 600; }
.opt-desc { font-size: .86em; color: var(--muted); margin-top: 2px; line-height: 1.6; }

.ask-q-other { display: flex; gap: 7px; }
.ask-q-other input {
  flex: 1; border: 1px solid var(--rule); border-radius: var(--radius-sm);
  padding: .6em .8em; background: var(--paper);
}
.ask-q-other input:focus { border-color: var(--seal); outline: none; }
.ask-q-foot { display: flex; gap: 8px; padding: 0 16px 14px; }
.ask-q.answered { opacity: .75; }
.ask-q-answer {
  padding: 10px 16px 14px; font-size: .9em; color: var(--ink-soft);
}
.ask-q-answer b { color: var(--seal); }

/* ---------------------------- permission card ---------------------------- */
.ask {
  border: 1px solid var(--seal); border-radius: var(--radius);
  background: var(--seal-wash); padding: 15px 17px; margin-bottom: 18px;
}
.ask h4 { margin: 0 0 6px; font-size: 1em; }
.ask .what {
  font-family: ui-monospace, monospace; font-size: .82em; direction: ltr; text-align: left;
  background: var(--paper); border-radius: var(--radius-sm); padding: .55em .7em;
  margin: 8px 0 12px; overflow-x: auto; white-space: pre-wrap; word-break: break-all;
  border: 1px solid var(--rule);
}
.ask-row { display: flex; gap: 9px; }

/* -------------------------------- composer ------------------------------- */
.composer-wrap { border-top: 1px solid var(--rule); background: var(--paper); padding: 12px 20px 14px; }
.controls { display: flex; gap: 9px; max-width: 720px; margin: 0 auto 10px; flex-wrap: wrap; }
.ctl { display: flex; align-items: center; gap: 6px; font-size: .84em; color: var(--muted); }
.ctl-label { white-space: nowrap; }
.ctl select {
  border: 1px solid var(--rule); border-radius: var(--radius-sm);
  /* The chevron is drawn at the physical left, which is inline-END in RTL —
     so the clearance for it must be padding-inline-end, not a physical value. */
  padding-block: .34em; padding-inline-start: .6em; padding-inline-end: 1.7em;
  background: var(--paper); color: var(--ink);
  cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><path d='M3 5l3 3 3-3' fill='none' stroke='%2366756B' stroke-width='1.6' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat; background-position: left .45em center; background-size: 12px;
}
.ctl select:hover { border-color: var(--seal); }


.composer {
  display: flex; align-items: flex-end; gap: 8px;
  max-width: 720px; margin: 0 auto;
  border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 6px; background: var(--paper);
  transition: border-color .15s;
}
.composer:focus-within { border-color: var(--seal); }
.composer textarea {
  flex: 1; border: none; background: none; resize: none;
  padding: .55em .35em; max-height: 190px; line-height: 1.75;
}
.composer textarea:focus { outline: none; }
/* The hint stays on one line however narrow the phone: cut with an ellipsis
   rather than wrapped into a second line that makes the box look full. */
.composer textarea::placeholder { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Fluid, not one phone breakpoint: the buttons, gaps and the hint's size follow
   the composer's own width (container units), so the hint stays on one line at
   any width — a phone, a split screen, a narrow window — and nothing is smaller
   than it has to be. Plain values first for browsers without container units. */
.composer-wrap { container-type: inline-size; }
.composer { gap: clamp(2px, 1.6cqi, 8px); padding: clamp(4px, 1.4cqi, 6px); }
.composer .icon-btn { width: clamp(30px, 9.5cqi, 40px); }
.composer .btn-send { width: clamp(34px, 10cqi, 40px); height: clamp(34px, 10cqi, 40px); }
.composer .btn-stop { height: clamp(34px, 10cqi, 40px); padding-inline: clamp(.45em, 2.4cqi, 1em); }
.composer textarea { padding-inline: clamp(.15em, 1cqi, .35em); }
.composer textarea::placeholder { font-size: clamp(.74em, 4.6cqi, 1em); }
/* Vertical centring, at the root: the row is aligned to the bottom, and a
   one-line textarea was 48px tall while the buttons were 35-40px, so every
   button hung 4-7px below the text (and Stop's label, padded like any .btn
   inside a fixed height, lower still). Now every control is one height, and a
   single line of text fills exactly that height with the text centred in it:
   the buttons sit on the text's centre line, and once it wraps they stay with
   the last line, where the writing is. */
.composer { --ctl-h: 40px; }
@supports (width: 1cqi) { .composer { --ctl-h: clamp(34px, 10cqi, 40px); } }
.composer .icon-btn, .composer .btn-send, .composer .btn-stop { height: var(--ctl-h); }
.composer .btn-send { width: var(--ctl-h); }
.composer .btn-stop { display: inline-grid; place-items: center; padding-block: 0; line-height: 1; }
.composer textarea {
  min-height: var(--ctl-h);
  padding-block: max(0px, calc((var(--ctl-h) - 1.75em) / 2));
}
.btn-send { display: grid; place-items: center; width: 40px; height: 40px; padding: 0; flex: none; background: var(--seal); color: var(--on-seal); border-radius: var(--radius-sm); }
.btn-send:hover:not(:disabled) { background: var(--seal-soft); }
/* The arrow points the way the writing goes: left in Persian, right in English. */
[dir="rtl"] .btn-send svg { transform: scaleX(-1); }
.btn-stop { border-color: var(--rule); color: var(--seal); flex: none; }
/* A message sent while it works, not yet read to Claude. */
.row-user.mid-turn .msg-user { opacity: .7; }
.mid-turn-note { font-size: .74em; color: var(--muted); margin-top: 3px; text-align: end; }
/* A message the server never got: faded, edged in the warning colour, and said so. */
.row-user.send-failed .msg-user { opacity: .7; outline: 1.5px dashed var(--warn); outline-offset: 2px; }
.send-failed-note { font-size: .74em; color: var(--warn); margin-top: 3px; text-align: end; }

.hint { max-width: 720px; margin: 7px auto 0; font-size: .78em; color: var(--muted); min-height: 1.1em; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; max-width: 720px; margin: 0 auto 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--tint); border: 1px solid var(--rule); border-radius: 999px;
  padding: .25em .75em; font-size: .82em;
}
.chip button { border: none; background: none; cursor: pointer; color: var(--muted); padding: 0; line-height: 1; }
.chip button:hover { color: var(--seal); }

/* A chip carries its own progress: the fill is the bar, so a file that is
   still arriving looks different from one that has arrived without needing a
   separate row of furniture under the composer. */
.chip { position: relative; overflow: hidden; max-width: 100%; box-sizing: border-box; }
/* The name is one unbreakable word: a long one is cut with an ellipsis rather
   than pushing the chip, and the composer with it, off a narrow screen. */
.chip > .chip-fill + span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-fill {
  position: absolute; inset-block: 0; inset-inline-start: 0;
  width: 0; background: var(--seal-wash);
  transition: width .18s linear;
  pointer-events: none;
}
/* Lift the label and buttons above the fill — but NOT the fill itself, which
   must stay absolute. `.chip > *` would have matched it too, at equal
   specificity and later in the file, quietly flattening the bar. */
.chip > span:not(.chip-fill), .chip > button { position: relative; }
.chip-pct { color: var(--muted); font-variant-numeric: tabular-nums; }
.chip-ready { color: var(--seal); }
.chip-failed { border-color: var(--danger); color: var(--danger); }
.chip-failed .chip-fill { background: var(--danger-wash); }

/* A model this platform does not offer. Greyed rather than removed, so that a
   model he remembers choosing before reads as a decision, not a disappearance. */
.ctl select option:disabled { color: var(--muted); font-style: italic; }

/* -------------------------------- search --------------------------------- */
.hit-group { margin: 0 0 6px; font-size: .8em; color: var(--muted); font-weight: 600; }
.hit-group + .hit-group { margin-top: 14px; }
.hit {
  display: block; width: 100%; text-align: start;
  background: none; border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: .6em .7em; margin-bottom: 4px; cursor: pointer;
  color: inherit; font: inherit;
}
.hit:hover, .hit:focus-visible { background: var(--tint); border-color: var(--rule); }
.hit-title { font-weight: 600; font-size: .95em; margin-bottom: .25em; overflow-wrap: anywhere; }
.hit-snippet {
  font-size: .88em; color: var(--ink-soft); line-height: 1.75;
  /* The snippet is one line of his own words; a long contract must not push
     the panel sideways. */
  overflow-wrap: anywhere;
}
.hit-mark { background: var(--seal-wash); color: var(--seal); border-radius: 3px; padding: 0 .15em; }

/* Where a search landed. Brief, because it is a pointer, not a selection. */
@keyframes flash-in { from { background: var(--seal-wash); } to { background: transparent; } }
.flash { animation: flash-in 1.6s ease-out; border-radius: var(--radius-sm); }
@media (prefers-reduced-motion: reduce) { .flash { animation: none; outline: 2px solid var(--seal); } }

/* --------------------------------- dialog -------------------------------- */
.dialog { border: 1px solid var(--rule); border-radius: var(--radius); padding: 0; width: min(560px, 92vw); max-height: 78vh; background: var(--paper); color: var(--ink); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(22,37,58,.45); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--rule); margin: 0; }
.dialog-head h3 { margin: 0; font-size: 1.02em; }
.dialog-body { padding: 12px 18px 18px; overflow-y: auto; }

.dialog-sm { width: min(420px, 92vw); }
.dialog-body p { margin: 0 0 12px; line-height: 1.85; }
.delete-warn {
  background: var(--danger-wash); color: var(--danger);
  border-radius: var(--radius-sm); padding: .55em .8em; font-size: .88em;
}
.dialog-actions { display: flex; gap: 8px; margin-top: 16px; }

.dialog-search {
  display: flex; align-items: center; gap: 8px;
  margin: 12px 18px 0; padding: .5em .75em;
  border: 1px solid var(--rule); border-radius: var(--radius-sm);
  background: var(--paper); color: var(--muted);
}
.dialog-search:focus-within { border-color: var(--seal); color: var(--seal); }
.dialog-search svg { width: 1.05em; height: 1.05em; flex: none; }
.dialog-search input {
  flex: 1; min-width: 0; border: none; background: none;
  color: var(--ink); font-size: .93em;
}
.dialog-search input:focus { outline: none; }
/* The browser's own clear button is drawn on the wrong edge under RTL. */
.dialog-search input::-webkit-search-cancel-button { -webkit-appearance: none; }
.dialog-count { margin: 8px 18px 0; font-size: .8em; color: var(--muted); min-height: 1.2em; }
/* Only the results scroll; the search box stays put above them. Scoped to
   [open] because a bare `display` here would override the closed dialog's
   user-agent `display: none` and leave it on screen permanently. */
.dialog[open] { display: flex; flex-direction: column; }
.dialog-body { flex: 1; min-height: 0; }

/* ------------------------------- account -------------------------------- */
.whoami {
  border: none; background: none; padding: .1em .3em; margin-inline-start: -.3em;
  color: inherit; font: inherit; cursor: pointer; border-radius: 6px;
  text-decoration: underline dotted; text-underline-offset: 4px;
}
.whoami:hover { color: var(--seal); background: var(--tint-deep); }

.acct-block { padding-bottom: 6px; }
.acct-block + .acct-block { margin-top: 22px; border-top: 1px solid var(--rule); padding-top: 18px; }
.acct-block h4 { margin: 0 0 10px; font-size: 1em; }
.acct-head { display: flex; align-items: center; gap: 10px; justify-content: space-between; flex-wrap: wrap; }
.acct-head h4 { margin: 0; }
.acct-note { margin: 0 0 12px; font-size: .84em; color: var(--muted); }
.acct-msg {
  margin: 0 0 12px; padding: .55em .8em; border-radius: var(--radius-sm); font-size: .87em;
  background: var(--seal-wash); color: var(--seal);
}
.acct-msg.good { background: var(--tint); color: var(--ink-soft); }
.inline-form + .acct-msg { margin-top: 10px; }

.session {
  display: flex; align-items: center; gap: 12px;
  border: 1px solid var(--rule); border-radius: var(--radius-sm);
  padding: .7em .85em; margin-bottom: 8px;
}
.session-main { flex: 1; min-width: 0; }
.session-device { font-weight: 600; }
.session-device .here {
  font-weight: 400; font-size: .78em; color: var(--seal);
  background: var(--seal-wash); border-radius: 999px; padding: .1em .6em; margin-inline-start: 7px;
}
/* Addresses and times read left-to-right even inside a right-to-left line. */
.session-meta { font-size: .82em; color: var(--muted); margin-top: 3px; unicode-bidi: plaintext; }
.session[data-current="1"] { border-color: var(--seal); background: var(--seal-wash); }

.empty { text-align: center; color: var(--muted); padding: 46px 20px; }
.empty .seal { margin-inline: auto; margin-bottom: 16px; }
.empty h3 { font-family: 'BTitr', serif; font-weight: 400; font-size: 1.3em; margin: 0 0 8px; color: var(--ink); }
.empty p { margin: 0; font-size: .93em; line-height: 1.9; }

.scrim { display: none; position: fixed; inset: 0; background: rgba(22,37,58,.4); border: none; z-index: 5; }

/* -------------------------------- responsive ----------------------------- */
@media (max-width: 780px) {
  /* The drawer is pinned to the inline-end edge, which in RTL is the RIGHT.
     translateX is not direction-aware — positive X is always rightwards — so
     hiding it off-screen is +100% regardless of direction. An earlier RTL
     override used -100%, which slid it back INTO view. */
  .sidebar {
    position: fixed; inset-block: 0; z-index: 6;
    /* inset-inline-START is the RIGHT edge in RTL — the same side the sidebar
       occupies in the desktop layout, so the drawer slides in from where the
       user already expects it. (inset-inline-END resolves to the left here,
       which pinned it to the wrong side entirely.) */
    inset-inline-start: 0;
    transform: translateX(100%); transition: transform .22s ease;
    box-shadow: var(--shadow);
    width: min(86vw, 340px);   /* a drawer can afford more room than a column */
    /* pinned to the screen, not inside .app: its own room for the phone's bars */
    padding-block: calc(18px + env(safe-area-inset-top, 0px)) calc(18px + env(safe-area-inset-bottom, 0px));
  }
  .sidebar.open { transform: translateX(0); }
  /* In LTR the drawer sits on the left, so it hides leftwards. */
  :root[dir="ltr"] .sidebar { transform: translateX(-100%); }
  :root[dir="ltr"] .sidebar.open { transform: translateX(0); }
  .scrim[data-open] { display: block; }
  #menu-btn { display: grid; }
  .thread { padding-inline: 15px; }
  .composer-wrap { padding-inline: 15px; }
  :root { --fs-msg: 17px; }
}

/* ------------------------- day / night transition ------------------------ */
/* The new theme is revealed under a circle growing out of the switch, rather
   than cross-faded. Both default animations are cancelled so the only motion
   is the clip-path the script animates; the incoming snapshot sits on top so
   the old one is uncovered rather than blended. */
::view-transition-old(root),
::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
::view-transition-new(root) { z-index: 9999; }
::view-transition-old(root) { z-index: 1; }
/* The marker the theme switch measures itself by: invisible, never in the way. */
.vt-probe { position: fixed; width: 1px; height: 1px; pointer-events: none; view-transition-name: vt-probe; }
::view-transition-group(vt-probe) { animation: none; opacity: 0; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* ------------------------------- views ----------------------------------- */
/* The main pane holds one view at a time: the chat, Settings or Admin. */
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
.view-page { overflow-y: auto; padding: 24px 20px 40px; display: block; }
.page { max-width: 760px; margin: 0 auto; }
.page h4 { margin: 0 0 10px; font-size: 1.02em; }
.page h5 { margin: 14px 0 8px; font-size: .95em; display: flex; align-items: center; gap: 8px; }
.page h6 { margin: 12px 0 6px; font-size: .85em; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input { flex: 1; }
.page input[type="text"], .page input[type="password"], .page input[type="number"], .page select, .page textarea {
  font: inherit; color: var(--ink); background: var(--paper);
  border: 1px solid var(--rule); border-radius: var(--radius-sm); padding: 8px 10px;
}
.page textarea { width: 100%; min-height: 96px; }

/* The role switcher and the admin's own navigation, in the sidebar. */
.role-pick { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; }
.role-pick select { flex: 1; font: inherit; color: var(--ink); background: var(--paper);
  border: 1px solid var(--rule); border-radius: var(--radius-sm); padding: 6px 8px; }
.admin-nav { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; }
.admin-nav-btn { font: inherit; text-align: start; background: none; border: 0; color: var(--ink);
  padding: 9px 12px; border-radius: var(--radius-sm); cursor: pointer; }
.admin-nav-btn:hover, .admin-nav-btn[aria-current="true"] { background: var(--seal-wash); color: var(--seal); }
.side-warn { margin: 0 0 8px; padding: 8px 10px; border-radius: var(--radius-sm);
  background: var(--warn-wash); color: var(--warn); font-size: .85em; }
/* The chat's role as one coloured dot (its name is the tooltip and the label
   for screen readers): the full name took a line of its own on a phone. */
.chat-role { flex: none; width: 9px; height: 9px; border-radius: 50%; margin-top: .55em;
  background: var(--role-c, var(--muted)); }
/* Each role's colour is the colour of its circle in the role dropdown (app.js
   ROLE_MARK): a native <select> cannot be styled on an iPhone, so there the
   circle is an emoji, and the dots here follow the emoji, not the reverse. */
.chat-role[data-role="general"], .role-tag[data-role="general"] { --role-c: #3aa757; }
.chat-role[data-role="lawyer"], .role-tag[data-role="lawyer"] { --role-c: #a0673e; }
.chat-role[data-role="designer"], .role-tag[data-role="designer"] { --role-c: #a05bd8; }
.chat-role[data-role="developer"], .role-tag[data-role="developer"] { --role-c: #2f80ed; }
.chat-role[data-role="admin"], .role-tag[data-role="admin"] { --role-c: #f08a24; }
/* In the chat list the dot leads the name (the right in Persian, the left in
   English): the inline end is where the "working" dot appears, and the two
   side by side read as one blinking thing. */
.chat-item > .chat-role { order: -1; }

/* Usage: exact and estimated figures are labelled, never mixed. */
.usage-head { color: var(--muted); margin: 0 0 8px; font-size: .9em; }
.usage-block { margin-top: 10px; }
.usage-row { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0;
  border-bottom: 1px dashed var(--rule); font-size: .92em; }
.usage-k { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.usage-v { color: var(--ink-soft); white-space: nowrap; unicode-bidi: plaintext; }
.usage-over .usage-v { color: var(--warn); font-weight: 600; }
.tag { font-size: .72em; font-weight: 600; border-radius: 999px; padding: 1px 8px; }
.tag-exact { background: var(--seal-wash); color: var(--seal); }
.tag-estimate { background: var(--warn-wash); color: var(--warn); }
.open-row { margin: 4px 0; font-size: .92em; }

/* ------------------------------- admin ----------------------------------- */
.adm-users { display: flex; flex-direction: column; gap: 8px; }
.adm-user-row, .adm-chat { font: inherit; color: inherit; text-align: start; cursor: pointer;
  display: flex; flex-direction: column; gap: 4px; padding: 10px 12px;
  border: 1px solid var(--rule); border-radius: var(--radius-sm); background: var(--paper); }
.adm-chat { flex-direction: row; align-items: center; gap: 6px; margin-bottom: 6px; width: 100%; }
.adm-user-row:hover, .adm-chat:hover { border-color: var(--seal); }
.adm-user-main { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.adm-user-meta { font-size: .85em; color: var(--muted); }
.adm-tags { display: inline-flex; gap: 4px; flex-wrap: wrap; }
/* In a user's card the roles get a line of their own under the name, so a long
   name and five roles never squeeze each other. */
.adm-user-main .adm-tags { flex-basis: 100%; }
/* A role by name: a small pill led by the role's dot (the dot alone is
   .chat-role, in the chat lists). */
.role-tag { display: inline-flex; align-items: center; gap: 5px; font-size: .75em; font-weight: 600;
  line-height: 1.5; white-space: nowrap; color: var(--ink-soft); background: var(--tint);
  border-radius: 999px; padding: 1px 8px; }
.role-tag::before { content: ""; flex: none; width: 7px; height: 7px; border-radius: 50%;
  background: var(--role-c, var(--muted)); }
.adm-over { color: var(--warn); font-weight: 600; }
.adm-off { background: var(--danger-wash); color: var(--danger); margin-inline-start: 6px; }
.adm-title { margin: 12px 0; }
.adm-banner { margin-bottom: 12px; }
.adm-form { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.adm-form .btn { align-self: flex-start; }
.adm-roles { display: flex; flex-wrap: wrap; gap: 10px 16px; }
.check { display: inline-flex; align-items: center; gap: 6px; }
.adm-chat-view .msg { margin: 10px 0; }
/* An admin's view of a user's files: as many columns as fit, never a fixed count. */
.adm-files { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 180px), 1fr)); gap: 12px; margin-top: 10px; }
.adm-file { min-width: 0; border: 1px solid var(--rule); border-radius: var(--radius-sm); padding: 8px; background: var(--paper); }
.adm-file img, .adm-file video { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: contain; background: var(--tint); border-radius: 4px; margin-bottom: 6px; }
.adm-file audio { width: 100%; margin-bottom: 6px; }
.adm-file .doc-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.adm-file-meta { margin: 2px 0 0; font-size: .8em; overflow-wrap: anywhere; }
.adm-chat-view .msg-user { background: var(--bubble-bg); color: var(--bubble-fg); border-radius: var(--radius-sm); padding: 8px 12px; white-space: pre-wrap; }
.skill-row { padding: 8px 0; border-bottom: 1px dashed var(--rule); }
.skill-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dialog-sm { width: min(440px, 92vw); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.dialog-sm input { width: 100%; font: inherit; padding: 8px 10px; border: 1px solid var(--rule);
  border-radius: var(--radius-sm); background: var(--paper); color: var(--ink); }

/* ------------------------- a faster thread ------------------------------- */
/* Off-screen messages skip layout and paint; 'auto' remembers each one's real
   size once seen, so scrolling back does not jump. */
.msg, .row-user, .notice, .doc-card { content-visibility: auto; contain-intrinsic-size: auto 140px; }
.att-card { min-height: 52px; }
#thread-top { height: 1px; }
.chat-item.opening { background: var(--tint); }
#status.queued #status-elapsed { display: none; }

/* --------------------------- image and video previews --------------------- */
.doc-card.has-preview { flex-wrap: wrap; }
.doc-preview { flex: 1 0 100%; height: 280px; display: flex; align-items: center; justify-content: center;
  background: var(--tint); border-radius: var(--radius-sm); overflow: hidden; margin-bottom: 8px; }
.doc-preview img, .doc-preview video { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.adm-render { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }

/* Every other dropdown gets the same drawn chevron, set in from the edge, and
   room for it on the inline-end side (the left in Persian, the right in
   English) so the text never runs under it. */
.role-pick select, .page select {
  appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><path d='M3 5l3 3 3-3' fill='none' stroke='%2366756B' stroke-width='1.6' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat; background-size: 12px;
  background-position: left .8em center;
  padding-inline-end: 2.4em;
}
.ctl select { background-position: left .6em center; padding-inline-end: 2em; }
[dir="ltr"] .ctl select { background-position: right .6em center; }
[dir="ltr"] .role-pick select, [dir="ltr"] .page select { background-position: right .8em center; }
.role-pick select:hover, .page select:hover { border-color: var(--seal); }

/* ---------------------------- the seal, refined ---------------------------
   A stamp has a second, finer ring inside the first. */
.seal { position: relative; }
.seal::before { content: ''; position: absolute; inset: 3px; border-radius: 50%;
  border: 1px dashed currentColor; opacity: .5; pointer-events: none; }
.seal-lg::before { inset: 5px; }

/* ------------------------------ the waves --------------------------------
   The moving edge of the cover and the opening screen: a strip wider than the
   screen by one wave, masked into crests, sliding sideways forever. Its colour
   is the layer's own (currentColor), so it follows the theme and the role. */
:root {
  --wave-up: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='48' viewBox='0 0 240 48'%3E%3Cpath d='M0 24Q60 -8 120 24T240 24V48H0Z'/%3E%3C/svg%3E");
  --wave-down: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='48' viewBox='0 0 240 48'%3E%3Cpath d='M0 24Q60 56 120 24T240 24V0H0Z'/%3E%3C/svg%3E");
}
.crest { position: absolute; left: 0; right: 0; height: 48px; overflow: hidden; pointer-events: none; }
.crest-top { bottom: 100%; margin-bottom: -1px; }
.crest-bot { top: 100%; margin-top: -1px; }
.wv { position: absolute; top: 0; bottom: 0; left: 0; width: calc(100% + 240px); background: currentColor;
  -webkit-mask: var(--wave-up) repeat-x 0 0 / 240px 48px; mask: var(--wave-up) repeat-x 0 0 / 240px 48px;
  animation: wv 1.5s linear infinite; will-change: transform; }
.wv-back { opacity: .45; -webkit-mask-position: 120px 0; mask-position: 120px 0; animation-duration: 2.6s; animation-direction: reverse; }
.wv-down { -webkit-mask-image: var(--wave-down); mask-image: var(--wave-down); animation-duration: 1.9s; }
@keyframes wv { from { transform: translate3d(0, 0, 0); } to { transform: translate3d(-240px, 0, 0); } }

/* The cover: ink first, then paper with the seal; both leave upward. */
.cover { position: fixed; inset: 0; z-index: 70; overflow: hidden; cursor: progress; }
.cover-l { position: absolute; inset: 0; transform: translate3d(0, calc(100% + 60px), 0); will-change: transform; }
.cover-ink { background: var(--seal); color: var(--seal); }
.cover-paper { background: var(--paper); color: var(--paper); display: grid; place-items: center; }
.cover-seal { color: var(--seal); border-color: var(--seal); transform: rotate(-7deg) scale(1.25); }

/* --------------------------------- opening ---------------------------------
   The seal is stamped on the role's colour while the app finds out who is
   signed in; the paper rises behind it as it loads, covers it, and drains
   away upward to show the page. */
.splash { position: fixed; inset: 0; z-index: 50; overflow: hidden; pointer-events: none; background: var(--seal); transition: opacity .35s ease, visibility .35s; }
.splash.out { opacity: 0; visibility: hidden; }
.splash.drain { background: transparent; }
.splash.drain > .splash-seal { visibility: hidden; }
.splash-seal { position: absolute; left: 50%; top: 50%; width: 104px; height: 104px; margin: -52px 0 0 -52px; border-radius: 50%;
  display: grid; place-items: center; border: 3.5px solid var(--on-seal); color: var(--on-seal);
  font-family: 'BTitr', serif; font-size: 27px; animation: stamp .7s cubic-bezier(.2,.9,.25,1.15) both; }
.splash-seal::before { content: ''; position: absolute; inset: 6px; border-radius: 50%; border: 1.5px dashed currentColor; opacity: .6;
  animation: ring-turn 9s linear infinite; }
.splash-seal::after { content: ''; position: absolute; inset: -3.5px; border-radius: 50%; border: 3.5px solid var(--on-seal);
  animation: ink 1.1s .45s ease-out both; }
.splash-pour { position: absolute; inset: 0; background: var(--paper); color: var(--paper);
  transform: translate3d(0, calc(100% + 60px), 0); animation: pour-in 2.4s .25s cubic-bezier(.22,.7,.2,1) forwards; will-change: transform; }
/* While loading, the paper climbs, but never past the seal. */
@keyframes pour-in { to { transform: translate3d(0, 64%, 0); } }
@keyframes stamp {
  0%   { opacity: 0; transform: scale(1.6) rotate(8deg); }
  60%  { opacity: 1; transform: scale(.94) rotate(-9deg); }
  100% { opacity: 1; transform: scale(1) rotate(-7deg); }
}
@keyframes ink { from { opacity: .45; transform: scale(1); } to { opacity: 0; transform: scale(1.45); } }
@keyframes ring-turn { to { transform: rotate(360deg); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ---------------------------------- motion ----------------------------------
   Small and quick: things arrive rather than appear. All of it is switched off
   by the reduced-motion rule above. */
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(6px); } to { opacity: 1; transform: none; } }

.login-card { animation: pop .45s cubic-bezier(.2,.8,.2,1) both; }
.login-card .seal { animation: stamp .7s .1s cubic-bezier(.2,.9,.25,1.15) both; }

/* A new message, a reply, a file, a question: each slides up into place. */
.row-user, .msg-assistant, .doc-card, .ask, .ask-q, .notice { animation: rise .32s cubic-bezier(.2,.8,.2,1) both; }
.empty { animation: rise .45s cubic-bezier(.2,.8,.2,1) both; }
.empty .seal { animation: stamp .7s .05s cubic-bezier(.2,.9,.25,1.15) both; }

/* Changing screens (chat, Settings, Admin) fades the new one in. */
.view:not([hidden]) { animation: fade-in .22s ease-out both; }

/* Dialogs open from a little below and the page dims behind them. */
.dialog[open] { animation: pop .26s cubic-bezier(.2,.8,.2,1) both; }
.dialog[open]::backdrop { animation: fade-in .26s ease-out both; }

/* Pressing a button gives a little. */
.btn, .chat-item, .theme-btn, .icon-btn { transition: transform .12s ease, background-color .18s ease, border-color .18s ease, color .18s ease, opacity .15s ease; }
.btn:active:not(:disabled), .chat-item:active, .theme-btn:active, .icon-btn:active { transform: scale(.97); }
.btn-send:active:not(:disabled) svg { transition: transform .12s ease; transform: translateX(-2px); }
[dir="rtl"] .btn-send:active:not(:disabled) svg { transform: scaleX(-1) translateX(-2px); }

/* The chat being opened (the double-click window) gets a soft pulse. */
.chat-item.opening { animation: pulse-bg .6s ease-in-out infinite; }
@keyframes pulse-bg { 50% { background: var(--seal-wash); } }

.no-enter { animation: none !important; }

/* An answer on its way: the card stays, quieter, until the server has it. */
.ask-sending { opacity: .75; }
.ask-note { margin: 8px 0 0; font-size: .88em; color: var(--muted); }
.ask-note-bad { color: var(--danger, #B42318); font-weight: 600; }

/* The plan-limits status bar: two thin meters, like Claude Code's status line. */
.plan-limits { display: grid; gap: 6px; padding: 10px 12px; margin-bottom: 10px; border: 1px solid var(--rule); border-radius: var(--radius-sm); background: var(--tint); font-size: .82em; }
.plan-limits[hidden] { display: none; }
.pl-title { font-weight: 700; color: var(--ink-soft); }
.pl-row { display: grid; grid-template-columns: 3.6em 1fr auto; align-items: center; gap: 4px 8px; }
.pl-bar { block-size: 6px; border-radius: 3px; background: var(--tint-deep); overflow: hidden; }
.pl-bar i { display: block; block-size: 100%; border-radius: 3px; background: var(--seal); transition: inline-size .6s cubic-bezier(.2,.8,.2,1); }
.pl-row[data-level="mid"] .pl-bar i { background: #C98A1B; }
.pl-row[data-level="high"] .pl-bar i { background: var(--danger); }
.pl-pct { font-variant-numeric: tabular-nums; font-weight: 600; }
.pl-when { grid-column: 2 / -1; color: var(--muted); font-size: .92em; margin-top: -2px; }
.pl-at { color: var(--muted); font-size: .92em; }

/* Document fonts in Settings. */
.font-group { display: grid; gap: 8px; margin-block: 10px 16px; }
.font-group h5 { margin: 0; font-size: .95em; color: var(--ink-soft); }
.font-pick { display: grid; grid-template-columns: 5em 1fr; align-items: center; gap: 8px; margin: 0; }
.font-sample { margin: 2px 0 0; padding: 10px 12px; border: 1px dashed var(--rule); border-radius: var(--radius-sm); font-size: 1.15em; line-height: 1.7; }
.font-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--rule); }
.font-name { flex: 1; font-size: 1.1em; }
.font-size { color: var(--muted); font-size: .88em; font-variant-numeric: tabular-nums; }
.btn-sm { padding: .35em .8em; font-size: .88em; }

/* ---------------------------------- gallery ----------------------------------
   A wall of tiles of different heights (CSS grid with small rows; each tile
   spans as many as its picture needs), and a viewer on black. */
.gallery-btn { display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 8px; }
.gallery-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.gallery-view { padding-inline: 14px; }
.gal-page { max-width: 1200px; margin: 0 auto; }
.gal-bar { display: flex; gap: 8px; margin-bottom: 10px; }
.gal-bar input { flex: 1; min-width: 0; }
.gal-types { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.gal-types button { border: 1px solid var(--rule); background: transparent; color: var(--ink-soft); border-radius: 999px; padding: .35em .9em; cursor: pointer; font: inherit; font-size: .9em; transition: background-color .18s, color .18s, border-color .18s; }
.gal-types button .n { opacity: .65; font-variant-numeric: tabular-nums; }
.gal-types button[aria-pressed="true"] { background: var(--seal); border-color: var(--seal); color: var(--on-seal); }
.gal-sum { margin: 4px 2px 12px; color: var(--muted); font-size: .88em; min-height: 1.2em; }
.gal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(46%, 190px), 1fr)); grid-auto-rows: 8px; column-gap: 12px; align-items: start; }
.gal-empty { grid-column: 1 / -1; text-align: center; padding: 40px 10px; }
.gal-tile { display: block; padding: 0; border: 0; background: none; cursor: zoom-in; text-align: start; border-radius: 14px; animation: rise .35s cubic-bezier(.2,.8,.2,1) both; }
.gal-media { position: relative; overflow: hidden; border-radius: 14px; background: var(--tint); box-shadow: 0 1px 0 var(--rule); transition: transform .2s ease, box-shadow .2s ease; }
.gal-tile:hover .gal-media, .gal-tile:focus-visible .gal-media { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(0,0,0,.14); }
.gal-media img, .gal-media video { display: block; inline-size: 100%; block-size: auto; min-block-size: 80px; }
.gal-broken { min-block-size: 120px; }
.gal-size, .gal-badge { position: absolute; inset-block-end: 8px; padding: 2px 8px; border-radius: 999px; background: rgba(10,10,12,.62); color: #fff; font-size: .74em; font-variant-numeric: tabular-nums; backdrop-filter: blur(4px); }
.gal-size { inset-inline-start: 8px; }
.gal-badge { inset-inline-end: 8px; }
.gal-sound { display: grid; place-items: center; align-content: center; gap: 8px; padding: 14px; color: #fff;
  background: linear-gradient(150deg, hsl(var(--h) 62% 52%), hsl(calc(var(--h) + 40) 58% 36%)); }
.gal-sound svg { width: 42px; height: 42px; fill: none; stroke: currentColor; stroke-width: 1.6; opacity: .9; }
.gal-sound-name { font-size: .82em; text-align: center; word-break: break-word; opacity: .95; }
.gal-skel { cursor: default; border-radius: 14px; background: linear-gradient(100deg, var(--tint) 30%, var(--tint-deep) 50%, var(--tint) 70%); background-size: 300% 100%; animation: shimmer 1.3s linear infinite; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

/* The viewer: always dark, whatever the theme, so the work is what you see. */
.gal-viewer { position: fixed; inset: 0; width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0;
  background: #000; color: #f2f2f2; overflow: hidden; }
.gal-viewer[open] { display: block; animation: fade-in .2s ease-out both; }
.gal-viewer::backdrop { background: #000; }
.gv-top { position: absolute; inset-inline: 0; inset-block-start: 0; z-index: 3; display: flex; align-items: center; gap: 6px; padding: max(8px, env(safe-area-inset-top)) 10px 8px;
  background: linear-gradient(rgba(0,0,0,.6), rgba(0,0,0,0)); }
.gv-count { flex: 1; text-align: center; font-variant-numeric: tabular-nums; opacity: .8; font-size: .9em; }
.gv-btn { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; border: 0; background: rgba(255,255,255,.1); color: #fff; cursor: pointer; }
.gv-btn:hover { background: rgba(255,255,255,.2); }
.gv-btn svg, .gv-nav svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.gv-danger:hover { background: rgba(220,60,60,.55); }
.gv-stage { position: absolute; inset: 0; display: grid; place-items: center; padding: 60px 8px 150px; touch-action: pan-y; }
.gv-stage img, .gv-stage video { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; animation: pop .25s cubic-bezier(.2,.8,.2,1) both; }
.gv-sound { display: grid; justify-items: center; gap: 14px; padding: 28px; border-radius: 22px; min-width: min(86vw, 380px);
  background: linear-gradient(150deg, hsl(var(--h) 62% 45%), hsl(calc(var(--h) + 40) 58% 28%)); }
.gv-sound svg { width: 72px; height: 72px; fill: none; stroke: #fff; stroke-width: 1.4; }
.gv-sound p { margin: 0; text-align: center; word-break: break-word; }
.gv-sound audio { width: 100%; }
.gv-nav { position: absolute; z-index: 2; inset-block-start: 45%; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(255,255,255,.12); color: #fff; cursor: pointer; }
.gv-nav:disabled { opacity: 0; pointer-events: none; }
/* Next is further along the reading direction: on the left in Persian. */
.gv-next { inset-inline-start: 10px; }
.gv-prev { inset-inline-end: 10px; }
[dir="ltr"] .gv-next { inset-inline-start: auto; inset-inline-end: 10px; }
[dir="ltr"] .gv-prev { inset-inline-end: auto; inset-inline-start: 10px; }
[dir="ltr"] .gv-nav svg { transform: scaleX(-1); }
@media (hover: none) { .gv-nav { display: none; } }

/* The sheet: a few lines of the chat at the bottom; drag or tap it up for all of it. */
.gv-sheet { --peek: 168px; --full: min(78dvh, 640px); --drag: 0px;
  position: absolute; z-index: 4; inset-inline: 0; inset-block-end: 0; max-width: 760px; margin-inline: auto;
  block-size: var(--full); transform: translateY(calc(var(--full) - var(--peek) + var(--drag)));
  display: flex; flex-direction: column; padding: 0 16px max(12px, env(safe-area-inset-bottom));
  background: rgba(18,18,22,.86); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-radius: 18px 18px 0 0; box-shadow: 0 -10px 30px rgba(0,0,0,.4);
  transition: transform .32s cubic-bezier(.2,.8,.2,1); touch-action: none; }
.gv-sheet.open { transform: translateY(max(0px, var(--drag))); }
.gv-sheet.dragging { transition: none; }
.gv-grip { display: grid; place-items: center; block-size: 26px; border: 0; background: none; cursor: grab; flex: none; }
.gv-grip i { width: 40px; height: 4px; border-radius: 2px; background: rgba(255,255,255,.35); }
.gv-text { flex: 1; min-height: 0; overflow: hidden; color: #e9e9ee;
  -webkit-mask-image: linear-gradient(#000 55%, transparent); mask-image: linear-gradient(#000 55%, transparent); }
.gv-sheet.open .gv-text { overflow-y: auto; touch-action: pan-y; -webkit-mask-image: none; mask-image: none; }
.gv-chat { margin: 0 0 2px; font-weight: 700; }
.gv-meta { margin: 0 0 10px; font-size: .8em; color: rgba(255,255,255,.6); }
.gv-label { margin: 12px 0 4px; font-size: .76em; letter-spacing: .02em; color: rgba(255,255,255,.55); text-transform: uppercase; }
.gv-prompt { margin: 0; white-space: pre-wrap; }
.gv-reply { color: #dcdce2; }
.gv-reply a { color: #9cc9ff; }
.gv-reply pre, .gv-reply code { background: rgba(255,255,255,.08); color: #eee; }
.gv-grip { order: -2; }
.gv-go { order: -1; flex: none; align-self: flex-start; margin: 0 0 8px; padding: .45em 1.1em; font-size: .9em; }
.gv-toast { position: absolute; z-index: 5; inset-block-start: 64px; inset-inline: 0; margin: 0 auto; width: fit-content; max-width: 90vw;
  padding: 8px 14px; border-radius: 999px; background: rgba(255,255,255,.92); color: #111; font-size: .9em; animation: pop .2s ease-out both; }

/* A download in progress: the button fills as the file arrives (app.js). */
.dl-busy { background-image: linear-gradient(to left, var(--seal-wash) var(--dl, 0%), transparent var(--dl, 0%)); font-variant-numeric: tabular-nums; }
[dir="ltr"] .dl-busy { background-image: linear-gradient(to right, var(--seal-wash) var(--dl, 0%), transparent var(--dl, 0%)); }
.dl-ready { background: var(--seal); color: var(--on-seal); border-color: var(--seal); }
/* An icon-only button (the gallery's) shows the count as a badge. */
.dl-busy[data-progress] { position: relative; }
.dl-busy[data-progress]::after {
  content: attr(data-progress); position: absolute; inset-block-start: -8px; inset-inline-end: -6px;
  padding: 1px 6px; border-radius: 999px; font-size: 11px; line-height: 1.5;
  background: var(--seal); color: var(--on-seal); white-space: nowrap;
}

/* --- this chat's files (chat-files.js): a list, newest first --- */
.chat-files-btn[hidden] { display: none; }
.chat-files-dialog { width: min(560px, 94vw); }
.cf-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.cf-row {
  display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; align-items: center; gap: 12px;
  padding: 8px; border: 1px solid var(--rule); border-radius: var(--radius-sm); background: var(--paper);
}
.cf-thumb {
  position: relative; width: 56px; height: 56px; border-radius: var(--radius-sm); overflow: hidden;
  display: grid; place-items: center; padding: 0; border: none;
  background: var(--tint); color: var(--muted); font: inherit;
}
button.cf-thumb { cursor: pointer; }
button.cf-thumb:focus-visible { outline: 2px solid var(--seal); outline-offset: 2px; }
.cf-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cf-ext { font-size: .72em; font-weight: 700; letter-spacing: .03em; color: var(--seal); }
.cf-play {
  position: absolute; inset-block-end: 4px; inset-inline-start: 4px; font-size: .62em; line-height: 1;
  padding: 3px 5px; border-radius: 6px; background: rgba(0,0,0,.55); color: #fff;
}
.cf-meta { min-width: 0; }
.cf-name { font-weight: 600; font-size: .92em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cf-sub { font-size: .78em; color: var(--muted); margin-top: 3px; font-variant-numeric: tabular-nums; display: flex; flex-wrap: wrap; column-gap: 10px; row-gap: 2px; }
.cf-sub > span { unicode-bidi: isolate; white-space: nowrap; }

/* One copy button per reply: only on its last text block (app.js syncCopyButtons). */
.msg-assistant.reply-part > .msg-tools { display: none; }
/* ---------------------------- install the app ---------------------------- */
/* Once, at the bottom, above everything (the sign-in screen included: a first
   visit is exactly when it matters). Clear of the iPhone's home bar. */
.install-card {
  position: fixed; z-index: 1000;
  inset-inline: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  max-width: 440px; margin-inline: auto;
  display: grid; grid-template-columns: auto 1fr auto; gap: 4px 12px; align-items: start;
  padding: 14px 14px 12px; border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--paper); color: var(--ink); box-shadow: var(--shadow), 0 10px 30px rgb(0 0 0 / .18);
  animation: install-in .25s ease-out;
}
@keyframes install-in { from { transform: translateY(16px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .install-card { animation: none; } }
.install-icon { width: 44px; height: 44px; border-radius: 10px; grid-row: span 2; }
.install-text { min-width: 0; font-size: .92em; line-height: 1.6; }
.install-text p { margin: 2px 0 0; color: var(--ink-soft); }
.install-steps { margin: 4px 0 0; padding: 0; list-style: none; color: var(--ink-soft); }
.install-steps li { margin: 2px 0; }
.install-share { width: 1.25em; height: 1.25em; vertical-align: -.25em; fill: none; stroke: var(--seal);
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.install-x { width: 32px; height: 32px; margin: -6px; font-size: 1.4em; line-height: 1; }
.install-actions { grid-column: 2 / -1; display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }

/* ------------------------------- the ghost seal -------------------------------
   The seal stays still in the middle while the layers pass over it; where a
   layer covers it, it shows in that layer's inverse colour (white on the
   role's colour, the role's colour on white), cut along the moving wave.
   Each layer carries its own copy of the seal inside a clip of its own
   shape: the top wave, the body, the bottom wave. The clip moves with the
   layer; the copy inside moves back by the same amount, so it never moves.
   Only transforms are animated (the masks themselves stay put), so the
   phone's compositor does the work:
     ghost       the top wave's mask, sliding with the front wave (1.5 s)
     ghost-un    undoes that slide
     ghost-b     the bottom wave's mask, sliding with its wave (1.9 s)
     ghost-b-un  undoes that slide
     ghost-view  the screen's box, moved against the layer (JS or CSS) */
.ghost { position: absolute; top: -47px; bottom: -47px; left: 0; right: -240px; pointer-events: none;
  -webkit-mask: var(--wave-up) repeat-x 0 0 / 240px 48px, linear-gradient(#000, #000) no-repeat 0 48px / 100% 100%;
          mask: var(--wave-up) repeat-x 0 0 / 240px 48px, linear-gradient(#000, #000) no-repeat 0 48px / 100% 100%;
  animation: wv 1.5s linear infinite; will-change: transform; }
.ghost-un { position: absolute; top: 0; bottom: 0; left: 0; right: 240px; animation: wv-un 1.5s linear infinite; will-change: transform; }
.ghost-b { position: absolute; top: 0; bottom: 0; left: 0; right: -240px;
  -webkit-mask: var(--wave-down) repeat-x 0 100% / 240px 48px, linear-gradient(#000, #000) no-repeat 0 0 / 100% calc(100% - 48px);
          mask: var(--wave-down) repeat-x 0 100% / 240px 48px, linear-gradient(#000, #000) no-repeat 0 0 / 100% calc(100% - 48px);
  animation: wv 1.9s linear infinite; will-change: transform; }
.ghost-b > .ghost-un { animation-duration: 1.9s; }
.ghost-view { position: absolute; top: 47px; bottom: 47px; left: 0; right: 0; will-change: transform; }
@keyframes wv-un { from { transform: translate3d(0, 0, 0); } to { transform: translate3d(240px, 0, 0); } }

/* The opening: the paper's copy of the seal, in the role's colour, exactly
   where (and as) the stamped one is. */
.splash-pour .ghost-view { transform: translate3d(0, calc(-100% - 60px), 0);
  animation: pour-back 2.4s .25s cubic-bezier(.22,.7,.2,1) forwards; }
@keyframes pour-back { to { transform: translate3d(0, -64%, 0); } }
.splash-seal.on-paper { color: var(--seal); border-color: var(--seal); }
.splash-seal.on-paper::after { border-color: var(--seal); }

/* The cover: the seal is white on the ink, the role's colour on the paper. */
.cover-l .ghost-view { display: grid; place-items: center; }
.cover-ink .cover-seal { color: var(--on-seal); border-color: var(--on-seal); }

/* ------------------------------ Cloudflare panel ------------------------------
   cloudflare.js: where it stands, a four-step guide with drawings of
   Cloudflare's dashboard (their labels, this page's colours), and the box the
   token is pasted into. In Settings for a Developer and on the admin's user page. */
.cf { display: flex; flex-direction: column; gap: 14px; }
.cf-devonly { margin: 0; }
.cf-status { border: 1px solid var(--rule); border-radius: var(--radius-sm); padding: 12px 14px; background: var(--tint); }
.cf-status.on { border-color: color-mix(in srgb, var(--seal) 45%, var(--rule)); background: var(--seal-wash); }
.cf-head { display: flex; align-items: center; gap: 8px; }
.cf-light { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.cf-status.on .cf-light { background: var(--seal); box-shadow: 0 0 0 3px color-mix(in srgb, var(--seal) 22%, transparent); }
.cf-status p { margin: 6px 0 0; }
.cf-facts { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: .94em; }
.cf-facts .warn { color: var(--warn); }
.cf-facts .muted { color: var(--muted); }
.cf-chips { display: inline-flex; flex-wrap: wrap; gap: 4px; vertical-align: middle; }
.cf-chip { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .86em; padding: 1px 8px; border-radius: 999px;
  background: var(--paper); border: 1px solid var(--rule); }
.cf-remove { margin-top: 10px; }
.cf-guide { border: 1px solid var(--rule); border-radius: var(--radius-sm); padding: 0; }
.cf-guide > summary { cursor: pointer; padding: 11px 14px; font-weight: 600; list-style-position: inside; }
.cf-guide[open] > summary { border-bottom: 1px solid var(--rule); }
.cf-steps { list-style: none; margin: 0; padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 18px; }
.cf-step { display: grid; grid-template-columns: minmax(0, 300px) minmax(0, 1fr); gap: 14px; align-items: start; }
.cf-step h5 { margin: 2px 0 4px; font-size: 1em; }
.cf-step p { margin: 0 0 8px; color: var(--ink-soft); font-size: .95em; line-height: 1.75; }
.cf-pic { margin: 0; }
.cf-open { display: inline-block; text-decoration: none; }
.cf-perms { margin-top: 10px; font-size: .92em; }
.cf-perms > summary { cursor: pointer; color: var(--ink-soft); }
.cf-ptable { border-collapse: collapse; margin: 8px 0; font-size: .9em; }
.cf-ptable td { padding: 2px 10px 2px 0; border-bottom: 1px solid var(--rule); white-space: nowrap; }
.cf-form { display: flex; flex-direction: column; gap: 8px; }
.cf-label { font-weight: 600; font-size: .95em; }
.cf-row { display: flex; gap: 8px; }
.cf-row input { flex: 1; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.cf-row .btn { flex: none; }
.cf-pick { margin: 0; font-size: .94em; }
.cf-form .acct-msg { margin: 0; }
@media (max-width: 640px) {
  .cf-step { grid-template-columns: minmax(0, 1fr); }
  .cf-pic { max-width: 360px; order: 2; }   /* on a phone: what to do first, then the picture of it */
}
/* The drawings: shapes in the page's colours; Cloudflare's own words in a plain sans. */
.cf-fig { display: block; width: 100%; height: auto; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
/* The page gives every svg an outline in the text colour (its icons); a drawing has none, and text never. */
.cf-fig { stroke: none; fill: none; }
.cf-fig text { stroke: none; }
.cf-fig .f-win { fill: var(--paper); stroke: var(--rule); stroke-width: 1.2; }
.cf-fig .f-bar { fill: var(--tint); }
.cf-fig .f-dot { fill: var(--rule); stroke: none; }
.cf-fig .f-url { fill: var(--paper); stroke: var(--rule); stroke-width: .8; }
.cf-fig .f-urlt { fill: var(--muted); font-size: 8.5px; }
.cf-fig .f-h { fill: var(--ink); font-size: 12px; font-weight: 700; }
.cf-fig .f-t, .cf-fig .f-s { fill: var(--ink); font-size: 9.5px; }
.cf-fig .f-b { font-weight: 700; }
.cf-fig .f-m { fill: var(--muted); }
.cf-fig .f-box { fill: var(--paper); stroke: var(--rule); stroke-width: 1; }
.cf-fig .f-row { fill: var(--tint); stroke: none; }
.cf-fig .f-btn { fill: var(--ink); stroke: none; }
.cf-fig .f-btnt { fill: var(--paper); font-size: 9.5px; font-weight: 700; }
.cf-fig .f-ring { fill: none; stroke: var(--seal); stroke-width: 2; stroke-dasharray: 4 3; }
.cf-fig .f-num { fill: var(--seal); stroke: none; }
.cf-fig .f-numt { fill: var(--on-seal); font-size: 10px; font-weight: 700; }
.cf-fig .f-tag { fill: var(--seal-wash); stroke: var(--seal); stroke-width: 1; }
.cf-fig .f-tagt { fill: var(--seal); font-size: 9.5px; font-weight: 700; text-anchor: middle; }
.cf-fig .f-arrow { fill: none; stroke: var(--seal); stroke-width: 2; }
.cf-fig .f-arrowhead { fill: var(--seal); stroke: none; }
.cf-fig .f-app { fill: var(--seal-wash); stroke: var(--seal); stroke-width: 1.2; }
.cf-fig .f-appbtn { fill: var(--seal); stroke: none; }
.cf-fig .f-appbtnt { fill: var(--on-seal); font-size: 9.5px; font-weight: 700; font-family: inherit; }
