/* ===== ViviendaSion — STOCK (estética moderna, minimal, coherente con index) ===== */
:root {
  /* Marca desde index.css con fallback */
  --viviendasion-red: #dc2626;
  --viviendasion-red-dark: #b91c1c;

  /* Base dark unificada */
  --bg: #0f172a;
  /* fondo general */
  --bg-soft: #0b1220;
  /* fondo suave / headers */
  --panel: #111827;
  /* cards/containers */
  --panel-2: #0c1320;
  /* variante de panel */
  --bdr: #334155;
  /* bordes */
  --txt: #e5e7eb;
  /* texto */
  --muted: #9ca3af;
  /* texto tenue */

  /* Marca / acento */
  --brand: var(--viviendasion-red);
  --brand-2: var(--viviendasion-red-dark);

  /* Semánticos suaves (para pills de estado) */
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
}

/* ===== Reset mínimo ===== */
* {
  box-sizing: border-box
}

html,
body {
  height: 100%
}

body {
  margin: 0;
  color: var(--txt);
  background: var(--bg);
  font: 14px/1.5 Inter, system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, sans-serif;
}

.mxw {
  max-width: 1360px;
  margin: 0 auto
}

/* ===== Topbar ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(17, 24, 39, .95);
  /* #111827 */
  border-bottom: 1px solid var(--bdr);
  backdrop-filter: saturate(120%) blur(6px);
}

.topbar .mxw {
  padding: 14px 24px
}

.backlink {
  color: #cbd5e1;
  text-decoration: none;
  border-radius: 8px;
  padding: 4px 8px
}

.backlink:hover {
  color: #fff;
  background: rgba(148, 163, 184, .08)
}

.sep {
  width: 1px;
  height: 24px;
  background: #334155;
  margin: 0 8px
}

.ttl {
  font-weight: 700;
  font-size: 18px
}

.brand {
  color: var(--brand)
}

/* ===== Tabs (píldoras minimalistas) ===== */
.tabs {
  display: flex;
  gap: 8px
}

.tab {
  background: var(--panel);
  border: 1px solid var(--bdr);
  color: #cbd5e1;
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}

.tab:hover {
  background: #0f172a;
  color: #fff
}

.tab.active {
  background: #1b0f0f;
  color: #ffecec;
  border-color: #7f1d1d;
}

/* ===== Botones / Inputs ===== */
.btn {
  background: var(--panel);
  color: #e5e7eb;
  border: 1px solid var(--bdr);
  padding: 9px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: filter .15s, box-shadow .15s, transform .03s;
}

.btn:hover {
  filter: brightness(1.06)
}

.btn:active {
  transform: translateY(1px)
}

.btn.subtle {
  background: var(--panel-2)
}

.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--txt)
}

.btn.primary {
  background: linear-gradient(180deg, var(--brand), var(--brand-2));
  border-color: #7f1d1d;
  color: #fff;
  box-shadow: 0 0 0 0 rgba(220, 38, 38, 0);
}

.btn.primary:hover {
  box-shadow: 0 0 0 3px rgba(220, 38, 38, .15)
}

.inp {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--bdr);
  color: var(--txt);
  padding: 9px 10px;
  border-radius: 10px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.inp:focus {
  border-color: #7f1d1d;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, .15);
}

/* Botones de color (mantener HTML existente pero minimalistas) */
.btn.blue {
  background: var(--panel);
  border-color: #1e3a8a;
  color: #c7d2fe
}

.btn.blue:hover {
  box-shadow: 0 0 0 3px rgba(59, 130, 246, .15)
}

.btn.green {
  background: var(--panel);
  border-color: #14532d;
  color: #bbf7d0
}

.btn.green:hover {
  box-shadow: 0 0 0 3px rgba(34, 197, 94, .15)
}

.btn.purple {
  background: var(--panel);
  border-color: #4c1d95;
  color: #e9d5ff
}

.btn.purple:hover {
  box-shadow: 0 0 0 3px rgba(168, 85, 247, .15)
}

.btn.vs {
  background: var(--panel);
  border-color: #7f1d1d;
  color: #ffe2e2
}

.btn.vs:hover {
  box-shadow: 0 0 0 3px rgba(220, 38, 38, .15)
}

.tag {
  background: #101826;
  color: #cfe3f6;
  border: 1px solid #223248;
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 600;
}

/* ===== Toolbar objetivo ===== */
.obj-wrap {
  display: flex;
  gap: 10px;
  align-items: end;
  flex-wrap: wrap;
  background: var(--panel);
  border: 1px solid var(--bdr);
  border-radius: 14px;
  padding: 10px;
}

.obj-cell {
  min-width: 160px
}

.obj-cell label {
  display: block;
  font-size: 12px;
  color: var(--muted)
}

.obj-actions {
  display: flex;
  gap: 8px
}

.hint {
  font-size: 12px;
  color: var(--muted)
}

/* ===== Panel de ayuda (acordeón) ===== */
.deck {
  border: 1px solid var(--bdr);
  border-radius: 14px;
  background: var(--panel-2)
}

