/* ─── Design tokens ──────────────────────────────────────────────────────── */
:root {
  --c-bg:          #f4f6f9;
  --c-surface:     #ffffff;
  --c-surface-2:   #f8fafc;
  --c-border:      #e2e8f0;
  --c-primary:     #1e3a5f;
  --c-primary-h:   #162c48;
  --c-primary-lt:  #e8f0f8;
  --c-accent:      #2563eb;
  --c-text:        #1a202c;
  --c-text-2:      #4a5568;
  --c-text-3:      #718096;
  --c-success:     #059669;
  --c-danger:      #dc2626;
  --c-warn:        #d97706;
  --c-total-bg:    #1e3a5f;
  --c-total-text:  #ffffff;

  --r:     8px;
  --r-lg:  12px;
  --sh:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --sh-md: 0 4px 12px rgba(0,0,0,.10), 0 2px 4px rgba(0,0,0,.06);
  --f:     'Montserrat', sans-serif;
}

/* ─── Reset & base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  font-family: var(--f);
  background: var(--c-bg);
  color: var(--c-text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ─── Top bar ────────────────────────────────────────────────────────────── */
#topbar {
  background: var(--c-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 56px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--sh-md);
}

#topbar-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  white-space: nowrap;
}

#topbar-sub {
  font-size: 11px;
  font-weight: 500;
  opacity: .65;
  letter-spacing: .06em;
  text-transform: uppercase;
  margin-left: 8px;
}

/* ─── Bottom nav ─────────────────────────────────────────────────────────── */
#nav {
  background: var(--c-surface);
  border-top: 1px solid var(--c-border);
  display: flex;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  box-shadow: 0 -1px 6px rgba(0,0,0,.07);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 8px 4px calc(8px + env(safe-area-inset-bottom, 0px));
  border: none;
  background: none;
  color: var(--c-text-3);
  font-family: var(--f);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color .15s;
  -webkit-tap-highlight-color: transparent;
  min-height: 56px;
}

.nav-btn svg { width: 22px; height: 22px; }

.nav-btn.active {
  color: var(--c-primary);
}

.nav-btn.active svg { stroke: var(--c-primary); }

/* ─── Main content area ──────────────────────────────────────────────────── */
#main {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
}

/* ─── View container ─────────────────────────────────────────────────────── */
.view { display: none; }
.view.active { display: block; }

/* ─── Cards & sections ───────────────────────────────────────────────────── */
.card {
  background: var(--c-surface);
  border-radius: var(--r-lg);
  box-shadow: var(--sh);
  padding: 20px;
  margin: 12px 16px;
}

.section-heading {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--c-text-3);
  margin: 20px 16px 6px;
}

/* ─── Form controls ──────────────────────────────────────────────────────── */
.field {
  margin-bottom: 16px;
}

.field:last-child { margin-bottom: 0; }

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--c-text-2);
  margin-bottom: 6px;
}

input[type="text"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1.5px solid var(--c-border);
  border-radius: var(--r);
  font-family: var(--f);
  font-size: 15px;
  color: var(--c-text);
  background: var(--c-surface);
  appearance: none;
  -webkit-appearance: none;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}

input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; }

input:focus, select:focus {
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%234a5568' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

input[type="number"].compact {
  width: 96px;
  text-align: right;
}

/* ─── Toggle / Checkbox row ──────────────────────────────────────────────── */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--c-border);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.toggle-row:last-child { border-bottom: none; }

.toggle-row label {
  flex: 1;
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--c-text);
  cursor: pointer;
  user-select: none;
}

/* Custom checkbox */
.toggle-row input[type="checkbox"] { display: none; }

.toggle-row .chk-box {
  width: 22px;
  height: 22px;
  border: 2px solid var(--c-border);
  border-radius: 5px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, border-color .15s;
}

.toggle-row input[type="checkbox"]:checked + .chk-box {
  background: var(--c-primary);
  border-color: var(--c-primary);
}

.toggle-row input[type="checkbox"]:checked + .chk-box::after {
  content: '';
  width: 6px;
  height: 10px;
  border-right: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(45deg) translate(-1px, -1px);
}

/* ─── Segmented control ──────────────────────────────────────────────────── */
.segmented {
  display: flex;
  gap: 0;
  border: 1.5px solid var(--c-border);
  border-radius: var(--r);
  overflow: hidden;
}

.segmented button {
  flex: 1;
  height: 40px;
  border: none;
  border-right: 1.5px solid var(--c-border);
  background: var(--c-surface);
  font-family: var(--f);
  font-size: 13px;
  font-weight: 600;
  color: var(--c-text-2);
  cursor: pointer;
  transition: background .12s, color .12s;
  -webkit-tap-highlight-color: transparent;
}

.segmented button:last-child { border-right: none; }

.segmented button.active {
  background: var(--c-primary);
  color: #fff;
}

/* ─── Counter input ──────────────────────────────────────────────────────── */
.counter {
  display: flex;
  align-items: center;
  gap: 0;
  border: 1.5px solid var(--c-border);
  border-radius: var(--r);
  overflow: hidden;
  width: fit-content;
}

