/* ===== MwSt-Rechner CH — eigenes Design: Schweizer Rot, behoerdlich-klar ===== */

:root {
  --ch-red: #da291c;
  --ch-red-dark: #b21f15;
  --ch-red-soft: #fbe9e7;

  --bg: #f3f4f6;
  --bg-grad-1: #ffffff;
  --bg-grad-2: #eef0f3;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --border: #d9dde3;
  --border-strong: #c2c8d0;

  --text: #1a1d21;
  --text-muted: #5b6470;
  --text-faint: #8a929c;

  --on-red: #ffffff;

  --shadow-sm: 0 1px 2px rgba(20, 24, 30, 0.06);
  --shadow-md: 0 4px 16px rgba(20, 24, 30, 0.08);

  --radius: 14px;
  --radius-sm: 10px;

  --tap: 48px;

  --focus: 0 0 0 3px rgba(218, 41, 28, 0.35);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

[data-theme="dark"] {
  --ch-red: #ff5a47;
  --ch-red-dark: #ff7a6a;
  --ch-red-soft: #3a1a17;

  --bg: #14171c;
  --bg-grad-1: #1b1f26;
  --bg-grad-2: #101216;
  --surface: #1d2128;
  --surface-2: #23282f;
  --border: #333a44;
  --border-strong: #424b57;

  --text: #f1f3f5;
  --text-muted: #aab2bd;
  --text-faint: #7b838f;

  --on-red: #1a1208;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.45);

  --focus: 0 0 0 3px rgba(255, 90, 71, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 500px at 50% -10%, var(--bg-grad-1), transparent 60%),
    linear-gradient(180deg, var(--bg-grad-2), var(--bg));
  background-attachment: fixed;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--ch-red);
  color: var(--on-red);
  padding: 10px 14px;
  border-radius: 0 0 var(--radius-sm) 0;
  z-index: 100;
}
.skip-link:focus { left: 0; }

/* ===== Header ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { display: inline-flex; flex: none; box-shadow: var(--shadow-sm); border-radius: 8px; }
.brand-mark svg { display: block; }
.brand-text { min-width: 0; }
.brand h1 {
  font-size: 1.15rem;
  margin: 0;
  line-height: 1.1;
  letter-spacing: -0.01em;
}
.brand-sub {
  margin: 2px 0 0;
  font-size: 0.74rem;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.icon-btn {
  flex: none;
  width: var(--tap);
  height: var(--tap);
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  transition: background .15s ease, border-color .15s ease, transform .1s ease;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { transform: scale(0.94); }
.theme-icon {
  width: 22px; height: 22px;
  display: block;
  background: currentColor;
  -webkit-mask: var(--moon) center / contain no-repeat;
  mask: var(--moon) center / contain no-repeat;
  --moon: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="black" d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8Z"/></svg>');
  --sun: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g fill="black"><circle cx="12" cy="12" r="5"/><path d="M12 1v3M12 20v3M4.2 4.2l2.1 2.1M17.7 17.7l2.1 2.1M1 12h3M20 12h3M4.2 19.8l2.1-2.1M17.7 6.3l2.1-2.1"/></g></svg>');
}
[data-theme="dark"] .theme-icon {
  -webkit-mask-image: var(--sun);
  mask-image: var(--sun);
}

/* ===== Main ===== */
.app-main {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ===== Card ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}
.card-title {
  margin: 0 0 12px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

/* ===== Segmented (Richtung) ===== */
.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.seg-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 12px 14px;
  min-height: var(--tap);
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  color: var(--text);
  transition: border-color .15s, background .15s, color .15s;
}
.seg-btn .seg-main { font-weight: 700; font-size: 0.98rem; }
.seg-btn .seg-sub { font-size: 0.76rem; color: var(--text-muted); }
.seg-btn:hover { border-color: var(--border-strong); }
.seg-btn.is-active {
  border-color: var(--ch-red);
  background: var(--ch-red);
  color: var(--on-red);
}
.seg-btn.is-active .seg-sub { color: color-mix(in srgb, var(--on-red) 80%, transparent); }

/* ===== Field / Input ===== */
.field { margin: 0; }
.field + .field { margin-top: 12px; }
.field-label {
  display: block;
  font-size: 0.86rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}
.field-hint {
  margin: 6px 0 0;
  font-size: 0.76rem;
  color: var(--text-faint);
}

.amount-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  transition: border-color .15s, box-shadow .15s;
}
.amount-wrap:focus-within {
  border-color: var(--ch-red);
  box-shadow: var(--focus);
}
.cur {
  font-weight: 700;
  color: var(--text-muted);
  font-size: 0.95rem;
  flex: none;
}
.amount-input {
  flex: 1 1 auto;
  width: 100%;
  border: none;
  background: transparent;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  padding: 14px 0;
  min-width: 0;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}
.amount-input:focus { outline: none; }
.amount-input::placeholder { color: var(--text-faint); font-weight: 600; }

/* ===== Rate Grid ===== */
.rate-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.rate-btn {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: flex-start;
  padding: 12px 14px;
  min-height: var(--tap);
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  color: var(--text);
  transition: border-color .15s, background .15s, color .15s;
}
.rate-val { font-weight: 800; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.rate-name { font-size: 0.76rem; color: var(--text-muted); }
.rate-btn:hover { border-color: var(--border-strong); }
.rate-btn.is-active {
  border-color: var(--ch-red);
  background: var(--ch-red-soft);
  color: var(--text);
}
.rate-btn.is-active .rate-val { color: var(--ch-red); }
.rate-btn.is-active .rate-name { color: var(--ch-red-dark); }

.custom-field { margin-top: 12px; }

/* ===== Result ===== */
.result-card {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}
.result-list { margin: 0; }
.result-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.result-row dt {
  font-size: 0.92rem;
  color: var(--text-muted);
  font-weight: 600;
  margin: 0;
}
.result-row dd {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  text-align: right;
}
.result-vat .vat-rate {
  display: inline-block;
  margin-left: 6px;
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--ch-red);
  background: var(--ch-red-soft);
  padding: 1px 7px;
  border-radius: 999px;
  vertical-align: middle;
}
.result-total {
  border-bottom: none;
  margin-top: 4px;
  padding-top: 16px;
  border-top: 2px solid var(--ch-red);
}
.result-total dt { color: var(--text); font-weight: 800; font-size: 1rem; }
.result-total dd { font-size: 1.5rem; font-weight: 800; color: var(--ch-red); }

.result-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.btn {
  flex: 1 1 0;
  min-height: var(--tap);
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0 12px;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { background: var(--surface); border-color: var(--ch-red); }
.btn:active { transform: scale(0.98); }
.btn-ghost { background: transparent; }

.disclaimer {
  margin: 4px 2px 0;
  font-size: 0.75rem;
  color: var(--text-faint);
  text-align: center;
  line-height: 1.5;
}

/* ===== Focus visibility ===== */
:focus-visible {
  outline: none;
  box-shadow: var(--focus);
  border-radius: var(--radius-sm);
}
.seg-btn:focus-visible,
.rate-btn:focus-visible,
.btn:focus-visible,
.icon-btn:focus-visible {
  box-shadow: var(--focus);
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translate(-50%, 16px);
  background: var(--text);
  color: var(--surface);
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 200;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.is-show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ===== Desktop ===== */
@media (min-width: 600px) {
  .app-main { padding-top: 24px; }
  .amount-input { font-size: 1.7rem; }
}

/* ===== Reduced motion ===== */
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
}
