/* ---------- Design tokens ---------- */
:root {
  --ink: #1B2430;
  --ink-soft: #4A5568;
  --ink-faint: #8B93A1;
  --paper: #F3EEE4;
  --paper-raised: #FFFFFF;
  --teal: #1F6F63;
  --teal-dark: #164F46;
  --teal-tint: rgba(31,111,99,0.08);
  --rust: #C1592F;
  --rust-dark: #A6481F;
  --gold: #D9A441;
  --line: #E4DECF;
  --line-soft: #ECE7DA;
  --danger-bg: #F7E2DC;
  --danger-ink: #9E3A1D;

  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  --shadow-sm: 0 1px 2px rgba(27,36,48,0.05), 0 1px 1px rgba(27,36,48,0.04);
  --shadow-md: 0 4px 10px rgba(27,36,48,0.07), 0 1px 3px rgba(27,36,48,0.06);
  --shadow-lg: 0 12px 28px rgba(27,36,48,0.14), 0 2px 6px rgba(27,36,48,0.08);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--ink);
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

h1, h2 { font-family: var(--font-display); margin: 0; }

button {
  font-family: var(--font-body);
  cursor: pointer;
  transition: transform 0.12s var(--ease), opacity 0.12s var(--ease), background-color 0.15s var(--ease);
}
button:active { transform: scale(0.97); }

input, select {
  font-family: var(--font-body);
  font-size: 16px;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

input:focus, select:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-tint);
}

::selection { background: var(--gold); color: var(--ink); }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Trip list screen ---------- */

.brand-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 32px 20px 22px;
}

.brand-mark {
  font-size: 22px;
  color: var(--teal);
  filter: drop-shadow(0 1px 1px rgba(31,111,99,0.15));
}

.brand-header h1 {
  font-size: 23px;
  font-weight: 600;
  letter-spacing: -0.015em;
  flex: 1;
}

.text-link-btn {
  background: none;
  border: none;
  color: var(--teal);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 8px;
}

.text-link-btn:active { background: var(--teal-tint); }

.setup-copy {
  color: rgba(243,238,228,0.72);
  font-size: 14px;
  line-height: 1.6;
  margin: -4px 0 18px;
}

.trip-list-main {
  padding: 4px 20px 40px;
  max-width: 560px;
  margin: 0 auto;
}

.trip-card {
  background: var(--paper-raised);
  border-radius: 16px;
  padding: 18px 20px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--line-soft);
  cursor: pointer;
  transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease), border-color 0.15s var(--ease);
}

.trip-card:hover { box-shadow: var(--shadow-md); border-color: var(--line); }
.trip-card:active { transform: scale(0.98); box-shadow: var(--shadow-sm); }

.trip-card h3 {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  margin: 0 0 5px;
  letter-spacing: -0.01em;
}

.trip-card .trip-card-dates {
  font-size: 12.5px;
  color: var(--ink-soft);
  font-family: var(--font-mono);
  letter-spacing: -0.01em;
}

