/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Light theme — dashboard-style chrome */
:root {
  --color-bg:        #f2f4f7;
  --color-surface:   #ffffff;
  --color-surface2:  #f8f9fb;
  --color-border:    #e0e4eb;
  --color-primary:   #c41230;
  --color-primary-h: #a50f28;
  --color-accent:    #d4880a;
  --color-text:      #1a1f2e;
  --color-text-muted:#7a859a;
  --color-success:   #16a34a;
  --color-danger:    #dc2626;
  --radius-sm:       6px;
  --radius-md:       10px;
  --radius-lg:       12px;
  --shadow:          0 1px 4px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --shadow-sm:       0 1px 3px rgba(0,0,0,.07);
  --transition:      0.15s ease;
  --font-sans:       'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono:       'Cascadia Code', 'Fira Code', 'Consolas', monospace;
}

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  line-height: 1.6;
}

/* ============================================================
   LAYOUT
   ============================================================ */
.app-wrapper {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px 20px 0;
}

/* ============================================================
   DESIGN SETTINGS BAR
   ============================================================ */
.design-bar {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  margin-bottom: 20px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.design-bar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: #fff;
  border-bottom: 1px solid var(--color-border);
  border-left: 3px solid var(--color-primary);
}

.dbh-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dbh-icon {
  font-size: 1.25rem;
  color: var(--color-primary);
  flex-shrink: 0;
  line-height: 1;
  filter: drop-shadow(0 0 6px rgba(196,18,48,.4));
}

.dbh-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.design-bar-title {
  font-size: .88rem;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: .2px;
  line-height: 1.2;
}

.design-bar-hint {
  font-size: .7rem;
  color: var(--color-text-muted);
  line-height: 1;
}

/* Preset strip */
.preset-strip {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 9px 18px;
  background: var(--color-surface2);
  border-bottom: 1px solid var(--color-border);
  overflow-x: auto;
  flex-wrap: wrap;
  row-gap: 7px;
}

.preset-group {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.pgrp-label {
  font-size: .62rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--color-primary);
  white-space: nowrap;
  padding-right: 3px;
}

.pgrp-sep {
  width: 1px;
  height: 22px;
  background: var(--color-border);
  margin: 0 10px;
  flex-shrink: 0;
  align-self: center;
}

.preset-pill {
  padding: 4px 12px;
  font-size: .76rem;
  font-weight: 600;
  background: #fff;
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  border-radius: 20px;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition),
              border-color var(--transition), box-shadow var(--transition);
}

.preset-pill:hover {
  background: #fef2f3;
  color: var(--color-primary);
  border-color: var(--color-primary);
}

.preset-pill.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(196,18,48,.25);
}

.btn-sm { padding: 5px 12px; font-size: .78rem; }

/* Controls — tag picker + variant cards */
.design-controls {
  display: flex;
  flex-direction: column;
}

.tag-picker {
  display: flex;
  gap: 6px;
  padding: 12px 18px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface2);
}

.tag-btn {
  padding: 5px 13px;
  font-size: .78rem;
  font-weight: 600;
  font-family: var(--font-mono);
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  letter-spacing: .2px;
}

.tag-btn:hover { background: #fef2f3; color: var(--color-primary); border-color: var(--color-primary); }

.tag-btn.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

/* Variant cards */
.variant-cards {
  display: flex;
  gap: 10px;
  padding: 14px 18px;
  flex-wrap: wrap;
  min-height: 130px;
  align-items: stretch;
  background: var(--color-surface2);
}

.variant-card {
  flex: 1 1 155px;
  max-width: 210px;
  background: #fff;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
  user-select: none;
  display: flex;
  flex-direction: column;
}

.variant-card:hover {
  border-color: var(--color-primary);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(196,18,48,.14);
}

.variant-card.active {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(196,18,48,.15);
}

.variant-card.active .card-footer {
  background: var(--color-primary);
}

.variant-card.active .card-name,
.variant-card.active .card-meta {
  color: #fff;
}

/* Toggle card (Drop Cap) — accent border instead of solid active fill */
.variant-card.toggle-card {
  border-style: dashed;
}
.variant-card.toggle-card.active {
  border-style: solid;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(212,136,10,.15);
}
.variant-card.toggle-card.active .card-footer {
  background: var(--color-accent);
}

.card-preview {
  background: #fafafa;
  padding: 12px 14px;
  min-height: 78px;
  flex: 1;
  display: flex;
  align-items: center;
  overflow: hidden;
}

.card-footer {
  padding: 7px 10px 8px;
  background: var(--color-surface2);
  border-top: 1px solid var(--color-border);
  transition: background var(--transition);
}

.card-name {
  font-size: .76rem;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.2;
  transition: color var(--transition);
}

.card-meta {
  font-size: .67rem;
  color: var(--color-text-muted);
  margin-top: 2px;
  transition: color var(--transition);
}

.app-main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}

