:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #1b1f27;
  --muted: #677084;
  --accent: #f7931a;
  --accent-ink: #1b1f27;
  --pos: #12804a;
  --neg: #c62f2f;
  --warn-bg: #fff4e0;
  --warn-text: #7a4a00;
  --err-bg: #fde8e8;
  --focus: #2f6fdf;
  --radius: 10px;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --surface: #1b2029;
    --surface-2: #232934;
    --border: #2f3744;
    --text: #e7eaf0;
    --muted: #949db0;
    --pos: #43c47f;
    --neg: #f06a6a;
    --warn-bg: #3a2c12;
    --warn-text: #f5cf8a;
    --err-bg: #3c1d1f;
    --focus: #6d9cf0;
  }
}

* { box-sizing: border-box; }

/* Das hidden-Attribut muss immer greifen, auch wenn eine Klasse display setzt (z.B. .login-view, .field) */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Segoe UI", system-ui, sans-serif;
}

h2 { font-size: 15px; margin: 0; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.req { color: var(--neg); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Kopfbereich */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 24px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.logo {
  display: inline-grid; place-items: center;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 18px;
}
.price-main { display: flex; align-items: center; gap: 8px; }
.price-main strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.price-meta { font-size: 12px; }
.price-meta.warn { color: var(--neg); }
.manual-price { display: flex; flex-direction: column; gap: 2px; }
.manual-price label { font-size: 12px; color: var(--muted); }
.input-with-btn { display: flex; gap: 6px; }
.input-with-btn input { width: 150px; }
.top-actions { display: flex; gap: 8px; margin-left: auto; }

/* Bedienelemente */
input, select {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 9px;
  min-width: 0;
}
input:focus, select:focus, .btn:focus-visible, .segmented button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}
input.invalid { border-color: var(--neg); }

.btn {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 7px;
  padding: 7px 14px;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .6; cursor: default; }
.btn-small { padding: 4px 9px; font-size: 12px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-link {
  font: inherit; font-size: 12px; cursor: pointer;
  background: none; border: none; color: var(--focus); padding: 2px 4px;
}
.btn-link.danger { color: var(--neg); }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented button {
  font: inherit; cursor: pointer; border: none; padding: 7px 14px;
  background: var(--surface); color: var(--muted);
}
.segmented button.active { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* Inhalt */
main { max-width: 1320px; margin: 0 auto; padding: 20px 24px 48px; display: grid; gap: 20px; }

.banner {
  background: var(--warn-bg); color: var(--warn-text);
  border-radius: var(--radius); padding: 10px 14px;
}

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px;
}
.kpi .k-label { font-size: 12px; color: var(--muted); }
.kpi .k-value { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi .k-sub { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.kpi.hero { border-top: 3px solid var(--accent); }

.grid2 { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; align-items: start; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.card-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; flex-wrap: wrap; margin-bottom: 12px;
}

/* Formular */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--muted); }
.field-wide { grid-column: 1 / -1; }
.err { color: var(--neg); font-size: 12px; min-height: 0; }
.err:empty { display: none; }
.tx-total {
  margin-top: 12px; padding: 8px 12px; border-radius: 7px;
  background: var(--surface-2); font-variant-numeric: tabular-nums;
}
.tx-total.warn { background: var(--warn-bg); color: var(--warn-text); }
.form-error {
  margin-top: 12px; padding: 8px 12px; border-radius: 7px;
  background: var(--err-bg); color: var(--neg);
}
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* Tabellen */
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted);
  padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 7px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: top; }
.table tbody tr:hover { background: var(--surface-2); }
.table tr.editing { background: var(--warn-bg); }
.table .num { text-align: right; }
.table .note { display: block; font-size: 12px; color: var(--muted); white-space: normal; max-width: 260px; }
.table.compact td { padding: 5px 8px; }
.badge {
  display: inline-block; font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px; background: var(--surface-2);
}
.badge.BUY, .badge.BTC_IN { color: var(--pos); }
.badge.SELL, .badge.BTC_OUT { color: var(--neg); }
.empty { margin: 12px 0 0; }

.input-with-unit { display: flex; gap: 6px; align-items: center; }
.mono { font-family: var(--mono); font-size: 13px; }
a.btn { text-decoration: none; white-space: nowrap; }
.tx-link { font-size: 12px; color: var(--focus); text-decoration: none; white-space: nowrap; }
.input-with-unit input { flex: 1; }
.input-with-unit select, .input-with-unit button { flex: 0 0 auto; }
.field-check { justify-content: flex-end; }
.field-check label { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--text); padding: 7px 0; }
.status-inactive { color: var(--muted); font-style: italic; }

/* Konfigurationsmaske */
h3 { font-size: 14px; margin: 0; font-weight: 600; }
.dialog {
  width: min(860px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 16px;
}
.dialog::backdrop { background: rgba(0, 0, 0, .45); }
.sub-card {
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 14px;
}

.table-wrap + .sub-card { margin: 14px 0 0; }
#httpForm p, #notifyForm p { margin: 0 0 8px; }

/* Anmeldeprotokoll und Hinweis beim Admin-Login (STORY-S7) */
.head-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.check-inline { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.banner.notice { display: flex; align-items: center; justify-content: space-between; gap: 8px 12px; flex-wrap: wrap; }
.notice-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.table tr.log-issue td:last-child { color: var(--neg); font-weight: 600; }
#loginLogInfo { margin: 0 0 8px; }
#notifyForm .input-with-btn input { flex: 1; width: auto; min-width: 0; }
#notifyForm .form-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }

.dialog-small { width: min(420px, calc(100vw - 32px)); }
.dialog-medium { width: min(560px, calc(100vw - 32px)); }

/* 2FA */
.form-actions.start { justify-content: flex-start; }
.btn-danger { color: var(--neg); border-color: var(--neg); background: var(--surface); }
.steps { margin: 0 0 12px; padding-left: 20px; }
.qr-wrap { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
/* QR-Code immer dunkel auf hell, damit er auch im Dark-Mode scannbar ist */
.qr-box { background: #fff; padding: 8px; border-radius: 8px; line-height: 0; }
.qr-box svg { width: 180px; height: 180px; }
.secret {
  display: block; font-family: var(--mono); font-size: 15px; letter-spacing: .5px;
  margin: 4px 0; word-break: break-all; user-select: all;
}
.backup-codes {
  list-style: none; padding: 0; margin: 0 0 8px;
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 16px;
  font-family: var(--mono); font-size: 15px;
}
#tfaDialog form, #tfaDialog section { display: grid; gap: 10px; }
.dialog-small .field { margin-bottom: 10px; }

/* Login */
.login-view { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(400px, 100%); padding: 24px; }
.login-card form { display: grid; gap: 12px; }
.login-card h2 { margin-bottom: 2px; }
.login-brand { justify-content: center; margin-bottom: 16px; }
.login-card .banner { margin-bottom: 12px; }
.user-box { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Datenspeicher */
.storage-actions { display: grid; gap: 8px; margin-top: 12px; justify-items: start; }
.storage-actions .btn { width: 100%; text-align: left; }
.storage-actions label { display: flex; gap: 6px; align-items: center; margin: -2px 0 6px 4px; }
.storage-line { text-align: center; margin: -8px 0 12px; }
#storageView .sub-card p { margin: 0 0 8px; }

@media (max-width: 900px) {
  .grid2 { grid-template-columns: 1fr; }
  .top-actions { margin-left: 0; }
}
@media (max-width: 600px) {
  .topbar { padding: 10px 16px; position: static; }
  main { padding: 16px 16px 40px; }
}
