:root {
  --nav-height: 2.5rem;
  --hu-blue-primary: #00376c;
  --hu-blue-secondary: #d7dde1;
  --hu-blue-hover: #99c2ff;
  --hu-margin: 0.4rem;
  --hu-padding: 0.4rem;
  --hu-padding2: 0.8rem;
  --hu-gap: 0.6rem;
  --hu-gap2: 0.3rem;
  --hu-panel-width: 400px;
  --hu-sparrow: "Sparrow 13:";
}

/* ===== GLOBAL ===== */
* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, sans-serif;
  overflow: hidden; /* verhindert doppeltes Scrollen */
  scrollbar-gutter: stable;
}

button {
    background-color: white;
    color: black;
    border: none;
    padding: 5px 10px;
    font-size: 1.2rem;
    cursor: pointer;
}

textarea {
  font-family: system-ui, sans-serif;
  font-size: 1rem;
}

input[type="text"] {
  font-family: system-ui, sans-serif;
  font-size: 1rem;
  width: 100%;
}

details details {
    margin-left: 0.25rem;
}

details div {
    margin-left: 1.25rem;
}

.tree summary,
.tree div {
    color: #0000ee;
    cursor: pointer;
    text-decoration: underline;
}

.tree summary::marker {
    color: black;
}

.spinner {
  width: 20vmin;
  height: 20vmin;
  border-width: 5vmin;
  border-style: solid;
  border-color: var(--hu-blue-secondary);
  border-top-color: var(--hu-blue-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: var(--hu-margin) auto;
}

.spinner-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.3); /* optional: dunkler Hintergrund */
  z-index: 9999;
}

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

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

#master {
  position: absolute;
  inset: 0;
  
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;

  background-color: var(--hu-blue-primary);
}

/* ===== NAVIGATION ===== */
#nav, #nav2 {
  grid-row: 1;

  display: flex;
  gap: var(--hu-gap);
  align-items: center;
  padding: var(--hu-padding);

  background: var(--hu-blue-primary);
}

#nav a, #nav2 a {
  display: inline-block;
  padding: var(--hu-padding);
  background: white;
  border: 1px solid #ccc;
  text-decoration: none;
  color: black;
}

#nav a:hover, #nav2 a:hover {
  background: var(--hu-blue-hover);
}

#panel-container {
  grid-row: 2;

  display: grid;
  grid-template-columns: repeat(4, var(--hu-panel-width));
  grid-template-rows: 1fr auto;
  min-height: 0;
  height: 100%;
  column-gap: var(--hu-gap);

  overflow-x: auto;
  overflow-y: hidden;
}

.icon {
    width: 1rem;
    height: 1rem;
    transform: scale(1.5);
}

#p1 {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: 8fr 2fr auto;
  gap: var(--hu-gap);
  height: 100%;
  min-height: 0;
}

#chatOutput {
  padding: var(--hu-padding);
  min-height: 0;           
  overflow-y: auto;
  background-color: var(--hu-blue-secondary);
}

#chatOutputBtn {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 8px;   /* Abstand zwischen den Buttons */
}

#chatInput {
/*  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: 1fr auto;
  gap: 10px; */
  height: 100%;
  min-height: 0;
  min-width: 0;
  width: 100%;
}

#chatInput > textarea {
  min-width: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
/*  height: 100%;
  min-height: 0;
  overflow-y: auto;
*/  
  padding: var(--hu-padding);
  resize: none;
}


#chatInputBtn {
  display: flex;
/*  flex-direction: column; */
  align-items: center;
  gap: 8px;   /* Abstand zwischen den Buttons */
}
/*
#chatInputButton  {
  display: block;            /* Macht das Input zu einem Block-Element 
  width: 100%;
  height: 100%;              /* Füllt jetzt die volle Höhe der Zeile aus 
  padding: var(--hu-padding);
/ *  
  margin: 0;
  padding: 8px var(--hu-padding, 8px);

  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  resize: none;
  padding: var(--hu-padding);
  * /
}*/

#chatQuestion {
  min-width: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  display: flex; /* Baut Flexbox auf */
}

#questionMessage {
  width: 100%;
  height: 100%;
  box-sizing: border-box; /* Verhindert, dass Padding das Input über 100% vergrößert */
  padding: var(--hu-padding); /* Gleiches Padding wie im Textarea verwenden */
  font-family: inherit;
  font-size: inherit;
}

