/*
 Theme tokens. Dark is the default look (:root, unconditional) — matches
 this app's original single-theme design, zero regression risk for anyone
 who never touches the toggle. Three ways a viewer ends up in light mode,
 in increasing priority: (1) OS-level prefers-color-scheme: light, only
 when no manual choice has ever been stored (the :not([data-theme]) guard);
 (2) [data-theme="light"], set by studio/public/theme.js when the sidebar
 toggle is used, and persisted to localStorage; (3) the [data-theme="dark"]
 block exists only so a manual "back to dark" choice unambiguously wins over
 a light-preferring OS — it repeats :root's own values on purpose.
 Brand accent (azure/sand/brown) and semantic status colors (success/
 warning/danger) are official tokens from config/colors.json and
 docs/Brand-Guide.md's Color System section, and stay identical across
 both themes; only surface, border, and text tokens change. See
 docs/Brand-Guide.md's Color System section for the palette rationale
 ("Use Navy 900 text on white backgrounds").
*/
:root {
  --navy-950: #0a141f;
  --navy-900: #0e1d2f;
  --navy-800: #1e2a3e;
  --navy-700: #2c3b52;
  --navy-600: #3a4d68;
  --azure: #4da3e3;
  --azure-hover: #2e8fd4;
  --azure-dim: #79bcea;
  --sand: #d9a96a;
  --brown: #8b5e34;
  --ink: #e6eaf0;
  --ink-dim: #9fb2c9;
  --white: #ffffff;
  --success: #2e9d67;
  --warning: #f2b84b;
  --danger: #d9534f;
  --display: "Poppins", "Inter", "Segoe UI", Arial, sans-serif;
  --body: "DM Sans", "Segoe UI", Arial, sans-serif;
  --sidebar-w: 264px;
  --modal-sm: 560px;
  --modal-md: 900px;
  --modal-lg: 1100px;
  --shadow-elevated: 0 24px 48px -16px rgba(0, 0, 0, 0.55);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --navy-950: #eef2f6;
    --navy-900: #f4f7fa;
    --navy-800: #ffffff;
    --navy-700: #d7dee6;
    --navy-600: #c3ccd6;
    --ink: #0e1d2f;
    --ink-dim: #5a6b82;
    --shadow-elevated: 0 24px 48px -16px rgba(14, 29, 47, 0.16);
  }
}

:root[data-theme="light"] {
  --navy-950: #eef2f6;
  --navy-900: #f4f7fa;
  --navy-800: #ffffff;
  --navy-700: #d7dee6;
  --navy-600: #c3ccd6;
  --ink: #0e1d2f;
  --ink-dim: #5a6b82;
  --shadow-elevated: 0 24px 48px -16px rgba(14, 29, 47, 0.16);
}

:root[data-theme="dark"] {
  --navy-950: #0a141f;
  --navy-900: #0e1d2f;
  --navy-800: #1e2a3e;
  --navy-700: #2c3b52;
  --navy-600: #3a4d68;
  --ink: #e6eaf0;
  --ink-dim: #9fb2c9;
  --shadow-elevated: 0 24px 48px -16px rgba(0, 0, 0, 0.55);
}

/*
 The sidebar and top header are persistent navigation chrome, deliberately
 kept dark navy in BOTH themes (a common pattern — only the content area
 goes light). Redeclaring the theme-sensitive custom properties here, scoped
 to these two containers, means every existing rule inside them that
 already reads var(--navy-950)/var(--ink)/var(--white)/etc. keeps working
 unchanged and stays legible — without hunting down and rewriting every
 individual white-on-navy text/icon rule across the file.
*/
.sidebar,
.app-header {
  --navy-950: #0a141f;
  --navy-900: #0e1d2f;
  --navy-800: #1e2a3e;
  --navy-700: #2c3b52;
  --navy-600: #3a4d68;
  --ink: #e6eaf0;
  --ink-dim: #9fb2c9;
}

* { box-sizing: border-box; }

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

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--navy-900);
  color: var(--ink);
  font-family: var(--body);
}

body {
  background-image:
    radial-gradient(ellipse 1200px 700px at 12% -10%, rgba(77, 163, 227, 0.1), transparent 60%),
    radial-gradient(ellipse 900px 600px at 100% 0%, rgba(217, 169, 106, 0.05), transparent 55%);
  position: relative;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  opacity: 0.03;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='120'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

/* ── App shell ────────────────────────────────────────────────────── */

.app-shell {
  display: flex;
  align-items: stretch;
  min-height: 100vh;
}

.main-scroll {
  flex: 1;
  min-width: 0;
  padding-bottom: 40px;
}

/* ── Persistent app header (brand name + switcher, every view) ──────── */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 40px;
  border-bottom: 1px solid var(--navy-700);
  background: var(--navy-950);
  position: sticky;
  top: 0;
  z-index: 20;
}

.app-header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.app-header-brand-logo {
  width: 28px;
  height: 28px;
  object-fit: contain;
  border-radius: 4px;
  flex-shrink: 0;
}

.app-header-brand-logo[hidden] { display: none; }

.app-header-brand-label {
  font-family: var(--body);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-dim);
  flex-shrink: 0;
}

.app-header-brand-name {
  font-family: var(--display);
  font-weight: 700;
  font-size: 16px;
  color: var(--white);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-header-brand-select {
  background: var(--navy-900);
  border: 1px solid var(--navy-700);
  border-radius: 6px;
  color: var(--ink);
  font-family: var(--body);
  font-size: 13px;
  padding: 8px 12px;
  max-width: 240px;
}

.app-header-brand-select:disabled { opacity: 0.5; cursor: not-allowed; }

.app-header-product-crumb {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.app-header-product-arrow {
  color: var(--ink-dim);
  font-size: 16px;
}

.app-header-product-label {
  font-family: var(--body);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-dim);
  flex-shrink: 0;
}

.app-header-product-name {
  font-family: var(--display);
  font-weight: 700;
  font-size: 16px;
  color: var(--azure-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 720px) {
  .app-header { padding: 12px 20px; flex-wrap: wrap; }
  .app-header-brand-select { max-width: 100%; }
}

/* ── Sidebar ──────────────────────────────────────────────────────── */

.sidebar {
  flex-shrink: 0;
  align-self: flex-start;
  width: var(--sidebar-w);
  height: 100vh;
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  background: var(--navy-950);
  border-right: 1px solid var(--navy-700);
}

.sidebar::after {
  content: "";
  position: absolute;
  top: 0;
  right: -1px;
  width: 2px;
  height: 100%;
  background: var(--azure);
  opacity: 0.45;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 26px 24px 22px;
  border-bottom: 1px solid var(--navy-700);
}

.brand-mark {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--sand);
  background: rgba(217, 169, 106, 0.1);
  border: 1px solid rgba(217, 169, 106, 0.3);
  border-radius: 10px;
}

.brand-mark svg { width: 21px; height: 21px; }

.brand-word {
  font-family: var(--display);
  font-weight: 800;
  font-size: 17px;
  color: var(--white);
  margin: 0;
  line-height: 1.15;
}

.brand-sub {
  font-family: var(--body);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--azure);
  margin: 2px 0 0;
}

