:root {
  --navy: #0c2d4a;
  --navy-soft: #1a4468;
  --gold: #c9a227;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --ink: #1a2332;
  --muted: #5c6778;
  --line: #d8dee8;
  --ok: #0d7a5f;
  --warn: #b45309;
  --danger: #b42318;
  --radius: 12px;
  --font: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
  --display: "Libre Baskerville", Georgia, serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  min-height: 100%;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    linear-gradient(105deg, rgba(12, 45, 74, 0.92) 0%, rgba(12, 45, 74, 0.78) 42%, rgba(12, 45, 74, 0.55) 100%),
    url("/comunidad/assets/edificio-garoe.jpg") center / cover no-repeat;
  filter: grayscale(1);
  z-index: -2;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at 20% 0%, rgba(201, 162, 39, 0.12), transparent 55%);
  z-index: -1;
  pointer-events: none;
}

.shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
  max-width: 1400px;
  margin: 0 auto;
}

@media (max-width: 960px) {
  .shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 20;
    max-height: none;
  }
}

.sidebar {
  background: rgba(255, 255, 255, 0.97);
  border-right: 1px solid var(--line);
  padding: 20px 16px 24px;
  overflow-y: auto;
  max-height: 100vh;
}

.brand {
  text-align: center;
  margin-bottom: 16px;
}

.brand img {
  width: 120px;
  height: 120px;
  object-fit: contain;
  border-radius: 50%;
  border: 3px solid var(--navy);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.brand h1 {
  font-family: var(--display);
  font-size: 1.15rem;
  color: var(--navy);
  margin: 10px 0 4px;
  line-height: 1.25;
}

.brand p {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}

.nav a {
  display: block;
  padding: 8px 10px;
  margin-bottom: 4px;
  border-radius: 8px;
  color: var(--ink);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 600;
}

.nav a:hover,
.nav a.active {
  background: var(--navy);
  color: #fff;
}

.back-play {
  display: inline-block;
  margin-bottom: 12px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--navy-soft);
  text-decoration: none;
}

.back-play:hover {
  text-decoration: underline;
}

.main {
  padding: 24px 20px 48px;
  overflow-y: auto;
}

.hero-card {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 18px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
}

.hero-card h2 {
  font-family: var(--display);
  color: var(--navy);
  margin: 0 0 8px;
  font-size: clamp(1.35rem, 2.5vw, 1.75rem);
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--muted);
}

.chip {
  background: #eef3f8;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  font-weight: 600;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 16px 0;
}

@media (max-width: 720px) {
  .stats {
    grid-template-columns: 1fr 1fr;
  }
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
}

.stat .n {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--navy);
}

.stat .l {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.panel {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 14px;
  overflow: hidden;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.06);
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 16px;
  background: linear-gradient(90deg, var(--navy), var(--navy-soft));
  color: #fff;
  cursor: pointer;
  user-select: none;
}

.panel-head h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.panel-body {
  display: none;
  padding: 12px 16px 16px;
}

.panel.open .panel-body {
  display: block;
}

.checklist {
  list-style: none;
  margin: 0;
  padding: 0;
}

.checklist li {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: start;
  padding: 10px 0;
  border-bottom: 1px solid #edf1f6;
  font-size: 0.9rem;
}

.checklist li:last-child {
  border-bottom: none;
}

.checklist input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: var(--navy);
}

.checklist li.done {
  opacity: 0.65;
}

.checklist li.done .item-text {
  text-decoration: line-through;
}

.estado {
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.estado.abierta {
  background: #fef3c7;
  color: #92400e;
}

.estado.cerrada {
  background: #d1fae5;
  color: var(--ok);
}

.estado.seguimiento,
.estado.presupuesto {
  background: #dbeafe;
  color: #1e40af;
}

.estado.bloqueada {
  background: #fee2e2;
  color: var(--danger);
}

.estado.historico,
.estado.informativo {
  background: #f3f4f6;
  color: var(--muted);
}

.subzona {
  margin: 12px 0 4px;
  font-weight: 800;
  color: var(--navy-soft);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.note {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 4px;
}

.docs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}

.doc-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: #fafbfc;
}

.doc-card a {
  color: var(--navy);
  font-weight: 700;
  text-decoration: none;
}

.doc-card a:hover {
  text-decoration: underline;
}

.doc-cat {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  font-weight: 700;
}

table.presup {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

table.presup th,
table.presup td {
  border-bottom: 1px solid var(--line);
  padding: 8px 6px;
  text-align: left;
}

table.presup th {
  font-size: 0.72rem;
  text-transform: uppercase;
  color: var(--muted);
}

.legal {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 0.88rem;
  line-height: 1.55;
}

.legal ul {
  margin: 8px 0 0;
  padding-left: 1.2rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.btn {
  font: inherit;
  font-weight: 700;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--navy);
}

.btn.primary {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}

.btn:hover {
  filter: brightness(1.05);
}

.preguntas li {
  margin-bottom: 8px;
  font-weight: 600;
}

.nav a.dragging {
  opacity: 0.45;
}

.nav a.drag-over {
  outline: 2px dashed var(--gold);
  outline-offset: 2px;
}

.badge-prog {
  font-size: 0.72rem;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.2);
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: 6px;
}

.toast {
  position: fixed;
  bottom: 88px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--navy);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.88rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 60;
}

.toast.show {
  opacity: 1;
}

