/* Rechnungsverteilungs-App – Styles */

:root {
  --primary: #1a56db;
  --primary-hover: #1e429f;
  --primary-light: #e8f0fe;
  --success: #057a55;
  --success-light: #def7ec;
  --danger: #c81e1e;
  --danger-light: #fde8e8;
  --bg: #f3f4f6;
  --card-bg: #ffffff;
  --text: #111827;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.05);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.5;
}

/* ── Layout ── */

.view {
  max-width: 600px;
  margin: 0 auto;
  padding: 16px;
}

.view-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
  gap: 16px;
  color: var(--text-muted);
}

/* ── App-Header ── */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0 16px;
}

.app-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
}

/* ── Card ── */

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.card h1 { font-size: 1.35rem; margin-bottom: 8px; }
.card h2 { font-size: 1.15rem; margin-bottom: 12px; }

.card h3 {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 20px 0 10px;
}

.card-success { border-top: 4px solid var(--success); }

/* ── Spinner ── */

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Formularfelder ── */

.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 5px;
}

.field input[type="text"],
.field input[type="number"],
.field input[type="date"],
.field input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  color: var(--text);
  background: #fff;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}

.field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.1);
}

.field-half { max-width: 220px; }

.field-row {
  display: flex;
  gap: 12px;
  margin-bottom: 0;
}

.field-row .field { flex: 1; min-width: 0; }
.field-row .field-half { max-width: none; }

.field-hint {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.help-link {
  font-weight: normal;
  font-size: 0.8rem;
  color: var(--primary);
  text-decoration: none;
  margin-left: 8px;
}

/* ── Schlüssel-Auswahl ── */

.key-selector {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.key-option {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  display: block;
  user-select: none;
}

.key-option:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-light);
}

.key-option input[type="radio"] { display: none; }