#chatButton {
  display: flex;
  flex-direction: column;
  gap: 8px;   /* Abstand zwischen den Buttons */
}



#chat {
  display: flex;
  flex-direction: column;
  gap: 8px;   /* Abstand zwischen den Buttons */
}

#chatBar {
  grid-column: 1;
  grid-row: 2;
}

.rio {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
 
#p2 {
  grid-column: 2;
  grid-row: 1;

  display: grid; 
  grid-template-rows:  minmax(0, 2fr) minmax(0, 3fr) minmax(0, 2fr); 
  gap: var(--hu-gap);
  
  height: 100%;
  min-height: 0;
   min-width: 0;
}

#help {
  overflow-y: auto;    
  min-height: 0;
  height: 100%;  
  background-color: var(--hu-blue-secondary);
  padding: var(--hu-padding);
}

#exerciseselect {
  background-color: white;  
  display: flex;
  flex-direction: column;
  padding: var(--hu-padding);
  min-height: 0;
  height: 100%;
}

#exerciseselect b {
  flex: 0 0 auto;
}

#vanillatree {
  flex: 1;
  overflow-y: auto;           /* Scrollbalken nur IM Tab, falls der Text zu lang ist */
  min-height: 0;
  padding: var(--hu-padding);
  background-color: white;  
}

#exerciseHistory {
  padding: var(--hu-padding);
  background-color: var(--hu-blue-secondary);
  
  /* NEU: Macht den Verlauf zum Flex-Container, damit die Kinder (linkList) flexibel sind */
  display: flex;
  flex-direction: column;
  
  /* NEU: Verhindert, dass das Grid-Element durch großen Inhalt gesprengt wird */
  min-height: 0; 
  min-width: 0;
}

#linkList {
  flex: 1;
  overflow-y: auto;   /* Hier reicht das Scrollen völlig aus */
  min-height: 0;
  min-width: 0;
}

#recent {
  padding: var(--hu-padding);
  margin: 0;
  list-style: none; /* Optional: Schickere Listenoptik */
  min-width: 0;
}

#recent li {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#p3 {
  grid-column: 3;
  grid-row: 1;

  display: grid;
  grid-template-rows: minmax(0, 1fr);
  gap: var(--hu-gap);

  min-height: 0;
  min-width: 0;
}
/*
#p3 {
  grid-column: 3;
  grid-row: 1;

  display: grid; 
  grid-template-rows: 1fr;
  gap: var(--hu-gap);
  
  height: 100%;
  min-height: 0;
}
*/

/*
#calcOutput {
  background-color: var(--hu-blue-secondary);
  color: black;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  font-size: 1.2rem;
}
*/

#formOutput {
  background-color: var(--hu-blue-secondary);
/*  margin-top: var(--hu-padding2); */
  padding: var(--hu-padding);
  overflow-y: auto;
  color: black;
  min-height: 0;
  height: 100%;
}

#p4 {
  grid-column: 4;
  grid-row: 1;

  display: grid; 
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); 
  gap: var(--hu-gap);
  
  height: 100%;
  min-height: 0;
}

#impressum {
  background-color: var(--hu-blue-secondary);
  padding: var(--hu-padding);
  overflow-y: auto;
  min-height: 0;
}

#datenschutzerklaerung {
  background-color: var(--hu-blue-secondary);
  padding: var(--hu-padding);
  overflow-y: auto;
  min-height: 0;
}

#exerciseBar {
  grid-column: 2;
  grid-row: 2;
}

#formInput {
  grid-column: 3;
  grid-row: 2;
}

#impressumInput {
  grid-column: 4;
  grid-row: 2;
}

/* Used in the introduction text */
#intro {
  display: grid; 
  grid-auto-flow: column; 
  grid-template-columns: 150px 1fr; 
  gap: var(--hu-gap);
}

#intro-img {
  width: 150px; 
  height: auto; 
  display: block;
}

#intro-col {
  display: flex; 
  flex-direction: column; 
  align-items: flex-start;
}

#intro-wrap {
  width: min(100%, 50ch); 
  display: table;
}

#intro-head {
  margin: 0 0 var(--hu-margin) 0;
  white-space: normal; 
  display: block; 
  font-family: sans-serif;
}

