/**
 * Email Template Builder — Shared UI Stylesheet (Review round 2)
 * CertifID EMD Tools
 *
 * Round-2 refinements (all five options share these):
 *   - Template chooser is a custom DROPDOWN (matches the PDF builder) so more
 *     templates can be added later.
 *   - No "new asset type" badge.
 *   - Formatted + Plain text are BOTH available (toggle / both shown), framed by
 *     each layout option.
 *   - Copy actions live OUTSIDE the document sheet (toolbars / rails / headers).
 *   - "Sign-off" is an editable detail (set once), not a per-recipient placeholder.
 *   - "Recipient name" is an optional field that falls back to the [placeholder].
 *
 * Layout-specific arrangement lives in each option's own <style> block.
 *
 * Dependencies: Inter (Google Fonts), Thicccboi (@font-face in HTML), Tabler Icons.
 */


/* ── 1. Design Tokens (identical to the Hub builders) ── */
:root {
  --brand-h: 216; --brand-s: 79%; --brand-l: 48%;

  --c-primary:       hsl(var(--brand-h), var(--brand-s), var(--brand-l));
  --c-primary-hover: hsl(var(--brand-h), var(--brand-s), 40%);
  --c-primary-light: hsl(var(--brand-h), 50%, 72%);
  --c-primary-wash:  hsl(var(--brand-h), 50%, 96%);

  --c-focus-border:  hsl(var(--brand-h), 50%, 82%);
  --c-focus-ring:    hsl(var(--brand-h), var(--brand-s), 94%);
  --c-focus-ring-sm: hsl(var(--brand-h), var(--brand-s), 92%);

  --t-dark:   hsl(var(--brand-h), 28%, 16%);
  --t-medium: hsl(var(--brand-h), 7%, 34%);
  --t-light:  hsl(var(--brand-h), 7%, 46%);

  --s-white:  #ffffff;
  --s-light:  hsl(var(--brand-h), 12%, 97%);
  --s-border: hsl(var(--brand-h), 10%, 91%);

  --doc-text:  #1f2733;
  --doc-muted: #5b6573;
  --doc-rule:  #e7ebf0;

  --toast-bg: hsl(145, 55%, 93%); --toast-text: hsl(145, 50%, 30%);
  --toast-border: hsl(145, 40%, 82%); --toast-icon: hsl(145, 50%, 36%);

  --font-heading: 'Thicccboi', system-ui, sans-serif;
  --font-body:    'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono:    'SF Mono', 'Fira Code', ui-monospace, monospace;

  --r-sm: 8px; --r-md: 12px; --r-lg: 16px;
  --panel-w: 360px; --panel-pad: 32px;

  --shadow-panel: 8px 0 25px rgba(0,0,0,0.05);
  --shadow-card:  0 4px 20px rgba(0,0,0,0.06);
  --shadow-toast: 0 4px 16px rgba(0,0,0,0.08);

  --ease-fast: 0.15s ease; --ease-base: 0.2s ease;
}


/* ── 2. Reset & Base ── */
*,*::before,*::after { margin:0; padding:0; box-sizing:border-box; }
body {
  font-family: var(--font-body);
  background: var(--s-white);
  min-height: 100vh;
  display: flex;
  overflow: hidden;
  color: var(--t-dark);
  -webkit-font-smoothing: antialiased;
}


