/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --bg:          #f2f2f7;
  --surface:     #ffffff;
  --nav-bg:      #1c1c1e;
  --nav-text:    #ffffffcc;
  --nav-active:  #ffffff;
  --text:        #1c1c1e;
  --text-muted:  #6e6e73;
  --border:      #d1d1d6;
  --accent:      #0071e3;
  --accent-h:    #0077ed;
  --danger:      #ff3b30;
  --radius:      12px;
  --radius-sm:   8px;
  --shadow:      0 2px 12px rgba(0,0,0,.08);
  --shadow-md:   0 8px 30px rgba(0,0,0,.15);
  --transition:  .18s ease;
  --nav-h:       56px;
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
}
button { font: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font: inherit; }
a { color: inherit; text-decoration: none; }

/* ── Nav ───────────────────────────────────────────────────────────────────── */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-h);
  background: var(--nav-bg);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
}

.nav-brand {
  font-weight: 700;
  font-size: .95rem;
  color: var(--nav-active);
  letter-spacing: -.02em;
  white-space: nowrap;
  flex-shrink: 0;
}

.nav-tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.nav-tabs::-webkit-scrollbar { display: none; }

.nav-tab {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: .85rem;
  color: var(--nav-text);
  white-space: nowrap;
  transition: background var(--transition), color var(--transition);
}
.nav-tab:hover  { background: rgba(255,255,255,.1); color: #fff; }
.nav-tab.active { background: rgba(255,255,255,.18); color: var(--nav-active); font-weight: 600; }

.nav-menu-toggle { display: none; color: var(--nav-active); font-size: 1.2rem; margin-left: auto; }

/* ── Stats bar ─────────────────────────────────────────────────────────────── */
.stats-bar {
  display: flex;
  gap: 12px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.stats-bar::-webkit-scrollbar { display: none; }

.stat-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  background: var(--bg);
  border-radius: 20px;
  font-size: .78rem;
  white-space: nowrap;
  color: var(--text-muted);
}
.stat-chip strong { color: var(--text); font-size: .9rem; }

/* ── Main ──────────────────────────────────────────────────────────────────── */
.main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.section-title {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -.03em;
}

.section-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.search-input {
  height: 38px;
  padding: 0 14px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  outline: none;
  width: 200px;
  transition: border-color var(--transition), width var(--transition);
  font-size: .9rem;
}
.search-input:focus { border-color: var(--accent); width: 240px; }

/* ── Grid ──────────────────────────────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

/* ── Card ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform var(--transition), box-shadow var(--transition);
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.card-name {
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.3;
  flex: 1;
}

.score-badge {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: .9rem;
  color: #fff;
}
.score-1,.score-2,.score-3,.score-4 { background: #ff3b30; }
.score-5,.score-6                   { background: #ff9500; }
.score-7,.score-8                   { background: #34c759; }
.score-9,.score-10                  { background: #007aff; }
.score-none { background: var(--border); color: var(--text-muted); }

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

.badge {
  font-size: .72rem;
  padding: 2px 9px;
  border-radius: 10px;
  background: var(--bg);
  color: var(--text-muted);
  font-weight: 500;
}
.badge-estado-viendo,
.badge-estado-leyendo  { background: #e8f4fd; color: #0071e3; }
.badge-estado-vista,
.badge-estado-leido    { background: #eafaf1; color: #1a8a3a; }
.badge-estado-pendiente { background: #fef9e7; color: #9a6a00; }
.badge-estado-abandonada,
.badge-estado-abandonado { background: #fdecea; color: #c0392b; }

.card-notes {
  font-size: .83rem;
  color: var(--text-muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-actions {
  display: flex;
  gap: 8px;
  margin-top: auto;
  padding-top: 4px;
  border-top: 1px solid var(--bg);
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: 20px;
  font-size: .875rem;
  font-weight: 600;
  transition: background var(--transition), opacity var(--transition);
  white-space: nowrap;
}
.btn:active { opacity: .85; }

.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); }

.btn-secondary { background: var(--bg); color: var(--text); border: 1.5px solid var(--border); }
.btn-secondary:hover { background: var(--border); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .88; }

.btn-ghost {
  font-size: .8rem;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
}
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-ghost.danger:hover { background: #fdecea; color: var(--danger); }

/* ── Empty state ───────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state p { margin-bottom: 20px; font-size: .95rem; }

/* ── Loading ───────────────────────────────────────────────────────────────── */
.loading-row {
  grid-column: 1 / -1;
  text-align: center;
  padding: 48px;
  color: var(--text-muted);
  font-size: .9rem;
}

/* ── Overlay / Modal ───────────────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 500px;
  max-height: 90dvh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.modal-sm { max-width: 360px; }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h2 { font-size: 1.15rem; font-weight: 700; }

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg);
  color: var(--text-muted);
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.modal-close:hover { background: var(--border); color: var(--text); }

.confirm-msg { font-size: .95rem; color: var(--text); }

/* ── Form ──────────────────────────────────────────────────────────────────── */
.form-fields { display: flex; flex-direction: column; gap: 14px; }

.form-group { display: flex; flex-direction: column; gap: 5px; }

.form-group label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.form-group input,
.form-group select,
.form-group textarea {
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition);
  width: 100%;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--accent); background: var(--surface); }

.form-group textarea { resize: vertical; min-height: 80px; }

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .nav-tabs { display: none; }
  .nav-tabs.open {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: var(--nav-h);
    left: 0;
    right: 0;
    background: var(--nav-bg);
    padding: 8px 12px 16px;
    gap: 4px;
    z-index: 99;
  }
  .nav-tabs.open .nav-tab { border-radius: var(--radius-sm); text-align: left; }
  .nav-menu-toggle { display: block; }

  .section-header { flex-direction: column; align-items: stretch; }
  .section-actions { justify-content: space-between; }
  .search-input { flex: 1; width: auto; }
  .search-input:focus { width: auto; }

  .grid { grid-template-columns: 1fr; }
}