.side-nav {
  flex: 1;
  overflow-y: auto;
  padding: 18px 14px 12px;
  display: flex;
  flex-direction: column;
}

.side-nav-label {
  font-family: var(--body);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin: 18px 10px 6px;
}

.side-nav-label:first-child { margin-top: 4px; }

.sidebar-foot {
  padding: 18px 24px 24px;
  border-top: 1px solid var(--navy-700);
}

.sidebar-tagline {
  font-family: var(--body);
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--ink-dim);
  margin: 0 0 16px;
}

.sidebar-count span {
  display: block;
  font-family: var(--display);
  font-size: 26px;
  font-weight: 800;
  color: var(--sand);
  line-height: 1;
}

.sidebar-count label {
  display: block;
  margin-top: 4px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

/* Deliberately a sibling of .sidebar-foot, not inside it — .sidebar-foot
   is hidden entirely below 880px (its content, the tagline/persona-count,
   is decorative), but logging out is a functional necessity that must stay
   reachable at every width. */
.sidebar-logout {
  width: calc(100% - 28px);
  margin: 0 14px 16px;
  color: var(--ink-dim);
  border-color: var(--navy-700);
}
.sidebar-logout:hover { color: var(--ink); border-color: var(--navy-600); }

.sidebar-theme-toggle {
  width: calc(100% - 28px);
  margin: 0 14px 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--ink-dim);
  border-color: var(--navy-700);
}
.sidebar-theme-toggle:hover { color: var(--ink); border-color: var(--navy-600); }
.sidebar-theme-toggle .theme-icon { width: 16px; height: 16px; flex-shrink: 0; }
/* Shows the icon for the theme a click would switch TO, not the active one
   — e.g. while dark is active, the toggle shows a sun (switch to light).
   Default (no data-theme, OS dark or no OS preference — matches :root's
   own dark-by-default) is "effectively dark", so show sun / hide moon. */
.sidebar-theme-toggle .theme-icon--dark { display: none; }
.sidebar-theme-toggle .theme-icon--light { display: inline; }
/* OS prefers light AND no manual override: flip to "effectively light". */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) .sidebar-theme-toggle .theme-icon--dark { display: inline; }
  :root:not([data-theme]) .sidebar-theme-toggle .theme-icon--light { display: none; }
}
/* Explicit manual choice always wins over OS preference — placed after the
   @media block above so equal-specificity source order resolves correctly. */
:root[data-theme="light"] .sidebar-theme-toggle .theme-icon--dark { display: inline; }
:root[data-theme="light"] .sidebar-theme-toggle .theme-icon--light { display: none; }
:root[data-theme="dark"] .sidebar-theme-toggle .theme-icon--dark { display: none; }
:root[data-theme="dark"] .sidebar-theme-toggle .theme-icon--light { display: inline; }

/* Small unread-style count on a sidebar nav item (currently only Issues) —
   same visual language as .issues-fab-badge, sized down for inline use. */
.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  margin-left: auto;
  border-radius: 999px;
  background: var(--danger);
  color: var(--white);
  font: 700 11px var(--body);
}
.nav-badge[hidden] { display: none; }

/* ── Masthead ─────────────────────────────────────────────────────── */

.eyebrow {
  font-family: var(--body);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--azure);
  margin: 0 0 18px;
}

h1 {
  font-family: var(--display);
  font-weight: 800;
  font-size: 56px;
  line-height: 1;
  margin: 0 0 18px;
  letter-spacing: -0.01em;
}

h1 .w { color: var(--white); }
h1 .a { color: var(--azure); }

.tagline {
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink-dim);
  max-width: 52ch;
  margin: 0;
}

/* ── Filters ──────────────────────────────────────────────────────── */

.filters {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 28px 40px;
  flex-wrap: wrap;
}

.generations-count {
  font-family: var(--body);
  font-size: 13px;
  color: var(--ink-dim);
  margin: 0;
}

.filter-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.pill {
  font-family: var(--body);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: transparent;
  color: var(--ink-dim);
  border: 1px solid var(--navy-700);
  border-radius: 999px;
  padding: 12px 18px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.pill:hover {
  border-color: var(--azure);
  color: var(--ink);
}

.pill.active {
  background: var(--azure);
  border-color: var(--azure);
  color: var(--navy-950);
  font-weight: 700;
}

.search-wrap {
  position: relative;
  min-width: 280px;
}

.search-glyph {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-dim);
  font-size: 13px;
}

#search {
  width: 100%;
  background: var(--navy-800);
  border: 1px solid var(--navy-700);
  border-radius: 999px;
  color: var(--ink);
  font-family: var(--body);
  font-size: 13px;
  padding: 10px 16px 10px 34px;
  transition: border-color 0.15s ease;
}

#search:focus { border-color: var(--azure); outline: none; }
#search:focus-visible { outline: 2px solid var(--azure); outline-offset: 2px; }
#search::placeholder { color: var(--ink-dim); }

/* ── Grid ─────────────────────────────────────────────────────────── */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
  padding: 12px 40px 80px;
}

.empty {
  text-align: center;
  color: var(--ink-dim);
  font-family: var(--body);
  font-size: 13px;
  padding: 60px 0;
}

.load-more-wrap {
  display: flex;
  justify-content: center;
  padding: 0 40px 60px;
}

.card {
  background: var(--navy-800);
  border: 1px solid var(--navy-700);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  position: relative;
  opacity: 0;
  animation: reveal 0.5s ease forwards;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
  transform: translateY(-3px);
  border-color: var(--azure);
  box-shadow: 0 12px 32px -12px rgba(0, 0, 0, 0.6);
}

.card-static {
  cursor: default;
}

.card-static:hover {
  transform: none;
  border-color: var(--navy-700);
  box-shadow: none;
}

@keyframes reveal {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.card-image-wrap {
  aspect-ratio: 1 / 1;
  background: var(--navy-900);
  position: relative;
  overflow: hidden;
}

.card-image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 10px;
}

