/* =========================================================
   app.css — estética violeta (Kimi), adaptada a datos remotos
   ========================================================= */

:root {
  color-scheme: light;
  --bg: #f8f6ff;
  --surface: #ffffff;
  --surface-2: #f4f2fd;
  --ink: #1a1625;
  --ink-2: #6b6680;
  --muted: #9b97af;
  --border: #e9e6f5;
  --shadow: rgba(26, 22, 37, 0.10);
  --radius: 20px;
  --radius-lg: 28px;
  --radius-sm: 12px;
  --accent: #7c3aed;
  --accent-hover: #6d28d9;

  --ok: #16a34a;
  --warn: #f59e0b;
  --bad: #f97316;
  --crit: #dc2626;

  --nav-h: 68px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #11101a;
  --surface: #1c1b29;
  --surface-2: #252336;
  --ink: #f6f4ff;
  --ink-2: #b6b0d4;
  --muted: #7b75a0;
  --border: #2f2d45;
  --shadow: rgba(0, 0, 0, 0.35);
  --accent: #a78bfa;
  --accent-hover: #8b5cf6;
  --ok: #4ade80;
  --warn: #fbbf24;
  --bad: #fb923c;
  --crit: #f87171;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #11101a;
    --surface: #1c1b29;
    --surface-2: #252336;
    --ink: #f6f4ff;
    --ink-2: #b6b0d4;
    --muted: #7b75a0;
    --border: #2f2d45;
    --shadow: rgba(0, 0, 0, 0.35);
    --accent: #a78bfa;
    --accent-hover: #8b5cf6;
    --ok: #4ade80;
    --warn: #fbbf24;
    --bad: #fb923c;
    --crit: #f87171;
  }
}

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

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + 40px + var(--safe-bottom));
  transition: background .2s ease, color .2s ease;
}

h1, h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-sm); }

/* ================= Banner offline ================= */
.offline-banner {
  position: sticky;
  top: 0;
  z-index: 60;
  padding: 8px 16px;
  background: var(--warn);
  color: #1a1625;
  font-size: 12.5px;
  font-weight: 700;
  text-align: center;
}

/* ================= Topbar ================= */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.topbar__title { flex: 1; min-width: 0; padding-left: 4px; }
.topbar__title h1 { font-size: 21px; font-weight: 800; letter-spacing: -0.03em; }
.topbar__title p { font-size: 12.5px; color: var(--ink-2); font-weight: 500; margin-top: 1px; }

.icon-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--ink-2);
  cursor: pointer;
  flex: none;
  transition: transform .12s ease, color .2s ease;
}
.icon-btn:hover { color: var(--ink); }
.icon-btn:active { transform: scale(.94); }

/* ================= Layout ================= */
.app {
  max-width: 680px;
  margin: 0 auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.section__title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 11px;
}
.section__title h2 { font-size: 12.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-2); }
.section__title span { font-size: 12px; font-weight: 600; color: var(--muted); }

/* ================= Hero ================= */
.hero {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: 0 8px 32px var(--shadow);
}
.hero__badge {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--accent);
  margin-bottom: 8px;
}
.hero__value { font-size: 40px; font-weight: 800; letter-spacing: -0.04em; line-height: 1.02; }
.hero__item { margin-top: 8px; font-size: 16.5px; font-weight: 700; }
.hero__meta { font-size: 12.5px; color: var(--ink-2); margin-top: 5px; display: flex; flex-wrap: wrap; gap: 5px 12px; }
.hero__meta b { color: var(--ink); font-weight: 700; }
.hero__bar { margin-top: 16px; }

.hero--skeleton { display: flex; flex-direction: column; gap: 12px; }
.sk { background: var(--surface-2); border-radius: 10px; animation: pulse 1.4s ease-in-out infinite; }
.sk--lg { height: 38px; width: 55%; }
.sk--sm { height: 16px; width: 75%; }
.sk--bar { height: 10px; border-radius: 99px; }
@keyframes pulse { 0%,100% { opacity: .55 } 50% { opacity: 1 } }

