/* Rubik + Fira Sans — match original cheb.media Setka fonts */
@import url('https://fonts.googleapis.com/css2?family=Rubik:wght@400;700&family=Fira+Sans:wght@400;700&display=swap');

/* ── DESIGN TOKENS ── */
:root {
  --bg:              #ffffff;
  --bg-subtle:       #f8fafc;
  --bg-muted:        #f1f5f9;
  --bg-hover:        #e8edf4;
  --border:          #e2e8f0;
  --border-strong:   #cbd5e1;
  --text:            #0f172a;
  --text-muted:      #64748b;
  --text-faint:      #94a3b8;
  --primary:         #2563eb;
  --primary-hover:   #1d4ed8;
  --primary-fg:      #ffffff;
  --danger:          #dc2626;
  --success:         #059669;

  --radius-sm:       4px;
  --radius:          6px;
  --radius-lg:       10px;
  --radius-xl:       16px;

  --shadow-sm:       0 1px 2px rgba(15,23,42,.06);
  --shadow:          0 1px 3px rgba(15,23,42,.1), 0 1px 2px rgba(15,23,42,.06);
  --shadow-md:       0 4px 6px rgba(15,23,42,.07), 0 2px 4px rgba(15,23,42,.06);
  --shadow-lg:       0 10px 15px rgba(15,23,42,.1), 0 4px 6px rgba(15,23,42,.05);

  --font-ui:         -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, system-ui, sans-serif;
  --font-mono:       'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
  --transition:      150ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── RESET ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; width: 100%; }

body {
  font-family: var(--font-ui);
  background: var(--bg-subtle);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── HEADER ── */
.header {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
  z-index: 10;
}

.header-top {
  display: flex;
  align-items: center;
  padding: 0 20px;
  height: 52px;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

.header-top .header-actions { margin-left: auto; }

.header-bottom {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 20px;
  height: 40px;
}

.hb-left  { display: flex; align-items: center; }
.hb-right { display: flex; align-items: center; justify-content: flex-end; }

/* ── BRAND ── */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.logo-text {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
}

.brand-sep {
  width: 1px;
  height: 16px;
  background: var(--border-strong);
}

.brand-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

/* ── DOCUMENT TITLE — mirrors cm-article h1 (Rubik, centered) ── */
.doc-title {
  display: block;
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: #1d1d1d;
  font-size: 44px;    /* 2.2 × 20px */
  font-weight: 700;
  font-family: 'Rubik', Arial, sans-serif;
  line-height: 1.15;
  text-align: center;
  letter-spacing: -0.02em;
  padding: 0 0 24px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.doc-title::placeholder { color: var(--text-faint); }

/* ── HEADER ACTIONS ── */
.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 12px;
  height: 34px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font-ui);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition);
  line-height: 1;
  text-decoration: none;
  touch-action: manipulation;
}

.btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { background: var(--bg-muted); color: var(--text); }
.btn-ghost.active { background: #dbeafe; color: var(--primary); }

.btn-outline {
  background: transparent;
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-outline:hover { background: var(--bg-muted); }

.btn-primary {
  background: var(--primary);
  color: var(--primary-fg);
  border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn-icon { width: 30px; height: 30px; padding: 0; }

.icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  stroke-width: 2;
}

/* ── VIEW SWITCHER ── */
.view-switcher {
  display: flex;
  align-items: center;
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px;
  gap: 1px;
}

.view-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  height: 26px;
  border-radius: calc(var(--radius) - 2px);
  border: none;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font-ui);
  cursor: pointer;
  white-space: nowrap;
  color: var(--text-muted);
  background: transparent;
  transition: background var(--transition), color var(--transition), box-shadow var(--transition);
  touch-action: manipulation;
}

.view-btn:hover:not(.active) {
  background: var(--bg-hover);
  color: var(--text);
}

.view-btn.active {
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.view-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

/* ── WORKSPACE ── */
.workspace {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

/* ── EDITOR PANE ── */
.editor-pane {
  flex: 1;
  overflow-y: auto;
  background: #dde3ea;
  padding: 40px 24px 80px;
  min-width: 0;
}

.editor-pane.hidden { display: none; }

/* A4-proportioned document card */
.doc-wrapper {
  max-width: 794px;
  margin: 0 auto;
  background: var(--bg);
  border-radius: var(--radius-lg);
  padding: 56px 72px 72px;
  box-shadow: var(--shadow-md);
  min-height: 860px;
}

#editorjs {
  max-width: 100%;
  min-height: 320px;
}

/* ── EditorJS OVERRIDES — typography mirrors article.css ── */
.ce-block__content,
.ce-toolbar__content { max-width: 100%; }

.codex-editor { color: #1a1a1a; }

/* Body text — Georgia 20px/30px — exact original Setka values */
.ce-paragraph {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 20px;
  line-height: 30px;
  color: #1d1d1d;
}

.ce-paragraph[data-placeholder]::before { color: var(--text-faint); }

/* Lists — match article */
.cdx-list,
.cdx-list__item {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 20px;
  line-height: 30px;
}

/* Headings — rendered as actual h1/h2/h3 tags by EditorJS Header plugin */
#editorjs h1 {
  font-family: 'Rubik', Arial, sans-serif;
  font-size: 44px;   /* 2.2 × 20px */
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
  letter-spacing: -0.02em;
  color: #1d1d1d;
  margin-bottom: 0.5em;
}

#editorjs h2 {
  font-family: 'Fira Sans', Arial, sans-serif;
  font-size: 29px;   /* 1.45 × 20px */
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.01em;
  color: #1d1d1d;
  margin-top: 1.5em;
  margin-bottom: 0.4em;
}

