:root {
  --bg: #01011d;
  --surface: #0f0f2a;
  --surface-2: #161636;
  --border: #262844;
  --hair: #232647;

  --text: #F4F4F8;
  --muted: #A0A3B8;
  --dim: #6B7290;

  --ember: #EC4899;
  --magenta: #EC4899;
  --violet: #8B5CF6;
  --coral: #F43F5E;
  --orange: #F97316;

  --success: #22c55e;
  --warning: #f97316;
  --error: #f43f5e;
  --info: #8b5cf6;

  --success-bg: rgba(34, 197, 94, 0.15);
  --warning-bg: rgba(249, 115, 22, 0.15);
  --error-bg: rgba(244, 63, 94, 0.15);
  --info-bg: rgba(139, 92, 246, 0.15);

  --gradient-brand: linear-gradient(110deg, #8B5CF6 0%, #EC4899 35%, #F43F5E 65%, #F97316 100%);
  --gradient-subtle: linear-gradient(110deg, #8B5CF6 0%, #EC4899 100%);

  --radius-sm: 8px;
  --radius: 11px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  --shadow-1: 0 2px 8px rgba(0, 0, 0, 0.10);
  --shadow-2: 0 4px 16px rgba(0, 0, 0, 0.12);
  --shadow-3: 0 8px 24px rgba(0, 0, 0, 0.15);
  --shadow-4: 0 16px 48px rgba(0, 0, 0, 0.20);

  --font: 'Poppins', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: ui-monospace, 'Cascadia Code', 'SF Mono', Consolas, monospace;

  /* Motion — entrances ease-out, exits ease-in, playful settles spring.
     Transform + opacity ONLY; every animation interruptible and under 320ms. */
  --dur-fast: 120ms;
  --dur: 200ms;
  --dur-slow: 320ms;

  --nav-w: 240px;
  --nav-w-collapsed: 64px;
  --context-h: 48px;
  --panel-w: 340px;

  --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
  --ease-in-out: cubic-bezier(0.42, 0, 0.58, 1);
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  color-scheme: dark;
}

.light-theme {
  --bg: #f5f4f9;
  --surface: #ffffff;
  --surface-2: #f3f2f9;
  --border: #e4e4ee;
  --hair: #ebebf2;

  --text: #1a1b2e;
  --muted: #667085;
  --dim: #98a2b3;

  --shadow-1: 0 2px 12px rgba(139, 92, 246, 0.05);
  --shadow-2: 0 8px 24px rgba(139, 92, 246, 0.08);
  --shadow-3: 0 12px 32px rgba(139, 92, 246, 0.10);
  --shadow-4: 0 16px 48px rgba(139, 92, 246, 0.12);

  color-scheme: light;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
*::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

body { user-select: none; }
input, textarea, [contenteditable] { user-select: text; }
::selection { background: rgba(139, 92, 246, 0.32); }
.light-theme ::selection { background: rgba(139, 92, 246, 0.22); }

.light-theme body, body.light-theme {
  background: linear-gradient(180deg, #f5f4f9 0%, #eaeef8 40%, #f3f0f8 70%, #f5f4f9 100%);
}

h1, h2, h3, h4, h5 {
  font-family: var(--font);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.25;
  color: var(--text);
}
.display { font-size: clamp(34px, 4vw, 48px); font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.015em; }
.h2 { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.h3 { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.body { font-size: 16px; font-weight: 400; line-height: 1.6; color: var(--text); }
.small { font-size: 13px; font-weight: 500; line-height: 1.54; color: var(--muted); }
.tiny { font-size: 11px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--dim); }

.gradient-text {
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
}

a { color: var(--ember); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font-family: var(--font); cursor: pointer; }
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--ember);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-family: var(--font);
  font-weight: 600;
  font-size: 14px;
  padding: 11px 22px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.15s var(--ease), filter 0.15s var(--ease), background 0.15s var(--ease), border-color 0.15s var(--ease);
  white-space: nowrap;
  line-height: 1;
}
.btn svg { width: 16px; height: 16px; }
/* Press physics: hover lifts, press settles down with a subtle scale snap. */
.btn:active { transform: translateY(0) scale(0.965); transition-duration: var(--dur-fast); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none !important; filter: none !important; }

.btn-primary {
  background: var(--gradient-brand);
  color: #ffffff;
  font-weight: 700;
}
.btn-primary:hover { filter: brightness(1.08); transform: translateY(-1px); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--surface-2); }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--surface-2); }

