/*!
 * BFT Core — core.css v1.0.0
 * Design-Tokens + Komponenten + Layout für alle Apps.
 *
 * Aufbau:  1. Tokens (dark = Default, [data-theme="light"] = hell)
 *          2. Reset & Basis    3. Komponenten    4. Layout    5. Utilities
 *
 * Regeln (PROJECT_KNOWLEDGE.md §10):
 *  - Apps überschreiben NUR Tokens (eigene :root-Werte NACH core.css laden),
 *    niemals Komponenten-Selektoren kopieren.
 *  - Neue Komponenten entstehen zuerst hier, dann in der App.
 */

/* ========== 1. DESIGN-TOKENS ========== */
:root {
  /* Farben — Dunkel (Default; Bestand/QuickCheck-Welt) */
  --bg:            #0d1018;
  --surface:       #1a1f2e;
  --surface-2:     #232a3d;   /* Hover, Inputs, abgesetzte Flächen */
  --border:        #2a3148;
  --text:          #e7ecf5;
  --muted:         #93a1bb;

  /* Markenfarbe + Semantik (in allen Apps identisch) */
  --accent:        #4f8ef7;
  --accent-soft:   rgba(79,142,247,.15);
  --ok:            #22c55e;
  --ok-soft:       rgba(34,197,94,.15);
  --warn:          #f7c44f;
  --warn-soft:     rgba(247,196,79,.15);
  --err:           #f05252;
  --err-soft:      rgba(240,82,82,.15);

  /* Radien */
  --radius-sm:     8px;
  --radius:        12px;
  --radius-lg:     16px;
  --radius-pill:   999px;

  /* Schatten */
  --shadow-sm:     0 1px 2px rgba(0,0,0,.18);
  --shadow:        0 4px 12px rgba(0,0,0,.22);
  --shadow-lg:     0 12px 40px rgba(0,0,0,.35);

  /* Typografie & Bewegung */
  --font:          -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono:     ui-monospace, SFMono-Regular, Menlo, monospace;
  --ease:          cubic-bezier(.4,0,.2,1);

  /* Layout-Maße */
  --sidebar-w:     240px;
  --topbar-h:      56px;
  --nav-h:         64px;      /* mobile Bottom-Navigation */
}

[data-theme="light"] {
  --bg:        #f5f7fb;
  --surface:   #ffffff;
  --surface-2: #eef2f8;
  --border:    #e4e9f1;
  --text:      #16202e;
  --muted:     #5d6b82;
  --shadow-sm: 0 1px 2px rgba(16,24,40,.06);
  --shadow:    0 4px 12px rgba(16,24,40,.08);
  --shadow-lg: 0 12px 40px rgba(16,24,40,.14);
}

/* ========== 2. RESET & BASIS ========== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
::selection { background: var(--accent-soft); }

/* ========== 3. KOMPONENTEN ========== */

/* --- Button --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--accent); color: #fff;
  border: none; padding: 10px 16px;
  border-radius: var(--radius-sm);
  font: inherit; font-size: .9rem; font-weight: 600;
  cursor: pointer; white-space: nowrap;
  transition: filter .15s var(--ease), transform .12s var(--ease);
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); font-weight: 500; }
.btn.danger { background: var(--err); }
.btn.ok { background: var(--ok); }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); font-weight: 500; }
.btn.sm { padding: 6px 12px; font-size: .8rem; }
.btn.lg { padding: 14px 20px; font-size: 1rem; border-radius: var(--radius); }
.btn.block { display: flex; width: 100%; }

/* --- Card --- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.card.tight { padding: 10px 14px; }
.card.clickable { cursor: pointer; transition: box-shadow .15s var(--ease), border-color .15s var(--ease); }
.card.clickable:hover { box-shadow: var(--shadow); border-color: var(--accent); }
.card-title { font-weight: 700; font-size: .95rem; margin-bottom: 8px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }

/* --- Badge --- */
.badge {
  display: inline-block; font-size: .7rem; font-weight: 700;
  padding: 3px 10px; border-radius: var(--radius-pill); white-space: nowrap;
  background: var(--surface-2); color: var(--muted);
}
.badge.ok   { background: var(--ok-soft);   color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err  { background: var(--err-soft);  color: var(--err); }
.badge.info { background: var(--accent-soft); color: var(--accent); }

/* --- Chip (Filter) --- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-pill);
  padding: 8px 14px; font: inherit; font-size: .85rem;
  cursor: pointer; white-space: nowrap;
  transition: border-color .15s var(--ease), background .15s var(--ease);
}
.chip:hover { border-color: var(--accent); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }

/* --- Tabelle --- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table.tbl { width: 100%; border-collapse: collapse; font-size: .88rem; background: var(--surface); }
.tbl th {
  text-align: left; padding: 10px 12px;
  font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
}
.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--border); }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl th.sortable { cursor: pointer; user-select: none; }
.tbl th.sortable:hover { color: var(--text); }

/* --- Formulare --- */
.fld { display: block; font-size: .82rem; font-weight: 500; color: var(--muted); margin: 12px 0 5px; }
.fld .req { color: var(--err); }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=search], input[type=date], input[type=url], input[type=time],
textarea, select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 10px 12px;
  font: inherit; font-size: .92rem;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; min-height: 90px; }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 17px; height: 17px; cursor: pointer; }