.card-index {
  position: absolute;
  top: 8px;
  left: 8px;
  font-family: var(--body);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--azure);
  background: rgba(10, 20, 31, 0.75);
  border: 1px solid var(--navy-700);
  border-radius: 4px;
  padding: 2px 6px;
}

.card-body {
  padding: 12px 14px 14px;
  border-top: 1px solid var(--navy-700);
}

.card-scope {
  font-family: var(--body);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--sand);
  margin: 0 0 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-brief {
  font-family: var(--display);
  font-weight: 500;
  font-size: 14px;
  line-height: 1.35;
  color: var(--ink);
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── Modal ────────────────────────────────────────────────────────── */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 10, 16, 0.82);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 32px;
  animation: fadeIn 0.15s ease;
}

.modal[hidden] {
  display: none;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  background: var(--navy-800);
  border: 1px solid var(--navy-700);
  border-radius: 14px;
  max-width: var(--modal-md);
  width: 100%;
  max-height: 88vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  position: relative;
  box-shadow: var(--shadow-elevated);
}

.confirm-modal-card {
  grid-template-columns: 1fr;
  max-width: 560px;
  overflow-y: auto;
  padding: 32px;
}

.modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(10, 20, 31, 0.7);
  border: 1px solid var(--navy-700);
  color: var(--ink);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
}

.modal-image-wrap {
  background: var(--navy-900);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-image-wrap img {
  max-width: 100%;
  max-height: 70vh;
  object-fit: contain;
}

.modal-details {
  padding: 32px 32px 28px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.modal-index {
  font-family: var(--body);
  font-size: 11px;
  font-weight: 600;
  color: var(--sand);
  letter-spacing: 0.08em;
  margin: 0 0 10px;
}

.modal-details h2 {
  font-family: var(--display);
  font-weight: 700;
  font-size: 22px;
  color: var(--azure);
  margin: 0 0 12px;
  text-transform: none;
}

.modal-brief {
  font-family: var(--display);
  font-weight: 500;
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  margin: 0 0 20px;
}

.modal-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  font-size: 12px;
  margin: 0 0 20px;
}

.modal-meta dt {
  color: var(--ink-dim);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 10px;
  font-weight: 600;
  align-self: center;
}

.modal-meta dd {
  margin: 0;
  color: var(--ink);
  word-break: break-all;
  font-family: var(--body);
}

.modal-meta-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin: 0 0 6px;
}

.result-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 14px;
}

.result-tag {
  font-family: var(--body);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink);
  background: var(--navy-900);
  border: 1px solid var(--navy-700);
  border-radius: 999px;
  padding: 4px 10px;
}

.result-tag[hidden] { display: none; }

.prompt-details {
  margin: 0 0 20px;
}

.prompt-details summary {
  cursor: pointer;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-dim);
  list-style: none;
}

.prompt-details summary::-webkit-details-marker { display: none; }

.prompt-details summary::before {
  content: "▸ ";
}

.prompt-details[open] summary::before {
  content: "▾ ";
}

.prompt-details .modal-brief {
  margin-top: 10px;
  font-family: var(--body);
  font-weight: 400;
  font-size: 13px;
}

#modal-reuse {
  list-style: none;
  padding: 0;
  margin: 0 0 20px;
  font-size: 12px;
  color: var(--ink-dim);
  font-family: var(--body);
}

#modal-reuse li {
  padding: 4px 0;
  border-bottom: 1px dashed var(--navy-700);
}

.delete-btn {
  margin-top: auto;
  align-self: flex-start;
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  font-family: var(--body);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 10px 18px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.delete-btn:hover {
  background: var(--danger);
  color: var(--navy-950);
}

.delete-btn.confirming {
  background: var(--danger);
  color: var(--navy-950);
  font-weight: 700;
}

/* ── Tabs (sidebar nav items) ─────────────────────────────────────── */

.tab {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  font-family: var(--body);
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-align: left;
  background: transparent;
  color: var(--ink-dim);
  border: none;
  border-radius: 9px;
  padding: 12px;
  min-height: 44px;
  margin-bottom: 4px;
  cursor: pointer;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.tab-icon { flex-shrink: 0; width: 18px; height: 18px; opacity: 0.85; }

.tab:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.04);
}

.tab.active {
  color: var(--white);
  background: linear-gradient(90deg, rgba(77, 163, 227, 0.22), rgba(77, 163, 227, 0.05));
  box-shadow: inset 2px 0 0 var(--azure);
}

.tab.active .tab-icon { opacity: 1; color: var(--azure); }

/* ── Create view ──────────────────────────────────────────────────── */

#view-create { padding: 12px 40px 80px; }
#view-new-persona { padding: 12px 40px 80px; }
#view-admin { padding: 12px 40px 80px; }
#view-create-brand { padding: 12px 40px 80px; }
#view-templates { padding: 12px 40px 80px; }

.create-layout {
  display: grid;
  /* minmax(0, ...) — without it, a grid item's default min-width:auto lets
     wide intrinsic content (e.g. a <textarea>) force the whole track wider
     than the container, overflowing it instead of wrapping/shrinking. */
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  gap: 28px;
  align-items: start;
}

.create-layout[hidden] { display: none; }

.create-layout-stacked {
  grid-template-columns: minmax(0, 1fr);
  max-width: 640px;
}

.create-layout-stacked .create-result {
  max-width: 400px;
  margin: 0 auto;
  min-height: unset;
  aspect-ratio: 3 / 4;
}

.create-layout-stacked .result-panel img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#new-campaign-btn {
  margin-top: 12px;
}

