/* ==========================================================================
   NimbookGR — base: reset, tokens de diseño, tipografía, utilidades
   ========================================================================== */

:root {
  /* Marca */
  --brand: #0866ff;
  --brand-hover: #0757d8;
  --brand-active: #064fc4;
  --brand-soft: #e7f3ff;
  --brand-soft-2: #dbeafe;

  /* Superficies (tema claro) */
  --bg: #f0f2f5;
  --bg-elevated: #ffffff;
  --card: #ffffff;
  --card-2: #f5f6f7;
  --card-3: #ebedf0;
  --overlay: rgba(0, 0, 0, .45);

  /* Texto */
  --text: #050505;
  --text-2: #65676b;
  --text-3: #8a8d91;
  --text-invert: #ffffff;

  /* Líneas */
  --line: #ced0d4;
  --line-soft: #e4e6eb;
  --line-strong: #bcc0c4;

  /* Estados */
  --hover: rgba(0, 0, 0, .05);
  --hover-strong: rgba(0, 0, 0, .08);
  --active: rgba(0, 0, 0, .12);
  --danger: #fa383e;
  --danger-soft: #ffebe8;
  --success: #31a24c;
  --warning: #f7b125;
  --online: #31a24c;

  /* Sombras */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .08);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .1), 0 2px 4px rgba(0, 0, 0, .06);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, .12), 0 1px 3px rgba(0, 0, 0, .08);
  --shadow-lg: 0 12px 28px rgba(0, 0, 0, .18), 0 2px 8px rgba(0, 0, 0, .1);
  --ring: 0 0 0 2px var(--brand);

  /* Radios */
  --r-xs: 4px;
  --r-sm: 6px;
  --r: 8px;
  --r-md: 10px;
  --r-lg: 12px;
  --r-xl: 18px;
  --r-full: 999px;

  /* Métricas de layout */
  --topbar-h: 56px;
  --left-w: 280px;
  --right-w: 360px;
  --feed-w: 680px;
  --nav-h: 62px;
  --gutter: 16px;

  /* Movimiento */
  --ease: cubic-bezier(.2, .8, .2, 1);
  --fast: 120ms;
  --med: 220ms;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}

html[data-theme="dark"] {
  --bg: #18191a;
  --bg-elevated: #242526;
  --card: #242526;
  --card-2: #3a3b3c;
  --card-3: #4e4f50;
  --text: #e4e6eb;
  --text-2: #b0b3b8;
  --text-3: #8a8d91;
  --line: #3e4042;
  --line-soft: #3e4042;
  --line-strong: #4e4f50;
  --hover: rgba(255, 255, 255, .1);
  --hover-strong: rgba(255, 255, 255, .14);
  --active: rgba(255, 255, 255, .18);
  --brand-soft: rgba(45, 136, 255, .18);
  --brand-soft-2: rgba(45, 136, 255, .24);
  --danger-soft: rgba(250, 56, 62, .18);
  --overlay: rgba(0, 0, 0, .7);
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .45), 0 2px 6px rgba(0, 0, 0, .3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, .55);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .65);
}

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

* { margin: 0; padding: 0; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  height: 100%;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

body {
  min-height: 100%;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.34;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-wrap: break-word;
  overscroll-behavior-y: none;
}

img, svg, video, canvas { display: block; max-width: 100%; }
img { height: auto; }

input, button, textarea, select {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  outline: none;
}

button { cursor: pointer; -webkit-tap-highlight-color: transparent; appearance: none; -webkit-appearance: none; }
button:disabled { cursor: not-allowed; opacity: .55; }

a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; }

ul, ol { list-style: none; }

hr { border: 0; border-top: 1px solid var(--line-soft); }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

/* los campos de texto ya muestran su propio foco (borde/fondo) */
input:focus-visible,
textarea:focus-visible,
select:focus-visible { outline: none; }

::selection { background: var(--brand-soft-2); color: var(--text); }

/* scrollbars */
.scroll-y { overflow-y: auto; overscroll-behavior: contain; }
.scroll-y::-webkit-scrollbar,
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background-color: var(--line-strong); background-clip: padding-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* ---------- tipografía ----------------------------------------------------- */
h1, h2, h3, h4 { font-weight: 700; line-height: 1.2; }
h1 { font-size: 24px; }
h2 { font-size: 20px; }
h3 { font-size: 17px; }
h4 { font-size: 15px; }