.counter button {
  width: 40px;
  height: 40px;
  border: none;
  background: var(--c-surface-2);
  font-size: 20px;
  line-height: 1;
  color: var(--c-text-2);
  cursor: pointer;
  font-family: var(--f);
  -webkit-tap-highlight-color: transparent;
}

.counter button:active { background: var(--c-border); }

.counter span {
  width: 44px;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  color: var(--c-text);
  border-left: 1.5px solid var(--c-border);
  border-right: 1.5px solid var(--c-border);
  line-height: 40px;
}

/* ─── Sub-fields (shown conditionally) ──────────────────────────────────── */
.sub-field {
  margin-top: 10px;
  padding: 12px 14px;
  background: var(--c-surface-2);
  border-radius: var(--r);
  border: 1px solid var(--c-border);
}

.sub-field label { font-size: 12px; color: var(--c-text-3); }

.sub-field .field { margin-bottom: 10px; }
.sub-field .field:last-child { margin-bottom: 0; }

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 20px;
  border-radius: var(--r);
  font-family: var(--f);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .03em;
  cursor: pointer;
  border: none;
  transition: background .15s, opacity .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(.97); }

.btn-primary {
  background: var(--c-primary);
  color: #fff;
}
.btn-primary:hover { background: var(--c-primary-h); }

.btn-outline {
  background: transparent;
  color: var(--c-primary);
  border: 1.5px solid var(--c-primary);
}
.btn-outline:hover { background: var(--c-primary-lt); }

.btn-ghost {
  background: transparent;
  color: var(--c-text-2);
  border: 1.5px solid var(--c-border);
}

.btn-danger {
  background: #fff5f5;
  color: var(--c-danger);
  border: 1.5px solid #fecaca;
}

.btn-sm {
  height: 34px;
  padding: 0 14px;
  font-size: 12px;
}

.btn-block { width: 100%; }

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 8px;
}

/* ─── Angebote list ──────────────────────────────────────────────────────── */
#view-angebote .page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 0;
}

#view-angebote .page-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--c-text);
}

.quote-list { padding: 8px 0; }

.quote-item {
  display: flex;
  align-items: center;
  background: var(--c-surface);
  border-radius: var(--r-lg);
  box-shadow: var(--sh);
  margin: 8px 16px;
  padding: 16px;
  gap: 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: box-shadow .15s;
}

.quote-item:active { box-shadow: var(--sh-md); }

.quote-item-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--c-primary-lt);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.quote-item-icon svg { width: 22px; height: 22px; stroke: var(--c-primary); }

.quote-item-body { flex: 1; min-width: 0; }

.quote-item-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--c-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.quote-item-meta {
  font-size: 12px;
  color: var(--c-text-3);
  margin-top: 2px;
}

.quote-item-amount {
  font-size: 16px;
  font-weight: 700;
  color: var(--c-primary);
  white-space: nowrap;
  flex-shrink: 0;
}

.quote-item-del {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  color: var(--c-text-3);
  border-radius: 6px;
  -webkit-tap-highlight-color: transparent;
}

.quote-item-del:active { background: #fff5f5; color: var(--c-danger); }

.empty-state {
  text-align: center;
  padding: 64px 24px;
  color: var(--c-text-3);
}

.empty-state svg { width: 56px; height: 56px; stroke: var(--c-border); margin-bottom: 16px; }

.empty-state h3 { font-size: 17px; font-weight: 700; color: var(--c-text-2); margin-bottom: 6px; }

.empty-state p { font-size: 14px; line-height: 1.6; }

/* ─── Kalkulation layout ─────────────────────────────────────────────────── */
#view-kalkulation .kalk-header {
  display: flex;
  gap: 12px;
  padding: 12px 16px 0;
  align-items: flex-end;
  flex-wrap: wrap;
}

#view-kalkulation .kalk-header .field { flex: 1; min-width: 180px; margin-bottom: 0; }

.ust-toggle {
  display: flex;
  gap: 0;
  border: 1.5px solid var(--c-border);
  border-radius: var(--r);
  overflow: hidden;
  height: 44px;
  flex-shrink: 0;
}

.ust-toggle button {
  flex: 1;
  padding: 0 16px;
  border: none;
  border-right: 1.5px solid var(--c-border);
  background: var(--c-surface);
  font-family: var(--f);
  font-size: 13px;
  font-weight: 600;
  color: var(--c-text-2);
  cursor: pointer;
  white-space: nowrap;
}
.ust-toggle button:last-child { border-right: none; }
.ust-toggle button.active { background: var(--c-primary); color: #fff; }

/* iPad+ two-column layout */
@media (min-width: 768px) {
  .kalk-body {
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 0;
    align-items: start;
  }

  .kalk-left {
    border-right: 1px solid var(--c-border);
    overflow-y: auto;
    max-height: calc(100dvh - 56px - 64px - 60px);
    position: sticky;
    top: 56px;
  }

  .kalk-right {
    overflow-y: auto;
  }
}

@media (max-width: 767px) {
  .kalk-body { display: block; }
}

/* ─── Calculation table ──────────────────────────────────────────────────── */
.calc-table-wrap {
  margin: 0 16px 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.calc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 460px;
}

.calc-table thead th {
  padding: 10px 8px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--c-text-3);
  border-bottom: 2px solid var(--c-border);
  white-space: nowrap;
}

