:root {
  --bg-primary: #1e1e1e;
  --bg-secondary: #2d2d30;
  --bg-accent: #0f3460;
  --text-primary: #ffffff;
  --text-secondary: #cccccc;
  --accent-blue: #0078d4;
  --accent-amd: #ed1c24;
  --border: #404040;
}

/* === Mobile-First Basis-Styles === */
body {
  font-family: "Arial", Verdana, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  padding: 10px;
  margin: 0;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow-x: hidden;
}

a, a:visited {
  color: var(--accent-blue);
}

h1, h2, h3, h4, h5, h6 {
  color: var(--text-primary);
  margin-top: 1.2em;
  margin-bottom: 0.5em;
}
h1 { font-size: 1.8em; }
h2 { font-size: 1.6em; }
h3 { font-size: 1.4em; }
h4 { font-size: 1.2em; }

.wikidoc {
  width: 100%;
  margin: 0 auto;
  padding: 15px;
  float: none;
  box-sizing: border-box;
  background: var(--bg-secondary);
  color: var(--text-primary);
  clear: both;
}

pre, code, .wikidoc pre, .wikidoc code {
  background: var(--bg-secondary);
  color: var(--accent-blue);
  border-radius: 5px;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
}

table, th, td {
  width: 100%;
  font-size: 12px;
  border: 1px solid var(--border);
  border-collapse: collapse;
  background: var(--bg-secondary);
  color: var(--text-primary);
  word-break: break-word;
  hyphens: auto;
}
th {
  background: var(--bg-accent);
  color: var(--text-primary);
  padding: 8px 4px;
}
td {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  padding: 8px 4px;
}

a[style*="background: #ff4444"] {
  background: var(--accent-amd) !important;
  color: #fff !important;
}
a[style*="background: #44ff44"] {
  background: var(--accent-blue) !important;
  color: #fff !important;
}
a[style*="background: linear-gradient"] {
  background: linear-gradient(135deg, var(--accent-blue) 0%, var(--bg-accent) 100%) !important;
  color: #fff !important;
}

/* Touchfreundliche Buttons/Links */
a[style*="padding: 12px"], a[style*="padding: 15px"], a, button, input[type="button"], input[type="submit"] {
  display: block;
  width: 100%;
  min-height: 44px;
  box-sizing: border-box;
  margin: 8px 0;
  text-align: center;
  font-size: 1.1em;
  padding: 12px 16px;
}

a + a, button + button {
  margin-top: 8px;
}

/* Bilder und Medien responsiv */
img {
  max-width: 100% !important;
  height: auto !important;
  display: block;
  margin: 10px auto;
}
iframe, embed, object {
  max-width: 100%;
  height: auto;
}

/* Sidebars und Fixed-Elemente auf Mobile ausblenden */
/* Standardmäßig: Sidebars ausblenden (Mobile-First) */
/* Sidebars und Fixed-Nav werden nur auf kleinen Bildschirmen ausgeblendet */
@media (max-width: 768px) {
  .left, .right, .fixed-nav {
    display: none !important;
    position: static !important;
    width: 100% !important;
  }
}

/* FIX: Ensure the main content area (.wikidoc) is always visible,
   overriding the display:none from .left, .right, etc. if they are on the same element. */
.wikidoc {
  display: block !important;
}

/* === Mobile Table Stacking (up to 480px) === */
@media (max-width: 480px) {
  table, thead, tbody, th, td, tr {
    display: block;
  }

  th {
    position: absolute;
    top: -9999px;
    left: -9999px;
  }

  tr {
    border: 1px solid var(--border);
    margin-bottom: 10px;
  }

  td {
    border: none;
    position: relative;
    padding-left: 50%;
  }

  td:before {
    content: attr(data-label) ": ";
    position: absolute;
    left: 6px;
    width: 45%;
    text-align: left;
    font-weight: bold;
  }
}

/* === Tablet-Styles (ab 601px) === */
@media only screen and (min-width: 601px) {
  body {
    font-size: 15px;
  }

  .wikidoc {
    width: 90%;
    margin: 0 auto;
    padding: 20px;
  }

  table, th, td {
    font-size: 14px;
  }

  /* FIX: Reset table cell width for traditional table layout.
     The mobile-first style sets td width to 100% for stacking,
     which needs to be undone for wider screens. */
  th, td {
    width: auto;
  }
}

/* === Desktop-Styles (ab 769px) === */
/* REFACTOR: Replaced float layout with a modern, robust CSS Grid layout.
   This is the ideal tool for creating multi-column page layouts. */
@media only screen and (min-width: 769px) {
  :root {
    --left-sidebar-width: 120px;
    --right-sidebar-width: 160px;
    --content-gutter: 16px;
  }

  body {
    display: grid;
    /* Define 3 columns: left sidebar, flexible content, right sidebar */
    grid-template-columns: minmax(var(--left-sidebar-width), 1fr) minmax(480px, 1.5fr) minmax(var(--right-sidebar-width), 1fr);
    grid-gap: var(--content-gutter);
  }

  .wikidoc {
    /* The content will live in the center column defined by the grid */
    max-width: 900px; /* Enforce the maximum content width */
    min-width: 480px; /* Ensure minimum readable width */
    justify-self: center; /* Center the content within its grid column on wide screens */
    width: 100%; /* Ensure it fills its column up to the max-width */
    margin: 0; /* Reset margins used for float layout */
  }

  .left {
    display: block !important;
  }

  .right {
    display: block !important;
  }

  .fixed-nav {
    /* position:fixed takes this element out of the grid flow, which is correct. */
    display: block !important;
    position: fixed !important;
    top: 0;
    z-index: 10;
    width: var(--left-sidebar-width);
  }
}

/* === Große Desktops (ab 1100px) === */
@media (min-width: 1100px) {
  :root {
    --left-sidebar-width: 180px;
    --right-sidebar-width: 240px;
    --content-gutter: 20px;
  }
  .right {
    /* On large screens, make the right sidebar 'sticky' */
    position: fixed;
    top: 0px;
    right: 0;
  }

  /* When right sidebar is fixed, it leaves the grid. Redefine the grid to 2 columns
     and add padding to the body to avoid content overlapping the fixed sidebar. */
  body {
    grid-template-columns: var(--left-sidebar-width) 1fr;
    padding-right: calc(var(--right-sidebar-width) + var(--content-gutter));
  }
}