/* ============================================================
   Kassenbon Manager – Mobile-First CSS
   ============================================================ */

/* ── CSS Variables ─────────────────────────────────────────── */
:root {
  --primary:        #4F46E5;
  --primary-dark:   #3730A3;
  --primary-light:  #EEF2FF;
  --secondary:      #64748B;
  --success:        #10B981;
  --success-light:  #D1FAE5;
  --danger:         #EF4444;
  --danger-light:   #FEE2E2;
  --warning:        #F59E0B;
  --warning-light:  #FEF3C7;

  --bg:             #F1F5F9;
  --bg-card:        #FFFFFF;
  --text:           #0F172A;
  --text-muted:     #64748B;
  --border:         #E2E8F0;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.06);
  --shadow:    0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);

  --radius:    12px;
  --radius-sm: 8px;
  --radius-xs: 4px;

  --header-h:  56px;
  --tabnav-h:  48px;
  --fab-size:  56px;
}

/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
               'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; height: auto; display: block; }

/* ── Typography ────────────────────────────────────────────── */
h1 { font-size: 1.25rem; font-weight: 700; }
h2 { font-size: 1.1rem;  font-weight: 700; }
h3 { font-size: 1rem;    font-weight: 600; }
p  { font-size: .9375rem; }

/* ── Utilities ─────────────────────────────────────────────── */
.d-none     { display: none !important; }
.d-none-sm  { display: none; }
@media (min-width: 640px) { .d-none-sm { display: inline; } }

/* ── Auth Layout ───────────────────────────────────────────── */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.auth-container {
  width: 100%;
  max-width: 400px;
}

.auth-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 2rem 1.5rem;
}

.auth-logo {
  display: flex;
  justify-content: center;
  margin-bottom: .75rem;
  color: var(--primary);
}

.auth-title {
  text-align: center;
  font-size: 1.4rem;
  margin-bottom: .25rem;
}

.auth-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: .875rem;
  margin-bottom: 1.5rem;
}

/* ── Header ────────────────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--primary);
  color: #fff;
  height: var(--header-h);
  box-shadow: var(--shadow-md);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  padding: 0 1rem;
  gap: .5rem;
}

.header-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  gap: .4rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-back {
  display: flex;
  align-items: center;
  gap: .5rem;
  min-width: 0;
  flex: 1;
}

.header-user  { display: flex; align-items: center; gap: .5rem; }
.header-actions { display: flex; align-items: center; gap: .25rem; }

.user-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: rgba(255,255,255,.25);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .85rem;
  flex-shrink: 0;
}

.user-name { font-size: .875rem; color: rgba(255,255,255,.9); }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: rgba(255,255,255,.85);
  cursor: pointer;
  transition: background .15s;
  flex-shrink: 0;
}
.btn-icon:hover { background: rgba(255,255,255,.15); }
.btn-icon svg   { pointer-events: none; }

/* ── Tab Navigation ────────────────────────────────────────── */
.tab-nav {
  position: sticky;
  top: var(--header-h);
  z-index: 90;
  background: var(--bg-card);
  border-bottom: 2px solid var(--border);
  display: flex;
  height: var(--tabnav-h);
}

.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: .8125rem;
  font-weight: 500;
  cursor: pointer;
  padding: 0 .5rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
  white-space: nowrap;
}

.tab-btn svg { flex-shrink: 0; }

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

/* ── Main Content ──────────────────────────────────────────── */
.main-content {
  padding: 1rem;
  padding-bottom: calc(var(--fab-size) + 2rem);
  max-width: 680px;
  margin: 0 auto;
}

/* ── Tab Panels ────────────────────────────────────────────── */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  margin-bottom: .75rem;
}

/* ── Forms ─────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: .875rem;
  font-weight: 500;
  margin-bottom: .35rem;
  color: var(--text);
}

.form-control {
  width: 100%;
  padding: .625rem .75rem;
  font-size: .9375rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  appearance: none;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.15);
}

textarea.form-control { resize: vertical; min-height: 70px; }

/* Radio / Checkbox ─────────────────────────────────────────── */
.radio-group,
.checkbox-list {
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.radio-option,
.checkbox-option {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .65rem .75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: .9rem;
  transition: border-color .15s, background .15s;
}

.radio-option:has(input:checked),
.checkbox-option:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-light);
}

.radio-option input,
.checkbox-option input {
  accent-color: var(--primary);
  width: 16px; height: 16px;
  flex-shrink: 0;
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .625rem 1.125rem;
  font-size: .9375rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: opacity .15s, transform .1s, box-shadow .15s;
  white-space: nowrap;
  user-select: none;
}

.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-full { width: 100%; }

