:root {
  --brand: #cc2d3b;
  --brand-strong: #b22532;
  --brand-soft: #fdecee;
  --brand-soft-2: #fad6da;
  --ink: #0f172b;
  --ink-2: #101828;
  --slate-900: #1d293d;
  --slate-700: #314158;
  --slate-500: #62748e;
  --slate-400: #90a1b9;
  --slate-300: #cad5e2;
  --slate-200: #e2e8f0;
  --slate-100: #f1f5f9;
  --bg: #f7f8fa;
  --surface: #ffffff;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button { font-family: inherit; }

h1, h2, h3, h4 {
  font-family: 'Plus Jakarta Sans', sans-serif;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 20px;
}

header {
  background: var(--ink);
  color: white;
  padding: 14px 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.25rem;
  font-weight: 700;
  text-decoration: none;
  color: white;
  letter-spacing: -0.01em;
}

.logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--brand);
  color: white;
  font-weight: 800;
  font-size: 1.05rem;
  box-shadow: 0 4px 14px rgba(204,45,59,0.4);
}

.logo-text {
  display: flex;
  flex-direction: column;
  line-height: 1;
}

.logo-by {
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--slate-400);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-top: 3px;
}

nav {
  display: flex;
  gap: 10px;
  align-items: center;
}

.welcome-name {
  opacity: 0.85;
  font-size: 0.9rem;
  color: var(--slate-300);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
  color: white;
  border: 1px solid rgba(255,255,255,0.08);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  font-family: inherit;
  transition: all 0.15s;
  touch-action: manipulation;
}

.account-link:hover {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.18);
}

.account-link.active {
  background: var(--brand);
  border-color: var(--brand);
  box-shadow: 0 4px 14px rgba(204,45,59,0.4);
}

.account-link-icon { font-size: 1rem; }

main {
  padding: 56px 20px 32px;
}

.hidden { display: none !important; }

.auth-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
}

.tab {
  flex: 1;
  padding: 12px;
  border: none;
  background: white;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 500;
  transition: all 0.2s;
}

.tab.active {
  background: var(--ink);
  color: white;
}

.card {
  background: var(--surface);
  border-radius: 14px;
  padding: 26px;
  box-shadow: 0 1px 2px rgba(15,23,43,0.04), 0 8px 24px rgba(15,23,43,0.06);
  margin-bottom: 16px;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
  border: 1px solid var(--slate-200);
}

.card h2, .card h3 {
  margin-bottom: 18px;
  color: var(--ink);
  font-weight: 700;
}

input:not([type="checkbox"]):not([type="radio"]), textarea {
  width: 100%;
  padding: 14px;
  margin-bottom: 12px;
  border: 1px solid var(--slate-200);
  border-radius: 10px;
  font-size: 16px;
  font-family: inherit;
  color: var(--ink);
  background: var(--surface);
  transition: border 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

input::placeholder { color: var(--slate-400); }

input:not([type="checkbox"]):not([type="radio"]):focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(204,45,59,0.12);
}

.btn-primary, .btn-secondary, .btn-danger, .btn-success {
  padding: 14px 20px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  transition: all 0.15s;
  min-height: 44px;
  touch-action: manipulation;
}

.btn-primary {
  background: var(--brand);
  color: white;
  width: 100%;
  box-shadow: 0 1px 2px rgba(15,23,43,0.06), 0 4px 14px rgba(204,45,59,0.25);
}

.btn-primary:hover { background: var(--brand-strong); }

.btn-secondary {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--slate-200);
}

.btn-secondary:hover { background: var(--slate-100); border-color: var(--slate-300); }

.btn-danger {
  background: transparent;
  color: var(--brand);
  border: 1px solid var(--brand-soft-2);
}

.btn-danger:hover { background: var(--brand-soft); }

.btn-success {
  background: var(--ink);
  color: white;
}

.btn-success:hover { background: var(--ink-2); }

.btn-small {
  padding: 10px 14px;
  font-size: 0.85rem;
  width: auto;
  min-height: 38px;
}

.error {
  color: var(--brand);
  margin-top: 8px;
  font-size: 0.9rem;
  min-height: 20px;
}

