:root {
  --color-bg: #f4f5f7;
  --color-surface: #ffffff;
  --color-border: #dfe2e7;
  --color-text: #1f2430;
  --color-text-muted: #6b7280;
  --color-primary: #2f6f4f;
  --color-primary-hover: #245a3f;
  --color-danger: #b3261e;
  --color-danger-hover: #8f1e18;
  --radius: 6px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
}

.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: 220px;
  flex: none;
  height: 100%;
  overflow-y: auto;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: 20px 12px;
}

.sidebar .brand {
  font-weight: 700;
  font-size: 1.05rem;
  line-height: 1.3;
  padding: 0 12px 20px;
  color: var(--color-primary);
}

.nav-link {
  display: block;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--color-text);
  text-decoration: none;
  font-size: 0.95rem;
}

.nav-link.active,
.nav-link:hover {
  background: var(--color-bg);
  color: var(--color-primary);
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
}

.app-header {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 32px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
}

.app-header h1 {
  margin: 0;
  font-size: 1.3rem;
}

.staff-session {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.link-button {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-size: 0.85rem;
  color: var(--color-primary);
  cursor: pointer;
  text-decoration: underline;
}

.link-button:hover {
  color: var(--color-primary-hover);
}

.content-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
  max-width: 1400px;
}

.list-toolbar {
  margin-bottom: 16px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}

.data-table th,
.data-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.9rem;
}

.data-table th {
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.emoji-cell {
  font-size: 1.1rem;
  width: 1%;
}

.row-actions {
  white-space: nowrap;
  text-align: right;
  width: 1%;
}

.empty-row {
  text-align: center;
  color: var(--color-text-muted);
  padding: 24px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-published {
  background: #e3f2e9;
  color: var(--color-primary);
}

.badge-draft {
  background: #f0f0f0;
  color: var(--color-text-muted);
}

.button {
  display: inline-block;
  padding: 7px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  text-decoration: none;
  font-size: 0.85rem;
  cursor: pointer;
  line-height: 1.2;
}

.button:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.button.primary {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

.button.primary:hover {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
  color: #fff;
}

.button.danger {
  background: #fff;
  border-color: var(--color-danger);
  color: var(--color-danger);
}

.button.danger:hover {
  background: var(--color-danger);
  color: #fff;
}

.form-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.form-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.form-error {
  background: #fdecea;
  border: 1px solid var(--color-danger);
  color: var(--color-danger);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.content-form {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 640px;
}

.field {
  margin-bottom: 16px;
  flex: 1;
}

.field-row {
  display: flex;
  gap: 16px;
}

.field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--color-text-muted);
}

.field input[type="text"],
.field input[type="number"],
.field textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--color-text);
}

.field textarea {
  resize: vertical;
}

.field-hint {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-top: -8px;
  margin-bottom: 16px;
}

/* Unlike .field-hint (which hugs the .field directly above it via a
   negative top margin), this sits below a whole form's .form-actions - the
   login page's "Use a different email" link. Reusing .field-hint there
   used to pull the link up into the bottom of the Log in button instead of
   spacing it below. */
.form-footnote {
  margin-top: 16px;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  text-align: center;
}

.checkbox-field label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  color: var(--color-text);
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.field select,
.field input[type="datetime-local"],
.field input[type="file"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-surface);
}

.section-heading {
  margin: 24px 0 12px;
  padding-top: 16px;
  border-top: 1px solid var(--color-border);
  font-size: 0.95rem;
  color: var(--color-text-muted);
}

.detail-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 24px;
}

.detail-panel .form-header {
  margin-bottom: 16px;
}

/* ---- Master-detail layout - the master form and its detail panel(s)
   (Sections, or Calculator's Answer Options/Tree Edges) sit side by side
   on desktop widths, stacked on narrow ones. .has-detail is only present
   when the detail column actually has content (edit mode, not "new") -
   a lone master-panel with no sibling just stays a single block. ---- */

.master-panel {
  min-width: 0;
}

.detail-column {
  min-width: 0;
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

@media (min-width: 900px) {
  .master-detail-layout.has-detail {
    display: grid;
    grid-template-columns: minmax(0, 640px) minmax(0, 1fr);
    align-items: start;
    gap: 24px;
  }

  .master-detail-layout.has-detail .detail-column {
    margin-top: 0;
  }
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  max-width: 1100px;
}

.image-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}

.image-card img {
  display: block;
  width: 100%;
  height: 140px;
  object-fit: cover;
  background: var(--color-bg);
}

.image-card-body {
  padding: 10px 12px;
}

