:root{
  --bg:#0b1020;
  --card:#121933;
  --line:#263152;
  --text:#e8ecff;
  --muted:#9fb0ff;
  --accent:#3a63ff;
  --radius:16px;
}

*{box-sizing:border-box}

html,body{
  margin:0;
  min-height:100vh; /* Viewport height statt 100% */
  background:var(--bg);
  color:var(--text);
  font:16px/1.4 system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  -webkit-text-size-adjust: 100%; /* Verhindert Text-Vergrößerung auf iOS */
  -webkit-tap-highlight-color: transparent; /* Entfernt Tap-Highlight auf iOS */
}

/* Sticky Footer Layout */
body {
  display: flex;
  flex-direction: column;
}

.wrap{
  max-width:1280px;              /* mehr Platz gesamt */
  margin-inline:auto;
  padding:16px;
  flex: 1;
}

/* Breite im eingeklappten Zustand NICHT verändern */
.acc-section,
.acc-table,
.acc-table-header,
.table-scroll{
  width:100%;
}


/* Mobile-first responsive padding */
@media (min-width: 480px) {
  .wrap { padding: 20px; }
}
@media (min-width: 768px) {
  .wrap { padding: 24px; }
}

.topbar{
  display:flex;
  gap:16px;
  align-items:center;
  justify-content:space-between;
  margin-bottom:20px;
  flex-wrap: wrap; /* Erlaubt Umbruch auf kleinen Bildschirmen */
  padding: 8px 0; /* Etwas mehr Platz oben und unten */
}

/* Mobile Topbar Anpassungen */
@media (max-width: 767px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  .topbar > div:first-child {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-content: center;
  }
  .topbar .actions {
    display: flex;
    justify-content: center;
  }
}

h1{
  font-size:1.5rem; 
  margin:0; 
  letter-spacing:.3px;
  font-weight: 700;
  color: var(--text);
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* Mobile H1 Anpassungen */
@media (max-width: 767px) {
  h1 {
    font-size: 1.3rem;
    letter-spacing: .2px;
  }
}

.btn{
  background:var(--accent);
  color:white;
  border:none;
  padding:12px 16px; /* Größere Touch-Targets */
  border-radius:12px;
  cursor:pointer;
  font-weight:600;
  box-shadow:0 6px 16px rgba(58,99,255,.35);
  font-size: 16px; /* Verhindert Zoom auf iOS */
  min-height: 44px; /* Mindestgröße für Touch-Targets */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease;
}
.btn:active{transform:translateY(1px)}
.btn:focus{outline: 2px solid rgba(58,99,255,0.5); outline-offset: 2px;}

/* Mobile Button Anpassungen */
@media (max-width: 767px) {
  .btn {
    padding: 14px 18px;
    font-size: 16px;
    min-height: 48px;
    width: 100%;
    max-width: 300px;
  }
}

/* Acc x8 */
.acc-section{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:var(--radius);
  padding:16px;
  margin-bottom:16px;
}
.acc-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  margin-bottom:12px;
}
.acc-header h2{
  font-size:1.05rem;
  margin:0;
}
.acc-actions{
  display:flex;
  align-items:center;
  gap:10px;
}
.acc-hint{color:var(--muted); font-size:.9rem}

.accounts{
  display:grid;
  grid-template-columns:1fr; /* Karten nutzen volle Breite */
  gap:12px;
}

.account-card{
  background:#0f1630;
  border:1px solid var(--line);
  border-radius:12px;
  padding:12px;
  display:flex;
  flex-direction:column;
  gap:10px;
}
.account-header{
  display:flex;
  gap:8px;
  align-items:center;
}
.account-name{
  flex:1;
  background:#0c1328;
  color:var(--text);
  border:1px solid var(--line);
  border-radius:10px;
  padding:8px 10px;
}
.btn-danger{
  background:#d53b3b;
  box-shadow:0 6px 16px rgba(213,59,59,.25);
}
.btn-secondary{
  background:#2b3f92;
  box-shadow:0 6px 16px rgba(43,63,146,.25);
}