.btn-primary  { background: var(--primary);   color: #fff; }
.btn-primary:hover  { background: var(--primary-dark); }

.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #CBD5E1; }

.btn-danger   { background: var(--danger);    color: #fff; }
.btn-danger:hover { background: #DC2626; }

.btn-success  { background: var(--success);   color: #fff; }

.btn-sm  { padding: .4rem .75rem;  font-size: .8125rem; }
.btn-xs  { padding: .25rem .55rem; font-size: .75rem; border-radius: var(--radius-xs); }

/* ── FAB ───────────────────────────────────────────────────── */
.fab {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 200;
  width: var(--fab-size);
  height: var(--fab-size);
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .15s, transform .15s, box-shadow .15s;
}

.fab:hover  { background: var(--primary-dark); box-shadow: 0 8px 25px rgba(79,70,229,.4); }
.fab:active { transform: scale(.93); }

/* ── Badges ────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: .15rem .5rem;
  border-radius: 99px;
  font-size: .72rem;
  font-weight: 600;
  line-height: 1.4;
}

.badge-split  { background: #EDE9FE; color: #6D28D9; }
.badge-single { background: #E0F2FE; color: #0369A1; }
.badge-paid   { background: var(--success-light); color: #065F46; }
.badge-user   { background: var(--primary-light); color: var(--primary-dark); font-weight: 600; font-size: .875rem; }

/* ── Alerts ────────────────────────────────────────────────── */
.alert {
  padding: .75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  margin-bottom: 1rem;
}

.alert-error   { background: var(--danger-light);  color: #991B1B; }
.alert-success { background: var(--success-light); color: #065F46; }
.alert-warning { background: var(--warning-light); color: #92400E; }

/* ── Loading & Empty States ────────────────────────────────── */
.loading-state,
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  text-align: center;
  gap: .75rem;
}

.empty-state svg { opacity: .4; }
.empty-state h3  { font-size: 1rem; color: var(--text); }
.empty-state p   { font-size: .875rem; }

.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Modal ─────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

@media (min-width: 480px) {
  .modal { align-items: center; }
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(2px);
}

.modal-dialog {
  position: relative;
  z-index: 1;
  background: var(--bg-card);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 540px;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp .22s ease;
}

@media (min-width: 480px) {
  .modal-dialog {
    border-radius: var(--radius);
    width: calc(100% - 2rem);
  }
}

.modal-sm { max-width: 360px; }

@keyframes slideUp {
  from { transform: translateY(30px); opacity: .5; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 1;
}

.modal-title { font-size: 1rem; }

.modal-close {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--border);
  color: var(--text-muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s;
}
.modal-close:hover { background: #CBD5E1; }

.modal-body   { padding: 1.25rem; }
.modal-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: .75rem;
  justify-content: flex-end;
  position: sticky;
  bottom: 0;
  background: var(--bg-card);
}

/* ── Vorgang Cards (Dashboard) ─────────────────────────────── */
.vorgang-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  margin-bottom: .75rem;
  cursor: pointer;
  transition: box-shadow .15s, transform .12s;
  display: block;
  color: var(--text);
}

.vorgang-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); text-decoration: none; }

.vorgang-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: .5rem;
  margin-bottom: .5rem;
}

.vorgang-title   { font-weight: 600; font-size: .9375rem; }
.vorgang-total   { font-size: 1.0625rem; font-weight: 700; color: var(--primary); white-space: nowrap; }
.vorgang-meta-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
  font-size: .8125rem;
  color: var(--text-muted);
}

.vorgang-actions {
  display: flex;
  gap: .5rem;
  margin-top: .75rem;
  border-top: 1px solid var(--border);
  padding-top: .75rem;
}

/* ── Payer Groups (My Articles tab) ────────────────────────── */
.payer-group {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: .75rem;
  overflow: hidden;
}

.payer-group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .875rem 1rem;
  background: var(--primary-light);
  gap: .5rem;
  flex-wrap: wrap;
}

.payer-group-name {
  font-weight: 600;
  font-size: .9375rem;
  color: var(--primary-dark);
}

.payer-group-total {
  font-weight: 700;
  font-size: 1rem;
  color: var(--primary-dark);
  white-space: nowrap;
}

.payer-group-actions {
  width: 100%;
  padding: .5rem 1rem;
  display: flex;
  justify-content: flex-end;
  border-bottom: 1px solid var(--border);
}

/* ── My Artikel Items ──────────────────────────────────────── */
.my-artikel-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  gap: .5rem;
  transition: background .15s;
}

.my-artikel-item:last-child { border-bottom: none; }