.image-card-meta {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-bottom: 6px;
}

.image-card-alt {
  font-size: 0.85rem;
  margin-bottom: 4px;
}

.image-card-id {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-bottom: 10px;
}

.edit-preview {
  display: block;
  max-width: 400px;
  max-height: 300px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-bottom: 20px;
}

/* ---- Login page - same structural shape (gradient-mesh backdrop + centred
   card) as the Admin App's login screen, themed with this app's own
   --color-primary rather than copying its palette literally. ---- */

.gradient-mesh {
  position: relative;
  isolation: isolate;
  /* Only clip horizontally (the decorative blurred ::before bleeds past the
     edges on purpose via its negative inset) - clipping vertically too
     cut off the bottom of the login card (e.g. the "Use a different email"
     link) whenever the card was taller than a short browser window,
     instead of letting the page scroll to show it. */
  overflow-x: hidden;
  overflow-y: auto;
}

.gradient-mesh::before {
  content: "";
  position: absolute;
  inset: -20%;
  z-index: -1;
  background:
    radial-gradient(circle at 20% 25%, rgba(47, 111, 79, 0.55), transparent 45%),
    radial-gradient(circle at 80% 20%, rgba(232, 179, 77, 0.4), transparent 45%),
    radial-gradient(circle at 50% 85%, rgba(31, 107, 63, 0.55), transparent 50%);
  background-color: #112318;
  filter: blur(40px);
  animation: meshDrift 18s ease-in-out infinite alternate;
}

@keyframes meshDrift {
  0%   { transform: translate(0, 0) scale(1); }
  50%  { transform: translate(3%, -2%) scale(1.08); }
  100% { transform: translate(-3%, 2%) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .gradient-mesh::before { animation: none; }
}

.login-body {
  min-height: 100vh;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 28px;
}

.login-card h1 {
  font-size: 1.05rem;
  line-height: 1.3;
  white-space: nowrap;
  margin: 0 0 16px;
  color: var(--color-primary);
}

.login-card .content-form {
  max-width: none;
  padding: 0;
  border: none;
}

/* ---- Image picker - the thumbnail + "Change image" widget every
   HeroImageId/CardImageId/ImageId/TeaserImageId field renders as now, and
   the modal (defined once in shell.html) it opens. ---- */

.image-picker-field {
  display: flex;
  align-items: center;
  gap: 14px;
}

.image-picker-thumb {
  width: 110px;
  height: 82px;
  object-fit: cover;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-bg);
  flex: none;
}

.image-picker-field-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.image-picker-modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 20, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 1000;
}

.image-picker-modal[hidden] {
  display: none;
}

.image-picker-modal-content {
  width: 100%;
  max-width: 900px;
  max-height: 80vh;
  background: var(--color-surface);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.image-picker-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border);
  flex: none;
}

.image-picker-modal-header h3 {
  margin: 0;
  font-size: 1.05rem;
}

.image-picker-search {
  padding: 12px 20px;
  border-bottom: 1px solid var(--color-border);
  flex: none;
}

.image-picker-search input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font: inherit;
  font-size: 0.9rem;
}

.image-picker-grid {
  flex: 1;
  /* Flex items default to min-height:auto, which refuses to shrink below
     their own content size - with ~80 images that content is taller than
     the space left inside the modal's 80vh cap, so the grid was expanding
     past it instead of scrolling, and .image-picker-modal-content's own
     overflow:hidden just clipped the excess. min-height:0 lets this item
     actually shrink to the flex space available, so overflow-y:auto above
     can do its job. */
  min-height: 0;
  overflow-y: auto;
  padding: 16px 20px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  /* Without this, auto-sized grid rows get compressed to divide up
     whatever height is available rather than overflowing - each
     .image-picker-item has overflow:hidden, which strips its "automatic
     minimum size" protection (a real CSS Grid/Flexbox spec rule: that
     protection only applies when overflow is visible), so with ~80 images
     needing 14 rows the algorithm squashed every row down to ~19px to fit
     them all in the space available, clipping each 90px image down to a
     sliver instead of leaving rows at their natural height and letting the
     grid scroll. min-content forces rows back to their natural content
     height regardless of that overflow-driven min-size loss. */
  grid-auto-rows: min-content;
  gap: 12px;
  align-content: start;
}

.image-picker-item {
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--color-bg);
}

.image-picker-item:hover {
  border-color: var(--color-primary);
}

.image-picker-item img {
  display: block;
  width: 100%;
  height: 90px;
  object-fit: cover;
  background: var(--color-border);
}

