/* Indelaf Tech — "Bosque Claro"
   Evolución liviana de la marca verde existente: sin topbar oscuro pesado,
   más aire entre elementos, acentos redondeados. Reskin sobre Bootstrap 5
   (no lo reemplaza — solo retoca tokens y componentes). */

:root {
  --ink: #283028;
  --paper: #F8F6F1;
  --card: #FFFFFF;
  --sage: #5C8A6C;
  --sage-dark: #3F6B4F;
  --sage-pale: #EAF1EA;
  --line: #E6E2D8;
  --muted: #7C8A7E;
  --warn-bg: #FBF0DE;
  --warn-ink: #96650F;
  --danger: #C0392B;
  --danger-bg: #FBEAE7;
  --font: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.55;
}

/* ── Tamaño de letra (preferencia por usuario, ver /mi-cuenta) ──
   Todo el resto del CSS usa rem, así que tocar el tamaño base alcanza para
   escalar texto Y el padding/espaciado que también está en rem — sin tocar
   medidas fijas en px (íconos, ancho del sidebar, avatares). */
html[data-fuente="chico"] { font-size: 14px; }
html[data-fuente="grande"] { font-size: 18px; }

/* ── Modo nocturno (preferencia por usuario, ver /mi-cuenta) ──
   color-mix() deriva los tonos de acento a partir del color de marca de cada
   empresa (paleta.accent, seteado en base.html) — así el modo oscuro no
   necesita una versión oscura hardcodeada de cada paleta de color. */
html[data-tema="oscuro"] {
  --ink: #E7EAE5;
  --paper: #141815;
  --card: #1E2420;
  --line: #303830;
  --muted: #8B978C;
  --sage-pale: color-mix(in srgb, var(--sage) 20%, var(--card) 80%);
  --sage-dark: color-mix(in srgb, var(--sage) 55%, white 45%);
  --warn-bg: #3A2F17;
  --warn-ink: #E0B15C;
  --danger: #E0685A;
  --danger-bg: #3A211D;

  /* Variables propias de Bootstrap 5.3 — cubren componentes (dropdowns,
     tablas, cards) que no pasan por nuestras clases/variables custom. */
  --bs-body-color: var(--ink);
  --bs-body-bg: var(--paper);
  --bs-emphasis-color: var(--ink);
  --bs-secondary-color: var(--muted);
  --bs-border-color: var(--line);
  --bs-card-color: var(--ink);
  --bs-card-bg: var(--card);
  --bs-card-border-color: var(--line);
  --bs-table-color: var(--ink);
  --bs-tertiary-bg: var(--card);
  --bs-dropdown-bg: var(--card);
  --bs-dropdown-color: var(--ink);
  --bs-dropdown-link-color: var(--ink);
  --bs-dropdown-link-hover-bg: var(--sage-pale);
  --bs-dropdown-border-color: var(--line);
}
html[data-tema="oscuro"] .text-muted { color: var(--muted) !important; }
html[data-tema="oscuro"] .sb-item:not(.active):hover,
html[data-tema="oscuro"] .chat-item:hover,
html[data-tema="oscuro"] .chat-contact-item:hover { background: rgba(255, 255, 255, .06); }
html[data-tema="oscuro"] .table-secondary, html[data-tema="oscuro"] .table-secondary > td { background: #262C26 !important; }
html[data-tema="oscuro"] .card,
html[data-tema="oscuro"] .table.bg-white,
html[data-tema="oscuro"] .chat-shell,
html[data-tema="oscuro"] .obra-card,
html[data-tema="oscuro"] .kpi-card {
  box-shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .35);
}
html[data-tema="oscuro"] .sb-backdrop { background: rgba(0, 0, 0, .55); }

a { color: var(--sage-dark); }
a:hover { color: var(--sage); }

