/* ---------- fonts (self-hosted, Latin + Swedish subset only) ---------- */
@font-face {
  font-family: 'Fraunces';
  font-style: normal;
  font-weight: 500 700;
  font-display: swap;
  src: url('/fonts/fraunces-var.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+2000-206F, U+20AC;
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('/fonts/inter-var.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+2000-206F, U+20AC;
}
@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/plexmono-400.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+2000-206F, U+20AC;
}
@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('/fonts/plexmono-500.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+2000-206F, U+20AC;
}

/* ---------- tokens ---------- */
:root {
  --ink: #14213D;
  --ink-soft: #3A4A6B;
  --paper: #F2F0EC;
  --paper-raised: #FFFFFF;
  --gold: #C9962F;
  --gold-soft: #E9D9B0;
  --line: #D8D3C4;
  --muted: #767267;
  --danger: #B4432E;

  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Inter', -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

[hidden] { display: none !important; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; margin: 0 0 0.4em; color: var(--ink); }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

/* ---------- offline banner ---------- */
.offline-banner {
  position: sticky; top: 0; z-index: 40;
  background: var(--ink);
  color: var(--paper);
  font-size: 13px;
  padding: 6px 14px;
  display: flex; align-items: center; gap: 8px;
  justify-content: center;
}
.offline-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--danger);
  display: inline-block;
}

/* ---------- header ---------- */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px;
  max-width: 760px;
  margin: 0 auto;
  position: sticky; top: 0; z-index: 30;
  background: var(--paper);
}
.header-right { display: flex; align-items: center; gap: 14px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  color: var(--gold);
  font-size: 20px;
  transform: rotate(20deg);
  display: inline-block;
}
.brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 21px;
  letter-spacing: 0.01em;
}
.sync-indicator {
  font-size: 12px; color: var(--muted);
  display: flex; align-items: center; gap: 6px;
}
.spin {
  width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid var(--gold-soft); border-top-color: var(--gold);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.account-btn {
  background: none; border: none; cursor: pointer; padding: 0;
  border-radius: 50%;
}
.account-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--ink); color: var(--gold-soft);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 600; font-size: 15px;
  border: 2px solid var(--gold-soft);
}
.account-btn:hover .account-avatar { border-color: var(--gold); }

.account-menu {
  position: fixed; top: 58px; right: 20px; z-index: 45;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(20,33,61,0.14);
  min-width: 200px;
  padding: 6px;
}
.account-menu-header {
  padding: 10px 12px 8px;
  font-family: var(--font-display); font-weight: 600; font-size: 14px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 4px;
}
.account-menu-item {
  display: block; width: 100%; text-align: left;
  background: none; border: none; cursor: pointer;
  padding: 9px 12px; border-radius: 6px;
  font-size: 13.5px; color: var(--ink-soft);
}
.account-menu-item:hover { background: var(--paper); color: var(--ink); }

/* ---------- login ---------- */
.login-view {
  position: fixed; inset: 0; z-index: 100;
  background: var(--paper);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%; max-width: 360px;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 32px 28px;
}
.login-brand {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  margin-bottom: 26px;
}
.login-brand .brand-mark { font-size: 26px; }
.login-brand .brand-name { font-size: 22px; }
.login-submit { width: 100%; margin-top: 4px; }
.login-divider {
  display: flex; align-items: center; gap: 10px;
  margin: 18px 0; color: var(--muted); font-size: 12px;
}
.login-divider::before, .login-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--line);
}

/* ---------- security panel ---------- */
.security-section {
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}
.security-section:last-child { border-bottom: none; }
.security-section h3 {
  font-size: 14px; font-family: var(--font-body); font-weight: 600;
  margin-bottom: 10px;
}
.security-hint { font-size: 12.5px; color: var(--muted); margin: 0 0 10px; }
.mono-hint { font-family: var(--font-mono); letter-spacing: 0.05em; }
.form-success { color: #3a7a4e; font-size: 13px; margin: -4px 0 12px; }
.passkey-list { list-style: none; padding: 0; margin: 0 0 10px; }
.passkey-list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; font-size: 13px; border-bottom: 1px solid var(--line);
}
.passkey-list li:last-child { border-bottom: none; }
.passkey-remove-btn {
  background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px;
}
.passkey-remove-btn:hover { color: var(--danger); }

.app-main {
  max-width: 760px;
  margin: 0 auto;
  padding: 10px 24px 80px;
}

/* ---------- home / trip list ---------- */
.home-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  margin: 8px 0 20px;
}
.home-toolbar h1 { font-size: 24px; }

.trip-list { display: flex; flex-direction: column; gap: 12px; }

.trip-card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px 18px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.trip-card:hover { border-color: var(--gold); }
.trip-card-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  margin-bottom: 3px;
}
.trip-card-dates { color: var(--ink-soft); font-size: 13px; }
.trip-card-meta {
  text-align: right;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: nowrap;
}
.trip-card-delete {
  background: none; border: none; color: var(--muted);
  font-size: 16px; cursor: pointer; padding: 4px 6px;
}
.trip-card-delete:hover { color: var(--danger); }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
.empty-state .brand-mark { font-size: 34px; display: block; margin-bottom: 10px; color: var(--gold-soft); }

/* ---------- buttons ---------- */
.btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14px;
  padding: 9px 16px;
  border-radius: 7px;
  border: 1px solid transparent;
  cursor: pointer;
}
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-primary:hover { background: #0d182e; }
.btn-ghost { background: transparent; color: var(--ink-soft); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--ink-soft); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-gold { background: var(--gold); color: var(--ink); }
.btn-gold:hover { background: #b9862a; }

/* ---------- trip view ---------- */
.trip-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 6px;
}
.trip-header h1 { font-size: 24px; margin-bottom: 2px; }
.trip-header .dates { color: var(--ink-soft); font-size: 13px; }
.back-link {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--muted); font-size: 13px; margin-bottom: 10px;
}
.back-link:hover { color: var(--ink); }

