.story-page {
  /* Aliased to the canonical WADIREP/WASCAL tokens from ckanext-custom/assets/style.css
     (loaded site-wide via base.html) instead of a locally hardcoded palette, so this
     page can't drift from the brand blue/green defined once in one place. Fallback
     hex values keep the page usable if that stylesheet somehow isn't loaded.
     --story-danger has no brand-token equivalent (it's a UI error state, not a brand
     colour) and stays a plain value. */
  --story-ink: var(--color-text-primary, #172331);
  --story-muted: var(--color-text-muted, #5c6875);
  --story-border: var(--color-border, #d9e1e7);
  --story-surface: var(--color-surface, #ffffff);
  --story-soft: var(--color-surface-secondary, #f5f8fa);
  --story-blue: var(--color-wascal-blue, #0D6BF1);
  --story-green: var(--color-wascal-green, #43C16F);
  --story-gold: var(--color-accent, #b87912);
  --story-danger: #b42318;
  --story-focus: rgba(13, 107, 241, 0.22);
  --story-green-soft: rgba(67, 193, 111, 0.14);
  --story-gold-soft: rgba(184, 121, 18, 0.16);
  color: var(--story-ink) !important;
  background: #f7fafb !important;
  letter-spacing: 0;
}

.dark .story-page {
  --story-ink: var(--color-text-dark-primary, #ffffff);
  --story-muted: var(--color-text-dark-secondary, #C4C4C4);
  --story-border: var(--color-border-dark, #6D7779);
  --story-surface: var(--color-surface-dark-secondary, #494A4F);
  --story-soft: var(--color-surface-dark, #0C0F13);
  background: var(--color-surface-dark, #0C0F13) !important;
}

.story-page *,
.story-page *::before,
.story-page *::after {
  box-sizing: border-box;
}

.story-container {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
}

.story-directory {
  padding: 28px 0 48px;
}

.story-directory-head,
.story-form-head,
.story-confirm-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.story-directory-head h1,
.story-read-title,
.story-form-head h1,
.story-confirm-head h1 {
  margin: 0;
  color: var(--story-ink) !important;
  font-size: clamp(2rem, 4vw, 3.25rem);
  font-weight: 760;
  line-height: 1.06;
  letter-spacing: 0;
}

.story-directory-head p,
.story-form-head p,
.story-confirm-head p {
  margin: 8px 0 0;
  color: var(--story-muted) !important;
  font-size: 1rem;
  line-height: 1.55;
}

.story-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  gap: 8px;
  padding: 10px 16px;
  border: 1px solid var(--story-border) !important;
  border-radius: 6px;
  background: var(--story-surface) !important;
  color: var(--story-ink) !important;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
}

.story-button:hover,
.story-button:focus {
  color: var(--story-ink) !important;
  text-decoration: none;
  border-color: var(--story-blue) !important;
  box-shadow: 0 0 0 3px var(--story-focus);
}

.story-button-primary {
  border-color: var(--story-blue) !important;
  background: var(--story-blue) !important;
  color: #ffffff !important;
}

.story-button-primary:hover,
.story-button-primary:focus {
  color: #ffffff !important;
}

.story-button-danger {
  border-color: var(--story-danger) !important;
  background: var(--story-danger) !important;
  color: #ffffff !important;
}

.story-button-danger:hover,
.story-button-danger:focus {
  color: #ffffff !important;
}

.story-button-muted {
  background: #eef3f6 !important;
}

.story-search {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 12px;
  margin-bottom: 24px;
  border: 1px solid var(--story-border) !important;
  border-radius: 8px;
  background: var(--story-surface) !important;
}

.story-filter-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  align-items: stretch;
}

.story-filter-grid input[type="search"] {
  grid-column: span 2;
}

.story-search input,
.story-form-control {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--story-border) !important;
  border-radius: 6px;
  background: #ffffff !important;
  /* Deliberately NOT var(--story-ink): it flips to white in dark mode, but
     these fields' background stays a fixed white in both themes, so the
     text/placeholder color must stay fixed dark too. */
  color: var(--color-text-primary, #172331) !important;
  padding: 9px 12px;
  font-size: 1rem;
  line-height: 1.4;
}

.story-search input::placeholder,
.story-form-control::placeholder {
  color: var(--color-text-muted, #5c6875) !important;
}

.story-form-control:focus,
.story-search input:focus {
  outline: 0;
  border-color: var(--story-blue) !important;
  box-shadow: 0 0 0 3px var(--story-focus);
}

.story-featured {
  margin-bottom: 28px;
  padding: 18px;
  border: 1px solid var(--story-border) !important;
  border-radius: 8px;
  background: var(--story-surface) !important;
}

.story-featured h2,
.story-results-heading h2,
.story-panel h2 {
  margin: 0;
  color: var(--story-ink) !important;
  font-size: 1.15rem;
  font-weight: 760;
  letter-spacing: 0;
}

/* CKAN core's snippets/social.html ("Social" share links) renders inside
   .story-panel using core's own unstyled, unlayered classes
   (.module-heading, .nav-item a) instead of a WASCAL heading/link class.
   .module-heading carries its own hardcoded light-gray background
   (#f6f6f6) and core's `a` a dark teal (#206b82); neither adapts to
   .story-panel's dark surface, so the heading text and links are
   illegible against it. */
.story-panel .module-heading {
  margin: 0 0 0.75rem;
  padding: 0;
  background: transparent !important;
  border: 0 !important;
  color: var(--story-ink) !important;
  font-size: 1.15rem;
  font-weight: 760;
}

.story-panel .nav-item a {
  color: var(--story-blue) !important;
}

.story-panel .nav-item a:hover {
  color: var(--story-ink) !important;
}

.story-results-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.story-results-heading > div {
  min-width: 0;
  max-width: 100%;
}

.story-results-heading h2,
.story-empty h2,
.story-card-title,
.story-card-summary,
.story-query-text {
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.story-query-text {
  display: inline;
  min-width: 0;
  max-width: 100%;
  color: var(--story-blue) !important;
  font-weight: 760;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.story-results-count {
  margin: 0.45rem 0 0;
  color: var(--story-muted) !important;
  font-weight: 650;
}

.story-sort-form {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.story-sort-label {
  margin: 0;
  color: var(--story-muted) !important;
  font-size: 0.92rem;
  font-weight: 750;
  line-height: 1.2;
  white-space: nowrap;
}

.story-sort-select {
  width: min(220px, 46vw);
  min-height: 40px;
  border: 1px solid var(--story-border) !important;
  border-radius: 6px;
  background: #ffffff !important;
  color: var(--color-text-primary, #172331) !important;
  padding: 8px 34px 8px 10px;
  font-size: 0.95rem;
  line-height: 1.3;
}

.story-sort-select:focus {
  outline: 0;
  border-color: var(--story-blue) !important;
  box-shadow: 0 0 0 3px var(--story-focus);
}

.story-sort-submit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  min-width: 40px;
  height: 40px;
  border: 1px solid var(--story-border) !important;
  border-radius: 6px;
  background: var(--story-surface) !important;
  color: var(--story-ink) !important;
}

.story-sort-submit:hover,
.story-sort-submit:focus {
  border-color: var(--story-blue) !important;
  box-shadow: 0 0 0 3px var(--story-focus);
}

.story-muted {
  color: var(--story-muted) !important;
  line-height: 1.6;
}

.story-featured-grid,
.story-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  margin-top: 16px;
}

.story-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--story-border) !important;
  border-radius: 8px;
  background: var(--story-surface) !important;
}

.story-card-media {
  display: block;
  aspect-ratio: 16 / 9;
  background: #e8eef2 !important;
  overflow: hidden;
}

.story-card-media img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.story-card-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
}

.story-card-title {
  margin: 0;
  color: var(--story-ink) !important;
  font-size: 1.2rem;
  line-height: 1.25;
  letter-spacing: 0;
}

.story-card-title a {
  color: inherit !important;
  text-decoration: none;
}

.story-card-title a:hover,
.story-card-title a:focus {
  color: var(--story-blue) !important;
  text-decoration: underline;
}

.story-card-summary {
  margin: 0;
  color: var(--story-muted) !important;
  line-height: 1.55;
}

.story-card-footer,
.story-read-meta,
.story-pill-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.story-card-footer {
  margin-top: auto;
  color: var(--story-muted) !important;
  font-size: 0.9rem;
}

.story-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  min-height: 28px;
  padding: 4px 9px;
  border: 1px solid var(--story-border) !important;
  border-radius: 999px;
  background: var(--story-green-soft) !important;
  color: var(--story-green) !important;
  font-size: 0.86rem;
  font-weight: 700;
  line-height: 1.2;
}

.story-pill-draft {
  background: var(--story-gold-soft) !important;
  color: var(--story-gold) !important;
}

.story-empty {
  padding: 34px 20px;
  border: 1px solid var(--story-border) !important;
  border-radius: 8px;
  background: var(--story-surface) !important;
  text-align: center;
}

.story-empty i {
  color: var(--story-blue) !important;
  font-size: 2rem;
}

.story-empty h2 {
  margin: 12px 0 0;
  color: var(--story-ink) !important;
  font-size: 1.35rem;
}

.story-pagination {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 26px;
}

.story-read-hero {
  padding: 28px 0 30px;
  background: #ffffff !important;
  border-bottom: 1px solid var(--story-border) !important;
}

.story-read-hero-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(280px, 0.95fr);
  gap: 28px;
  align-items: center;
}

.story-read-kicker {
  margin: 0 0 10px;
  color: var(--story-blue) !important;
  font-size: 0.92rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

.story-read-summary {
  margin: 14px 0 0;
  color: var(--story-muted) !important;
  font-size: 1.16rem;
  line-height: 1.65;
}

.story-read-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.story-read-image {
  width: 100%;
  aspect-ratio: 16 / 10;
  display: block;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--story-border) !important;
  background: #e8eef2 !important;
}

.story-read-figure {
  margin: 0;
}

.story-read-figure figcaption {
  margin-top: 8px;
  color: var(--story-muted) !important;
  font-size: 0.9rem;
  line-height: 1.45;
}

.story-read-figure figcaption span {
  display: block;
}

.story-read-content {
  padding: 30px 0 54px;
}

.story-read-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 28px;
  align-items: start;
}

.story-article,
.story-panel,
.story-form-panel,
.story-confirm-panel {
  border: 1px solid var(--story-border) !important;
  border-radius: 8px;
  background: var(--story-surface) !important;
}

.story-article {
  padding: 26px;
}

.story-article .ckanext-pages-content {
  color: var(--story-ink) !important;
  font-size: 1.04rem;
  line-height: 1.75;
}

.story-article .ckanext-pages-content img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

.story-impact-section {
  padding-top: 22px;
  margin-top: 24px;
  border-top: 1px solid var(--story-border) !important;
}

.story-impact-section h2 {
  margin: 18px 0 8px;
  color: var(--story-ink) !important;
  font-size: 1.2rem;
  line-height: 1.25;
}

.story-metadata-list {
  margin: 14px 0 0;
}

.story-metadata-list dt {
  margin-top: 12px;
  color: var(--story-ink) !important;
  font-size: 0.86rem;
  font-weight: 800;
}

.story-metadata-list dd {
  margin: 4px 0 0;
  color: var(--story-muted) !important;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.story-panel {
  padding: 18px;
  margin-bottom: 16px;
}

.story-topic-list,
.story-dataset-list {
  list-style: none;
  padding: 0;
  margin: 14px 0 0;
}

.story-topic-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.story-dataset-list li + li {
  margin-top: 10px;
}

.story-dataset-list a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  color: var(--story-ink) !important;
  text-decoration: none;
  border-bottom: 1px solid var(--story-border) !important;
}

.story-dataset-list a:hover,
.story-dataset-list a:focus {
  color: var(--story-blue) !important;
}

.story-form-page,
.story-confirm-page {
  padding: 28px 0 52px;
}

.story-form-panel,
.story-confirm-panel {
  padding: 22px;
}

.story-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.story-form-section {
  padding-bottom: 22px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--story-border) !important;
}

.story-form-section:last-of-type {
  margin-bottom: 0;
}

.story-form-section h2 {
  margin: 0 0 16px;
  color: var(--story-ink) !important;
  font-size: 1.18rem;
  line-height: 1.25;
}

.story-field {
  min-width: 0;
}

.story-field-wide {
  grid-column: 1 / -1;
}

.story-field label,
.story-field-label,
.story-checkbox {
  display: block;
  margin: 0 0 7px;
  color: var(--story-ink) !important;
  font-weight: 750;
}

.story-language-grid {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.story-language-grid label {
  min-height: 42px;
  display: flex;
  align-items: center;
  margin: 0;
  color: var(--story-muted) !important;
  font-size: 0.92rem;
  font-weight: 750;
}

.story-link-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) repeat(3, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.story-field textarea.story-form-control {
  min-height: 120px;
  resize: vertical;
}

.story-field textarea.story-content-editor {
  min-height: 330px;
}

.story-checkbox {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  margin-top: 25px;
}

.story-error {
  display: block;
  margin-top: 6px;
  color: var(--story-danger) !important;
  font-weight: 700;
}

.story-form-actions,
.story-confirm-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 20px;
  margin-top: 20px;
  border-top: 1px solid var(--story-border) !important;
}

.story-confirm-panel p {
  color: var(--story-muted) !important;
  line-height: 1.6;
}

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

@media (max-width: 900px) {
  .story-featured-grid,
  .story-grid,
  .story-read-hero-layout,
  .story-read-layout {
    grid-template-columns: 1fr;
  }

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

  .story-filter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .story-filter-grid input[type="search"] {
    grid-column: span 2;
  }

  .story-link-row {
    grid-template-columns: 1fr 1fr;
  }

  .story-read-sidebar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
  }

  .story-panel {
    margin-bottom: 0;
  }
}

@media (max-width: 640px) {
  .story-container {
    width: min(100% - 20px, 1180px);
  }

  .story-directory-head,
  .story-form-head,
  .story-confirm-head,
  .story-search {
    grid-template-columns: 1fr;
  }

  .story-directory-head,
  .story-form-head,
  .story-confirm-head {
    display: grid;
  }

  .story-search {
    display: grid;
  }

  .story-filter-grid input[type="search"] {
    grid-column: auto;
  }

  .story-language-grid,
  .story-link-row {
    grid-template-columns: 1fr;
  }

  .story-read-sidebar {
    grid-template-columns: 1fr;
  }

  .story-results-heading,
  .story-sort-form {
    align-items: stretch;
    flex-direction: column;
  }

  .story-results-count {
    margin: 0.45rem 0 0;
    color: var(--story-muted) !important;
    font-weight: 650;
  }

  .story-sort-select {
    width: 100%;
  }

  .story-sort-submit {
    width: 100%;
  }

  .story-button {
    width: 100%;
  }

  .story-read-actions,
  .story-form-actions,
  .story-confirm-actions {
    flex-direction: column;
  }
}