/* ── Layout: sidebar + área principal ── */
.shell {
  display: flex;
  align-items: stretch;
  height: 100vh;
}
.sidebar {
  width: 236px;
  flex: none;
  background: var(--card);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  height: 100vh;
}
.sb-brand {
  padding: 18px 16px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  text-decoration: none !important;
}
.brandmark {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--sage);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 13px;
  flex: none;
}
.brandtext { display: flex; flex-direction: column; line-height: 1.2; }
.brandtext .name { font-weight: 800; font-size: .9rem; color: var(--ink); letter-spacing: -.01em; }
.brandtext .sub { font-size: .68rem; color: var(--muted); font-weight: 600; }

.sb-nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.sb-group { display: flex; flex-direction: column; gap: 1px; }
.sb-group-label {
  font-size: .65rem;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 10px;
  margin-bottom: 6px;
}
.sb-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: .82rem;
  font-weight: 600;
  color: var(--ink) !important;
  text-decoration: none !important;
}
.nav-icon {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}
.sb-item .nav-icon { color: var(--muted); }
.sb-item.active {
  background: var(--sage-pale);
  color: var(--sage-dark) !important;
  font-weight: 700;
}
.sb-item.active .nav-icon { color: var(--sage-dark); }
.sb-item:not(.active):hover { background: #F4F2EC; }

.sb-footer { border-top: 1px solid var(--line); padding: 12px 16px; }
.poweredby { display: flex; align-items: center; gap: 5px; font-size: .68rem; color: var(--muted); font-weight: 600; }
.poweredby .leaf { width: 12px; height: 12px; stroke: var(--muted); fill: none; stroke-width: 1.6; flex: none; }

.sb-backdrop { display: none; }

.mainarea { flex: 1; min-width: 0; height: 100vh; display: flex; flex-direction: column; }
.topstrip {
  flex: none;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.topstrip .pagelabel { font-size: .95rem; font-weight: 800; color: var(--ink); letter-spacing: -.01em; }
.userarea { display: flex; align-items: center; gap: 12px; }
.userarea .uname { font-size: .8rem; font-weight: 700; color: var(--ink); }
.userarea .out {
  font-size: .72rem;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  color: var(--sage-dark);
  text-decoration: none;
}
.userarea .out:hover { background: var(--sage-pale); border-color: var(--sage); }
.sb-toggle-btn {
  display: none;
  border: none;
  background: transparent;
  color: var(--ink);
  padding: 6px;
  border-radius: 8px;
}
.sb-toggle-btn:hover { background: var(--sage-pale); }

.content-pad { flex: 1; min-height: 0; overflow-y: auto; padding: 24px; max-width: 1400px; width: 100%; }

@media (max-width: 991.98px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 1050;
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .sb-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(40, 48, 40, .35);
    z-index: 1040;
  }
  body.sidebar-open .sb-backdrop { display: block; }
  .sb-toggle-btn { display: inline-flex; align-items: center; justify-content: center; }
  .content-pad { padding: 18px; }
}

/* ── Cards ── */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px !important;
  box-shadow: 0 1px 2px rgba(40, 48, 40, .03), 0 6px 18px rgba(40, 48, 40, .05);
}
.card-title { font-weight: 700; }
/* Algunas pantallas agregan "bg-white" al .card por costumbre del theme viejo —
   bootstrap la aplica con !important, así que sin esto quedaban blancas fijas
   sin importar el modo (el fix de .table.bg-white de abajo es el mismo caso). */
.card.bg-white { background: var(--card) !important; }

/* ── Botones ── */
.btn { border-radius: 24px; font-weight: 700; font-size: .875rem; padding: .5rem 1.1rem; }
.btn-sm { padding: .3rem .8rem; font-size: .8rem; }
.btn-primary {
  background: var(--sage); border-color: var(--sage); color: #fff;
}
.btn-primary:hover, .btn-primary:focus {
  background: var(--sage-dark); border-color: var(--sage-dark);
}
.btn-outline-primary {
  color: var(--sage-dark); border-color: var(--sage);
}
.btn-outline-primary:hover {
  background: var(--sage); border-color: var(--sage); color: #fff;
}
.btn-success { background: var(--sage); border-color: var(--sage); }
.btn-success:hover { background: var(--sage-dark); border-color: var(--sage-dark); }
.btn-outline-success { color: var(--sage-dark); border-color: var(--sage); }
.btn-outline-success:hover { background: var(--sage); border-color: var(--sage); }
.btn-outline-danger { color: var(--danger); border-color: var(--danger); }
.btn-outline-danger:hover { background: var(--danger); border-color: var(--danger); }
.btn-outline-secondary { color: var(--muted); border-color: var(--line); }
.btn-outline-secondary:hover { background: var(--sage-pale); border-color: var(--sage); color: var(--sage-dark); }