/* ================= Barras ================= */
.progress {
  position: relative;
  height: 10px;
  border-radius: 99px;
  background: var(--border);
  overflow: hidden;
}
.progress__fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  border-radius: 99px;
  background: var(--bar-color, var(--accent));
  transition: width .5s cubic-bezier(.25,.8,.25,1), background-color .3s ease;
}
.progress.is-good     { --bar-color: var(--ok); }
.progress.is-warning  { --bar-color: var(--warn); }
.progress.is-serious  { --bar-color: var(--bad); }
.progress.is-critical { --bar-color: var(--crit); }

/* ================= Ítem ================= */
.item {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--cat-color, var(--accent));
  border-radius: var(--radius);
  padding: 15px 16px 15px 14px;
  cursor: pointer;
  box-shadow: 0 3px 12px var(--shadow);
  transition: transform .12s ease, box-shadow .2s ease;
}
.item:active { transform: scale(.99); }
.item:hover { box-shadow: 0 6px 20px var(--shadow); }

.item__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 11px; }
.item__title { flex: 1; min-width: 0; font-size: 15.5px; font-weight: 700; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item__time { flex: none; font-size: 13px; font-weight: 800; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.item__time.is-critical { color: var(--crit); }
.item__bar { margin-bottom: 11px; }

.item__foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--muted); }
.item__dates { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.item-list { display: flex; flex-direction: column; gap: 11px; }

/* ================= Estado ================= */
.status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--ink-2);
  flex: none;
}
.status svg { flex: none; }
.status.is-good     svg { color: var(--ok); }
.status.is-warning  svg { color: var(--warn); }
.status.is-serious  svg { color: var(--bad); }
.status.is-critical svg { color: var(--crit); }

/* ================= Categorías ================= */
.cat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; }
@media (min-width: 520px) { .cat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.cat-card {
  display: flex;
  flex-direction: column;
  gap: 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px;
  cursor: pointer;
  text-align: left;
  box-shadow: 0 3px 12px var(--shadow);
  transition: transform .12s ease, box-shadow .2s ease;
}
.cat-card:active { transform: scale(.98); }
.cat-card:hover { box-shadow: 0 6px 20px var(--shadow); }
.cat-card__dot { width: 26px; height: 5px; border-radius: 99px; background: var(--cat-color, var(--accent)); }
.cat-card__name { font-size: 14.5px; font-weight: 700; }
.cat-card__meta { font-size: 11.5px; color: var(--ink-2); font-weight: 500; }

.cat-card--add {
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 94px;
  border-style: dashed;
  box-shadow: none;
  color: var(--muted);
  background: transparent;
}
.cat-card--add:hover { color: var(--accent); border-color: var(--accent); }
.cat-card--add svg { color: var(--accent); }

/* ================= Empty ================= */
.empty {
  text-align: center;
  padding: 40px 22px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  color: var(--ink-2);
}
.empty h3 { font-size: 16px; font-weight: 700; color: var(--ink); margin-bottom: 7px; }
.empty p { font-size: 13px; line-height: 1.55; }

/* ================= FAB + nav inferior ================= */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(var(--nav-h) + 26px + var(--safe-bottom));
  z-index: 35;
  width: 56px;
  height: 56px;
  border-radius: 18px;
  border: 0;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 10px 26px color-mix(in srgb, var(--accent) 42%, transparent);
  transition: transform .12s ease, background .2s ease;
}
.fab:hover { background: var(--accent-hover); }
.fab:active { transform: scale(.94); }

.bottom-nav {
  position: fixed;
  left: 14px;
  right: 14px;
  bottom: calc(10px + var(--safe-bottom));
  z-index: 40;
  height: var(--nav-h);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  box-shadow: 0 10px 30px var(--shadow);
}
.nav-item {
  flex: 1;
  border: 0;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 700;
  cursor: pointer;
  transition: color .18s ease;
}
.nav-item:hover { color: var(--accent); }