.image-picker-item-meta {
  padding: 4px 6px;
  font-size: 0.7rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------------------------------------------------------------------
   Screenshot mockup picker (PageSections.ShotVariant, 'product' pages
   only) - see BuildShotVariantPickerHtml in PagesPagesUnit.pas. Each card
   renders a live, CSS-scaled copy of the real fragment the website shows
   (ShotHtmlForVariant in LowEnergyBuild\LowEnergyBuildSiteUnit.pas) so
   editors see what they're picking rather than a bare label. The
   .feature-shot- and .shot- prefixed rules below are a themed copy of that website's
   styles.css rules (same class names, this project's own --color-* tokens
   instead of Pico's), scaled down via .shotvariant-thumb-inner's
   transform - keep both copies in sync by hand if the website's rules for
   these classes ever change.
   --------------------------------------------------------------------- */

.shotvariant-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.shotvariant-card {
  position: relative;
  display: block;
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  padding: 8px;
  cursor: pointer;
  background: var(--color-surface);
}

.shotvariant-card:hover {
  border-color: var(--color-primary);
}

.shotvariant-card input[type="radio"] {
  position: absolute;
  top: 8px;
  right: 8px;
  margin: 0;
}

.shotvariant-card:has(input:checked) {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 1px var(--color-primary);
}

.shotvariant-thumb {
  height: 108px;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: var(--color-bg);
  position: relative;
}

.shotvariant-thumb-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  font-size: 0.78rem;
  color: var(--color-text-muted);
}

.shotvariant-thumb-inner {
  width: 260px;
  transform: scale(0.4);
  transform-origin: top left;
}

.shotvariant-label {
  margin-top: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  text-align: center;
  color: var(--color-text);
}

/* Themed copy of the website's .feature-shot- and .shot- prefixed rules -
   see the block comment above. */
.shotvariant-thumb-inner .feature-shot-bar {
  display: flex;
  gap: 5px;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--color-border);
}

.shotvariant-thumb-inner .feature-shot-bar span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-border);
}

.shotvariant-thumb-inner .feature-shot-body {
  padding: 1.1rem 1.3rem;
}

.shotvariant-thumb-inner .shot-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--color-text-muted);
  margin: 0 0 1rem;
}

.shotvariant-thumb-inner .shot-stage-pills {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.1rem;
}

.shotvariant-thumb-inner .shot-pill {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
}

.shotvariant-thumb-inner .shot-pill.done {
  background: rgba(47, 111, 79, 0.14);
  color: var(--color-primary);
}

.shotvariant-thumb-inner .shot-pill.active {
  background: rgba(232, 179, 77, 0.18);
  color: #8a6a1f;
}

.shotvariant-thumb-inner .shot-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0;
  border-top: 1px solid var(--color-border);
  font-size: 0.85rem;
}

.shotvariant-thumb-inner .shot-row:first-of-type,
.shotvariant-thumb-inner .shot-row.plain:first-of-type {
  border-top: none;
}

.shotvariant-thumb-inner .shot-row.plain {
  justify-content: space-between;
}

.shotvariant-thumb-inner .shot-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.shotvariant-thumb-inner .shot-dot.done {
  background: #4fae6c;
}

.shotvariant-thumb-inner .shot-dot.pending {
  background: #e8b34d;
}

.shotvariant-thumb-inner .shot-row-text {
  flex: 1;
  font-weight: 600;
}

.shotvariant-thumb-inner .shot-tag {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 5px;
  white-space: nowrap;
}

.shotvariant-thumb-inner .shot-tag.ok {
  background: rgba(47, 111, 79, 0.14);
  color: var(--color-primary);
}

.shotvariant-thumb-inner .shot-tag.pending {
  background: rgba(232, 179, 77, 0.18);
  color: #8a6a1f;
}

.shotvariant-thumb-inner .shot-tag.neutral {
  background: var(--color-border);
  color: var(--color-text-muted);
}

.shotvariant-thumb-inner .shot-comment {
  font-style: italic;
  color: var(--color-text-muted);
  font-size: 0.82rem;
  margin: 0.6rem 0 0;
}

.shotvariant-thumb-inner .shot-check {
  width: 18px;
  flex: 0 0 auto;
  color: #4fae6c;
  font-weight: 700;
  text-align: center;
}

.shotvariant-thumb-inner .shot-check.pending {
  color: var(--color-text-muted);
}

.shotvariant-thumb-inner .shot-handle {
  color: var(--color-text-muted);
  letter-spacing: -2px;
  font-size: 0.9rem;
}

.shotvariant-thumb-inner .shot-add {
  margin: 0.6rem 0 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-primary);
}
