/* Verbesserte Responsive CSS für Borbarad - Mobile-First Approach */

:root{
  --tap-target: 44px; /* Mindest-Touch-Größe für mobile Geräte */
  --mobile-padding: 16px;
  --mobile-gap: 12px;
}

/* Mobile-First: Basis-Styles für mobile Geräte */
* {
  box-sizing: border-box;
}

/* Touch-freundliche Buttons und Eingabefelder */
.btn, 
input, 
select, 
textarea {
  min-height: var(--tap-target);
  font-size: 16px; /* Verhindert Zoom auf iOS */
}

.btn {
  padding: 12px 16px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* Navigation für Mobile optimieren */
@media (max-width: 860px) {
  .topbar {
    position: sticky;
    top: 0;
    z-index: 1000;
    padding: 12px var(--mobile-padding);
    background: rgba(14, 10, 15, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }
  
  .brand {
    font-size: 16px;
    line-height: 1.2;
    max-width: 50vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  
  .menu {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    mask: linear-gradient(90deg, transparent, black 20px, black calc(100% - 20px), transparent);
    -webkit-mask: linear-gradient(90deg, transparent, black 20px, black calc(100% - 20px), transparent);
  }
  
  .menu::-webkit-scrollbar {
    display: none;
  }
  
  .menu a {
    padding: 10px 14px;
    white-space: nowrap;
    border-radius: 20px;
    min-width: max-content;
  }
  
  .authbox {
    flex-direction: column;
    gap: 6px;
  }
  
  .authbox .btn {
    padding: 8px 12px;
    font-size: 14px;
    min-height: 36px;
  }
}

/* Layout-Anpassungen für Tablets und Mobile */
@media (max-width: 768px) {
  .app {
    padding: var(--mobile-padding);
    gap: var(--mobile-gap);
  }
  
  .card {
    padding: var(--mobile-padding);
    border-radius: 12px;
  }
  
  .row, .grid {
    grid-template-columns: 1fr !important;
    gap: var(--mobile-gap);
  }
  
  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: var(--mobile-gap);
  }
  
  .toolbar > * {
    width: 100%;
  }
  
  .toolbar > div {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }
}

/* Formulare mobile-optimiert */
@media (max-width: 768px) {
  .input, select, textarea {
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    font-size: 16px; /* Verhindert iOS Zoom */
  }
  
  .label {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 6px;
  }
  
  /* Spezielle Behandlung für Datum-Picker */
  .date-picker-row {
    display: grid;
    grid-template-columns: 1fr 2fr 1fr;
    gap: 8px;
    align-items: end;
  }
}

/* TABELLEN RESPONSIVE MACHEN - KORRIGIERTE VERSION */
@media (max-width: 768px) {
  .table-wrapper {
    position: relative;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--panel);
  }
  
  /* WICHTIG: Tabelle bleibt als Tabelle sichtbar */
  .table {
    min-width: 600px; /* Mindestbreite für Lesbarkeit */
    width: 100%;
    display: table !important; /* Explizit als Tabelle */
    border-collapse: collapse;
  }
  
  .table thead {
    display: table-header-group !important;
  }
  
  .table tbody {
    display: table-row-group !important;
  }
  
  .table tr {
    display: table-row !important;
  }
  
  .table th,
  .table td {
    display: table-cell !important;
    padding: 12px 8px;
    white-space: nowrap;
    vertical-align: top;
  }
  
  /* Scroll-Indikator für horizontales Scrollen */
  .scroll-indicator {
    position: sticky;
    left: 0;
    top: 0;
    background: linear-gradient(90deg, var(--accent), transparent);
    color: white;
    padding: 6px 12px;
    font-size: 12px;
    text-align: center;
    z-index: 2;
    display: none; /* Wird per JavaScript aktiviert */
  }
  
  /* Hover-Effekte für Touch-Geräte entfernen */
  .table tr:hover {
    background: transparent;
  }
  
  .table tr:active,
  .table tr.active {
    background: var(--panel-soft);
  }
}

/* Sehr kleine Screens - Tabelle bleibt trotzdem sichtbar */
@media (max-width: 480px) {
  .table {
    min-width: 500px; /* Etwas schmaler aber immer noch scrollbar */
    font-size: 14px;
  }
  
  .table th,
  .table td {
    padding: 8px 6px;
  }
  
  /* Avatars in Tabellen kleiner */
  .table img {
    width: 28px !important;
    height: 28px !important;
    border-radius: 6px;
  }
}

/* NSC/Object Zeilen-spezifische Fixes */
@media (max-width: 768px) {
  .nsc-row, .obj-row, .diary-row {
    cursor: pointer;
    transition: background-color 0.2s ease;
    display: table-row !important;
  }
  
  .nsc-row:active, .obj-row:active, .diary-row:active {
    background: var(--panel-soft) !important;
    transform: scale(0.98);
  }
  
  .nsc-row td, .obj-row td, .diary-row td {
    display: table-cell !important;
  }
  
  /* Avatar-Größen in Zeilen anpassen */
  .nsc-row img, .obj-row img {
    width: 32px !important;
    height: 32px !important;
    border-radius: 6px;
  }
}

/* Kalender mobile Optimierungen */
@media (max-width: 768px) {
  .cal-grid {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 6px;
  }
  
  .cal-cell {
    min-height: 100px;
    padding: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
  }
  
  .cal-cell:active {
    transform: scale(0.95);
    background: var(--panel-soft);
  }
  
  .cal-toolbar {
    background: var(--panel-soft);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 8px;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  
  .cal-left {
    width: 100%;
    justify-content: center;
    margin-bottom: 12px;
  }
  
  .cal-right {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }
  
  .cal-legend {
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 12px;
    justify-content: space-between;
  }
  
  .cal-legend label {
    flex: 1;
    text-align: center;
    padding: 8px;
    background: var(--panel);
    border-radius: 6px;
    border: 1px solid var(--line);
    min-width: 120px;
  }
  
  .cal-legend input[type="checkbox"] {
    margin-right: 6px;
  }
  
  .chip {
    font-size: 10px;
    padding: 2px 6px;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

@media (max-width: 480px) {
  .cal-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

/* Modal Optimierungen */
@media (max-width: 768px) {
  .modal {
    padding: 0;
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(4px);
    align-items: flex-end; /* Modal von unten schieben */
  }
  
  .modal .panel {
    width: 100%;
    height: auto;
    max-width: none;
    max-height: 95vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 16px 16px 0 0;
    margin: 0;
    padding: 20px;
    position: relative;
    animation: slideUp 0.3s ease-out;
  }
  
  /* Drag-Indikator */
  .modal .panel::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: var(--line-strong);
    border-radius: 2px;
  }
  
  /* Modal-Header für Mobile */
  .modal h3:first-child {
    margin-top: 16px;
    text-align: center;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
  }
  
  /* Modal-Buttons sticky am Bottom */
  .modal .toolbar {
    position: sticky;
    bottom: 0;
    background: var(--panel);
    margin: 16px -20px -20px -20px;
    padding: 16px 20px;
    border-top: 1px solid var(--line);
    border-radius: 0 0 16px 16px;
  }
  
  @keyframes slideUp {
    from {
      transform: translateY(100%);
      opacity: 0;
    }
    to {
      transform: translateY(0);
      opacity: 1;
    }
  }
}

/* Helden-Karten responsive */
@media (max-width: 768px) {
  .hero-list {
    grid-template-columns: 1fr !important;
    gap: var(--mobile-gap);
  }
  
  .hero-card {
    padding: var(--mobile-padding);
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas: 
      "name ap"
      "lp lp"
      "bar bar";
    gap: 8px;
    align-items: center;
  }
  
  .hero-name {
    grid-area: name;
    margin: 0;
    font-size: 16px;
  }
  
  .hero-card .kv:nth-child(2) {
    grid-area: ap;
    justify-self: end;
  }
  
  .hero-card .kv:nth-child(3) {
    grid-area: lp;
    justify-content: center;
  }
  
  .hero-card .bar {
    grid-area: bar;
    height: 20px;
  }
}

/* Tags und Chips */
@media (max-width: 768px) {
  .tags, .chips {
    gap: 6px;
  }
  
  .tag, .chip {
    padding: 6px 10px;
    font-size: 12px;
  }
}

/* RTE (Rich Text Editor) mobile */
@media (max-width: 768px) {
  .rte-toolbar {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--panel-soft);
    border-radius: 8px 8px 0 0;
    padding: 8px;
    border-bottom: 2px solid var(--line);
    flex-wrap: wrap;
    gap: 6px;
  }
  
  .rte-toolbar .btn {
    min-width: 36px;
    min-height: 36px;
    padding: 8px;
    font-size: 14px;
    border-radius: 6px;
  }
  
  .rte-toolbar select {
    flex: 1;
    min-width: 100px;
    max-width: 150px;
    padding: 8px;
    border-radius: 6px;
    font-size: 14px;
  }
  
  .rte-editor {
    border-radius: 0 0 12px 12px;
    min-height: 200px;
    font-size: 16px;
    line-height: 1.6;
    padding: 16px;
  }
  
  .rte-editor:focus {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
  }
}

/* Suggest-Dropdown mobile */
@media (max-width: 768px) {
  .suggest-wrap {
    position: relative;
    width: 100%;
  }
  
  .suggest {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    max-height: 40vh;
    border-radius: 12px;
    border: 2px solid var(--line-strong);
    background: var(--panel);
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
    z-index: 1000;
  }
  
  .suggest-item {
    padding: 16px;
    font-size: 16px;
    border-bottom: 1px solid var(--line-soft);
    cursor: pointer;
    transition: background-color 0.2s ease;
  }
  
  .suggest-item:active {
    background: var(--accent);
    color: white;
  }
  
  .suggest-item:last-child {
    border-bottom: none;
    border-radius: 0 0 12px 12px;
  }
  
  .suggest-item:first-child {
    border-radius: 12px 12px 0 0;
  }
}

/* Performance Optimierungen */
@media (max-width: 768px) {
  /* Reduzierte Animationen für schwächere Geräte */
  @media (prefers-reduced-motion: reduce) {
    * {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
    }
  }
  
  /* GPU-Beschleunigung für kritische Elemente */
  .modal .panel,
  .cal-cell,
  .btn,
  .hero-card {
    will-change: transform;
    transform: translateZ(0);
  }
  
  /* Optimierte Schatten für bessere Performance */
  .card, .modal .panel {
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  }
  
  /* Bilder optimieren */
  img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
  }
  
  /* Avatar-Größen anpassen */
  .avatar {
    width: 32px !important;
    height: 32px !important;
  }
}

/* Accessibility Verbesserungen für Mobile */
@media (max-width: 768px) {
  /* Größere Touch-Targets */
  button, input, select, textarea, a, .cal-cell {
    min-height: 44px;
    min-width: 44px;
  }
  
  /* Bessere Fokus-Indikatoren */
  button:focus,
  input:focus,
  select:focus,
  textarea:focus,
  a:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }
  
  /* Bessere Kontraste für kleine Screens */
  .small {
    font-size: 14px;
    color: var(--text);
    opacity: 0.8;
  }
  
  .muted {
    color: var(--text);
    opacity: 0.7;
  }
  
  /* Screen-Reader freundliche Labels */
  .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;
  }
}

