:root {
  color-scheme: dark;

  --bg: #050e28;
  --bg-2: #081536;
  --card: #0c1d4a;
  --card-2: #11285f;
  --card-3: #173272;
  --line: #1c3672;
  --line-strong: #2d4f9e;

  --ink: #f2f6ff;
  --ink-2: #bccaea;
  --ink-3: #8a9dc9;

  --lime: #c8f542;
  --lime-strong: #b6e72c;
  --lime-soft: rgba(200, 245, 66, 0.14);
  --on-lime: #071330;
  --blue: #5aa2ff;
  --blue-soft: rgba(90, 162, 255, 0.15);
  --chart-blue: #4a90f0;

  --ok: #4fe3a1;
  --warn: #ffc857;
  --danger: #ff8078;
  --ok-soft: rgba(79, 227, 161, 0.14);
  --warn-soft: rgba(255, 200, 87, 0.14);
  --danger-soft: rgba(255, 128, 120, 0.14);

  --font-body: 'Manrope', 'Segoe UI', system-ui, sans-serif;
  --font-display: 'Sora', 'Segoe UI', system-ui, sans-serif;

  --radius-s: 10px;
  --radius-m: 14px;
  --radius-l: 20px;
  --shadow: 0 18px 50px rgba(2, 8, 28, 0.55);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

h1,
h2,
h3,
h4 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

img,
svg {
  display: block;
}

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

button {
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0;
}

a {
  color: var(--lime);
}

:focus-visible {
  outline: 2px solid var(--lime);
  outline-offset: 2px;
}

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

.muted {
  color: var(--ink-3);
}

/* Botões */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: var(--card-2);
  color: var(--ink);
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  position: relative;
  transition: transform 0.18s var(--ease), background 0.18s, border-color 0.18s, box-shadow 0.25s;
}

.btn:hover {
  background: var(--card-3);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(1px) scale(0.985);
}

.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--lime);
  border-color: var(--lime);
  color: var(--on-lime);
}

.btn-primary:hover {
  background: var(--lime-strong);
  border-color: var(--lime-strong);
  box-shadow: 0 10px 30px rgba(200, 245, 66, 0.28);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink-2);
}

.btn-ghost:hover {
  background: rgba(120, 160, 255, 0.1);
  color: var(--ink);
}

.btn-danger {
  background: var(--danger-soft);
  border-color: transparent;
  color: var(--danger);
}

.btn-danger:hover {
  background: rgba(255, 128, 120, 0.24);
}

.btn-block {
  width: 100%;
}

.btn-large {
  min-height: 52px;
  font-size: 15px;
  border-radius: 14px;
}

.btn-small {
  min-height: 36px;
  padding: 0 12px;
  font-size: 13px;
  border-radius: 10px;
}

.btn-icon {
  width: 40px;
  min-height: 40px;
  padding: 0;
}

.btn.is-loading {
  color: transparent;
  pointer-events: none;
}

.btn.is-loading .icon {
  opacity: 0;
}

.btn.is-loading::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2.5px solid var(--ink-2);
  border-right-color: transparent;
  animation: spin 0.7s linear infinite;
}

.btn-primary.is-loading::after {
  border-color: var(--on-lime);
  border-right-color: transparent;
}

/* Campos */
.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field > label,
.field-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-2);
}

.field small {
  color: var(--ink-3);
  font-size: 12.5px;
}

.required {
  color: var(--lime);
}

.input {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: rgba(4, 12, 36, 0.6);
  color: var(--ink);
  transition: border-color 0.18s, box-shadow 0.2s, background 0.18s;
}

textarea.input {
  min-height: 92px;
  resize: vertical;
}

select.input {
  appearance: none;
  padding-right: 38px;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%),
    linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}

select.input option {
  background: var(--card);
}

.input::placeholder {
  color: var(--ink-3);
}

.input:hover {
  border-color: #3f66bd;
}

.input:focus {
  outline: 0;
  border-color: var(--lime);
  box-shadow: 0 0 0 3px rgba(200, 245, 66, 0.18);
}

.input.invalid {
  border-color: var(--danger);
  animation: shake 0.36s;
}

input[type='date'].input {
  color-scheme: dark;
}

.field-error {
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
}

.check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  cursor: pointer;
  color: var(--ink-2);
  font-size: 14px;
}

.check input {
  appearance: none;
  flex: none;
  width: 22px;
  height: 22px;
  margin: 0;
  border-radius: 7px;
  border: 1.5px solid var(--line-strong);
  background: rgba(4, 12, 36, 0.6);
  cursor: pointer;
  position: relative;
  transition: background 0.16s, border-color 0.16s, transform 0.2s var(--spring);
}

.check input:checked {
  background: var(--lime);
  border-color: var(--lime);
  transform: scale(1.04);
}

.check input:checked::after {
  content: '';
  position: absolute;
  left: 7px;
  top: 3px;
  width: 6px;
  height: 11px;
  border: solid var(--on-lime);
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(42deg);
}

.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  cursor: pointer;
}