.calc-table tbody tr { border-bottom: 1px solid var(--c-border); }

.calc-table tbody tr:last-child { border-bottom: none; }

.calc-table tbody tr:hover { background: var(--c-surface-2); }

.calc-table td {
  padding: 10px 8px;
  vertical-align: middle;
}

.calc-table .td-pos {
  font-size: 11px;
  font-weight: 700;
  color: var(--c-text-3);
  width: 28px;
}

.calc-table .td-name {
  font-weight: 600;
  color: var(--c-text);
}

.calc-table .td-amt {
  text-align: right;
  font-weight: 600;
  color: var(--c-text-2);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.calc-table .td-corr {
  width: 110px;
}

.calc-table .td-corr input {
  width: 100px;
  height: 36px;
  padding: 0 8px;
  text-align: right;
  font-size: 13px;
  border: 1.5px solid var(--c-border);
  border-radius: 6px;
  font-family: var(--f);
  font-variant-numeric: tabular-nums;
}

.calc-table .td-corr input:focus {
  border-color: var(--c-accent);
  box-shadow: 0 0 0 2px rgba(37,99,235,.1);
  outline: none;
}

.calc-table .td-end {
  text-align: right;
  font-weight: 700;
  color: var(--c-text);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ─── Summary block ──────────────────────────────────────────────────────── */
.summary-block {
  background: var(--c-primary);
  color: #fff;
  border-radius: var(--r-lg);
  margin: 4px 16px 16px;
  padding: 20px;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 5px 0;
}

.summary-row .s-label {
  font-size: 13px;
  font-weight: 500;
  opacity: .8;
}

.summary-row .s-value {
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.summary-row.total {
  border-top: 1px solid rgba(255,255,255,.2);
  margin-top: 8px;
  padding-top: 12px;
}

.summary-row.total .s-label {
  font-size: 14px;
  font-weight: 700;
  opacity: 1;
}

.summary-row.total .s-value {
  font-size: 20px;
}

.global-adjust-row {
  margin: 0 16px 12px;
}

.global-adjust-row label {
  font-size: 12px;
  color: var(--c-text-3);
  font-weight: 600;
  margin-bottom: 4px;
}

.global-adjust-row input {
  width: 140px;
  height: 40px;
  padding: 0 12px;
  text-align: right;
  font-size: 14px;
  border: 1.5px solid var(--c-border);
  border-radius: var(--r);
  font-family: var(--f);
  font-variant-numeric: tabular-nums;
}

.save-bar {
  display: flex;
  gap: 10px;
  padding: 0 16px 16px;
}

/* ─── Preise view ────────────────────────────────────────────────────────── */
#view-preise .preise-group {
  margin-bottom: 4px;
}

#view-preise .preise-group-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--c-text-3);
  padding: 16px 16px 6px;
}

.rate-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
}

.rate-row:first-of-type { border-top-left-radius: var(--r-lg); border-top-right-radius: var(--r-lg); }
.rate-row:last-of-type  { border-bottom-left-radius: var(--r-lg); border-bottom-right-radius: var(--r-lg); border-bottom: none; }

.preise-group .card { padding: 0; overflow: hidden; }

.rate-label { flex: 1; font-size: 14px; font-weight: 500; color: var(--c-text); }

.rate-unit { font-size: 12px; color: var(--c-text-3); font-weight: 600; white-space: nowrap; }

.rate-input {
  width: 90px !important;
  height: 40px !important;
  text-align: right;
  font-size: 14px !important;
  font-weight: 700;
}

.preise-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px;
}

/* ─── Toast notification ─────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: calc(72px + env(safe-area-inset-bottom, 0px) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1a202c;
  color: #fff;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  z-index: 200;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  white-space: nowrap;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ─── Modal ──────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 150;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

@media (min-width: 560px) {
  .modal-backdrop { align-items: center; }
}

.modal {
  background: var(--c-surface);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom, 0px));
  width: 100%;
  max-width: 480px;
  box-shadow: var(--sh-md);
}

@media (min-width: 560px) {
  .modal { border-radius: var(--r-lg); padding-bottom: 24px; }
}

.modal h3 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 16px;
}

.modal .modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

/* ─── Misc helpers ───────────────────────────────────────────────────────── */
.hidden { display: none !important; }

.inline-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.inline-row label { flex: 1; margin: 0; }

.text-muted { color: var(--c-text-3); font-size: 12px; }

.mt-8  { margin-top: 8px; }
.mt-12 { margin-top: 12px; }

.calc-section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--c-text-3);
  padding: 12px 16px 6px;
}
