/* ============================================
   UPMYS - Portal de Estadías Profesionales
   Sistema de Diseño Institucional
   ============================================ */

/* --- Custom Properties --- */
:root {
  --primary-900: #061856;
  --primary-700: #134074;
  --primary-500: #0054A2;
  --primary-300: #5590FF;
  --primary-50: #F2F9FF;

  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --border-focus: var(--primary-500);

  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-inverse: #ffffff;

  --success: #16a34a;
  --success-bg: #f0fdf4;
  --error: #dc2626;
  --error-bg: #fef2f2;
  --warning: #d97706;
  --warning-bg: #fffbeb;

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;

  --shadow-xs: 0 1px 2px rgba(6, 24, 86, 0.04);
  --shadow-sm: 0 1px 3px rgba(6, 24, 86, 0.06), 0 1px 2px rgba(6, 24, 86, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(6, 24, 86, 0.06), 0 2px 4px -2px rgba(6, 24, 86, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(6, 24, 86, 0.06), 0 4px 6px -4px rgba(6, 24, 86, 0.04);

  --font-family: 'Open Sans', system-ui, -apple-system, sans-serif;
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 250ms ease;
}

/* --- Reset --- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* --- Base --- */
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family);
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--text-primary);
  background-color: var(--primary-50);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --- Tipografía --- */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-family);
  font-weight: 700;
  line-height: 1.3;
  color: var(--primary-900);
}

.display-title {
  font-size: clamp(1.5rem, 2.5vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--primary-900);
}

.page-title {
  font-size: clamp(1.25rem, 2vw, 1.5rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--primary-900);
}

.section-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--primary-700);
}

.subtitle {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 400;
}

.eyebrow {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--primary-500);
}

.label-text {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 0.375rem;
}

.help-text {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  line-height: 1.4;
}

/* --- Header Institucional --- */
.institutional-header {
  background: linear-gradient(135deg, var(--primary-900) 0%, var(--primary-700) 100%);
  color: var(--text-inverse);
  padding: 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(6, 24, 86, 0.15);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.875rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.header-logo {
  height: 40px;
  width: auto;
  flex-shrink: 0;
}

.header-divider {
  width: 1px;
  height: 32px;
  background: rgba(255, 255, 255, 0.2);
  flex-shrink: 0;
}

.header-text-group {
  flex: 1;
  min-width: 0;
}

.header-eyebrow {
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--primary-300);
  line-height: 1;
  margin-bottom: 0.125rem;
}

.header-title {
  font-size: clamp(0.875rem, 1.5vw, 1.0625rem);
  font-weight: 700;
  color: var(--text-inverse);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-back {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 0.875rem;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-sm);
  color: var(--text-inverse);
  font-size: 0.8125rem;
  font-weight: 600;
  text-decoration: none;
  transition: all var(--transition-fast);
  white-space: nowrap;
  flex-shrink: 0;
}

.header-back:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.3);
}

.header-back svg {
  width: 16px;
  height: 16px;
}

/* --- Footer Institucional --- */
.institutional-footer {
  background: var(--primary-900);
  color: rgba(255, 255, 255, 0.7);
  text-align: center;
  padding: 1.5rem;
  font-size: 0.75rem;
  margin-top: auto;
  line-height: 1.6;
}

.institutional-footer strong {
  color: rgba(255, 255, 255, 0.9);
  font-weight: 600;
}

/* --- Contenido Principal --- */
.main-content {
  flex: 1;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.main-content-narrow {
  max-width: 900px;
}

/* --- Stepper / Barra de Progreso --- */
.stepper-wrapper {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-xs);
}

.stepper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  max-width: 600px;
  margin: 0 auto;
}

.stepper-track {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  z-index: 0;
}

.stepper-progress {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  height: 3px;
  background: var(--primary-500);
  border-radius: 2px;
  z-index: 1;
  transition: width var(--transition-slow);
}

.stepper-step {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.stepper-circle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8125rem;
  font-weight: 700;
  transition: all var(--transition-base);
  border: 3px solid transparent;
}

.stepper-circle--active {
  background: var(--primary-500);
  color: var(--text-inverse);
  box-shadow: 0 0 0 4px rgba(0, 84, 162, 0.15);
}

.stepper-circle--completed {
  background: var(--success);
  color: var(--text-inverse);
}

.stepper-circle--pending {
  background: var(--surface-alt);
  color: var(--text-muted);
  border-color: var(--border);
}

.stepper-label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
  white-space: nowrap;
}

.stepper-label--active {
  color: var(--primary-500);
}

.stepper-label--completed {
  color: var(--success);
}

/* --- Formularios --- */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  box-shadow: var(--shadow-xs);
}

.form-step {
  transition: opacity var(--transition-base);
}

.form-step.hidden {
  display: none;
}

.form-step-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 1rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 0.75rem;
}