/* ── Tablas ── */
.table {
  --bs-table-bg: transparent;
  font-size: .875rem;
}
.table thead th {
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--line) !important;
  background: transparent;
}
.table td, .table th {
  border-bottom: 1px solid var(--line) !important;
  vertical-align: middle;
  padding-top: .65rem;
  padding-bottom: .65rem;
}
.table.bg-white { background: var(--card) !important; border-radius: 18px; overflow: hidden; border: 1px solid var(--line);
  box-shadow: 0 1px 2px rgba(40, 48, 40, .03), 0 6px 18px rgba(40, 48, 40, .05); }
.table-warning, .table-warning > td { --bs-table-bg: var(--warn-bg) !important; background: var(--warn-bg) !important; }
.table-secondary, .table-secondary > td { --bs-table-bg: #F1F0EC !important; background: #F1F0EC !important; color: var(--muted); }

/* ── Formularios ── */
.form-control, .form-select {
  border-radius: 12px;
  border-color: var(--line);
  background: var(--sage-pale);
  font-size: .875rem;
  padding: .5rem .8rem;
}
.form-control:focus, .form-select:focus {
  border-color: var(--sage);
  box-shadow: 0 0 0 .2rem rgba(92, 138, 108, .15);
  background: var(--card);
}
.form-label {
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted);
}
.form-check-input:checked { background-color: var(--sage); border-color: var(--sage); }

