/* Druckkostenrechner – Gestaltung
   Primärfarbe #811d6e · Flächen #f3f3f3 / #f9f9f9 · Text #000000 */

:root {
  --prim: #811d6e;
  --prim-dark: #651656;
  --prim-soft: #f4e8f1;
  --bg: #f3f3f3;
  --card: #f9f9f9;
  --ink: #000000;
  --ink-2: #555555;
  --line: #dedede;
  --error: #c0262d;
  --ok: #2e7d32;
  --radius: 6px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--font);
}
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
small { color: var(--ink-2); font-weight: 400; }

/* ---------- Kopfleiste ---------- */
.topbar { background: var(--prim); color: #fff; margin-bottom: 24px; }
.topbar__in { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 60px; }
.topbar__brand { display: block; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; opacity: .8; }
.topbar__title { display: block; font-size: 19px; font-weight: 600; }
.topbar__link { color: #fff; text-decoration: none; font-size: 14px; padding: 7px 14px; border: 1px solid rgba(255,255,255,.45); border-radius: var(--radius); white-space: nowrap; }
.topbar__link:hover { background: rgba(255,255,255,.12); }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; padding-bottom: 48px; }
.layout__side { position: sticky; top: 16px; }
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .layout__side { position: static; }
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

/* ---------- Formularfelder ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field__label { font-size: 13px; font-weight: 600; }
.field__label b, .motive__head b { color: var(--prim); }
input[type=text], input[type=number], input[type=password], select {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid #c9c9c9;
  border-radius: var(--radius);
  padding: 9px 11px;
  min-height: 40px;
  transition: border-color .15s, box-shadow .15s;
}
select { padding-right: 30px; }
input:focus, select:focus { outline: none; border-color: var(--prim); box-shadow: 0 0 0 3px rgba(129, 29, 110, .18); }
.is-invalid { border-color: var(--error) !important; background: #fff6f6; }
option:disabled { color: #aaa; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid transparent; border-radius: var(--radius);
  padding: 10px 18px; min-height: 42px; text-decoration: none;
  transition: background .15s, color .15s, border-color .15s;
}
.btn--primary { background: var(--prim); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--prim-dark); }
.btn--primary:disabled { background: #b9a2b4; cursor: not-allowed; }
.btn--light { background: var(--bg); color: var(--ink); border-color: var(--line); }
.btn--light:hover { background: #ebebeb; }
.btn--ghost { background: transparent; color: var(--prim); border: 1px dashed var(--prim); }
.btn--ghost:hover { background: var(--prim-soft); }
.btn--dark { background: #000; color: #fff; }
.btn--dark:hover { background: #222; }
.btn--block { width: 100%; margin-top: 10px; }
.btn--add { width: 100%; padding: 14px; }
.btn--add span { font-size: 20px; line-height: 1; }

/* ---------- Position ---------- */
.pos { padding: 0; overflow: hidden; animation: popIn .2s ease-out; }
.pos--leaving { opacity: 0; transform: scale(.98); transition: opacity .18s, transform .18s; }
@keyframes popIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.pos__head { display: flex; align-items: center; justify-content: space-between; background: var(--prim); color: #fff; padding: 10px 20px; }
.pos__head h2 { margin: 0; font-size: 17px; }
.pos__remove { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.5); border-radius: 50%; width: 30px; height: 30px; font-size: 18px; line-height: 1; cursor: pointer; }
.pos__remove:hover { background: rgba(255,255,255,.15); }
.pos__grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; padding: 18px 20px 6px; }
.field--textil { grid-column: span 4; }
.field--menge, .field--third { grid-column: span 2; }
@media (max-width: 640px) {
  .pos__grid { grid-template-columns: 1fr 1fr; }
  .field--textil { grid-column: 1 / -1; }
  .field--menge, .field--third { grid-column: span 1; }
}

