/* splitHelp — flat travel-ticket aesthetic
   Paper cream ground, ink borders, hard offset shadows, bold flat accents. */

:root {
  --paper: #faf6ef;
  --ink: #191714;
  --coral: #ff5c39;
  --teal: #0e7c66;
  --sun: #ffc94d;
  --sky: #b8d8e8;
  --rose: #f4b8c4;
  --muted: #8a8378;
  --card: #fffdf8;
  --danger: #d12f2f;
  --border: 2px solid var(--ink);
  --shadow: 4px 4px 0 var(--ink);
  --shadow-sm: 3px 3px 0 var(--ink);
  --radius: 14px;
  --display: "Bricolage Grotesque", sans-serif;
  --body: "Familjen Grotesk", sans-serif;
}

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

html {
  -webkit-text-size-adjust: 100%;
  background: var(--paper); /* paper shows through iOS overscroll/safe areas */
}

body {
  font-family: var(--body);
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
  min-height: 100dvh; /* iOS: exclude dynamic browser chrome */
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent; /* no grey flash on tap */
  /* flat dotted-paper texture */
  background-image: radial-gradient(rgba(25, 23, 20, 0.07) 1px, transparent 1px);
  background-size: 22px 22px;
}

h1, h2, h3 { font-family: var(--display); line-height: 1.1; letter-spacing: -0.01em; }

button, a, .chip, label.chip {
  touch-action: manipulation; /* kill the 300ms double-tap-zoom delay */
}
button { font: inherit; cursor: pointer; -webkit-touch-callout: none; }
input, select { font: inherit; }