.char-list{
  display:flex;
  flex-direction:column;
  gap:8px;
}
.char-row{
  display:grid;
  grid-template-columns:1fr 180px 200px 200px 36px; /* Name | Gilde | Klasse | Spezialisierung | X */
  gap:8px;
  align-items:center;
}

/* Mobile Char-Row Layout */
@media (max-width: 767px) {
  .char-row {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 12px;
    background: rgba(15, 22, 48, 0.5);
    border-radius: 8px;
    margin-bottom: 8px;
  }
  
  .char-row > * {
    width: 100%;
    min-width: unset;
  }
  
  .char-row .icon-btn {
    width: 44px;
    height: 44px;
    margin: 0 auto;
  }
}
.char-name,
.char-type,
.char-subtype,
.char-guild{
  background:#0c1328;
  color:var(--text);
  border:1px solid var(--line);
  border-radius:10px;
  padding:12px; /* Größere Touch-Targets */
  font-size: 16px; /* Verhindert Zoom auf iOS */
  min-height: 44px; /* Mindestgröße für Touch-Targets */
}

.char-name{
  width:100%;
}
.char-type{
  min-width:160px;
  width:100%;
}
.char-subtype{
  min-width:160px;
  width:100%;
}
.char-guild{
  min-width:140px;
  width:100%;
}

/* Mobile Input Anpassungen */
@media (max-width: 767px) {
  .char-name,
  .char-type,
  .char-subtype,
  .char-guild {
    padding: 14px;
    font-size: 16px;
    min-height: 48px;
    width: 100%;
    min-width: unset;
  }
}
.icon-btn{
  background:#23315e;
  color:#fff;
  border:none;
  width:44px; /* Größere Touch-Targets */
  height:44px;
  border-radius:10px;
  cursor:pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease;
}
.icon-btn:hover {
  background: #2a3a6e;
}
.icon-btn:active {
  background: #1e2a4a;
}
.account-footer{display:flex; justify-content:flex-end}

/* Einklappbare Account-Karte */
.account-card.collapsed .char-list,
.account-card.collapsed .account-footer{ display:none }

.table-scroll{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:var(--radius);
  overflow-x:auto; /* Horizontales Scrollen für mobile Geräte */
  overflow-y:auto;
  -webkit-overflow-scrolling: touch; /* Smooth scrolling auf iOS */
}

/* Mobile Table Anpassungen */
@media (max-width: 767px) {
  .table-scroll {
    border-radius: 12px;
    margin: 0 -4px; /* Nutzt mehr Bildschirmbreite */
    max-height: none; /* Keine Höhenbegrenzung mehr nötig */
    overflow-y: auto;
    margin-bottom: 20px; /* Extra Abstand zum Footer */
  }
  
  .grid {
    min-width: 600px; /* Größere Mindestbreite für bessere Lesbarkeit */
    table-layout: fixed; /* Feste Spaltenbreite für bessere Kontrolle */
  }
  
  .grid th,
  .grid td {
    padding: 10px 8px;
    font-size: 14px;
  }
  
  .grid .col-name {
    min-width: 140px;
    max-width: 140px;
    font-weight: 600;
    font-size: 15px;
  }
  
  /* Mobile: Bessere Header-Darstellung */
  .grid thead th {
    height: 60px; /* Angepasst für senkrechte Labels */
    font-size: 13px;
    padding: 8px 6px;
  }
  
  .grid tbody tr td {
    padding: 8px 6px;
    font-size: 14px;
  }
  
  /* Checkboxen größer für Touch */
  .grid tbody tr td input[type="checkbox"] {
    width: 22px;
    height: 22px;
    transform: scale(1.2);
  }
  
  /* Mini-Header auf mobilen Geräten ausblenden */
  .mini-header-row {
    display: none;
  }
  
  /* Mobile senkrechte Labels */
  .rot {
    transform: rotate(-90deg); /* Nur auf Mobile: senkrecht */
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: visible;
    text-overflow: unset;
    width: 18px;
    height: 50px;
    line-height: 18px;
    margin: 0 auto;
  }
  
  /* Char-Namen besser lesbar */
  .char-name-inline {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
  }
  
  /* Char-Badges besser sichtbar */
  .char-badge {
    font-size: 0.9rem;
    padding: 3px 8px;
    margin-right: 8px;
  }
}