.wizard-nav {
  display: flex; gap: 8px; align-items: center;
  background: var(--gold-soft);
  border-radius: 8px;
  padding: 10px 14px;
  margin: 14px 0;
  justify-content: space-between;
}
.wizard-nav .wizard-label { font-size: 13px; color: var(--ink-soft); }
.wizard-nav-buttons { display: flex; gap: 8px; }

.day-tabs {
  display: flex; gap: 4px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  margin: 18px 0 18px;
  padding-bottom: 1px;
}
.day-tab {
  flex: 0 0 auto;
  padding: 8px 14px 10px;
  font-size: 13px;
  color: var(--ink-soft);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.day-tab .day-tab-count {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
}
.day-tab.active {
  color: var(--ink);
  border-bottom-color: var(--gold);
  font-weight: 600;
}

.day-empty {
  text-align: center; color: var(--muted);
  padding: 40px 10px;
  font-size: 14px;
}

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

/* ---------- ticket-stub card ---------- */
.stop-card {
  position: relative;
  display: flex;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: visible;
}
.stop-card.pending { border-style: dashed; border-color: var(--gold); }

.stop-stub {
  flex: 0 0 76px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px;
  padding: 14px 6px;
  border-right: 2px dashed var(--line);
  position: relative;
}
.stop-stub::before, .stop-stub::after {
  content: '';
  position: absolute;
  right: -8px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--paper);
  border: 1px solid var(--line);
}
.stop-stub::before { top: -9px; }
.stop-stub::after { bottom: -9px; }

.stop-icon { font-size: 20px; color: var(--gold); }
.stop-time { font-family: var(--font-mono); font-size: 12px; color: var(--ink-soft); }

.stop-main {
  flex: 1;
  padding: 14px 16px;
  min-width: 0;
}
.stop-top-row {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
}
.stop-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
}
.stop-route {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--ink-soft);
  margin-top: 2px;
}
.stop-tags {
  display: flex; gap: 6px; flex-wrap: wrap;
  margin-top: 8px;
}
.stop-tag {
  background: var(--gold-soft);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 4px;
}
.stop-notes {
  margin-top: 8px;
  color: var(--ink-soft);
  font-size: 13px;
}
.stop-pending-badge {
  font-size: 11px;
  color: var(--gold);
  font-weight: 600;
  display: inline-flex; align-items: center; gap: 4px;
  margin-top: 8px;
}
.stop-pending-badge .spin { border-color: var(--gold-soft); border-top-color: var(--gold); }

.stop-actions {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 8px;
  border-left: 1px solid var(--line);
}
.stop-actions button {
  background: none; border: none; cursor: pointer;
  color: var(--muted);
  font-size: 14px;
  padding: 4px;
  line-height: 1;
}
.stop-actions button:hover { color: var(--ink); }
.stop-actions button:disabled { opacity: 0.3; cursor: default; }
.stop-actions button.attach-btn { color: var(--gold); font-size: 16px; }

.add-stop-btn {
  align-self: flex-start;
  margin-top: 4px;
}

/* ---------- modal / trip form ---------- */
.modal-overlay, .attachment-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20, 33, 61, 0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--paper-raised);
  border-radius: 12px;
  padding: 24px;
  width: 100%; max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
}
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; font-size: 13px; color: var(--ink-soft); }
.field em { font-style: normal; color: var(--muted); }
.field input, .field select, .field textarea {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px 10px;
  background: var(--paper);
  color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--gold);
}
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.form-error { color: var(--danger); font-size: 13px; margin: -4px 0 12px; }
.modal-actions {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 8px;
}
.modal-actions-right { display: flex; gap: 8px; margin-left: auto; }
.file-existing { font-size: 12px; color: var(--muted); display: block; margin-top: 4px; }

/* ---------- slide-over panel ---------- */
.panel-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20, 33, 61, 0.45);
  display: flex; justify-content: flex-end;
}
.panel {
  background: var(--paper-raised);
  width: 100%; max-width: 420px;
  height: 100%;
  overflow-y: auto;
  padding: 22px 22px 30px;
  box-shadow: -8px 0 24px rgba(20,33,61,0.12);
}
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.icon-btn {
  background: none; border: none; cursor: pointer;
  font-size: 15px; color: var(--muted); padding: 4px 8px;
}
.icon-btn:hover { color: var(--ink); }

/* ---------- attachment viewer ---------- */
.attachment-modal {
  position: relative;
  background: var(--ink);
  width: 100%; max-width: 900px; height: 90vh;
  border-radius: 10px;
  overflow: hidden;
  display: flex;
}
.attachment-body { flex: 1; display: flex; align-items: center; justify-content: center; }
.attachment-body iframe { width: 100%; height: 100%; border: none; background: #fff; }
.attachment-body img { max-width: 100%; max-height: 100%; object-fit: contain; }
.attachment-close {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  background: rgba(255,255,255,0.9); border-radius: 50%; color: var(--ink);
}

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--paper);
  padding: 10px 18px; border-radius: 8px; font-size: 13px;
  z-index: 60;
}

@media (max-width: 480px) {
  .app-header, .app-main { padding-left: 16px; padding-right: 16px; }
  .field-row { flex-direction: column; gap: 0; }
  .panel { max-width: 100%; }
}