.btn-outline {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-outline:hover { background: var(--surface-2); border-color: var(--ember); }

.btn-danger {
  background: var(--error);
  color: #ffffff;
  font-weight: 700;
}
.btn-danger:hover { filter: brightness(1.08); }

.btn-sm { padding: 7px 14px; font-size: 13px; border-radius: var(--radius-sm); }
.btn-icon {
  width: 34px; height: 34px; padding: 0;
  border-radius: var(--radius-sm);
  background: transparent; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid transparent;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.btn-icon svg { width: 18px; height: 18px; }
.btn-icon:hover { background: var(--surface-2); color: var(--text); }
.btn-icon.active { color: var(--ember); background: var(--info-bg); }

/* Editor toolbar — compact, matching the sidebar's premium icon style */
.editor-toolbar .btn-icon { width: 30px; height: 30px; border-radius: 6px; }
.editor-toolbar .btn-icon svg { width: 16px; height: 16px; }
.editor-toolbar .btn-icon:hover { background: var(--surface-2); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  transition: transform 0.15s var(--ease), border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.light-theme .card { background: linear-gradient(145deg, #ffffff, #f9f7fe); }
.card-accent {
  width: 40px; height: 4px; border-radius: 2px;
  background: var(--gradient-brand);
  margin-bottom: var(--space-4);
}
.card.hoverable { cursor: pointer; }
.card.hoverable:hover { transform: translateY(-2px); border-color: var(--ember); box-shadow: var(--shadow-2); }

.input, .textarea, .select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
/* Focus glow — a soft violet ring that blooms without shifting layout. */
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--violet);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.16);
}
.input::placeholder, .textarea::placeholder { color: var(--dim); }
.textarea { min-height: 80px; resize: vertical; line-height: 1.5; }
.select { appearance: none; cursor: pointer; padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23A0A3B8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
.field { margin-bottom: var(--space-4); }
.field-label { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: var(--space-2); }
.field-help { font-size: 12px; color: var(--dim); margin-top: var(--space-1); }
.field-error { font-size: 12px; color: var(--error); margin-top: var(--space-1); }

.badge {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 3px 10px;
  border-radius: var(--radius-xl);
  font-size: 11px; font-weight: 600;
  background: var(--info-bg); color: var(--info);
  font-variant-numeric: tabular-nums;
}
.badge.success { background: var(--success-bg); color: var(--success); }
.badge.warning { background: var(--warning-bg); color: var(--warning); }
.badge.error { background: var(--error-bg); color: var(--error); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.neutral { background: rgba(160, 163, 184, 0.15); color: var(--muted); }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* Dual-arc indeterminate ring (Apple-style): conic sweep on a ring with a
   soft trailing arc. One class, used everywhere. */
.spinner {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: conic-gradient(transparent 0deg, var(--violet) 130deg, var(--ember) 220deg, transparent 260deg);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 2px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 2px));
  animation: spin 0.9s cubic-bezier(0.55, 0.15, 0.45, 0.85) infinite;
  display: inline-block;
  flex-shrink: 0;
}
.spinner.lg {
  width: 24px; height: 24px;
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2.5px), #000 calc(100% - 2.5px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 2.5px), #000 calc(100% - 2.5px));
}
@keyframes spin { to { transform: rotate(360deg); } }

.progress {
  height: 4px;
  background: var(--surface-2);
  border-radius: 2px;
  overflow: hidden;
}
.progress > div {
  height: 100%;
  background: var(--gradient-subtle);
  border-radius: 2px;
  transition: width 0.3s var(--ease);
}
.progress.indeterminate > div {
  width: 40% !important;
  animation: indet 1.4s var(--ease-in-out) infinite;
}
@keyframes indet {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}

.skeleton {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  position: relative;
  overflow: hidden;
}
.skeleton::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.05), transparent);
  animation: shimmer 1.5s var(--ease-in-out) infinite;
}
.light-theme .skeleton::after { background: linear-gradient(90deg, transparent, rgba(14, 20, 40, 0.045), transparent); }
@keyframes shimmer { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }

