/* SMAU FILE
 * Path: css/smau-studio2-contenteditor.css
 * Owns: Creator Studio 2.0 — the UNIVERSAL CONTENT EDITOR's visuals ONLY: the
 *       World "contentedit" screen (js/creator/creator.contentEditor.js) — the
 *       focused form (blueprint 05: result line, labelled fields, toggles,
 *       impact note, save/cancel footer), the read-only field row with its
 *       reason, the message-thread list with its per-message tools, and the
 *       Edit Message bottom sheet (blueprint 06). Generic Studio 2.0
 *       primitives (.s2-screen, .s2-head, .s2-card, .s2-btn, .s2-input,
 *       .s2-field, .s2-label…) are owned by css/smau-studio2.css; every rule
 *       here is scoped to a ce2- prefixed class so the files never fight over
 *       a name. Class selectors only — this screen mints its own DOM, so there
 *       is no id in index.html to anchor to (and tools/dead-css-test.mjs is
 *       right to insist on that).
 * Depends: css/smau-studio2.css tokens on #studio-root — --s2-accent,
 *          --s2-accent-soft, --s2-ok, --s2-warn, --s2-danger, --s2-ink,
 *          --s2-muted, --s2-card, --s2-card-border, --s2-radius. Every one has
 *          a fallback here so this file never renders blank if a token moves.
 */

#studio-root {
  --ce2-accent: var(--s2-accent, #8b7cf8);
  --ce2-accent-soft: var(--s2-accent-soft, rgba(139, 124, 248, 0.14));
  --ce2-ok: var(--s2-ok, #3ecf8e);
  --ce2-warn: var(--s2-warn, #ffb454);
  --ce2-danger: var(--s2-danger, #ff5c5c);
  --ce2-ink: var(--s2-ink, rgba(238, 240, 248, 0.94));
  --ce2-muted: var(--s2-muted, rgba(238, 240, 248, 0.55));
  --ce2-card: var(--s2-card, rgba(255, 255, 255, 0.04));
  --ce2-card-border: var(--s2-card-border, rgba(255, 255, 255, 0.08));
  --ce2-radius: var(--s2-radius, 16px);
  --ce2-sheet-bg: #14141c;
}

@media (prefers-color-scheme: light) {
  #studio-root {
    --ce2-ink: var(--s2-ink, rgba(20, 20, 30, 0.92));
    --ce2-muted: var(--s2-muted, rgba(20, 20, 30, 0.55));
    --ce2-card: var(--s2-card, rgba(20, 20, 30, 0.035));
    --ce2-card-border: var(--s2-card-border, rgba(20, 20, 30, 0.12));
    --ce2-sheet-bg: #f4f4f8;
  }
}

/* The explicit theme toggle wins over the OS media query in both directions —
   :root[data-theme] #studio-root out-specifies the plain #studio-root above
   whatever the source order is. */
:root[data-theme="light"] #studio-root {
  --ce2-ink: var(--s2-ink, rgba(20, 20, 30, 0.92));
  --ce2-muted: var(--s2-muted, rgba(20, 20, 30, 0.55));
  --ce2-card: var(--s2-card, rgba(20, 20, 30, 0.035));
  --ce2-card-border: var(--s2-card-border, rgba(20, 20, 30, 0.12));
  --ce2-sheet-bg: #f4f4f8;
}

:root[data-theme="dark"] #studio-root {
  --ce2-ink: var(--s2-ink, rgba(238, 240, 248, 0.94));
  --ce2-muted: var(--s2-muted, rgba(238, 240, 248, 0.55));
  --ce2-card: var(--s2-card, rgba(255, 255, 255, 0.04));
  --ce2-card-border: var(--s2-card-border, rgba(255, 255, 255, 0.08));
  --ce2-sheet-bg: #14141c;
}

/* ── Screen chrome ───────────────────────────────────────────────── */

.ce2-screen { gap: 12px; }
.ce2-sub { margin-bottom: 2px; }

.ce2-head { gap: 8px; }