.form-step-header h2 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.0625rem;
  font-weight: 600;
}

.form-step-header h2 svg {
  width: 20px;
  height: 20px;
  color: var(--primary-500);
  flex-shrink: 0;
}

.form-grid {
  display: grid;
  gap: 1.25rem;
}

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

.form-grid-3 {
  grid-template-columns: 1fr;
}

.form-group {
  display: flex;
  flex-direction: column;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}

/* --- Inputs --- */
.input-field {
  width: 100%;
  padding: 0.6875rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-family);
  font-size: 0.875rem;
  color: var(--text-primary);
  background: var(--surface);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  line-height: 1.5;
  appearance: none;
  -webkit-appearance: none;
}

.input-field::placeholder {
  color: var(--text-muted);
}

.input-field:hover {
  border-color: #cbd5e1;
}

.input-field:focus {
  outline: none;
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgba(0, 84, 162, 0.1);
}

.input-field:disabled {
  background: var(--surface-alt);
  color: var(--text-muted);
  cursor: not-allowed;
}

.input-field:invalid:not(:placeholder-shown) {
  border-color: var(--error);
}

.input-field:invalid:not(:placeholder-shown):focus {
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

/* Select */
select.input-field {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 16px;
  padding-right: 2.5rem;
  cursor: pointer;
}

/* Date input */
input[type="date"].input-field {
  cursor: pointer;
}

input[type="date"].input-field::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 0.5;
}

input[type="date"].input-field::-webkit-calendar-picker-indicator:hover {
  opacity: 0.8;
}

/* Textarea */
textarea.input-field {
  resize: vertical;
  min-height: 80px;
}

/* --- Radio Buttons (Custom) --- */
.radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.radio-option {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  background: var(--surface);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.radio-option:hover {
  border-color: var(--primary-300);
  background: var(--primary-50);
}

.radio-option input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-radius: 50%;
  transition: all var(--transition-fast);
  position: relative;
  flex-shrink: 0;
}

.radio-option input[type="radio"]::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary-500);
  transition: transform var(--transition-fast);
}

.radio-option input[type="radio"]:checked {
  border-color: var(--primary-500);
}

.radio-option input[type="radio"]:checked::after {
  transform: translate(-50%, -50%) scale(1);
}

.radio-option:has(input:checked) {
  border-color: var(--primary-500);
  background: var(--primary-50);
  color: var(--primary-700);
}

.radio-option input[type="radio"]:focus-visible {
  outline: 2px solid var(--primary-500);
  outline-offset: 2px;
}

/* --- Botones --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  font-family: var(--font-family);
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.5;
}

.btn:focus-visible {
  outline: 2px solid var(--primary-500);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* Primary */
.btn-primary {
  background: var(--primary-500);
  color: var(--text-inverse);
  border-color: var(--primary-500);
}

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

.btn-primary:active {
  transform: scale(0.98);
}

/* Secondary (Ghost) */
.btn-secondary {
  background: transparent;
  color: var(--primary-500);
  border-color: var(--primary-500);
}

.btn-secondary:hover {
  background: var(--primary-50);
}

.btn-secondary:active {
  transform: scale(0.98);
}

/* Danger */
.btn-danger {
  background: var(--error);
  color: var(--text-inverse);
  border-color: var(--error);
}

.btn-danger:hover {
  background: #b91c1c;
  border-color: #b91c1c;
}

/* Small */
.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
}

/* Icon Only */
.btn-icon {
  padding: 0.5rem;
  border-radius: var(--radius-sm);
}

.btn-icon svg {
  width: 18px;
  height: 18px;
}

/* --- Navegación del Formulario --- */
.form-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  gap: 1rem;
}

.form-nav-spacer {
  flex: 1;
}

/* --- Tarjetas del Dashboard --- */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.dashboard-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  text-decoration: none;
  color: inherit;
  transition: all var(--transition-base);
  overflow: hidden;
  cursor: pointer;
}

.dashboard-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--primary-500);
  transform: scaleY(0);
  transform-origin: bottom;
  transition: transform var(--transition-base);
  border-radius: 2px 0 0 2px;
}

.dashboard-card:hover {
  border-color: transparent;
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.dashboard-card:hover::before {
  transform: scaleY(1);
}

.dashboard-card-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--primary-50);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.875rem;
  transition: background var(--transition-fast);
}

.dashboard-card-icon svg {
  width: 20px;
  height: 20px;
  color: var(--primary-500);
}

.dashboard-card:hover .dashboard-card-icon {
  background: var(--primary-500);
}

.dashboard-card:hover .dashboard-card-icon svg {
  color: var(--text-inverse);
}

.dashboard-card-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
  transition: color var(--transition-fast);
}

.dashboard-card:hover .dashboard-card-title {
  color: var(--primary-500);
}

.dashboard-card-desc {
  font-size: 0.8125rem;
  color: var(--text-muted);
  line-height: 1.5;
  flex: 1;
}

