/* ============================ Karten ============================ */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--sp-4);
  box-shadow: var(--shadow-xs);
}
.card.flush { padding: 0; overflow: hidden; }
.card.pad-lg { padding: var(--sp-5); }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-3); margin-bottom: var(--sp-3);
}
.card-title { font-size: .9rem; font-weight: 650; }
.card-sub { font-size: .78rem; color: var(--text-muted); }
.card-body { padding: var(--sp-4); }
.card-foot {
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--line); background: var(--surface-2);
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
}
.card-link { display: block; color: inherit; }
.card-link:hover { text-decoration: none; border-color: var(--line-strong); }
.card-interactive { transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease); cursor: pointer; }
.card-interactive:hover { border-color: var(--line-strong); box-shadow: var(--shadow-sm); }
.card-interactive:active { transform: translateY(1px); }

/* ============================ Buttons ============================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 0 14px; min-height: 36px;
  border-radius: var(--radius); border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--text);
  font-size: .86rem; font-weight: 550; white-space: nowrap;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
              opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn svg { flex: 0 0 auto; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); border-color: color-mix(in srgb, var(--accent) 88%, #000); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-subtle { background: var(--surface-2); border-color: transparent; }
.btn-subtle:hover { background: var(--surface-3); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 86%, #000); }
.btn-danger-ghost { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); background: transparent; }
.btn-danger-ghost:hover { background: var(--danger-bg); }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: .8rem; border-radius: var(--radius-sm); }
.btn-lg { min-height: 44px; padding: 0 20px; font-size: .93rem; }
.btn-block { width: 100%; }
.btn-icon { padding: 0; width: 36px; min-height: 36px; }
.btn-icon.btn-sm { width: 30px; min-height: 30px; }

.btn-group { display: inline-flex; background: var(--surface-2); border-radius: var(--radius); padding: 3px; gap: 2px; }
.btn-group button {
  border: 0; background: transparent; color: var(--text-muted);
  padding: 5px 12px; border-radius: var(--radius-sm);
  font-size: .82rem; font-weight: 550;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.btn-group button:hover { color: var(--text); }
.btn-group button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-xs); font-weight: 600; }

/* Schwebender Aktionsbutton (nur mobil) */
.fab {
  position: fixed; right: var(--sp-4);
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + var(--sp-4));
  width: 52px; height: 52px; border-radius: 16px; z-index: 35;
  background: var(--accent); color: var(--accent-ink); border: 0;
  display: none; place-items: center; box-shadow: var(--shadow-lg);
}
@media (max-width: 1024px) { .fab { display: grid; } }

/* ============================ Formulare ============================ */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label {
  font-size: .78rem; font-weight: 600; color: var(--text-muted);
}
.field-hint { font-size: .74rem; color: var(--text-faint); }
.field-error { font-size: .75rem; color: var(--danger); }

.input, .select, .textarea {
  width: 100%; min-height: 38px; padding: 8px 11px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  font-size: .88rem; transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  appearance: none;
}
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-faint); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak);
}
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input[aria-invalid="true"], .select[aria-invalid="true"] { border-color: var(--danger); }
.textarea { min-height: 78px; resize: vertical; line-height: 1.5; }
.input.num-input { font-variant-numeric: tabular-nums; }
.select {
  padding-right: 30px; cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23878d99' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat; background-position: right 9px center;
}
input[type="color"] { padding: 3px; height: 38px; cursor: pointer; }
input[type="date"], input[type="time"] { min-height: 38px; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-4); }
.form-grid .span-2 { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid { grid-template-columns: minmax(0, 1fr); } .form-grid .span-2 { grid-column: auto; } }

/* Schalter */
.switch { position: relative; display: inline-flex; flex: 0 0 auto; width: 42px; height: 24px; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch .track {
  position: absolute; inset: 0; border-radius: 999px;
  background: var(--line-strong); transition: background var(--dur) var(--ease);
}
.switch .track::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px;
  background: #fff; border-radius: 50%; box-shadow: var(--shadow-xs);
  transition: transform var(--dur) var(--ease);
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

.setting-row {
  display: flex; align-items: center; gap: var(--sp-4);
  padding: var(--sp-3) 0; border-bottom: 1px solid var(--line);
}
.setting-row:last-child { border-bottom: 0; }
.setting-row .setting-label { font-size: .88rem; font-weight: 550; }
.setting-row .setting-desc { font-size: .77rem; color: var(--text-muted); margin-top: 2px; }
.setting-row .setting-control { margin-left: auto; flex: 0 0 auto; display: flex; align-items: center; gap: var(--sp-2); }
.setting-row .setting-control .input,
.setting-row .setting-control .select { min-width: 160px; }
@media (max-width: 560px) {
  .setting-row { flex-direction: column; align-items: stretch; }
  .setting-row .setting-control { margin-left: 0; width: 100%; }
  .setting-row .setting-control .input, .setting-row .setting-control .select { min-width: 0; width: 100%; }
  .setting-row .setting-control .switch { margin-left: auto; }
}

/* Farbwahl */
.swatches { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.swatch {
  width: 30px; height: 30px; border-radius: 8px; border: 2px solid transparent;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.09); position: relative;
  transition: transform var(--dur) var(--ease);
}
.swatch:hover { transform: scale(1.08); }
.swatch.active { border-color: var(--text); }
.swatch.active::after {
  content: ''; position: absolute; inset: 0; margin: auto; width: 9px; height: 9px;
  border-radius: 50%; background: #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.16);
}

/* ============================ Badges / Chips ============================ */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px;
  font-size: .73rem; font-weight: 600; white-space: nowrap;
  background: var(--surface-3); color: var(--text-muted);
}
.badge-accent { background: var(--accent-weak); color: var(--accent); }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-outline { background: transparent; border: 1px solid var(--line-strong); }

.dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.dot-lg { width: 10px; height: 10px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: var(--surface);
  font-size: .81rem; font-weight: 550; color: var(--text-muted);
  transition: all var(--dur) var(--ease);
}
.chip:hover { border-color: var(--text-faint); color: var(--text); }
.chip.active { background: var(--accent-weak); border-color: color-mix(in srgb, var(--accent) 40%, transparent); color: var(--accent); }
.chip-row { display: flex; gap: var(--sp-2); overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }

/* ============================ Tabellen ============================ */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .87rem; }
.table th {
  text-align: left; font-size: .73rem; font-weight: 650; text-transform: uppercase;
  letter-spacing: .04em; color: var(--text-faint);
  padding: 9px var(--sp-3); border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table td { padding: 10px var(--sp-3); border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background var(--dur) var(--ease); }
.table tbody tr:hover { background: var(--surface-2); }
.table .col-actions { width: 1%; white-space: nowrap; text-align: right; }
.table .num { font-variant-numeric: tabular-nums; }
.row-actions { display: inline-flex; gap: 2px; opacity: .55; transition: opacity var(--dur) var(--ease); }
tr:hover .row-actions, .row-actions:focus-within { opacity: 1; }
@media (hover: none) { .row-actions { opacity: 1; } }

/* ============================ Listen ============================ */
.list { display: flex; flex-direction: column; }
.list-item {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--line);
  transition: background var(--dur) var(--ease); text-align: left;
  background: transparent; border-left: 0; border-right: 0; border-top: 0; width: 100%;
  color: inherit;
}
.list-item:last-child { border-bottom: 0; }
.list-item:hover { background: var(--surface-2); text-decoration: none; }
.list-title { font-size: .88rem; font-weight: 550; }
.list-sub { font-size: .77rem; color: var(--text-muted); }
.list-meta { margin-left: auto; text-align: right; flex: 0 0 auto; }

/* ============================ Modal / Sheet ============================ */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(12, 15, 20, .42);
  backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
  display: grid; place-items: center; padding: var(--sp-5);
  animation: fadeIn 140ms var(--ease);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--bg-elevated); border: 1px solid var(--line);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-lg);
  width: min(560px, 100%); max-height: min(86dvh, 820px);
  display: flex; flex-direction: column; overflow: hidden;
  animation: modalIn 180ms var(--ease);
}
@keyframes modalIn { from { opacity: 0; transform: translateY(10px) scale(.985); } to { opacity: 1; transform: none; } }
.modal.modal-lg { width: min(760px, 100%); }
.modal.modal-sm { width: min(420px, 100%); }
.modal-head {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--line);
}
.modal-title { font-size: 1rem; font-weight: 650; }
.modal-desc { font-size: .8rem; color: var(--text-muted); margin-top: 2px; }
.modal-close { margin-left: auto; flex: 0 0 auto; }
.modal-body { padding: var(--sp-5); overflow-y: auto; flex: 1 1 auto; }
.modal-foot {
  display: flex; align-items: center; justify-content: flex-end; gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--line);
  background: var(--surface-2); flex-wrap: wrap;
}
.modal-foot .spacer { margin-right: auto; }

@media (max-width: 640px) {
  /* Auf dem Smartphone als Bottom-Sheet – natuerlicher fuer Touch. */
  .modal-backdrop { padding: 0; align-items: end; }
  .modal {
    width: 100%; max-width: none; max-height: 92dvh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    border-bottom: 0; animation: sheetIn 220ms var(--ease);
    padding-bottom: var(--safe-bottom);
  }
  @keyframes sheetIn { from { transform: translateY(100%); } to { transform: none; } }
  .modal-head, .modal-body, .modal-foot { padding-left: var(--sp-4); padding-right: var(--sp-4); }
  .modal-foot { position: sticky; bottom: 0; }
  .modal-foot .btn { flex: 1 1 auto; }
  .modal-foot .spacer { flex-basis: 100%; margin-right: 0; }
  .sheet-handle {
    width: 36px; height: 4px; border-radius: 2px; background: var(--line-strong);
    margin: 8px auto 0; flex: 0 0 auto;
  }
}
@media (min-width: 641px) { .sheet-handle { display: none; } }