/* The dirty pill. It says one of two true things and never a third. */
.ce2-dirty {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 700;
  padding: 5px 11px;
  border-radius: 999px;
  white-space: nowrap;
  color: var(--ce2-ok);
  background: rgba(62, 207, 142, 0.12);
}
.ce2-dirty[data-state="dirty"] {
  color: var(--ce2-warn);
  background: rgba(255, 180, 84, 0.14);
}

.ce2-impact {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ce2-accent);
  background: var(--ce2-accent-soft);
  border-radius: 12px;
  padding: 9px 12px;
}

/* ── "Current result" (blueprint 05) ─────────────────────────────── */

.ce2-result {
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-color: rgba(139, 124, 248, 0.32);
}
.ce2-result-top {
  display: flex;
  align-items: center;
  gap: 10px;
}
.ce2-result-label {
  flex: 1 1 auto;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ce2-muted);
}
.ce2-result-value {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.35;
  color: var(--ce2-ink);
  overflow-wrap: anywhere;
}
.ce2-valid[data-state="valid"] { color: var(--ce2-ok); background: rgba(62, 207, 142, 0.13); }
.ce2-valid[data-state="invalid"] { color: var(--ce2-danger); background: rgba(255, 92, 92, 0.13); }

/* ── The form ────────────────────────────────────────────────────── */

.ce2-form {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.ce2-field[data-kind="toggle"] {
  flex-direction: row;
  align-items: center;
  gap: 12px;
}
.ce2-field[data-kind="toggle"] .s2-label {
  flex: 1 1 auto;
  font-size: 13.5px;
  color: var(--ce2-ink);
}
.ce2-field[data-kind="toggle"] .s2-hint,
.ce2-field[data-kind="toggle"] .ce2-err { flex: 1 1 100%; }

.ce2-toggle {
  flex: 0 0 auto;
  width: 50px;
  height: 30px;
  border-radius: 999px;
  padding: 3px;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid var(--ce2-card-border);
  transition: background 0.15s ease;
}
.ce2-toggle[data-state="on"] {
  background: var(--ce2-accent);
  border-color: transparent;
  justify-content: flex-end;
}
.ce2-toggle:focus-visible { outline: 2px solid var(--ce2-accent); outline-offset: 2px; }
.ce2-toggle-knob {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

.ce2-err {
  font-size: 12px;
  font-weight: 600;
  color: var(--ce2-danger);
}
.ce2-err[hidden] { display: none; }

/* ── Read-only field: the value, and WHY it can't be touched ─────── */

.ce2-ro {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px dashed var(--ce2-card-border);
}
.ce2-ro:last-child { margin-bottom: 0; }
.ce2-ro-head { display: flex; align-items: center; gap: 8px; }
.ce2-ro-head .s2-label { flex: 1 1 auto; }
.ce2-ro-lock {
  flex: 0 0 auto;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ce2-muted);
}
.ce2-ro-value {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ce2-ink);
  overflow-wrap: anywhere;
}
.ce2-ro-why {
  font-size: 12px;
  line-height: 1.4;
  color: var(--ce2-muted);
}

/* ── Footer actions ──────────────────────────────────────────────── */

.ce2-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}
.ce2-cancel { flex: 0 0 auto; }
.ce2-save { flex: 1 1 auto; min-height: 52px; font-size: 15px; }
.ce2-delete { width: 100%; }

.ce2-none {
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--ce2-muted);
}

/* ── Message thread ──────────────────────────────────────────────── */

.ce2-msgs-label { margin-top: 4px; }

.ce2-msgs {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ce2-msg {
  display: flex;
  align-items: stretch;
  gap: 6px;
  border-radius: var(--ce2-radius);
  border: 1px solid var(--ce2-card-border);
  background: var(--ce2-card);
  padding: 8px 8px 8px 10px;
  border-left: 3px solid rgba(255, 255, 255, 0.16);
}
.ce2-msg[data-sender="me"] { border-left-color: var(--ce2-accent); }

.ce2-msg-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  text-align: left;
  color: var(--ce2-ink);
}
.ce2-msg-who {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ce2-accent);
}
.ce2-msg[data-sender="them"] .ce2-msg-who { color: var(--ce2-muted); }
.ce2-msg-text {
  font-size: 13.5px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.ce2-msg-ts { font-size: 11.5px; color: var(--ce2-muted); }

.ce2-msg-tools {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(2, 32px);
  gap: 2px;
  align-content: center;
}
.ce2-msg-tool {
  flex: none;
  width: 32px;
  height: 32px;
  font-size: 13px;
}
.ce2-msg-tool[disabled] { opacity: 0.3; }
.ce2-msg-tool--del:hover { color: var(--ce2-danger); background: rgba(255, 92, 92, 0.1); }

.ce2-msg-add { width: 100%; }

/* ── Edit Message bottom sheet (blueprint 06) ────────────────────── */

.ce2-sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
}