.info-banner {
  background: var(--surface);
  border-radius: 14px;
  padding: 16px 20px;
  margin-bottom: 20px;
  border: 1px solid var(--slate-200);
  border-left: 4px solid var(--brand);
}

.info-sub {
  font-size: 0.85rem;
  color: var(--slate-500);
  margin-top: 4px;
}

.actions-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

.actions-bar h2 {
  color: var(--ink);
  font-size: 1.4rem;
  letter-spacing: -0.02em;
}

.actions-bar .btn-primary,
.actions-bar .btn-secondary {
  width: auto;
  padding: 10px 18px;
}

.actions-bar-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.archive-week {
  margin-bottom: 28px;
}

.week-header {
  font-size: 1rem;
  color: var(--ink);
  margin-bottom: 12px;
  padding: 12px 16px;
  background: var(--slate-100);
  border-radius: 10px;
  border: 1px solid var(--slate-200);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.week-count {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--slate-500);
  background: var(--surface);
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--slate-200);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-buttons {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.form-buttons button {
  flex: 1;
}

.trip-card {
  background: var(--surface);
  border-radius: 14px;
  padding: 22px;
  margin-bottom: 12px;
  border: 1px solid var(--slate-200);
  box-shadow: 0 1px 2px rgba(15,23,43,0.04);
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}

.trip-card:hover {
  border-color: var(--slate-300);
  box-shadow: 0 1px 2px rgba(15,23,43,0.04), 0 8px 20px rgba(15,23,43,0.06);
}

.trip-route {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.arrow {
  color: var(--brand);
  font-size: 1.3rem;
}

.trip-meta {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  color: var(--slate-500);
  font-size: 0.9rem;
  margin-bottom: 12px;
}

.trip-meta span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.trip-driver {
  font-size: 0.88rem;
  color: var(--slate-500);
  margin-bottom: 12px;
}

.trip-driver strong { color: var(--ink); }

.trip-cost {
  background: var(--slate-100);
  padding: 14px;
  border-radius: 10px;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  border: 1px solid var(--slate-200);
}

.cost-label {
  font-size: 0.82rem;
  color: var(--slate-500);
}

.cost-value {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.02em;
}

.passengers-list {
  font-size: 0.88rem;
  color: var(--slate-500);
  margin-bottom: 12px;
  padding: 10px 14px;
  background: var(--slate-100);
  border-radius: 10px;
  border: 1px solid var(--slate-200);
}

.passengers-list strong {
  color: var(--ink);
}

.trip-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.notes {
  color: var(--slate-700);
  margin-bottom: 12px;
  padding: 10px 14px;
  background: var(--brand-soft);
  border-radius: 10px;
  border-left: 3px solid var(--brand);
  font-size: 0.9rem;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--slate-500);
}

.empty-state h3 { color: var(--ink); margin-bottom: 6px; }

.badge {
  background: var(--ink);
  color: white;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge-grey {
  background: var(--slate-400);
}

.badge-orange {
  background: var(--brand);
}

.badge-direction {
  background: var(--ink);
  color: white;
}

.badge-direction.badge-return {
  background: var(--slate-700);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--slate-100);
  border: 1px solid var(--slate-200);
  border-radius: 10px;
  cursor: pointer;
  margin-bottom: 12px;
  font-size: 0.92rem;
  color: var(--slate-700);
  font-weight: 500;
  user-select: none;
}

.checkbox-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--brand);
  cursor: pointer;
}

.checkbox-row strong {
  color: var(--ink);
  font-weight: 700;
}

.trip-paired { border-left: 3px solid var(--brand); }

.view-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  padding: 5px;
  border-radius: 12px;
  margin-bottom: 18px;
  border: 1px solid var(--slate-200);
}

.view-tab {
  flex: 1;
  padding: 11px 8px;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--slate-500);
  transition: all 0.15s;
  font-family: inherit;
  min-height: 42px;
  touch-action: manipulation;
  white-space: nowrap;
}

.view-tab:hover {
  background: var(--slate-100);
  color: var(--ink);
}

.view-tab.active {
  background: var(--ink);
  color: white;
  box-shadow: 0 2px 6px rgba(15,23,43,0.18);
}

.account-title {
  color: var(--ink);
  margin-bottom: 4px;
  font-size: 1.5rem;
  letter-spacing: -0.02em;
}

