:root {
  --bg: #f4f4f8;
  --bg-translucent: rgba(244, 244, 248, .82);
  --card: #ffffff;
  --text: #1b1b2b;
  --text-dim: #6b7280;
  --accent: #6366f1;
  --accent-strong: #4f46e5;
  --accent-soft: rgba(99, 102, 241, .1);
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --border: #e5e7eb;
  --shadow: 0 1px 2px rgba(17, 17, 34, .05), 0 2px 8px rgba(17, 17, 34, .06);
  --shadow-lift: 0 2px 4px rgba(17, 17, 34, .06), 0 8px 24px rgba(17, 17, 34, .1);
  --cat-familia: #e11d48;
  --cat-amistad: #0284c7;
  --cat-conocido: #64748b;
  --cat-negocios: #059669;
  --avatar-1: #e11d48;
  --avatar-2: #ea580c;
  --avatar-3: #b45309;
  --avatar-4: #65a30d;
  --avatar-5: #16a34a;
  --avatar-6: #059669;
  --avatar-7: #0d9488;
  --avatar-8: #0891b2;
  --avatar-9: #2563eb;
  --avatar-10: #7c3aed;
  --avatar-11: #9333ea;
  --avatar-12: #db2777;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1016;
    --bg-translucent: rgba(15, 16, 22, .82);
    --card: #1a1b26;
    --text: #ececf4;
    --text-dim: #9ca3af;
    --accent: #818cf8;
    --accent-strong: #6366f1;
    --accent-soft: rgba(129, 140, 248, .14);
    --green: #4ade80;
    --amber: #fbbf24;
    --red: #f87171;
    --border: #2b2c3b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 2px 8px rgba(0, 0, 0, .35);
    --shadow-lift: 0 2px 4px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

button { font-family: inherit; }

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

/* ---------- layout ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + var(--safe-top)) 18px 10px;
  background: var(--bg-translucent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  max-width: 640px;
  margin: 0 auto;
}

.topbar h1 {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -.02em;
}

#main {
  padding: 0 14px calc(96px + var(--safe-bottom));
  max-width: 640px;
  margin: 0 auto;
}

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  background: var(--bg-translucent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 9px 0 7px;
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .01em;
  cursor: pointer;
  transition: color .15s ease;
}

.tab.active { color: var(--accent); }

.tab-icon {
  position: relative;
  display: inline-flex;
  line-height: 0;
}

.tab.active .tab-icon svg { fill: var(--accent-soft); }

.tab-badge {
  position: absolute;
  top: -5px;
  right: -10px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  line-height: 17px;
  text-align: center;
}

.btn-fab {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(79, 70, 229, .35);
  transition: transform .12s ease, box-shadow .12s ease;
}
.btn-fab:hover { box-shadow: 0 4px 14px rgba(79, 70, 229, .45); }
.btn-fab:active { transform: scale(.92); }

/* ---------- sections & cards ---------- */

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-dim);
  margin: 20px 6px 10px;
}

.count-pill {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 12px;
  letter-spacing: 0;
}

.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 56px 24px;
  line-height: 1.65;
  font-size: 15px;
}
.empty .big { font-size: 44px; display: block; margin-bottom: 12px; }
.empty-icon {
  display: flex;
  justify-content: center;
  margin-bottom: 14px;
  color: var(--accent);
  opacity: .75;
}
.empty-detail { font-size: 13px; opacity: .8; margin-top: 4px; }
.btn-retry { max-width: 200px; margin: 18px auto 0; }

.swipe-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}

.swipe-bg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  color: #fff;
  font-size: 15px;
}
.swipe-bg .bg-done  { background: var(--green); flex: 1; height: 100%; display: flex; align-items: center; padding-left: 18px; }
.swipe-bg .bg-snooze{ background: var(--amber); flex: 1; height: 100%; display: flex; align-items: center; justify-content: flex-end; padding-right: 18px; }

.card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 13px;
  background: var(--card);
  padding: 14px 15px;
  touch-action: pan-y;
  cursor: pointer;
  will-change: transform;
}

.card.removing { transition: transform .25s ease, opacity .25s ease; opacity: 0; }
.card.snap-back { transition: transform .2s ease; }

.avatar {
  position: relative;
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: .02em;
  background-image: linear-gradient(145deg, rgba(255,255,255,.22), rgba(0,0,0,.12));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.12);
}

.avatar-badge {
  position: absolute;
  bottom: -3px;
  right: -3px;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: var(--card);
  box-shadow: 0 0 0 2px var(--card), var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  line-height: 1;
}

