:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #1f2933;
  --muted: #6b7280;
  --line: #e3e6ea;
  --brand: #2f6f4f;
  --brand-ink: #ffffff;
  --error: #b3261e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.5rem 1.25rem;
  background: var(--brand);
  color: var(--brand-ink);
  position: relative;
  z-index: 20;
}
.brand { color: var(--brand-ink); text-decoration: none; font-weight: 600; white-space: nowrap; }
.topnav { display: flex; align-items: center; gap: 1rem; margin-left: auto; }

/* Menú superior con desplegables (hover y teclado) */
.menu ul { list-style: none; margin: 0; padding: 0; }
.menu > ul { display: flex; flex-wrap: wrap; gap: 0.15rem; }
.menu > ul > li { position: relative; }
.menu > ul > li > a {
  display: block; padding: 0.45rem 0.75rem; border-radius: 6px;
  color: var(--brand-ink); text-decoration: none; font-size: 0.95rem; white-space: nowrap;
}
.menu > ul > li:hover > a, .menu > ul > li:focus-within > a { background: rgba(255,255,255,0.14); }
.menu > ul > li.active > a { background: rgba(255,255,255,0.22); font-weight: 600; }
.menu > ul > li > ul {
  display: none; position: absolute; left: 0; top: 100%; min-width: 13rem;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.12); padding: 0.35rem 0; z-index: 30;
}
.menu > ul > li:hover > ul, .menu > ul > li:focus-within > ul { display: block; }
.menu > ul > li > ul > li > a {
  display: block; padding: 0.45rem 0.9rem; color: var(--ink); text-decoration: none; font-size: 0.92rem; white-space: nowrap;
}
.menu > ul > li > ul > li > a:hover, .menu > ul > li > ul > li > a:focus { background: var(--bg); color: var(--brand); }
@media (max-width: 720px) {
  .menu { order: 3; width: 100%; }
  .menu > ul { gap: 0; }
  .menu > ul > li > a { padding: 0.4rem 0.55rem; font-size: 0.9rem; }
}
.user { opacity: 0.9; font-size: 0.9rem; }
.inline { display: inline; margin: 0; }
.linkbtn {
  background: none; border: 0; color: var(--brand-ink);
  text-decoration: underline; cursor: pointer; font: inherit; padding: 0;
}

.container { max-width: 960px; margin: 2rem auto; padding: 0 1.25rem; }

h1 { font-size: 1.5rem; margin-top: 0; }
.muted { color: var(--muted); }
.error { color: var(--error); font-weight: 500; }
.ok-msg { color: #1d6b3f; font-weight: 500; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.5rem;
}
.auth { max-width: 360px; margin: 3rem auto; }

.stack { display: flex; flex-direction: column; gap: 1rem; }
label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.9rem; color: var(--muted); }
input {
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 1rem;
  color: var(--ink);
}
input:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: var(--brand); }

button[type="submit"] {
  padding: 0.6rem 1rem;
  background: var(--brand);
  color: var(--brand-ink);
  border: 0;
  border-radius: 6px;
  font-size: 1rem;
  cursor: pointer;
}
button[type="submit"]:hover { filter: brightness(1.05); }

table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 8px; }
th, td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
td.num, th.num { text-align: right; }

textarea, select {
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--ink);
  background: #fff;
}
textarea:focus, select:focus { outline: 2px solid var(--brand); border-color: var(--brand); }

/* Navegación por tarjetas */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; margin-top: 1.5rem; }
.navcard {
  display: block; text-decoration: none; color: inherit;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 1rem 1.1rem;
}
.navcard:hover { border-color: var(--brand); box-shadow: 0 2px 8px rgba(0,0,0,0.05); }
.navcard h3 { margin: 0 0 0.25rem; font-size: 1.05rem; }
.navcard p { margin: 0; color: var(--muted); font-size: 0.9rem; }

/* Migas y formularios */
.crumbs { color: var(--muted); font-size: 0.9rem; margin-bottom: 0.25rem; }
.crumbs a { color: var(--brand); text-decoration: none; }
.row { display: flex; gap: 1rem; align-items: flex-end; }
.row.wrap { flex-wrap: wrap; }
.row.gap { gap: 0.75rem; align-items: center; }
.endrow { margin-left: auto; align-self: flex-end; }
.card.row, .card.stack { margin-bottom: 1.5rem; }

.actions { display: flex; gap: 0.75rem; align-items: center; white-space: nowrap; }
.actions a { color: var(--brand); text-decoration: none; }
.danger { color: var(--error); }
.btn-sec {
  display: inline-block; padding: 0.55rem 0.9rem; border: 1px solid var(--line);
  border-radius: 6px; text-decoration: none; color: var(--ink); background: #fff;
}

