:root {
  --bg: #f6f4ee;
  --panel: #fffdf8;
  --ink: #1a2226;
  --accent: #26667f;
  --accent-2: #e7833f;
  --line: #d9d2c5;
  --glow-a: rgba(38, 102, 127, 0.08);
  --glow-b: rgba(231, 131, 63, 0.06);
  --theme-gradient: linear-gradient(120deg, #e9f6ff, #fff2e7);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Manrope", sans-serif;
  background: radial-gradient(circle at 10% 5%, #fff, transparent 40%),
    radial-gradient(circle at 90% 20%, #fff2df, transparent 35%),
    var(--bg);
  color: var(--ink);
}

.bg-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: var(--theme-gradient);
  opacity: 0.3;
}

/* Print header is invisible on screen; shown in print only */
.print-header {
  display: none;
}

.shell {
  position: relative;
  z-index: 1;
  max-width: 980px;
  margin: 0 auto;
  padding: 2rem 1rem 4rem;
}

.hero h1 {
  font-family: "Fraunces", serif;
  font-size: clamp(2rem, 4vw, 3.4rem);
  margin: 0;
}

.eyebrow {
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-size: 0.75rem;
  color: var(--accent);
  margin-bottom: 0.5rem;
}

.subtitle {
  max-width: 60ch;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1.2rem;
  box-shadow: 0 24px 60px rgba(26, 34, 38, 0.08);
}

.brand-studio {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.9rem;
  background: linear-gradient(145deg, #ffffff, #faf6ef);
}

.brand-studio h3 {
  margin-top: 0;
  margin-bottom: 0.35rem;
  font-family: "Fraunces", serif;
}

.brand-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem;
}

.tab-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.tab {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.tab.active {
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  color: #fff;
  border-color: transparent;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fade-in 250ms ease;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-weight: 600;
  font-size: 0.92rem;
}

label textarea,
label input,
label select,
button {
  font: inherit;
}

input,
textarea,
select {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
  background: #fff;
}

.actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 0.65rem;
}

button {
  border: 1px solid transparent;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  color: #fff;
  border-radius: 10px;
  padding: 0.6rem 1rem;
  cursor: pointer;
  transition: transform 130ms ease;
}

button:hover {
  transform: translateY(-1px);
}

button.secondary {
  background: #fff;
  color: var(--accent);
  border-color: var(--line);
}

.result {
  margin-top: 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
  background: #fff;
}

.hidden {
  display: none;
}

.print-reflection {
  border-left: 3px solid var(--accent-2);
  padding: 0.3rem 0 0.3rem 0.75rem;
  margin: 0 0 0.9rem;
  font-style: italic;
  color: #333;
}

.passage {
  margin-bottom: 0.9rem;
}

.passage h4 {
  margin: 0 0 0.3rem;
}

.meta {
  color: #4f626c;
  font-size: 0.9rem;
}

.admin-toolbar {
  margin-top: 1rem;
  display: grid;
  gap: 0.8rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.admin-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.6rem;
}

.admin-stat {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem;
  background: #fff;
}

.admin-stat .label {
  display: block;
  font-size: 0.78rem;
  color: #4f626c;
}

.admin-stat .value {
  font-family: "Fraunces", serif;
  font-size: 1.2rem;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.status-chip.approved {
  background: #e8f6ef;
  color: #1e7b4f;
}

.status-chip.draft {
  background: #fff3e8;
  color: #a35618;
}

.status-chip.rejected {
  background: #fdeaea;
  color: #9b2c2c;
}

.template-card {
  margin-bottom: 0.9rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.75rem;
  background: linear-gradient(180deg, #ffffff, #fdfbf7);
}

.template-card .head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.4rem;
  gap: 0.5rem;
}

.template-card p {
  margin-top: 0;
}

@media (max-width: 780px) {
  .shell {
    padding: 1rem 0.75rem 3rem;
  }

  .hero h1 {
    font-size: 1.8rem;
  }

  .hero .subtitle {
    font-size: 0.9rem;
  }

  .panel {
    padding: 1rem;
    border-radius: 12px;
  }

  .brand-studio {
    padding: 0.75rem;
  }

  .grid {
    grid-template-columns: 1fr;
  }

  .brand-grid {
    grid-template-columns: 1fr;
  }

  .admin-toolbar,
  .admin-stats {
    grid-template-columns: 1fr;
  }

  .actions {
    flex-direction: column;
  }

  button {
    width: 100%;
    justify-content: center;
  }

  .tab {
    flex: 1;
    text-align: center;
    padding: 0.55rem 0.5rem;
  }

  input,
  textarea,
  select {
    font-size: 1rem; /* prevent iOS zoom on focus */
  }
}

@media print {
  @page {
    margin: 0.75in 0.85in;
  }

  body {
    background: var(--bg) !important;
    color: #1a1a1a;
    font-size: 10.5pt;
    font-family: "Manrope", sans-serif;
  }

  /* Hide all screen-only chrome */
  .bg-glow,
  .hero,
  .tab-row,
  .brand-studio,
  #query-form,
  #admin-view,
  #tab-admin,
  #tab-user,
  .actions,
  .screen-only {
    display: none !important;
  }

  /* Strip layout shell */
  .shell {
    max-width: none;
    padding: 0;
    margin: 0;
  }

  .panel {
    border: none !important;
    box-shadow: none !important;
    padding: 0;
    background: transparent !important;
    border-radius: 0;
  }

  .tab-content {
    display: block !important;
  }

  #result {
    border: none !important;
    box-shadow: none !important;
    padding: 0;
    margin: 0;
    background: transparent !important;
    border-radius: 0;
  }

  /* ── Print header ─────────────────────────────── */
  .print-header {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    background: var(--theme-gradient);
    border-radius: 4pt;
    border-left: 4pt solid var(--accent);
    padding: 0.55rem 0.85rem 0.6rem;
    margin-bottom: 1.6rem;
  }

  .print-org {
    font-family: "Fraunces", serif;
    font-size: 17pt;
    font-weight: 700;
    color: var(--accent);
  }

  .print-topic {
    font-size: 11pt;
    font-weight: 600;
    color: #444;
    text-transform: capitalize;
    flex: 1;
    text-align: center;
  }

  .print-date {
    font-size: 8.5pt;
    color: #888;
    white-space: nowrap;
  }

  /* ── Personalization reflection ────────────────── */
  .print-reflection {
    font-family: "Fraunces", serif;
    font-size: 11pt;
    font-style: italic;
    border-left: 3pt solid var(--accent-2);
    padding: 0.35rem 0 0.35rem 0.85rem;
    margin: 0 0 1.5rem;
    color: #333;
    page-break-inside: avoid;
    break-inside: avoid;
  }

  .print-reflection strong {
    display: block;
    font-size: 7.5pt;
    font-style: normal;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent-2);
    margin-bottom: 0.25rem;
  }

  /* ── Passage cards ─────────────────────────────── */
  .passage {
    page-break-inside: avoid;
    break-inside: avoid;
    border-left: 3pt solid var(--accent);
    padding: 0.25rem 0 0.25rem 0.85rem;
    margin-bottom: 1.1rem;
  }

  .passage h4 {
    font-family: "Fraunces", serif;
    font-size: 11.5pt;
    font-weight: 700;
    color: var(--accent);
    margin: 0 0 0.2rem;
  }

  .passage p {
    margin: 0;
    font-size: 10.5pt;
    line-height: 1.68;
    color: #1a1a1a;
  }

  .passage .meta {
    margin-top: 0.35rem;
    font-size: 8.5pt;
    color: #666;
    font-style: italic;
  }

  /* ── Support resources ─────────────────────────── */
  #result h4 {
    font-family: "Fraunces", serif;
    font-size: 11pt;
    color: var(--accent);
    margin: 1rem 0 0.4rem;
    page-break-after: avoid;
    break-after: avoid;
  }

  #result ul {
    margin: 0;
    padding-left: 1.1rem;
    font-size: 9.5pt;
    color: #333;
  }
}