.account-intro {
  color: var(--slate-500);
  font-size: 0.9rem;
  margin-bottom: 20px;
}

.account-subtitle {
  color: var(--ink);
  margin: 24px 0 12px;
  font-size: 1.05rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.stat-grid-2 {
  grid-template-columns: repeat(2, 1fr);
}

.stat-card {
  background: var(--surface);
  border-radius: 14px;
  padding: 20px;
  border: 1px solid var(--slate-200);
  border-top: 3px solid var(--slate-300);
}

.stat-highlight {
  border-top-color: var(--brand);
  background: linear-gradient(180deg, var(--brand-soft) 0%, white 60%);
}

.stat-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--slate-500);
  font-weight: 700;
}

.stat-sub {
  font-size: 0.78rem;
  color: var(--slate-400);
  margin-bottom: 10px;
}

.stat-value {
  font-size: 1.85rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 4px;
  letter-spacing: -0.025em;
}

.stat-meta {
  font-size: 0.78rem;
  color: var(--slate-500);
}

.monthly-list {
  background: var(--surface);
  border-radius: 14px;
  padding: 4px 18px;
  border: 1px solid var(--slate-200);
}

.monthly-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 16px;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--slate-100);
  font-size: 0.95rem;
}

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

.monthly-month {
  font-weight: 600;
  color: var(--ink);
}

.monthly-trips {
  font-size: 0.85rem;
  color: var(--slate-500);
}

.monthly-amount {
  font-weight: 700;
  color: var(--brand);
  min-width: 80px;
  text-align: right;
}

.all-time-banner {
  margin-top: 20px;
  padding: 18px 22px;
  background: var(--ink);
  background-image: radial-gradient(circle at 100% 0%, rgba(204,45,59,0.35) 0%, transparent 50%);
  color: white;
  border-radius: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.all-time-banner strong {
  font-size: 1.5rem;
}

.all-time-meta {
  font-size: 0.85rem;
  opacity: 0.85;
}

.balance-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.balance-card {
  background: var(--surface);
  border-radius: 14px;
  padding: 20px;
  border: 1px solid var(--slate-200);
}

.balance-owed {
  border-left: 4px solid var(--brand);
}

.balance-receive {
  border-left: 4px solid var(--ink);
}

.balance-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1rem;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--slate-200);
  color: var(--slate-700);
}

.balance-header strong {
  font-size: 1.4rem;
  color: var(--ink);
  letter-spacing: -0.02em;
}

.balance-list {
  list-style: none;
  padding: 0;
}

.balance-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--slate-100);
  flex-wrap: wrap;
  font-size: 0.92rem;
  color: var(--slate-700);
}

.balance-list li:last-child { border-bottom: none; }

.balance-list .amount {
  font-weight: 700;
  color: var(--ink);
}

.balance-list .btn-small {
  padding: 5px 10px;
  font-size: 0.8rem;
  width: auto;
}

.user-cost {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 0.95rem;
}

.user-cost.owed {
  background: var(--brand-soft);
  color: var(--brand-strong);
  border-left: 3px solid var(--brand);
}

.user-cost.paid {
  background: var(--slate-100);
  color: var(--ink);
  border-left: 3px solid var(--ink);
}

.user-cost strong {
  font-size: 1.15rem;
}

.passengers-list ul {
  list-style: none;
  padding: 6px 0 0;
  margin: 4px 0 0;
}

.passengers-list li {
  padding: 4px 0;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.paid-tag {
  color: var(--ink);
  background: var(--slate-100);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}

.unpaid-tag {
  color: var(--brand-strong);
  background: var(--brand-soft);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}

.btn-link {
  background: none;
  border: none;
  color: var(--brand);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0;
  text-decoration: underline;
  font-family: inherit;
}

.btn-link:hover { color: var(--brand-strong); }

.badge-warn {
  background: var(--brand);
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--slate-500);
  margin-bottom: 4px;
  font-weight: 500;
}

label input {
  margin-top: 4px;
}