.my-artikel-info { flex: 1; min-width: 0; }
.my-artikel-name {
  font-size: .9rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.my-artikel-sub {
  font-size: .75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: .35rem;
  margin-top: .15rem;
  flex-wrap: wrap;
}

.my-artikel-link { color: var(--primary); font-size: .75rem; }

.my-artikel-right {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-shrink: 0;
}

.my-artikel-price { font-weight: 600; font-size: .9rem; white-space: nowrap; }

.btn-pay {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: border-color .15s, background .15s, color .15s;
  flex-shrink: 0;
}

.btn-pay:hover { border-color: var(--success); color: var(--success); }
.btn-pay.paid  { border-color: var(--success); background: var(--success-light); color: var(--success); }

/* ── Vorgang Detail ────────────────────────────────────────── */
.vorgang-info-card { margin-bottom: 1rem; }

.vorgang-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: .75rem;
  margin-bottom: .75rem;
}

.meta-item  { display: flex; flex-direction: column; gap: .2rem; }
.meta-label { font-size: .75rem; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.meta-value { font-size: .9375rem; font-weight: 600; }
.price-total { font-size: 1.1rem; color: var(--primary); }

.vorgang-notes { margin-top: .75rem; }
.vorgang-notes p { font-size: .875rem; color: var(--text-muted); margin-top: .25rem; }

.section-divider { height: 1px; background: var(--border); margin: .75rem 0; }

/* ── Receipt Upload ────────────────────────────────────────── */
.receipt-section { margin-top: .5rem; }

.upload-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 1.5rem 1rem;
  cursor: pointer;
  color: var(--text-muted);
  text-align: center;
  transition: border-color .15s, background .15s;
}

.upload-area:hover { border-color: var(--primary); background: var(--primary-light); }
.upload-hint { font-size: .75rem; }

.receipt-preview { margin-bottom: .75rem; }
.receipt-img     { border-radius: var(--radius-sm); max-height: 220px; width: 100%; object-fit: contain; background: var(--bg); }

.receipt-actions { display: flex; gap: .5rem; margin-top: .5rem; }

#ai-scan-result {
  border-radius: var(--radius-sm);
  background: var(--success-light);
  padding: .75rem;
  font-size: .875rem;
}

/* ── Artikel Cards (Vorgang Detail) ────────────────────────── */
.artikel-section { margin-top: 0; }

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .75rem;
}

.section-title { font-size: 1rem; font-weight: 700; }

.artikel-card {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  border: 1.5px solid var(--border);
  padding: .75rem 1rem;
  margin-bottom: .625rem;
  transition: opacity .15s;
}

.artikel-card.paid {
  opacity: .55;
  background: #F8FAFC;
}

.artikel-main {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: .5rem;
}

.artikel-info {
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}

.artikel-name {
  font-weight: 500;
  font-size: .9375rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.artikel-price-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  flex-shrink: 0;
}

.artikel-price { font-weight: 700; font-size: .9375rem; color: var(--primary); }
.artikel-share { font-size: .75rem; color: var(--text-muted); }

.artikel-assignment {
  display: flex;
  align-items: center;
  gap: .3rem;
  font-size: .8rem;
  color: var(--text-muted);
  margin-top: .4rem;
}

.artikel-actions {
  display: flex;
  gap: .5rem;
  margin-top: .625rem;
  padding-top: .625rem;
  border-top: 1px solid var(--border);
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (min-width: 640px) {
  .main-content { padding: 1.25rem; }
  .card         { padding: 1.25rem; }
  .modal-footer { justify-content: flex-end; }
}

/* ── Settings Page ───────────────────────────────────────────── */
.settings-content { max-width: 640px; margin: 0 auto; }

.settings-profile-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
}
.profile-avatar-lg {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 1.4rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.profile-name { font-size: 1.05rem; font-weight: 600; color: var(--text); }
.profile-meta { font-size: .8rem; color: var(--text-muted); margin-top: .15rem; }

.settings-section { margin-bottom: 1rem; }
.settings-section-title {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 1rem;
}
.settings-danger-zone { border: 1.5px solid var(--danger); }
.danger-title { color: var(--danger); }
.danger-description { color: var(--text-muted); font-size: .875rem; margin: -.25rem 0 1rem; }

/* ── History Page ────────────────────────────────────────────── */
.history-filter { margin-bottom: .75rem; }
.filter-row { display: flex; gap: .625rem; }
.form-control-sm { padding: .4rem .65rem; font-size: .875rem; }

.history-summary {
  display: flex;
  gap: 0;
  margin-bottom: .75rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.summary-row {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .125rem;
  padding: .875rem .5rem;
  background: var(--bg-card);
}
.summary-row:first-child {
  border-right: 1px solid var(--border);
}
.summary-label { font-size: .75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; }
.summary-value { font-size: 1.1rem; font-weight: 700; color: var(--text); }
.summary-value:first-of-type { color: var(--success); }

/* Bezahlt-Preis in der History-Liste grün hervorheben */
.history-paid-price { color: var(--success) !important; }

/* ── Header back nav ─────────────────────────────────────────── */
.header-back {
  display: flex;
  align-items: center;
  gap: .375rem;
  min-width: 0;
}
.header-back .header-title {
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
