:root {
      /* Responsive heading font size */
      --fs-h1: clamp(1.5rem, 2.6vw, 2.25rem);

      /* Base font size with a minimum of 16px for readability/accessibility */
      --fs-base: max(16px, clamp(.95rem, 1.1vw, 1rem));
    }

     /* Prevent horizontal overflow on the full page */
     html, body{
      width: 100%;
      overflow-x: hidden;
    }

    /* Form wrapper is intentionally narrower than the gallery layout */
    .wrap {
      width: min(720px, 100% - 32px);
      margin-inline: auto;
      padding: 16px 0
    }
    
    /* --- Upload form layout ---*/

    form {
      display: grid;
      gap: 14px;
      font-size: var(--fs-base)
    }
   
    /* Paragraph blocks inside the form use a small vertical layout */
    form p{
      margin: 0;
      display: grid;
      gap: 6px;              
      justify-items: start;  
    }

    /* Labels inside form paragraphs are aligned inline with small spacing */
    form p > label{
      display: inline-flex;
      align-items: center;
      gap: 6px;
    }

    /* Default label weight */
    label {
      font-weight: 600
    }

     /* Fields grouped in fieldsets */
    fieldset.form-group {
      border: 0;
      padding: 0;
      margin: 0 0 18px;

      /* Prevent overflow issues inside flex/grid parents */
      min-inline-size: 0; /* verhindert Overflow in flex/grid */
    }

    /* Legend styling for grouped form sections */
    fieldset.form-group > legend {
      display: inline-flex;
      align-items: center;
      gap: 6px;

      font-weight: 600;
      font-size: var(--fs-base);
      margin-bottom: 8px;
      padding: 0;
    }

    /* Small spacing before required asterisk or similar hidden markers */
    fieldset.form-group > legend span[aria-hidden="true"] {
      margin-left: 4px;
    }

    /* Vertical spacing between direct children of a form group */
    fieldset.form-group > * + * {
      margin-top: 10px;
    }

    /* Inline label row helper */
    fieldset.form-group .label-row {
      display: inline-flex;
      align-items: center;
      gap: 6px;
    }

    /* Shared layout for legends with help icons */
    .legend-row {
      display: flex;
      align-items: center;
      gap: 6px;
    }

    /* Reset default legend spacing */
    legend {
      margin: 0;
      padding: 0;
    }

    /* Base text field styling */
    input[type="text"],
    input[type="file"],
    input[type="password"],
    textarea {
      width: 100%;
      padding: 12px 14px;
      border: 1px solid var(--border);
      border-radius: 10px;
      background: var(--bg);
      color: var(--text);
      font-size: var(--fs-base);
    }
   
    /* Default textarea behavior and minimum height */
    textarea {
      resize: vertical;
      min-height: 110px;
      overflow: hidden;
    }

    /* Links textarea is intentionally more compact */
    textarea[name="extra_links"] {
      min-height: 0;
      height: 40px;
      max-height: 140px;
    }

    /* - Generic drag & drop area styles (cover/images/docs) - */

    .dropzone {
      position: relative;
      border: 1px dashed var(--border);
      background: var(--bg);
      border-radius: 12px;
      padding: 18px;
      display: grid;
      gap: 8px;
      place-items: center;
      text-align: center;
      cursor: pointer;
      transition: .2s
    }

    /* Hover state for dropzones */
    .dropzone:hover {
        outline: 3px solid var(--focus-color) !important;
        outline-offset: 3px !important;
        border-radius: 10px !important;          
        background: var(--grey) !important;
    }

    /* Visual feedback when files are dragged over the dropzone */
    .dropzone.dragover {
      border-color: var(--field-br-focus);
      background: var(--card);
      box-shadow: 0 0 0 3px  var(--grey)  inset
    }

    /* Upload/dropzone icon */
    .dz-icon {
      width: 34px;
      height: 34px;
      fill: var(--text)
    }

    /* Main title inside the dropzone */
    .dz-title {
      font-weight: 700
    }

    /* Helper text inside the dropzone */
    .dz-hint {
      color: var(--muted);
      font-size: .95em
    }

    /* Visually hide native file inputs */
    .visually-hidden {
      position: absolute !important;
      width: 1px;
      height: 1px;
      overflow: hidden;
      clip: rect(0, 0, 0, 0)
    }

    /* Hide the native cover file input while keeping it accessible */
    #id_image {
      position: absolute !important;
      width: 1px;
      height: 1px;
      padding: 0;
      margin: -1px;
      overflow: hidden;
      clip: rect(0 0 0 0);
      white-space: nowrap;
      border: 0;
    }

    /* - Thumbs with alt-input textfield -*/

    /* Alt-text input fields shown below image/video previews */
    .alt-field{
      width: 100%;
      font-size: 0.9rem;
      line-height: 1.25;
      padding: 10px 12px;
      border: 1px solid var(--field-br);
      border-radius: 10px;
      background: var(--bg);
      color: var(--text);
      resize: none;
      overflow: hidden;

      /* Override the global textarea minimum height */
      min-height: 0 !important;
      height: auto;

      /* Allow long text to wrap cleanly */
      white-space: pre-wrap;
      overflow-wrap: anywhere;
    }

    /* Override base thumbnail layout because alt text needs extra vertical space */
    /* Wider thumbnail grid */
    #coverThumbs.thumbs,
    #extraThumbs.thumbs,
    #videoList.thumbs,
    #docList.thumbs{
      display: grid;
      gap: 12px;
      grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr));
      margin-top: 18px !important;
    }

    /* Thumbnail boxes become variable height to fit text fields underneath */
    #coverThumbs .thumb,
    #extraThumbs .thumb,
    #videoList .thumb,
    #docList .thumb{
      position: relative;
      aspect-ratio: auto;        /* override base.css 1/1 */
      overflow: visible;         /* override base.css hidden */
      display: grid;
      gap: 8px;
      padding: 10px;
      align-content: start;
      min-width: 0;
      max-width: 320px;
    }

    #coverThumbs .thumb[hidden],
    #extraThumbs .thumb[hidden],
    #videoList .thumb[hidden],
    #docList .thumb[hidden] {
      display: none !important;
    }

    /* Documents use a separate, denser grid */
    #docList.thumbs{
      display: grid;
      gap: 12px;
      grid-template-columns: repeat(auto-fit, minmax(min(160px, 100%), 220px));
      justify-content: start;
    }

    /* Document thumbnail box layout */
    #docList .thumb{
      position: relative;
      width: 100%;
      aspect-ratio: 1 / 1;
      overflow: hidden;

      display: grid;
      grid-template-rows: auto auto;
      justify-items: center;
      align-content: center;
      gap: 10px;

      padding: 12px;
      min-width: 0; 
    }

    /* Larger file icon inside document thumbnails */
    #docList .file-emoji svg{
      width: 32px;
      height: 32px;
    }

    /* Filename is clamped to two lines */
    #docList .file-label{
      max-width: 100%;
      min-width: 0;

      font-size: .85rem;
      line-height: 1.2;
      text-align: center;

      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;

      overflow: hidden;
      word-break: break-word;
    }

    /* Position the remove button in the top-right corner of document thumbs */
    #docList .thumb .x{
      position: absolute;
      top: 10px;
      right: 10px;
    }

    /* Extra image thumbnails allow space for inputs below the preview */
    #coverThumbs .thumb img,
    #extraThumbs .thumb img,
    #videoList .thumb img{
      border-radius: 10px;
      display: block;
      width: 100%;
      height: auto;           
      max-height: 160px;      
      object-fit: cover;
    }

    /* Video thumbnails should visually match image thumbnails */
    #videoList .thumb video{
      border-radius: 10px;
      display: block;
      width: 100%;
      height: auto;           
      max-height: 160px;      
      object-fit: cover;
    }
    
    /* Position the remove button slightly more inward on media previews */
    #coverThumbs .thumb .x,
    #extraThumbs .thumb .x,
    #videoList .thumb .x{
      top: 14px;
      right: 14px;
    }

    /* Reset list styling for thumbnail containers */
    ul.thumbs,
    .thumbs {
      margin: 0 !important;
      padding: 0 !important;
      padding-inline-start: 0 !important;
      list-style: none !important;
    }

    /* Reset list item spacing */
    ul.thumbs li {
      margin: 0;
      padding: 0;
    }

    /* Add more space between dropzones and the thumbnail list below */
    .dropzone + ul.thumbs,
    .dropzone + .thumbs {
      margin-top: 18px !important;
    }

    /* Optional additional spacing after hint text */
    .dz-hint + ul.thumbs {
      margin-top: 18px !important;
    }

    /* Keep long titles/hints centered and wrapped */
    .dz-title,
    .dz-hint {
      width: 100%;
      text-align: center;
      margin: 0 auto;
      overflow-wrap: anywhere;
      word-break: break-word;
    }

    /* Prevent file names and alt fields from overflowing their container */
    .file-name,
    .alt-field{
      min-width: 0;
      max-width: 100%;
    }

    .file-name{
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
      overflow: hidden;
      max-width: 100%;
      min-width: 0;
      font-size: .85rem;
      line-height: 1.2;
      word-break: break-word;
      overflow-wrap: anywhere;
    }

    /* - Toggle button for selfmade yes/no -*/

    /* Full-width toggle container */
    .toggle-btns {
      display: flex;
      width: 100%;
      overflow: hidden;
      border-radius: 10px;
      background: var(--button-focused); 
      border: 1px solid var(--border);
    }

    /* Individual toggle buttons */
    .toggle-btns > button {
      flex: 1;
      min-height: 44px;              /* WCAG touch target */
      padding: 10px 14px;
      border: 0;
      background: transparent;
      color: var(--text);
      cursor: pointer;
      transition: background .2s, color .2s;
    }

    /* Divider between the two toggle buttons */
    .toggle-btns > button + button {
      border-left: 1px solid var(--border);
    }

    /* Active toggle state */
    .toggle-btns > button[aria-pressed="true"] {
      background: var(--selfmade);
      color: var(--button-focused);
      font-weight: 600;
      position: relative;
    }

    /* Toggle-specific focus state overriding the global focus-visible rule */
    .toggle-btns > button:focus,
    .toggle-btns > button:focus-visible{
      outline: none !important;              /* kill global outline */
      outline-offset: 0 !important;
      background: inherit !important;        /* kill global focus background overlay */
      box-shadow: inset 0 0 0 3px var(--focus-color);  /* inner focus ring */
    }

    /* Keep the active button green even while focused */
    .toggle-btns > button[aria-pressed="true"]:focus,
    .toggle-btns > button[aria-pressed="true"]:focus-visible{
      background: var(--selfmade) !important;        /* force green */
      color:var (--bg) !important;
    }

    /* Checkmark shown on the active toggle option */
    .toggle-btns > button[aria-pressed="true"]::before {
      content: "✓";
      margin-right: 6px;
      font-weight: 900;
    }
    
    /* - Help icon - */
    
    .label-row{
      display: inline-flex;
      align-items: center;
      gap: 6px;
    }

    /* Wrapper for help icon and tooltip */
    .help {
      position: relative;
      display: inline-block;
      margin-left: 6px;
      cursor: default;;
    }

    /* Circular help icon button */
    .help .help-icon{
      width: 18px;
      height: 18px;
      display: inline-grid;
      place-items: center;
      border-radius: 50%;
      background: var(--button-focused);
      color: var(--text);
      font-size: 12px;
      font-weight: 700;
      line-height: 1;      
      padding: 0;          
      border: 0;
      cursor: help;
    }

    /* Slight optical correction for the question mark glyph */
    .help .help-icon .q{
      display: inline-block;
      transform: translateX(0.7px) translateY(0.5px); 
    }

    /* Custom focus ring for the help icon */
    .help .help-icon:focus-visible{
      outline: 2px solid  var(--text);
      outline-offset: 2px;
    }

    /* Tooltip bubble */
    .help .tooltip {
      position: absolute;
      bottom: 125%;
      left: 50%;
      transform: translateX(-50%);
      background: var(--button-focused);
      color:  var(--text);
      padding: 8px 10px;
      border-radius: 8px;
      font-size: 0.85rem;
      white-space: nowrap;
      opacity: 0;
      pointer-events: none;
      transition: opacity .15s ease;
      box-shadow: 0 4px 12px var(--shadow-lg);
      z-index: 10;
      max-height: 90vh;
      overflow-y: auto;
    }

    /* Hidden tooltip should not take up layout space */
    .tooltip[hidden] { display: none; }

    /* Tooltip state when opened via keyboard/touch/JS */
    .help.open .tooltip {            /* Enter/Space/Touch */
      opacity: 1;
      pointer-events: auto;
    }

    /* On small screens, move tooltip to the bottom as a floating panel */
    @media (max-width: 900px){
      .help .tooltip{
        position: fixed;
        left: 50%;
        bottom: 16px;
        top: auto;
        transform: translateX(-50%);
        max-width: min(92vw, 360px);
        white-space: normal;
        overflow-wrap: anywhere;
        word-break: break-word;
        z-index: 9999;
      }
    }

    /* Placeholder styling for textareas */
    textarea::placeholder {
      color: var(--muted);    
      font-style: italic; 
      opacity: 0.7;         
    }

    /* Placeholder styling while the textarea is focused */
    textarea:focus::placeholder {
      color: (--muted);     
    }

    /* Error message box */
    .error-text {
      margin-top: 10px;
      padding: 10px 12px;
      border: 1px solid var(--danger);
      border-radius: 10px;
      background: var(--danger-dark);
      color: var( --danger-light);
      font-size: 0.95rem;
      line-height: 1.4;
    }

    @media (prefers-color-scheme: light) {
      .error-text {
      margin-top: 10px;
      padding: 10px 12px;
      border: 1px solid var(--danger);
      border-radius: 10px;
      background: var(--danger-light);
      color: var( --danger);
      font-size: 0.95rem;
      line-height: 1.4;
    }
  }

    /* Ensure visible error blocks are displayed */
    .error-text:not(.visually-hidden) {
      display: block;
    }

    /* Error state for invalid dropzones */
    .dropzone[aria-invalid="true"] {
      border-color: var(--danger) !important;
      box-shadow: 0 0 0 3px (--danger-dark);
    }

    /* - Submit overlay - */

     .submit-processing-overlay{
      position: fixed;
      inset: 0;
      z-index: 10000;
      display: grid;
      place-items: center;
      padding: 20px;
      background: var(--bg);
      backdrop-filter: blur(3px);
    }

    .submit-processing-overlay[hidden]{
      display: none !important;
    }

    .submit-processing-box{
      width: min(560px, 100%);
      background: var(--card);
      color: var(--text);
      border: 2px solid var(--selfmade);
      border-radius: 20px;
      box-shadow: var(--shadow-lg);
      padding: clamp(20px, 4vw, 32px);
      text-align: center;
    }

    .submit-processing-title{
      margin: 0 0 10px;
      font-size: clamp(1.2rem, 2vw, 1.6rem);
      line-height: 1.2;
    }

    .submit-processing-text{
      margin: 0;
      font-size: 1rem;
      line-height: 1.5;
      color: var(--muted);
    }

    .submit-processing-spinner{
      width: 54px;
      height: 54px;
      margin: 0 auto 18px;
      border-radius: 50%;
      border: 4px solid var(--grey);
      border-top-color: var(--selfmade);
      animation: submitSpin .8s linear infinite;
    }

    @keyframes submitSpin{
      to { transform: rotate(360deg); }
    }

    .green-btn[aria-busy="true"]{
      opacity: .85;
      pointer-events: none;
    }