.chat-fab {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--gold), #e8c547);
  color: var(--navy);
  font-size: 1.4rem;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.25);
  z-index: 55;
}

.chat-panel {
  position: fixed;
  right: 20px;
  bottom: 88px;
  width: min(400px, calc(100vw - 32px));
  max-height: min(520px, 70vh);
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.2);
  transform: translateY(12px) scale(0.96);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 54;
}

.chat-panel.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.chat-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, var(--navy), var(--navy-soft));
  color: #fff;
  border-radius: var(--radius) var(--radius) 0 0;
}

.chat-head p {
  margin: 4px 0 0;
  font-size: 0.78rem;
  opacity: 0.85;
}

.chat-clear {
  border: none;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 6px 8px;
  cursor: pointer;
}

.chat-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}

.chat-quick button {
  font: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  border: 1px solid var(--line);
  background: #f8fafc;
  border-radius: 999px;
  padding: 5px 10px;
  cursor: pointer;
  color: var(--navy);
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
  font-size: 0.86rem;
  line-height: 1.45;
}

.chat-msg {
  margin-bottom: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  max-width: 95%;
}

.chat-msg.user {
  margin-left: auto;
  background: #e8f0fa;
  color: var(--ink);
}

.chat-msg.assistant {
  background: #f4f6f9;
  border: 1px solid var(--line);
}

.chat-form {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--line);
}

.chat-form input {
  flex: 1;
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}

.chat-form button {
  font: inherit;
  font-weight: 700;
  background: var(--navy);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}

/* ——— Móvil ——— */
.mobile-bar {
  display: none;
}

.nav-overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 45, 74, 0.45);
  z-index: 40;
  backdrop-filter: blur(2px);
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -4px;
  padding-bottom: 4px;
}

@media (max-width: 960px) {
  .mobile-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    position: sticky;
    top: 0;
    z-index: 35;
    padding: max(10px, env(safe-area-inset-top)) 12px 10px;
    background: rgba(255, 255, 255, 0.96);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  }

  .mobile-menu-btn,
  .mobile-chat-btn {
    font: inherit;
    font-weight: 700;
    font-size: 0.82rem;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--navy);
    border-radius: 10px;
    padding: 10px 12px;
    min-height: 44px;
    cursor: pointer;
  }

  .mobile-chat-btn {
    min-width: 44px;
    padding: 10px;
    font-size: 1.1rem;
  }

  .mobile-brand {
    font-family: var(--display);
    font-weight: 700;
    color: var(--navy);
    text-decoration: none;
    font-size: 1.05rem;
  }

  .shell {
    grid-template-columns: 1fr;
    max-width: none;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(300px, 88vw);
    max-height: none;
    z-index: 45;
    transform: translateX(-105%);
    transition: transform 0.25s ease;
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.18);
    padding-bottom: max(24px, env(safe-area-inset-bottom));
  }

  .sidebar.open {
    transform: translateX(0);
  }

  body.nav-open {
    overflow: hidden;
  }

  .main {
    padding: 14px 12px calc(96px + env(safe-area-inset-bottom));
  }

  .hero-card {
    padding: 16px 14px;
  }

  .hero-meta {
    font-size: 0.8rem;
    line-height: 1.4;
  }

  .toolbar {
    flex-direction: column;
  }

  .toolbar .btn {
    width: 100%;
    min-height: 44px;
    text-align: center;
  }

  .panel-head {
    padding: 12px 14px;
  }

  .panel-head h3 {
    font-size: 0.92rem;
    line-height: 1.35;
    flex: 1;
    min-width: 0;
  }

  .checklist li {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 8px 10px;
    padding: 12px 0;
  }

  .checklist input[type="checkbox"] {
    width: 22px;
    height: 22px;
    margin-top: 2px;
    flex-shrink: 0;
  }

  .checklist li > div,
  .checklist li > .item-text {
    flex: 1 1 calc(100% - 36px);
    min-width: 0;
  }

  .checklist li > .estado {
    flex: 1 1 100%;
    margin-left: 34px;
    white-space: normal;
  }

  .nav a {
    padding: 12px 10px;
    font-size: 0.9rem;
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .brand img {
    width: 96px;
    height: 96px;
  }

  .chat-fab {
    right: max(16px, env(safe-area-inset-right));
    bottom: max(16px, env(safe-area-inset-bottom));
    width: 52px;
    height: 52px;
  }

  .chat-panel {
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: min(85vh, 640px);
    border-radius: var(--radius) var(--radius) 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .chat-panel.open {
    transform: translateY(0);
  }

  .chat-form {
    flex-wrap: wrap;
  }

  .chat-form input {
    min-height: 44px;
    font-size: 16px;
  }

  .chat-form button {
    min-height: 44px;
    flex: 1;
  }

  .toast {
    bottom: calc(80px + env(safe-area-inset-bottom));
    max-width: calc(100vw - 32px);
    text-align: center;
  }

  table.presup {
    min-width: 520px;
  }
}

@media (max-width: 480px) {
  .stats {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .stat {
    padding: 10px 8px;
  }

  .stat .n {
    font-size: 1.25rem;
  }

  .stat .l {
    font-size: 0.65rem;
  }

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

  .chat-quick button {
    flex: 1 1 calc(50% - 6px);
    min-height: 40px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .chat-panel,
  .toast {
    transition: none;
  }
}