/* ── 3. Control Panel (Sidebar) ── */
.control-panel {
  width: var(--panel-w);
  height: 100vh;
  background: var(--s-white);
  border-right: 1px solid var(--s-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0; top: 0; z-index: 100;
  box-shadow: var(--shadow-panel);
}
.panel-scrollable {
  flex: 1; overflow-y: auto; overflow-x: hidden; min-height: 0;
  scrollbar-width: none; -ms-overflow-style: none;
}
.panel-scrollable::-webkit-scrollbar { display: none; }
.panel-content { padding: 0 var(--panel-pad) var(--panel-pad); }

.panel-header {
  padding: 36px var(--panel-pad) var(--panel-pad);
  border-bottom: 1px solid var(--s-border);
  animation: builderSlideDown 0.12s ease-out; animation-fill-mode: backwards;
}
.panel-back-link {
  display: inline-flex; align-items: center; gap: 6px; margin-bottom: 18px;
  color: var(--c-primary); font-size: 12px; font-weight: 600; text-decoration: none;
}
.panel-back-link:hover { color: var(--c-primary-hover); }
.logo-mark { width: 32px; height: 32px; margin-bottom: 16px; }
.logo-mark img { width: 100%; height: 100%; }
.panel-title { font-family: var(--font-heading); font-size: 15px; font-weight: 600; color: var(--t-dark); margin-bottom: 4px; }
.panel-subtitle { font-size: 13px; color: var(--t-light); font-weight: 400; letter-spacing: -0.01em; }


/* ── 4. Sections & Form Fields ── */
.section {
  padding: 24px 0; border-bottom: 1px solid var(--s-border);
  animation: builderSlideDown 0.22s ease-out; animation-fill-mode: backwards;
}
.section:last-child { border-bottom: none; }
.section:nth-child(1){animation-delay:.10s}.section:nth-child(2){animation-delay:.15s}
.section:nth-child(3){animation-delay:.20s}.section:nth-child(4){animation-delay:.25s}

.section-label {
  font-size: 11px; font-weight: 600; color: var(--t-light);
  text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 16px;
}
.form-field { margin-bottom: 16px; }
.form-field:last-child { margin-bottom: 0; }
.field-label { display:block; font-size:13px; font-weight:500; color: var(--t-medium); margin-bottom: 8px; }
.field-label .req { color: var(--c-primary); margin-left: 2px; }
.field-label .opt { color: var(--t-light); font-weight: 400; margin-left: 4px; }
.field-hint { font-size: 11.5px; color: var(--t-light); margin-top: 7px; line-height: 1.5; }

.input-affix { position: relative; display: flex; align-items: center; }
.input-affix > i { position: absolute; left: 12px; font-size: 16px; color: var(--t-light); pointer-events: none; }
.input-affix .form-input { padding-left: 36px; }

.form-input {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--s-border); border-radius: var(--r-sm);
  font-size: 14px; font-family: inherit; color: var(--t-dark);
  background: var(--s-white);
  transition: border-color var(--ease-base), box-shadow var(--ease-base);
}
.form-input:hover { border-color: var(--c-primary-light); }
.form-input:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px var(--c-focus-ring-sm); }
.form-input::placeholder { color: hsl(var(--brand-h), 8%, 65%); }


/* ── 5. Custom Select (Template dropdown — mirrors the PDF builder) ── */
.custom-select { position: relative; }
.custom-select-trigger {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--s-border); border-radius: var(--r-sm);
  background: var(--s-white);
  font-family: inherit; font-size: 14px; font-weight: 500; color: var(--t-dark);
  cursor: pointer; transition: border-color .2s, box-shadow .2s;
}
.custom-select-trigger:hover { border-color: var(--c-focus-border); }
.custom-select.open .custom-select-trigger { border-color: var(--c-focus-border); box-shadow: 0 0 0 3px var(--c-focus-ring); }
.custom-select-icon {
  display: flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 6px;
  background: var(--c-primary-wash); color: var(--c-primary);
  font-size: 14px; flex-shrink: 0;
}
.custom-select-text { flex: 1; text-align: left; }
.custom-select-arrow { font-size: 16px; color: var(--t-light); transition: transform .2s; }
.custom-select.open .custom-select-arrow { transform: rotate(180deg); }
.custom-select-options {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--s-white); border: 1px solid var(--s-border); border-radius: var(--r-sm);
  box-shadow: 0 8px 24px rgba(0,0,0,0.08); z-index: 200; padding: 4px;
  /* Animate BOTH open and close (visibility + opacity + transform). */
  opacity: 0; visibility: hidden;
  transform: translateY(-6px) scale(0.98); transform-origin: top center;
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
  pointer-events: none;
}
.custom-select.open .custom-select-options {
  opacity: 1; visibility: visible; transform: translateY(0) scale(1); pointer-events: auto;
}
.custom-select-option {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px;
  border-radius: 6px; cursor: pointer; font-size: 14px; color: var(--t-medium);
  transition: background .12s;
}
.custom-select-option i:first-child { font-size: 16px; color: var(--t-light); width: 20px; text-align: center; }
.custom-select-option span { flex: 1; text-align: left; }
.custom-select-check { font-size: 16px; color: var(--c-primary); opacity: 0; }
.custom-select-option.selected .custom-select-check { opacity: 1; }
.custom-select-option.selected { color: var(--c-primary); background: var(--c-primary-wash); }
.custom-select-option.selected i:first-child { color: var(--c-primary); }
.custom-select-option:hover:not(.selected) { background: var(--s-light); }