.card-body { flex: 1; min-width: 0; }
.card-name {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-label {
  color: var(--text-dim);
  font-size: 13.5px;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-meta {
  flex-shrink: 0;
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 7px;
}

.badge {
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-overdue { background: rgba(220,38,38,.12); color: var(--red); }
.badge-today   { background: rgba(217,119,6,.14); color: var(--amber); }
.badge-future  { background: rgba(107,114,128,.1); color: var(--text-dim); }

@media (prefers-color-scheme: dark) {
  .badge-overdue { background: rgba(248,113,113,.15); }
  .badge-today   { background: rgba(251,191,36,.14); }
  .badge-future  { background: rgba(156,163,175,.12); }
}

.card-actions { display: flex; gap: 6px; }

.mini-btn {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text-dim);
  border-radius: 9px;
  padding: 5px 11px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color .12s ease, color .12s ease, background .12s ease;
}
.mini-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.mini-btn:active { transform: scale(.95); }
.mini-btn-danger:hover { border-color: var(--red); color: var(--red); background: rgba(220,38,38,.08); }

/* ---------- skeletons ---------- */

.skeleton-card {
  display: flex;
  align-items: center;
  gap: 13px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 15px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  margin-top: 10px;
}
.skeleton-card:first-child { margin-top: 20px; }
.skeleton-avatar { width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0; }
.skeleton-lines { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.skeleton-line { height: 12px; border-radius: 6px; }

.shimmer {
  background: linear-gradient(90deg, var(--border) 25%, var(--bg) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite linear;
}
@keyframes shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

/* ---------- people list ---------- */

.search-wrap { margin: 14px 2px 0; }
.search-input {
  -webkit-appearance: none;
}

.person-row {
  display: flex;
  align-items: center;
  gap: 13px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 13px 15px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}
.person-row:hover { box-shadow: var(--shadow-lift); }
.person-row:active { transform: scale(.985); }
.person-row .card-label { font-size: 13px; }

.chevron {
  color: var(--text-dim);
  font-size: 22px;
  opacity: .5;
  flex-shrink: 0;
  line-height: 1;
}

/* ---------- sheet / modal ---------- */

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 20, .5);
  z-index: 20;
  animation: fade-in .18s ease;
}

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

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 21;
  background: var(--card);
  border-radius: 22px 22px 0 0;
  max-height: 88vh;
  overflow-y: auto;
  padding: 10px 20px calc(26px + var(--safe-bottom));
  max-width: 640px;
  margin: 0 auto;
  animation: slide-up .24s cubic-bezier(.2, .9, .3, 1);
  box-shadow: var(--shadow-lift);
}

@keyframes slide-up {
  from { transform: translateY(48px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

.sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 8px auto 16px;
}

.sheet h2 { font-size: 22px; letter-spacing: -.01em; margin-bottom: 4px; }
.sheet-sub { color: var(--text-dim); font-size: 14px; margin-bottom: 14px; line-height: 1.5; }

.sheet .section-title { margin-left: 0; margin-right: 0; }

.form-row { margin-bottom: 13px; }
.form-row label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 5px;
}

input[type=text], input[type=password], input[type=number], input[type=search], textarea, select {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  transition: border-color .12s ease, box-shadow .12s ease;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; min-height: 64px; }

.freq-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.freq-row input[type=text] { flex: 2.2; }
.freq-row .freq-cada { color: var(--text-dim); font-size: 14px; flex-shrink: 0; }
.freq-row input[type=number] { flex: .9; min-width: 58px; }
.freq-row select { flex: 1.3; min-width: 96px; }
.freq-row .row-del {
  border: none; background: none; color: var(--red);
  font-size: 20px; cursor: pointer; flex-shrink: 0; padding: 0 2px;
}

.btn {
  display: inline-block;
  border: none;
  border-radius: 12px;
  padding: 13px 18px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: transform .12s ease, box-shadow .12s ease, opacity .12s ease;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn:active:not(:disabled) { transform: scale(.98); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
  width: 100%;
  box-shadow: 0 2px 8px rgba(79, 70, 229, .3);
}
.btn-primary.busy { opacity: .7; }

.btn-ghost {
  background: none;
  border: 1px dashed var(--border);
  color: var(--accent);
  width: 100%;
  padding: 10px;
  font-size: 14px;
}
.btn-ghost:hover { border-color: var(--accent); background: var(--accent-soft); }

.btn-danger-link {
  background: none;
  color: var(--red);
  width: 100%;
  font-size: 14px;
  font-weight: 600;
  padding: 12px;
}

.sheet-actions { display: flex; gap: 8px; margin-top: 18px; }

/* interaction rows in detail */

.int-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.int-row:last-of-type { border-bottom: none; }
.int-info { flex: 1; min-width: 0; }
.int-label { font-weight: 600; font-size: 15px; }
.int-meta { color: var(--text-dim); font-size: 13px; margin-top: 2px; }

.history-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}
.history-item:last-child { border-bottom: none; }
.history-date { color: var(--text-dim); white-space: nowrap; }

.cat-chip {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  border-radius: 999px;
  padding: 3px 10px;
  vertical-align: middle;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  bottom: calc(78px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  background: var(--text);
  color: var(--bg);
  border-radius: 14px;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-lift);
  max-width: 92vw;
  animation: toast-in .2s ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
.toast.toast-error { background: var(--red); color: #fff; }
.toast button {
  border: none;
  background: none;
  color: #a5b4fc;
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
}
.toast.toast-error button { color: #fff; text-decoration: underline; }

/* ---------- login ---------- */

.login {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(1200px 500px at 50% -10%, var(--accent-soft), transparent 60%),
    var(--bg);
  z-index: 50;
  padding: 24px;
}
.login-box { width: 100%; max-width: 320px; text-align: center; }
.login-icon {
  width: 76px;
  height: 76px;
  border-radius: 20px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-lift);
}
.login-box h1 { letter-spacing: -.02em; margin-bottom: 4px; }
.login-sub { color: var(--text-dim); font-size: 14px; margin-bottom: 22px; }
.login-box input { margin-bottom: 12px; text-align: center; }
.login-error { color: var(--red); font-size: 14px; margin-top: 10px; min-height: 18px; }

/* ---------- reduced motion & desktop ---------- */

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

@media (min-width: 700px) {
  .sheet {
    border-radius: 22px;
    bottom: auto;
    top: 50%;
    transform: translateY(-50%);
    animation: none;
  }
}
