/* --- Basis & Layout --- */
*, *::before, *::after {
  box-sizing: border-box; /* Verhindert, dass Padding die Breiten sprengt */
}

body, html {
  font-family: "Titillium Web", Calibri, sans-serif;
  margin: 0; padding: 0; background: #f5f5f5; height: 100%;
  display: flex; flex-direction: column;
  width: 100%; max-width: 100vw; overflow-x: hidden; /* Mobile Fixes direkt hier integriert */
}

/* ── Widescreen Fix: Begrenzung und Zentrierung der Hauptbereiche ── */
#headerBar, 
#uploadContainer, 
#memoryContainer, 
#summaryBar, 
#tableWrapper {
  width: 100%;
  max-width: 1400px; /* Ab hier hört das Strecken auf */
  margin: 0 auto;    /* Zentriert den Inhalt auf großen Monitoren */
}
/* ────────────────────────────────────────────────────────────────── */

#headerBar {
  display: flex; align-items: center; padding: 8px 16px;
  background: #fff; border-bottom: 1px solid #ccc;
}

#headerTitle { margin: 0; font-size: 24px; color: #333; }

#headerCenter { margin-left: 20px; flex: 1; }

#toast {
  display: none; background: #333; color: #fff; padding: 6px 14px;
  border-radius: 4px; font-size: 13px; max-width: 400px;
  z-index: 9999;
}

#uploadContainer {
  display: flex; gap: 10px; padding: 10px 16px;
  background: #fff; align-items: center;
  flex-wrap: wrap; /* Mobile Fix */
}

/* --- Memory Buttons Row --- */
#memoryContainer {
  display: flex; gap: 8px; padding: 6px 16px 10px 16px;
  background: #fff; border-bottom: 1px solid #ccc;
  flex-wrap: wrap; /* Mobile Fix */
}

.mem-btn {
  flex: 1 1 18%; min-width: 45px; /* Mobile Fix kombiniert */
  padding: 4px 4px; font-size: 11px; font-family: monospace;
  background: #f8f9fa; border: 1px solid #ccc; border-radius: 4px;
  color: #555; transition: all 0.2s; cursor: pointer;
  text-align: center; font-weight: bold;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.mem-btn:hover { background: #e2e6ea; }

.mem-btn.saved {
  background: #fdfdfd; 
  color: #000; 
  border: 2px solid #28a745; /* Green border for saved state */
  padding: 3px 3px; 
}

.mem-btn.saved:hover { background: #e2e6ea; }

.mem-btn.active-conn {
  border-color: #dc3545 !important; /* Red border for active connection */
}

button {
  font-family: inherit; padding: 6px 14px; font-size: 13px; font-weight: bold;
  cursor: pointer; border: 1px solid #aaa; border-radius: 4px;
  background: #f0f0f0; color: #333; transition: all 0.2s;
}

button:hover { background: #e0e0e0; }

#clearBtn {
  background: #f8f9fa; color: #333; border: 1px solid #ccc;
}

#clearBtn:hover {
  background: #e2e6ea;
}

#summaryBar {
  display: flex; padding: 8px 16px; background: #fff; border-bottom: 1px solid #ccc;
  font-size: 14px; font-weight: bold; color: #444; gap: 20px;
  flex-wrap: wrap; /* Mobile Fix */
}

#tableWrapper {
  flex: 1; padding: 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch; /* Flüssiges Scrollen auf iOS */
}

table {
  width: 100%; border-collapse: collapse; background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1); border-radius: 6px; overflow: hidden;
}

th, td {
  padding: 8px 12px; border: 1px solid #ddd; text-align: left; font-size: 14px;
}

th { background: #f8f9fa; font-weight: bold; color: #333; }
td { vertical-align: middle; }

.badge {
  padding: 3px 8px; border-radius: 12px; font-size: 12px; font-weight: bold; color: #fff;
}
.b-good { background: #28a745; }
.b-warn { background: #fd7e14; }
.b-err  { background: #dc3545; }

.ps-char {
  display: inline-block; width: 14px; text-align: center;
  font-family: monospace; background: #eee; border-bottom: 2px solid #aaa;
  margin-right: 2px; border-radius: 2px 2px 0 0;
}

/* --- Expanding rows and sub-tables --- */
.main-row {
  cursor: pointer;
  transition: background-color 0.2s;
}
.main-row:hover {
  background-color: #f1f8ff !important;
}
.chevron {
  display: inline-block;
  transition: transform 0.2s;
  font-weight: bold;
  color: #007bff;
}
.main-row.expanded .chevron {
  transform: rotate(90deg);
}

.sub-row {
  background: #fafafa;
}
.sub-row td {
  padding: 0; border: none;
}
.sub-table-container {
  padding: 10px 20px 10px 40px;
  border-bottom: 2px solid #ddd;
  background: #f8f9fa;
  box-shadow: inset 0 3px 6px rgba(0,0,0,0.04);
}
.sub-table {
  width: 100%;
  font-family: monospace;
  font-size: 12px;
  background: #fff;
  border: 1px solid #ccc;
}
.sub-table th {
  background: #eaeaea; font-size: 11px; text-transform: uppercase;
}
.sub-table th, .sub-table td {
  padding: 4px 8px; border: 1px solid #eee;
}

/* --- Chips --- */
.ai-chip {
  display: inline-block; border-radius: 4px; padding: 2px 6px; font-size: 11px