/* Safe-area aware page padding (notch, home indicator, landscape ears) */
#app {
  max-width: 720px;
  margin: 0 auto;
  padding:
    max(24px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    calc(96px + env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

/* ---------- entry animation ---------- */
.reveal > * { animation: rise 0.45s cubic-bezier(0.2, 0.9, 0.3, 1) both; }
.reveal > *:nth-child(2) { animation-delay: 0.06s; }
.reveal > *:nth-child(3) { animation-delay: 0.12s; }
.reveal > *:nth-child(4) { animation-delay: 0.18s; }
.reveal > *:nth-child(5) { animation-delay: 0.24s; }
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

/* ---------- header ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 28px; gap: 12px;
}
.logo {
  font-family: var(--display); font-weight: 800; font-size: 1.5rem;
  text-decoration: none; color: var(--ink); display: inline-flex; align-items: center; gap: 10px;
}
.logo .mark {
  width: 36px; height: 36px; border-radius: 10px; background: var(--coral);
  border: var(--border); box-shadow: var(--shadow-sm);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--paper); font-size: 1.15rem; transform: rotate(-6deg);
}
.topbar .who { font-size: 0.9rem; color: var(--muted); text-align: right; }
.topbar .who b { color: var(--ink); display: block; }

/* ---------- cards & buttons ---------- */
.card {
  background: var(--card); border: var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--ink); color: var(--paper);
  border: var(--border); border-radius: 999px;
  padding: 10px 20px; font-weight: 700; font-family: var(--display);
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
@media (hover: hover) {
  .btn:hover { transform: translate(-2px, -2px); box-shadow: 5px 5px 0 var(--ink); }
  .iconbtn:hover { color: var(--danger); background: rgba(209, 47, 47, 0.08); }
}
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.btn.coral { background: var(--coral); }
.btn.teal { background: var(--teal); }
.btn.ghost { background: var(--card); color: var(--ink); }
.btn.small { padding: 9px 16px; font-size: 0.9rem; box-shadow: 2px 2px 0 var(--ink); min-height: 40px; }
.btn:disabled { opacity: 0.5; pointer-events: none; }
/* comfortable thumb target on touch */
.btn { min-height: 44px; }

.iconbtn {
  background: none; border: none; color: var(--muted); font-size: 1.1rem;
  min-width: 44px; min-height: 44px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
}
.iconbtn:active { color: var(--danger); background: rgba(209, 47, 47, 0.12); }

/* ---------- forms ---------- */
label.field { display: block; margin-bottom: 14px; font-weight: 500; }
label.field span { display: block; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 6px; color: var(--muted); }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], select {
  width: 100%; padding: 12px 14px; background: var(--paper);
  border: var(--border); border-radius: 10px; color: var(--ink);
  font-size: 16px; /* iOS will not zoom-on-focus at >=16px */
  min-height: 48px;
  -webkit-appearance: none; appearance: none;
}
select {
  /* native chevron is removed by appearance:none — draw our own */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23191714' stroke-width='3'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 40px;
}
input:focus, select:focus { outline: 3px solid var(--sun); outline-offset: 1px; }

.row { display: flex; gap: 12px; }
.row > * { flex: 1; }

/* ---------- auth ---------- */
.auth-wrap { max-width: 420px; margin: 6vh auto 0; }
.auth-hero { text-align: center; margin-bottom: 26px; }
.auth-hero h1 { font-size: clamp(2.4rem, 8vw, 3.4rem); font-weight: 800; }
.auth-hero h1 em { font-style: normal; color: var(--coral); }
.auth-hero p { color: var(--muted); margin-top: 8px; }
.stamp {
  display: inline-block; margin-bottom: 14px; padding: 6px 14px;
  background: var(--sun); border: var(--border); border-radius: 999px;
  font-family: var(--display); font-weight: 600; font-size: 0.85rem;
  transform: rotate(-2deg); box-shadow: var(--shadow-sm);
}
.tabs { display: flex; gap: 0; margin-bottom: -2px; padding: 0 16px; }
.tabs button {
  background: var(--paper); border: var(--border); border-bottom: none;
  border-radius: 12px 12px 0 0; padding: 9px 18px; font-family: var(--display); font-weight: 600;
  color: var(--muted);
}
.tabs button.active { background: var(--card); color: var(--ink); position: relative; z-index: 1; }
.auth-wrap .card { border-top-left-radius: 0; }

/* ---------- trip list ---------- */
.triplist { display: grid; gap: 16px; }
.trip-card {
  display: block; text-decoration: none; color: inherit;
  background: var(--card); border: var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; position: relative; overflow: hidden;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
@media (hover: hover) {
  .trip-card:hover { transform: translate(-2px, -2px); box-shadow: 6px 6px 0 var(--ink); }
}
.trip-card:active { transform: translate(1px, 1px); box-shadow: 2px 2px 0 var(--ink); }
.trip-card::before {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 10px;
  background: var(--accent, var(--teal)); border-right: var(--border);
}
.trip-card h3 { font-size: 1.3rem; margin-left: 12px; }
.trip-card .meta { margin-left: 12px; color: var(--muted); font-size: 0.9rem; margin-top: 4px; }
.trip-card .total {
  position: absolute; right: 18px; top: 50%; transform: translateY(-50%) rotate(2deg);
  font-family: var(--display); font-weight: 800; font-size: 1.1rem;
  background: var(--sun); border: var(--border); padding: 4px 12px; border-radius: 8px;
  box-shadow: 2px 2px 0 var(--ink);
}

.empty { text-align: center; color: var(--muted); padding: 36px 12px; }
.empty .big { font-size: 2.4rem; display: block; margin-bottom: 8px; }

/* ---------- trip detail ---------- */
.trip-head { margin-bottom: 20px; }
.trip-head h1 { font-size: clamp(1.8rem, 6vw, 2.6rem); font-weight: 800; }
.trip-head .sub { color: var(--muted); margin-top: 4px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.code-chip {
  font-family: var(--display); font-weight: 700; letter-spacing: 0.15em;
  background: var(--sky); border: var(--border); border-radius: 8px; padding: 6px 12px;
  cursor: pointer; box-shadow: 2px 2px 0 var(--ink); color: var(--ink); font-size: 0.85rem;
  min-height: 34px;
}
.code-chip:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--ink); }
.back { color: var(--muted); text-decoration: none; font-weight: 500; }
.back:hover { color: var(--ink); }

.section-title {
  font-family: var(--display); font-weight: 800; font-size: 1.05rem;
  text-transform: uppercase; letter-spacing: 0.1em; margin: 26px 0 12px;
  display: flex; align-items: center; gap: 10px;
}
.section-title::after { content: ""; flex: 1; border-top: 2px dashed var(--ink); opacity: 0.25; }

/* balances */
.balances { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.balance {
  border: var(--border); border-radius: 12px; padding: 12px 14px;
  background: var(--card); box-shadow: var(--shadow-sm);
}
.balance .name { display: flex; align-items: center; gap: 8px; font-weight: 700; margin-bottom: 6px; }
.balance .amount { font-family: var(--display); font-weight: 800; font-size: 1.25rem; }
.balance.pos .amount { color: var(--teal); }
.balance.neg .amount { color: var(--coral); }
.balance .hint { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

.avatar {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--ink);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.7rem; font-weight: 700; flex: none; color: var(--ink);
}

/* settle up */
.settle {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  border: var(--border); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px;
  background: var(--card); box-shadow: var(--shadow-sm); flex-wrap: wrap;
}
.settle .flow { display: flex; align-items: center; gap: 8px; font-weight: 600; flex-wrap: wrap; }
.settle .arrow { font-family: var(--display); color: var(--coral); font-weight: 800; }
.settle .amt { font-family: var(--display); font-weight: 800; }
.all-square {
  border: var(--border); border-radius: 12px; padding: 16px; text-align: center;
  background: var(--teal); color: var(--paper); font-family: var(--display); font-weight: 700;
  box-shadow: var(--shadow-sm);
}

/* expenses */
.expense {
  display: flex; align-items: center; gap: 12px;
  border: var(--border); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px;
  background: var(--card); box-shadow: var(--shadow-sm);
}
.expense .desc { flex: 1; min-width: 0; }
.expense .desc b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.expense .desc small { color: var(--muted); }
.expense .amt { font-family: var(--display); font-weight: 800; white-space: nowrap; }

/* history */
.history-item { display: flex; gap: 8px; color: var(--muted); font-size: 0.9rem; padding: 6px 2px; }
.history-item b { color: var(--ink); }

/* ---------- modal (bottom sheet on phones) ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(25, 23, 20, 0.45);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50;
  animation: fade 0.18s ease both;
  overscroll-behavior: contain; /* scrolling the sheet doesn't scroll the page */
}
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--card); border: var(--border); border-radius: 18px 18px 0 0;
  border-bottom: none; box-shadow: 0 -4px 0 var(--ink);
  width: 100%; max-width: 560px;
  /* leave room below the action buttons for the iOS home indicator */
  padding: 24px 20px calc(28px + env(safe-area-inset-bottom));
  max-height: 92dvh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  animation: slide 0.25s cubic-bezier(0.2, 0.9, 0.3, 1) both;
}
@keyframes slide { from { transform: translateY(40px); opacity: 0; } }
.modal h2 { margin-bottom: 18px; }
.modal .actions { display: flex; gap: 10px; margin-top: 8px; }
@media (min-width: 600px) {
  .modal-backdrop { align-items: center; }
  .modal {
    border-radius: 18px; border-bottom: var(--border); box-shadow: var(--shadow);
    padding: 24px 20px 28px; max-height: 88dvh;
  }
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: var(--border); border-radius: 999px; padding: 6px 14px;
  background: var(--paper); font-weight: 600; font-size: 0.9rem;
  display: inline-flex; align-items: center; gap: 6px; user-select: none;
}
.chip input { display: none; }
.chip:has(input:checked) { background: var(--sun); box-shadow: 2px 2px 0 var(--ink); }