/* Landscape-Modus für Smartphones */
@media (max-width: 896px) and (orientation: landscape) {
  .topbar {
    padding: 8px var(--mobile-padding);
  }
  
  .brand {
    font-size: 14px;
  }
  
  .menu a {
    padding: 6px 10px;
    font-size: 14px;
  }
  
  .modal .panel {
    max-height: 85vh;
    margin: 5vh auto;
  }
  
  .cal-grid {
    grid-template-columns: repeat(6, 1fr) !important;
  }
  
  .cal-cell {
    min-height: 60px;
  }
}

@media (max-width: 896px) and (orientation: landscape) and (max-height: 500px) {
  .topbar {
    padding: 6px 16px;
  }
}

/* PWA-spezifische Styles */
@media (display-mode: standalone) {
  /* App-ähnliches Gefühl */
  body {
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
  }
  
  /* Texteingaben wieder erlauben */
  input, textarea {
    user-select: text;
    -webkit-user-select: text;
  }
  
  /* Verstecke Scrollbars in Standalone-Modus */
  ::-webkit-scrollbar {
    width: 0px;
    background: transparent;
  }
  
  /* Safe-Area für Geräte mit Notch */
  .topbar {
    padding-top: max(10px, env(safe-area-inset-top));
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
  
  body {
    padding-bottom: max(80px, env(safe-area-inset-bottom));
  }
}

/* Dark-Mode Anpassungen für OLED Displays */
@media (max-width: 768px) {
  :root {
    --bg: #000000; /* Echter schwarzer Hintergrund für OLED */
    --panel: #111111;
  }
}

@media (prefers-color-scheme: dark) and (max-width: 768px) {
  :root {
    --bg: #000000; /* Echter schwarz für OLED */
    --panel: #0a0a0a;
    --panel-soft: #111111;
  }
}

/* Container für bessere mobile Navigation */
@media (max-width: 768px) {
  body {
    padding-bottom: 80px; /* Platz für mögliche mobile Navigation */
  }
}

/* Spezielle Behandlung für sehr kleine Displays */
@media (max-width: 320px) {
  .topbar {
    padding: 8px;
  }
  
  .brand {
    font-size: 14px;
    max-width: 40vw;
  }
  
  .menu {
    gap: 4px;
  }
  
  .menu a {
    padding: 8px;
    font-size: 13px;
  }
  
  .cal-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 4px;
  }
  
  .cal-cell {
    min-height: 80px;
    padding: 4px;
  }
  
  .chip {
    font-size: 9px;
    padding: 1px 4px;
  }
}

/* High-DPI Display Optimierungen */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 2dppx) {
  /* Schärfere Bilder für Retina-Displays */
  img {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
  }
  
  /* Dünnere Linien für High-DPI */
  .table th, .table td {
    border-width: 0.5px;
  }
  
  .card, .input, .btn {
    border-width: 0.5px;
  }
}

/* Loading Spinner */
.loading-spinner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(7, 5, 7, 0.8);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--line);
  border-top: 4px solid var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Pull-to-Refresh Indikator */
.pull-to-refresh {
  position: fixed;
  top: -60px;
  left: 0;
  right: 0;
  height: 60px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  transition: transform 0.3s ease;
  z-index: 1001;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* Scroll-to-Top Button */
.scroll-top {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 48px;
  height: 48px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 1000;
  transition: all 0.3s ease;
  display: none;
}

.scroll-top:active {
  transform: scale(0.9);
}