/* ============================ Toast ============================ */
.toast-root {
  position: fixed; z-index: 300; bottom: calc(var(--safe-bottom) + var(--sp-4));
  left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column-reverse; gap: var(--sp-2);
  width: min(420px, calc(100vw - 24px)); pointer-events: none;
}
@media (max-width: 1024px) { .toast-root { bottom: calc(var(--tabbar-h) + var(--safe-bottom) + var(--sp-3)); } }
.toast {
  display: flex; align-items: center; gap: 10px; pointer-events: auto;
  padding: 11px 14px; border-radius: var(--radius);
  background: var(--bg-elevated); border: 1px solid var(--line);
  box-shadow: var(--shadow-md); font-size: .86rem;
  animation: toastIn 200ms var(--ease);
}
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.toast.leaving { animation: toastOut 160ms var(--ease) forwards; }
@keyframes toastOut { to { opacity: 0; transform: translateY(6px); } }
.toast .toast-icon { flex: 0 0 auto; display: grid; place-items: center; }
.toast-ok .toast-icon { color: var(--ok); }
.toast-error .toast-icon { color: var(--danger); }
.toast-warn .toast-icon { color: var(--warn); }
.toast-info .toast-icon { color: var(--info); }
.toast .toast-action { margin-left: auto; flex: 0 0 auto; }

/* ============================ Leerzustaende ============================ */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--sp-3); padding: var(--sp-8) var(--sp-5); text-align: center;
}
.empty-icon {
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  background: var(--surface-2); color: var(--text-faint);
}
.empty-title { font-size: .93rem; font-weight: 600; }
.empty-text { font-size: .83rem; color: var(--text-muted); max-width: 40ch; }

.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%);
  background-size: 400% 100%; animation: shimmer 1.3s ease infinite; border-radius: var(--radius-sm);
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* ============================ Statistik-Kacheln ============================ */
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: var(--sp-4); min-width: 0;
}
.stat-label {
  font-size: .74rem; font-weight: 600; color: var(--text-faint);
  text-transform: uppercase; letter-spacing: .045em;
}
.stat-value {
  font-size: 1.65rem; font-weight: 660; font-variant-numeric: tabular-nums;
  letter-spacing: -.02em; line-height: 1.1; margin-top: 6px;
}
.stat-value.sm { font-size: 1.25rem; }
.stat-meta { font-size: .77rem; color: var(--text-muted); margin-top: 4px; display: flex; align-items: center; gap: 5px; }
.trend-up { color: var(--ok); } .trend-down { color: var(--danger); } .trend-flat { color: var(--text-faint); }

/* ============================ Fortschritt ============================ */
.progress { height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: 3px; background: var(--accent); transition: width 320ms var(--ease); }

/* ============================ Segmentierte Tabs ============================ */
.tabs { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  border: 0; background: transparent; color: var(--text-muted);
  padding: 9px 13px; font-size: .86rem; font-weight: 550; white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* ============================ Menu (Popover) ============================ */
.menu {
  position: fixed; z-index: 120; min-width: 190px;
  background: var(--bg-elevated); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 5px; animation: menuIn 120ms var(--ease);
}
@keyframes menuIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.menu button, .menu a {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 7px 10px; border: 0; background: transparent; color: var(--text);
  font-size: .85rem; text-align: left; border-radius: var(--radius-sm);
}
.menu button:hover, .menu a:hover { background: var(--surface-2); text-decoration: none; }
.menu .danger { color: var(--danger); }
.menu .menu-sep { height: 1px; background: var(--line); margin: 5px 3px; }
.menu .menu-label { font-size: .71rem; color: var(--text-faint); padding: 6px 10px 3px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

/* ============================ Sync-Status ============================ */
.sync-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 9px; border-radius: 999px; font-size: .74rem; font-weight: 600;
  background: var(--surface-2); color: var(--text-muted); border: 1px solid transparent;
}
.sync-pill.syncing { color: var(--info); background: color-mix(in srgb, var(--info) 12%, transparent); }
.sync-pill.offline { color: var(--warn); background: var(--warn-bg); }
.sync-pill.error { color: var(--danger); background: var(--danger-bg); }
.sync-pill.synced { color: var(--ok); background: var(--ok-bg); }
.sync-pill .spin { animation: spin 1s linear infinite; }

.banner {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4); border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface-2); font-size: .84rem;
}
.banner-icon { flex: 0 0 auto; margin-top: 1px; }
.banner-warn { background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.banner-danger { background: var(--danger-bg); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.banner-info { background: color-mix(in srgb, var(--info) 10%, transparent); border-color: color-mix(in srgb, var(--info) 26%, transparent); }
.banner .banner-action { margin-left: auto; flex: 0 0 auto; }
