/* SAOAS Lizenzportal - ein einziges Stylesheet, keine Frameworks.
   Aufbau: erst die gemeinsame Gestaltung, unten die Anpassungen fuer
   kleinere Bildschirme (Haltepunkte bei 900, 720 und 480 Pixeln). */

:root {
  /* Teilt Browser und Formularelementen mit, dass beides moeglich ist -
     Auswahllisten, Bildlaufleisten und Kalender folgen dann von selbst. */
  color-scheme: dark light;

  --bg: #0f1115;
  --flaeche: #161a21;
  --flaeche-hell: #1d222b;
  --rand: #262c37;
  --akzent: #3b82f6;
  --akzent-hover: #2563eb;
  --text: #e6e9ef;
  --schwach: #8b94a5;
  --gruen: #22c55e;
  --gelb: #eab308;
  --rot: #ef4444;
  --radius: 10px;
  --rand-aussen: clamp(12px, 3vw, 20px);
  --tippziel: 44px;      /* Mindesthoehe fuer Finger statt Mauszeiger */

  /* Fliessende Schriftgroessen: wachsen stufenlos mit der Fensterbreite,
     statt an festen Haltepunkten zu springen. */
  --s-h1:      clamp(20px, 1rem + 1.6vw, 26px);
  --s-h2:      clamp(13px, .8rem + .3vw, 15px);
  --s-kachel:  clamp(19px, 1rem + 1.4vw, 27px);
  --s-text:    clamp(14.5px, .9rem + .2vw, 15.5px);
}

/* Helles Geraetethema: Wer sein System auf hell gestellt hat, bekommt
   auch hier eine helle Oberflaeche - ohne Umschalter, ohne Cookie. */
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6f8;
    --flaeche: #ffffff;
    --flaeche-hell: #eef0f4;
    --rand: #d9dde5;
    --akzent: #2563eb;
    --akzent-hover: #1d4ed8;
    --text: #11151c;
    --schwach: #5b6472;
    --gruen: #15803d;
    --gelb: #a16207;
    --rot: #b91c1c;
  }
  .s-aktiv      { background: rgba(21,128,61,.12); }
  .s-testphase  { background: rgba(161,98,7,.12); }
  .s-abgelaufen,
  .s-gesperrt   { background: rgba(185,28,28,.12); }
  .geraet, .karte { box-shadow: 0 1px 3px rgba(16,24,40,.06); }
}

/* Wer mehr Kontrast angefordert hat, bekommt kraeftigere Raender. */
@media (prefers-contrast: more) {
  :root { --rand: currentColor; --schwach: var(--text); }
  .knopf.still { border-width: 2px; }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: var(--s-text)/1.55 "Segoe UI", system-ui, -apple-system, sans-serif;
  overflow-wrap: break-word;
  /* Randbereiche moderner Handys (Notch, abgerundete Ecken) aussparen */
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* Sprungmarke fuer Tastatur- und Screenreader-Nutzung */
.ueberspringen {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--akzent); color: #fff; padding: 12px 18px;
  border-radius: 0 0 8px 0;
}
.ueberspringen:focus { left: 0; }

/* Sichtbarer Fokusrahmen, aber nur bei Tastaturbedienung */
:focus-visible {
  outline: 2px solid var(--akzent); outline-offset: 2px; border-radius: 4px;
}

a { color: var(--akzent); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  font-family: Consolas, ui-monospace, monospace;
  background: var(--flaeche-hell); padding: 1px 5px;
  border-radius: 4px; font-size: .9em;
  overflow-wrap: anywhere;
}

h1 { font-size: var(--s-h1); margin: 0 0 4px; line-height: 1.25; }
h2 { font-size: var(--s-h2); margin: 22px 0 8px; color: var(--schwach);
     text-transform: uppercase; letter-spacing: .06em; }