.create-form {
  background: var(--navy-800);
  border: 1px solid var(--navy-700);
  border-radius: 12px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Same field-to-field spacing as .create-form, without its card chrome
   (background/border/padding) — for a <form> nested inside a panel that
   already has that chrome (e.g. #admin-user-form inside a .create-form
   panel, #issue-form inside .modal-card). Without this, a <form>'s own
   children stack with zero gap, since .create-form's flex gap only
   reaches its own direct children, not a nested form's children one
   level deeper. */
.field-stack {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-family: var(--body);
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-dim);
  letter-spacing: 0.02em;
  transition: opacity 0.15s ease;
}

.field em {
  font-style: normal;
  font-weight: 400;
  color: var(--ink-dim);
  opacity: 0.7;
}

.field small {
  font-family: var(--body);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: normal;
  color: var(--ink-dim);
  opacity: 0.75;
}

.field select,
.field input[type="text"],
.field input[type="email"],
.field input[type="password"],
.field input[type="number"],
.field input[type="url"],
.field textarea {
  background: var(--navy-900);
  border: 1px solid var(--navy-700);
  border-radius: 6px;
  color: var(--ink);
  font-family: var(--body);
  font-size: 13px;
  font-weight: 400;
  padding: 9px 12px;
  resize: vertical;
  transition: border-color 0.15s ease;
}

.field textarea {
  min-height: 90px;
  max-height: 60vh;
  overflow-y: auto;
  line-height: 1.5;
}

.field select:focus,
.field input[type="text"]:focus,
.field input[type="email"]:focus,
.field input[type="password"]:focus,
.field input[type="number"]:focus,
.field input[type="url"]:focus,
.field textarea:focus {
  border-color: var(--azure);
  outline: none;
}

.field select:focus-visible,
.field input[type="text"]:focus-visible,
.field input[type="email"]:focus-visible,
.field input[type="password"]:focus-visible,
.field input[type="number"]:focus-visible,
.field input[type="url"]:focus-visible,
.field textarea:focus-visible {
  outline: 2px solid var(--azure);
  outline-offset: 2px;
}

.checkbox-field {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  font-weight: 500;
  color: var(--ink);
}

.checkbox-field input {
  width: 16px;
  height: 16px;
  accent-color: var(--azure);
}

.generate-btn {
  background: var(--azure);
  color: var(--navy-950);
  border: none;
  border-radius: 8px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 14px;
  padding: 13px 20px;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.generate-btn:hover { opacity: 0.9; }
.generate-btn:disabled { opacity: 0.5; cursor: wait; }

.generate-action-row {
  display: flex;
  gap: 10px;
}

.generate-action-row .generate-btn {
  flex: 1;
}

.generate-status {
  font-family: var(--body);
  font-size: 12px;
  color: var(--ink-dim);
  margin: -6px 0 0;
  min-height: 16px;
}

.generate-status.error { color: var(--danger); }

.create-result {
  background: var(--navy-800);
  border: 1px solid var(--navy-700);
  border-radius: 12px;
  min-height: 320px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  min-width: 0;
}

.create-result > * {
  /* Same flex-item min-width:auto issue as .create-layout's grid columns —
     without this, create-preview-header's width:100% nowrap row forces its
     ancestor wider than .create-result's actual available space. */
  min-width: 0;
}

.result-empty p {
  font-family: var(--body);
  font-size: 13px;
  color: var(--ink-dim);
  text-align: center;
}

.create-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-bottom: 12px;
  font-family: var(--body);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-dim);
}

.preview-popup-body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.preview-popup-disconnected {
  font-family: var(--body);
  font-size: 15px;
  color: var(--ink-dim);
  text-align: center;
  max-width: 420px;
}

.result-panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.result-panel[hidden] {
  display: none;
}

.result-panel img {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--navy-700);
}

.section-heading {
  font-family: var(--display);
  font-weight: 700;
  font-size: 16px;
  color: var(--ink);
  margin: 40px 0 16px;
}

.section-heading--flush { margin-top: 0; }
.section-heading--header { margin: 32px 0 0; }

.section-header {
  margin-bottom: 24px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--navy-700);
}

/* Positions the .modal-close (position:absolute) inside #campaign-wizard's
   header instead of letting it fall through to body, which pins it to the
   page's top-right corner over the app nav. */
#campaign-wizard .section-header {
  position: relative;
}

.section-header h2 {
  font-family: var(--display);
  font-weight: 700;
  font-size: 20px;
  color: var(--ink);
  margin: 0 0 6px;
}

.section-sub {
  font-family: var(--body);
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-dim);
  margin: 0;
  max-width: 560px;
}

.recent-grid .card-brief { font-size: 12px; font-weight: 400; font-family: var(--body); color: var(--ink-dim); }

/* Campaign posts span many aspect ratios (story/banner/poster); square-cropping them like Archive's portraits letterboxes everything identically. */
.recent-grid .card-image-wrap { aspect-ratio: 4 / 3; }

.edit-recomposite-btn { align-self: stretch; margin-top: 8px; }
.edit-recomposite-btn:disabled { opacity: 0.5; cursor: not-allowed; }

@media (max-width: 900px) {
  .create-layout { grid-template-columns: minmax(0, 1fr); }
}

/* ── Settings / design tokens ─────────────────────────────────────── */

/* #view-archive/#view-generations don't get the section-level padding rule other
   views use (below) — their .filters (28px 40px) and .grid (12px 40px 80px) already
   supply the left/right gutter and bottom padding for everything below the header,
   so padding the section itself would double that horizontal gutter. Instead, pad
   just the header to match. */
#view-archive > .section-header,
#view-generations > .section-header {
  padding-top: 12px;
  padding-left: 40px;
  padding-right: 40px;
  /* padding-bottom stays the 18px from the base .section-header rule above. */
}

#view-settings { padding: 12px 40px 80px; }
#view-catalog { padding: 12px 40px 80px; }
#view-issues { padding: 12px 40px 80px; }
#view-projects { padding: 12px 40px 80px; }
#view-project-detail { padding: 12px 40px 80px; }

/* #pm-projects-grid reuses .grid's layout but its padding would double up with
   #view-projects's own padding above — the parent already provides it. */
#pm-projects-grid { padding: 0; }

.pm-calendar {
  display: grid;
  gap: 4px;
  margin-top: 16px;
}

.settings-context-bar {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 18px;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--navy-700);
}

.settings-context-select-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.settings-context-select-group select {
  background: var(--navy-900);
  border: 1px solid var(--navy-700);
  border-radius: 6px;
  color: var(--ink);
  font-family: var(--body);
  font-size: 13px;
  padding: 8px 12px;
  min-width: 200px;
}

.settings-context-breadcrumb {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-left: auto;
}

.settings-context-label {
  font-family: var(--body);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.settings-context-name {
  font-family: var(--display);
  font-weight: 700;
  font-size: 18px;
  color: var(--ink);
}

.settings-tabs { margin-bottom: 20px; }

.admin-usage-note {
  font-family: var(--body);
  font-size: 12px;
  color: var(--ink-dim);
  margin: 0 0 16px;
}

.admin-usage-totals {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
}

.admin-usage-stat {
  background: var(--navy-800);
  border: 1px solid var(--navy-700);
  border-radius: 10px;
  padding: 14px 18px;
  min-width: 160px;
}

.admin-usage-stat span {
  display: block;
  font-family: var(--display);
  font-weight: 700;
  font-size: 22px;
  color: var(--ink);
}

.admin-usage-stat label {
  font-family: var(--body);
  font-size: 11px;
  color: var(--ink-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.admin-usage-table-wrap { overflow-x: auto; }

.admin-usage-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--body);
  font-size: 12.5px;
}

.admin-usage-table th {
  text-align: left;
  padding: 8px 10px;
  color: var(--ink-dim);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--navy-700);
  white-space: nowrap;
}

