:root {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
  --bg: #0f1115;
  --fg: #e8e8ea;
  --muted: #8a8d94;
  --accent: #4c8bf5;
  --accent-press: #3a78e0;
  --field-bg: #1a1d24;
  --border: #2a2e37;
  --ok: #4ade80;
  --err: #f87171;
}

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

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  overscroll-behavior-y: none;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
}

main {
  width: 100%;
  max-width: 520px;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0 16px;
  padding-top: max(16px, env(safe-area-inset-top));
}

header {
  padding: 8px 0 16px;
}

h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
}

.scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field span {
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0.01em;
}

.field input,
.field select,
.field textarea {
  background: var(--field-bg);
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 12px 14px;
  border-radius: 10px;
  font: inherit;
  font-size: 16px;
  min-height: 48px;
  width: 100%;
  touch-action: manipulation;
  appearance: none;
  -webkit-appearance: none;
}

.field select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%238a8d94'><path d='M4 6l4 4 4-4'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
  padding-right: 40px;
}

.field textarea {
  resize: vertical;
  min-height: 80px;
  line-height: 1.4;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

.field input[type="date"] { cursor: pointer; }
.field input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(0.8);
  cursor: pointer;
  padding: 6px;
}

/* Combobox */
.combobox { position: relative; }
.combobox > input {
  background: var(--field-bg);
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 12px 40px 12px 14px;
  border-radius: 10px;
  font: inherit;
  font-size: 16px;
  min-height: 48px;
  width: 100%;
  touch-action: manipulation;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%238a8d94'><path d='M4 6l4 4 4-4'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
}
.combobox > input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
.combobox-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--field-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  max-height: 280px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  z-index: 10;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.combobox-option {
  padding: 12px 14px;
  font-size: 16px;
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
}
.combobox-list { touch-action: pan-y; }
.combobox-option:hover,
.combobox-option.active {
  background: rgba(76, 139, 245, 0.18);
}
.combobox-option[hidden] { display: none; }
.combobox-list.empty::after {
  content: "Sin resultados";
  display: block;
  padding: 12px 14px;
  color: var(--muted);
  font-size: 14px;
}

/* File input */
.field .file-input { padding: 12px 14px; cursor: pointer; }
.field .file-input::-webkit-file-upload-button,
.field .file-input::file-selector-button {
  background: var(--accent);
  color: white;
  border: 0;
  padding: 8px 14px;
  border-radius: 6px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  margin-right: 12px;
}
.file-info {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
  min-height: 18px;
  word-break: break-all;
}
.file-info.ok { color: var(--ok); }
.file-info.err { color: var(--err); }

/* Submit button */
.submit-bar {
  position: sticky;
  bottom: 0;
  background: linear-gradient(to top, var(--bg) 70%, rgba(15, 17, 21, 0));
  padding: 16px 0;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}
button#submit {
  background: var(--accent);
  color: white;
  border: 0;
  padding: 16px 20px;
  border-radius: 12px;
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  min-height: 52px;
  touch-action: manipulation;
  transition: background-color 0.15s ease, transform 0.05s ease;
}
button#submit:active { background: var(--accent-press); transform: scale(0.99); }
button#submit:disabled { opacity: 0.6; cursor: not-allowed; }

#status {
  color: var(--muted);
  margin: 12px 0 0;
  text-align: center;
  font-size: 14px;
  min-height: 20px;
}
#status.ok { color: var(--ok); }
#status.err { color: var(--err); }

/* Loading screen */
.loading-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  color: var(--muted);
  font-size: 14px;
}
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.spinner-lg { width: 52px; height: 52px; border-width: 4px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Submit overlay loader */
.submit-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 21, 0.85);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
}
.submit-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  color: var(--fg);
  font-size: 15px;
}
.loader-orbit {
  position: relative;
  width: 72px;
  height: 72px;
}
.loader-orbit span {
  position: absolute;
  inset: 0;
  border: 3px solid transparent;
  border-radius: 50%;
  animation: orbit 1.4s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}
.loader-orbit span:nth-child(1) {
  border-top-color: var(--accent);
  animation-delay: 0s;
}
.loader-orbit span:nth-child(2) {
  border-right-color: #7aa8ff;
  animation-delay: -0.35s;
  inset: 8px;
}
.loader-orbit span:nth-child(3) {
  border-bottom-color: #b3cdff;
  animation-delay: -0.7s;
  inset: 16px;
}
@keyframes orbit {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Success screen */
.success-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 24px 0;
  gap: 18px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}
.success-icon svg {
  width: 96px;
  height: 96px;
  display: block;
}
.success-circle {
  stroke: var(--ok);
  stroke-width: 2.5;
  stroke-dasharray: 165;
  stroke-dashoffset: 165;
  animation: drawCircle 0.55s ease forwards;
  transform-origin: center;
}
.success-check {
  stroke: var(--ok);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 60;
  stroke-dashoffset: 60;
  animation: drawCheck 0.4s 0.45s ease forwards;
}
@keyframes drawCircle { to { stroke-dashoffset: 0; } }
@keyframes drawCheck { to { stroke-dashoffset: 0; } }

.success-screen h2 {
  margin: 4px 0 0;
  font-size: 24px;
  font-weight: 600;
  animation: fadeUp 0.4s 0.7s both;
}

.success-summary {
  background: var(--field-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: fadeUp 0.4s 0.85s both;
}
.success-summary .row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  font-size: 14px;
  gap: 16px;
  padding: 4px 0;
}
.success-summary .row + .row { border-top: 1px solid var(--border); padding-top: 8px; }
.success-summary .label { color: var(--muted); white-space: nowrap; }
.success-summary .value {
  text-align: right;
  word-break: break-word;
  font-weight: 500;
}

.success-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 420px;
  margin-top: 4px;
  animation: fadeUp 0.4s 1s both;
}
.btn-primary, .btn-secondary {
  padding: 14px 20px;
  border-radius: 12px;
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  touch-action: manipulation;
  transition: background-color 0.15s ease, transform 0.05s ease;
}
.btn-secondary svg { flex-shrink: 0; }
.btn-primary {
  background: var(--accent);
  color: white;
  border: 0;
}
.btn-primary:active { background: var(--accent-press); transform: scale(0.99); }
.btn-secondary {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--field-bg); }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
