/* ============================================
   GRID DYNAMICS — Base CSS
   Reset + utilidades globales pixel-art/cyber
   ============================================ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -moz-text-size-adjust: none;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
  scroll-padding-top: var(--space-16);
}

body {
  min-height: 100dvh;
  line-height: 1.6;
  font-family: var(--font-ui, sans-serif);
  font-size: var(--text-base);
  color: var(--text);
  background-color: var(--bg);
}

img, picture, video, canvas, svg {
  display: block;
  max-width: 100%;
  height: auto;
}

ul[role="list"], ol[role="list"] { list-style: none; }
input, button, textarea, select { font: inherit; color: inherit; }

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-ui);
  text-wrap: balance;
  line-height: 1.15;
  color: var(--text);
}

p, li, figcaption {
  text-wrap: pretty;
  max-width: 72ch;
}

::selection {
  background: rgba(0, 229, 255, 0.2);
  color: var(--text);
}

:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
  border-radius: var(--radius);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

button { cursor: pointer; background: none; border: none; }
a { text-decoration: none; color: inherit; }
table { border-collapse: collapse; width: 100%; }

a, button, [role="button"], [role="link"], input, textarea, select {
  transition: color var(--transition),
              background var(--transition),
              border-color var(--transition),
              box-shadow var(--transition);
}

.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;
}

/* ===== CONTENEDOR ===== */
.container {
  max-width: 1200px;
  margin-inline: auto;
  padding-inline: var(--space-6);
}
.container-narrow { max-width: 800px; margin-inline: auto; padding-inline: var(--space-6); }

/* ===== BOTONES ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-6);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s var(--ease-cyber);
  border: 1px solid transparent;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}
.btn i { font-size: 18px; flex-shrink: 0; }

.btn-primary {
  background: var(--cyan);
  color: #050a0d;
  border-color: var(--cyan);
}
.btn-primary:hover {
  background: #fff;
  color: #050a0d;
  box-shadow: 0 0 20px rgba(0, 229, 255, 0.5);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }

.btn-outline {
  background: transparent;
  color: var(--cyan);
  border-color: var(--cyan);
}
.btn-outline:hover {
  background: var(--p-blue);
  box-shadow: 0 0 15px rgba(0, 229, 255, 0.2);
}

.btn-ghost {
  background: transparent;
  color: var(--text2);
  border-color: var(--border);
}
.btn-ghost:hover {
  color: var(--text);
  background: var(--p-blue);
  border-color: var(--border-bright);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ===== BADGE / TAG ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-3);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: var(--radius);
  border: 1px solid;
}
.badge-cyber {
  color: var(--cyan);
  background: var(--p-green);
  border-color: rgba(0,229,255,0.3);
}
.badge-muted {
  color: var(--text3);
  background: rgba(0,229,255,0.04);
  border-color: var(--border);
}
.badge-success {
  color: #00e564;
  background: rgba(0,229,100,0.1);
  border-color: rgba(0,229,100,0.3);
}
.badge-warn {
  color: #ffa000;
  background: rgba(255,160,0,0.1);
  border-color: rgba(255,160,0,0.3);
}
.badge-error {
  color: #ff3250;
  background: rgba(255,50,80,0.1);
  border-color: rgba(255,50,80,0.3);
}

/* ===== CARD ===== */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
  position: relative;
  overflow: hidden;
}
.card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--grad-card);
  pointer-events: none;
}
.card:hover {
  border-color: var(--border-bright);
  box-shadow: var(--shadow);
}

/* ===== FORM ELEMENTS ===== */
.label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text2);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: var(--space-2);
}

.input, .select, .textarea {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: var(--text-sm);
  font-family: var(--font-ui);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input::placeholder, .textarea::placeholder {
  color: var(--text3);
}

.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(0,229,255,0.12);
}

.input:hover, .select:hover {
  border-color: rgba(0,229,255,0.35);
}

.select {
  appearance: none;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M6 8L1 3h10z' fill='%234a7a8a'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-4) center;
  padding-right: var(--space-10);
}

.textarea { resize: vertical; min-height: 100px; }

/* ===== TOAST ===== */
#toast-container {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s var(--ease-cyber);
  pointer-events: auto;
  min-width: 260px;
  max-width: 380px;
}
.toast i { font-size: 20px; flex-shrink: 0; }
.toast.toast-success { border-left: 3px solid #00e564; }
.toast.toast-success i { color: #00e564; }
.toast.toast-error   { border-left: 3px solid #ff3250; }
.toast.toast-error i { color: #ff3250; }
.toast.toast-info    { border-left: 3px solid var(--cyan); }
.toast.toast-info i  { color: var(--cyan); }
.toast.toast-warn    { border-left: 3px solid #ffa000; }
.toast.toast-warn i  { color: #ffa000; }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ===== GLITCH EFFECT ===== */
.glitch-text {
  position: relative;
  color: var(--cyan);
}
.glitch-text::before,
.glitch-text::after {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.glitch-text::before {
  color: #ff3250;
  animation: glitch1 3s infinite linear;
  clip-path: polygon(0 30%, 100% 30%, 100% 50%, 0 50%);
}
.glitch-text::after {
  color: #00e5ff;
  animation: glitch2 3s infinite linear;
  clip-path: polygon(0 55%, 100% 55%, 100% 75%, 0 75%);
}
@keyframes glitch1 {
  0%, 90%, 100% { transform: translate(0); opacity: 0; }
  92% { transform: translate(-3px, 1px); opacity: 0.7; }
  94% { transform: translate(2px, -1px); opacity: 0.5; }
}
@keyframes glitch2 {
  0%, 93%, 100% { transform: translate(0); opacity: 0; }
  95% { transform: translate(3px, -1px); opacity: 0.6; }
  97% { transform: translate(-2px, 1px); opacity: 0.4; }
}

/* ===== UTILIDADES ===== */
.text-cyan   { color: var(--cyan); }
.text-muted  { color: var(--text2); }
.text-faint  { color: var(--text3); }
.font-ui     { font-family: var(--font-ui); }
.font-mono   { font-family: var(--font-mono); }
.font-ench   { font-family: var(--font-ench); }
.uppercase   { text-transform: uppercase; letter-spacing: 0.1em; }
.hidden      { display: none !important; }
.flex        { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-2       { gap: var(--space-2); }
.gap-4       { gap: var(--space-4); }

/* ===== SKELETON ===== */
@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.skeleton {
  background: linear-gradient(90deg,
    rgba(0,229,255,0.05) 25%,
    rgba(0,229,255,0.12) 50%,
    rgba(0,229,255,0.05) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius);
}

/* ===== DIVISOR ===== */
.divider {
  height: 1px;
  background: var(--border);
  margin-block: var(--space-6);
}

/* ===== SCAN LINE (decorativo) ===== */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 229, 255, 0.012) 2px,
    rgba(0, 229, 255, 0.012) 4px
  );
  pointer-events: none;
  z-index: 9998;
}

/* ===== SCROLLBAR CUSTOM ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb {
  background: rgba(0,229,255,0.2);
  border-radius: var(--radius);
}
::-webkit-scrollbar-thumb:hover { background: rgba(0,229,255,0.4); }

/* Responsive base */
@media (max-width: 480px) {
  .container, .container-narrow {
    padding-inline: var(--space-4);
  }
  #toast-container {
    bottom: var(--space-4);
    right: var(--space-4);
    left: var(--space-4);
  }
  .toast { min-width: unset; width: 100%; }
}