/* Motive */
.motive { padding: 10px 20px 4px; }
.motive__head, .motiv { display: grid; grid-template-columns: 28px minmax(220px, 1.1fr) minmax(0, 1fr); gap: 12px; align-items: center; }
.motive__head { font-size: 13px; font-weight: 600; padding-bottom: 6px; }
.motiv { padding: 8px 0; border-top: 1px solid var(--line); }
.motiv--new { animation: slideIn .2s ease-out; }
@keyframes slideIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.motiv__nr { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--prim-soft); color: var(--prim); font-size: 13px; font-weight: 700; }
.motiv__size { display: flex; align-items: center; gap: 8px; }
.motiv__size input { text-align: right; }
.motiv__x, .motiv__unit { color: var(--ink-2); }
.motiv__pos { display: flex; gap: 8px; }
.motiv__pos > * { flex: 1 1 0; min-width: 0; }
@media (max-width: 640px) {
  .motive__head { display: none; }
  .motiv { grid-template-columns: 28px minmax(0, 1fr); }
  .motiv__pos { grid-column: 2; flex-wrap: wrap; }
  .motiv__pos > * { flex-basis: 100%; }
}

/* Berechnung je Position */
.calc { margin: 10px 0 0; padding: 14px 20px 16px; background: var(--bg); border-top: 1px solid var(--line); }
.calc div { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; }
.calc dt { color: var(--ink-2); }
.calc dd { margin: 0; font-variant-numeric: tabular-nums; white-space: nowrap; }
.calc__einzel { font-weight: 600; }
.calc__einzel dt { color: var(--ink); }
.calc__sep { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 8px !important; }
.calc__total dt, .calc__total dd { color: var(--prim); font-weight: 700; }
.pos--done .pos__head { background: var(--prim); }