@media (max-width: 768px) {
  .container { padding: 0 14px; }
  main { padding: 40px 14px 24px; }

  header {
    padding: 12px 0;
    position: sticky;
    top: 0;
    z-index: 10;
  }

  .welcome-name { display: none; }

  .account-link {
    padding: 8px 10px;
    font-size: 0.82rem;
  }

  .account-link-label { display: none; }
  .account-link-icon { font-size: 1.05rem; }

  .logo { font-size: 1.2rem; }

  nav { gap: 8px; }
  nav span {
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.85rem;
  }

  .card {
    padding: 18px 16px;
    border-radius: 10px;
  }

  .card h2, .card h3 { font-size: 1.1rem; }

  .info-banner {
    padding: 12px 14px;
    font-size: 0.9rem;
    border-radius: 10px;
  }

  .info-sub { font-size: 0.78rem; }

  .actions-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 14px;
  }

  .actions-bar h2 {
    font-size: 1.2rem;
    text-align: left;
  }

  .actions-bar-buttons {
    display: flex;
    gap: 8px;
  }

  .actions-bar .btn-primary,
  .actions-bar .btn-secondary {
    flex: 1;
    width: auto;
    padding: 12px 14px;
    font-size: 0.9rem;
  }

  .grid-2 { grid-template-columns: 1fr; }

  .form-buttons { flex-direction: column; }

  .balance-grid {
    grid-template-columns: 1fr;
    gap: 12px;
    margin-bottom: 18px;
  }

  .balance-card { padding: 14px; }

  .balance-header { font-size: 1rem; }
  .balance-header strong { font-size: 1.25rem; }

  .balance-list li {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 12px 0;
  }

  .balance-list li > span {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
  }

  .balance-list .amount { font-size: 1.05rem; }

  .balance-list .btn-small {
    width: 100%;
    text-align: center;
    padding: 11px 12px;
  }

  .trip-card {
    padding: 16px 14px;
    border-radius: 10px;
  }

  .trip-route {
    font-size: 0.98rem;
    flex-wrap: wrap;
    gap: 8px;
  }

  .trip-meta {
    gap: 10px;
    font-size: 0.85rem;
  }

  .trip-driver { font-size: 0.85rem; }

  .trip-cost { padding: 12px; }
  .cost-label { font-size: 0.8rem; }
  .cost-value { font-size: 1.25rem; }

  .user-cost {
    flex-wrap: wrap;
    gap: 4px;
    font-size: 0.9rem;
    padding: 12px 14px;
  }

  .user-cost span { flex: 1 1 auto; }
  .user-cost strong { font-size: 1.1rem; }

  .trip-actions {
    flex-direction: column;
    gap: 8px;
  }

  .trip-actions button {
    width: 100%;
    text-align: center;
  }

  .passengers-list {
    font-size: 0.85rem;
    padding: 10px 12px;
  }

  .passengers-list li { padding: 6px 0; }

  .week-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    font-size: 0.95rem;
    padding: 12px 14px;
  }

  .auth-tabs { margin-bottom: 12px; }
  .tab { padding: 14px 8px; font-size: 0.95rem; }

  .empty-state { padding: 30px 16px; }
  .empty-state h3 { font-size: 1.1rem; }

  .view-tabs {
    padding: 4px;
    gap: 4px;
    margin-bottom: 14px;
  }

  .view-tab {
    padding: 10px 4px;
    font-size: 0.82rem;
    min-height: 40px;
  }

  .stat-grid,
  .stat-grid-2 {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .stat-card { padding: 14px 16px; }
  .stat-value { font-size: 1.5rem; }

  .monthly-list { padding: 2px 14px; }

  .monthly-row {
    grid-template-columns: 1fr auto;
    gap: 6px;
    padding: 10px 0;
    font-size: 0.9rem;
  }

  .monthly-trips {
    grid-column: 1;
    font-size: 0.78rem;
  }

  .monthly-amount {
    grid-row: 1 / span 2;
    grid-column: 2;
    align-self: center;
  }

  .all-time-banner {
    padding: 14px 16px;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .all-time-banner strong { font-size: 1.4rem; }
}

@media (max-width: 380px) {
  .container { padding: 0 10px; }
  main { padding: 14px 10px; }

  .logo { font-size: 1.1rem; }
  nav span { max-width: 80px; font-size: 0.78rem; }

  .actions-bar h2 { font-size: 1.1rem; }
  .info-banner { font-size: 0.85rem; }
  .trip-route { font-size: 0.92rem; }
  .cost-value { font-size: 1.15rem; }
}