/* ------------------------------------------------------------- Layout */
.mitte {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; min-height: 100dvh;   /* dvh: Adressleiste am Handy */
  padding: var(--rand-aussen);
  padding-bottom: calc(var(--rand-aussen) + env(safe-area-inset-bottom));
}
.karte {
  background: var(--flaeche); border: 1px solid var(--rand);
  border-radius: var(--radius); padding: 28px;
  width: 100%; max-width: 440px;
}
.karte.breit { max-width: 620px; }
.huelle { max-width: 1180px; margin: 0 auto;
          padding: 0 var(--rand-aussen)
                   calc(60px + env(safe-area-inset-bottom)); }

.kopf {
  border-bottom: 1px solid var(--rand); background: var(--flaeche);
  padding: 14px 0; margin-bottom: 28px;
}
.kopf .huelle { display: flex; align-items: center; gap: 16px;
                padding-bottom: 0; flex-wrap: wrap; }
.marke { font-weight: 700; font-size: 18px; color: var(--akzent); }
.kopf nav { display: flex; gap: 16px; margin-left: auto; }
.kopf nav a { color: var(--schwach); font-size: 14px; white-space: nowrap; }
.kopf nav a.aktiv { color: var(--text); }

/* -------------------------------------------------------------- Kacheln */
.kacheln {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: 26px;
}
.kachel {
  background: var(--flaeche); border: 1px solid var(--rand);
  border-radius: var(--radius); padding: 16px 18px;
  min-width: 0;                 /* verhindert Ueberlauf langer Inhalte */
}
.kachel span { display: block; color: var(--schwach); font-size: 12px; }
.kachel strong { display: block; font-size: var(--s-kachel); margin-top: 4px;
                 font-weight: 600; line-height: 1.2; }

/* -------------------------------------------------------------- Tabelle */
.tabellenhuelle {
  width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch;
  /* Sanfter Schatten am Rand, solange noch etwas ausserhalb liegt -
     macht sichtbar, dass sich die Tabelle seitlich schieben laesst. */
  background:
    linear-gradient(to right, var(--bg) 30%, transparent),
    linear-gradient(to left,  var(--bg) 30%, transparent) 100% 0,
    radial-gradient(farthest-side at 0 50%, rgba(0,0,0,.35), transparent),
    radial-gradient(farthest-side at 100% 50%, rgba(0,0,0,.35), transparent) 100% 0;
  background-repeat: no-repeat;
  background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
  background-attachment: local, local, scroll, scroll;
}

table {
  width: 100%; border-collapse: collapse; background: var(--flaeche);
  border: 1px solid var(--rand); border-radius: var(--radius); overflow: hidden;
}
th, td { padding: 11px 14px; text-align: left; font-size: 14px;
         border-bottom: 1px solid var(--rand); }
th { color: var(--schwach); font-size: 12px; text-transform: uppercase;
     letter-spacing: .05em; font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--flaeche-hell); }
td.schluessel { font-family: Consolas, ui-monospace, monospace;
                letter-spacing: .04em; overflow-wrap: anywhere; }

/* -------------------------------------------------------------- Formular */
.feld, select, textarea {
  width: 100%; padding: 11px 13px; margin: 5px 0;
  background: var(--flaeche-hell); border: 1px solid var(--rand);
  border-radius: 8px; color: var(--text); font-size: 15px;
  font-family: inherit; min-height: var(--tippziel);
}
.feld:focus, select:focus, textarea:focus {
  outline: 2px solid var(--akzent); outline-offset: -1px; border-color: var(--akzent);
}
label { display: block; margin-top: 12px; font-size: 12px; color: var(--schwach); }

.knopf {
  display: inline-block; padding: 11px 18px; border: none; border-radius: 8px;
  background: var(--akzent); color: #fff; font: 600 14px/1.2 inherit;
  cursor: pointer; margin-top: 12px; min-height: var(--tippziel);
  text-align: center;
}
.knopf:hover { background: var(--akzent-hover); text-decoration: none; }
.knopf.voll { width: 100%; padding: 13px; }
.knopf.still { background: var(--flaeche-hell); color: var(--text);
               border: 1px solid var(--rand); }
.knopf.gefahr { background: var(--rot); }
.knopf.klein { padding: 7px 12px; font-size: 12px; margin: 0;
               min-height: 34px; }