/* ── 6. Action Footer & Copy Button ── */
.action-footer {
  padding: var(--panel-pad); border-top: 1px solid var(--s-border); flex-shrink: 0;
  animation: builderSlideDown 0.3s ease-out; animation-delay: 0.18s; animation-fill-mode: backwards;
}
.copy-main {
  width: 100%; padding: 13px 20px;
  background: var(--c-primary); color: #fff; border: none; border-radius: var(--r-sm);
  font-family: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: background var(--ease-base), transform var(--ease-fast);
}
.copy-main:hover { background: var(--c-primary-hover); }
.copy-main:active { transform: translateY(1px); }
.copy-main i { font-size: 17px; }
.footer-hint { font-size: 11.5px; color: var(--t-light); text-align: center; margin-top: 12px; line-height: 1.5; }


/* ── 7. Main Content & Preview Area (base) ── */
.main-content { flex: 1; margin-left: var(--panel-w); display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.preview-area {
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column; align-items: center;
  background: var(--s-light); padding: 44px 40px 72px;
  animation: builderSlideDown 0.5s ease-out; animation-fill-mode: backwards;
}
@keyframes builderSlideDown { 0% { opacity: 0; transform: translateY(-10px); } 100% { opacity: 1; transform: translateY(0); } }
@keyframes docFade { 0% { opacity: 0; transform: translateY(8px); } 100% { opacity: 1; transform: translateY(0); } }


/* ── 8. Shared atoms: toggle, copy buttons, sheets, block headers ── */

/* Format toggle (Formatted / Plain) */
.seg { display: inline-flex; gap: 3px; padding: 4px; background: var(--s-light); border: 1px solid var(--s-border); border-radius: 10px; }
.seg-btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 8px 15px;
  border: none; border-radius: 7px; background: none;
  font-family: inherit; font-size: 13px; font-weight: 600; color: var(--t-light);
  cursor: pointer; transition: all var(--ease-fast);
}
.seg-btn:hover { color: var(--t-medium); }
.seg-btn.active { background: #fff; color: var(--c-primary); box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.seg-btn i { font-size: 15px; }

/* Copy action buttons (used OUTSIDE the sheet) */
.act-btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px;
  border: 1px solid var(--s-border); border-radius: var(--r-sm);
  background: var(--s-white); color: var(--t-dark);
  font-family: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: all var(--ease-fast); white-space: nowrap;
}
.act-btn:hover { border-color: var(--c-primary); color: var(--c-primary); background: var(--c-primary-wash); }
.act-btn i { font-size: 16px; color: var(--c-primary); }
.act-btn--primary { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }
.act-btn--primary:hover { background: var(--c-primary-hover); color: #fff; }
.act-btn--primary i { color: #fff; }
.act-btn--sm { padding: 8px 13px; font-size: 12.5px; }

/* Block header strip (label left, copy right) — lives ABOVE a sheet */
.blk-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.blk-head-label { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--t-light); }
.blk-head-label i { color: var(--c-primary); font-size: 15px; }

/* Top toolbar */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; width: 100%; flex-wrap: wrap; }
.toolbar-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* The text-only document sheet (formatted) */
.doc-sheet {
  background: var(--s-white); border: 1px solid var(--s-border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-card);
  padding: 40px 44px;
}
.doc-sheet .subject-text { font-size: 18px; }
.doc-divider { height: 1px; background: var(--doc-rule); margin: 20px 0 24px; }