/* Skeleton composites — layout-matching placeholders for loading grids.
   Cards arrive as skeletons; the real content swaps in without layout shift. */
.skel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.skel-thumb { height: 130px; border-radius: 0; }
.skel-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 9px; }
.skel-line { height: 11px; border-radius: 6px; }
.skel-line.w-60 { width: 60%; }
.skel-line.w-80 { width: 80%; }
.skel-line.w-40 { width: 40%; }
.skel-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.skel-avatar { width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0; }
.skel-lines { flex: 1; display: flex; flex-direction: column; gap: 8px; }

/* Rise-in — content arrives (never pops). Applied to freshly rendered grid
   children; per-index delays create the staggered choreography. */
@keyframes rise-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.rise-in { animation: rise-in var(--dur-slow) var(--ease-out) backwards; }

.divider { height: 1px; background: var(--border); border: none; }
.divider.hair { background: var(--hair); }

.tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--border); }
.tab {
  padding: 10px 16px;
  font-size: 13px; font-weight: 600; color: var(--muted);
  background: transparent; border: none; cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s var(--ease), border-color 0.15s var(--ease);
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--ember); }

.pill-tabs {
  display: inline-flex; gap: var(--space-1);
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 3px;
}
.pill-tab {
  padding: 7px 14px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600; color: var(--muted);
  background: transparent; border: none; cursor: pointer;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.pill-tab:hover { color: var(--text); }
.pill-tab.active { background: var(--gradient-subtle); color: #fff; }

.overlay {
  position: fixed; inset: 0;
  background: rgba(1, 1, 29, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  animation: fadein var(--dur) var(--ease);
  transition: opacity 160ms var(--ease-in-out);
}
.overlay.closing { opacity: 0; pointer-events: none; }
.overlay.closing .modal { transform: scale(0.96); opacity: 0; }
.light-theme .overlay { background: rgba(26, 27, 46, 0.45); }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  width: 100%; max-width: 480px;
  max-height: 85vh; overflow-y: auto;
  box-shadow: var(--shadow-3);
  animation: modalin var(--dur) var(--ease-out);
  transition: transform 160ms var(--ease-in-out), opacity 160ms var(--ease-in-out);
}
.modal.lg { max-width: 640px; }
.modal.xl { max-width: 880px; }
@keyframes modalin { from { transform: scale(0.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-4); }
.modal-title { font-size: 18px; font-weight: 700; color: var(--text); }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-5); }

.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: var(--space-8) var(--space-5);
  gap: var(--space-3);
  animation: rise-in var(--dur-slow) var(--ease-out) backwards;
}
.empty .empty-icon { color: var(--dim); margin-bottom: var(--space-2); }
/* Empty-state icons drift gently — a living page, not a dead end. */
.empty .empty-icon, .empty > span:first-child {
  animation: emptyFloat 3.8s var(--ease-in-out) infinite;
}
@keyframes emptyFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}
.empty .empty-title { font-size: 18px; font-weight: 600; color: var(--text); }
.empty .empty-desc { font-size: 14px; color: var(--muted); max-width: 380px; }

.tooltip-host { position: relative; display: inline-flex; }
.tooltip {
  position: absolute;
  bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); font-size: 12px; font-weight: 500;
  padding: 5px 10px; border-radius: var(--radius-sm);
  white-space: nowrap; pointer-events: none;
  box-shadow: var(--shadow-2);
  opacity: 0; transition: opacity 0.2s var(--ease);
  z-index: 1100;
}
.tooltip-host:hover .tooltip { opacity: 1; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--ember); background-clip: padding-box; }

/* ===== MODERN MINIMAL THEME ===== */
/* Zinc + Indigo, flat, system fonts. Activated via data-theme-family="modern-minimal" on <html>. */