.strong { font-weight: 600; }
.bold { font-weight: 700; }
.muted { color: var(--text-2); }
.dim { color: var(--text-3); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.big { font-size: 17px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.link { color: var(--brand); cursor: pointer; }
.link:hover { text-decoration: underline; }

/* ---------- utilidades ----------------------------------------------------- */
.row { display: flex; align-items: center; }
.col { display: flex; flex-direction: column; }
.between { justify-content: space-between; }
.center { display: flex; align-items: center; justify-content: center; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.gap-4 { gap: 4px; } .gap-6 { gap: 6px; } .gap-8 { gap: 8px; }
.gap-10 { gap: 10px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; }
.mt-4 { margin-top: 4px; } .mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; } .mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; }
.hide { 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: 0;
}
.no-select { user-select: none; -webkit-user-select: none; }
.pointer { cursor: pointer; }

/* ---------- iconos -------------------------------------------------------- */
.ico { display: inline-block; flex: none; vertical-align: middle; }
.ico-btn {
  width: 40px; height: 40px; border-radius: var(--r-full);
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--card-2); color: var(--text);
  transition: background var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.ico-btn:hover { background: var(--card-3); }
.ico-btn:active { transform: scale(.94); }
.ico-btn.plain { background: transparent; }
.ico-btn.plain:hover { background: var(--hover); }

/* ---------- animaciones --------------------------------------------------- */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in {
  0% { opacity: 0; transform: scale(.9) translateY(8px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes pop-bounce {
  0% { transform: scale(.4); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}
@keyframes slide-up {
  from { transform: translateY(14px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { 100% { transform: translateX(100%); } }
@keyframes pulse-dot { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

.fade-in { animation: fade-in var(--med) var(--ease); }
.pop-in { animation: pop-in var(--med) var(--ease); }

.spinner {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2.5px solid var(--line);
  border-top-color: var(--brand);
  animation: spin .7s linear infinite;
}
.spinner.big { width: 32px; height: 32px; border-width: 3px; }
.spinner.on-brand { border-color: rgba(255,255,255,.45); border-top-color: #fff; }

.skeleton {
  position: relative; overflow: hidden;
  background: var(--card-2); border-radius: var(--r-sm);
}
.skeleton::after {
  content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, var(--hover), transparent);
  animation: shimmer 1.4s infinite;
}

/* ---------- splash -------------------------------------------------------- */
.splash {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; background: var(--bg); color: var(--text);
  transition: opacity .35s var(--ease), visibility .35s;
}
.splash.hide { opacity: 0; visibility: hidden; pointer-events: none; }
.splash img { border-radius: 26px; box-shadow: 0 18px 40px -16px rgba(8, 102, 255, .6); }
.splash-name {
  font-size: 26px; font-weight: 700; letter-spacing: -.4px;
  background: linear-gradient(90deg, var(--brand), #4f9bff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.splash-bar {
  width: 148px; height: 4px; border-radius: 4px; overflow: hidden;
  background: var(--line-soft); margin-top: 4px;
}
.splash-bar span {
  display: block; width: 40%; height: 100%; border-radius: 4px;
  background: var(--brand); animation: splash-slide 1.1s infinite var(--ease);
}
@keyframes splash-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}
.splash-msg { font-size: 13px; color: var(--text-2); max-width: 280px; text-align: center; }

.splash-error {
  max-width: 440px; width: calc(100% - 32px);
  background: var(--card); border-radius: var(--r-lg);
  box-shadow: var(--shadow-md); padding: 22px; text-align: center;
  animation: pop-in var(--med) var(--ease);
}
.splash-error h2 { font-size: 18px; margin-bottom: 8px; }
.splash-error p { font-size: 13.5px; line-height: 1.55; color: var(--text-2); }
.splash-error button {
  margin-top: 14px; height: 42px; padding: 0 22px; border-radius: var(--r);
  background: var(--brand); color: #fff; font-weight: 600; font-size: 15px;
}
.splash-error button:hover { background: var(--brand-hover); }
.splash-hint { margin-top: 14px; font-size: 12px; color: var(--text-3); }
.splash-hint code {
  background: var(--card-2); padding: 1px 5px; border-radius: 4px;
  font-size: 11.5px; word-break: break-all;
}

/* ---------- toasts -------------------------------------------------------- */
.toasts {
  position: fixed; z-index: 9000; bottom: 24px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; width: min(92vw, 460px);
}
@media (max-width: 767px) {
  .toasts { bottom: calc(var(--nav-h) + 14px); }
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-radius: var(--r-md);
  background: #303030; color: #fff; font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow-lg); animation: slide-up var(--med) var(--ease);
  max-width: 100%;
}
html[data-theme="dark"] .toast { background: #4e4f50; }
.toast.error { background: #c62828; }
.toast.success { background: #1b7a35; }
.toast .ico { flex: none; }
.toast.out { animation: fade-in var(--med) reverse forwards; }