.admin-usage-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--navy-800);
  color: var(--ink);
  white-space: nowrap;
}

.admin-usage-table td .pill {
  padding: 6px 10px;
  min-height: 0;
  font-size: 10.5px;
  margin-right: 6px;
}

.admin-usage-table td .issues-body-cell {
  white-space: normal;
  overflow-wrap: break-word;
  max-width: 420px;
}

.product-row {
  border: 1px solid var(--navy-700);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--navy-900);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

/* Name+domain block (the row's unclassed first child) — let it shrink and
   truncate instead of forcing the action pills to overflow the row. */
.product-row > div:first-child {
  min-width: 0;
  flex: 1 1 200px;
}

.product-row-name,
.product-row-domain {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.product-row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex-shrink: 0;
}

.product-row-actions .pill {
  padding: 10px 14px;
  min-height: 44px;
  font-size: 11px;
}

.product-delete-btn {
  color: var(--danger);
  border-color: var(--danger);
}

.product-delete-btn.confirming {
  background: var(--danger);
  color: var(--navy-950);
  font-weight: 700;
}

.settings-form-shell {
  max-width: 640px;
}

.settings-form-shell[hidden] { display: none; }

.settings-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.settings-panel[hidden] { display: none; }

/* Wider than the plain .create-form default (640px, tuned for narrow
   single-column forms like Create Brand) — Settings and Admin panels also
   hold data tables (admin-usage-table, brand member lists) that were
   cramped into that width while most of a wide viewport sat empty. */
.settings-panel.create-form { max-width: 960px; }

#create-brand-form { max-width: 640px; }

#create-brand-form details {
  border: 1px solid var(--navy-700);
  border-radius: 8px;
  background: var(--navy-900);
  padding: 4px 14px;
}

#create-brand-form details[open] { padding-bottom: 16px; }

#create-brand-form summary {
  cursor: pointer;
  font-family: var(--body);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.02em;
  padding: 12px 2px;
  list-style: none;
}

#create-brand-form summary::-webkit-details-marker { display: none; }

#create-brand-form details[open] summary { margin-bottom: 14px; }

#create-brand-form details .field:not(:last-child) { margin-bottom: 14px; }

.settings-form-footer {
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.settings-form-footer[hidden] { display: none; }

#mascot-name-field[hidden] { display: none; }
#mascot-identity-rules-field[hidden] { display: none; }
#openai-key-clear-btn[hidden] { display: none; }

.color-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.color-input-row input[type="color"] {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--navy-700);
  border-radius: 6px;
  background: none;
  cursor: pointer;
}

.color-input-row input[type="text"] { flex: 1; }

.brand-color-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 16px;
}

.brand-color-preview-swatch {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-color-preview-chip {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: 1px solid var(--navy-700);
  flex-shrink: 0;
}

.brand-color-preview-swatch span {
  font-family: var(--body);
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
}

.brand-color-preview-swatch small {
  font-family: var(--body);
  font-size: 11px;
  color: var(--ink-dim);
}

.colors-panel {
  width: 100%;
}

.token-subheading {
  font-family: var(--display);
  font-weight: 700;
  font-size: 13px;
  color: var(--ink-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 24px 0 10px;
}

.color-token-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 10px;
}

.color-token-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.color-token-row input[type="text"].token-key {
  width: 120px;
  flex-shrink: 0;
}

.color-token-row .token-remove {
  background: transparent;
  border: 1px solid var(--navy-700);
  color: var(--danger);
  border-radius: 6px;
  width: 30px;
  height: 30px;
  cursor: pointer;
  flex-shrink: 0;
}

.colors-save-btn { margin-top: 20px; }

/* ── Services editor (Brand Settings) ────────────────────────────────── */

.services-summary-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.service-summary-row {
  border: 1px solid var(--navy-700);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--navy-900);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.service-summary-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.service-summary-name {
  font-family: var(--display);
  font-weight: 600;
  font-size: 13px;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.service-summary-blurb {
  font-family: var(--body);
  font-size: 11.5px;
  color: var(--ink-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Service popup (create/edit + AI auto-write) ─────────────────────── */

.service-modal-card {
  grid-template-columns: 1fr;
  max-width: var(--modal-sm);
}

.service-modal-details {
  padding: 32px;
}

#service-auto-write {
  margin: -4px 0 14px;
  align-self: flex-start;
}

/* ── Persona tags ─────────────────────────────────────────────────── */

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.tag-chip {
  font-family: var(--body);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--azure);
  background: rgba(77, 163, 227, 0.12);
  border: 1px solid rgba(77, 163, 227, 0.35);
  border-radius: 999px;
  padding: 3px 9px;
}

.tags-edit-row { margin: 10px 0 12px; }
.tags-edit-row .field input { font-size: 12px; padding: 7px 10px; }

.save-tags-btn {
  margin-bottom: 4px;
}

.tags-status {
  font-family: var(--body);
  font-size: 11px;
  color: var(--ink-dim);
  margin-left: 10px;
}

/* ── Reuse-persona picker ─────────────────────────────────────────── */

.reuse-picker-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.reuse-preview-empty {
  font-family: var(--body);
  font-size: 12px;
  color: var(--ink-dim);
}

.reuse-preview-thumb {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  border: 1px solid var(--navy-700);
  object-fit: contain;
  background: var(--navy-900);
}

.mascot-current-image {
  display: block;
  max-width: 220px;
  max-height: 220px;
  border-radius: 8px;
  border: 1px solid var(--navy-700);
  object-fit: contain;
  background: var(--navy-900);
  margin-bottom: 16px;
}

.mascot-current-image[hidden] {
  display: none;
}

.logo-variant-block {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--navy-700);
}

.logo-variant-block:last-of-type {
  border-bottom: none;
}

#logo-generate-block {
  padding: 18px 20px;
  margin-bottom: 24px;
  background: var(--navy-900);
  border: 1px solid var(--azure);
  border-radius: 10px;
}

#logo-generate-block .token-subheading { margin-top: 0; }

#logo-generate-block select { margin-bottom: 10px; }

.logo-current-preview {
  display: block;
  max-width: 260px;
  max-height: 140px;
  border-radius: 8px;
  border: 1px solid var(--navy-700);
  object-fit: contain;
  padding: 12px;
  margin: 10px 0;
}

.logo-current-preview[hidden] { display: none; }

