/* ---------- Schriften (lokal, keine Drittanbieter) ---------- */
@font-face { font-family: "Plex"; src: url(fonts/ibm-plex-sans-latin-400-normal.woff2) format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Plex"; src: url(fonts/ibm-plex-sans-latin-500-normal.woff2) format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Plex"; src: url(fonts/ibm-plex-sans-latin-600-normal.woff2) format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Plex Cond"; src: url(fonts/ibm-plex-sans-condensed-latin-500-normal.woff2) format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Plex Cond"; src: url(fonts/ibm-plex-sans-condensed-latin-600-normal.woff2) format("woff2"); font-weight: 600; font-display: swap; }

/* ---------- Tokens ---------- */
:root {
  --paper: #ECEEF1;
  --surface: #FFFFFF;
  --ink: #18212C;
  --muted: #5C6878;
  --rule: #D3D9E0;
  --gold: #9C7412;
  --gold-fill: #D9AE3E;
  --silver: #5F6C79;
  --silver-fill: #A3AFBB;
  --up: #1E7650;
  --down: #B0373A;
  --focus: #2F6FD0;

  --sans: "Plex", "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --cond: "Plex Cond", "IBM Plex Sans Condensed", "Arial Narrow", "Roboto Condensed", var(--sans);

  --r-lg: 18px;
  --r-sm: 9px;
  --pad: clamp(16px, 4vw, 28px);
  --tabbar: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #10151C;
    --surface: #18202A;
    --ink: #E7EBF0;
    --muted: #93A0AF;
    --rule: #29323E;
    --gold: #E2B94E;
    --gold-fill: #C99A2E;
    --silver: #BAC4CE;
    --silver-fill: #7F8B98;
    --up: #5CC08F;
    --down: #EE7B7B;
    --focus: #79A8F0;
    color-scheme: dark;
  }
}

/* ---------- Basis ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 15px/1.5 var(--sans);
  font-feature-settings: "tnum" 1;
  min-height: 100dvh;
  padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom));
}
h1, h2 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 17px; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
a { color: inherit; }
abbr { text-decoration: none; cursor: help; color: var(--muted); }
code { font-size: 0.92em; background: color-mix(in srgb, var(--rule) 60%, transparent); padding: 1px 5px; border-radius: 5px; }

/* ---------- Kopfzeile ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: calc(env(safe-area-inset-top) + 12px) max(var(--pad), calc((100vw - 1240px) / 2 + var(--pad))) 12px;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.brand > div { min-width: 0; }
.brand-mark { width: 34px; height: 34px; flex: none; }
.brand-mark .m-gold { fill: var(--gold-fill); }
.brand-mark .m-silver { fill: var(--silver-fill); mix-blend-mode: multiply; opacity: .9; }
@media (prefers-color-scheme: dark) { .brand-mark .m-silver { mix-blend-mode: screen; } }
.brand h1 { font-size: 19px; line-height: 1.15; }
.status { margin: 0; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status.err { color: var(--down); }

.icon-btn {
  width: 42px; height: 42px; flex: none;
  display: grid; place-items: center;
  border: 1px solid var(--rule); border-radius: 50%;
  background: var(--surface);
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.spin svg { animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Tabs: oben am Desktop, unten als Tab-Leiste am Handy */
.tabs { display: flex; gap: 4px; padding: 4px; background: color-mix(in srgb, var(--rule) 55%, transparent); border-radius: 12px; }
.tab { border: 0; background: transparent; padding: 8px 18px; border-radius: 9px; color: var(--muted); font-weight: 500; }
.tab[aria-current="page"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / .08); }

@media (max-width: 719px) {
  /* backdrop-filter würde die fixierte Tab-Leiste im Header einsperren */
  .top { backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--paper); }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    height: calc(var(--tabbar) + env(safe-area-inset-bottom));
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
    border-radius: 0; gap: 8px;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--rule);
  }
  .tab { flex: 1; font-size: 15px; }
  .tab[aria-current="page"] { background: color-mix(in srgb, var(--rule) 60%, transparent); box-shadow: none; }
}
@media (min-width: 720px) { body { padding-bottom: 32px; } }

