/* Einheiten-Profi CH — eigenes Design: Stahlblau + Weiss, Mess-Anmutung */
:root {
  --steel:      #0284c7;
  --steel-600:  #0369a1;
  --steel-700:  #075985;
  --steel-400:  #38bdf8;
  --accent:     #0ea5e9;

  --bg:         #f1f5f9;
  --bg-grid:    rgba(2, 132, 199, 0.06);
  --surface:    #ffffff;
  --surface-2:  #f8fafc;
  --line:       #cbd5e1;
  --line-soft:  #e2e8f0;
  --text:       #0f172a;
  --text-soft:  #475569;
  --text-faint: #64748b;
  --field-bg:   #ffffff;
  --shadow:     0 6px 24px rgba(15, 23, 42, 0.08);
  --shadow-sm:  0 2px 8px rgba(15, 23, 42, 0.06);
  --ok:         #059669;

  --radius:     16px;
  --radius-sm:  10px;
  --focus:      0 0 0 3px rgba(2, 132, 199, 0.35);
  --maxw:       640px;
}

[data-theme="dark"] {
  --steel:      #38bdf8;
  --steel-600:  #0ea5e9;
  --steel-700:  #7dd3fc;
  --accent:     #38bdf8;

  --bg:         #0b1220;
  --bg-grid:    rgba(56, 189, 248, 0.07);
  --surface:    #121d2e;
  --surface-2:  #0f1a29;
  --line:       #2b3a52;
  --line-soft:  #243246;
  --text:       #e8eef6;
  --text-soft:  #aebdd0;
  --text-faint: #8497ad;
  --field-bg:   #0f1a29;
  --shadow:     0 6px 24px rgba(0, 0, 0, 0.4);
  --shadow-sm:  0 2px 8px rgba(0, 0, 0, 0.3);
  --ok:         #34d399;
  --focus:      0 0 0 3px rgba(56, 189, 248, 0.4);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--bg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px);
  background-size: 26px 26px;
  line-height: 1.5;
  min-height: 100vh;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  -webkit-font-smoothing: antialiased;
}

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

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 16px 16px 8px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px; height: 46px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--steel-700));
  color: #fff;
  flex: none;
  box-shadow: var(--shadow-sm);
}
[data-theme="dark"] .brand-mark { color: #07111f; }
.brand-text { min-width: 0; }
.brand-text h1 {
  margin: 0;
  font-size: 1.18rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.brand-ch {
  color: var(--steel);
  font-weight: 900;
}
.brand-sub {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-faint);
}

.icon-btn {
  flex: none;
  width: 44px; height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-size: 1.3rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease, transform .1s ease, border-color .15s ease;
}
.icon-btn:hover { border-color: var(--steel); }
.icon-btn:active { transform: scale(0.95); }
.icon-btn:focus-visible { outline: none; box-shadow: var(--focus); }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: var(--maxw);
  margin: 4px auto 0;
  padding: 8px 16px 4px;
}
.tab {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-soft);
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background .15s ease, color .15s ease, border-color .15s ease, transform .1s ease;
}
.tab .tab-ico { font-size: 1rem; line-height: 1; }
.tab:hover { border-color: var(--steel-400); }
.tab:active { transform: scale(0.97); }
.tab:focus-visible { outline: none; box-shadow: var(--focus); }
.tab[aria-selected="true"] {
  background: linear-gradient(135deg, var(--steel), var(--steel-600));
  border-color: transparent;
  color: #fff;
  box-shadow: var(--shadow-sm);
}
[data-theme="dark"] .tab[aria-selected="true"] { color: #07111f; }

/* ---------- Content ---------- */
.content {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 8px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.card-head { margin-bottom: 14px; }
.cat-title {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.cat-hint {
  margin: 4px 0 0;
  font-size: 0.84rem;
  color: var(--text-faint);
}

/* ---------- Fields ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
input[type="text"], select {
  width: 100%;
  font-size: 1.05rem;
  color: var(--text);
  background: var(--field-bg);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-family: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}
#inputValue {
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
select {
  appearance: none;
  -webkit-appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-soft) 50%),
    linear-gradient(135deg, var(--text-soft) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 50%,
    calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 36px;
  cursor: pointer;
}
input:focus-visible, select:focus-visible {
  outline: none;
  border-color: var(--steel);
  box-shadow: var(--focus);
}
input.is-invalid { border-color: #dc2626; }
.help {
  margin: 2px 0 0;
  font-size: 0.76rem;
  color: var(--text-faint);
}

.convert-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 10px;
  margin-top: 14px;
}
.unit-field { min-width: 0; }

.swap-btn {
  flex: none;
  width: 46px; height: 46px;
  margin-bottom: 1px;
  border-radius: 50%;
  border: 1.5px solid var(--steel);
  background: var(--surface);
  color: var(--steel);
  font-size: 1.35rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform .2s ease, background .15s ease, color .15s ease;
}
.swap-btn:hover { background: var(--steel); color: #fff; }
[data-theme="dark"] .swap-btn:hover { color: #07111f; }
.swap-btn:active { transform: rotate(180deg) scale(0.92); }
.swap-btn:focus-visible { outline: none; box-shadow: var(--focus); }

/* ---------- Result ---------- */
.result {
  margin-top: 18px;
  padding: 16px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px dashed var(--line);
}
.result-line { min-height: 1.2em; }
.result-echo {
  font-size: 0.88rem;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}
.result-value {
  display: block;
  margin-top: 4px;
  font-size: 2rem;
  font-weight: 800;
  color: var(--steel);
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  word-break: break-word;
  overflow-wrap: anywhere;
}
[data-theme="dark"] .result-value { color: var(--steel-700); }
.result-actions { margin-top: 12px; }

.ghost-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-soft);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.ghost-btn:hover { border-color: var(--steel); color: var(--steel); }
.ghost-btn:focus-visible { outline: none; box-shadow: var(--focus); }

/* ---------- Table ---------- */
.table-card { padding-bottom: 8px; }
.sub-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
}
.sub-hint {
  margin: 4px 0 12px;
  font-size: 0.82rem;
  color: var(--text-faint);
}
.table-wrap { overflow: hidden; }
.quick-table {
  list-style: none;
  margin: 0;
  padding: 0;
}
.quick-table li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--line-soft);
}
.quick-table li:last-child { border-bottom: none; }
.qt-unit {
  font-weight: 600;
  color: var(--text-soft);
  flex: 1 1 auto;
  min-width: 0;
  word-break: break-word;
}
.qt-val {
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  text-align: right;
  flex: 0 0 auto;
  word-break: break-word;
}
.qt-val.is-base { color: var(--steel); }

/* ---------- Footer ---------- */
.app-foot {
  text-align: center;
  padding: 4px 8px 0;
}
.app-foot p {
  margin: 0;
  font-size: 0.76rem;
  color: var(--text-faint);
}

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

/* ---------- Responsive ---------- */
@media (max-width: 400px) {
  .convert-row {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .swap-btn {
    justify-self: center;
    transform: rotate(90deg);
    margin: 0;
  }
  .swap-btn:active { transform: rotate(270deg) scale(0.92); }
  .brand-text h1 { font-size: 1.05rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
  .swap-btn:active { transform: scale(0.95); }
}
