/* ============================================================================
   MOBILE FIX - Smartphone-Optimierungen
   ============================================================================ */

/* Basis-Optimierungen für Touch-Geräte */
* {
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
  -webkit-touch-callout: none;
}

/* Verbesserte Touch-Targets (min. 44x44px) */
button, 
.btn, 
.tab, 
.choice,
input[type="button"],
input[type="submit"],
a {
  min-height: 44px;
  min-width: 44px;
  touch-action: manipulation;
}

/* Größere Buttons auf Mobile */
@media (max-width: 768px) {
  .btn, 
  button {
    padding: 14px 20px;
    font-size: 16px;
    line-height: 1.4;
  }
  
  .btn--primary {
    padding: 16px 24px;
    font-size: 17px;
  }
  
  /* Tab-Navigation größer */
  .tab {
    padding: 12px 16px;
    font-size: 15px;
  }
  
  /* Input-Felder größer */
  input[type="text"],
  input[type="date"],
  input[type="email"],
  input[type="tel"],
  input[type="number"],
  select,
  textarea {
    font-size: 16px !important; /* Verhindert Zoom auf iOS */
    padding: 12px 16px;
    min-height: 44px;
  }
  
  /* Textarea größer */
  textarea {
    min-height: 120px;
  }
  
  /* Quiz-Choices größer */
  .choice {
    padding: 16px 20px;
    font-size: 16px;
    margin-bottom: 12px;
  }
  
  /* Modal auf Mobile */
  .modal__card {
    width: 95%;
    max-width: 95vw;
    margin: 20px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
  }
  
  /* Onboarding Modal */
  #onboarding .modal__card {
    padding: 20px;
  }
  
  #onboarding .grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  
  /* Header kompakter auf Mobile */
  .topbar {
    padding: 8px 12px;
  }
  
  .brand {
    font-size: 18px;
    padding: 8px 12px;
  }
  
  /* Lehrjahr-Buttons kompakter */
  .yearBtn {
    padding: 8px 12px;
    font-size: 14px;
  }
  
  /* Panel-Header */
  .panel__header {
    padding: 16px;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  
  .panel__meta {
    width: 100%;
    flex-wrap: wrap;
  }
  
  /* Cards */
  .card {
    padding: 16px;
    margin-bottom: 16px;
  }
  
  /* Grid auf Mobile einspaltiger */
  .grid {
    grid-template-columns: 1fr !important;
    gap: 16px;
  }
  
  /* Glossar-Layout auf Mobile */
  .glossarLayout {
    flex-direction: column;
    gap: 0;
  }
  
  .glossarSide {
    width: 100%;
    max-width: 100%;
    border-right: none;
    border-bottom: 2px solid rgba(107,89,69,.18);
    max-height: 250px;
    overflow-y: auto;
    padding: 12px;
    background: rgba(255,255,255,.70);
    border-radius: 16px 16px 0 0;
  }
  
  .glossarMain {
    width: 100%;
    padding: 16px;
    background: rgba(255,255,255,.60);
    border-radius: 0 0 16px 16px;
    margin-top: -1px;
  }
  
  /* Glossar-Liste kompakter auf Mobile */
  .glossarSideList {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }
  
  .glossarItemBtn {
    padding: 10px 12px;
    font-size: 14px;
    text-align: left;
    border-radius: 10px;
    border: 1px solid rgba(107,89,69,.14);
    background: rgba(238,236,228,.75);
    cursor: pointer;
    transition: background 0.2s;
  }
  
  .glossarItemBtn:active,
  .glossarItemBtn.is-active {
    background: rgba(188,158,129,.75);
  }
  
  /* Glossar-TOC kompakter */
  .glossarToc {
    gap: 4px;
    margin-bottom: 10px;
  }
  
  .glossarToc a {
    min-width: 32px;
    height: 32px;
    font-size: 14px;
  }
  
  /* Glossar-Suche größer */
  #glossarySearch {
    font-size: 16px !important;
    padding: 12px;
  }
  
  /* Kalender auf Mobile */
  .calendar {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  .calendar table {
    min-width: 100%;
    font-size: 14px;
  }
  
  .calendar td,
  .calendar th {
    padding: 8px 4px;
    font-size: 13px;
  }
  
  /* Kalender-Grid Alternative */
  .calendarGrid {
    gap: 4px;
  }
  
  .calDay {
    min-height: 40px;
    font-size: 14px;
  }
  
  /* Leere Kalender-Zellen */
  .calDay--empty {
    background: transparent;
    border: none;
    cursor: default;
  }
  
  /* Heute-Markierung */
  .calDay.is-today {
    background: rgba(188,158,129,.85);
    border-color: rgba(107,89,69,.35);
    font-weight: 900;
  }
  
  /* Quiz auf Mobile */
  .quizTop {
    flex-direction: column;
    gap: 12px;
  }
  
  .quizTop__left,
  .quizTop__right {
    width: 100%;
    justify-content: space-between;
  }
  
  /* Footer kompakter */
  footer {
    padding: 16px;
    font-size: 13px;
  }
  
  /* Scrollbars auf Mobile verstecken */
  .glossarSideList::-webkit-scrollbar,
  .calendar::-webkit-scrollbar {
    width: 4px;
  }
  
  .glossarSideList::-webkit-scrollbar-thumb,
  .calendar::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
  }
}