.check-row { display: flex; align-items: center; gap: 8px; margin: 12px 0; cursor: pointer; }
.field-error { color: var(--err); font-size: .78rem; margin-top: 4px; display: none; }
.invalid input, .invalid textarea, .invalid select { border-color: var(--err); }
.invalid .field-error { display: block; }
.form-help { color: var(--muted); font-size: .78rem; margin-top: 4px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* --- Suchfeld --- */
.search-box { position: relative; }
.search-box input { padding-left: 36px; }
.search-box::before {
  content: "⌕"; position: absolute; left: 12px; top: 50%;
  transform: translateY(-50%); color: var(--muted); font-size: 1.1rem; pointer-events: none;
}
.search-results {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 250;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  max-height: 55vh; overflow-y: auto; display: none;
}
.search-results.open { display: block; }
.search-hit { padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--border); }
.search-hit:last-child { border-bottom: none; }
.search-hit:hover, .search-hit.sel { background: var(--surface-2); }
.search-hit .t { font-weight: 600; font-size: .9rem; }
.search-hit .s { color: var(--muted); font-size: .8rem; }
.search-hit .s mark { background: var(--warn-soft); color: var(--warn); border-radius: 3px; padding: 0 2px; }

/* --- Modal --- */
.modal {
  display: none; position: fixed; inset: 0; z-index: 300;
  background: rgba(8,10,16,.6); backdrop-filter: blur(2px);
  align-items: flex-start; justify-content: center;
  padding: 4vh 16px;
}
.modal.open { display: flex; }
.modal-content {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: 100%; max-width: min(720px, 96vw);
  max-height: 90vh; display: flex; flex-direction: column;
  animation: core-pop .18s var(--ease);
}
.modal-content.wide { max-width: min(1100px, 96vw); }
.modal-header {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 1.05rem; }
.modal-close {
  background: none; border: none; color: var(--muted);
  font-size: 1.15rem; cursor: pointer; padding: 4px 8px; border-radius: var(--radius-sm);
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-body { flex: 1; overflow-y: auto; padding: 16px 18px; }
.modal-footer {
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 14px 18px; border-top: 1px solid var(--border);
}
@keyframes core-pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }

/* --- Toast --- */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(80px);
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 12px 18px; font-weight: 600; font-size: .9rem;
  z-index: 400; opacity: 0; pointer-events: none; max-width: min(480px, 90vw);
  transition: opacity .25s var(--ease), transform .25s var(--ease);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { border-color: var(--ok);   color: var(--ok); }
.toast.error   { border-color: var(--err);  color: var(--err); }
.toast.warning { border-color: var(--warn); color: var(--warn); }
body.has-bottomnav .toast { bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); }

/* --- Benachrichtigungs-Glocke --- */
.notif-bell { position: relative; background: none; border: none; color: var(--muted); font-size: 1.15rem; cursor: pointer; padding: 6px 9px; border-radius: var(--radius-sm); }
.notif-bell:hover { background: var(--surface-2); color: var(--text); }
.notif-bell .cnt {
  position: absolute; top: 0; right: 0;
  background: var(--err); color: #fff;
  font-size: .62rem; font-weight: 700;
  min-width: 16px; height: 16px; line-height: 16px;
  border-radius: var(--radius-pill); text-align: center; padding: 0 3px;
}

/* --- Leerzustand / Laden --- */
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty .icon { font-size: 2rem; margin-bottom: 8px; }
.spinner {
  width: 22px; height: 22px; margin: 24px auto;
  border: 3px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: core-spin .7s linear infinite;
}
@keyframes core-spin { to { transform: rotate(360deg); } }

/* ========== 4. LAYOUT ========== */
#sidebar {
  position: fixed; top: 0; left: 0; z-index: 200;
  width: var(--sidebar-w); height: 100dvh;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transition: transform .25s var(--ease);
}
.sidebar-brand { padding: 16px; font-weight: 800; font-size: 1.02rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 10px 8px; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; margin: 1px 0; border-radius: var(--radius-sm);
  color: var(--muted); font-size: .9rem; font-weight: 500; text-decoration: none;
}
.sidebar-nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.sidebar-nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar-foot { padding: 12px 16px; border-top: 1px solid var(--border); color: var(--muted); font-size: .78rem; }

#app-shell { margin-left: var(--sidebar-w); min-height: 100dvh; display: flex; flex-direction: column; }

#topbar {
  display: flex; align-items: center; gap: 12px;
  height: var(--topbar-h); padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 150;
}
#topbar .grow { flex: 1; }
.burger { display: none; background: none; border: none; color: var(--text); font-size: 1.3rem; cursor: pointer; padding: 4px 8px; }

#content { flex: 1; padding: 20px; max-width: 1400px; width: 100%; }

#bottomnav {
  display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 150;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
#bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: .68rem; font-weight: 600; text-decoration: none;
}
#bottomnav a .ic { font-size: 1.25rem; }
#bottomnav a.active { color: var(--accent); }

@media (max-width: 900px) {
  #sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  #sidebar.open { transform: translateX(0); }
  #app-shell { margin-left: 0; }
  #content { padding: 14px 12px calc(var(--nav-h) + 24px); }
  .burger { display: block; }
  body.has-bottomnav #bottomnav { display: flex; }
  .modal { padding: 0; align-items: flex-end; }
  .modal-content { max-width: 100%; max-height: 94vh; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .form-actions { flex-direction: column-reverse; }
  .form-actions .btn { width: 100%; }
}

/* ========== 5. UTILITIES ========== */
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.mono { font-family: var(--font-mono); }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mt0 { margin-top: 0; } .mb0 { margin-bottom: 0; }
.hidden { display: none !important; }
.text-ok { color: var(--ok); } .text-warn { color: var(--warn); } .text-err { color: var(--err); }