#editorjs h3 {
  font-family: 'Fira Sans', Arial, sans-serif;
  font-size: 23px;   /* 1.15 × 20px */
  font-weight: 700;
  line-height: 1.35;
  color: #1d1d1d;
  margin-top: 1.2em;
  margin-bottom: 0.3em;
}

.ce-header { color: #1d1d1d; font-weight: 700; }

.ce-toolbar__plus,
.ce-toolbar__settings-btn { color: var(--text-muted); border-radius: var(--radius-sm); }

.ce-toolbar__plus:hover,
.ce-toolbar__settings-btn:hover { background: var(--bg-muted); color: var(--text); }

.ce-toolbox {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}
.ce-toolbox__button { color: var(--text-muted); }
.ce-toolbox__button:hover { background: var(--bg-muted); color: var(--text); }

.ce-popover {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.ce-popover-item:hover { background: var(--bg-muted); }
.ce-popover-item__title { color: var(--text); }
.ce-popover-item__icon { background: var(--bg-muted); border-radius: var(--radius-sm); }

.ce-inline-toolbar {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}
.ce-inline-tool { color: var(--text-muted); }
.ce-inline-tool:hover { background: var(--bg-muted); color: var(--text); }
.ce-inline-tool--active { color: var(--primary); }

.image-tool__image-picture { border-radius: var(--radius); }
.image-tool__caption { color: var(--text-muted); border-top: 1px solid var(--border); }
.image-tool__caption[contenteditable="true"]:before { color: var(--text-faint); }

.cdx-button {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius);
  font-family: var(--font-ui);
  transition: background var(--transition), border-color var(--transition);
}
.cdx-button:hover { background: var(--bg-muted); border-color: var(--border-strong); }

/* ── CUSTOM BLOCKS — match article.css output ── */
.ce-block__callout {
  background: #f6f6f6; /* exact match: --cm-callout-bg */
  border: none;
  border-radius: 10px;  /* exact match: cm-callout border-radius */
  padding: 24px 32px;   /* exact match: cm-callout padding */
}

.ce-block__grid {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
}

.grid-cols { display: grid; gap: 12px; }
.grid--2col .grid-cols { grid-template-columns: 1fr 1fr; }
.grid--3col .grid-cols { grid-template-columns: 1fr 1fr 1fr; }

.ce-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-family: var(--font-ui);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.ce-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.ce-input::placeholder { color: var(--text-faint); }
.ce-input--caption { font-size: 11px; margin-top: 6px; }

.ce-image-preview {
  width: 100%;
  aspect-ratio: 4 / 3;  /* match cm-2col/cm-3col img */
  height: auto;
  object-fit: cover;
  border-radius: var(--radius-sm);
  margin: 6px 0;
  display: none;
  border: 1px solid var(--border);
}

.ce-grid-slot { display: flex; flex-direction: column; }

.ce-callout-input {
  width: 100%;
  min-height: 60px;
  background: transparent;
  border: none;
  color: #1d1d1d;
  font-size: 22px;  /* 1.1 × 20px */
  font-style: italic;
  line-height: 1.5;
  outline: none;
  resize: none;
  font-family: Georgia, 'Times New Roman', serif;
}
.ce-callout-input::placeholder { color: #aaa; }

.block-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-faint);
  margin-bottom: 8px;
}

/* ── PREVIEW PANE ── */
.preview-pane {
  flex: 1;
  overflow: hidden;
  background: #dde4ec;
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-left: 1px solid var(--border);
}

.preview-pane.hidden { display: none; }

.preview-bar {
  display: flex;
  align-items: center;
  height: 34px;
  padding: 0 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.preview-bar-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.preview-frame {
  flex: 1;
  width: 100%;
  min-height: 0;
  border: none;
  background: var(--bg);
  display: block;
}

/* Mobile mode */
.preview-pane.mobile-mode {
  background: #1e293b;
  align-items: center;
  justify-content: flex-start;
  overflow-y: auto;
  padding: 24px;
}

.preview-pane.mobile-mode .preview-bar { display: none; }

.preview-pane.mobile-mode .preview-frame {
  flex: none;
  width: 375px;
  height: 812px;
  min-height: 812px;
  border-radius: 44px;
  box-shadow: 0 0 0 10px #0f172a, 0 0 0 11px #334155, 0 24px 60px rgba(0,0,0,.6);
  display: block;
  margin: 0 auto;
}

/* Split mode */
.workspace.split .editor-pane,
.workspace.split .preview-pane { flex: 1; }

/* ── MODAL ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.45);
  backdrop-filter: blur(3px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay.open { display: flex; }

.modal-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 600px;
  max-width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  flex-shrink: 0;
}

.modal-header > span { flex: 1; }

.modal-body {
  padding: 16px 18px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
  min-height: 0;
}

#md-textarea {
  flex: 1;
  min-height: 240px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.65;
  padding: 12px;
  outline: none;
  resize: vertical;
  transition: border-color var(--transition), box-shadow var(--transition);
}

#md-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

#md-textarea::placeholder { color: var(--text-faint); }

.modal-hint {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── TOAST ── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 200ms ease, transform 200ms ease;
  z-index: 200;
  max-width: 320px;
  box-shadow: var(--shadow-md);
}

.toast.visible { opacity: 1; transform: translateY(0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0ms !important; }
}