:root[data-theme-family='modern-minimal'] {
  --bg: #09090b;
  --surface: #18181b;
  --surface-2: #27272a;
  --border: #27272a;
  --hair: #27272a;
  --text: #fafafa;
  --muted: #a1a1aa;
  --dim: #71717a;
  --ember: #6366f1;
  --magenta: #6366f1;
  --violet: #6366f1;
  --coral: #ef4444;
  --orange: #f59e0b;
  --success: #22c55e;
  --warning: #f59e0b;
  --error: #ef4444;
  --info: #6366f1;
  --success-bg: rgba(34, 197, 94, 0.15);
  --warning-bg: rgba(245, 158, 11, 0.15);
  --error-bg: rgba(239, 68, 68, 0.15);
  --info-bg: rgba(99, 102, 241, 0.15);
  --gradient-brand: #6366f1;
  --gradient-subtle: #6366f1;
  --radius-sm: 4px;
  --radius: 6px;
  --radius-lg: 8px;
  --radius-xl: 12px;
  --shadow-1: none;
  --shadow-2: 0 4px 16px rgba(0,0,0,.5);
  --shadow-3: 0 4px 16px rgba(0,0,0,.5);
  --shadow-4: 0 8px 32px rgba(0,0,0,.6);
}

:root[data-theme-family='modern-minimal'] body.light-theme,
body.light-theme[data-theme-family='modern-minimal'] {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --border: #e4e4e7;
  --hair: #e4e4e7;
  --text: #18181b;
  --muted: #71717a;
  --dim: #a1a1aa;
  --ember: #4f46e5;
  --magenta: #4f46e5;
  --violet: #4f46e5;
  --info: #4f46e5;
  --info-bg: rgba(79,70,229,.1);
  --shadow-2: 0 4px 16px rgba(0,0,0,.08);
  --shadow-3: 0 4px 16px rgba(0,0,0,.08);
  --shadow-4: 0 8px 32px rgba(0,0,0,.12);
}

:root[data-theme-family='modern-minimal'] body { font-size: 14px; letter-spacing: -0.01em; }
:root[data-theme-family='modern-minimal'] .card { padding: 24px; background: var(--surface); border-color: var(--border); }
:root[data-theme-family='modern-minimal'] .h1 { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; }
:root[data-theme-family='modern-minimal'] .h2 { font-size: 18px; font-weight: 600; }
:root[data-theme-family='modern-minimal'] .h3 { font-size: 15px; font-weight: 600; }
:root[data-theme-family='modern-minimal'] .btn { font-size: 13px; font-weight: 500; border-radius: var(--radius); }
:root[data-theme-family='modern-minimal'] .input { font-size: 13px; border-radius: var(--radius); }
:root[data-theme-family='modern-minimal'] .small { font-size: 12px; }
:root[data-theme-family='modern-minimal'] .card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }

