/* Farben: Apple-System-Semantik, Kontrast ≥ 4.5:1 für Text in beiden Modi */
:root {
  color-scheme: light dark;
  --bg: #f2f2f7;
  --card: #ffffff;
  --fill: #e5e5ea;
  --text: #1c1c1e;
  --text2: #636366;      /* 5.9:1 auf weiß, 5.3:1 auf --bg */
  --sep: rgba(60, 60, 67, 0.18);
  --accent: #0066cc;     /* weißer Text 5.6:1, als Text auf weiß 5.6:1 */
  --accent-text: #0066cc;
  --accent-soft: rgba(0, 102, 204, 0.1);
  --red: #c4001a;        /* 6.3:1 auf weiß */
  --red-soft: rgba(215, 0, 21, 0.07);
  --green: #1f7a35;      /* weißer Text 5.4:1 */
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --fill: #2c2c2e;
    --text: #f2f2f7;
    --text2: #aeaeb2;    /* 8.4:1 auf --card */
    --sep: rgba(84, 84, 88, 0.6);
    --accent: #0a6cd6;   /* weißer Text 5.0:1 */
    --accent-text: #409cff;
    --accent-soft: rgba(64, 156, 255, 0.16);
    --red: #ff6961;      /* 6.6:1 auf --card */
    --red-soft: rgba(255, 105, 97, 0.1);
    --green: #248a3d;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { min-height: 100dvh; -webkit-tap-highlight-color: transparent; }
h1 { font-size: 34px; line-height: 1.15; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
a { color: var(--accent-text); }
.muted { color: var(--text2); }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent-text); outline-offset: 2px; }
svg.i { width: 1.2em; height: 1.2em; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Buttons – min. 44 px Touchfläche */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border: 0; border-radius: 12px;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  background: var(--fill); color: var(--text); transition: transform 0.1s, opacity 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: default; transform: none; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.tinted { background: var(--accent-soft); color: var(--accent-text); }
.btn.green { background: var(--green); color: #fff; }
.btn.large { min-height: 54px; font-size: 18px; border-radius: 14px; width: 100%; }

input[type="text"], input[type="password"] {
  width: 100%; min-height: 50px; padding: 12px 16px; font: inherit; color: var(--text);
  background: var(--card); border: 1px solid var(--sep); border-radius: 12px; outline: none;
}
input:focus { border-color: var(--accent-text); box-shadow: 0 0 0 4px var(--accent-soft); }
label { display: block; font-size: 15px; font-weight: 600; color: var(--text2); margin: 0 0 8px 4px; }

/* ---------- Login / Startseite ---------- */
.center { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.panel { width: 100%; max-width: 380px; display: grid; gap: 20px; text-align: center; }
.panel form { display: grid; gap: 12px; text-align: left; }
.logo { width: 72px; height: 72px; margin: 0 auto; border-radius: 18px; display: grid; place-items: center; background: var(--accent); color: #fff; }
.logo svg { width: 38px; height: 38px; }
.error { color: var(--red); font-size: 15px; font-weight: 500; min-height: 1.4em; margin: 0; text-align: center; }
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; text-align: left; box-shadow: var(--shadow); }
.list a { display: flex; align-items: center; justify-content: space-between; min-height: 54px; padding: 0 16px; color: var(--text); text-decoration: none; font-weight: 500; }
.list a + a { border-top: 1px solid var(--sep); }
.list a span { color: var(--text2); font-weight: 400; font-size: 15px; }

/* ---------- Upload (Monteur) ---------- */
.upload { max-width: 640px; margin: 0 auto; padding: max(20px, env(safe-area-inset-top)) 16px 150px; display: grid; gap: 22px; }
.upload header { display: grid; gap: 4px; padding-top: 12px; }
.eyebrow { font-size: 15px; font-weight: 600; color: var(--text2); }
.picker {
  display: grid; place-items: center; gap: 10px; min-height: 190px; padding: 24px; width: 100%;
  border: 2px dashed color-mix(in srgb, var(--accent-text) 45%, transparent); border-radius: 18px;
  background: var(--accent-soft); color: var(--accent-text); font: inherit; font-weight: 600; font-size: 19px; cursor: pointer; text-align: center;
}
.picker svg { width: 46px; height: 46px; stroke-width: 1.6; }
.picker small { color: var(--text2); font-weight: 400; font-size: 15px; }
.picker:active { transform: scale(0.99); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
.tile { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--fill); }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile.busy::after { content: ""; position: absolute; inset: 0; margin: auto; width: 22px; height: 22px; border: 3px solid var(--text2); border-top-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; }
.tile .x { position: absolute; top: 0; right: 0; width: 44px; height: 44px; border: 0; background: none; padding: 0; cursor: pointer; display: grid; place-items: center; }
.tile .x span { width: 26px; height: 26px; border-radius: 50%; background: rgba(0, 0, 0, 0.62); color: #fff; display: grid; place-items: center; font-size: 15px; line-height: 1; }
.add-tile { aspect-ratio: 1; border-radius: 10px; border: 2px dashed var(--sep); display: grid; place-items: center; color: var(--accent-text); cursor: pointer; background: none; }
.add-tile svg { width: 32px; height: 32px; }
.sendbar {
  position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px max(12px, env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--sep);
}
.sendbar > div { max-width: 608px; margin: 0 auto; display: grid; gap: 8px; }
.progress { height: 6px; border-radius: 3px; background: var(--fill); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
.status { text-align: center; font-size: 15px; color: var(--text2); margin: 0; min-height: 1.4em; }
.status.err { color: var(--red); font-weight: 500; }
.done-view { min-height: 80dvh; display: grid; place-items: center; text-align: center; padding: 16px; }
.done-view > div { display: grid; gap: 14px; justify-items: center; }
.check { width: 88px; height: 88px; border-radius: 50%; background: var(--green); color: #fff; display: grid; place-items: center; animation: pop 0.35s cubic-bezier(.2, .9, .3, 1.3); }
.check svg { width: 48px; height: 48px; stroke-width: 3; }

/* ---------- Innendienst ---------- */
.app { display: grid; grid-template-columns: 260px 1fr; min-height: 100dvh; }
.sidebar { position: sticky; top: 0; height: 100dvh; padding: 24px 12px; display: flex; flex-direction: column; gap: 4px; border-right: 1px solid var(--sep); background: color-mix(in srgb, var(--card) 55%, var(--bg)); }
.sidebar .title { padding: 0 12px 16px; display: grid; gap: 2px; }
.sidebar .title strong { font-size: 22px; letter-spacing: -0.01em; }
.nav { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px; border-radius: 10px; color: var(--text); text-decoration: none; font-weight: 500; }
.nav:hover { background: var(--fill); }
.nav[aria-current="page"] { background: var(--accent); color: #fff; }
.nav .badge { margin-left: auto; font-size: 15px; font-weight: 600; color: var(--text2); }
.nav[aria-current="page"] .badge { color: #fff; }
.sidebar form { margin-top: auto; }
.sidebar form .btn { width: 100%; justify-content: flex-start; padding: 0 12px; color: var(--text2); background: none; font-weight: 500; }
.main { padding: 32px clamp(16px, 4vw, 48px) 48px; min-width: 0; }
.main > header { margin-bottom: 20px; display: grid; gap: 4px; }
.cards { display: grid; gap: 14px; max-width: 1100px; }
.card { background: var(--card); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); display: grid; gap: 12px; border-left: 4px solid transparent; }
.card.warn { border-left-color: var(--red); background: linear-gradient(var(--red-soft), var(--red-soft)), var(--card); }
.card .top { display: flex; gap: 12px 16px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.card .name { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; overflow-wrap: anywhere; margin: 0; }
.card .meta { font-size: 15px; color: var(--text2); margin-top: 2px; }
.card .red { color: var(--red); font-weight: 600; }
.card .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.thumbs { display: flex; gap: 6px; flex-wrap: wrap; }
.thumbs a, .thumbs button { width: 84px; height: 84px; border-radius: 8px; overflow: hidden; background: var(--fill); flex: none; display: grid; place-items: center; border: 0; padding: 0; cursor: pointer; color: var(--text); font: inherit; font-weight: 600; }
.thumbs img { width: 100%; height: 100%; object-fit: cover; display: block; }
.empty { padding: 64px 16px; text-align: center; color: var(--text2); display: grid; gap: 8px; justify-items: center; }
.empty svg { width: 48px; height: 48px; stroke-width: 1.4; }

.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.card.stat { gap: 2px; }
.card.stat strong { font-size: 24px; letter-spacing: -0.01em; }
.card.stat.total { background: var(--accent); color: #fff; }
.card.stat.total .eyebrow, .card.stat.total .muted { color: rgba(255, 255, 255, 0.85); }
.table-wrap { overflow-x: auto; gap: 4px; }
.stat-table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; margin-top: 8px; }
.stat-table th, .stat-table td { text-align: right; padding: 10px 12px; border-top: 1px solid var(--sep); white-space: nowrap; }
.stat-table th:first-child { text-align: left; }
.stat-table thead th { border-top: 0; font-size: 15px; color: var(--text2); font-weight: 600; }
.stat-table tbody th { font-weight: 500; }

/* Handy/Tablet hochkant: Seitenleiste wird zur Umschaltung oben */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { z-index: 2; height: auto; padding: 12px 16px; flex-direction: row; flex-wrap: wrap; gap: 6px; border-right: 0; border-bottom: 1px solid var(--sep);
    background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); }
  .sidebar .title { width: 100%; padding: 0 4px 6px; }
  .nav { flex: 1; justify-content: center; background: var(--fill); }
  .nav svg { display: none; }
  .nav .badge { margin-left: 4px; }
  .sidebar form { display: none; }
  .main { padding-top: 20px; }
  h1 { font-size: 28px; }
  .card .actions { width: 100%; }
  .card .actions .btn { flex: 1; }
  .thumbs a, .thumbs button { width: calc((100% - 18px) / 4); height: auto; aspect-ratio: 1; }
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pop { from { transform: scale(0.5); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { *, *::after { animation: none !important; transition: none !important; } }
