/* ===== ViviendaSion — Centros de Costo (paleta unificada con index.css) ===== */
:root {
  /* Marca desde index.css con fallback */
  --viviendasion-red: #dc2626;
  --viviendasion-red-dark: #b91c1c;

  /* Base dark común */
  --bg: #0f172a;
  /* fondo general */
  --panel: #111827;
  /* tarjetas / contenedores */
  --panel-2: #0b1220;
  /* otro tono para headers */
  --border: #334155;
  /* bordes */
  --text: #e5e7eb;
  /* texto */
  --muted: #9ca3af;
  /* texto suave */

  /* Primario = rojo corporativo */
  --primary: var(--viviendasion-red);
  --primary-2: var(--viviendasion-red-dark);

  /* Semánticos */
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
}

/* Reset */
* {
  box-sizing: border-box
}

html,
body {
  height: 100%
}

body.theme {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ===== Topbar ===== */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(17, 24, 39, .96);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar .left {
  display: flex;
  align-items: center;
  gap: 10px
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px
}

.brand strong {
  font-weight: 600;
  color: var(--primary)
}

.brand .sub {
  font-size: 12px;
  color: var(--muted)
}

/* ===== Botones ===== */
.actions {
  display: flex;
  gap: 8px;
  align-items: center
}

.btn {
  background: #1d2330;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
}

.btn:hover {
  filter: brightness(1.1)
}

.btn.primary {
  background: linear-gradient(180deg, var(--primary), var(--primary-2));
  border-color: #7f1d1d;
  color: #fff;
}

.btn.danger {
  background: linear-gradient(180deg, var(--primary), var(--primary-2));
  border-color: #7f1d1d;
  color: #fff;
}

.btn.ghost {
  background: transparent
}

/* Backlink consistente */
.backlink {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  background: #1d2330;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 10px;
  line-height: 1;
}

.backlink:hover {
  filter: brightness(1.1)
}

.backlink:focus {
  outline: 2px solid var(--primary);
  outline-offset: 2px
}

/* ===== Layout ===== */
.container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
}

.list {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
}

.sidebar {
  display: block;              /* importante que SIEMPRE esté como bloque */
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  min-height: 120px;
}

.placeholder {
  color: var(--muted);
  padding: 12px
}

/* ===== Toolbar / inputs ===== */
.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 10px
}

.input {
  width: 100%;
  background: #0d1016;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: 10px;
  outline: none;
}

.input:focus {
  border-color: #7f1d1d;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, .15)
}

/* ===== Tabs ===== */
.tabs {
  display: flex;
  gap: 6px;
  margin: 8px 0 10px
}

.tab {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel);
}

.tab.active {
  background: #1b0f0f;
  color: #ffecec;
  border-color: #7f1d1d;
}

.tabpanel.hidden {
  display: none
}

/* ===== Cards / side panels ===== */
.card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  background: var(--panel-2);
  margin-bottom: 10px;
}

.side-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px
}

.side-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text)
}

.side-sub {
  font-size: 12px;
  color: var(--muted)
}

/* ===== Tabla ===== */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px
}

.table th,
.table td {
  border-bottom: 1px solid var(--border);
  padding: 10px 8px;
  text-align: left;
  vertical-align: top
}

.table th {
  color: var(--muted);
  font-weight: 500;
  background: #0f172a
}

.table td.right {
  text-align: right;
  white-space: nowrap
}

/* Columna monto optimizada */
.table th.col-monto,
.table td.col-monto {
  width: 1%;
  white-space: nowrap
}

/* Detalle que no rompa fila */
.table td.col-detalle {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap
}

/* KPI / badges */
.kpi {
  display: inline-flex;
  gap: 6px;
  align-items: center
}

.badge {
  display: inline-block;
  font-size: 12px;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: #0d1016;
}

.badge.ok {
  color: #b7f7d6;
  border-color: #225e45;
  background: #122a23
}

.badge.warn {
  color: #fff1b3;
  border-color: #5b4d1c;
  background: #2a2412
}

.badge.danger {
  color: #ffd4dd;
  border-color: #5e222f;
  background: #2a1218
}

/* ===== Modales ===== */
.modal {
  border: none;
  padding: 0;
  background: transparent
}

.modal::backdrop {
  background: rgba(0, 0, 0, .5)
}

.modal-card {
  width: min(680px, 92vw);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}

.modal-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2)
}

.modal-body {
  padding: 12px 14px
}

.modal-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  background: var(--panel-2)
}

/* Grid de formulario */
.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px
}

.field.full {
  grid-column: 1 / -1
}

/* Drag&drop import */
.importlabel {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  border: 1px dashed var(--border);
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
}

/* Código/box mono */
.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  background: #0b0e12;
  border: 1px solid var(--border);
  padding: 8px;
  border-radius: 10px;
  overflow: auto;
}

.muted {
  color: var(--muted)
}

/* Scroll en tarjetas del sidebar */
.card .scroll {
  max-height: 50vh;
  overflow: auto
}

/* Inputs number sin spinners */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0
}

input[type="number"] {
  -moz-appearance: textfield
}

/* Confirm botón danger coherente */
#confirmOk.btn.danger {
  filter: brightness(1)
}

#confirmOk.btn.danger:hover {
  filter: brightness(1.05);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, .15)
}

/* ===== Dashboard Centros de Costo ===== */
.stats-section {
  margin-top: 24px;
}

.section-title {
  font-size: 1.2rem;
  font-weight: 600;
  margin: 0 0 4px;
}

.section-subtitle {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0 0 12px;
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin: 12px 0 16px;
}