main { max-width: 1240px; margin: 0 auto; padding: 20px var(--pad) 24px; }

/* ---------- Metall-Kacheln ---------- */
.view { display: grid; gap: 20px; }
.view > *, .metals > *, .alerts-grid > * { min-width: 0; }
.metals { display: grid; gap: 16px; }
@media (min-width: 720px) { .metals { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1100px) {
  #view-prices { grid-template-columns: 360px 1fr; align-items: start; }
  .metals { grid-template-columns: 1fr; }
}

.metal {
  --c: var(--gold); --cf: var(--gold-fill);
  position: relative;
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 20px 20px 16px;
  border: 1px solid var(--rule);
  overflow: hidden;
}
.metal[data-metal="silver"] { --c: var(--silver); --cf: var(--silver-fill); }
.metal::before { /* Metallkante oben */
  content: ""; position: absolute; inset: 0 0 auto; height: 4px;
  background: linear-gradient(90deg, var(--cf), color-mix(in srgb, var(--cf) 40%, var(--surface)) 60%, var(--cf));
}
.metal > header { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.metal h2 { font-size: 17px; color: var(--muted); font-weight: 500; }

/* Punze: das gestempelte Feingehaltszeichen */
.hallmark {
  display: grid; place-items: center; line-height: 1;
  width: 60px; height: 44px; border-radius: 50%;
  border: 2px solid var(--c); color: var(--c);
  box-shadow: inset 0 0 0 3px var(--surface), inset 0 0 0 4px color-mix(in srgb, var(--c) 45%, transparent);
  transform: rotate(-6deg);
}
.hallmark span { font: 600 17px/1 var(--cond); letter-spacing: .02em; }
.hallmark small { font: 500 9px/1 var(--cond); margin-top: -9px; letter-spacing: .04em; }

.spot { margin: 0; display: flex; align-items: baseline; gap: 8px; }
.num { font: 600 clamp(38px, 9vw, 46px)/1 var(--cond); letter-spacing: -0.015em; }
.unit { font-size: 14px; color: var(--muted); }
.delta { margin: 6px 0 14px; font-size: 14px; color: var(--muted); min-height: 1.5em; }
.delta .up { color: var(--up); font-weight: 500; }
.delta .down { color: var(--down); font-weight: 500; }

.metal dl { margin: 0; display: grid; gap: 0; border-top: 1px solid var(--rule); }
.metal dl > div { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--rule); }
.metal dt { color: var(--muted); font-size: 14px; }
.metal dd { margin: 0; text-align: right; }
.num-sm { font: 600 20px/1.1 var(--cond); }
.avail { display: block; font-size: 12px; color: var(--muted); }
.avail.out { color: var(--down); }

/* Aufgeld als Balken: Anteil Spot (voll) + Aufschlag (schraffiert) */
.premium-bar { height: 6px; margin: 14px 0 12px; border-radius: 3px; background: color-mix(in srgb, var(--cf) 70%, transparent); position: relative; overflow: hidden; }
.premium-bar i {
  position: absolute; top: 0; bottom: 0; right: 0; width: 0;
  background: repeating-linear-gradient(-45deg, var(--c) 0 3px, transparent 3px 6px);
  transition: width .6s cubic-bezier(.2,.7,.2,1);
}
.dealer-link { font-size: 13px; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--rule); }
.dealer-link:hover { color: var(--ink); text-decoration-color: currentColor; }

/* ---------- Chart ---------- */
.chart-panel, .card {
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--r-lg); padding: 18px 20px 16px;
}
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }

.seg { display: inline-flex; padding: 3px; gap: 3px; border-radius: 11px; background: color-mix(in srgb, var(--rule) 55%, transparent); }
.seg button { border: 0; background: transparent; padding: 6px 14px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / .08); }