/* ================= Hojas ================= */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(2px);
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes slideUp { from { transform: translateY(100%) } to { transform: translateY(0) } }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 55;
  max-height: 92dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--bg);
  border-radius: 24px 24px 0 0;
  border-top: 1px solid var(--border);
  padding: 6px 16px calc(20px + var(--safe-bottom));
  animation: slideUp .28s cubic-bezier(.22,.61,.36,1);
}
@media (min-width: 640px) {
  .sheet {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: 520px;
    bottom: 24px;
    border-radius: 24px;
    border: 1px solid var(--border);
    animation: fade .2s ease;
  }
  .sheet__grab { display: none; }
}

.sheet__grab { width: 38px; height: 5px; border-radius: 99px; background: var(--border); margin: 4px auto 10px; }
.sheet__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet__head h2 { font-size: 18px; font-weight: 800; letter-spacing: -0.01em; }

/* ================= Formulario ================= */
.form { display: flex; flex-direction: column; gap: 15px; }
.field { display: flex; flex-direction: column; gap: 6px; border: 0; padding: 0; margin: 0; min-width: 0; }
.field__label { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); }
.field__hint { font-size: 11.5px; color: var(--muted); }

.field__input {
  width: 100%;
  min-height: 48px;
  padding: 12px 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  appearance: none;
  transition: border-color .15s ease;
}
.field__input:focus { outline: none; border-color: var(--accent); }
.field__input::placeholder { color: var(--muted); font-weight: 400; }

select.field__input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6' fill='none' stroke='%239b97af' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 18px;
  padding-right: 38px;
}

.duration-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mini-field { display: flex; flex-direction: column; gap: 4px; }
.mini-field span { font-size: 10.5px; color: var(--muted); text-align: center; font-weight: 700; text-transform: uppercase; }
.mini-field .field__input { text-align: center; font-variant-numeric: tabular-nums; }

.chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 2px; }
.chip {
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all .15s ease;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

.swatches { display: flex; flex-wrap: wrap; gap: 11px; }
.swatch {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 2px solid transparent;
  background: var(--sw);
  cursor: pointer;
  position: relative;
  padding: 0;
  transition: transform .12s ease;
}
.swatch:active { transform: scale(.93); }
.swatch[aria-checked="true"] { border-color: var(--ink); transform: scale(1.06); }
.swatch[aria-checked="true"]::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: rgba(255,255,255,.95);
  box-shadow: 0 0 0 1px rgba(0,0,0,.22);
}

.preview {
  background: var(--surface);
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.preview__row { display: flex; justify-content: space-between; align-items: baseline; font-size: 12.5px; color: var(--ink-2); gap: 10px; }
.preview__row b { color: var(--ink); font-weight: 800; font-variant-numeric: tabular-nums; }

.form__actions {
  display: flex;
  gap: 10px;
  padding-top: 4px;
  position: sticky;
  bottom: 0;
  background: linear-gradient(to top, var(--bg) 74%, transparent);
  padding-bottom: calc(8px + var(--safe-bottom));
  margin-bottom: calc(-8px - var(--safe-bottom));
}
.btn {
  flex: 1;
  min-height: 50px;
  border-radius: 15px;
  border: 1px solid transparent;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  transition: filter .15s ease, opacity .15s ease;
}
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { filter: brightness(1.08); }
.btn--ghost { flex: 0 0 auto; padding: 0 18px; background: transparent; border-color: var(--border); color: var(--crit); }
.btn--ghost:hover { background: color-mix(in srgb, var(--crit) 12%, transparent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ================= Toast ================= */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + 40px + var(--safe-bottom) + 48px);
  transform: translateX(-50%) translateY(10px);
  z-index: 70;
  max-width: calc(100vw - 32px);
  padding: 11px 16px;
  border-radius: 13px;
  background: var(--ink);
  color: var(--bg);
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 10px 28px rgba(0,0,0,.35);
  opacity: 0;
  transition: opacity .18s ease, transform .18s ease;
  pointer-events: none;
}
.toast[data-open="true"] { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
