:root {
  --bg: #f2f5f7;
  --card: #ffffff;
  --text: #1d2a33;
  --muted: #4f5d68;
  --line: #dde4ea;
  --accent: #0e8a7e;
  --accent-soft: #e3f4f2;
  --danger: #c0392b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 17px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 { font-size: 22px; margin: 0; }
.topbar h1 span { color: var(--accent); font-weight: 500; }
.topbar-actions { display: flex; gap: 8px; }

.btn {
  border: 1px solid var(--line);
  background: var(--card);
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(0.95); }
.btn-ghost:hover { background: var(--bg); }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  gap: 20px;
  padding: 20px 24px;
  align-items: start;
}

/* ---------- Angebot ---------- */
.offer {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 28px 32px;
}

.offer-head {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 2px solid var(--accent);
  padding-bottom: 16px;
  margin-bottom: 20px;
}
.company { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.offer-meta { display: flex; flex-direction: column; gap: 4px; text-align: right; }
.offer-meta h2 { margin: 0 0 6px; color: var(--accent); font-size: 30px; letter-spacing: 1px; }
.offer-meta label {
  flex-direction: row;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
}
.offer-meta .inline-input { text-align: right; width: 140px; }

.inline-input {
  border: 1px dashed transparent;
  background: transparent;
  font: inherit;
  color: inherit;
  padding: 2px 4px;
  border-radius: 4px;
  resize: none;
}
.inline-input:hover, .inline-input:focus { border-color: var(--line); outline: none; background: #fafcfd; }
.inline-input.big { font-size: 24px; font-weight: 700; }

fieldset.customer {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 16px 16px;
  margin: 0 0 20px;
}
legend { font-weight: 600; padding: 0 6px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.span-2 { grid-column: span 2; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 6px; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 9px;
  background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.positions h3 { margin: 0 0 8px; }
.empty-hint {
  padding: 24px;
  text-align: center;
  color: var(--muted);
  border: 2px dashed var(--line);
  border-radius: 8px;
}

.pos-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.pos-table .col-pos { width: 40px; }
.pos-table .col-qty { width: 76px; }
.pos-table .col-unit { width: 76px; }
.pos-table .col-price { width: 92px; }
.pos-table .col-total { width: 108px; }
.pos-table .col-del { width: 32px; }
.pos-table th {
  text-align: left;
  white-space: nowrap;
  font-size: 14px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  padding: 6px;
}
.pos-table td { padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.pos-table .num { text-align: right; }
.pos-table .pos-name { font-weight: 600; }
.pos-table .pos-scope { color: var(--muted); font-size: 14px; margin-top: 2px; }
.pos-table input { width: 100%; text-align: right; padding: 4px 6px; -moz-appearance: textfield; }
.pos-table input::-webkit-outer-spin-button,
.pos-table input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.pos-table .line-total { font-weight: 600; white-space: nowrap; }
.pos-table .pos-name, .pos-table .pos-scope { overflow-wrap: anywhere; }
.btn-remove {
  border: none; background: none; color: var(--danger);
  cursor: pointer; font-size: 22px; line-height: 1;
}

.totals {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-top: 18px;
  align-items: flex-start;
}
.totals-options { display: flex; flex-direction: column; gap: 8px; }
.totals-options input[type=number] { width: 110px; }
.totals-table { border-collapse: collapse; min-width: 280px; margin-left: auto; }
.totals-table td { padding: 5px 8px; }
.totals-table td:last-child { text-align: right; white-space: nowrap; }
.totals-table .grand td {
  border-top: 2px solid var(--text);
  font-weight: 700;
  font-size: 19px;
  padding-top: 8px;
}

.note { color: var(--muted); font-size: 14px; }
.notes-label { margin-top: 18px; }

.signature { display: flex; gap: 40px; margin-top: 48px; }
.signature div { flex: 1; font-size: 14px; color: var(--muted); }
.signature span { display: block; border-top: 1px solid var(--text); margin-bottom: 4px; }

.offer-footer {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 18px;
  margin-top: 32px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
}
.offer-footer .inline-input { display: inline-block; min-width: 40px; }

.hidden { display: none !important; }

/* ---------- Login ---------- */
.login { display: none; }
body.locked .login {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  align-items: center;
  padding: 16px;
  background: linear-gradient(160deg, var(--accent-soft), var(--bg) 60%);
}
body.locked > :not(.login):not(script) { display: none !important; }

.login-card {
  margin: auto 0;
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 32px 28px 24px;
  box-shadow: 0 10px 30px rgba(14, 60, 70, 0.08);
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}
.login-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  font-size: 20px;
  letter-spacing: 1px;
  display: grid;
  place-items: center;
}
.login-card h1 { margin: 0; font-size: 24px; line-height: 1.25; }
.login-card h1 span { color: var(--accent); font-weight: 500; font-size: 20px; }
.login-card label { text-align: left; font-size: 14px; }
.login-card input { font-size: 18px; padding: 10px 12px; letter-spacing: 3px; }
.login-card .btn { font-size: 17px; padding: 10px; }
.login-error { color: var(--danger); font-size: 14px; margin: 0; min-height: 1.2em; }
.login-contact {
  font-style: normal;
  font-size: 14px;
  line-height: 1.6;
  color: var(--muted);
  border-top: 1px solid var(--line);
  padding-top: 14px;
  margin-top: 4px;
}
.login-contact strong { color: var(--text); }
.login-contact a { color: var(--accent); }
.login-credit {
  margin: 24px 0 0;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}
.login-credit strong { color: var(--text); letter-spacing: 0.5px; }
.login-credit a { color: inherit; }

/* ---------- Preisliste ---------- */
.services {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  position: sticky;
  top: 76px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
}
.services-head { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.services-head h2 { margin: 0; font-size: 19px; }

.cat-title {
  font-size: 16px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--accent);
  margin: 22px 0 8px;
  padding-bottom: 4px;
  border-bottom: 2px solid var(--accent-soft);
}

.service {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
}
.service:hover { border-color: var(--accent); }
.service.selected { background: var(--accent-soft); border-color: var(--accent); }
.service input[type=checkbox] { margin: 2px 0 0; accent-color: var(--accent); width: 16px; height: 16px; }
.service-name { font-weight: 600; font-size: 16px; line-height: 1.3; color: var(--text); }
.service-scope { color: var(--muted); font-size: 15px; margin-top: 4px; line-height: 1.4; }
.service-price { text-align: right; white-space: nowrap; font-weight: 700; font-size: 16px; color: var(--accent); }
.service-price small { display: block; color: var(--muted); font-weight: 400; font-size: 14px; }

.service-actions {
  grid-column: 2 / -1;
  display: flex;
  gap: 6px;
  padding-top: 8px;
  margin-top: 2px;
  border-top: 1px solid var(--line);
}
.btn-small {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 5px;
  padding: 3px 9px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
}
.btn-small:hover { border-color: var(--accent); color: var(--accent); }
.btn-small.danger:hover { border-color: var(--danger); color: var(--danger); }
.service.editing { outline: 2px solid #e0a100; }

.custom-service {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fafcfd;
}
.custom-service summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.custom-service form { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.custom-service .grid-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.custom-service input,
.custom-service select,
.custom-service textarea { width: 100%; min-width: 0; }
.form-actions { display: flex; gap: 8px; }
.form-actions .btn { flex: 1; }
.list-tools { display: flex; gap: 8px; margin-top: 12px; }
.list-tools .btn { flex: 1; font-size: 14px; padding: 8px 6px; }
.save-status { font-size: 13px; color: var(--accent); margin: 10px 0 0; min-height: 1em; }
.save-status.error { color: var(--danger); font-weight: 600; }

.link-btn {
  border: none; background: none; padding: 0;
  color: var(--muted); font: inherit; font-size: 13px;
  text-decoration: underline; cursor: pointer; margin-top: 10px;
}

/* ---------- Responsive ---------- */
@media screen and (max-width: 960px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .services { position: static; max-height: none; order: -1; }
  .offer { padding: 20px 16px; }
  .offer-head { flex-direction: column; }
  .offer-meta { text-align: left; }
  .offer-meta .inline-input { text-align: left; }
  .totals { flex-direction: column; }
  .totals-table { width: 100%; }
  .pos-table { font-size: 14px; }
}

@media screen and (max-width: 560px) {
  .grid-2 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .topbar { padding: 12px 16px; }
  .topbar h1 span { display: none; }
}

/* ---------- Druck ---------- */
@media print {
  /* Seitenrand 0 → Browser druckt keine Kopf-/Fußzeile (Titel, URL, Datum).
     Der Rand wird stattdessen als Innenabstand gesetzt und auf jeder Seite wiederholt. */
  @page { size: A4 portrait; margin: 0; }
  html, body { width: auto; margin: 0; }
  body {
    background: #fff;
    font-size: 10.5pt;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .no-print { display: none !important; }
  .layout { display: block; padding: 0; }
  .offer {
    border: none;
    border-radius: 0;
    padding: 12mm 15mm 20mm;
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
  }

  input, select, textarea, .inline-input {
    border: none !important;
    padding: 0;
    background: none !important;
    appearance: none;
    -webkit-appearance: none;
    font-size: inherit;
  }
  input::-webkit-calendar-picker-indicator { display: none; }
  ::placeholder { color: transparent !important; }
  textarea { resize: none; overflow: hidden; field-sizing: content; height: auto !important; }
  .print-empty { display: none !important; }

  /* Kopf: Firma links, Angebotsdaten rechts */
  .offer-head { flex-direction: row; gap: 10mm; padding-bottom: 4mm; margin-bottom: 5mm; }
  .inline-input.big { font-size: 15pt; }
  .offer-meta { flex: 0 0 62mm; text-align: right; }
  .offer-meta h2 { font-size: 20pt; }
  .offer-meta label { flex-direction: row; justify-content: flex-end; align-items: baseline; gap: 3mm; font-size: 9pt; }
  .offer-meta .inline-input { width: 30mm; text-align: right; color: var(--text); }

  /* Kunde kompakt */
  fieldset.customer { border: 1px solid #ccc; padding: 2mm 4mm 3mm; margin-bottom: 5mm; }
  fieldset.customer .grid-2 { grid-template-columns: 1fr 1fr; gap: 1.5mm 6mm; }
  fieldset.customer label { font-size: 8.5pt; gap: 0; }
  fieldset.customer input, fieldset.customer select { font-size: 10.5pt; }

  /* Positionen */
  .positions h3 { font-size: 12pt; margin-bottom: 2mm; }
  .pos-table th { font-size: 8.5pt; padding: 1.5mm 1mm; }
  .pos-table td { padding: 1.6mm 1mm; line-height: 1.3; }
  .pos-table td input { display: block; height: auto; margin: 0; padding: 0; line-height: 1.3; }
  .pos-table .col-pos { width: 9mm; }
  .pos-table .col-qty { width: 15mm; }
  .pos-table .col-unit { width: 16mm; }
  .pos-table .col-price { width: 20mm; }
  .pos-table .col-total { width: 24mm; }
  .pos-table .pos-scope { font-size: 9pt; }
  .pos-table input { width: 100%; }
  .pos-table tr { break-inside: avoid; page-break-inside: avoid; }
  .pos-table thead { display: table-header-group; }

  /* Summen, Notizen, Unterschrift */
  .totals { flex-direction: row; justify-content: flex-end; margin-top: 4mm; break-inside: avoid; }
  .totals-table { width: 80mm; min-width: 0; }
  .totals-table td { padding: 1mm 2mm; }
  .totals-table .grand td { font-size: 12pt; }
  .notes-label { margin-top: 5mm; font-size: 9pt; break-inside: avoid; }
  .notes-label textarea { font-size: 10pt; }
  .signature { margin-top: 10mm; break-inside: avoid; }
  .signature div { font-size: 9pt; }

  /* Fußzeile mit Firmendaten auf jeder Seite unten */
  .offer-footer {
    position: fixed;
    left: 15mm;
    right: 15mm;
    bottom: 8mm;
    margin: 0;
    padding-top: 2mm;
    border-top: 1px solid #ccc;
    font-size: 8pt;
    gap: 0 6mm;
  }
  .offer-footer .inline-input { min-width: 0; padding: 0; }
}