/* Extra kleine Geräte (Phones < 375px) */
@media (max-width: 374px) {
  .btn, button {
    padding: 12px 16px;
    font-size: 15px;
  }
  
  .tab {
    padding: 10px 12px;
    font-size: 14px;
  }
  
  .brand {
    font-size: 16px;
  }
  
  .modal__card {
    width: 100%;
    margin: 10px;
    max-height: calc(100vh - 20px);
  }
}

/* Landscape-Modus auf Smartphones */
@media (max-width: 896px) and (orientation: landscape) {
  .modal__card {
    max-height: calc(100vh - 20px);
    overflow-y: auto;
  }
  
  .topbar {
    padding: 6px 12px;
  }
  
  .panel__header {
    padding: 12px;
  }
}

/* Touch-Feedback für interaktive Elemente */
@media (hover: none) and (pointer: coarse) {
  button:active,
  .btn:active,
  .tab:active,
  .choice:active {
    transform: scale(0.98);
    opacity: 0.9;
  }
  
  .glossarItemBtn:active {
    background: rgba(0, 0, 0, 0.1);
  }
}

/* Verbesserte Lesbarkeit auf kleinen Bildschirmen */
@media (max-width: 768px) {
  body {
    font-size: 16px;
    line-height: 1.6;
  }
  
  h1, .h1 {
    font-size: 24px;
  }
  
  h2, .h2 {
    font-size: 20px;
  }
  
  h3, .h3 {
    font-size: 18px;
  }
  
  /* Bessere Abstände */
  .panel {
    padding: 16px;
  }
  
  .divider {
    margin: 16px 0;
  }
  
  /* Hilfe-Texte kleiner */
  .help,
  .muted {
    font-size: 14px;
  }
}

/* Safe Area für iPhone X und neuere Modelle */
@supports (padding: max(0px)) {
  body {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
  }
  
  .topbar {
    padding-top: max(8px, env(safe-area-inset-top));
  }
  
  footer {
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
}

/* Verhindere Zoom bei Input-Focus auf iOS */
@media (max-width: 768px) {
  input[type="text"]:focus,
  input[type="date"]:focus,
  input[type="email"]:focus,
  input[type="tel"]:focus,
  input[type="number"]:focus,
  select:focus,
  textarea:focus {
    font-size: 16px !important;
  }
}

/* Optimierte Scrollbars für Touch-Geräte */
@media (max-width: 768px) {
  * {
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
  }
}