/* dropzone */
.dropzone {
  border: 2px dashed var(--ink); border-radius: 12px; padding: 16px;
  text-align: center; margin-bottom: 18px; background: var(--paper);
  transition: background 0.15s ease, transform 0.15s ease;
}
.dropzone p { margin-bottom: 10px; }
.dropzone small { color: var(--muted); }
.dropzone.drag { background: var(--sun); transform: scale(1.02); border-style: solid; box-shadow: var(--shadow-sm); }
.dropzone.busy { background: var(--sky); pointer-events: none; }
.dropzone.busy .dz-actions { opacity: 0.4; }
.dz-busy { font-family: var(--display); font-weight: 700; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }
.dz-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* fab — clears the home indicator and landscape notch */
.fab {
  position: fixed; z-index: 40;
  right: calc(20px + env(safe-area-inset-right));
  bottom: calc(24px + env(safe-area-inset-bottom));
  font-size: 1rem; padding: 15px 26px;
}

/* error + toast */
.form-error { color: var(--danger); font-weight: 600; margin-bottom: 12px; min-height: 1.2em; }
#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(120px);
  max-width: calc(100vw - 32px); text-align: center;
  background: var(--ink); color: var(--paper); padding: 10px 22px;
  border-radius: 999px; font-family: var(--display); font-weight: 600;
  border: 2px solid var(--paper); transition: transform 0.25s cubic-bezier(0.2, 0.9, 0.3, 1);
  z-index: 60; pointer-events: none;
}
#toast.show { transform: translateX(-50%) translateY(0); }

.loading { text-align: center; color: var(--muted); padding: 48px 0; font-family: var(--display); }

/* respect reduced-motion preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* tighten layout on small phones */
@media (max-width: 380px) {
  .balances { grid-template-columns: 1fr 1fr; gap: 10px; }
  .trip-card .total { position: static; transform: rotate(2deg); display: inline-block; margin: 8px 0 0 12px; }
  .auth-hero h1 { font-size: clamp(2rem, 12vw, 2.8rem); }
}