/* Minimal light-theme card overrides (no gradients) */
:root[data-theme-family='modern-minimal'] body.light-theme .card,
body.light-theme[data-theme-family='modern-minimal'] .card { background: var(--surface); }
:root[data-theme-family='modern-minimal'] .connect-card { background: var(--surface); }
:root[data-theme-family='modern-minimal'] .page-card { background: var(--surface); }
:root[data-theme-family='modern-minimal'] .media-cell { background: var(--surface); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===== CREATE WORKSPACE ===== */

.create-guide { background: var(--surface); border: 1px solid var(--hair); border-radius: var(--radius); padding: 14px 18px; margin-bottom: 18px; }
.create-guide-title { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 4px; display: flex; align-items: center; gap: 6px; }
/* Create workspace — constrain ALL SVGs to prevent them from expanding */
.create-guide-title svg, .create-guide-text svg { width: 16px; height: 16px; flex-shrink: 0; }
.create-page-card svg { width: 16px; height: 16px; flex-shrink: 0; }
.create-page-check svg { width: 12px; height: 12px; }
.article-template-diagram svg { width: 100%; height: 76px; }
.article-template-card .btn svg { width: 14px; height: 14px; }
#createBody .btn svg { width: 14px; height: 14px; }
#createBody button svg { width: 16px; height: 16px; flex-shrink: 0; }
.create-guide-text { font-size: 12.5px; color: var(--muted); line-height: 1.5; }

.create-page-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.create-page-card { display: flex; flex-direction: column; gap: 4px; background: var(--surface); border: 1px solid var(--hair); border-radius: var(--radius); padding: 14px; cursor: pointer; transition: border-color .15s var(--ease), background .15s var(--ease); position: relative; }
.create-page-card:hover { border-color: var(--ember); }
.create-page-card.selected { border-color: var(--ember); background: var(--surface-2); }
.create-page-card.selected .create-page-check { display: flex; }
.create-page-check { display: none; position: absolute; top: 10px; right: 10px; width: 22px; height: 22px; border-radius: 50%; background: var(--ember); color: #fff; align-items: center; justify-content: center; font-size: 12px; }
.create-page-name { font-size: 14px; font-weight: 600; color: var(--text); }
.create-page-slug { font-size: 12px; color: var(--muted); font-family: var(--font-mono, monospace); }

.create-form-row { display: flex; gap: 14px; flex-wrap: wrap; }
.create-field { display: flex; flex-direction: column; gap: 5px; }
.create-field label { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

/* Article template cards */
.article-template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.article-template-card { display: flex; flex-direction: column; gap: 10px; background: var(--surface); border: 1px solid var(--hair); border-radius: var(--radius); padding: 16px; cursor: pointer; transition: border-color .15s var(--ease); }
.article-template-card:hover { border-color: var(--ember); }
.article-template-diagram { background: var(--surface-2); border: 1px solid var(--hair); border-radius: var(--radius-sm); padding: 10px; color: var(--muted); }
.article-template-card:hover .article-template-diagram { color: var(--ember); }
.article-template-name { font-size: 15px; font-weight: 700; color: var(--text); }
.article-template-desc { font-size: 12.5px; color: var(--muted); line-height: 1.45; flex: 1; }

/* Article compose */
.article-compose-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
@media (max-width: 900px) { .article-compose-grid { grid-template-columns: 1fr; } }
.article-compose-form { display: flex; flex-direction: column; }
.article-body-toolbar { display: flex; gap: 6px; margin-bottom: 8px; }
.article-blocks { display: flex; flex-direction: column; gap: 8px; max-height: 380px; overflow-y: auto; padding: 2px; }
.article-block { background: var(--surface); border: 1px solid var(--hair); border-radius: var(--radius-sm); padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.article-block-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.article-block-image img { max-height: 120px; object-fit: cover; }
.flex-spacer { flex: 1; }
.article-block-handle { display: inline-flex; align-items: center; color: var(--dim); cursor: grab; padding: 2px 4px; border-radius: 4px; }
.article-block-handle:hover { color: var(--text); background: var(--surface-2); }
.article-block-handle svg { width: 14px; height: 14px; }
.article-block.article-dragging { opacity: .45; }
.article-block.article-drop-target { outline: 2px dashed var(--violet); outline-offset: 2px; }
.article-style-tools { display: inline-flex; gap: 2px; }
.style-btn { border: 1px solid var(--hair); background: var(--surface-2); color: var(--text); border-radius: 6px; width: 26px; height: 24px; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; cursor: pointer; line-height: 1; }
.style-btn:hover { border-color: var(--violet); color: var(--violet); }
.style-btn b, .style-btn i, .style-btn u { font-size: 13px; }
.block-edit { min-height: 64px; max-height: 200px; overflow-y: auto; white-space: pre-wrap; word-break: break-word; font-size: 13px; line-height: 1.55; }
.block-edit:empty::before { content: attr(data-ph); color: var(--dim); pointer-events: none; }
.block-edit:focus { outline: none; border-color: var(--violet); }

/* Preview overlay (template previews + media pickers) */
.create-preview-overlay { position: fixed; inset: 0; z-index: 2000; background: rgba(0,0,0,.65); display: flex; align-items: center; justify-content: center; padding: 24px; animation: fadein var(--dur) var(--ease); transition: opacity 160ms var(--ease-in-out); }
.create-preview-overlay.closing { opacity: 0; pointer-events: none; }
.create-preview-overlay.closing .create-preview-modal { transform: scale(0.97) translateY(6px); opacity: 0; }
.create-preview-modal { background: var(--surface); border: 1px solid var(--hair); border-radius: var(--radius); width: 100%; max-width: 900px; max-height: 90vh; display: flex; flex-direction: column; overflow: hidden; animation: modalin var(--dur-slow) var(--ease-out); transition: transform 160ms var(--ease-in-out), opacity 160ms var(--ease-in-out); }
.create-preview-modal.create-preview-a4 { width: min(820px, calc(100vw - 48px)); height: calc(100vh - 48px); max-width: none; max-height: none; }
.create-preview-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 18px; border-bottom: 1px solid var(--hair); flex-shrink: 0; }
.create-preview-title { font-size: 14px; font-weight: 600; color: var(--text); }
.create-preview-frame { flex: 1; width: 100%; border: none; background: #fff; }
.create-media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.create-media-item { cursor: pointer; border: 2px solid transparent; border-radius: 8px; overflow: hidden; transition: border-color .15s; }
.create-media-item:hover { border-color: var(--ember); }

/* Brand workspace: colour shuffle + nav list */
.brand-shuffle-bar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--surface); border: 1px solid var(--hair); border-radius: var(--radius); margin-bottom: 18px; }
.brand-nav-list { display: flex; flex-direction: column; gap: 4px; }
.brand-nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: var(--surface); border: 1px solid var(--hair); border-radius: var(--radius-sm); font-size: 13px; }
.brand-nav-item .nav-depth { color: var(--dim); font-size: 11px; }

/* ===== TEXT STYLE TOOLBAR + RICH TEXT EDITOR ===== */

.style-toolbar { display: flex; align-items: center; gap: 4px; padding: 6px 8px; background: var(--surface-2); border: 1px solid var(--hair); border-radius: var(--radius-sm) var(--radius-sm) 0 0; border-bottom: none; }
.st-btn { min-width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center; background: transparent; border: 1px solid transparent; border-radius: 5px; color: var(--text); font-size: 13px; cursor: pointer; padding: 0 6px; transition: background .12s, border-color .12s; }
.st-btn:hover { background: var(--surface); border-color: var(--border); }
.st-btn:active { transform: scale(0.95); }
.st-sep { width: 1px; height: 18px; background: var(--hair); margin: 0 4px; }
.st-colors { display: flex; gap: 4px; }
.st-color { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--border); cursor: pointer; padding: 0; transition: transform .12s, border-color .12s; }
.st-color:hover { transform: scale(1.2); border-color: var(--text); }