.dashboard-card-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  margin-top: 0.875rem;
  padding: 0.25rem 0.625rem;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 600;
  width: fit-content;
}

.dashboard-card-badge--local {
  background: var(--primary-50);
  color: var(--primary-500);
}

.dashboard-card-badge--external {
  background: var(--surface-alt);
  color: var(--text-muted);
}

.dashboard-card-badge svg {
  width: 12px;
  height: 12px;
}

/* --- Vista Previa --- */
.preview-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
}

.preview-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.875rem 1.25rem;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.preview-header svg {
  width: 16px;
  height: 16px;
  color: var(--primary-500);
}

.preview-body {
  padding: 1.5rem;
  font-size: 0.8125rem;
  line-height: 1.7;
  color: var(--text-primary);
  max-height: calc(100vh - 220px);
  overflow-y: auto;
}

.preview-body::-webkit-scrollbar {
  width: 6px;
}

.preview-body::-webkit-scrollbar-track {
  background: transparent;
}

.preview-body::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.preview-body::-webkit-scrollbar-thumb:hover {
  background: #cbd5e1;
}

.preview-body p {
  margin-bottom: 0.75rem;
}

.preview-body b {
  font-weight: 600;
}

/* --- Alertas --- */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.8125rem;
  line-height: 1.5;
  margin-bottom: 1rem;
}

.alert svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  margin-top: 1px;
}

.alert--info {
  background: var(--primary-50);
  color: var(--primary-700);
  border: 1px solid rgba(0, 84, 162, 0.15);
}

.alert--success {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid rgba(22, 163, 74, 0.15);
}

.alert--error {
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid rgba(220, 38, 38, 0.15);
}

.alert--warning {
  background: var(--warning-bg);
  color: var(--warning);
  border: 1px solid rgba(217, 119, 6, 0.15);
}

/* --- Badges --- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.625rem;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 600;
}

.badge--primary {
  background: var(--primary-50);
  color: var(--primary-500);
}

.badge--success {
  background: var(--success-bg);
  color: var(--success);
}

.badge--error {
  background: var(--error-bg);
  color: var(--error);
}

/* --- Tablas --- */
.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.table th {
  background: var(--surface-alt);
  font-weight: 600;
  color: var(--text-secondary);
  padding: 0.625rem 0.875rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.table td {
  padding: 0.625rem 0.875rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

.table tr:last-child td {
  border-bottom: none;
}

.table tr:hover td {
  background: var(--surface-alt);
}

/* --- Actividades Dinámicas (Plan de Trabajo) --- */
.activity-item {
  position: relative;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem;
  transition: border-color var(--transition-fast);
}

.activity-item:hover {
  border-color: var(--primary-300);
}

.activity-item-number {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary-500);
  color: var(--text-inverse);
  font-size: 0.6875rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.activity-item-delete {
  position: absolute;
  top: 0.75rem;
  right: 3rem;
  background: none;
  border: none;
  padding: 0.25rem;
  cursor: pointer;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
}

.activity-item-delete:hover {
  color: var(--error);
  background: var(--error-bg);
}

.activity-item-delete svg {
  width: 16px;
  height: 16px;
}

/* --- Secciones Condicionales --- */
.conditional-section {
  margin-top: 1.25rem;
  padding: 1.25rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: all var(--transition-base);
}

.conditional-section.hidden {
  display: none;
}

.conditional-section-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--primary-700);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* --- Utilidades --- */
.hidden {
  display: none !important;
}

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

/* --- Responsive: Tablet (>= 640px) --- */
@media (min-width: 640px) {
  .form-grid-2 {
    grid-template-columns: 1fr 1fr;
  }

  .form-grid-3 {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .stepper-label {
    font-size: 0.75rem;
  }

  .stepper-circle {
    width: 40px;
    height: 40px;
    font-size: 0.875rem;
  }
}

/* --- Responsive: Desktop (>= 1024px) --- */
@media (min-width: 1024px) {
  .main-content {
    padding: 2.5rem 2rem;
  }

  .form-card {
    padding: 2rem;
  }

  .stepper-label {
    font-size: 0.8125rem;
  }

  .stepper-circle {
    width: 42px;
    height: 42px;
  }
}

/* --- Print --- */
@media print {
  .institutional-header,
  .institutional-footer,
  .stepper-wrapper,
  .form-nav,
  .preview-panel {
    display: none;
  }

  .form-card {
    box-shadow: none;
    border: none;
  }

  .main-content {
    max-width: 100%;
    padding: 0;
  }
}

/* --- Animations --- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.animate-fadeIn {
  animation: fadeIn var(--transition-base) ease-out;
}
/* --- Plantilla oculta para exportación a Word --- */
#word-template {
  position: absolute;
  left: -9999px;
  top: -9999px;
  width: 800px;
  visibility: hidden;
}