.summary-cards .card {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.card-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.card-value {
  font-size: 1.6rem;
  font-weight: 700;
}

.card-value.positive {
  color: var(--ok);
}

.card-value.negative {
  color: var(--danger);
}

.card-description {
  font-size: 0.8rem;
  color: var(--muted);
}

.stats-grid {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}

.stats-panel {
  background: var(--panel-2);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 10px 12px;
}

.stats-panel-wide {
  grid-column: 1 / -1;
}

.stats-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.stats-panel-header .section-title {
  margin-bottom: 0;
}

.number-cell {
  text-align: right;
}

.chart-wrapper {
  position: relative;
  width: 100%;
  max-width: 820px;      /* ancho máximo del gráfico */
  margin: 0 auto;        /* centrado dentro del panel */
  height: 240px;         /* un poco más bajo */
}

.stats-panel-wide .chart-wrapper {
  max-width: 820px;      /* mismo límite también para el panel ancho */
  height: 260px;
}

.chart-wrapper canvas {
  width: 100% !important;
  height: 100% !important;
}

.table-container {
  background: transparent;
  border: none;
  border-radius: 0;
  overflow-x: auto;
}

.stats-panel .table {
  width: 100%;
  margin: 0;
}

/* Utilidad genérica para ocultar elementos (para el bot) */
.hidden {
  display: none !important;
}

/* ================== SIDEBAR BOT CENTROS DE COSTO ================== */

.bot-sidebar {
  position: fixed;
  top: 0;
  right: -500px;
  width: 500px;
  height: 100vh;
  background: #020617;
  border-left: 1px solid #1f2937;
  z-index: 100;
  transition: right 0.3s ease;
  display: flex;
  flex-direction: column;
  box-shadow: -6px 0 18px rgba(0, 0, 0, 0.7);
}

.bot-sidebar.open {
  right: 0;
}

.bot-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #0f172a;
  border-bottom: 1px solid #1f2937;
}

.bot-sidebar-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 1rem;
}

.bot-sidebar-title .dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15);
}

.bot-sidebar-close {
  background: transparent;
  border: none;
  color: #9ca3af;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bot-sidebar-close:hover {
  background: rgba(255, 255, 255, 0.07);
  color: #fff;
}

.bot-sidebar-body {
  flex: 1;
  overflow: auto;
  padding: 16px;
}

.bot-sidebar-chat {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 100%;
}

.bot-sidebar-message {
  display: flex;
  gap: 8px;
}

.bot-sidebar-message.user {
  flex-direction: row-reverse;
}

.bot-sidebar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0b1220;
  border: 1px solid #1f2937;
  font-size: 1rem;
  flex-shrink: 0;
}

.bot-sidebar-bubble {
  max-width: 80%;
  padding: 9px 13px;
  border-radius: 14px;
  background: #020617;
  border: 1px solid #1f2937;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
  font-size: 0.9rem;
  line-height: 1.4;
}

.bot-sidebar-message.user .bot-sidebar-bubble {
  background: #1e3a8a;
  border-color: #3b82f6;
}

.bot-sidebar-message-time {
  font-size: 0.75rem;
  color: #6b7280;
  margin-top: 4px;
}

.bot-sidebar-typing {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #6b7280;
  font-size: 0.85rem;
  margin-top: 8px;
}

.bot-sidebar-typing-dots {
  display: inline-flex;
  gap: 4px;
}

.bot-sidebar-typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #6b7280;
  display: inline-block;
  opacity: 0.7;
  animation: blink 1.2s infinite;
}

.bot-sidebar-typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.bot-sidebar-typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes blink {
  0%,
  80%,
  100% {
    opacity: 0.2;
  }
  40% {
    opacity: 1;
  }
}

.bot-sidebar-composer {
  padding: 16px;
  border-top: 1px solid #1f2937;
  background: #020617;
}

.bot-sidebar-form {
  display: flex;
  gap: 8px;
}

.bot-sidebar-input {
  flex: 1;
  min-height: 40px;
  max-height: 120px;
  resize: none;
  padding: 8px 12px;
  font-size: 0.95rem;
  border-radius: 8px;
  border: 1px solid #1f2937;
  background: #020617;
  color: #e5e7eb;
  outline: none;
}

.bot-sidebar-send {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid #20416e;
  background: #1d4ed8;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.bot-sidebar-send:hover:not(:disabled) {
  background: #1e40af;
}

.bot-sidebar-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.bot-sidebar-resizer {
  position: absolute;
  left: -4px;
  top: 0;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  z-index: 101;
}

.bot-sidebar-resizer:hover,
.bot-sidebar-resizer.dragging {
  background: rgba(59, 130, 246, 0.3);
}

/* Botón para abrir la sidebar */
.bot-sidebar-launcher {
  position: fixed;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  background: #1e3a8a;
  color: white;
  border: none;
  border-radius: 8px 0 0 8px;
  padding: 12px 8px;
  cursor: pointer;
  z-index: 99;
  box-shadow: -2px 0 8px rgba(0, 0, 0, 0.3);
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: 0.9rem;
}

.bot-sidebar-launcher:hover {
  background: #1e40af;
  padding-right: 12px;
}

.bot-sidebar-launcher-icon {
  font-size: 1.2rem;
}

/* Overlay para cuando está abierta */
.bot-sidebar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.35);
  z-index: 90;
  display: none;
}

.bot-sidebar-overlay.open {
  display: block;
}

/* Responsive sidebar bot */
@media (max-width: 768px) {
  .bot-sidebar {
    width: 100%;
    right: -100%;
  }

  .bot-sidebar.open {
    right: 0;
  }

  .bot-sidebar-resizer {
    display: none;
  }
}