#intro-sparrow {
  width: 100%; 
  display: block; 
  height: auto;
}

.error-box {
    padding: var(--hu-padding);
    border-radius: 0.5rem;
    border: 0.125rem solid red;
    box-shadow: 0 0.125rem 1rem rgba(0, 0, 0, 0.3);
    font-family: sans-serif;
    text-align: center;
}

.error-box[open] {
    position: fixed;
    top: 50%;
    left: 50%;
    margin: 0;

    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--hu-gap);
}

.error-box p {
    margin: 0;
}

.error-box button {
    padding: var(--hu-padding)  var(--hu-padding2);
    cursor: pointer;
    border-radius: 0.125rem;
    border: 0.125rem solid #ccc;
    background-color: #f0f0f0;
}

#impressum {
  padding: var(--hu-padding);
  background-color: var(--hu-blue-secondary);
  height: 100%;
}

.button-bar {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
  padding-bottom: var(--hu-padding);
  padding-top: var(--hu-padding);
  column-gap: var(--hu-gap);
}

/*
#formInput, #impressumBar, #exerciseBar, #chatBar {
  margin-top: var(--hu-gap);
}
  */

@media print {

  /* =========================================
     SEITE / BODY FREIGEBEN
     ========================================= */

  html,
  body {
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;

    margin: 0 !important;
    padding: 0 !important;

    overflow: visible !important;
  }


  /* =========================================
     GRUNDSÄTZLICH NICHT DRUCKEN
     ========================================= */

  body * {
    visibility: hidden !important;
  }


  /* =========================================
     NUR DIE BEIDEN AUSGABEN SICHTBAR
     ========================================= */

  #chatOutput,
  #chatOutput *,
  #calcOutput,
  #calcOutput * {
    visibility: visible !important;
  }


  /* =========================================
     ÜBERGEORDNETE CONTAINER
     ========================================= */

  #master,
  #panel-container,
  #p1 {
    display: block !important;

    position: static !important;

    width: auto !important;
    height: auto !important;

    min-width: 0 !important;
    min-height: 0 !important;

    max-width: none !important;
    max-height: none !important;

    overflow: visible !important;

    transform: none !important;
  }


  /* =========================================
     NICHT BENÖTIGTE BEREICHE ENTFERNEN
     ========================================= */

  #nav,
  #p2,
  #p3,
  #p4,
  #chatOutputBtn,
  #chatInput,
  #chatInputBtn,
  #chatQuestion,
  #chatQuestionBtn,
  #calcInput,
  #formOutput,
  #chatBar,
  #exerciseBar,
  #formInput,
  #impressumInput {
    display: none !important;
  }


  /* =========================================
     CHAT
     ========================================= */

  #chatOutput {
    display: block !important;

    position: static !important;

    width: 100% !important;
    height: auto !important;

    min-width: 0 !important;
    min-height: 0 !important;

    max-width: none !important;
    max-height: none !important;

    overflow: visible !important;

    box-sizing: border-box !important;

    background: white !important;
    color: black !important;

    transform: none !important;

    /* Mehrseitigen Inhalt erlauben */
    break-inside: auto !important;
    page-break-inside: auto !important;

    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }


  /* =========================================
     NEBENRECHNUNG
     ========================================= */

  #calcOutput {
    display: block !important;

    position: relative !important;

    width: 100% !important;
    height: auto !important;

    min-width: 0 !important;
    min-height: 0 !important;

    max-width: none !important;
    max-height: none !important;

    overflow: visible !important;

    box-sizing: border-box !important;

    background: white !important;
    color: black !important;

    transform: none !important;

    /* Trennung */
    border-top: 1px solid black !important;

    margin-top: 10mm !important;
    padding-top: 10mm !important;

    /* Mehrseitigen Inhalt erlauben */
    break-inside: auto !important;
    page-break-inside: auto !important;

    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }


  /* =========================================
     BESCHRIFTUNG
     ========================================= */

  #calcOutput::before {
    content: var(--print-calc-title);

    position: absolute !important;

    top: -0.7em !important;
    left: 50% !important;

    transform: translateX(-50%) !important;

    background: white !important;

    padding: 0 5mm !important;

    font-weight: bold !important;
    color: black !important;

    white-space: nowrap !important;
  }


  /* =========================================
     A4
     ========================================= */

  @page {
    size: A4;
    margin: 15mm;
  }
}