/* ==========================================================================
   FaultSettle - Embed Mode & Embed Widget Stylesheet
   Zero-FOUC Embed Display & Accessible Embed Modal
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Zero-FOUC Embed Mode (?embed=true)
   Hides outer chrome, headers, footers, content guides, FAQs, and embed button.
   Keeps ONLY the core two-column calculator interface.
   -------------------------------------------------------------------------- */
html.fs-embed-mode {
  margin: 0 !important;
  padding: 0 !important;
  background: transparent !important;
  min-height: auto !important;
  height: auto !important;
  width: 100% !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;
}

html.fs-embed-mode body {
  margin: 0 !important;
  padding: 0 !important;
  background: transparent !important;
  min-height: auto !important;
  height: auto !important;
  width: 100% !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
}

/* Strict element suppression in embed mode */
html.fs-embed-mode .site-header,
html.fs-embed-mode .hero-header,
html.fs-embed-mode .content-section,
html.fs-embed-mode .site-footer,
html.fs-embed-mode .fs-hero-embed-wrap,
html.fs-embed-mode .fs-embed-trigger-btn,
html.fs-embed-mode #fs-embed-modal,
html.fs-embed-mode .anchor-target {
  display: none !important;
}

/* Layout resets for iframe container */
html.fs-embed-mode .main-wrapper {
  margin: 0 !important;
  padding: 0 !important;
  width: 100% !important;
  flex: none !important;
}

html.fs-embed-mode .hero-section {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 8px !important;
  margin: 0 !important;
  width: 100% !important;
}

html.fs-embed-mode .hero-section > .container {
  max-width: 100% !important;
  width: 100% !important;
  padding: 0 !important;
  margin: 0 auto !important;
}

/* Embed Mode Calculator Grid */
html.fs-embed-mode .calculator-grid {
  width: 100% !important;
  margin: 0 !important;
}

/* On viewports >= 720px within iframe, retain core two-column layout */
@media (min-width: 720px) {
  html.fs-embed-mode .calculator-grid {
    display: grid !important;
    grid-template-columns: 1.15fr 0.85fr !important;
    gap: 1.25rem !important;
    align-items: start !important;
  }
}

/* On mobile viewports (< 720px), responsively stack into single column */
@media (max-width: 719px) {
  html.fs-embed-mode .calculator-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 1.25rem !important;
  }
}

/* Static positioning for results panel inside iframe */
html.fs-embed-mode .results-card {
  position: static !important;
  top: auto !important;
  width: 100% !important;
  box-shadow: var(--shadow-sm) !important;
}

html.fs-embed-mode .calc-card {
  box-shadow: var(--shadow-sm) !important;
}

/* --------------------------------------------------------------------------
   2. Embed Trigger Button in Hero Section
   -------------------------------------------------------------------------- */
.fs-hero-embed-wrap {
  margin-top: 1.25rem;
  display: flex;
  justify-content: center;
  align-items: center;
}

.fs-embed-trigger-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background-color: #ffffff;
  color: var(--accent, #2563eb);
  border: 1px solid #cbd5e1;
  padding: 0.55rem 1.15rem;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-full, 9999px);
  cursor: pointer;
  box-shadow: var(--shadow-xs, 0 1px 2px 0 rgba(15, 23, 42, 0.05));
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  min-height: 40px;
}