.ce2-sheet {
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 16px calc(18px + env(safe-area-inset-bottom, 0px));
  background: var(--ce2-sheet-bg, #14141c);
  color: var(--ce2-ink);
  border-radius: 22px 22px 0 0;
  border: 1px solid var(--ce2-card-border);
  border-bottom: none;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.5);
}

.ce2-sheet-grip {
  width: 44px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.28);
  margin: 2px auto 4px;
}

.ce2-sheet-head {
  display: flex;
  align-items: center;
  gap: 10px;
}
.ce2-sheet-title {
  flex: 1 1 auto;
  font-size: 18px;
  font-weight: 800;
}

.ce2-sheet-body { display: flex; flex-direction: column; }

.ce2-sheet-actions {
  display: flex;
  gap: 10px;
}
.ce2-sheet-actions .s2-btn { flex: 1 1 0; }

/* ── Delete confirm: the list of things that point at it ─────────── */

.ce2-confirm .ce2-ref-list {
  margin: 8px 0 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 12.5px;
  line-height: 1.4;
  text-align: left;
}

/* ── Wider screens: the form gets a comfortable column, the message
      tools stop competing with the text for width. ───────────────── */

@media (min-width: 720px) {
  .ce2-msg-tools { grid-template-columns: repeat(4, 32px); }
}

/* ── The `days` control: seven weekday buttons, Sunday first ──────
      Why buttons and not a multi-select: an alarm that repeats on
      Tue/Thu is read at a glance as two lit letters, and a select
      that needs a modifier key to multi-pick is a control that only
      works with a mouse. */

.ce2-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.ce2-day {
  min-height: 38px;
  border-radius: 10px;
  border: 1px solid var(--ce2-card-border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--ce2-muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease;
}
.ce2-day[data-state="on"] {
  background: var(--ce2-accent);
  border-color: transparent;
  color: #fff;
}
.ce2-day:focus-visible { outline: 2px solid var(--ce2-accent); outline-offset: 2px; }

/* ── "＋ New": the button, and the picker sheet it opens ──────────
      The sheet reuses .ce2-sheet / .ce2-sheet-backdrop wholesale;
      only the list of makeable types and the honest "not from here"
      footer are new. */

.ce2-new { width: 100%; }

.ce2-newsheet { max-height: min(78vh, 640px); overflow-y: auto; }
.ce2-new-sub { margin: -2px 0 2px; }

.ce2-new-list { gap: 6px; }

.ce2-new-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid var(--ce2-card-border);
  background: var(--ce2-card);
  color: var(--ce2-ink);
  cursor: pointer;
}
.ce2-new-row:hover { background: var(--ce2-accent-soft); border-color: var(--ce2-accent); }
.ce2-new-row:focus-visible { outline: 2px solid var(--ce2-accent); outline-offset: 2px; }
.ce2-new-label { flex: 1 1 auto; font-size: 14px; font-weight: 700; }
.ce2-new-app {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ce2-muted);
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
}

.ce2-new-notes {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 4px;
  border-top: 1px solid var(--ce2-card-border);
}
.ce2-new-note { display: flex; flex-direction: column; gap: 2px; }
.ce2-new-note-label { font-size: 12.5px; font-weight: 700; color: var(--ce2-ink); }
.ce2-new-note-why { font-size: 11.5px; line-height: 1.45; color: var(--ce2-muted); }

/* A record that has never been saved says so in the dirty pill. */
.ce2-dirty[data-state="new"] {
  background: var(--ce2-accent-soft);
  color: var(--ce2-accent);
}

@media (min-width: 720px) {
  .ce2-new { width: auto; }
}