.badge { padding: 0.1rem 0.5rem; border-radius: 99px; font-size: 0.8rem; }
.badge.abierto { background: #e7f4ec; color: #1d6b3f; }
.badge.cerrado { background: #eee; color: #555; }

/* Editor de coeficientes */
.sumbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 1rem;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: 0.6rem 1rem; margin-bottom: 0.75rem;
}
.sumbar button { margin-left: auto; }
.sumbar .mini { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.85rem; color: var(--muted); margin-left: auto; }
.sumbar .mini + button { margin-left: 0.75rem; }
.sumbar .ok { color: #1d6b3f; font-weight: 600; }
.sumbar .warn { color: var(--error); font-weight: 600; }
.coefinput { width: 7rem; text-align: right; }

.tabs { display: flex; gap: 0.5rem; }
.tabs a {
  padding: 0.35rem 0.8rem; border: 1px solid var(--line); border-radius: 6px;
  text-decoration: none; color: var(--ink); background: #fff;
}
.tabs a.active { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
td.danger, th.danger { color: var(--error); }
tfoot th { border-top: 2px solid var(--line); }
.recibo-head { display: flex; justify-content: space-between; align-items: flex-start; }
@media print {
  .topbar, .no-print, .crumbs { display: none !important; }
  .container { margin: 0; max-width: none; }
  .card { border: none; padding: 0; }
}

/* Importación de documentos con IA */
.badge.procesando { background: #fff4d6; color: #8a5a00; }
.badge.revisando { background: #e3edf9; color: #1f4e8c; }
.badge.importada { background: #e7f4ec; color: #1d6b3f; }
.badge.error { background: #fde8e6; color: var(--error); }
.badge.pendiente { background: #eee; color: #555; }
.badge.alta { background: #e7f4ec; color: #1d6b3f; }
.badge.media { background: #fff4d6; color: #8a5a00; }
.badge.baja { background: #fde8e6; color: var(--error); }
.badge.ent { background: #eef1f5; color: #37475a; font-family: ui-monospace, monospace; }
.spinner {
  display: inline-block; width: 1em; height: 1em; border: 2px solid var(--line);
  border-top-color: var(--brand); border-radius: 50%; animation: giro 0.8s linear infinite; vertical-align: -0.15em;
}
@keyframes giro { to { transform: rotate(360deg); } }
.preguntas { background: #fff8e6; border: 1px solid #f1dfa8; border-radius: 8px; padding: 0.75rem 1rem; margin: 1rem 0; }
.preguntas ul { margin: 0.25rem 0 0; padding-left: 1.2rem; }
.item { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 0.75rem 1rem; margin-bottom: 0.6rem; }
.item.importado { opacity: 0.7; }
.item.descartado { opacity: 0.5; }
.item.error { border-color: var(--error); }
.item .head { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.item .head .orden { color: var(--muted); font-size: 0.85rem; }
.item .dudas { color: #8a5a00; font-size: 0.85rem; margin: 0.25rem 0 0; }
.item .campos { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 0.5rem; align-items: flex-end; }
.item .campos label { font-size: 0.8rem; }
.item .campos input, .item .campos select { padding: 0.35rem 0.5rem; font-size: 0.9rem; }
.item .campos input.corto { width: 7rem; }
.item .campos input.medio { width: 11rem; }
.item .campos input.largo { width: 18rem; }
.item details { margin-top: 0.4rem; font-size: 0.9rem; }
.item details summary { cursor: pointer; color: var(--brand); }
.item .acciones { display: flex; gap: 0.5rem; align-items: center; margin-top: 0.5rem; }
.item .acciones button { padding: 0.4rem 0.8rem; font-size: 0.9rem; }
.btn-sec.small, button.small { padding: 0.35rem 0.7rem; font-size: 0.85rem; }
.btn-danger { background: var(--error) !important; }
.chat { display: flex; flex-direction: column; gap: 0.5rem; max-height: 28rem; overflow-y: auto; padding: 0.5rem 0; }
.chat .msg { max-width: 85%; padding: 0.6rem 0.9rem; border-radius: 10px; white-space: pre-wrap; font-size: 0.95rem; }
.chat .msg.user { align-self: flex-end; background: #e3edf9; }
.chat .msg.ia { align-self: flex-start; background: #f0f2f5; }
.chat .msg .quien { display: block; font-size: 0.75rem; color: var(--muted); margin-bottom: 0.2rem; }
.toolbar { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; margin: 1rem 0; }
.filebox { padding: 1rem; border: 2px dashed var(--line); border-radius: 8px; background: #fff; }
.filebox input[type="file"] { border: 0; padding: 0; }

.card.peligro { border-color: #f1c4c0; background: #fffafa; }
