:root {
  --accent: #E2001A;
  --accent-dark: #b30015;
  --bg: #f4f4f6;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #6b6b70;
  --border: #e4e4e8;
  --success: #1a8a3c;
  --warning: #c77800;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior-y: contain;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + var(--safe-top)) 18px 14px 18px;
  background: var(--accent);
  color: #fff;
}
.topbar-title { font-size: 19px; font-weight: 700; letter-spacing: 0.3px; }
.icon-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
}

/* View area */
.view {
  padding: 14px 14px calc(90px + var(--safe-bottom)) 14px;
  max-width: 720px;
  margin: 0 auto;
  min-height: calc(100vh - 60px);
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  z-index: 20;
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0 6px 0;
  font-size: 11px;
  color: var(--muted);
}
.nav-item:visited { color: var(--muted); }
.nav-item.active, .nav-item.active:visited { color: var(--accent); font-weight: 600; }
.nav-icon { font-size: 20px; line-height: 1; }

/* FAB */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(76px + var(--safe-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 28px;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  cursor: pointer;
  z-index: 15;
}

/* Cards / lists */
.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin: 18px 4px 8px 4px;
  font-weight: 700;
}
.section-title:first-child { margin-top: 2px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  border-radius: var(--radius);
  padding: 13px 16px;
  margin-bottom: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  cursor: pointer;
}
.list-item:active { background: #fafafa; }
.list-item-main { min-width: 0; }
.list-item-title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.list-item-sub .badge { margin-top: 0; margin-left: 6px; vertical-align: middle; }
.list-item-side { text-align: right; flex-shrink: 0; margin-left: 10px; }
.list-item-amount { font-weight: 700; font-size: 15px; }

.list-item.compact { padding: 10px 14px; margin-bottom: 6px; }
.list-item.compact .list-item-title { font-size: 14px; }

.list-item-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; margin-left: 10px; }
.icon-btn-sm {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg);
  font-size: 14px;
  flex-shrink: 0;
}
.icon-btn-sm:active { background: #e8e8ea; }

.search-bar { margin-bottom: 10px; }
.search-bar input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  background: #fff;
  color: var(--text);
  font-family: inherit;
}
.search-bar input::-webkit-search-cancel-button { -webkit-appearance: none; }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  margin-top: 4px;
}
.badge-entwurf { background: #eee; color: #666; }
.badge-gesendet { background: #fff3cd; color: #8a6400; }
.badge-akzeptiert { background: #d8f3e1; color: var(--success); }
.badge-abgelehnt { background: #fde0e0; color: var(--accent-dark); }
.badge-paid { background: #d8f3e1; color: var(--success); }
.badge-unpaid { background: #fde0e0; color: var(--accent-dark); }
.badge-neu { background: #dbe9ff; color: #1a4fa0; }
.badge-in-bearbeitung { background: #fff3cd; color: #8a6400; }
.badge-offeriert { background: #e4d8f7; color: #5a2a9e; }
.badge-abgeschlossen { background: #d8f3e1; color: var(--success); }
.badge-offen { background: #fff3cd; color: #8a6400; }
.badge-gestellt { background: #d8f3e1; color: var(--success); }
.badge-sent { background: #dbe9ff; color: #1a4fa0; margin-left: 4px; }
.badge-unsent { background: #eee; color: #666; margin-left: 4px; }

/* Stat grid on dashboard */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 6px; }
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.stat-value { font-size: 24px; font-weight: 800; }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat-card.accent { background: var(--accent); color: #fff; }
.stat-card.accent .stat-label { color: rgba(255,255,255,0.85); }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}
.empty-state .big { font-size: 40px; margin-bottom: 8px; }

/* Forms */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  background: #fff;
  color: var(--text);
  font-family: inherit;
}
.field textarea { resize: vertical; min-height: 70px; }
.code-textarea {
  width: 100%; min-height: 280px; resize: vertical;
  font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 12px; line-height: 1.5;
  padding: 11px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: #fff; color: var(--text); white-space: pre; overflow-wrap: normal; overflow-x: auto;
}
.checkbox-field { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; color: var(--text); cursor: pointer; }
.checkbox-field input[type="checkbox"] { width: 18px; height: 18px; flex-shrink: 0; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 18px;
  border-radius: 10px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; width: 100%; }
.btn-secondary { background: #eee; color: var(--text); }
.btn-ghost { background: transparent; color: var(--accent); padding: 8px 10px; }
.btn-danger { background: #fde0e0; color: var(--accent-dark); }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 10px; margin-top: 18px; }
.btn-row .btn { flex: 1; }

/* Positions / bullet editors */
.pos-row, .bullet-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.pos-row input[type="text"] { flex: 1; }
.pos-row input[type="number"] { width: 110px; }
.row-remove {
  background: #fde0e0;
  color: var(--accent-dark);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  font-size: 16px;
  flex-shrink: 0;
  cursor: pointer;
}
.add-row-btn {
  background: #eee;
  border: none;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  margin-top: 2px;
}

/* Inquiry file attachments */
.file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.file-thumb {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  background: #f0f0f0;
}
.file-thumb-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}
.file-item-main { min-width: 0; flex: 1; }
.file-item-name {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-item-sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
#inquiry-file-input { display: block; margin-bottom: 8px; font-size: 13px; }

.totals-box {
  background: #f8f8fa;
  border-radius: 10px;
  padding: 10px 14px;
  margin-top: 6px;
  font-size: 14px;
}
.totals-box div { display: flex; justify-content: space-between; padding: 2px 0; }
.totals-box .grand { font-weight: 800; font-size: 16px; margin-top: 4px; border-top: 1px dashed #ccc; padding-top: 6px; }

/* Sheet (bottom modal) */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 30;
}
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-height: 90vh;
  background: var(--card);
  border-radius: 18px 18px 0 0;
  z-index: 31;
  padding: 10px 18px calc(24px + var(--safe-bottom)) 18px;
  overflow-y: auto;
  box-shadow: 0 -6px 24px rgba(0,0,0,0.25);
}
.sheet-handle { width: 40px; height: 4px; background: #ddd; border-radius: 4px; margin: 4px auto 14px auto; }
.sheet h2 { font-size: 19px; margin: 0 0 14px 0; }

.toast {
  position: fixed;
  bottom: calc(90px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: #222;
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 50;
}

/* Detail view */
.detail-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; }
.detail-title { font-size: 20px; font-weight: 800; }
.detail-sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.action-grid { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0; }
.action-grid .btn { flex: 1; min-width: 130px; }

/* Settings */
.settings-logo-preview { max-height: 60px; max-width: 160px; display: block; margin-bottom: 10px; object-fit: contain; }

/* Provisionen */
.person-total-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 12px; }
.person-total-card { margin-bottom: 0; }
.person-total-name { font-weight: 700; font-size: 14px; margin-bottom: 6px; }
.person-total-percent { font-weight: 400; color: var(--muted); font-size: 12px; }
.person-total-row { display: flex; justify-content: space-between; font-size: 13px; padding: 2px 0; color: var(--muted); }
.person-total-row.grand { font-weight: 700; color: var(--text); border-top: 1px dashed #ccc; margin-top: 4px; padding-top: 5px; }
.tabs { display: flex; gap: 6px; margin: 8px 0 12px 0; }
.tab-btn { flex: 1; background: #eee; border: none; border-radius: 8px; padding: 9px 0; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; }
.tab-btn.active { background: var(--accent); color: #fff; }
.person-paid-row { background: var(--card); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); }

/* Login page */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: var(--accent);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
.login-card {
  background: #fff; border-radius: 18px; padding: 32px 28px;
  width: 90%; max-width: 340px; box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  display: flex; flex-direction: column; gap: 12px;
}
.login-logo { font-size: 24px; font-weight: 800; text-align: center; color: var(--accent); letter-spacing: 1px; }
.login-sub { text-align: center; color: var(--muted); margin: 0 0 6px 0; font-size: 14px; }
.login-card input {
  padding: 13px 14px; border: 1px solid var(--border); border-radius: 10px; font-size: 16px;
}
.login-card button {
  background: var(--accent); color: #fff; border: none; border-radius: 10px;
  padding: 13px; font-size: 16px; font-weight: 700; cursor: pointer;
}
.login-error { color: var(--accent-dark); text-align: center; font-size: 13px; margin: 0; }

@media (min-width: 640px) {
  .bottom-nav { max-width: 420px; left: 50%; transform: translateX(-50%); border-radius: 18px 18px 0 0; border: 1px solid var(--border); border-bottom: none; }
  .fab { right: calc(50% - 310px); }
}