.new-trip-card {
  background: linear-gradient(165deg, var(--ink) 0%, #232E3D 100%);
  border-radius: 20px;
  padding: 26px 22px;
  margin-top: 22px;
  box-shadow: var(--shadow-lg);
}

.new-trip-card h2 {
  color: var(--paper);
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
  letter-spacing: -0.01em;
}

.new-trip-card input {
  width: 100%;
  padding: 13px 14px;
  border-radius: 11px;
  border: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 10px;
  background: rgba(255,255,255,0.08);
  color: var(--paper);
}

.new-trip-card input:focus {
  border-color: rgba(217,164,65,0.5);
  box-shadow: 0 0 0 3px rgba(217,164,65,0.12);
}

.new-trip-card input::placeholder { color: rgba(243,238,228,0.42); }
.new-trip-card input[type="date"] { color-scheme: dark; }

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

.date-row span { color: rgba(243,238,228,0.4); }
.date-row input { margin-bottom: 0; }

.btn-primary {
  width: 100%;
  padding: 14px;
  border-radius: 11px;
  border: none;
  background: var(--teal);
  color: white;
  font-size: 15px;
  font-weight: 600;
  margin-top: 8px;
  box-shadow: 0 2px 8px rgba(31,111,99,0.3);
}

.btn-primary:hover { background: var(--teal-dark); }

.btn-secondary {
  padding: 12px 18px;
  border-radius: 11px;
  border: none;
  background: rgba(27,36,48,0.055);
  color: var(--ink);
  font-weight: 600;
  font-size: 14px;
}

.btn-secondary:hover { background: rgba(27,36,48,0.09); }

.btn-danger {
  padding: 12px 18px;
  border-radius: 11px;
  border: none;
  background: var(--danger-bg);
  color: var(--danger-ink);
  font-weight: 600;
  font-size: 14px;
}

.btn-danger:hover { background: #F2D3C9; }

/* ---------- Trip detail screen ---------- */

.trip-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 16px;
  background: var(--ink);
  color: var(--paper);
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 1px 0 rgba(255,255,255,0.06);
}

.icon-btn {
  background: none;
  border: none;
  color: var(--paper);
  font-size: 20px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:active { background: rgba(255,255,255,0.12); }

.trip-header-info { flex: 1; min-width: 0; }

.trip-header-info h1 {
  font-size: 18px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.01em;
}

.trip-dates {
  font-size: 12px;
  font-family: var(--font-mono);
  color: rgba(243,238,228,0.55);
}

.tab-bar {
  display: flex;
  background: var(--ink);
  padding: 0 12px;
  position: sticky;
  top: 70px;
  z-index: 9;
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  color: rgba(243,238,228,0.5);
  padding: 12px 0 14px;
  font-size: 14px;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  transition: color 0.15s var(--ease), border-color 0.15s var(--ease);
}

.tab-btn.active {
  color: var(--paper);
  border-bottom-color: var(--gold);
}

.trip-main {
  max-width: 560px;
  margin: 0 auto;
  padding: 18px 16px 112px;
}

.tab-panel { display: none; animation: fade-in 0.2s var(--ease); }
.tab-panel.active { display: block; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.import-status {
  text-align: center;
  color: var(--ink-soft);
  font-size: 13px;
  padding: 6px 0;
  min-height: 20px;
}

.empty-state {
  text-align: center;
  color: var(--ink-faint);
  padding: 64px 24px;
  font-size: 14px;
  line-height: 1.6;
}

/* ---------- Ticket stub cards (signature element) ---------- */

.stops-list { display: flex; flex-direction: column; gap: 14px; }

.stop-card {
  display: flex;
  background: var(--paper-raised);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--line-soft);
  position: relative;
  transition: box-shadow 0.15s var(--ease), transform 0.15s var(--ease);
  cursor: pointer;
}

.stop-card:hover { box-shadow: var(--shadow-md); }
.stop-card:active { transform: scale(0.99); }

.stop-stub {
  width: 86px;
  flex-shrink: 0;
  background: linear-gradient(165deg, var(--teal) 0%, var(--teal-dark) 100%);
  color: white;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 6px;
  position: relative;
}

.stop-stub .stub-icon { font-size: 22px; margin-bottom: 4px; filter: drop-shadow(0 1px 1px rgba(0,0,0,0.15)); }
.stop-stub .stub-time {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  text-align: center;
  line-height: 1.3;
}

/* Perforated ticket edge between stub and body */
.stop-stub::after {
  content: "";
  position: absolute;
  right: -1px;
  top: 0;
  bottom: 0;
  width: 0;
  border-right: 2px dashed rgba(255,255,255,0.45);
}

.stop-body {
  flex: 1;
  padding: 14px 16px;
  min-width: 0;
}

.stop-body .stop-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
  margin-bottom: 3px;
  letter-spacing: -0.005em;
  line-height: 1.3;
}

.stop-body .stop-place {
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 9px;
}

.stop-body .stop-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.stop-code {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 8px;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
}

.map-link-btn {
  font-size: 12px;
  font-weight: 600;
  color: var(--teal-dark);
  background: var(--teal-tint);
  border: none;
  border-radius: 20px;
  padding: 5px 12px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: background-color 0.15s var(--ease);
}

.map-link-btn:hover { background: rgba(31,111,99,0.15); }

.review-flag {
  position: absolute;
  top: 10px;
  right: 10px;
  background: var(--gold);
  color: var(--ink);
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(217,164,65,0.5);
}

/* ---------- Expenses ---------- */

.expenses-summary {
  background: linear-gradient(165deg, var(--ink) 0%, #232E3D 100%);
  color: var(--paper);
  border-radius: 16px;
  padding: 22px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-lg);
}

.expenses-summary .total-label {
  font-size: 11.5px;
  color: rgba(243,238,228,0.55);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 600;
}

.expenses-summary .total-amount {
  font-family: var(--font-display);
  font-size: 33px;
  font-weight: 600;
  margin: 5px 0 16px;
  letter-spacing: -0.01em;
}

.category-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.category-chip {
  font-size: 12px;
  background: rgba(255,255,255,0.09);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 20px;
  padding: 5px 12px;
  font-family: var(--font-mono);
}

.expenses-list { display: flex; flex-direction: column; gap: 8px; }

.expense-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--paper-raised);
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  padding: 13px 14px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s var(--ease), transform 0.1s var(--ease);
  cursor: pointer;
}