.key-option-content {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.key-name { font-weight: 600; font-size: 0.95rem; }

.key-shares {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-family: 'Courier New', monospace;
}

/* ── Live-Vorschau ── */

.preview-section {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin: 8px 0 16px;
}

.preview-section h3 { margin-top: 0; }

.preview-placeholder {
  color: var(--text-muted);
  font-size: 0.875rem;
  text-align: center;
  padding: 6px 0;
}

.preview-item {
  display: flex;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}

.preview-item:last-child { border-bottom: none; }

.preview-party { flex: 1; font-weight: 500; font-size: 0.9rem; }

.preview-pct {
  color: var(--text-muted);
  font-size: 0.85rem;
  width: 48px;
  text-align: right;
}

.preview-amount {
  font-weight: 700;
  width: 90px;
  text-align: right;
  color: var(--primary);
  font-size: 0.95rem;
}

/* ── Buttons ── */

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

.btn {
  display: block;
  width: 100%;
  padding: 11px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: background 0.15s, opacity 0.15s;
  text-decoration: none;
}

.btn:active:not(:disabled) { opacity: 0.85; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-primary:disabled { background: #9ca3af; cursor: not-allowed; }

.btn-secondary {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}
.btn-secondary:hover { background: var(--primary-light); }

.btn-whatsapp {
  background: #25d366;
  color: #fff;
  border: none;
}
.btn-whatsapp:hover { background: #1ebe5d; }

.btn-muted {
  background: var(--bg);
  color: var(--text-muted);
  border: 1.5px solid var(--border);
  cursor: not-allowed;
}

.btn-icon {
  background: transparent;
  border: none;
  font-size: 1.15rem;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
  line-height: 1;
}
.btn-icon:hover { background: var(--border); }

.btn-back {
  background: transparent;
  border: none;
  color: var(--primary);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  white-space: nowrap;
}

/* ── Tab-Navigation ── */

.tab-bar {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
}

.tab-btn {
  flex: 1;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.tab-btn:hover { background: var(--primary-light); color: var(--primary); border-color: var(--primary); }
.tab-active { background: var(--primary); color: #fff; border-color: var(--primary); }
.tab-active:hover { background: var(--primary-hover); }

/* ── Export-Statusleiste ── */

.export-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  margin-bottom: 4px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.export-bar span { flex: 1; }

.btn-link {
  background: transparent;
  border: none;
  color: var(--primary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  white-space: nowrap;
}

.btn-link:hover { text-decoration: underline; }

/* ── Autocomplete ── */

.autocomplete-wrapper { position: relative; }

.autocomplete-dropdown {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  list-style: none;
  z-index: 200;
  max-height: 200px;
  overflow-y: auto;
}

.autocomplete-item {
  padding: 9px 12px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.1s;
}
.autocomplete-item:hover { background: var(--primary-light); }

/* ── Status-Meldungen ── */

.error-message {
  background: var(--danger-light);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-top: 12px;
}

.text-muted {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-bottom: 20px;
  line-height: 1.6;
}

/* ── Bestätigungsansicht ── */

.success-icon {
  width: 56px;
  height: 56px;
  background: var(--success);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  font-weight: bold;
  margin: 0 auto 16px;
}

.summary-table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0 4px;
  font-size: 0.9rem;
}

.summary-table th,
.summary-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.summary-table th {
  color: var(--text-muted);
  font-weight: 500;
  width: 110px;
}

.summary-table tr:last-child th,
.summary-table tr:last-child td { border-bottom: none; }

.share-tiles {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin: 8px 0 20px;
}

.share-tile {
  background: var(--success-light);
  border-radius: var(--radius-sm);
  padding: 12px 8px;
  text-align: center;
}

.share-tile-party {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.share-tile-pct {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.share-tile-amount {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--success);
}

/* ── Summenzeile Vorschau ── */

.preview-sum {
  border-top: 2px solid var(--border) !important;
  border-bottom: none !important;
  margin-top: 2px;
  font-weight: 700;
}

.preview-sum .preview-party { color: var(--text); }
.preview-sum .preview-pct   { color: var(--text); }
.preview-sum .preview-amount { color: var(--text); }

/* ── Summenzeile Bestätigung ── */

.share-sum-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--success-light);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-weight: 700;
  font-size: 0.9rem;
}

.share-sum-label { flex: 1; color: var(--text); }
.share-sum-pct   { color: var(--text-muted); font-size: 0.85rem; white-space: nowrap; }
.share-sum-amount { color: var(--success); text-align: right; min-width: 90px; }

/* ── Schlüsselverwaltung ── */

.back-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.back-header h2 { margin: 0; }

.key-form { margin-bottom: 4px; }

.party-shares {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 4px;
}

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

.party-share-row label {
  flex: 1;
  font-size: 0.9rem;
}

.share-input-wrapper {
  display: flex;
  align-items: center;
  gap: 6px;
}

.share-input {
  width: 76px;
  padding: 7px 10px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  text-align: right;
  transition: border-color 0.15s;
}

.share-input:focus {
  outline: none;
  border-color: var(--primary);
}

.key-sum {
  margin-top: 10px;
  font-size: 0.875rem;
  padding: 8px 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
}

.sum-ok { color: var(--success); margin-left: 6px; font-weight: 700; }
.sum-error { color: var(--danger); margin-left: 6px; font-weight: 600; }

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 24px 0;
}

/* ── Listen-Verwaltung ── */

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  min-height: 32px;
}

.tag-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--primary-light);
  border: 1px solid var(--primary);
  border-radius: 20px;
  padding: 4px 10px 4px 12px;
  font-size: 0.875rem;
}

.tag-del {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 1rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  opacity: 0.7;
}
.tag-del:hover { opacity: 1; }

.list-add-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.list-add-input {
  flex: 1;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  color: var(--text);
  background: #fff;
  transition: border-color 0.15s;
}
.list-add-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,86,219,0.1);
}

.list-add-row .btn { width: auto; white-space: nowrap; }

/* ── Fehler-View ── */

.error-icon { font-size: 2.5rem; text-align: center; margin-bottom: 12px; }

/* ── Responsive ── */

@media (max-width: 420px) {
  .key-selector { grid-template-columns: 1fr; }
  .share-tiles { grid-template-columns: repeat(2, 1fr); }
  .field-half { max-width: 100%; }
  .card { padding: 18px; }
}
