/* Minimal estilo inspirado en Microsoft Forms */
:root {
  --bg: #f5f6fa;
  --card-bg: #fff;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-contrast: #fff;
  --success: #059669;
  --border: #e5e7eb;
}
* { box-sizing: border-box; }
body { font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif; margin: 0; background: var(--bg); color: var(--text); }
.container { max-width: 960px; margin: 0 auto; padding: 16px; }
.app-header { background: var(--card-bg); border-bottom: 1px solid var(--border); padding: 12px 16px; position: relative; top: auto; z-index: 1; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.brand-logo { height: 32px; width: auto; object-fit: contain; }
.label { display: flex; align-items: center; gap: 8px; }
.info-btn { border: none; background: var(--primary); color: var(--primary-contrast); border-radius: 50%; width: 24px; height: 24px; font-weight: 600; cursor: pointer; line-height: 24px; text-align: center; }

.modal { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,0.4); z-index: 100; }
.modal.hidden { display: none; }
.modal-content { background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; padding: 16px; max-width: 640px; width: 92%; box-shadow: 0 4px 16px rgba(0,0,0,0.2); }
.modal-title { margin: 0 0 8px 0; font-size: 1.1rem; }
.modal-body { color: var(--text); line-height: 1.5; font-size: 0.95rem; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }

@media (max-width: 480px) {
  .brand-logo { height: 28px; }
  .card-title { font-size: 1.1rem; }
  .modal-content { width: 96%; padding: 14px; }
  .modal-body { font-size: 0.95rem; }
}
.card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; padding: 20px; box-shadow: 0 1px 2px rgba(0,0,0,0.04); }
.card-title { margin: 0 0 8px 0; font-size: 1.25rem; }
.card-header { display: flex; justify-content: space-between; align-items: baseline; }
.muted { color: var(--muted); }
.hint { margin-top: 10px; font-size: 0.9rem; }