.deck-head {
  cursor: pointer;
  list-style: none;
  padding: 14px 16px;
  font-weight: 700;
  border-bottom: 1px solid var(--bdr);
  color: #d6dee9;
}

.deck[open] .deck-head {
  border-bottom: 1px solid var(--bdr)
}

.deck-grid {
  display: grid;
  gap: 14px;
  padding: 14px;
  grid-template-columns: repeat(4, minmax(0, 1fr))
}

@media (max-width:1200px) {
  .deck-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr))
  }
}

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

/* ===== Cards ===== */
.card {
  background: var(--panel);
  border: 1px solid var(--bdr);
  border-radius: 14px;
  padding: 16px
}

.card-ttl {
  font-weight: 700;
  margin: 0 0 8px
}

.card-sub {
  margin: 8px 0 6px;
  color: var(--muted);
  font-weight: 600
}

/* ===== Rubros / Tabla ===== */
#rubros>details {
  border: 1px solid var(--bdr);
  border-radius: 14px;
  overflow: hidden;
  margin-bottom: 14px;
  background: var(--panel);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
}

#rubros>details[open] summary {
  border-bottom: 1px solid var(--bdr)
}

#rubros summary {
  padding: 12px 14px;
  background: var(--bg-soft);
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-left: 4px solid var(--brand);
}

#rubros summary .count {
  color: #94a3b8;
  font-size: 12px;
  font-weight: 600
}

.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0
}

.table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #0f172a;
  color: #cbd5e1;
  font-weight: 700;
  font-size: 12px;
  border-bottom: 1px solid var(--bdr);
  padding: 12px 14px;
  text-align: left;
  white-space: nowrap;
  backdrop-filter: blur(2px);
}

.table tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid #1e293b;
  vertical-align: middle;
}

.table tbody tr:nth-child(even) td {
  background: #0e1624
}

.table tbody tr:hover td {
  background: #141d2b;
  transition: .12s
}

.table .mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace
}

/* Columnas / anchos */
.table td:nth-child(1) {
  width: 9rem
}

/* Código */
.table td:nth-child(2) {
  max-width: 520px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis
}

/* Nombre */
.table td:nth-child(3) {
  width: 6rem;
  text-align: center
}

/* Unidad */
.table td:nth-child(4),
.table td:nth-child(5),
.table td:nth-child(6),
.table td:nth-child(7) {
  text-align: right;
  white-space: nowrap
}

.table td:nth-child(8) {
  white-space: nowrap
}

/* Centro de costo */
.table td:nth-child(9) {
  width: 15rem;
  text-align: right
}

/* Acciones */

/* Pills de estado (semánticas y discretas) */
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  padding: 0 10px;
  height: 22px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 12px;
  border: 1px solid transparent;
}

.pill.ok {
  background: #0b2a1f;
  color: #86efac;
  border-color: #14532d
}

.pill.low {
  background: #2b2108;
  color: #fde68a;
  border-color: #b45309
}

.pill.crit {
  background: #2b0b0b;
  color: #fecaca;
  border-color: #7f1d1d
}

/* Botones compactos dentro de la grilla */
.table td .btn {
  padding: 6px 9px;
  border-radius: 8px;
  font-size: 12px
}

.table td .btn+.btn {
  margin-left: 6px
}

/* ===== Empty state ===== */
.empty {
  text-align: center;
  color: #93a3b5;
  padding: 36px;
  border: 1px dashed var(--bdr);
  border-radius: 14px;
  background: var(--panel-2);
  display: none;
}

/* ===== Dialogs ===== */
dialog {
  border: none;
  background: transparent
}

dialog::backdrop {
  background: rgba(0, 0, 0, .5)
}

.dlg-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--bdr);
  background: var(--bg-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 14px 14px 0 0;
}

