:root {
  --primary: #1d4ed8;
  --primary-dark: #1e3a8a;
  --primary-light: #eff4ff;
  --accent: #f59e0b;
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-muted: #f1f5f9;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --whatsapp: #25d366;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.1);
  --tab-h: 62px;
  --font: "Inter", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-layout {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}

.app-header-inner {
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  box-sizing: border-box;
}

.app-header-brand {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--primary);
  text-decoration: none;
  white-space: nowrap;
}

.app-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.lang-switch {
  display: inline-flex;
  gap: 4px;
  padding: 3px;
  background: var(--surface-muted);
  border-radius: 10px;
}

.lang-switch button {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 6px 9px;
  border-radius: 8px;
  cursor: pointer;
}

.lang-switch button.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow);
}

.app-header-back {
  display: none;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  white-space: nowrap;
}

.app-header-back:hover {
  color: var(--primary);
  border-color: var(--primary);
}

.app-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

.app-main {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.app-root {
  padding: 16px 16px calc(var(--tab-h) + 16px);
  max-width: 720px;
  margin: 0 auto;
  -webkit-overflow-scrolling: touch;
}

.app-root.no-tabs {
  padding-bottom: 16px;
}

body.auth-screen {
  background: linear-gradient(180deg, #dbeafe 0%, var(--bg) 280px);
}

body.auth-screen .app-main {
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

body.auth-screen .app-root {
  width: 100%;
  max-width: 480px;
  padding: 24px 16px 48px;
}

.auth-panel {
  width: 100%;
}

.auth-panel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 24px;
  box-shadow: var(--shadow-md);
}

.auth-panel-lead {
  margin: 0 0 20px;
  text-align: center;
  color: var(--text-muted);
  line-height: 1.5;
  font-size: 0.95rem;
}

.auth-panel-title {
  margin: 0 0 6px;
  font-size: 1.35rem;
  font-weight: 800;
  text-align: center;
}

.auth-panel-subtitle {
  margin: 0 0 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.auth-segmented {
  margin-bottom: 20px;
}

.auth-switch {
  margin: 18px 0 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.auth-switch-link {
  border: none;
  background: none;
  color: var(--primary);
  font-weight: 700;
  cursor: pointer;
  padding: 0;
  margin-left: 4px;
}

#auth-form .field:last-of-type {
  margin-bottom: 18px;
}

.tab-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--tab-h);
  background: var(--surface);
  border-top: 1px solid var(--border-light);
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  z-index: 30;
}

.tab-bar.hidden {
  display: none;
}

.tab-btn {
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 4px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
}

.tab-btn.active {
  color: var(--primary);
}

.tab-btn .icon {
  font-size: 22px;
  line-height: 1;
}

.screen-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding-top: 8px;
}

.screen-title {
  font-size: 1.35rem;
  font-weight: 700;
  margin: 0;
}

.screen-subtitle {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.back-btn {
  border: none;
  background: var(--surface);
  width: 40px;
  height: 40px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  cursor: pointer;
  font-size: 1.2rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-muted { background: var(--surface-muted); color: var(--text-muted); }
.badge-outline { border: 1px solid var(--border); color: var(--text-muted); background: transparent; }
.badge-warning { background: var(--warning-bg); color: var(--warning); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: var(--surface-muted); color: var(--text); }
.btn-whatsapp { background: var(--whatsapp); color: #fff; }
.btn-outline-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger-bg); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.input,
.select,
.textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--surface);
  color: var(--text);
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: 2px solid rgba(29, 78, 216, 0.2);
  border-color: var(--primary);
}

.label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.field {
  margin-bottom: 14px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface-muted);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}

.segmented button {
  border: none;
  background: transparent;
  border-radius: 10px;
  padding: 10px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

.segmented button.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow);
}

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

.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 600;
  color: var(--text-muted);
}

.chip.active {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.empty-state .icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

.route-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

.route-arrow {
  color: var(--text-subtle);
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 12px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  border-top: 1px solid var(--border-light);
  border-bottom: 1px solid var(--border-light);
  padding: 12px 0;
  margin: 12px 0;
}

.detail-grid .detail-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 600;
}

