/* UniGOU Motos — Chat de Viajes (DESIGN.md tokens) */
:root {
  color-scheme: light;
  --canvas: #FAF8F4;
  --surface-1: #FFFFFF;
  --surface-2: #121215;
  --surface-3: #F3F1EB;
  --surface-hover: #EAE6DC;

  --accent: #F5A60A;
  --accent-hover: #DC9000;
  --accent-soft: #FEF5DC;
  --accent-border: #E5A00D;
  --accent-ink: #121215;

  --ink: #121215;
  --ink-secondary: #52525B;
  --ink-muted: #71717A;

  --border-subtle: #E5E2DA;
  --border-strong: #C8C3B8;

  --pending: #B45309;
  --pending-soft: #FEF3C7;
  --active: #1D4ED8;
  --active-soft: #DBEAFE;
  --transit: #4338CA;
  --transit-soft: #E0E7FF;
  --success: #15803D;
  --success-soft: #DCFCE7;
  --error: #B91C1C;
  --error-soft: #FEE2E2;

  --font-display: 'Space Grotesk', system-ui, -apple-system, sans-serif;
  --font-body: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;

  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-full: 9999px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  display: flex;
  justify-content: center;
  overflow: hidden;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* App Shell */
.app-shell {
  width: 100%;
  max-width: 560px;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  background: var(--canvas);
  position: relative;
}

@media (min-width: 600px) {
  body {
    background: #F1EEE7;
    padding: 16px;
  }
  .app-shell {
    height: calc(100dvh - 32px);
    border: 1px solid var(--border-subtle);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 12px 36px rgba(18, 18, 21, 0.06);
  }
}

/* Header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border-subtle);
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-avatar {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  overflow: hidden;
  flex-shrink: 0;
  border: 1px solid var(--border-subtle);
}

.brand-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand-meta h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.2;
}

.status-line {
  margin: 2px 0 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.76rem;
  color: var(--ink-secondary);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--surface-1);
  color: var(--ink-secondary);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background-color 140ms ease, color 140ms ease;
}

.icon-btn:hover {
  background: var(--surface-3);
  color: var(--ink);
}

.text-btn {
  height: 34px;
  padding: 0 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--surface-3);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 140ms ease;
}

.text-btn:hover {
  background: var(--surface-hover);
}

/* Step Ribbon */
.step-ribbon {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 8px 14px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border-subtle);
}

.step-pill {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--ink-muted);
  background: var(--surface-3);
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  text-align: center;
  padding: 4px 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background-color 160ms ease, color 160ms ease, border-color 160ms ease;
}

.step-pill.is-active {
  background: var(--accent-soft);
  color: var(--ink);
  border-color: var(--accent-border);
}

.step-pill.is-done {
  background: var(--success-soft);
  color: var(--success);
}

/* Chat Feed */
.chat-feed {
  overflow-y: auto;
  padding: 16px 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.msg-row {
  display: flex;
  flex-direction: column;
  max-width: 88%;
  gap: 4px;
  opacity: 1;
  transform: translateY(0);
  transition: opacity 180ms ease, transform 180ms ease;
}

@starting-style {
  .msg-row {
    opacity: 0;
    transform: translateY(6px);
  }
}

.msg-row.bot {
  align-self: flex-start;
}

.msg-row.user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg-row.card-row {
  max-width: 96%;
  width: 100%;
}

.bubble {
  padding: 11px 14px;
  font-size: 0.92rem;
  line-height: 1.48;
  word-wrap: break-word;
}

.msg-row.bot .bubble {
  background: var(--surface-1);
  color: var(--ink);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) 4px;
}

.msg-row.user .bubble {
  background: var(--surface-2);
  color: #FFFFFF;
  border-radius: var(--radius-lg) var(--radius-lg) 4px var(--radius-lg);
}

.msg-time {
  font-size: 0.68rem;
  color: var(--ink-muted);
  padding: 0 4px;
  font-variant-numeric: tabular-nums;
}

/* Typing indicator */
.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 18px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-muted);
  animation: pulseDot 1s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
  animation-delay: 140ms;
}

.typing-dots span:nth-child(3) {
  animation-delay: 280ms;
}

@keyframes pulseDot {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.85); }
  40% { opacity: 1; transform: scale(1); }
}

/* Interactive Cards inside Chat */
.chat-card {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  container-type: inline-size;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card-eyebrow {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-secondary);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: var(--radius-full);
  font-variant-numeric: tabular-nums;
}

.badge.pending { background: var(--pending-soft); color: var(--pending); }
.badge.active { background: var(--active-soft); color: var(--active); }
.badge.transit { background: var(--transit-soft); color: var(--transit); }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.error { background: var(--error-soft); color: var(--error); }

/* Destination choices */
.choice-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.choice-btn {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--canvas);
  color: var(--ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-family: inherit;
  transition: border-color 140ms ease, background-color 140ms ease;
}

.choice-btn:hover {
  border-color: var(--accent-border);
  background: var(--accent-soft);
}

.choice-btn strong {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
}

.choice-btn span {
  display: block;
  font-size: 0.76rem;
  color: var(--ink-secondary);
  margin-top: 2px;
}

/* GPS Card */
.gps-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-primary,
.btn-secondary,
.btn-outline {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  transition: background-color 140ms ease, border-color 140ms ease, opacity 140ms ease;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border: 1px solid var(--accent-border);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: wait;
}

.btn-secondary {
  background: var(--surface-3);
  color: var(--ink);
  border: 1px solid var(--border-subtle);
  font-weight: 600;
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-hover);
}

.btn-outline {
  background: var(--surface-1);
  color: var(--ink);
  border: 1px solid var(--border-strong);
  font-weight: 600;
}

.btn-outline:hover {
  background: var(--surface-3);
}