.rt-editor { min-height: 80px; max-height: 200px; overflow-y: auto; padding: 10px 12px; background: var(--surface); border: 1px solid var(--hair); border-radius: 0 0 var(--radius-sm) var(--radius-sm); color: var(--text); font-size: 14px; line-height: 1.6; outline: none; font-family: inherit; }
.rt-editor:focus { border-color: var(--ember); }
.rt-editor:empty::before { content: attr(data-placeholder); color: var(--dim); pointer-events: none; }
.rt-editor span { font-size: inherit !important; }
.rt-editor [style*="font-size"] { font-size: inherit !important; }

/* Nav tier badges — premium, unintrusive */
.nav-badge { font-size: 9px; font-weight: 700; letter-spacing: .08em; padding: 2px 6px; border-radius: 4px; margin-left: auto; flex-shrink: 0; }
.nav-badge.tier-pro { background: linear-gradient(135deg, #8B5CF6, #6366F1); color: #fff; }
.nav-badge.tier-max { background: linear-gradient(135deg, #F59E0B, #F43F5E); color: #fff; }
.nav-panel:not(.collapsed) .nav-badge { margin-left: auto; }
.nav-panel.collapsed .nav-badge { display: none; }

/* Context menu style buttons */
.cm-style-row { display: flex; gap: 4px; padding: 6px 12px; }
.cm-style-btn { min-width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center; background: var(--surface); border: 1px solid var(--border); border-radius: 5px; color: var(--text); font-size: 13px; cursor: pointer; padding: 0 6px; }
.cm-style-btn:hover { background: var(--surface-2); border-color: var(--ember); }
.cm-color-row { display: flex; gap: 6px; padding: 4px 12px 8px; }
.cm-style-btn.cm-color { width: 22px !important; height: 22px !important; min-width: 22px !important; border-radius: 50% !important; padding: 0 !important; overflow: hidden; }

/* Context menu AI submenu */
.cm-submenu-trigger { position: relative; }
.cm-arrow { margin-left: auto; font-size: 14px; color: var(--dim); transition: transform .15s; }
.cm-submenu-trigger:hover .cm-arrow { transform: translateX(2px); color: var(--ember); }
.cm-submenu { display: none; position: absolute; left: 100%; top: 0; min-width: 180px; background: var(--surface); border: 1px solid var(--hair); border-radius: var(--radius-sm); box-shadow: 0 8px 24px rgba(0,0,0,.3); padding: 4px; z-index: 1600; }
.cm-submenu.open { display: block; }
.cm-submenu .cm-item { padding: 6px 12px; }