.switch input {
  appearance: none;
  flex: none;
  width: 46px;
  height: 26px;
  margin: 0;
  border-radius: 999px;
  background: var(--line-strong);
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
}

.switch input::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.26s var(--spring);
}

.switch input:checked {
  background: var(--lime);
}

.switch input:checked::after {
  transform: translateX(20px);
  background: var(--on-lime);
}

/* Selo */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  background: rgba(120, 160, 255, 0.14);
  color: var(--ink-2);
}

.badge.lime {
  background: var(--lime-soft);
  color: var(--lime);
}

.badge.blue {
  background: var(--blue-soft);
  color: #a6cdff;
}

.badge.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.badge.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

/* Fotos com carregamento suave */
.photo-frame {
  position: relative;
  overflow: hidden;
  background: linear-gradient(110deg, var(--card-2) 30%, var(--card-3) 50%, var(--card-2) 70%);
  background-size: 220% 100%;
  animation: shimmer 1.5s linear infinite;
}

.photo-frame.loaded {
  animation: none;
  background: var(--card-2);
}

.photo-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  filter: blur(12px);
  transform: scale(1.07);
  transition: opacity 0.5s var(--ease), filter 0.6s var(--ease), transform 0.8s var(--ease);
}

.photo-frame.loaded img {
  opacity: 1;
  filter: none;
  transform: scale(1);
}

.photo-empty {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--ink-3);
}

/* Modais */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(3, 9, 28, 0.66);
  backdrop-filter: blur(8px);
  animation: fade-in 0.22s both;
}

.modal {
  position: relative;
  width: min(100%, var(--modal-width, 520px));
  max-height: min(88dvh, 860px);
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-l);
  background: var(--card);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: modal-in 0.34s var(--spring) both;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px 8px;
}

.modal-head h2 {
  font-size: 20px;
}

.modal-head p {
  margin-top: 4px;
  color: var(--ink-3);
  font-size: 14px;
}

.modal-close {
  flex: none;
  width: 36px;
  height: 36px;
  margin: -4px -8px 0 0;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: var(--ink-3);
  transition: background 0.16s, color 0.16s, transform 0.3s var(--ease);
}

.modal-close:hover {
  background: rgba(120, 160, 255, 0.12);
  color: var(--ink);
  transform: rotate(90deg);
}

.modal-body {
  padding: 14px 24px 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 24px;
  border-top: 1px solid var(--line);
  background: rgba(4, 12, 36, 0.3);
}

.modal-root.closing .modal {
  animation: modal-out 0.18s ease-in both;
}

.modal-root.closing .modal-backdrop {
  animation: fade-out 0.18s both;
}

@media (max-width: 640px) {
  .modal-root {
    padding: 0;
    place-items: end stretch;
  }

  .modal {
    width: 100%;
    max-height: 92dvh;
    border-radius: 22px 22px 0 0;
    border-width: 1px 0 0;
    animation: sheet-in 0.36s var(--ease) both;
  }

  .modal::before {
    content: '';
    align-self: center;
    flex: none;
    width: 42px;
    height: 4px;
    margin-top: 10px;
    border-radius: 4px;
    background: var(--line-strong);
  }

  .modal-root.closing .modal {
    animation: sheet-out 0.2s ease-in both;
  }

  .modal-head {
    padding: 14px 18px 6px;
  }

  .modal-body {
    padding: 12px 18px 18px;
  }

  .modal-foot {
    padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
  }

  .modal-foot .btn {
    flex: 1;
  }
}

/* Avisos */
.toasts {
  position: fixed;
  z-index: 80;
  top: 18px;
  right: 18px;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--card-3);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
  font-weight: 600;
  font-size: 14px;
  pointer-events: auto;
  animation: toast-in 0.34s var(--spring) both;
}

.toast .icon {
  flex: none;
  color: var(--lime);
}

.toast.error .icon {
  color: var(--danger);
}

.toast.leaving {
  animation: toast-out 0.2s ease-in both;
}

@media (max-width: 640px) {
  .toasts {
    left: 16px;
    right: 16px;
    top: 12px;
    width: auto;
  }
}

.empty-state {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 48px 20px;
  text-align: center;
  color: var(--ink-3);
}

.empty-state .icon {
  color: var(--line-strong);
}

.empty-state strong {
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
}

/* Entrada escalonada de listas */
.reveal {
  animation: rise 0.5s var(--ease) both;
  animation-delay: calc(var(--i, 0) * 45ms);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes shimmer {
  from {
    background-position: 120% 0;
  }

  to {
    background-position: -120% 0;
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

@keyframes fade-out {
  to {
    opacity: 0;
  }
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.95);
  }
}

@keyframes modal-out {
  to {
    opacity: 0;
    transform: translateY(8px) scale(0.97);
  }
}

@keyframes sheet-in {
  from {
    transform: translateY(100%);
  }
}

@keyframes sheet-out {
  to {
    transform: translateY(100%);
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-12px) scale(0.96);
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(-8px);
  }
}

@keyframes shake {
  20%,
  60% {
    transform: translateX(-5px);
  }

  40%,
  80% {
    transform: translateX(5px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