@media (max-width: 860px) {
  .app-main { grid-template-columns: 1fr; }
}

/* ============================================================
   PANEL
   ============================================================ */
.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 18px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  border-left: 3px solid var(--color-primary);
}

.panel-header h2 {
  font-size: .82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--color-text-muted);
}

.output-actions {
  display: flex;
  gap: 8px;
}

/* ============================================================
   QUILL RICH TEXT EDITOR
   ============================================================ */

/* Toolbar */
#quillToolbar.ql-toolbar.ql-snow {
  border: none;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface2);
  padding: 8px 12px;
  flex-wrap: wrap;
  gap: 2px;
  font-family: inherit;
}

#quillToolbar .ql-formats {
  margin-right: 6px;
}

/* Toolbar buttons / selects */
#quillToolbar .ql-snow .ql-stroke { stroke: var(--color-text-muted); }
#quillToolbar .ql-snow .ql-fill   { fill:   var(--color-text-muted); }
#quillToolbar .ql-snow.ql-toolbar button:hover .ql-stroke,
.ql-snow.ql-toolbar button.ql-active .ql-stroke { stroke: var(--color-primary); }
#quillToolbar .ql-snow.ql-toolbar button:hover .ql-fill,
.ql-snow.ql-toolbar button.ql-active .ql-fill   { fill: var(--color-primary); }