.detail-grid .detail-value {
  font-size: 0.9rem;
  font-weight: 500;
}

.tabs-inline {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.tabs-inline button {
  border: none;
  background: transparent;
  padding: 14px 8px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  position: relative;
}

.tabs-inline button.active {
  color: var(--primary);
}

.tabs-inline button.active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: var(--primary);
}

.counts-row {
  text-align: center;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 12px;
}

.section-route {
  color: var(--primary);
  font-weight: 700;
  margin: 16px 0 8px;
}

.stats-card {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.stat-box {
  background: var(--primary-light);
  border-radius: 12px;
  padding: 12px;
  text-align: center;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--primary);
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
}

.fab {
  position: fixed;
  right: 24px;
  bottom: calc(var(--tab-h) + 20px);
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 14px 18px;
  font-weight: 700;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  z-index: 10;
}

.language-grid {
  display: grid;
  gap: 10px;
  margin-top: 24px;
}

.lang-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 14px;
  padding: 16px;
  text-align: left;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.lang-btn:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.auth-brand {
  text-align: center;
  margin: 24px 0 20px;
}

.auth-brand h1 {
  margin: 0;
  font-size: 2rem;
  color: var(--primary);
}

.auth-brand p {
  margin: 8px 0 0;
  color: var(--text-muted);
}

.profile-header {
  display: flex;
  align-items: center;
  gap: 14px;
}

.avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1.2rem;
}

.profile-name {
  font-size: 1.1rem;
  font-weight: 700;
}

.profile-phone {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.row-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
}

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

.plan-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 10px;
  cursor: pointer;
}

.plan-card.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

.plan-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.radio {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: inline-grid;
  place-items: center;
}

.plan-card.selected .radio {
  border-color: var(--primary);
}

.radio::after {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: transparent;
}

.plan-card.selected .radio::after {
  background: var(--primary);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #0f172a;
  color: #fff;
  padding: 12px 18px;
  border-radius: 12px;
  font-weight: 600;
  z-index: 100;
  max-width: 90vw;
}

.toast.hidden {
  display: none;
}

.hidden {
  display: none !important;
}

@media (min-width: 768px) {
  .app-header-inner {
    padding: 14px 28px;
  }

  .app-header-brand {
    font-size: 1.25rem;
  }

  .app-header-back {
    display: inline-flex;
    align-items: center;
  }

  .app-body.has-nav {
    flex-direction: row;
    align-items: flex-start;
    gap: 24px;
    max-width: 1180px;
    width: 100%;
    margin: 0 auto;
    padding: 24px 28px 32px;
    box-sizing: border-box;
  }

  .app-body:not(.has-nav) {
    max-width: none;
    padding: 0;
  }

  body.auth-screen .app-root {
    padding: 40px 16px 64px;
  }

  .auth-panel-card {
    padding: 32px 28px;
  }

  .app-body.has-nav .tab-bar {
    position: sticky;
    top: 76px;
    bottom: auto;
    left: auto;
    right: auto;
    width: 232px;
    height: auto;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    align-self: flex-start;
  }

  .tab-btn {
    flex-direction: row;
    justify-content: flex-start;
    padding: 12px 14px;
    font-size: 0.9rem;
    gap: 10px;
    border-radius: 10px;
  }

  .tab-btn.active {
    background: var(--primary-light);
  }

  .app-body.has-nav .app-main {
    flex: 1;
    min-width: 0;
  }

  .app-body.has-nav .app-root {
    max-width: none;
    margin: 0;
    padding: 0 0 24px;
  }

  .app-body.has-nav .app-root.no-tabs {
    padding-bottom: 0;
  }

  .fab {
    right: 28px;
    bottom: 32px;
  }

  .screen-title {
    font-size: 1.6rem;
  }

  .stats-card {
    max-width: 420px;
  }

  .detail-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .profile-back-site {
    display: none;
  }
}

@media (max-width: 767px) {
  .app-header-back {
    display: none;
  }
}