.range { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: space-between; }
.chips { display: flex; gap: 6px; min-width: 0; max-width: 100%; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chips button, .legend button {
  flex: none; border: 1px solid var(--rule); background: transparent;
  padding: 6px 12px; border-radius: 999px; font-size: 14px; color: var(--muted);
}
.chips button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.dates { display: flex; gap: 10px; }
.dates label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.dates input {
  border: 1px solid var(--rule); background: var(--paper); border-radius: var(--r-sm);
  padding: 6px 8px; min-height: 36px; font-size: 14px; color: var(--ink);
}

.legend { display: flex; gap: 6px; flex-wrap: wrap; margin: 14px 0 6px; }
.legend button { display: inline-flex; align-items: center; gap: 8px; }
.legend button[aria-pressed="false"] { opacity: .5; text-decoration: line-through; }
.legend button[aria-pressed="true"] { color: var(--ink); }
.sw { width: 18px; height: 0; border-top: 2.5px solid var(--metal-c, var(--gold-fill)); }
.sw-coin { border-top-style: dashed; }
.sw-prem { border-top: 2px dotted var(--muted); }

.chart-box { position: relative; height: clamp(260px, 46vh, 460px); }
.chart-box .empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px; }
.empty { color: var(--muted); font-size: 14px; margin: 8px 0; }
.chart-foot { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin-top: 10px; font-size: 13px; color: var(--muted); }
.range-stats { margin: 0; }
.text-link { color: var(--muted); text-underline-offset: 3px; }

/* ---------- Alarme ---------- */
.alerts-grid { display: grid; gap: 20px; }
@media (min-width: 900px) { .alerts-grid { grid-template-columns: minmax(320px, 420px) 1fr; align-items: start; } }
.card h2 { margin-bottom: 14px; }
.form h2 { margin-bottom: 0; }
.form { display: grid; gap: 14px; }
.form label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.form input:not([type="checkbox"]), .form select {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--rule); border-radius: var(--r-sm);
  background: var(--paper); color: var(--ink); font-size: 16px; /* 16px verhindert Zoom auf iOS */
}
.input-suffix { position: relative; display: block; }
.input-suffix input { padding-right: 40px !important; }
.input-suffix b { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 500; }
.hint { color: var(--muted); font-size: 12px; min-height: 1em; }
.opt { font-size: 12px; }
.form .check { display: flex; gap: 10px; align-items: flex-start; color: var(--ink); }
.form .check input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--ink); flex: none; }
.form-error { color: var(--down); font-size: 14px; margin: 0; min-height: 0; }
.form-error:empty { display: none; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.notice { margin: 0; padding: 10px 12px; border-radius: var(--r-sm); background: color-mix(in srgb, var(--gold-fill) 18%, transparent); color: var(--ink); font-size: 14px; }

.btn {
  min-height: 44px; padding: 10px 18px; border-radius: 11px;
  border: 1px solid var(--rule); background: var(--surface); font-weight: 500;
}
.btn.primary { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.btn:disabled { opacity: .6; cursor: progress; }

.alert-list { list-style: none; margin: 0; padding: 0; }
.alert-list li {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center;
  padding: 14px 0; border-top: 1px solid var(--rule);
}
.alert-list li:first-child { border-top: 0; padding-top: 0; }
.alert-list .what { font-weight: 500; }
.alert-list .what .mk { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; vertical-align: middle; }
.alert-list .meta { grid-column: 1; font-size: 13px; color: var(--muted); }
.alert-list .meta .fired { color: var(--gold); }
.alert-list .actions { grid-row: 1 / span 2; grid-column: 2; display: flex; gap: 6px; align-items: center; }
.alert-list li.paused .what { color: var(--muted); }

.switch { position: relative; width: 44px; height: 26px; border-radius: 13px; border: 0; background: var(--rule); transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--surface); box-shadow: 0 1px 2px rgb(0 0 0 / .2); transition: transform .2s; }
.switch[aria-checked="true"] { background: var(--up); }
.switch[aria-checked="true"]::after { transform: translateX(18px); }
.del { width: 36px; height: 36px; border-radius: 50%; border: 0; background: transparent; color: var(--muted); display: grid; place-items: center; }
.del:hover { color: var(--down); background: color-mix(in srgb, var(--down) 12%, transparent); }
.del svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 14px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: min(92vw, 460px); padding: 11px 16px; border-radius: 12px;
  background: var(--ink); color: var(--surface); font-size: 14px;
  transition: opacity .2s, transform .2s; z-index: 30;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--down); color: #fff; }
@media (min-width: 720px) { .toast { bottom: 24px; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