.ql-snow.ql-toolbar button         { padding: 4px 5px; border-radius: 4px; }
.ql-snow.ql-toolbar button:hover   { background: #fef2f3; }
.ql-snow.ql-toolbar button.ql-active { background: #fef2f3; }

.ql-snow .ql-picker-label          { color: var(--color-text-muted); border-color: var(--color-border); border-radius: 4px; }
.ql-snow .ql-picker-label:hover    { color: var(--color-primary); }
.ql-snow .ql-picker-options        { border-color: var(--color-border); border-radius: var(--radius); box-shadow: var(--shadow); background: var(--color-surface); }
.ql-snow .ql-picker-item:hover     { color: var(--color-primary); }

/* Editor body */
.ql-container.ql-snow {
  border: none;
  font-family: inherit;
  font-size: .9rem;
}

.ql-editor {
  min-height: 320px;
  max-height: 460px;
  overflow-y: auto;
  padding: 16px 18px;
  line-height: 1.7;
  color: var(--color-text);
  background: #fff;
  font-size: .9rem;
}

.ql-editor.ql-blank::before {
  color: #bcc4d0;
  font-style: italic;
  left: 18px;
}

.ql-editor:focus {
  box-shadow: inset 0 0 0 2px rgba(196,18,48,.18);
}

/* Focus ring on the container */
.ql-container.ql-snow:focus-within {
  box-shadow: inset 0 0 0 2px rgba(196,18,48,.18);
}

/* Quill tooltip (link editor) */
.ql-snow .ql-tooltip {
  border-color: var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  color: var(--color-text);
  background: var(--color-surface);
  font-family: inherit;
}
.ql-snow .ql-tooltip input[type=text] {
  border-color: var(--color-border);
  border-radius: 4px;
  color: var(--color-text);
  outline: none;
}
.ql-snow .ql-tooltip input[type=text]:focus {
  border-color: var(--color-primary);
}
.ql-snow .ql-tooltip a.ql-action::after  { color: var(--color-primary); }
.ql-snow .ql-tooltip a.ql-remove::before { color: #888; }

/* Scrollbar in editor */
.ql-editor::-webkit-scrollbar               { width: 6px; }
.ql-editor::-webkit-scrollbar-track         { background: transparent; }
.ql-editor::-webkit-scrollbar-thumb         { background: #d0d5de; border-radius: 8px; }

/* ============================================================
   ACTION BAR
   ============================================================ */
.action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 18px;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface2);
}

/* ============================================================
   MODE TOGGLE
   ============================================================ */
.mode-label {
  font-size: .8rem;
  color: var(--color-text-muted);
  margin-right: 8px;
  white-space: nowrap;
}

.mode-toggle {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.toggle-group {
  display: flex;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.toggle-btn {
  padding: 6px 14px;
  font-size: .82rem;
  font-weight: 500;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  display: flex;
  align-items: center;
  gap: 5px;
}

.toggle-btn:hover { background: #fef2f3; color: var(--color-primary); }

.toggle-btn.active {
  background: var(--color-primary);
  color: #fff;
}

.toggle-icon { font-size: .7rem; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  white-space: nowrap;
}

.btn:active { transform: scale(.97); }

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(196,18,48,.25);
}
.btn-primary:hover {
  background: var(--color-primary-h);
  box-shadow: 0 4px 14px rgba(196,18,48,.35);
}

.btn-secondary {
  background: var(--color-accent);
  color: #fff;
}
.btn-secondary:hover { filter: brightness(1.08); }

.btn-ghost {
  background: #fff;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}
.btn-ghost:hover { background: #fef2f3; color: var(--color-primary); border-color: var(--color-primary); }

/* ============================================================
   TABS
   ============================================================ */
.tab-bar {
  display: flex;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface2);
}

.tab {
  padding: 10px 20px;
  font-size: .85rem;
  font-weight: 500;
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition);
}

.tab:hover { color: var(--color-text); }
.tab.active { color: var(--color-primary); border-bottom-color: var(--color-primary); font-weight: 600; }

.tab-content { display: none; position: relative; }
.tab-content.active { display: block; }

/* ============================================================
   PREVIEW
   ============================================================ */
.preview-badge {
  position: absolute;
  top: 10px;
  right: 14px;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  padding: 3px 8px;
  border-radius: 20px;
  background: var(--color-primary);
  color: #fff;
  z-index: 1;
}

.preview-area {
  min-height: 380px;
  max-height: 520px;
  overflow-y: auto;
  padding: 24px 22px;
  font-size: .92rem;
  line-height: 1.7;
  color: #333;
  background: #fff;
}

.placeholder-text {
  color: #aaa;
  font-style: italic;
  font-size: .9rem;
}

/* preview typography reset — matches inline CSS output */
.preview-area h1 { font-size: 28px; margin-bottom: 14px; color: #1a1a1a; font-weight: 700; }
.preview-area h2 { font-size: 22px; margin-bottom: 10px; color: #1a1a1a; font-weight: 700; }
.preview-area h3 { font-size: 18px; margin-bottom: 8px; color: #1a1a1a; font-weight: 600; }
.preview-area h4 { font-size: 16px; margin-bottom: 8px; color: #1a1a1a; font-weight: 600; }
.preview-area p  { margin-bottom: 12px; color: #333; }

/* ── Card group label (spans full width inside variant-cards grid) ───────── */
.card-group-label {
  grid-column: 1 / -1;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--color-primary);
  padding: 4px 2px 2px;
  border-bottom: 1.5px solid var(--color-border);
  margin-top: 6px;
}
.card-group-label:first-child {
  margin-top: 0;
}

/* Alignment cards are narrower — show 4 per row when in p section */
.variant-card.align-card {
  min-width: 0;
}

/* ── Image placeholder (preview mode — no heavy image loads) ────────────── */
.img-placeholder {
  background: var(--color-surface2);
  border: 2px dashed var(--color-border);
  border-radius: 8px;
  padding: 14px 18px;
  margin: 16px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  min-height: 72px;
  justify-content: center;
}
.img-ph-icon {
  font-size: 26px;
  line-height: 1;
  opacity: .55;
}
.img-ph-label {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: .6px;
}
.img-ph-input {
  width: 100%;
  max-width: 420px;
  padding: 6px 10px;
  border: 1.5px solid var(--color-border);
  border-radius: 5px;
  font-size: 12px;
  color: var(--color-text);
  background: var(--color-surface);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.img-ph-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(196,18,48,.1);
}
.img-ph-input::placeholder {
  color: var(--color-text-muted);
  font-style: italic;
}
.preview-area ul,
.preview-area ol { margin: 0 0 12px 22px; }
.preview-area li { margin-bottom: 6px; }
.preview-area a  { color: #c41230; text-decoration: underline; }
.preview-area blockquote {
  border-left: 4px solid #c41230;
  padding: 8px 16px;
  margin: 0 0 12px;
  color: #555;
  background: #fff0f2;
  border-radius: 0 4px 4px 0;
}
.preview-area strong { font-weight: 700; }
.preview-area em     { font-style: italic; }

/* ============================================================
   CODE OUTPUT
   ============================================================ */
.code-area {
  min-height: 380px;
  max-height: 520px;
  overflow: auto;
  padding: 18px 18px;
  background: #f8f9fb;
  border: none;
  margin: 0;
}

.code-area code {
  font-family: var(--font-mono);
  font-size: .8rem;
  line-height: 1.65;
  color: #374151;
  white-space: pre-wrap;
  word-break: break-all;
  display: block;
}

/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1a1f2e;
  color: #fff;
  border: none;
  padding: 10px 22px;
  border-radius: 50px;
  font-size: .85rem;
  font-weight: 500;
  box-shadow: 0 4px 20px rgba(0,0,0,.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 9999;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============================================================
   SCROLLBAR
   ============================================================ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d0d5de; border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: #adb5c7; }

/* ============================================================
   EMBED MODE — full-height tool, no page scroll
   ============================================================ */
html.fmt-embed,
html.fmt-embed body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

html.fmt-embed .app-wrapper {
  height: 100%;
  max-width: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Design bar: fixed height, no radius, flush to edges */
html.fmt-embed .design-bar {
  flex: 0 0 auto;
  border-radius: 0;
  margin-bottom: 0;
  border-left: none;
  border-right: none;
  border-top: none;
}

/* Main grid: fill remaining height, panels stretch to match */
html.fmt-embed .app-main {
  flex: 1 1 0%;
  min-height: 0;
  overflow: hidden;
  align-items: stretch;
  padding: 0;
  gap: 0;
  border-top: 1px solid var(--color-border);
}

html.fmt-embed .app-main > .panel + .panel {
  border-left: 1px solid var(--color-border);
}

@media (max-width: 860px) {
  html.fmt-embed .app-main {
    overflow-y: auto;
    align-items: start;
    gap: 0;
  }
  html.fmt-embed .app-main > .panel + .panel {
    border-left: none;
    border-top: 1px solid var(--color-border);
  }
}

/* Panels fill grid cell height */
html.fmt-embed .panel {
  height: 100%;
  min-height: 0;
  overflow: hidden;
  border-radius: 0;
  border: none;
  box-shadow: none;
  display: flex;
  flex-direction: column;
}

/* Input panel: quill editor grows to fill */
html.fmt-embed .ql-container.ql-snow {
  flex: 1 1 0%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

html.fmt-embed .ql-editor {
  flex: 1 1 0%;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
}

/* Output panel: active tab content fills height */
html.fmt-embed .tab-content {
  display: none;
  flex: 1 1 0%;
  min-height: 0;
  flex-direction: column;
}

html.fmt-embed .tab-content.active {
  display: flex;
}

html.fmt-embed .preview-area {
  flex: 1 1 0%;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
}

html.fmt-embed .code-area {
  flex: 1 1 0%;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
}