.logo-current-preview-light { background: var(--white); }
.logo-current-preview-dark { background: var(--navy-950); }

.picker-modal-card {
  grid-template-columns: 1fr;
  max-width: var(--modal-lg);
  max-height: 82vh;
}

.picker-modal-body {
  padding: 28px;
  overflow-y: auto;
}

.picker-modal-body .search-wrap { margin-bottom: 16px; }

.picker-grid {
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  padding: 0;
}

.picker-grid .card { cursor: pointer; }

/* ── Project Management: Kanban board (Task 8) ───────────────────────── */

.pm-kanban-board {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.pm-kanban-column {
  background: var(--navy-800);
  border: 1px solid var(--navy-700);
  border-radius: 10px;
  padding: 12px;
  min-height: 120px;
}

.pm-kanban-column h4 {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--ink-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.pm-kanban-column-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 40px;
}

.pm-kanban-card {
  cursor: grab;
  padding: 10px;
}

/* ── Project Management: Calendar view (Task 9) ──────────────────────── */

.pm-calendar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0 12px;
}

.pm-calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}

.pm-calendar-cell {
  background: var(--navy-800);
  border: 1px solid var(--navy-700);
  border-radius: 6px;
  min-height: 64px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.pm-calendar-day {
  font-size: 12px;
  color: var(--ink-dim);
}

.pm-marker {
  font-size: 10px;
  border-radius: 4px;
  padding: 1px 5px;
  width: fit-content;
}

.pm-marker--due {
  background: rgba(242, 184, 75, 0.18);
  color: var(--warning);
}

.pm-marker--publish {
  background: rgba(46, 157, 103, 0.18);
  color: var(--success);
}

#pm-item-social-status {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

/* ── Services checklist ───────────────────────────────────────────── */

.services-checklist-row {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 4px;
}

.services-select-all {
  flex-direction: row;
  font-size: 12px;
  color: var(--azure);
}

.services-checklist {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--navy-700);
  border-radius: 8px;
  padding: 12px;
  background: var(--navy-900);
}

.services-checklist-empty {
  font-family: var(--body);
  font-size: 12px;
  color: var(--ink-dim);
}

.service-check-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.service-check-row input {
  margin-top: 3px;
  width: 15px;
  height: 15px;
  accent-color: var(--azure);
  flex-shrink: 0;
}

.service-check-row .service-check-label {
  font-family: var(--body);
  font-size: 13px;
}

.service-check-row .service-check-name {
  color: var(--ink);
  font-weight: 600;
}

.service-check-row .service-check-blurb {
  color: var(--ink-dim);
  display: block;
  font-size: 11px;
  margin-top: 2px;
}

/* ── Home ─────────────────────────────────────────────────────────── */

#view-home { padding: 44px 40px 80px; max-width: 1100px; }

.home-hero { max-width: 720px; margin-bottom: 48px; }

.home-hero h2 {
  font-family: var(--display);
  font-weight: 800;
  font-size: 40px;
  color: var(--ink);
  margin: 10px 0 18px;
  line-height: 1.15;
}

.home-hero h2 .a { color: var(--azure); }

.home-lede {
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink-dim);
  margin: 0;
}

.home-lede code {
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  background: var(--navy-800);
  border: 1px solid var(--navy-700);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 13px;
  color: var(--sand);
}

.home-quick-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
  margin-bottom: 8px;
}

.home-quick-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  text-align: left;
  background: var(--navy-800);
  border: 1px solid var(--navy-700);
  border-radius: 12px;
  padding: 20px 22px;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.home-quick-btn:hover {
  border-color: var(--azure);
  transform: translateY(-2px);
}

.home-quick-btn-primary {
  background: linear-gradient(135deg, rgba(77, 163, 227, 0.16), rgba(77, 163, 227, 0.04));
  border-color: rgba(77, 163, 227, 0.4);
}

.home-quick-title {
  font-family: var(--display);
  font-weight: 700;
  font-size: 16px;
  color: var(--ink);
}

.home-quick-desc {
  font-family: var(--body);
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-dim);
}

.home-recent-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--azure);
  font-family: var(--body);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px;
}

.link-btn:hover { color: var(--azure-dim); }

@media (max-width: 880px) {
  .app-shell { flex-direction: column; }

  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  .sidebar::after { display: none; }

  .sidebar-brand { border-bottom: none; padding: 16px 20px; }

  .side-nav {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 0 12px 14px;
  }

  .side-nav-label { display: none; }

  .tab { width: auto; white-space: nowrap; margin-bottom: 0; margin-right: 4px; }
  .tab.active { box-shadow: inset 0 -2px 0 var(--azure); }

  .sidebar-foot { display: none; }
}

@media (max-width: 720px) {
  .modal-card { grid-template-columns: 1fr; }
  h1 { font-size: 38px; }
  .grid, #view-create, #view-settings, #view-home, #view-new-persona, #view-admin, #view-catalog, #view-create-brand, #view-templates, #view-issues, #view-projects, #view-project-detail { padding-left: 20px; padding-right: 20px; }
  /* #view-archive/#view-generations have no section-level horizontal padding of their
     own (see the #view-archive > .section-header rule above) — .filters/.grid are
     already covered by this same media query, so only the header needs the override. */
  #view-archive > .section-header, #view-generations > .section-header { padding-left: 20px; padding-right: 20px; }
  .filters { padding-left: 20px; padding-right: 20px; }
  .home-quick-actions { grid-template-columns: 1fr; }
}

/* ── Auth (login) ─────────────────────────────────────────────────── */

.auth-body {
  min-height: 100vh;
  display: flex;
}

.auth-shell {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--navy-800);
  border: 1px solid var(--navy-700);
  border-radius: 16px;
  padding: 40px 36px 36px;
  position: relative;
  box-shadow: var(--shadow-elevated);
}

.auth-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 24px;
  right: 24px;
  height: 3px;
  border-radius: 0 0 4px 4px;
  background: var(--azure);
  opacity: 0.7;
}

.auth-mark {
  width: 44px;
  height: 44px;
  margin-bottom: 18px;
}

.auth-mark svg { width: 27px; height: 27px; }

/* ── Reduced motion ───────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .card { animation: none; opacity: 1; }
  .modal { animation: none; }
}

/* ── Progressive disclosure (Create Post advanced fields) ────────────── */

.field-row-disabled { opacity: 0.45; }
.field-row-disabled input,
.field-row-disabled select,
.field-row-disabled textarea { cursor: not-allowed; }

.field-disclosure {
  border: 1px solid var(--navy-700);
  border-radius: 8px;
  background: var(--navy-900);
  padding: 2px 14px;
}