/* Abstand und einklappbare Account-Tabellen */
.acc-table{margin-top:16px}
.acc-table + .acc-table{margin-top:20px}
.acc-table-header{
  display:flex;
  align-items:center;
  gap:10px;
  margin:8px 0 8px;
  color:var(--muted);
}
.acc-collapse-btn{
  width:28px; height:28px;
  border-radius:6px; border:1px solid var(--line);
  background:#172045; color:#fff; cursor:pointer;
}
.acc-table.collapsed .table-scroll{display:none}
.acc-table-title{font-weight:700}

.grid{
  width:100%;
  border-collapse:separate;
  border-spacing:0;
  min-width:0; /* keine Mindestbreite, damit nichts herausragt */
  table-layout:fixed; /* Spalten teilen sich den Platz */
}

.grid th,
.grid td{
  border-bottom:1px solid var(--line);
  padding:10px 12px;
  text-align:center;
}

.grid thead th{
  position:sticky;
  top:0;
  background:linear-gradient(#18224a,#151d3f);
  z-index:1;
  font-weight:700;
  height:56px; /* Normale Höhe für Desktop */
  overflow:hidden;
  width:auto; /* Breite automatisch */
  word-break:break-word;
}

.grid .col-name{
  text-align:left;
  min-width:320px;               /* Name + Nummer passt */
}


/* Diagonale Spaltenüberschriften */
.rot{
  transform:none; /* Desktop: normal horizontal */
  display:block;
  white-space:nowrap;
  font-size:0.9rem;
  position:static;
  color:var(--text);
  overflow:visible;
  text-overflow:unset;
  text-align:center;
  font-weight:600;
}
.rot.mini{ font-size:0.85rem }
.mini-header-row td{ border-bottom:none; padding:6px 12px 6px }

.grid tbody tr:last-child td{
  border-bottom:none;
}

input[type="checkbox"]{
  width:24px; /* Größere Checkboxen für Touch */
  height:24px;
  cursor:pointer;
  accent-color: var(--accent); /* Moderne Browser */
}

/* Mobile Checkbox Anpassungen */
@media (max-width: 767px) {
  input[type="checkbox"] {
    width: 28px;
    height: 28px;
    transform: scale(1.2); /* Größere Checkboxen auf mobilen Geräten */
  }
}

td[contenteditable="true"]{
  outline:none;
}
td[contenteditable="true"]:empty:before{
  content:attr(data-placeholder);
  color:var(--muted);
}

/* Inline editierbarer Name in der Tabelle */
.char-name-inline[contenteditable="true"]{
  outline:none;
}

.hint{
  color:var(--muted);
  font-size:.9rem;
  margin:.8rem 0 0;
}

/* Tabelle: optische Unterscheidung Account/Char */
.is-account{font-weight:700}
.is-char{padding-left:24px; color:#cdd6ff}

/* Badge vor Char-Namen in Tabelle */
.char-badge{
  display:inline-block;
  background:#2b3f92;
  color:#fff;
  border-radius:6px;
  padding:2px 6px;
  font-size:.8rem;
  margin-right:6px;
}
.char-badge.sub{
  background:#5a2b92; /* andere Farbe für Spezialisierung */
}

/* Kopf: "Account" über dem Namen */
.col-name::before{
  content:"Account";
  display:block;
  color:var(--muted);
  font-size:.85rem;
  margin-bottom:6px;
}
/* Breites, aber nicht verzerrtes Logo */
.logo-wide{
  height: 64px;          /* Größere Höhe für bessere Sichtbarkeit */
  width: auto;           /* Breite passt sich an – keine Verzerrung */
  object-fit: contain;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.3)); /* Schatten für bessere Tiefe */
}