.dlg-foot {
  padding: 14px 18px;
  border-top: 1px solid var(--bdr);
  background: var(--bg-soft);
  border-radius: 0 0 14px 14px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.dlg-x {
  color: #cbd5e1
}

.card.rounded-xl {
  padding: 0;
  overflow: hidden
}

/* Forzar tipografías/colores dentro del modal */
dialog .card {
  color: var(--txt)
}

dialog .card label {
  color: #d6dee9
}

dialog .card .inp {
  color: var(--txt)
}

dialog .card .inp::placeholder {
  color: #94a3b8
}

.dlg-head h3,
.dlg-foot {
  color: var(--txt)
}

dialog .card .btn {
  color: #e5e7eb
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 60;
  background: #064e3b;
  color: #d1fae5;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid #065f46;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

.toast.err {
  background: #7f1d1d;
  color: #fee2e2;
  border-color: #7f1d1d
}

/* ===== Utilidades ===== */
.soft {
  background: var(--panel);
  border: 1px solid var(--bdr)
}

.rounded {
  border-radius: 10px
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace
}

.kv {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 3px 0;
  border-bottom: 1px dashed #1e293b
}

.kv:last-child {
  border-bottom: none
}

/* Scrollbars suaves */
* {
  scrollbar-width: thin;
  scrollbar-color: #243444 transparent
}

*::-webkit-scrollbar {
  height: 10px;
  width: 10px
}

*::-webkit-scrollbar-thumb {
  background: #243444;
  border-radius: 10px
}

*::-webkit-scrollbar-track {
  background: transparent
}

/* ===== Responsive ===== */
@media (max-width:980px) {
  .obj-wrap {
    flex-direction: column;
    align-items: stretch
  }

  .obj-actions {
    justify-content: flex-end
  }
}

/* ===== Print ===== */
@media print {

  .topbar,
  .tabs,
  .deck,
  .toast {
    display: none !important
  }

  body {
    background: #fff;
    color: #000
  }

  .card,
  #rubros>details,
  .empty {
    border-color: #ddd
  }

  .table thead th {
    background: #fafafa;
    color: #000;
    border-color: #ddd
  }

  .table tbody td {
    border-color: #eee
  }
}

/* ===== Chat bubble (mínimo) ===== */
.chat-bubble {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000
}

.chat-toggle {
  width: 60px;
  height: 60px;
  background: var(--brand);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(220, 38, 38, .3);
  transition: all .3s ease;
}

.chat-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 25px rgba(220, 38, 38, .4)
}

.chat-window {
  position: absolute;
  bottom: 70px;
  right: 0;
  width: 380px;
  height: 500px;
  background: var(--panel);
  border: 1px solid var(--bdr);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .3);
}

.chat-window.hidden {
  display: none
}

.chat-header {
  padding: 16px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--bdr);
  border-radius: 14px 14px 0 0;
  display: flex;
  justify-content: space-between;
  align-items: center
}

.chat-header h3 {
  margin: 0;
  color: var(--brand);
  font-size: 16px
}

.chat-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center
}

.chat-close:hover {
  color: var(--txt)
}

.chat-messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px
}

.chat-message {
  padding: 12px;
  border-radius: 12px;
  max-width: 85%;
  word-wrap: break-word
}

.chat-message.user {
  background: #1f2937;
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px
}

.chat-message.bot {
  background: var(--panel-2);
  border: 1px solid var(--bdr);
  align-self: flex-start;
  border-bottom-left-radius: 4px
}

.chat-input-container {
  padding: 16px;
  border-top: 1px solid var(--bdr);
  display: flex;
  gap: 8px
}

.chat-input {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--bdr);
  border-radius: 20px;
  padding: 12px 16px;
  color: var(--txt);
  outline: none
}

.chat-input:focus {
  border-color: #7f1d1d
}

.chat-send {
  background: var(--brand);
  border: none;
  border-radius: 20px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--bg);
  font-weight: bold
}

.chat-send:hover {
  background: var(--brand-2)
}

/* ===== Compact mode de grilla ===== */
#rubros .table {
  font-size: 12px;
  line-height: 1.2
}

#rubros .table thead th {
  padding: 6px 8px;
  font-size: 11.5px
}

#rubros .table tbody td {
  padding: 6px 8px;
  border-bottom: 1px solid #1e293b
}

#rubros .table tbody tr:nth-child(even) td {
  background: #0e1624
}

#rubros .table tbody tr:hover td {
  background: #141d2b
}

#rubros .table td:nth-child(1) {
  width: 7.5rem
}

/* código */
#rubros .table td:nth-child(2) {
  max-width: 420px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis
}

#rubros .table td:nth-child(3) {
  width: 5rem;
  text-align: center
}

#rubros .table td:nth-child(4),
#rubros .table td:nth-child(5),
#rubros .table td:nth-child(6),
#rubros .table td:nth-child(7) {
  text-align: right;
  white-space: nowrap
}

#rubros .table td:nth-child(8) {
  white-space: nowrap;
  text-align: left
}

#rubros .table td:nth-child(9) {
  width: 12.5rem;
  text-align: right
}

#rubros .pill {
  min-width: 24px;
  height: 18px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px
}

#rubros .table td .btn {
  padding: 4px 6px;
  font-size: 11.5px;
  border-radius: 6px;
  line-height: 1.1
}

#rubros .table td .btn+.btn {
  margin-left: 4px
}

#rubros summary {
  padding: 8px 10px
}

#rubros summary .count {
  font-size: 11px
}

dialog .card .inp {
  padding: 7px 8px
}

dialog .card label {
  font-size: 11.5px
}

/* Alineación TH/TD */
#rubros .table thead th:nth-child(1) {
  width: 7.5rem !important;
  text-align: left
}

#rubros .table thead th:nth-child(2) {
  width: auto !important;
  text-align: left
}

#rubros .table thead th:nth-child(3) {
  width: 5rem !important;
  text-align: center
}

#rubros .table thead th:nth-child(4),
#rubros .table thead th:nth-child(5),
#rubros .table thead th:nth-child(6),
#rubros .table thead th:nth-child(7) {
  text-align: right !important
}

#rubros .table thead th:nth-child(8) {
  text-align: left !important
}

#rubros .table thead th:nth-child(9) {
  width: 12.5rem !important;
  text-align: right !important
}

#rubros .table thead th,
#rubros .table tbody td {
  padding: 6px 8px !important
}