@import url('https://fonts.googleapis.com/css2?family=Figtree:wght@500;600;700;800&family=Inter:wght@400;500;600;700&display=swap');
@import url('./tokens.css');

*,*::before,*::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 15px; line-height: 24px;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overscroll-behavior-y: none;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; padding: 0; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1,h2,h3,h4 { font-family: 'Figtree', system-ui, sans-serif; margin: 0; letter-spacing: -0.01em; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 2px; }

/* ===== Layout ===== */
.app { max-width: 640px; margin: 0 auto; padding: var(--space-4) var(--space-4) calc(var(--space-8) * 2); }

/* ===== App-Header ===== */
.app-header {
  position: relative;
  display: flex; justify-content: space-between; align-items: center;
  gap: var(--space-3);
  padding-bottom: var(--space-3);
  margin-bottom: var(--space-5);
  border-bottom: 1px solid var(--border);
}
.app-header-title { display: flex; align-items: center; gap: var(--space-2); min-width: 0; flex: 1 1 auto; }
.app-header-icon { display: inline-flex; color: var(--action); flex-shrink: 0; }
.app-header-icon svg { stroke-width: 1.5; }
.app-header-icon img { width: 28px; height: 28px; border-radius: 7px; display: block; }
.app-header-title h1 {
  font-family: 'Figtree', system-ui, sans-serif;
  font-size: 22px; line-height: 28px; font-weight: 800;
  color: var(--text);
  margin: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.app-header-actions { display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0; }
.app-header-status {
  position: absolute; bottom: -9px; right: 0;
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: 10px; line-height: 14px; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap; pointer-events: none;
  transition: opacity 0.25s, background-color 0.2s, border-color 0.2s, color 0.2s;
}
.app-header-status[hidden] { display: none; }
.app-header-status[data-status="offline"]  { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning-text); }
.app-header-status[data-status="pending"]  { background: var(--info-bg);    border-color: var(--info-border);    color: var(--info-text); }
.app-header-status[data-status="saved"]    { background: var(--success-bg); border-color: var(--success-border); color: var(--success-text); }
.app-header-status[data-status="error"]    { background: var(--error-bg);   border-color: var(--error-border);   color: var(--error-text); }

/* ===== btn-pill (header actions) ===== */
.btn-pill {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: var(--radius-pill);
  padding: 0 var(--space-3);
  min-height: 44px; min-width: 44px;
  font-size: 14px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--space-1);
  cursor: pointer; white-space: nowrap; flex-shrink: 0;
  transition: background-color 0.15s;
}
.btn-pill:hover  { background: var(--surface-hover); }
.btn-pill:active { background: var(--surface-active); }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  padding: 0 var(--space-4);
  min-height: 44px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-weight: 600; font-size: 15px;
  cursor: pointer; transition: background-color 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn-primary { background: var(--action); color: var(--on-action); }
.btn-primary:hover { background: var(--action-hover); }
.btn-accent { background: var(--accent-solid); color: var(--on-accent); border-color: var(--accent-solid); }
.btn-accent:hover { background: var(--a-800); border-color: var(--a-800); }
[data-theme="dark"] .btn-accent:hover { background: var(--a-200); border-color: var(--a-200); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-hover); }
.btn-ghost { background: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--surface-hover); }
.btn-danger { background: transparent; color: var(--error-text); border-color: var(--error-border); }
.btn-danger:hover { background: var(--error); color: var(--n-0); border-color: var(--error); }
[data-theme="dark"] .btn-danger:hover { color: var(--n-900); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== icon-btn (list-item actions) ===== */
.icon-btn {
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  transition: background-color 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.icon-btn.danger { color: var(--error-text); }
.icon-btn.danger:hover { background: var(--error-bg); }
.item-actions { display: flex; gap: 2px; flex-shrink: 0; margin-left: auto; }

/* ===== Section headings ===== */
.section-label {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 12px; line-height: 16px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-muted);
  margin: var(--space-5) 0 var(--space-2);
}
.section-label:first-child { margin-top: 0; }

/* ===== Cards ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  margin-bottom: var(--space-2);
  transition: background-color 0.15s, border-color 0.15s;
}
.card-link { display: block; color: inherit; cursor: pointer; }
.card-link:hover { background: var(--surface-hover); border-color: var(--border-strong); text-decoration: none; }

.trip-card-title { font-family: 'Figtree', system-ui, sans-serif; font-size: 18px; line-height: 24px; font-weight: 700; margin: 0 0 4px; }
.trip-card-meta { font-size: 13px; color: var(--text-muted); margin-bottom: var(--space-2); }
.trip-card-balance { font-size: 14px; font-weight: 600; }
.trip-card-balance.positive { color: var(--success-text); }
.trip-card-balance.negative { color: var(--error-text); }
.trip-card-balance.zero     { color: var(--text-muted); font-weight: 500; }

/* Archive — compact rows */
.archive-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  color: inherit; cursor: pointer;
  border: 1px solid transparent;
}
.archive-row:hover { background: var(--surface-hover); border-color: var(--border); text-decoration: none; }
.archive-row-title { font-weight: 600; }
.archive-row-meta { font-size: 13px; color: var(--text-muted); }