.gps-status {
  font-size: 0.8rem;
  color: var(--ink-secondary);
  margin: 0;
}

.gps-status.is-error {
  color: var(--error);
  background: var(--error-soft);
  padding: 8px 10px;
  border-radius: var(--radius-xs);
}

.gps-status.is-warn {
  color: var(--pending);
  background: var(--pending-soft);
  padding: 8px 10px;
  border-radius: var(--radius-xs);
}

/* Interactive Pickup Map (Leaflet) */
.map-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pickup-map {
  width: 100%;
  height: 220px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  overflow: hidden;
  background: var(--surface-3);
  z-index: 1;
}

.map-readout {
  padding: 8px 10px;
  border-radius: var(--radius-xs);
  background: var(--canvas);
  border: 1px solid var(--border-subtle);
  font-size: 0.82rem;
}

.map-readout strong {
  display: block;
  color: var(--ink);
  font-weight: 600;
}

.map-readout small {
  display: block;
  margin-top: 2px;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

.gps-btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* Route Summary & Quote Card */
.route-points {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 12px;
  background: var(--canvas);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}

.route-point {
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: 8px;
  align-items: start;
}

.point-marker {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 5px;
}

.point-marker.origin {
  background: var(--success);
  box-shadow: 0 0 0 3px var(--success-soft);
}

.point-marker.dest {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.route-point small {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.route-point strong {
  display: block;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--ink);
  margin-top: 1px;
}

.quote-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.quote-metric {
  background: var(--surface-3);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}

.quote-metric small {
  display: block;
  font-size: 0.7rem;
  color: var(--ink-secondary);
}

.quote-metric strong {
  display: block;
  margin-top: 2px;
  font-family: var(--font-display);
  font-size: 0.96rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.quote-metric.is-price {
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
}

/* Inline Confirmation Form inside Chat Card */
.confirm-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

@container (min-width: 390px) {
  .form-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink);
}

.field-hint {
  font-size: 0.72rem;
  color: var(--ink-muted);
}

.field input {
  width: 100%;
  height: 40px;
  padding: 0 11px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-strong);
  background: var(--surface-1);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.88rem;
  transition: border-color 140ms ease, background-color 140ms ease;
}

.field input:focus {
  outline: none;
  border-color: var(--ink);
}

.field input:user-invalid,
.field input.user-invalid-fallback {
  border-color: var(--error);
  background: #FFF7F7;
}

.field input:user-valid {
  border-color: var(--success);
}

.field-error {
  display: none;
  font-size: 0.73rem;
  color: var(--error);
  font-weight: 500;
}

.field input:user-invalid + .field-error,
.field input.user-invalid-fallback + .field-error {
  display: block;
}

.payment-pills {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.pay-option {
  position: relative;
}

.pay-option input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}

.pay-option span {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 38px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-subtle);
  background: var(--surface-3);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-secondary);
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease;
}

.pay-option input:checked + span {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--ink);
}

.pay-option input:focus-visible + span {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

/* Dispatch & Driver Card */
.order-code {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.driver-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--active-soft);
  border: 1px solid #BFDBFE;
}

.driver-box strong {
  display: block;
  font-size: 0.9rem;
  color: var(--ink);
}

.driver-box span {
  display: block;
  font-size: 0.78rem;
  color: var(--ink-secondary);
}

.driver-links {
  display: flex;
  gap: 6px;
}

.driver-links a {
  padding: 7px 11px;
  border-radius: var(--radius-xs);
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  color: var(--ink);
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 700;
}

/* Composer & Quick Chips */
.composer-bar {
  background: var(--surface-1);
  border-top: 1px solid var(--border-subtle);
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quick-bar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}

.quick-bar:empty {
  display: none;
}

.quick-bar::-webkit-scrollbar {
  display: none;
}

.chip-btn {
  flex-shrink: 0;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
  background: var(--surface-3);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.79rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 140ms ease, border-color 140ms ease;
}

.chip-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent-border);
}

.composer-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface-3);
  border: 1px solid var(--border-subtle);
  border-radius: 22px;
  padding: 5px 5px 5px 14px;
  transition: border-color 140ms ease, background-color 140ms ease;
}

.composer-form:focus-within {
  border-color: var(--ink);
  background: var(--surface-1);
}

.composer-form textarea {
  flex: 1;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.94rem;
  line-height: 1.4;
  padding: 7px 0;
  resize: none;
  outline: none;
  field-sizing: content;
  height: auto;
  min-block-size: 1.4lh;
  max-block-size: 4lh;
}

.send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 140ms ease, transform 120ms ease;
}

.send-btn:hover {
  background: var(--accent-hover);
}

.send-btn:active {
  transform: scale(0.95);
}

/* Native Dialogs */
dialog {
  width: min(92vw, 420px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 0;
  background: var(--surface-1);
  color: var(--ink);
  box-shadow: 0 20px 48px rgba(18, 18, 21, 0.16);
}

dialog::backdrop {
  background: rgba(18, 18, 21, 0.42);
  backdrop-filter: blur(2px);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.dialog-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
}

.dialog-body {
  padding: 16px;
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--ink-secondary);
}

.help-steps {
  margin: 0 0 14px;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.help-steps strong {
  color: var(--ink);
}

.fare-box {
  background: var(--canvas);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.fare-box-title {
  margin: 0 0 8px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink);
}

.fare-list {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.fare-list > div {
  display: flex;
  justify-content: space-between;
  font-size: 0.84rem;
}

.fare-list dd {
  margin: 0;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

@media (prefers-reduced-motion: reduce) {
  .chat-feed { scroll-behavior: auto; }
  .msg-row { transition: none; }
  .typing-dots span { animation: none; }
}