/* ---------- Gesamtübersicht ---------- */
.summary { border-top: 5px solid var(--prim); }
.summary__title { margin: 0 0 12px; font-size: 17px; }
.summary__rows { font-size: 14px; }
.summary__row { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px dotted var(--line); font-variant-numeric: tabular-nums; }
.summary__row--open span:last-child { color: var(--ink-2); font-style: italic; }
.totals { margin: 12px 0 0; }
.totals div { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; }
.totals dd { margin: 0; font-variant-numeric: tabular-nums; white-space: nowrap; }
.totals__end { border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 10px !important; font-size: 18px; font-weight: 700; }
.totals__end dd { color: var(--prim); }
.hint { margin: 12px 0 0; font-size: 13px; color: var(--ink-2); background: #fff; border-left: 3px solid var(--prim); padding: 8px 10px; }

/* ---------- Hinweise ---------- */
.notice { padding: 12px 16px; border-radius: var(--radius); margin: 0 0 16px; background: #fff; border-left: 4px solid var(--prim); }
.notice--error { border-left-color: var(--error); color: var(--error); }
.notice--ok { border-left-color: var(--ok); }
.totals__end dt small { display: block; font-size: 12px; }

/* ---------- Neue Position / Duplizieren ---------- */
.addbar { display: flex; gap: 12px; align-items: stretch; }
.addbar .btn--add { flex: 1 1 0; width: auto; }
.addbar__dup { flex: 1 1 0; display: flex; min-width: 0; }
.addbar__dup select { min-height: 100%; border: 1px dashed var(--prim); color: var(--prim); font-weight: 600; cursor: pointer; }

/* ---------- Hinweis identische Ausführung ---------- */
.pos__dup { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 10px 20px 0; padding: 10px 14px; background: #fff8e5; border: 1px solid #e6c46b; border-left: 4px solid #d19a00; border-radius: var(--radius); font-weight: 600; }
.pos__dup .btn { min-height: 36px; padding: 6px 14px; }

/* ---------- Fußzeile ---------- */
.footer { text-align: center; font-size: 5px; line-height: 1.4; color: var(--ink-2); padding: 0 16px 12px; }

/* ---------- Responsive (kleine Bildschirme) ---------- */
img, svg { max-width: 100%; }
.topbar__in { flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }

@media (max-width: 640px) {
  body { font-size: 15px; }
  /* 16px verhindert das automatische Hineinzoomen auf iOS */
  input[type=text], input[type=number], input[type=password], select { font-size: 16px; }
  .wrap { padding: 0 10px; }
  .topbar { margin-bottom: 14px; }
  .topbar__title { font-size: 17px; }
  .card { padding: 14px; }
  .pos { padding: 0; }
  .pos__head { padding: 10px 14px; }
  .pos__grid { gap: 12px; padding: 14px 14px 4px; }
  .motive { padding: 8px 14px 4px; }
  .calc { padding: 12px 14px 14px; }
  .pos__dup { margin: 10px 14px 0; }
  .layout { gap: 14px; padding-bottom: 24px; }
  .addbar { flex-direction: column; }
  .addbar__dup select { min-height: 46px; }
  .motiv__size input { min-width: 0; }
  .totals__end { font-size: 17px; }
}

@media (max-width: 400px) {
  .pos__grid { grid-template-columns: minmax(0, 1fr); }
  .field--menge, .field--third { grid-column: 1 / -1; }
  .motiv { grid-template-columns: minmax(0, 1fr); }
  .motiv__nr { justify-self: start; }
  .motiv__pos { grid-column: 1; }
  .calc div, .totals div { flex-wrap: wrap; }
  .calc dd, .totals dd { margin-left: auto; }
}

/* ---------- 0.1.2: Berechnung rechts über der Gesamtübersicht ---------- */
.sidecalc { padding: 0; overflow: hidden; }
.sidecalc__head { margin: 0; padding: 9px 16px; font-size: 15px; background: var(--prim); color: #fff; }
.sidecalc .calc { margin: 0; padding: 12px 16px 14px; border-top: 0; font-size: 14px; }
.sidecalc .calc small { font-size: 12px; }
@media (min-width: 901px) {
  .layout__side { max-height: calc(100vh - 32px); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
}
.disclaimer { margin: 12px 0 0; font-size: 11px; line-height: 1.4; color: var(--ink-2); }
.btn--dark:disabled { background: #888; cursor: not-allowed; }
button.topbar__link { background: transparent; font: inherit; font-size: 14px; cursor: pointer; }

/* ---------- Fenster „Kalkulation ansehen“ ---------- */
.view__main { max-width: 820px; padding-bottom: 24px; }
.view__h { margin: 0 0 8px; font-size: 18px; color: var(--prim); }
.view__label { display: block; font-size: 12px; color: var(--ink-2); }
.view__meta { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.view__date { text-align: right; }
.view__pos .pos__head span { font-size: 14px; }
.view__grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; padding: 14px 20px 6px; }
.view__motive { width: calc(100% - 40px); margin: 6px 20px 12px; border-collapse: collapse; font-size: 14px; }
.view__motive th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-2); border-bottom: 1px solid var(--line); padding: 4px 8px 4px 0; }
.view__motive td { padding: 5px 8px 5px 0; border-bottom: 1px solid var(--line); }
.view__pos .calc { margin-top: 0; }
.view__actions { text-align: center; margin: 8px 0 16px; }
@media (max-width: 640px) {
  .view__grid { grid-template-columns: 1fr 1fr; padding: 12px 14px 4px; }
  .view__grid > :first-child { grid-column: 1 / -1; }
  .view__motive { width: calc(100% - 28px); margin: 6px 14px 10px; }
  .view__date { text-align: left; }
}
@media print {
  .topbar__btn, .view__actions { display: none; }
  body { background: #fff; }
}
.view__pos { animation: none; }

/* ---------- 0.1.6: Vorschaufenster „Kalkulation ansehen“ ---------- */
.preview { width: min(880px, 94vw); height: min(86vh, 900px); padding: 0; border: 0; border-radius: 10px; overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,.35); background: var(--bg); }
.preview[open] { display: flex; flex-direction: column; }
.preview::backdrop { background: rgba(20, 10, 20, .55); }
.preview__bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px 10px 18px; background: var(--prim); color: #fff; flex: 0 0 auto; }
.preview__x { width: 32px; height: 32px; border-radius: 50%; border: 1px solid rgba(255,255,255,.5); background: transparent; color: #fff; font-size: 20px; line-height: 1; cursor: pointer; }
.preview__x:hover { background: rgba(255,255,255,.15); }
.preview__frame { flex: 1 1 auto; width: 100%; border: 0; background: var(--bg); }
@media (max-width: 640px) {
  .preview { width: 100vw; height: 100dvh; max-width: 100vw; max-height: 100dvh; border-radius: 0; }
}
.view--embed .view__main { padding-top: 14px; }

/* Motivgröße: Beschriftung Breite / Höhe */
.motiv__fld { display: flex; flex-direction: column; gap: 2px; flex: 1 1 0; min-width: 0; }
.motiv__cap { font-size: 11px; color: var(--ink-2); line-height: 1.2; }
.motiv__size { align-items: flex-end; }
.motiv__x, .motiv__unit { padding-bottom: 10px; }
.motive__head small { font-weight: 400; }