.form-grid { display: grid; gap: 12px; }
.form-row { display: grid; gap: 6px; }
label { font-weight: 500; }
input[type="text"], input[type="date"], input[type="number"], select, textarea { padding: 10px; border: 1px solid var(--border); border-radius: 8px; width: 100%; }
input.locked { background: #f3f4f6; color: var(--muted); }

.btn { padding: 10px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--card-bg); cursor: pointer; }
.btn.primary { background: var(--primary); color: var(--primary-contrast); border-color: var(--primary); }
.btn.success { background: var(--success); color: #fff; border-color: var(--success); }
.btn.disabled, .btn[aria-disabled="true"] { opacity: 0.6; pointer-events: none; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

.survey-root { display: grid; gap: 16px; }
.field { padding: 12px; border: 1px dashed var(--border); border-radius: 8px; overflow: auto; }
.field[data-field-key="barrio"] { overflow: visible; }
.field .label { font-weight: 600; margin-bottom: 6px; }
.field .note { font-size: 0.85rem; color: var(--muted); }
.options { display: flex; gap: 8px; flex-wrap: wrap; }
.option-item { display: flex; align-items: center; gap: 6px; transition: max-height 220ms ease, opacity 220ms ease; overflow: hidden; }
.option-item.option-hidden { max-height: 0; opacity: 0; pointer-events: none; margin-top: 0; margin-bottom: 0; }
.option-item.option-visible { opacity: 1; }

/* Toast notifications */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #28a745;
    color: white;
    padding: 12px 20px;
    border-radius: 4px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    z-index: 1000;
    opacity: 0;
    transform: translateX(100%);
    transition: all 0.3s ease;
}

.toast.show {
    opacity: 1;
    transform: translateX(0);
}

.toast.error {
    background: #dc3545;
}

/* Conditional field animations */
.field-group {
    transition: opacity 0.3s ease, max-height 0.3s ease;
    overflow: hidden;
}

.field-group[data-hidden="true"] {
    opacity: 0;
    max-height: 0;
    margin: 0;
    padding: 0;
}

/* Success message styling */
.success-message {
    text-align: center;
    padding: 40px 20px;
    max-width: 500px;
    margin: 0 auto;
}

.success-icon {
    font-size: 4rem;
    color: #28a745;
    margin-bottom: 20px;
    display: block;
}

.success-message h2 {
    color: #28a745;
    margin-bottom: 15px;
}

.success-message p {
    margin-bottom: 10px;
    color: #666;
}

.response-id {
    font-family: monospace;
    background: #f8f9fa;
    padding: 8px 12px;
    border-radius: 4px;
    border: 1px solid #dee2e6;
    display: inline-block;
    margin: 15px 0;
}

.success-actions {
    margin-top: 30px;
}

.success-actions .btn {
    margin: 0 10px;
}

/* Loading state for buttons */
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Improved field visibility transitions */
.field-container {
    transition: all 0.3s ease-in-out;
}

.field-container.hidden {
    opacity: 0;
    max-height: 0;
    overflow: hidden;
    margin: 0;
    padding: 0;
}

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.3); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; }
.hidden { display: none; }
.spinner { width: 28px; height: 28px; border: 3px solid #fff; border-top-color: var(--primary); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Responsive */
@media (max-width: 640px) {
  .container { padding: 12px; }
  .card { padding: 16px; }
  .actions { flex-direction: column; align-items: stretch; }
}

/* Matriz (campo 2) horizontal */
.matrix-scroll {

}
.matrix-scroll::-webkit-scrollbar { display: none; } /* WebKit */
.matrix { display: grid; gap: 8px; width: max-content; }
.matrix-header, .matrix-row {
  display: grid;
  grid-template-columns: minmax(160px, 2fr) repeat(var(--scale-cols), 1fr);
  column-gap: 8px;
  align-items: center;
}
.matrix-header > div { font-weight: 600; text-align: center; }
.matrix-header > div:first-child { visibility: hidden; }
.matrix-row > div { display: flex; justify-content: center; }
.matrix-row > div:first-child { justify-content: flex-start; }
.matrix-row input[type="radio"] { margin: 0 auto; }

/* --- Acordeón móvil para matrices --- */
@media (max-width: 768px) {
  .matrix-scroll { display: none; }
  .matrix-accordion { display: grid; gap: 8px; }
  .accordion-toggle-all { margin-bottom: 8px; }
  .accordion-section { border: 1px solid #e5e7eb; border-radius: 8px; background: #fff; overflow: hidden; }
  .accordion-header { width: 100%; display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; background: #f9fafb; border: none; cursor: pointer; }
  .accordion-title { font-weight: 600; }
  .accordion-icon { font-size: 1rem; color: #374151; }
  .accordion-content { max-height: 0; overflow: auto; transition: max-height 0.25s ease; padding: 0 12px; }
  .accordion-content.open { padding: 8px 12px; }
  .accordion-option { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed #eee; }
  .accordion-option:last-child { border-bottom: none; }
  .option-label { font-size: 0.95rem; color: #111827; }
}

@media (min-width: 769px) {
  .matrix-accordion { display: none; }
}

/* Grupo de confirmación de datos (campo 1.1) */
.data-confirmation-group { border: 1px solid #e5e7eb; border-radius: 8px; padding: 12px; background: #fafafa; }
.data-fields-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
.data-fields-grid label { font-weight: 600; margin-bottom: 4px; display: block; }
.data-fields-grid input[readonly] { background: #f3f4f6; color: #6b7280; }
.confirmation-actions { display: flex; gap: 10px; margin-top: 10px; }

@media (min-width: 640px) {
  .data-fields-grid { grid-template-columns: 1fr 1fr; }
}

/* Opciones en línea para radios y checkboxes */
.options { display: flex; flex-wrap: wrap; gap: 10px; }
.option-item { display: inline-flex; align-items: center; gap: 6px; transition: max-height 220ms ease, opacity 220ms ease; overflow: hidden; }
.option-item.option-hidden { max-height: 0; opacity: 0; pointer-events: none; margin-top: 0; margin-bottom: 0; }
.option-item.option-visible { opacity: 1; }
.combo { position: relative; max-width: 480px; }
.combo-toggle { width: 100%; text-align: left; padding: 8px 10px; border: 1px solid #ccc; border-radius: 6px; background: #fff; cursor: pointer; }
.combo-toggle:disabled { color: #777; background: #f4f4f4; cursor: not-allowed; }
.combo-panel { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid #ddd; border-radius: 6px; box-shadow: 0 6px 20px rgba(0,0,0,0.12); padding: 8px; max-height: 280px; overflow: auto; display: none; z-index: 10; }
.combo-panel.open { display: block; }
.combo-search { width: 100%; padding: 8px 10px; border: 1px solid #ddd; border-radius: 6px; margin-bottom: 8px; }
.combo-list { display: grid; grid-template-columns: 1fr; gap: 4px; }
.combo-item { display: block; width: 100%; text-align: left; padding: 8px 10px; border: none; background: #f9fafb; border-radius: 6px; cursor: pointer; }
.combo-item:hover { background: #eef2ff; }
.combo-item.selected { background: #e0e7ff; }

/* Component library additions */
:root {
  --brand-1: #6a5af9;
  --brand-2: #8a5cf6;
  --brand-3: #23c6ea;
  --brand-4: #1fb6ff;
  --danger: #ef4444;
  --warning: #f59e0b;
}

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }
.btn.icon { padding-left: 12px; }
.btn.gradient {
  background: linear-gradient(135deg, var(--brand-1), #5636f5);
  color: #fff; border-color: transparent; box-shadow: 0 6px 20px rgba(106,90,249,0.35);
}
.btn.gradient-teal { background: linear-gradient(135deg, var(--brand-3), #0ea5e9); color:#fff; border-color: transparent; }
.btn.outline { background: transparent; color: var(--brand-1); border-color: var(--brand-1); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.round { border-radius: 999px; }
.btn.square { border-radius: 12px; }
.btn:focus-visible { outline: 3px solid rgba(37,99,235,0.35); outline-offset: 2px; }

/* Toggle options (pill radios) */
.toggle-group { display: flex; gap: 8px; flex-wrap: wrap; }
.toggle-option { padding: 10px 14px; border: 1px solid var(--border); border-radius: 999px; cursor: pointer; background: #fff; color: var(--text); }
.toggle-option[aria-pressed="true"], .toggle-option.active { background: #eef2ff; border-color: #c7d2fe; color: #4338ca; box-shadow: inset 0 0 0 2px #a5b4fc; }
.toggle-option:focus-visible { outline: 3px solid rgba(165,180,252,0.6); }

/* Inputs */
.input { padding: 12px; border: 1.5px solid var(--border); border-radius: 12px; background:#fff; }
.input:focus { border-color: #a5b4fc; box-shadow: 0 0 0 4px rgba(165,180,252,0.35); outline: none; }
.input.error { border-color: var(--danger); box-shadow: 0 0 0 4px rgba(239,68,68,0.25); }
.input.success { border-color: #10b981; box-shadow: 0 0 0 4px rgba(16,185,129,0.25); }
.input.with-icon { padding-right: 40px; position: relative; }
.input-icon { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: #9ca3af; }

/* Slider */
input[type="range"].slider { -webkit-appearance: none; width: 100%; height: 6px; border-radius: 6px; background: #e5e7eb; outline: none; }
input[type="range"].slider::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 20px; height: 20px; border-radius: 50%; background: var(--brand-1); box-shadow: 0 2px 8px rgba(106,90,249,0.4); cursor: pointer; }
input[type="range"].slider::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; background: var(--brand-1); box-shadow: 0 2px 8px rgba(106,90,249,0.4); cursor: pointer; }
.slider-labels { display: flex; justify-content: space-between; font-size: 0.85rem; color: var(--muted); margin-top: 6px; }

/* Stars rating */
.stars { display: inline-flex; gap: 8px; align-items: center; }
.star { width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border); display: grid; place-items: center; cursor: pointer; background: #fff; color: #9ca3af; }
.star[aria-pressed="true"], .star.active { color: #f59e0b; background: #fff7ed; border-color: #fbbf24; }
.star:hover { color: #f59e0b; }
.stars.sm .star { width: 28px; height: 28px; }
.stars.lg .star { width: 44px; height: 44px; }

/* Other components: alerts */
.alert { display:flex; align-items:center; gap:10px; padding:12px 16px; border-radius: 12px; color: #fff; }
.alert.info { background: linear-gradient(135deg, #60a5fa, #818cf8); }
.alert.success { background: linear-gradient(135deg, #34d399, #10b981); }
.alert.warning { background: linear-gradient(135deg, #f59e0b, #f97316); }
.alert .close { margin-left:auto; cursor:pointer; opacity:0.9; }

/* Responsive tweaks for components */
@media (max-width: 640px) {
  .toggle-group { gap: 6px; }
  .star { width: 32px; height: 32px; }
  .btn { padding: 10px 12px; }
}

/* Hero header */
.hero-header { position: sticky; top: 0; z-index: 8; border-radius: 16px; overflow: hidden; margin-bottom: 16px; transition: box-shadow 0.3s ease, transform 0.3s ease, padding 0.3s ease; }
.hero-bg { position: absolute; inset: 0; background: radial-gradient(1000px 300px at 10% 10%, rgba(106,90,249,0.25), transparent), linear-gradient(135deg, var(--brand-1), var(--brand-4)); transition: filter 0.3s ease, opacity 0.3s ease; }
.hero-content { position: relative; padding: 20px; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 16px; color: #fff; transition: padding 0.3s ease, transform 0.3s ease; }
.hero-back { background: rgba(255,255,255,0.2); border: 1px solid rgba(255,255,255,0.3); color: #fff; border-radius: 999px; padding: 8px 12px; cursor: pointer; }
.hero-title h1 { margin: 0; font-size: 1.25rem; color: #fff; }
.hero-title .muted { color: rgba(255,255,255,0.85); }
.progress-line { height: 6px; border-radius: 999px; background: rgba(255,255,255,0.3); margin-top: 8px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: #fff; border-radius: inherit; transition: width 0.3s ease; }
.progress-text { font-size: 0.85rem; color: rgba(255,255,255,0.9); }
.profile-card { background: #fff; color: var(--text); border-radius: 16px; padding: 12px; display:flex; align-items:center; gap: 12px; box-shadow: 0 10px 24px rgba(0,0,0,0.15); transition: box-shadow 0.3s ease, transform 0.3s ease, padding 0.3s ease; }
.avatar { width: 48px; height: 48px; border-radius: 50%; display:grid; place-items:center; font-weight: 700; color:#fff; background: linear-gradient(135deg, var(--brand-2), var(--brand-1)); transition: width 0.2s ease, height 0.2s ease; }
.profile-info .name { font-weight: 700; transition: font-size 0.2s ease; }
.chips { display:flex; gap:8px; flex-wrap:wrap; margin-top:4px; }
.chip { display:inline-flex; align-items:center; padding:6px 10px; border-radius:999px; border:1px solid var(--border); background:#f9fafb; color: var(--text); font-size:0.85rem; }
@media (max-width:640px){ .hero-content { grid-template-columns: 1fr; } .profile-card { margin-top: 4px; } }
/* Sticky state styles */
.hero-header.stuck { border-radius: 0 0 16px 16px; box-shadow: 0 6px 20px rgba(31,45,65,0.15); }
.hero-header.stuck .hero-content { padding: 10px 16px; gap: 8px; transform: translateZ(0); }
.hero-header.stuck .hero-title h1 { opacity: 1; }
.hero-header.stuck .profile-card { padding: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.12); }
.hero-header.stuck .avatar { width: 40px; height: 40px; }
.hero-header.stuck .hero-bg { filter: saturate(115%) brightness(1.05); }

/* Mobile optimizations for hero header */
@media (max-width: 480px) {
  .hero-header { margin-bottom: 8px; }
  .hero-content { padding: 10px 12px; gap: 8px; grid-template-columns: 1fr; }
  .hero-title h1 {
    font-size: clamp(0.95rem, 3.8vw, 1.05rem);
    line-height: 1.15;
    overflow-wrap: anywhere;
    word-break: break-word;
    hyphens: auto;
    text-wrap: balance;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    margin: 0;
  }
  .progress-text { font-size: 0.75rem; }
  .profile-card { padding: 8px; gap: 8px; }
  .avatar { width: 36px; height: 36px; }
  .profile-info .name { font-size: clamp(0.9rem, 3.6vw, 1rem); }
  .chips { gap: 6px; flex-wrap: nowrap; }
  .chip { font-size: 0.8rem; padding: 4px 8px; max-width: 45vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .road-progress { height: 34px; }
  #profile-progress-text { margin-top: 4px; }
}
/* Road progress styles */
.road-progress {
  position: relative;
  width: 100%;
  height: 40px; /* accommodates paradero (40px) */
  margin-top: 12px;
}
.road-progress .road-bg {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 20px; /* via.svg height */
  background-image: url('/static/via.svg');
  background-repeat: repeat-x;
  background-size: auto 20px; /* auto width, 20px tall */
}
.road-progress .road-stop {
  position: absolute;
  right: 0;
  bottom: 0;
  height: 40px; /* paradero.svg height */
  width: auto;
}
.road-progress .road-bus {
  position: absolute;
  bottom: 0;
  height: 37px; /* bus height */
  width: auto;
  transform: translateX(0);
  transition: transform 0.3s ease;
  will-change: transform;
}
/* Optional: align progress text under the road */
#profile-progress-text {
  margin-top: 6px;
}
.success-actions {
    margin-top: 30px;
}

.success-actions .btn {
    margin: 0 10px;
}

/* Loading state for buttons */
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Improved field visibility transitions */
.field-container {
    transition: all 0.3s ease-in-out;
}

.field-container.hidden {
    opacity: 0;
    max-height: 0;
    overflow: hidden;
    margin: 0;
    padding: 0;
}

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.3); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; }
.hidden { display: none; }
.spinner { width: 28px; height: 28px; border: 3px solid #fff; border-top-color: var(--primary); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Responsive */
@media (max-width: 640px) {
  .container { padding: 12px; }
  .card { padding: 16px; }
  .actions { flex-direction: column; align-items: stretch; }
}

/* Matriz (campo 2) horizontal */
.matrix-scroll {
}
.matrix-scroll::-webkit-scrollbar { display: none; } /* WebKit */
.matrix { display: grid; gap: 8px; width: max-content; }
.matrix-header, .matrix-row {
  display: grid;
  grid-template-columns: minmax(160px, 2fr) repeat(var(--scale-cols), 1fr);
  column-gap: 8px;
  align-items: center;
}
.matrix-header > div { font-weight: 600; text-align: center; }
.matrix-header > div:first-child { visibility: hidden; }
.matrix-row > div { display: flex; justify-content: center; }
.matrix-row > div:first-child { justify-content: flex-start; }
.matrix-row input[type="radio"] { margin: 0 auto; }

/* Opciones en línea para radios y checkboxes */
.options { display: flex; flex-wrap: wrap; gap: 10px; }
.option-item { display: inline-flex; align-items: center; gap: 6px; transition: max-height 220ms ease, opacity 220ms ease; overflow: hidden; }
.option-item.option-hidden { max-height: 0; opacity: 0; pointer-events: none; margin-top: 0; margin-bottom: 0; }
.option-item.option-visible { opacity: 1; }
.combo { position: relative; max-width: 480px; }
.combo-toggle { width: 100%; text-align: left; padding: 8px 10px; border: 1px solid #ccc; border-radius: 6px; background: #fff; cursor: pointer; }
.combo-toggle:disabled { color: #777; background: #f4f4f4; cursor: not-allowed; }
.combo-panel { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid #ddd; border-radius: 6px; box-shadow: 0 6px 20px rgba(0,0,0,0.12); padding: 8px; max-height: 280px; overflow: auto; display: none; z-index: 10; }
.combo-panel.open { display: block; }
.combo-search { width: 100%; padding: 8px 10px; border: 1px solid #ddd; border-radius: 6px; margin-bottom: 8px; }
.combo-list { display: grid; grid-template-columns: 1fr; gap: 4px; }
.combo-item { display: block; width: 100%; text-align: left; padding: 8px 10px; border: none; background: #f9fafb; border-radius: 6px; cursor: pointer; }
.combo-item:hover { background: #eef2ff; }
.combo-item.selected { background: #e0e7ff; }