.fs-embed-trigger-btn:hover {
  background-color: var(--accent-light, #eff6ff);
  border-color: var(--accent-border, #bfdbfe);
  color: var(--accent-hover, #1d4ed8);
  box-shadow: var(--shadow-sm, 0 1px 3px 0 rgba(15, 23, 42, 0.08));
  transform: translateY(-1px);
}

.fs-embed-trigger-btn:active {
  transform: translateY(0);
}

.fs-embed-trigger-btn:focus-visible {
  outline: 2px solid var(--accent, #2563eb);
  outline-offset: 2px;
}

.fs-embed-trigger-btn svg {
  flex-shrink: 0;
  stroke: currentColor;
}

/* --------------------------------------------------------------------------
   3. Embed Modal Dialog & Backdrop
   -------------------------------------------------------------------------- */
.fs-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background-color: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.fs-modal-backdrop.fs-open {
  opacity: 1;
  visibility: visible;
}

.fs-modal-dialog {
  background-color: #ffffff;
  border-radius: 16px;
  border: 1px solid var(--border, #e2e8f0);
  box-shadow: 0 20px 25px -5px rgba(15, 23, 42, 0.15), 0 10px 10px -5px rgba(15, 23, 42, 0.08);
  width: 100%;
  max-width: 620px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  transform: scale(0.96) translateY(8px);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.fs-modal-backdrop.fs-open .fs-modal-dialog {
  transform: scale(1) translateY(0);
}

/* Modal Header */
.fs-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 1.25rem 1.5rem 1rem;
  border-bottom: 1px solid var(--border, #e2e8f0);
  gap: 1rem;
}

.fs-modal-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary, #0f2b48);
  margin: 0;
  line-height: 1.3;
}

.fs-modal-desc {
  font-size: 0.85rem;
  color: var(--text-muted, #64748b);
  margin: 0.25rem 0 0 0;
  line-height: 1.4;
}

.fs-modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted, #64748b);
  cursor: pointer;
  padding: 0.35rem;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  min-width: 36px;
  min-height: 36px;
  flex-shrink: 0;
}

.fs-modal-close-btn:hover {
  background-color: var(--card-subtle, #f1f5f9);
  color: var(--text, #1e293b);
}

.fs-modal-close-btn:focus-visible {
  outline: 2px solid var(--accent, #2563eb);
}

/* Modal Body */
.fs-modal-body {
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.fs-modal-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.fs-modal-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text, #1e293b);
  margin: 0;
}

/* Preset Buttons */
.fs-preset-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.625rem;
}

.fs-preset-btn {
  background-color: #f8fafc;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 8px;
  padding: 0.6rem 0.5rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  transition: all 0.15s ease;
  font-family: inherit;
}

.fs-preset-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text, #1e293b);
}

.fs-preset-dim {
  font-size: 0.75rem;
  color: var(--text-muted, #64748b);
}

.fs-preset-btn:hover {
  background-color: #f1f5f9;
  border-color: #cbd5e1;
}

.fs-preset-btn.active {
  background-color: var(--accent-light, #eff6ff);
  border-color: var(--accent, #2563eb);
  box-shadow: 0 0 0 1px var(--accent, #2563eb);
}

.fs-preset-btn.active .fs-preset-name {
  color: var(--accent, #2563eb);
}

.fs-preset-btn.active .fs-preset-dim {
  color: var(--accent-hover, #1d4ed8);
  font-weight: 500;
}

/* Snippet Header & Textarea */
.fs-snippet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.fs-snippet-badge {
  font-size: 0.725rem;
  font-weight: 600;
  color: var(--secondary, #0d9488);
  background-color: var(--secondary-light, #f0fdfa);
  padding: 0.15rem 0.5rem;
  border-radius: 9999px;
}

.fs-textarea-wrapper {
  position: relative;
  width: 100%;
}

.fs-embed-code-textarea {
  width: 100%;
  font-family: var(--font-mono, ui-monospace, Menlo, Monaco, Consolas, monospace);
  font-size: 0.8rem;
  line-height: 1.5;
  background-color: #0f172a;
  color: #e2e8f0;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 0.85rem 1rem;
  resize: none;
  white-space: pre-wrap;
  word-break: break-all;
  outline: none;
  cursor: text;
  box-shadow: inset 0 2px 4px 0 rgba(0, 0, 0, 0.2);
}

.fs-embed-code-textarea:focus {
  border-color: var(--accent, #2563eb);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.25);
}

.fs-modal-hint {
  font-size: 0.775rem;
  color: var(--text-muted, #64748b);
  margin: 0;
  line-height: 1.4;
}

/* Modal Footer */
.fs-modal-footer {
  padding: 1rem 1.5rem 1.25rem;
  background-color: #f8fafc;
  border-top: 1px solid var(--border, #e2e8f0);
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.fs-preview-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.825rem;
  font-weight: 600;
  color: var(--accent, #2563eb);
  text-decoration: none;
  transition: color 0.15s ease;
}

.fs-preview-link:hover {
  color: var(--accent-hover, #1d4ed8);
  text-decoration: underline;
}

.fs-preview-link svg {
  flex-shrink: 0;
}

.fs-copy-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background-color: var(--accent, #2563eb);
  color: #ffffff;
  border: none;
  border-radius: 8px;
  padding: 0.65rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 1px 3px 0 rgba(37, 99, 235, 0.3);
  min-height: 40px;
}

.fs-copy-btn:hover {
  background-color: var(--accent-hover, #1d4ed8);
  box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.35);
  transform: translateY(-1px);
}

.fs-copy-btn:active {
  transform: translateY(0);
}

.fs-copy-btn.copied {
  background-color: #059669 !important;
  color: #ffffff !important;
  box-shadow: 0 1px 3px 0 rgba(5, 150, 105, 0.4);
}

.fs-copy-btn:focus-visible {
  outline: 2px solid var(--accent, #2563eb);
  outline-offset: 2px;
}

/* Mobile Responsiveness for Modal */
@media (max-width: 540px) {
  .fs-preset-buttons {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .fs-preset-btn {
    flex-direction: row;
    justify-content: space-between;
    padding: 0.55rem 0.85rem;
  }

  .fs-modal-footer {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .fs-preview-link {
    justify-content: center;
  }

  .fs-copy-btn {
    width: 100%;
  }
}