.field-disclosure summary {
  font-family: var(--body);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.02em;
  padding: 12px 2px;
  cursor: pointer;
  list-style: none;
}

.field-disclosure summary::-webkit-details-marker { display: none; }

.field-group {
  border: 1px solid var(--navy-700);
  border-radius: 8px;
  background: var(--navy-900);
  padding: 16px 14px 14px;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field-group legend {
  font-family: var(--body);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-dim);
  padding: 0 4px;
}

.field-disclosure summary::before {
  content: "▸";
  display: inline-block;
  width: 14px;
  color: var(--ink-dim);
  transition: transform 0.15s ease;
}

.field-disclosure[open] summary::before { transform: rotate(90deg); }

.field-disclosure summary em {
  font-style: normal;
  font-weight: 400;
  color: var(--ink-dim);
}

.field-disclosure-body {
  padding: 4px 2px 16px;
  flex-direction: column;
  gap: 16px;
}

/* Explicit open/closed display, not relying on <details>'s native
   non-summary-child hiding — that native behavior didn't reliably apply
   here, leaving the body visible (with real layout) while the closed
   <details> element itself still reported its native collapsed height,
   so the body's fields overlapped the form's later siblings. Same class of
   bug as the [hidden] overrides fixed elsewhere this session. */
.field-disclosure[open] .field-disclosure-body {
  display: flex;
}

.field-disclosure:not([open]) .field-disclosure-body {
  display: none;
}

.auth-help {
  margin: 18px 0 0;
  font-family: var(--body);
  font-size: 12px;
  color: var(--ink-dim);
  text-align: center;
}

/* ── Campaign expand/review ───────────────────────────────────────── */

/* These children only need top/bottom spacing to avoid doubling horizontal
   padding. */
#campaign-review { padding: 0 0 80px; }
#campaign-setup { padding: 12px 0 0; }

.campaign-posts-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.campaign-post-card {
  background: var(--navy-800);
  border: 1px solid var(--navy-700);
  border-radius: 12px;
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.campaign-post-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.campaign-post-index {
  font-family: var(--display);
  font-weight: 700;
  font-size: 13px;
  color: var(--sand);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.card-caption {
  font-family: var(--body);
  font-size: 12px;
  line-height: 1.5;
  color: var(--ink-dim);
  margin: 8px 0 0;
}

.card-hashtags {
  font-family: var(--body);
  font-size: 11.5px;
  color: var(--azure-dim);
  margin: 6px 0 0;
}

.card-body .pill { margin-top: 10px; font-size: 11px; padding: 10px 14px; min-height: 44px; }

/* Archive/Generations cards pack 3 action pills ("Reuse"/"Use as base",
   "Download", "Delete") into a ~190px-wide card body. Without wrapping,
   they overflow the flex row and get clipped by .card's overflow:hidden. */
.card-body .product-row-actions {
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.card-body .product-row-actions .pill {
  flex: 1 1 auto;
  min-width: 0;
  margin-top: 0;
  padding: 8px 10px;
  font-size: 10.5px;
  min-height: 36px;
  text-align: center;
}

.product-row-archived { opacity: 0.55; }

.archived-badge {
  margin-left: 8px;
  font-family: var(--body);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--warning);
  border: 1px solid var(--warning);
  border-radius: 999px;
  padding: 2px 7px;
  vertical-align: middle;
}

.inherited-badge {
  display: inline-block;
  margin: 6px 0 10px;
  font-family: var(--body);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--azure);
  border: 1px solid var(--azure);
  border-radius: 999px;
  padding: 2px 9px;
}

/* ── Reference image uploads (product photos) ─────────────────────── */

.reference-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.reference-thumbs:empty { display: none; }

.reference-thumb {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--navy-700);
  background: var(--navy-900);
}

.reference-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.reference-thumb-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: rgba(10, 20, 31, 0.8);
  color: var(--ink);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}

.reference-thumb-uploading {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--ink-dim);
  text-align: center;
  padding: 4px;
}

.campaign-post-preview-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.campaign-post-preview-list:empty { display: none; }

.campaign-post-preview-thumb {
  width: 110px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.campaign-post-preview-thumb img {
  width: 110px;
  height: 110px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--navy-700);
  background: var(--navy-900);
}

.campaign-post-preview-thumb span {
  font-family: var(--body);
  font-size: 10px;
  color: var(--ink-dim);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.campaign-post-header-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.campaign-post-header-actions .pill {
  padding: 10px 14px;
  min-height: 44px;
  font-size: 11px;
}

.campaign-post-status {
  font-family: var(--body);
  font-size: 12px;
  color: var(--ink-dim);
  margin-top: -6px;
}

.campaign-post-status:empty { display: none; }

.campaign-post-status.error { color: var(--danger); }

/* ── Layout editor ────────────────────────────────────────────────────── */

.layout-editor-card {
  grid-template-columns: 1fr;
  width: min(960px, 92vw);
  max-height: 90vh;
  overflow-y: auto;
}

.layout-editor-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 28px;
}

.layout-editor-toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.layout-editor-brand-field {
  min-width: 200px;
}

