:root {
  --bg: #f4f5f7; --surface: #fff; --ink: #161a21; --muted: #667085; --line: #e3e6eb;
  --nav: #14181f; --nav-ink: #c9cfd9; --nav-active: #232a35;
  --red: #c8202f; --red-dark: #a3161f; --red-soft: #fdecee;
  --blue: #2f5fd0; --green: #14804a; --amber: #b25e09;
  --c-einsatz: #c8202f; --c-dienst: #2f5fd0; --c-uebung: #d98a0b; --c-sonstiges: #7a8394;
  --radius: 12px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px; color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.5rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* Layout */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--nav); color: var(--nav-ink); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 10px 18px; color: #fff; }
.brand svg { flex: none; }
.brand b { display: block; font-size: .95rem; }
.brand span { font-size: .75rem; color: #8d96a5; }
.nav a { display: flex; gap: 10px; align-items: center; padding: 9px 10px; border-radius: 8px; color: var(--nav-ink); text-decoration: none; cursor: pointer; }
.nav a:hover { background: #1c222b; }
.nav a.active { background: var(--nav-active); color: #fff; box-shadow: inset 3px 0 0 var(--red); }
.nav svg { width: 18px; height: 18px; flex: none; opacity: .9; }
.side .spacer { flex: 1; }
.side .linkbtn { color: #8d96a5; background: none; border: 0; text-align: left; padding: 9px 10px; cursor: pointer; border-radius: 8px; }
.side .linkbtn:hover { background: #1c222b; color: #fff; }
main { padding: 28px 32px 60px; max-width: 1240px; width: 100%; }
.pagehead { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.pagehead p { margin: 4px 0 0; color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* Karten & Tabellen */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 18px 20px; }
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 16px; }
.kpi { padding: 16px 18px; position: relative; overflow: hidden; }
.kpi::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--accent, var(--line)); }
.kpi .label { color: var(--muted); font-size: .82rem; }
.kpi .value { font-size: 1.9rem; font-weight: 650; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: .82rem; margin-top: 2px; }
.two { grid-template-columns: 1.6fr 1fr; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #fafbfc; position: sticky; top: 0; }
th.num, td.num { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: #f7f8fa; }
.tablewrap { overflow-x: auto; border-radius: var(--radius); }
tfoot td { font-weight: 650; background: #fafbfc; border-top: 2px solid var(--line); }
.empty { padding: 44px 20px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--ink); margin-bottom: 4px; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: #eef0f4; color: #3b4352; white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--dot, #99a); }
.badge.einsatz { --dot: var(--c-einsatz); background: var(--red-soft); color: var(--red-dark); }
.badge.dienst { --dot: var(--c-dienst); background: #e9effc; color: #234aa8; }
.badge.uebung { --dot: var(--c-uebung); background: #fdf1de; color: #8a5206; }
.badge.sonstiges { --dot: var(--c-sonstiges); }
.badge.ok { --dot: var(--green); background: #e5f5ec; color: #0e5f37; }
.badge.draft { --dot: var(--amber); background: #fdf1de; color: #8a5206; }

/* Formulare */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 9px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-weight: 550; box-shadow: var(--shadow); }
.btn:hover { background: #f7f8fa; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-dark); }
.btn.danger { color: var(--red-dark); }
.btn.small { padding: 4px 9px; font-size: .85rem; box-shadow: none; }
.btn.ghost { box-shadow: none; border-color: transparent; background: transparent; }
.btn svg { width: 16px; height: 16px; }
label.f { display: grid; gap: 5px; font-size: .82rem; color: var(--muted); font-weight: 550; }
input, select, textarea { padding: 8px 10px; border: 1px solid #cfd4dc; border-radius: 8px; background: #fff; color: var(--ink); width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid #f1a1a8; outline-offset: 1px; border-color: var(--red); }
input:disabled, select:disabled, textarea:disabled { background: #f3f4f6; color: #5b6472; }
textarea { min-height: 70px; resize: vertical; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.fields .wide { grid-column: 1 / -1; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-weight: 550; font-size: .88rem; }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.search { max-width: 260px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar select, .toolbar input, .pagehead select, .row select, .row input:not([type=checkbox]) { width: auto; }

/* Drawer */
.scrim { position: fixed; inset: 0; background: rgba(16,24,40,.38); z-index: 20; animation: fade .15s; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(880px, 100%); background: var(--bg); z-index: 21; display: flex; flex-direction: column; box-shadow: -12px 0 40px rgba(0,0,0,.18); animation: slide .2s ease-out; }
.drawer header { padding: 16px 22px; background: #fff; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.drawer .body { padding: 20px 22px; overflow: auto; flex: 1; display: grid; gap: 16px; align-content: start; }
.drawer footer { padding: 14px 22px; background: #fff; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: space-between; flex-wrap: wrap; }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
.att td, .att th { padding: 6px 8px; }
.att input { padding: 5px 7px; }
.att .t { width: 178px; } .att .m { width: 76px; } .att .r { width: 120px; }

dialog { border: 0; border-radius: 14px; padding: 0; box-shadow: 0 20px 60px rgba(0,0,0,.3); width: min(460px, 94vw); }
dialog::backdrop { background: rgba(16,24,40,.45); }
dialog form { padding: 20px; display: grid; gap: 14px; }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; margin: 4px 0 0; padding: 0; }

/* Chart */
.chart text { fill: var(--muted); font-size: 11px; }
.legend { display: flex; gap: 14px; font-size: .82rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }

/* Toasts */
#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 50; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.25); animation: fade .2s; max-width: 92vw; }
.toast.err { background: var(--red-dark); }

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1200px 500px at 20% -10%, #2a1316 0, transparent 60%), var(--nav); }
.auth .card { width: min(400px, 100%); padding: 28px; display: grid; gap: 16px; }
.notice { padding: 12px 14px; border-radius: 10px; background: #fff8e8; border: 1px solid #f0dcaa; color: #6b4a06; font-size: .9rem; }
.notice.info { background: #eef3fe; border-color: #cddafa; color: #23408f; }
.stack { display: grid; gap: 14px; }
.sep { height: 1px; background: var(--line); margin: 4px 0; }
.chk { display: inline-flex; gap: 8px; align-items: center; font-weight: 500; color: var(--ink); }
.chk input { width: auto; }

@media print { .side, .toolbar, #toasts { display: none; } .shell { display: block; } body { background: #fff; } }
.card.pad.stack { align-content: space-between; }

[hidden] { display: none !important; }
.show-m { display: none; }
/* ================= Smartphone / Tablet hochkant ================= */
.fab { display: none; }
html { -webkit-text-size-adjust: 100%; }
button, a, select, .chip, label { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
@media (max-width: 860px) {
  body { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
  .shell { display: block; }
  /* Navigation als Tab-Leiste unten */
  .side { position: fixed; left: 0; right: 0; bottom: 0; top: auto; height: auto; z-index: 15; flex-direction: row; padding: 0 4px env(safe-area-inset-bottom); gap: 0;
    background: var(--nav); border-top: 1px solid #262d38; }
  .side .brand, .side .spacer, .side .linkbtn { display: none; }
  .nav { display: grid; grid-template-columns: repeat(5, 1fr); width: 100%; }
  .nav a { flex-direction: column; gap: 3px; padding: 9px 2px 8px; font-size: .68rem; border-radius: 0; text-align: center; min-height: 58px; justify-content: center; }
  .nav a span { display: block; }
  .nav a.active { background: none; box-shadow: inset 0 3px 0 var(--red); color: #fff; }
  .nav svg { width: 22px; height: 22px; }
  main { padding: 16px 14px 24px; padding-left: calc(14px + env(safe-area-inset-left)); padding-right: calc(14px + env(safe-area-inset-right)); }
  h1 { font-size: 1.3rem; }
  .pagehead { margin-bottom: 14px; gap: 10px; }
  .pagehead > .row { width: 100%; justify-content: space-between; }
  .hide-m { display: none !important; }
  .two { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 12px 14px; } .kpi .value { font-size: 1.5rem; }

  /* Touch-Ziele & kein iOS-Zoom */
  input, select, textarea { font-size: 16px; min-height: 44px; }
  input[type=checkbox] { min-height: 0; width: 22px; height: 22px; }
  .btn { min-height: 44px; padding: 9px 16px; }
  .btn.small { min-height: 40px; min-width: 40px; }
  .chk { min-height: 40px; }
  .chip { padding: 10px 15px; flex: none; }
  .toolbar { gap: 8px; }
  .toolbar .chips { flex-wrap: nowrap; overflow-x: auto; width: 100%; padding-bottom: 2px; scrollbar-width: none; margin: 0 -14px; padding: 0 14px 2px; }
  .toolbar .chips::-webkit-scrollbar { display: none; }
  .toolbar select, .toolbar .search { flex: 1 1 140px; max-width: none; }
  .fields { grid-template-columns: 1fr; }
  .card.pad { padding: 16px; }

  /* Tabellen -> Karten */
  .tablewrap { overflow: visible; background: none; border: 0; box-shadow: none; }
  .card.tablewrap { background: none; border: 0; box-shadow: none; }
  table.rt, table.rt tbody, table.rt tfoot, table.rt tr, table.rt td { display: block; }
  table.rt thead { display: none; }
  table.rt tbody tr { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; margin-bottom: 10px; }
  table.rt td { border: 0; padding: 0; }
  table.rt tfoot tr { display: flex; justify-content: space-between; padding: 6px 4px; }
  table.rt tfoot td { background: none; border: 0; padding: 0; }
  table.rt tfoot td:empty { display: none; }
  table.rt tr.click:active { background: #f1f3f6; }

  table.acts tbody tr { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "title title" "when type" "people hours" "status status"; gap: 6px 10px; align-items: center; }
  table.acts .c-title { grid-area: title; } .acts .c-title > div:first-child { font-size: 1.02rem; }
  table.acts .c-when { grid-area: when; display: flex; gap: 8px; align-items: baseline; } .acts .c-when .muted { font-size: .9rem !important; }
  table.acts .c-type { grid-area: type; justify-self: end; }
  table.acts .c-people { grid-area: people; text-align: left; color: var(--muted); }
  table.acts .c-hours { grid-area: hours; font-weight: 650; }
  table.acts .c-status { grid-area: status; }
  table.acts .c-status:has(.ok) { display: none; }
  table.acts .c-nr, table.acts .c-sel { display: none; }
  table.acts .c-sel { display: none; }

  table.mem tbody tr { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px 6px; }
  table.mem tbody tr > td:first-child { grid-column: 1 / -1; font-size: 1.02rem; }
  table.mem .m-no { grid-column: 1 / -1; text-align: left; font-size: .82rem; margin-top: -6px; }
  table.mem td[data-l]:not(.m-no) { text-align: left; font-variant-numeric: tabular-nums; }
  table.mem td[data-l]::before, table.att td[data-l]::before { content: attr(data-l); display: block; font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; margin-bottom: 2px; }
  table.mem .m-no::before { display: none; }

  /* Detailansicht: Vollbild */
  .drawer { width: 100%; animation: rise .22s ease-out; }
  .drawer header { padding: calc(12px + env(safe-area-inset-top)) 16px 12px; position: sticky; top: 0; }
  .drawer .body { padding: 14px 12px; }
  .drawer footer { padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); }
  .drawer footer > .row { flex: 1 1 auto; } .drawer footer > .row:last-child { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; width: 100%; }
  .drawer footer .btn { justify-content: center; }
  .att-head { gap: 10px; } .att-head > .row { width: 100%; } .att-head select { width: 100%; }
  .att-head .row { gap: 8px; }
  table.att tbody tr { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; position: relative; box-shadow: none; background: #fafbfc; }
  table.att .a-name { grid-column: 1 / -1; font-weight: 650; padding-right: 44px; }
  table.att .a-del { position: absolute; top: 4px; right: 4px; }
  table.att .t, table.att .m, table.att .r { width: 100%; }
  table.att td[data-l="Funktion"] { grid-column: 1 / -1; }
  table.att tbody tr td:nth-child(2), table.att tbody tr td:nth-child(3) { grid-column: span 1; }
  .att-wrap { padding: 0 10px 10px; }
  dialog { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 18px 18px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  dialog form { padding: 20px 18px; }
  dialog menu { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; }
  dialog menu .btn { justify-content: center; }
  #toasts { bottom: calc(86px + env(safe-area-inset-bottom)); width: calc(100% - 28px); }
  .toast { text-align: center; }

  /* Schnell-Button für neue Tätigkeit */
  .fab { display: inline-flex; align-items: center; gap: 8px; position: fixed; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 14;
    background: var(--red); color: #fff; border: 0; border-radius: 999px; padding: 14px 20px; font-weight: 650; box-shadow: 0 6px 18px rgba(200,32,47,.45); min-height: 52px; }
  .fab:active { background: var(--red-dark); }
  .fab svg { width: 20px; height: 20px; }
  .auth { padding: 16px; align-items: start; padding-top: 14vh; }
}
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
@media (max-width: 380px) { .kpis { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }
@media (max-width: 860px) { .drawer .tablewrap { padding: 0 10px 4px; } }

@media (max-width: 860px) {
  .show-m { display: inline; }
  .drawer .body { grid-template-columns: minmax(0, 1fr); }
  .drawer .body > * { min-width: 0; }
  .fields { grid-template-columns: minmax(0, 1fr); }
  table.att tbody tr { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  table.att td { min-width: 0; }
  table.mem td.m-no::before { content: 'Nr. '; display: inline; font-size: inherit; text-transform: none; letter-spacing: 0; font-weight: 400; margin: 0; }
  .drawer footer { display: grid; grid-template-columns: 1fr; gap: 8px; }
  .drawer footer > .row:first-child:empty { display: none; }
  .drawer footer > .row:first-child { order: 2; justify-content: center; }
  .drawer footer .btn.danger { border-color: transparent; box-shadow: none; min-height: 40px; }
  .drawer .att-head h2 { width: 100%; }
}
.notice a { color: inherit; font-weight: 650; }
@media (max-width: 860px) {
  table.att tbody tr { grid-template-columns: minmax(0, 1fr); }
  table.att td[data-l="Minuten"] { max-width: 50%; }
}