.reihe { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.reihe > * { flex: 1; min-width: 140px; }

/* --------------------------------------------------------------- Status */
.marke-status { display: inline-block; padding: 3px 10px; border-radius: 20px;
                font-size: 12px; font-weight: 600; white-space: nowrap; }
.s-aktiv      { background: rgba(34,197,94,.15);  color: var(--gruen); }
.s-testphase  { background: rgba(234,179,8,.15);  color: var(--gelb); }
.s-abgelaufen { background: rgba(239,68,68,.15);  color: var(--rot); }
.s-gesperrt   { background: rgba(239,68,68,.15);  color: var(--rot); }

.erfolg  { color: var(--gruen); }
.fehler  { color: var(--rot); }
.warnung { color: var(--gelb); }
.schwach { color: var(--schwach); font-size: 13px; }

.hinweis { background: var(--flaeche-hell); border-left: 3px solid var(--akzent);
           padding: 12px 16px; border-radius: 6px; margin: 14px 0; font-size: 14px; }

/* =====================================================================
   Grosse Tablets und schmale Fenster
   ===================================================================== */
@media (max-width: 900px) {
  :root { --rand-aussen: 16px; }
  .kacheln { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
  .kachel strong { font-size: 22px; }
  h1 { font-size: 22px; }
}

/* =====================================================================
   Handys und kleine Tablets: Tabellen werden zu Karten.

   Spalten auszublenden waere einfacher, wuerde dem Nutzer aber genau die
   Angaben vorenthalten, wegen derer er die Seite geoeffnet hat. Jede Zelle
   traegt darum ein data-label und wird hier zu einer eigenen Zeile.
   ===================================================================== */
@media (max-width: 720px) {
  .kopf { padding: 12px 0; margin-bottom: 20px; }
  .kopf .huelle { gap: 10px; }
  .kopf nav {
    margin-left: 0; width: 100%; gap: 14px;
    overflow-x: auto; padding-bottom: 4px;
    scrollbar-width: none;
  }
  .kopf nav::-webkit-scrollbar { display: none; }
  .kopf nav a { padding: 6px 0; font-size: 15px; }

  .karte { padding: 20px; }
  .huelle { padding-bottom: 40px; }

  table, thead, tbody, tr, td { display: block; width: 100%; }
  thead { position: absolute; left: -9999px; }   /* fuer Screenreader erhalten */

  table { border: none; background: transparent; }
  tbody tr {
    background: var(--flaeche); border: 1px solid var(--rand);
    border-radius: var(--radius); margin-bottom: 10px; padding: 4px 0;
  }
  tbody tr:hover { background: var(--flaeche); }

  td {
    border-bottom: 1px solid var(--rand);
    display: flex; justify-content: space-between; align-items: baseline;
    gap: 14px; padding: 10px 14px; text-align: right;
  }
  td:last-child { border-bottom: none; }
  td::before {
    content: attr(data-label);
    color: var(--schwach); font-size: 12px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .04em;
    text-align: left; flex: 0 0 auto;
  }
  /* Zellen ohne Beschriftung (Aktionsknoepfe) fuellen die Breite */
  td:not([data-label]) { justify-content: stretch; text-align: left; }
  td:not([data-label]) .knopf { width: 100%; }
  td:not([data-label]) form { width: 100%; }

  .reihe { flex-direction: column; align-items: stretch; }
  .reihe > * { width: 100%; flex: none; }

  .kacheln { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
}

/* =====================================================================
   Kleine Handys
   ===================================================================== */
@media (max-width: 480px) {
  :root { --rand-aussen: 12px; }
  body { font-size: 15px; }
  h1 { font-size: 20px; }
  h2 { font-size: 13px; margin-top: 18px; }

  .karte { padding: 18px 16px; border-radius: 12px; }
  .mitte { padding: 12px; align-items: flex-start; padding-top: 32px; }

  .kacheln { grid-template-columns: 1fr 1fr; }
  .kachel { padding: 12px 14px; }
  .kachel strong { font-size: 19px; }

  /* Schluessel sind lang - hier lieber kleiner als umgebrochen */
  td.schluessel, .schluessel { font-size: 12px; letter-spacing: 0; }

  td { flex-direction: column; align-items: flex-start;
       text-align: left; gap: 2px; }
  td::before { margin-bottom: 2px; }

  .hinweis { padding: 10px 12px; font-size: 13px; }
}

/* ---------------------------------------------------- Sonderfaelle
   Angebotskacheln brauchen mehr Platz als Kennzahlkacheln, und die
   Aktionsknoepfe im Dashboard sollen nebeneinander bleiben, solange
   sie passen. */
.kachel.angebot { display: flex; flex-direction: column; }
.kachel.angebot .knopf { margin-top: auto; }

.reihe.aktionen { align-items: stretch; }
.reihe.aktionen > * { flex: 0 0 auto; min-width: 0; }
.reihe.aktionen form { margin: 0; }
.reihe.aktionen .knopf {
  margin-top: 0;
  width: auto;
  white-space: nowrap;   /* Text nicht umbrechen -> kein zerquetschter Knopf */
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 720px) {
  .reihe.aktionen { flex-direction: row; flex-wrap: wrap; }
  .reihe.aktionen > * { flex: 1 1 auto; }
  .reihe.aktionen .knopf { width: 100%; }
  .kacheln .kachel.angebot { grid-column: 1 / -1; }
}

@media (max-width: 480px) {
  .reihe.waehlbar .karte { padding: 16px 14px; }
}

.blaettern {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-top: 14px;
}
.blaettern .reihe > * { flex: 0 0 auto; min-width: 0; }

@media (max-width: 480px) {
  .blaettern { flex-direction: column; align-items: stretch; }
  .blaettern .reihe { justify-content: space-between; }
}

/* =====================================================================
   Querformat auf Handys: wenig Hoehe, viel Breite. Ohne diese Regel
   fuellt allein die Anmeldemaske den Bildschirm und man scrollt zum Knopf.
   ===================================================================== */
@media (max-height: 520px) and (orientation: landscape) {
  .mitte { align-items: flex-start; padding-top: 16px; }
  .kopf { padding: 8px 0; margin-bottom: 14px; }
  .karte { padding: 16px 18px; }
  h1 { font-size: 19px; }
  h2 { margin-top: 12px; }
  label { margin-top: 8px; }
  .feld, select, textarea { margin: 3px 0; }
}

/* =====================================================================
   Container Queries: Kacheln richten sich nach dem Platz ihres
   Elternelements, nicht nach der Fensterbreite. Wichtig fuer die
   Angebotskacheln, die je nach Seite unterschiedlich viel Raum haben.
   ===================================================================== */
@supports (container-type: inline-size) {
  .kacheln { container-type: inline-size; }
  @container (max-width: 380px) {
    .kachel strong { font-size: 18px; }
    .kachel { padding: 12px 14px; }
  }
}

/* =====================================================================
   Druck und PDF-Export: Kunden drucken ihre Lizenzuebersicht aus.
   ===================================================================== */
@media print {
  :root { --bg: #fff; --flaeche: #fff; --flaeche-hell: #fff;
          --text: #000; --schwach: #444; --rand: #999; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .kopf nav, .knopf, form, .ueberspringen { display: none !important; }
  .huelle { max-width: none; padding: 0; }
  .karte, .kachel, table { border: 1px solid #999; box-shadow: none;
                           break-inside: avoid; }
  a { color: #000; text-decoration: underline; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 9pt; }
  h1, h2 { break-after: avoid; }
  tr { break-inside: avoid; }
}

/* Geraete ohne Mauszeiger: groessere Tippflaechen, kein Hover-Flackern */
@media (hover: none) {
  .knopf.klein { min-height: 40px; padding: 9px 14px; }
  tbody tr:hover { background: var(--flaeche); }
  a:hover { text-decoration: none; }
}

/* Nutzer, die Bewegung reduzieren moechten */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
