/* Screen layouts: sign in, the conversation workspace, the rule editor. Mobile first. */

/* ---- Sign in ---- */
.signin {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--s-5); padding: var(--s-6) var(--gutter); background: var(--brand-wash);
}
.signin-brand { display: flex; align-items: center; gap: var(--s-3); }
.signin-brand h1 { font-size: var(--fs-xl); }
.signin-card { width: 100%; max-width: 420px; padding: var(--s-5); }
.signin-card h2 { font-size: var(--fs-lg); }
.signin-foot { max-width: 420px; text-align: center; }
.code-input { font-size: var(--fs-xl); letter-spacing: 0.3em; font-variant-numeric: tabular-nums; text-align: center; }

.back-link { align-self: flex-start; padding-left: var(--s-2); margin-left: calc(-1 * var(--s-2)); }
.small-heading { font-size: var(--fs-md); }

/* ---- Conversation ---- */
.conv-tabs { display: flex; }
.conv-layout { display: block; min-width: 0; }
.conv-layout[data-pane="messages"] .conv-person { display: none; }
.conv-layout[data-pane="person"] .conv-messages { display: none; }
.conv-pane { min-width: 0; display: flex; flex-direction: column; gap: var(--s-3); }
@media (min-width: 1000px) {
  .conv-tabs { display: none; }
  .conv-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: var(--s-4); align-items: start; }
  .conv-layout[data-pane] .conv-person, .conv-layout[data-pane] .conv-messages { display: flex; }
  .conv-person { position: sticky; top: calc(var(--header-h) + var(--s-4)); max-height: calc(100vh - var(--header-h) - 32px); overflow-y: auto; }
}

.timeline {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-3);
  padding: var(--s-3); display: flex; flex-direction: column; gap: var(--s-2);
  max-height: min(64vh, 720px); overflow-y: auto; min-width: 0; overscroll-behavior: contain;
}
.timeline-empty { text-align: center; padding: var(--s-5); }
.day-sep { align-self: center; font-size: var(--fs-xs); color: var(--ink-3); background: var(--surface-3); border-radius: var(--r-pill); padding: 2px 10px; margin: var(--s-2) 0; }
.msg { display: flex; min-width: 0; }
.msg-in { justify-content: flex-start; }
.msg-out { justify-content: flex-end; }
.bubble {
  max-width: min(85%, 560px); min-width: 0; padding: var(--s-2) var(--s-3); border-radius: var(--r-3);
  border: 1px solid var(--line); box-shadow: var(--shadow-1); display: flex; flex-direction: column; gap: 4px;
}
.msg-in .bubble { background: var(--bubble-in); border-top-left-radius: 4px; }
.msg-out .bubble { background: var(--bubble-out); border-top-right-radius: 4px; }
.msg-problem .bubble { border-color: var(--danger); border-style: dashed; }
.msg-unknown .bubble { border-color: var(--warn); border-width: 2px; }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
.msg-kind { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-xs); font-weight: var(--fw-bold); color: var(--ink-2); }
.msg-kind svg { width: 14px; height: 14px; }
.msg-meta { display: flex; flex-wrap: wrap; gap: 4px var(--s-2); align-items: center; font-size: var(--fs-xs); color: var(--ink-3); }
.msg-note { font-size: var(--fs-xs); color: var(--warn); font-weight: var(--fw-medium); }

.composer { display: flex; flex-direction: column; gap: var(--s-3); min-width: 0; }
.reply-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-3); padding: var(--s-3); }
.reply-box.is-closed { background: var(--surface-3); }
.reply-box.is-closed .textarea { min-height: var(--tap); resize: none; }
.reply-box.is-closed [data-testid="window-reason"] { color: var(--warn); font-weight: var(--fw-medium); }
.template-box { min-width: 0; }
.template-preview {
  white-space: pre-wrap; overflow-wrap: anywhere; background: var(--bubble-out); border: 1px solid var(--line);
  border-radius: var(--r-2); padding: var(--s-3); font-size: var(--fs-sm);
}
.panel .card h2 { font-size: var(--fs-md); }
.link-row { padding: var(--s-2) 0; border-top: 1px solid var(--line); }
.link-row:first-child { border-top: 0; padding-top: 0; }

/* ---- Deliveries ---- */
.filters .field { flex: 1 1 140px; }
.item.delivery.is-unknown { background: var(--warn-wash); }
.item.delivery.is-unknown .item-preview { color: var(--ink); }

/* ---- Rules ---- */
.rule-layout { display: grid; gap: var(--s-4); grid-template-columns: minmax(0, 1fr); align-items: start; }
@media (min-width: 1100px) {
  .rule-layout { grid-template-columns: minmax(0, 1fr) 360px; }
  .rule-side { position: sticky; top: calc(var(--header-h) + var(--s-4)); }
}
.version-pick { max-width: 520px; }
.describe { font-size: var(--fs-md); line-height: var(--lh); overflow-wrap: anywhere; }
.problems li { color: var(--danger); display: flex; gap: 6px; align-items: flex-start; }
.problems svg { width: 16px; height: 16px; margin-top: 3px; }
.cond-group { border-left: 4px solid var(--ctx); background: var(--surface-2); border-radius: var(--r-2); padding: var(--s-3); display: flex; flex-direction: column; gap: var(--s-3); min-width: 0; }
.cond-group.depth-1 { border-left-color: var(--line-strong); background: var(--surface); }
.cond-group.depth-2 { border-left-color: var(--ctx); background: var(--surface-2); }
.group-mode { max-width: 280px; font-weight: var(--fw-medium); }
.cond { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-2); padding: var(--s-3); display: flex; flex-direction: column; gap: var(--s-2); min-width: 0; }
.cond-fields { display: grid; gap: var(--s-2); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 640px) { .cond-fields { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr); } }
.param-row { display: grid; gap: var(--s-2); grid-template-columns: auto minmax(0, 1fr); align-items: center; }
.param-row .input { grid-column: 1 / -1; }
@media (min-width: 640px) { .param-row { grid-template-columns: auto 220px minmax(0, 1fr) auto; } .param-row .input { grid-column: auto; } }
.param-n { font-family: var(--mono); font-size: var(--fs-sm); color: var(--ink-2); }
.save-bar {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-3);
  padding: var(--s-3) var(--s-4); display: flex; flex-direction: column; gap: var(--s-2);
}
.save-bar.is-dirty {
  position: sticky; bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom)); z-index: 5; box-shadow: var(--shadow-2);
  border-color: var(--ctx);
}
.save-bar:empty { display: none; }
@media (min-width: 900px) { .save-bar.is-dirty { bottom: var(--s-3); } }
/* On a phone the plain-language summary and Simulate / Publish come first, above the form. */
@media (max-width: 1099px) { .rule-side { order: -1; } }
.sim-run { margin-top: var(--s-2); }
.sim-run h3 { margin-top: var(--s-3); }
.rule-side > .card { display: flex; flex-direction: column; gap: var(--s-2); }
/* The side panel is narrow at every width: two stats a row, whatever the viewport. */
.rule-side .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.rule-side .stat-value { font-size: var(--fs-lg); }

.evidence { border-top: 1px solid var(--line); padding-top: var(--s-2); }
.evidence:first-child { border-top: 0; padding-top: 0; }