/* ── Badges / estados ── */
.badge.bg-success, .badge.bg-primary { background: var(--sage-pale) !important; color: var(--sage-dark) !important; font-weight: 700; }
.badge.bg-warning { background: var(--warn-bg) !important; color: var(--warn-ink) !important; font-weight: 700; }
.badge.bg-danger { background: var(--danger-bg) !important; color: var(--danger) !important; font-weight: 700; }
.badge.bg-secondary { background: #F1F0EC !important; color: var(--muted) !important; font-weight: 700; }

/* ── Alertas ── */
.alert-danger { background: var(--danger-bg); border-color: #F3D6D0; color: var(--danger); border-radius: 12px; }
.alert-info { background: var(--sage-pale); border-color: var(--line); color: var(--sage-dark); border-radius: 12px; }
.alert-success { background: var(--sage-pale); border-color: var(--line); color: var(--sage-dark); border-radius: 12px; }

/* ── Listas / chat / navegación secundaria ── */
.list-group-item { border-color: var(--line); }
.list-group-item-action:hover { background: var(--sage-pale); }
.nav-tabs { border-bottom-color: var(--line); }
.nav-tabs .nav-link { color: var(--muted); font-weight: 700; border: none; border-radius: 20px 20px 0 0; }
.nav-tabs .nav-link.active { color: var(--sage-dark); border-bottom: 2px solid var(--sage); background: transparent; }

/* ── Paginación ── */
.pagination .page-link { color: var(--sage-dark); border-color: var(--line); }
.pagination .page-item.active .page-link { background: var(--sage); border-color: var(--sage); }
.pagination .page-item.disabled .page-link { color: var(--muted); }

/* ── Login (login.html) ── */
body.bg-light { background: var(--sage-pale) !important; }

/* ── Chat: lista + conversación, burbujas ── */
.chat-shell {
  height: 70vh;
  min-height: 460px;
  display: flex;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(40, 48, 40, .03), 0 6px 18px rgba(40, 48, 40, .05);
}

.chat-list { width: 300px; flex: none; flex-direction: column; border-right: 1px solid var(--line); }
.chat-list-head { padding: 16px 16px 10px; border-bottom: 1px solid var(--line); flex: none; }
.chat-list-title { font-size: .72rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.chat-list-items { flex: 1; min-height: 0; overflow-y: auto; padding: 8px; }
.chat-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 8px; border-radius: 12px;
  text-decoration: none !important; color: var(--ink) !important;
}
.chat-item:hover { background: #F4F2EC; }
.chat-item.active { background: var(--sage-pale); }
.chat-item.active .chat-item-name { color: var(--sage-dark); }
.chat-item-info { min-width: 0; flex: 1; }
.chat-item-name { font-size: .85rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-meta { font-size: .68rem; color: var(--muted); }
.chat-list-new { flex: none; border-top: 1px solid var(--line); padding: 10px 10px 12px; max-height: 220px; display: flex; flex-direction: column; }
.chat-list-new .chat-list-title { padding: 0 6px; }
.chat-new-group-btn { font-size: .68rem; font-weight: 800; color: var(--sage-dark); padding: 3px 9px; border-radius: 14px; background: var(--sage-pale); text-decoration: none !important; }
.chat-new-group-btn:hover { background: var(--sage); color: #fff; }
.chat-contacts { overflow-y: auto; min-height: 0; display: flex; flex-direction: column; gap: 1px; margin-top: 2px; }
.chat-contact-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 10px; text-decoration: none !important; color: var(--ink) !important; font-size: .8rem; font-weight: 600; }
.chat-contact-item:hover { background: #F4F2EC; }
.chat-contact-item.active { background: var(--sage-pale); color: var(--sage-dark) !important; }
.chat-avatar-sm { width: 26px; height: 26px; font-size: .68rem; flex: none; }

.chat-avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: .8rem;
  background: var(--sage-pale); color: var(--sage-dark);
}
.chat-avatar .nav-icon { width: 18px; height: 18px; color: inherit; }
.chat-avatar-group { background: var(--sage); color: #fff; }

.chat-conv { flex: 1; min-width: 0; flex-direction: column; }
.chat-conv-header { flex: none; background: var(--sage); color: #fff; padding: 12px 20px; display: flex; align-items: center; gap: 12px; }
.chat-conv-header .chat-avatar { background: rgba(255, 255, 255, .2); color: #fff; }
.chat-conv-header-name { font-weight: 800; font-size: .92rem; }
.chat-back { color: #fff; display: flex; align-items: center; justify-content: center; padding: 4px; border-radius: 8px; }
.chat-back:hover { background: rgba(255, 255, 255, .15); }

.chat-msgs { flex: 1; min-height: 0; overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 10px; background: var(--paper); }
.chat-conv-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: .88rem; text-align: center; padding: 20px; }

.cmsg { max-width: 70%; padding: 9px 13px; border-radius: 14px; font-size: .85rem; line-height: 1.45; word-break: break-word; }
.cmsg-own { align-self: flex-end; background: var(--sage); color: #fff; border-bottom-right-radius: 4px; }
.cmsg-other { align-self: flex-start; background: var(--card); border: 1px solid var(--line); color: var(--ink); border-bottom-left-radius: 4px; }
.cmsg-author { font-size: .68rem; font-weight: 800; margin-bottom: 2px; color: var(--sage-dark); }
.cmsg-hora { font-size: .65rem; opacity: .65; margin-top: 4px; }

.chat-input-row { flex: none; border-top: 1px solid var(--line); padding: 12px 16px; display: flex; gap: 8px; align-items: center; background: var(--card); }
.chat-input-row .form-control { border-radius: 22px; background: var(--sage-pale); }
.chat-send-btn {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  background: var(--sage); color: #fff; border: none;
  display: flex; align-items: center; justify-content: center;
}
.chat-send-btn:hover { background: var(--sage-dark); }

@media (max-width: 767.98px) {
  .chat-shell { height: calc(100vh - 190px); border-radius: 14px; }
  .chat-list { width: 100%; border-right: none; }
}

/* ── Topbar: buscador global + campanita ── */
.topbar-search {
  display: flex; align-items: center; gap: 8px; flex: 1; max-width: 380px;
  background: var(--sage-pale); border-radius: 20px; padding: 7px 14px; margin: 0 16px;
}
.topbar-search .nav-icon { color: var(--muted); width: 15px; height: 15px; }
.topbar-search input {
  border: none; background: transparent; outline: none; font-size: .82rem; color: var(--ink);
  width: 100%; font-family: var(--font);
}
.topbar-search input::placeholder { color: var(--muted); }
@media (max-width: 767.98px) { .topbar-search { display: none; } }

.notif-bell {
  position: relative; border: none; background: transparent; color: var(--ink); padding: 6px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
}
.notif-bell:hover { background: var(--sage-pale); }
.notif-badge {
  position: absolute; top: 0; right: 0; background: var(--danger); color: #fff; font-size: .6rem; font-weight: 800;
  min-width: 16px; height: 16px; border-radius: 50%; display: flex; align-items: center; justify-content: center; padding: 0 3px;
}
.notif-menu { min-width: 260px; max-height: 340px; overflow-y: auto; border-radius: 14px; border-color: var(--line); padding: 6px; }
.notif-menu .dropdown-item { border-radius: 8px; font-size: .82rem; padding: 8px 10px; }
.notif-menu .dropdown-item:hover { background: var(--sage-pale); }

/* ── Obras: tarjetas ── */
.obra-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.obra-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px;
  text-decoration: none !important; color: var(--ink) !important; display: block;
  box-shadow: 0 1px 2px rgba(40, 48, 40, .03), 0 6px 18px rgba(40, 48, 40, .05);
  transition: transform .12s, border-color .12s;
}
.obra-card:hover { transform: translateY(-2px); border-color: var(--sage); }
.obra-card-nombre { font-weight: 800; font-size: 1rem; }
.obra-card-meta { font-size: .82rem; color: var(--muted); margin-top: 4px; }
.obra-card-presupuesto { display: flex; justify-content: space-between; gap: 10px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); font-size: .74rem; color: var(--muted); }
.obra-card-presupuesto b { color: var(--sage-dark); }

/* ── Dashboard: tarjetas KPI ── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
.kpi-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px 18px;
  text-decoration: none !important; display: block;
  box-shadow: 0 1px 2px rgba(40, 48, 40, .03), 0 6px 18px rgba(40, 48, 40, .05);
  border-left: 4px solid var(--sage);
  transition: transform .12s;
}
.kpi-card:hover { transform: translateY(-2px); }
.kpi-card.kpi-warn { border-left-color: #C99A3E; }
.kpi-card.kpi-danger { border-left-color: var(--danger); }
.kpi-valor { font-size: 1.7rem; font-weight: 800; color: var(--ink); line-height: 1; }
.kpi-label { font-size: .74rem; color: var(--muted); font-weight: 600; margin-top: 6px; }

/* ── Calendario: colores por tipo de evento ── */
.cal-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 3px; }
.cal-dot-reunion { background: #2558A8; }
.cal-dot-inspeccion { background: #1E9E5E; }
.cal-dot-entrega { background: #D97706; }
.cal-dot-vencimiento { background: #EF4444; }
.cal-dot-cumpleanos { background: #EC4899; }
.cal-dot-renovacion { background: #0891B2; }
.cal-dot-otro { background: #7C3AED; }

.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-daylabel { text-align: center; font-size: .68rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding-bottom: 4px; }
.cal-day {
  min-height: 84px; background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 6px; font-size: .72rem; display: flex; flex-direction: column; gap: 3px;
}
.cal-day.cal-fuera-mes { background: transparent; border-color: transparent; }
.cal-day.cal-hoy { border-color: var(--sage); box-shadow: 0 0 0 1px var(--sage); }
.cal-day-num { font-weight: 800; color: var(--ink); }
.cal-fuera-mes .cal-day-num { color: var(--muted); font-weight: 600; }
.cal-evento {
  font-size: .66rem; font-weight: 700; padding: 2px 5px; border-radius: 5px; color: #fff;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cal-legend { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-top: 14px; font-size: .74rem; color: var(--muted); }
.cal-legend span { display: flex; align-items: center; }

@media (max-width: 767.98px) {
  .cal-grid { grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
  .cal-day { min-height: 52px; padding: 3px; font-size: .62rem; }
  .cal-daylabel { font-size: .58rem; }
}