/* ===== Empty state ===== */
.empty {
  text-align: center;
  padding: var(--space-8) var(--space-4);
  color: var(--text-muted);
}
.empty-icon { color: var(--text-muted); opacity: 0.6; margin-bottom: var(--space-4); }
.empty h2 { font-family: 'Figtree', system-ui, sans-serif; font-size: 21px; font-weight: 700; color: var(--text); margin-bottom: var(--space-2); }
.empty p { margin-bottom: var(--space-5); }
.empty-actions { display: flex; gap: var(--space-2); justify-content: center; flex-wrap: wrap; }

/* ===== Forms ===== */
.form-group { margin-bottom: var(--space-4); }
.form-group label {
  display: block;
  font-size: 13px; font-weight: 600;
  color: var(--text-2);
  margin-bottom: var(--space-1);
}
.form-control {
  width: 100%;
  padding: 0 var(--space-3);
  min-height: 44px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  transition: border-color 0.15s;
}
.form-control:focus { border-color: var(--action); outline: 2px solid var(--focus); outline-offset: 0; }
textarea.form-control { padding-top: var(--space-2); padding-bottom: var(--space-2); min-height: 80px; resize: vertical; }
.form-row { display: flex; gap: var(--space-2); }
.form-row > * { flex: 1; }
.form-help { font-size: 12px; color: var(--text-muted); margin-top: var(--space-1); }

.amount-input-wrap { position: relative; }
.amount-input-wrap .form-control { padding-right: 48px; text-align: right; font-variant-numeric: tabular-nums; font-size: 18px; font-weight: 600; }
.amount-input-wrap .currency-suffix {
  position: absolute; right: var(--space-3); top: 50%; transform: translateY(-50%);
  font-weight: 600; color: var(--text-muted); pointer-events: none;
}

/* ===== Tabs ===== */
.tabs {
  display: flex;
  gap: 2px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: var(--radius-md);
  margin-bottom: var(--space-5);
}
.tab {
  flex: 1;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600;
  color: var(--text-muted);
  text-align: center;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ===== Trip detail ===== */
.trip-title-block { margin-bottom: var(--space-5); }
.trip-title-block h1 {
  font-family: 'Figtree', system-ui, sans-serif;
  font-size: 28px; line-height: 36px; font-weight: 800;
  margin-bottom: var(--space-1);
}
.trip-title-block .meta { color: var(--text-muted); font-size: 14px; }

.balance-summary {
  background: var(--surface-2);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
  text-align: center;
}
.balance-summary .label { font-size: 13px; color: var(--text-muted); margin-bottom: var(--space-1); }
.balance-summary .amount {
  font-family: 'Figtree', system-ui, sans-serif;
  font-size: 32px; line-height: 40px; font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.balance-summary .amount.positive { color: var(--success-text); }
.balance-summary .amount.negative { color: var(--error-text); }
.balance-summary .amount.zero     { color: var(--text); }

/* ===== Expense list items ===== */
.expense-item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-2);
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}
.expense-item:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.expense-icon {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  color: var(--action);
  flex-shrink: 0;
}
.expense-body { flex: 1; min-width: 0; }
.expense-title { font-weight: 600; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.expense-meta { font-size: 12px; color: var(--text-muted); }
.expense-amount {
  font-family: 'Figtree', system-ui, sans-serif;
  font-weight: 700; font-size: 16px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ===== People chips ===== */
.people-chips { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-3); }
.person-chip {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  font-size: 13px; font-weight: 600;
  border: 1px solid var(--border);
}

/* People-Picker (in Ausgabe-Form) */
.person-toggle {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  margin-bottom: 4px;
  transition: background-color 0.15s, border-color 0.15s;
}
.person-toggle:hover { background: var(--surface-hover); }
.person-toggle.selected { background: var(--p-50); border-color: var(--action); }
[data-theme="dark"] .person-toggle.selected { background: var(--p-800); border-color: var(--action); }
.person-toggle .toggle-indicator {
  width: 22px; height: 22px;
  border-radius: 6px;
  border: 2px solid var(--border-strong);
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.person-toggle.selected .toggle-indicator {
  background: var(--action); border-color: var(--action);
  color: var(--on-action);
}
.person-toggle .name { flex: 1; font-weight: 500; }
.person-toggle .share {
  font-size: 12px; color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ===== Settlement rows ===== */
.settlement-row {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-2);
}
.settlement-row .from, .settlement-row .to { font-weight: 600; }
.settlement-row .arrow { color: var(--text-muted); }
.settlement-row .amount {
  margin-left: auto;
  font-family: 'Figtree', system-ui, sans-serif;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ===== FAB ===== */
.fab {
  position: fixed; bottom: var(--space-5); right: max(var(--space-5), calc((100vw - 640px)/2 + var(--space-5)));
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--accent-solid);
  color: var(--on-accent);
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-lg);
  border: none;
  cursor: pointer;
  z-index: 10;
  transition: background-color 0.15s, transform 0.15s;
}
.fab:hover { background: var(--a-800); }
[data-theme="dark"] .fab:hover { background: var(--a-200); }
.fab:active { transform: scale(0.96); }

/* ===== Modal/Dialog (mobile sheet style) ===== */
.modal-backdrop {
  position: fixed; inset: 0;
  background: var(--overlay);
  z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade-in 0.2s;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%; max-width: 640px;
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: var(--space-5) var(--space-4) var(--space-5);
  max-height: 92vh;
  overflow-y: auto;
  animation: slide-up 0.25s;
  box-shadow: var(--shadow-lg);
}
@keyframes slide-up { from { transform: translateY(20px); } to { transform: translateY(0); } }
.modal-handle {
  width: 36px; height: 4px;
  background: var(--border-strong);
  border-radius: 2px;
  margin: -8px auto var(--space-3);
  opacity: 0.5;
}
.modal h2 {
  font-family: 'Figtree', system-ui, sans-serif;
  font-size: 21px; font-weight: 700;
  margin-bottom: var(--space-4);
}
.modal-actions { display: flex; gap: var(--space-2); margin-top: var(--space-5); }
.modal-actions .btn { flex: 1; }

@media (min-width: 640px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: var(--radius-lg); max-width: 480px; }
}