.layout-editor-canvas-wrap {
  display: grid;
  grid-template-columns: 32px auto;
  grid-template-rows: 28px auto;
  justify-content: center;
  background: var(--navy-950, #05070c);
  border: 1px solid var(--navy-700);
  border-radius: 8px;
  padding: 16px;
  /* The canvas is a fixed BOX_EDITOR_MAX_CANVAS_WIDTH (box-editor-shared.js) —
     intentional, so drag/resize coordinates stay accurate; on narrow
     viewports it scrolls within this wrapper instead of overflowing the page. */
  max-width: 100%;
  overflow-x: auto;
}

.layout-editor-ruler-corner {
  grid-column: 1;
  grid-row: 1;
}

.layout-editor-ruler-h {
  grid-column: 2;
  grid-row: 1;
  position: relative;
  height: 28px;
  background: var(--navy-900);
  border-bottom: 1px solid var(--navy-700);
}

.layout-editor-ruler-v {
  grid-column: 1;
  grid-row: 2;
  position: relative;
  width: 32px;
  background: var(--navy-900);
  border-right: 1px solid var(--navy-700);
}

.layout-editor-canvas {
  position: relative;
  display: inline-block;
}

.layout-editor-canvas img {
  display: block;
  max-width: 100%;
  height: auto;
}

.ruler-tick {
  position: absolute;
  background: var(--navy-700);
}

.layout-editor-ruler-h .ruler-tick {
  top: 0;
  width: 1px;
  height: 6px;
}

.layout-editor-ruler-h .ruler-tick.labeled {
  height: 12px;
}

.layout-editor-ruler-v .ruler-tick {
  left: 0;
  height: 1px;
  width: 6px;
}

.layout-editor-ruler-v .ruler-tick.labeled {
  width: 12px;
}

.ruler-tick-label {
  position: absolute;
  font-family: var(--body);
  font-size: 9px;
  color: var(--ink-dim);
  white-space: nowrap;
}

.layout-editor-ruler-h .ruler-tick-label {
  top: 12px;
  left: 2px;
}

.layout-editor-ruler-v .ruler-tick-label {
  left: 14px;
  top: -4px;
  transform-origin: left top;
  transform: rotate(-90deg) translateX(-100%);
}

.ruler-indicator-h {
  position: absolute;
  top: 0;
  width: 1px;
  height: 100%;
  background: var(--azure);
  pointer-events: none;
}

.ruler-indicator-v {
  position: absolute;
  left: 0;
  height: 1px;
  width: 100%;
  background: var(--azure);
  pointer-events: none;
}

.layout-editor-coord-label {
  position: absolute;
  background: var(--navy-900);
  border: 1px solid var(--navy-700);
  color: var(--ink);
  font-family: var(--body);
  font-size: 10px;
  padding: 2px 5px;
  border-radius: 4px;
  pointer-events: none;
  white-space: nowrap;
  z-index: 5;
}

.layout-editor-box {
  position: absolute;
  border: 2px dashed rgba(77, 163, 227, 0.55);
  background: rgba(77, 163, 227, 0.08);
  cursor: move;
  box-sizing: border-box;
}

.layout-editor-box.selected {
  border: 2px solid var(--azure);
  background: rgba(77, 163, 227, 0.18);
}

.layout-editor-box-label {
  position: absolute;
  top: -20px;
  left: 0;
  font-family: var(--body);
  font-size: 10px;
  color: var(--white);
  white-space: nowrap;
  pointer-events: none;
  background: rgba(15, 23, 42, 0.82);
  padding: 1px 5px;
  border-radius: 3px;
  line-height: 1.5;
}

.layout-editor-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: var(--azure);
  border-radius: 50%;
  cursor: nwse-resize;
}

.layout-editor-handle[data-corner="nw"] { left: -5px; top: -5px; cursor: nwse-resize; }
.layout-editor-handle[data-corner="ne"] { right: -5px; top: -5px; cursor: nesw-resize; }
.layout-editor-handle[data-corner="sw"] { left: -5px; bottom: -5px; cursor: nesw-resize; }
.layout-editor-handle[data-corner="se"] { right: -5px; bottom: -5px; cursor: nwse-resize; }

.layout-editor-side-panel {
  border-top: 1px solid var(--navy-700);
  padding-top: 12px;
}

.layout-editor-element-list {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.layout-editor-element-list-item {
  font-family: var(--body);
  font-size: 11.5px;
  color: var(--ink-dim);
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
}

.layout-editor-element-list-item:hover {
  border-color: var(--navy-700);
  color: var(--ink);
}

.layout-editor-element-list-item.selected {
  border-color: var(--azure);
  color: var(--ink);
  background: var(--navy-900);
}

/* ── Page-Anchored Issue Tracker ──────────────────────────────────── */

.issues-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 60;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: var(--azure);
  color: var(--navy-950);
  font: 700 20px var(--display);
  cursor: pointer;
  box-shadow: var(--shadow-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
}
.issues-fab:hover { background: var(--azure-hover); }
.issues-fab[hidden] { display: none; }

.issues-fab-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--danger);
  color: var(--white);
  border-radius: 999px;
  min-width: 18px;
  height: 18px;
  font: 700 11px var(--body);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}
.issues-fab-badge[hidden] { display: none; }

.issues-panel {
  position: fixed;
  right: 24px;
  bottom: 88px;
  z-index: 60;
  width: min(360px, calc(100vw - 32px));
  max-height: min(480px, calc(100vh - 140px));
  display: flex;
  flex-direction: column;
  background: var(--navy-800);
  border: 1px solid var(--navy-700);
  border-radius: 12px;
  box-shadow: var(--shadow-elevated);
  padding: 14px;
  gap: 10px;
}
.issues-panel[hidden] { display: none; }

.issues-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.issues-panel-head strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.issues-panel-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.issues-panel-card {
  background: var(--navy-900);
  border: 1px solid var(--navy-700);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
}

.issues-status-badge {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 8px;
  font: 700 11px var(--body);
  text-transform: uppercase;
  margin-right: 6px;
  background: var(--navy-700);
  color: var(--ink-dim);
}
.issues-status-open, .issues-status-reopened { background: var(--azure); color: var(--navy-950); }
.issues-status-in_progress { background: var(--sand); color: var(--navy-950); }
.issues-status-blocked { background: var(--warning); color: var(--navy-950); }
.issues-status-resolved, .issues-status-closed { background: var(--success); color: var(--navy-950); }

#issues-groups details {
  margin-bottom: 12px;
  border: 1px solid var(--navy-700);
  border-radius: 10px;
  padding: 10px 14px;
}
#issues-groups summary {
  cursor: pointer;
  font: 700 14px var(--display);
}

/* .modal-card's base grid-template-columns: 1fr 1fr is meant for the
   image+details split (see .modal-image-wrap/.modal-details) — with only
   a heading and a form as its (non-absolutely-positioned) children,
   #issue-form-card was auto-placing them into separate half-width grid
   columns side by side instead of stacking, and the form had no scroll
   of its own so a tall form could clip against the base 88vh max-height.
   Same override pattern as .confirm-modal-card/.picker-modal-card. */
#issue-form-card {
  grid-template-columns: 1fr;
  max-height: 88vh;
  overflow-y: auto;
  padding: 32px;
}

@media (max-width: 720px) {
  .issues-panel { right: 16px; left: 16px; width: auto; }
  .issues-fab { right: 16px; bottom: 16px; }
}

.markdown-field-view { border: 1px solid var(--navy-700); border-radius: 6px; padding: 0.75rem; min-height: 2rem; }
.markdown-field-view :first-child { margin-top: 0; }
.markdown-field-view :last-child { margin-bottom: 0; }
.markdown-field-edit { display: flex; flex-direction: column; gap: 0.5rem; }
.markdown-field-edit[hidden] { display: none; }
.markdown-field-textarea { width: 100%; min-height: 8rem; font-family: monospace; }
.markdown-field-preview { border: 1px dashed var(--navy-700); border-radius: 6px; padding: 0.75rem; }