.expense-row:hover { box-shadow: var(--shadow-md); }
.expense-row:active { transform: scale(0.99); }

.expense-icon {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--paper);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.expense-info { flex: 1; min-width: 0; }
.expense-info .expense-title { font-weight: 600; font-size: 14px; }
.expense-info .expense-sub { font-size: 12px; color: var(--ink-soft); margin-top: 1px; }

.expense-amount {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 14.5px;
}

/* ---------- Checklist ---------- */

.checklist-type-row {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.checklist-type-btn {
  background: var(--paper-raised);
  border: 1px solid var(--line-soft);
  border-radius: 20px;
  padding: 7px 15px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
}

.checklist-type-btn.active {
  background: var(--teal);
  border-color: var(--teal);
  color: white;
  box-shadow: 0 2px 8px rgba(31,111,99,0.3);
}

.checklist-list { display: flex; flex-direction: column; gap: 7px; margin-bottom: 14px; }

.checklist-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--paper-raised);
  border: 1px solid var(--line-soft);
  border-radius: 11px;
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s var(--ease);
  cursor: pointer;
}

.checklist-row:hover { box-shadow: var(--shadow-md); }

.checklist-row .check-circle {
  width: 21px;
  height: 21px;
  border-radius: 50%;
  border: 2px solid var(--line);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease);
}

.checklist-row.done .check-circle {
  background: var(--teal);
  border-color: var(--teal);
  color: white;
}

.checklist-row.done .check-text {
  text-decoration: line-through;
  color: var(--ink-faint);
}

.check-text { flex: 1; font-size: 14px; }

.check-delete {
  background: none;
  border: none;
  color: var(--ink-faint);
  font-size: 16px;
  padding: 4px;
  border-radius: 6px;
}

.check-delete:hover { color: var(--danger-ink); background: var(--danger-bg); }

.checklist-add-row {
  display: flex;
  gap: 8px;
  position: sticky;
  bottom: 16px;
}

.checklist-add-row input {
  flex: 1;
  padding: 13px 14px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--paper-raised);
  box-shadow: var(--shadow-md);
}

/* ---------- FAB ---------- */

.fab {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  padding: 14px 28px;
  border-radius: 999px;
  border: none;
  background: linear-gradient(165deg, var(--rust) 0%, var(--rust-dark) 100%);
  color: white;
  font-size: 15px;
  font-weight: 600;
  box-shadow: 0 8px 20px rgba(193,89,47,0.4), 0 2px 6px rgba(193,89,47,0.25);
  z-index: 20;
  letter-spacing: -0.005em;
}

.fab:active { transform: translateX(-50%) scale(0.96); }

/* ---------- Modals ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(27,36,48,0.55);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-end;
  z-index: 100;
  animation: overlay-in 0.2s var(--ease);
}

@keyframes overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-sheet {
  background: var(--paper-raised);
  width: 100%;
  border-radius: 22px 22px 0 0;
  padding: 26px 24px;
  max-height: 88vh;
  overflow-y: auto;
  padding-bottom: calc(26px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgba(27,36,48,0.2);
  animation: sheet-in 0.25s var(--ease);
}

@keyframes sheet-in {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-sheet h2 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 4px;
  letter-spacing: -0.01em;
}

.modal-sheet label {
  display: block;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 18px;
  margin-bottom: 7px;
}

.modal-sheet input,
.modal-sheet select {
  width: 100%;
  padding: 12px 13px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
}

.modal-sheet select {
  appearance: none;
  -webkit-appearance: none;
  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='%234A5568' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 38px;
}

.extracted-fields {
  margin-top: 18px;
  background: var(--paper);
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  padding: 4px 14px;
}

.field-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 13px;
  padding: 8px 0;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--line-soft);
}

.field-row:last-child { border-bottom: none; }

.field-row .field-value {
  font-family: var(--font-mono);
  color: var(--ink);
  text-align: right;
  word-break: break-word;
}

.modal-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 28px;
  gap: 8px;
}

.modal-actions-right { display: flex; gap: 8px; }