/* ===== Diary / Reisetagebuch ===== */
.diary-map {
  height: 360px;
  width: 100%;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
  overflow: hidden;
  margin-bottom: var(--space-4);
}
.diary-map.empty {
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  height: 200px;
}
/* Leaflet dark-mode tweak: lass Marker etc. unangetastet, nur Attribution lesbar */
[data-theme="dark"] .leaflet-tile-pane { filter: brightness(0.9) saturate(0.85); }
[data-theme="dark"] .leaflet-control-attribution {
  background: rgba(38, 35, 32, 0.85) !important;
  color: var(--text-2) !important;
}
[data-theme="dark"] .leaflet-control-attribution a { color: var(--link) !important; }

.photo-card {
  display: flex; gap: var(--space-3);
  padding: var(--space-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-2);
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}
.photo-card:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.photo-thumb {
  width: 72px; height: 72px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--surface-2);
  flex-shrink: 0;
}
.photo-thumb.placeholder {
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
}
.photo-body { flex: 1; min-width: 0; padding: 4px 0; }
.photo-caption { font-weight: 600; margin-bottom: 4px; word-break: break-word; }
.photo-caption.empty { color: var(--text-muted); font-weight: 500; font-style: italic; }
.photo-meta { font-size: 12px; color: var(--text-muted); }
.photo-meta .geo { display: inline-flex; align-items: center; gap: 2px; }
.photo-meta .no-geo { color: var(--warning-text); }

/* Foto-Detail-Modal: vollformatiges Bild */
.photo-detail-img {
  width: 100%;
  max-height: 60vh;
  object-fit: contain;
  background: var(--n-900);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
  display: block;
}
.photo-upload-progress {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: var(--info-bg);
  border: 1px solid var(--info-border);
  color: var(--info-text);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-2);
  font-size: 13px;
}
.photo-upload-progress.error {
  background: var(--error-bg); border-color: var(--error-border); color: var(--error-text);
}

/* Marker-Popup tweak */
.leaflet-popup-content-wrapper {
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-md);
}
.leaflet-popup-tip { background: var(--surface); }
.leaflet-popup-content { margin: var(--space-3); font-family: 'Inter', system-ui, sans-serif; }
.leaflet-popup-content img { width: 100%; max-width: 200px; border-radius: var(--radius-sm); margin-bottom: 4px; cursor: pointer; }
.leaflet-popup-content .popup-caption { font-weight: 600; margin-bottom: 2px; }
.leaflet-popup-content .popup-meta { font-size: 12px; color: var(--text-muted); }

/* ===== Misc utility ===== */
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.text-muted { color: var(--text-muted); }
.small { font-size: 13px; line-height: 20px; }
.row { display: flex; align-items: center; gap: var(--space-2); }
.spread { display: flex; justify-content: space-between; align-items: center; }
.center { text-align: center; }
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--action);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.invite-code {
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 28px; font-weight: 700;
  letter-spacing: 0.15em;
  text-align: center;
  padding: var(--space-3);
  background: var(--surface-2);
  border-radius: var(--radius-md);
  border: 1px dashed var(--border-strong);
  user-select: all;
  margin-bottom: var(--space-3);
}

.toast {
  position: fixed; bottom: 96px; left: 50%; transform: translateX(-50%);
  background: var(--n-900); color: var(--n-0);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow-md);
  z-index: 100;
  animation: toast-in 0.2s;
}
[data-theme="dark"] .toast { background: var(--n-100); color: var(--n-900); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

.back-btn {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--text-muted);
  font-size: 14px;
  padding: var(--space-2) 0;
  margin-bottom: var(--space-2);
}
.back-btn:hover { color: var(--text); }