/* Responsive Logo-Größen */
@media (min-width: 480px) {
  .logo-wide { height: 72px; }
}
@media (min-width: 768px) {
  .logo-wide { height: 80px; }
}
@media (min-width: 900px) {
  .logo-wide { height: 88px; }
}

/* Mobile-spezifische Verbesserungen */
@media (max-width: 767px) {
  /* Größere Touch-Targets für alle interaktiven Elemente */
  .acc-collapse-btn {
    width: 44px;
    height: 44px;
    font-size: 18px;
  }
  
  /* Logo mobile Anpassung */
  .logo-wide {
    height: 56px; /* Etwas kleiner auf sehr kleinen Bildschirmen */
  }
  
  /* Account-Header mobile Anpassung */
  .account-header {
    flex-wrap: wrap;
    gap: 8px;
  }
  
  .account-name {
    order: 2;
    flex: 1 1 100%;
  }
  
  /* Account-Actions mobile Anpassung */
  .acc-actions {
    flex-direction: column;
    gap: 8px;
    align-items: stretch;
  }
  
  .acc-hint {
    text-align: center;
    font-size: 0.85rem;
  }
  
  /* Account-Footer mobile Anpassung */
  .account-footer {
    justify-content: center;
  }
  
  /* Hint-Text mobile Anpassung */
  .hint {
    text-align: center;
    padding: 0 16px;
  }
}

/* Sehr kleine Bildschirme (unter 360px) */
@media (max-width: 359px) {
  .wrap {
    padding: 12px;
  }
  
  .logo-wide {
    height: 48px; /* Minimalgröße für sehr kleine Bildschirme */
  }
  
  h1 {
    font-size: 1.2rem;
  }
  
  .btn {
    padding: 12px 14px;
    font-size: 15px;
  }
}

/* Footer Styles */
#footer-container {
  margin-top: auto; /* Drückt Footer an den Boden */
}

footer {
  background: var(--card);
  border-top: 1px solid var(--line);
  padding: 20px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  border-radius: var(--radius) var(--radius) 0 0; /* Abgerundete obere Ecken */
  margin-top: 20px; /* Abstand zum Hauptinhalt */
}

/* --- Layout mit linker Sidebar --- */
.layout{
  display:grid;
  grid-template-columns: 260px 1fr;   /* Sidebar | Hauptbereich */
  gap:16px;
}
@media (max-width: 900px){
  .layout{ grid-template-columns: 1fr; }
}

/* Sidebar: Char-Liste */
.side-panel{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:var(--radius);
  padding:14px;
  position:sticky;
  top:12px;
  align-self:start;
  max-height: calc(100vh - 24px);
  overflow:auto;
}
.side-panel h3{
  margin:0 0 10px 0;
  font-size:1rem;
  color:var(--text);
}
#charList{
  margin:0; padding-left:18px;
  display:block;
  line-height:1.5;
  color:var(--muted);
}
#charList li{
  margin:2px 0;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

/* Fav-Stern */
.fav-btn{
  width:32px; height:32px;
  border-radius:8px;
  border:1px solid var(--line);
  background:#1b2550;
  color:#b3bcd7;
  cursor:pointer;
  display:inline-flex; align-items:center; justify-content:center;
  font-size:18px;
}
.fav-btn.active{
  color:#ffd54d;                 /* golden */
  border-color:#ffd54d;
  text-shadow:0 0 8px rgba(255,213,77,.5);
}
/* Einklappen per Klasse – Breite bleibt stabil */
.acc-section.collapsed #accountsContainer{ display:none; }
/* Hauptspalte: stapelt Accounts-Sektion und Tabellen untereinander */
.main-col{
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0; /* verhindert ungewolltes Überlaufen in Grids */
}

/* Safety: Container im Hauptbereich immer volle Breite */
.main-col .acc-section,
.main-col #tablesContainer,
.main-col .table-scroll{
  width: 100%;
}
