/* styles/global.css — Shared layout, typography, and reusable elements */

body {
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: var(--color-text);
  background: radial-gradient(circle at top right, var(--color-primary-soft), var(--color-bg) 38%);
  background-attachment: fixed;
}

/* ── Anti-FOUC Loader ───────────────────────────────────────────────── */

.app-loading {
  opacity: 0;
}

.app-loaded {
  opacity: 1;
  transition: opacity 0.3s ease-in-out;
}

/* ── App Shell ──────────────────────────────────────────────────────── */

.app-shell {
  height: 100vh;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.app-layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(280px, 1fr);
  gap: 1rem;
  min-height: 0;
}

/* Ensure component slots pass the layout height down to their inner panels */
.app-layout > [data-component] {
  display: contents;
}
/* ── App Header ─────────────────────────────────────────────────────── */

.app-header {
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  border-radius: 14px;
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  box-shadow: 0 12px 24px -18px var(--color-shadow);
}

.app-header h1 {
  margin: 0.2rem 0 0;
  font-size: 1.2rem;
  line-height: 1.2;
}

.eyebrow {
  margin: 0;
  color: var(--color-muted);
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

/* ── Status Message ─────────────────────────────────────────────────── */

.status-message {
  margin: 0;
  padding: 0.44rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  color: var(--color-muted);
  background: var(--color-surface-soft);
  font-size: 0.8rem;
}

.status-message[data-status="success"] {
  color: var(--color-success);
  border-color: color-mix(in hsl, var(--color-success) 45%, var(--color-border));
  background: color-mix(in hsl, var(--color-success) 14%, var(--color-surface));
}

.status-message[data-status="error"] {
  color: var(--color-danger);
  border-color: color-mix(in hsl, var(--color-danger) 50%, var(--color-border));
  background: color-mix(in hsl, var(--color-danger) 15%, var(--color-surface));
}

/* ── Shared Field Group ─────────────────────────────────────────────── */

.field-group {
  display: grid;
  gap: 0.35rem;
  color: var(--color-muted);
  font-size: 0.78rem;
}

.field-group input,
.field-group select {
  width: 100%;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  font-size: 0.9rem;
  background: var(--color-surface-soft);
  color: var(--color-text);
}

.field-group input:focus,
.field-group select:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px color-mix(in hsl, var(--color-primary) 20%, transparent);
  outline: none;
}

/* ── Screen-reader only ─────────────────────────────────────────────── */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  border: 0;
  padding: 0;
  clip: rect(0 0 0 0);
  overflow: hidden;
}

/* ── Responsive ─────────────────────────────────────────────────────── */

/* DESKTOP layout logic for the panels inside app-layout */
.app-layout > [data-component="SettingsPanel"] {
  grid-column: 1 / -1; /* Spans both columns above editor/preview */
}
.app-layout > [data-component="EditorPanel"] { grid-column: 1; }
.app-layout > [data-component="PreviewPanel"] { grid-column: 2; }

/* Hide mobile nav on Desktop */
.bottom-nav {
  display: none;
}

@media (max-width: 1160px) {
  .app-shell {
    height: 100vh;
    padding: 0;
    margin: 0;
    gap: 0;
    overflow: hidden;
  }

  .app-header {
    margin: 0.7rem;
    flex-shrink: 0;
  }

  /* Hide settings toggle on mobile since it's now in the bottom nav */
  #settingsToggleButton {
    display: none;
  }

  /* Force Settings to display as a full page even if .is-hidden was set by Desktop JS */
  .settings-panel.is-hidden {
    display: grid !important;
  }

  /* Hide verbose text strings to save screen real estate in mobile */
  .app-header h1,
  .panel-editor__subtitle,
  .panel-preview__subtitle {
    display: none;
  }

  /* On mobile, carousel panes must be real flex children, not display:contents */
  .app-layout > [data-component] {
    display: flex;
    flex-direction: column;
  }

  /* FAB: push above the bottom nav on mobile */
  .fab-container {
    bottom: 6rem;
  }

  /* FAB: hide when not on the Editor pane */
  .fab-hidden-mobile .fab-container,
  .fab-hidden-mobile {
    display: none !important;
  }

  /* Mobile App Layout becomes a Carousel */
  .app-layout {
    display: flex;
    flex-direction: row;
    gap: 0; /* Remove desktop gap to fix trailing space */
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth; /* Native smooth scroll on anchor clicks */
    -webkit-overflow-scrolling: touch;
    flex: 1;
    min-height: 0;
    padding-bottom: 4.5rem; /* Space for the bottom navbar */
    scrollbar-width: none; /* Firefox */
  }
  
  .app-layout::-webkit-scrollbar {
    display: none; /* Safari/Chrome */
  }

  /* Each Pane config */
  .carousel-pane {
    width: 100vw;
    flex: 0 0 100vw;
    scroll-snap-align: start;
    padding: 0;
    box-sizing: border-box;
    /* Sub-panels should scroll vertically inside their pane */
    display: flex;
    flex-direction: column;
    overflow-y: auto;
  }

  /* When taking full width on mobile, panels should lose their rounded corners and side borders */
  .carousel-pane > .panel,
  .carousel-pane > .settings-panel {
    border-radius: 0;
    border-left: none;
    border-right: none;
    box-shadow: none;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
  }

  /* Bottom Navigation Bar */
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 4.5rem;
    background: color-mix(in hsl, var(--color-surface) 90%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--color-border);
    z-index: 50;
    padding-bottom: env(safe-area-inset-bottom);
    justify-content: space-around;
    align-items: center;
  }

  .bottom-nav__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    flex: 1;
    height: 100%;
    color: var(--color-muted);
    transition: color 0.2s ease;
  }

  .bottom-nav__item.active {
    color: var(--color-primary);
  }

  .bottom-nav__icon {
    font-size: 1.3rem;
    line-height: 1;
  }

  .bottom-nav__label {
    font-size: 0.7rem;
    font-weight: 500;
  }
}