/* The text-only plain block */
.plain-block {
  font-family: var(--font-mono); font-size: 12.5px; line-height: 1.7; color: var(--doc-text);
  white-space: pre-wrap; word-wrap: break-word;
  background: var(--s-white); border: 1px solid var(--s-border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-card);
  padding: 28px 30px; margin: 0;
}


/* ── 9. Email Document Typography ── */
.email-doc { font-family: var(--font-body); color: var(--doc-text); font-size: 15px; line-height: 1.65; animation: docFade 0.3s ease-out; }
.email-doc p { margin: 0 0 16px; }
.email-doc p:last-child { margin-bottom: 0; }
.email-doc strong { font-weight: 600; color: var(--doc-text); }
.email-doc ul { margin: 0 0 16px; padding-left: 22px; list-style: none; }
.email-doc li { position: relative; margin-bottom: 7px; padding-left: 4px; }
.email-doc li::before { content: ""; position: absolute; left: -14px; top: 0.62em; width: 5px; height: 5px; border-radius: 50%; background: var(--c-primary); }

.subject-eyebrow { font-size: 11px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; color: var(--t-light); margin-bottom: 6px; }
.subject-text { font-family: var(--font-heading); font-weight: 600; color: var(--t-dark); font-size: 18px; line-height: 1.4; }

/* Variable tokens (highlighted ONLY in the on-screen preview) */
.tok { border-radius: 4px; padding: 0 3px; font-weight: 600; white-space: nowrap; transition: background var(--ease-fast); }
.tok-var { background: var(--c-primary-wash); color: var(--c-primary-hover); box-shadow: inset 0 0 0 1px hsl(var(--brand-h),60%,88%); }
.tok-var.flash { background: hsl(var(--brand-h),70%,86%); }
.tok-ph { color: var(--doc-muted); font-weight: 600; background: repeating-linear-gradient(-45deg, transparent, transparent 4px, hsl(var(--brand-h),10%,93%) 4px, hsl(var(--brand-h),10%,93%) 5px); box-shadow: inset 0 -1px 0 0 hsl(var(--brand-h),12%,82%); }

.tok-legend { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 4px; }
.tok-legend-item { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--t-medium); }
.tok-swatch { width: 26px; height: 16px; border-radius: 4px; flex-shrink: 0; }
.tok-swatch--var { background: var(--c-primary-wash); box-shadow: inset 0 0 0 1px hsl(var(--brand-h),60%,88%); }
.tok-swatch--ph  { background: repeating-linear-gradient(-45deg,#fff,#fff 4px, hsl(var(--brand-h),10%,93%) 4px, hsl(var(--brand-h),10%,93%) 5px); box-shadow: inset 0 0 0 1px hsl(var(--brand-h),12%,86%); }


/* ── 10. Toast ── */
.toast {
  position: fixed; bottom: 28px; right: 28px;
  background: var(--toast-bg); color: var(--toast-text);
  padding: 12px 20px; border-radius: var(--r-sm); border: 1px solid var(--toast-border);
  font-size: 13px; font-weight: 500; box-shadow: var(--shadow-toast);
  display: flex; align-items: center; gap: 8px;
  opacity: 0; transform: translateY(12px); transition: opacity .25s, transform .25s;
  pointer-events: none; z-index: 9999;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast i { font-size: 17px; color: var(--toast-icon); }


/* ── 11. Responsive ── */
@media (max-width: 1024px) {
  :root { --panel-w: 300px; --panel-pad: 24px; }
  .panel-header { padding: 28px var(--panel-pad) 24px; }
  .preview-area { padding: 32px 24px 64px; }
}
@media (max-width: 600px) {
  body { flex-direction: column; overflow: auto; }
  .control-panel { position: relative; width: 100%; height: auto; box-shadow: none; border-right: none; border-bottom: 1px solid var(--s-border); }
  .panel-scrollable { overflow-y: visible; }
  .main-content { margin-left: 0; height: auto; overflow: visible; }
  .preview-area { padding: 24px 16px 56px; overflow: visible; }
  .toast { left: 16px; right: 16px; bottom: 16px; justify-content: center; }
}
