/* CORE — tema oscuro profesional */

:root {
  --bg: #0f1419;
  --panel: #1a2027;
  --border: #2a323c;
  --text: #e6e9ed;
  --muted: #8b96a5;
  --primary: #2dd4a7;
  --danger: #f06a6a;
  --warn: #e8b34b;
  --sidebar-w: 230px;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

h1, h2, h3, h4 { margin: 0 0 12px; font-weight: 600; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
a { color: var(--primary); text-decoration: none; }
p { margin: 0 0 10px; }
label { display: block; font-size: 0.85rem; color: var(--muted); margin: 10px 0 4px; }

/* ---------- Layout shell ---------- */

.app-body { min-height: 100vh; }

.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 50;
}

.sidebar-logo {
  padding: 20px 18px 16px;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--primary);
  border-bottom: 1px solid var(--border);
}
.sidebar-logo span {
  display: block;
  font-size: 0.72rem;
  font-weight: 400;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text);
  font-size: 0.92rem;
  white-space: nowrap;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.05); }
.nav-item.active {
  background: rgba(45, 212, 167, 0.12);
  color: var(--primary);
  font-weight: 600;
}
.nav-corto { display: none; }

.main-wrap { margin-left: var(--sidebar-w); min-height: 100vh; }

.topbar {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  z-index: 40;
}
.topbar-right { display: flex; align-items: center; gap: 12px; }
.user-name { color: var(--muted); font-size: 0.9rem; }
.empresa-select { min-width: 200px; max-width: 320px; }

main#view { padding: 22px; max-width: 1280px; }

.view-loading { color: var(--muted); padding: 32px 4px; }
.view-error { color: var(--muted); padding: 24px; }

/* ---------- Componentes ---------- */

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: filter 0.12s, background 0.12s;
}
.btn:hover { filter: brightness(1.15); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #0b2a22;
}
.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
}
.btn-ghost:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.btn-danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}
.btn-danger:hover { background: rgba(240, 106, 106, 0.12); }

.input, .select {
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.92rem;
  outline: none;
}
.input:focus, .select:focus { border-color: var(--primary); }
.input::placeholder { color: var(--muted); opacity: 0.7; }
.select { appearance: auto; }
select.select option { background: var(--panel); color: var(--text); }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.table th {
  text-align: left;
  padding: 9px 10px;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  border-bottom: 1px solid var(--border);
}
.table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
}
.table tbody tr:hover { background: rgba(255, 255, 255, 0.03); }
.table-wrap { overflow-x: auto; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(139, 150, 165, 0.18);
  color: var(--muted);
}
.badge.ok { background: rgba(45, 212, 167, 0.15); color: var(--primary); }
.badge.danger { background: rgba(240, 106, 106, 0.15); color: var(--danger); }
.badge.warn { background: rgba(232, 179, 75, 0.15); color: var(--warn); }

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 12, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 200;
}

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: min(560px, 96vw);
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; }
.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 18px; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

/* ---------- Toast ---------- */

.toast-stack {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 300;
}
.toast {
  background: var(--panel);
  border: 1px solid var(--primary);
  border-left-width: 4px;
  color: var(--text);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 0.9rem;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.45);
  animation: toast-in 0.18s ease-out;
  max-width: 340px;
}
.toast.error, .toast.danger { border-color: var(--danger); }
.toast.warn { border-color: var(--warn); }
.toast.out { opacity: 0; transition: opacity 0.3s; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Grafico de barras ---------- */

.bar-chart { display: block; }
.bar-chart text { font-family: inherit; }

/* ---------- Login ---------- */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
}
.login-card {
  width: min(380px, 100%);
  padding: 32px 28px;
  margin: 0;
}
.login-logo { text-align: center; margin-bottom: 22px; }
.login-logo h1 {
  font-size: 2.1rem;
  letter-spacing: 4px;
  color: var(--primary);
  margin: 0;
}
.login-logo p { color: var(--muted); font-size: 0.85rem; margin: 4px 0 0; }
.login-label { margin-top: 14px; }
.login-btn { width: 100%; justify-content: center; margin-top: 20px; }
.login-error {
  margin-top: 14px;
  padding: 9px 12px;
  border-radius: 8px;
  background: rgba(240, 106, 106, 0.12);
  border: 1px solid var(--danger);
  color: var(--danger);
  font-size: 0.85rem;
}

/* ---------- Responsive ---------- */

@media (max-width: 767px) {
  .sidebar {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: auto;
    flex-direction: row;
    border-right: none;
    border-top: 1px solid var(--border);
  }
  .sidebar-logo { display: none; }
  .sidebar-nav {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 6px 8px;
    gap: 4px;
    -webkit-overflow-scrolling: touch;
  }
  .nav-item { padding: 8px 10px; font-size: 0.8rem; flex: 0 0 auto; }
  .nav-label { display: none; }
  .nav-corto { display: inline; }

  .main-wrap { margin-left: 0; padding-bottom: 64px; }
  main#view { padding: 14px; }
  .topbar { padding: 10px 14px; }
  .empresa-select { min-width: 130px; }
  .user-name { display: none; }

  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }

  .table { display: block; overflow-x: auto; white-space: nowrap; }
}

/* ---------- Campana de notificaciones ---------- */

.notif-wrap { position: relative; display: flex; align-items: center; }

.notif-bell {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.12s;
}
.notif-bell:hover { background: rgba(255, 255, 255, 0.06); }
.notif-bell-icon { display: inline-block; }

.notif-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 99px;
  background: var(--danger);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 17px;
  text-align: center;
}

.notif-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(340px, 92vw);
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5);
  z-index: 120;
  overflow: hidden;
}
.notif-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.9rem;
}
.notif-marcar {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  padding: 0;
}
.notif-marcar:hover { text-decoration: underline; }

.notif-list { overflow-y: auto; }
.notif-empty { padding: 18px 14px; color: var(--muted); font-size: 0.88rem; }

.notif-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: rgba(255, 255, 255, 0.04); }
.notif-item.no-leida { background: rgba(45, 212, 167, 0.07); }
.notif-item.no-leida .notif-item-titulo { color: var(--primary); }
.notif-item-titulo { font-size: 0.88rem; font-weight: 600; }
.notif-item-cuerpo { font-size: 0.82rem; color: var(--text); margin-top: 2px; }
.notif-item-fecha { font-size: 0.72rem; color: var(--muted); margin-top: 4px; }

/* ---------- Kanban ---------- */

.kanban-board {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  align-items: flex-start;
  padding-bottom: 8px;
}
.kanban-col {
  min-width: 280px;
  max-width: 300px;
  flex: 0 0 auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 200px);
}
.kanban-col-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.9rem;
}
.kanban-col-head .kanban-col-count {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
}
.kanban-col-body {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  flex: 1;
}
.kanban-col.drop-target { outline: 2px dashed var(--primary); outline-offset: -2px; }

.kanban-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: grab;
  transition: border-color 0.12s, transform 0.12s;
}
.kanban-card:hover { border-color: var(--primary); }
.kanban-card.dragging { opacity: 0.45; }
.kanban-card.drop-target { border-color: var(--primary); border-style: dashed; }
.kanban-card-titulo { font-size: 0.9rem; font-weight: 500; }
.kanban-card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
  font-size: 0.75rem;
  color: var(--muted);
}

.kanban-chip {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 99px;
  font-size: 0.7rem;
  font-weight: 600;
  background: rgba(139, 150, 165, 0.18);
  color: var(--muted);
}

.kanban-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 99px;
  background: rgba(45, 212, 167, 0.18);
  color: var(--primary);
  font-size: 0.7rem;
  font-weight: 700;
}
.kanban-venc { color: var(--muted); }
.kanban-venc.cerca { color: var(--warn); }
.kanban-venc.vencido { color: var(--danger); font-weight: 600; }

.kanban-add {
  margin: 0 10px 10px;
  padding: 7px;
  border-radius: 8px;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  cursor: pointer;
  text-align: center;
}
.kanban-add:hover { color: var(--text); border-color: var(--primary); }

/* ---------- Chat ---------- */

.chat-layout {
  display: flex;
  height: calc(100vh - 140px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
}
.chat-sidebar {
  width: 260px;
  flex: 0 0 auto;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.chat-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.chat-canal-list { flex: 1; overflow-y: auto; }
.chat-canal-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.12s;
}
.chat-canal-item:hover { background: rgba(255, 255, 255, 0.04); }
.chat-canal-item.activo { background: rgba(45, 212, 167, 0.12); color: var(--primary); }
.chat-canal-item .chat-canal-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 99px;
  background: var(--danger);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-main-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.chat-mensajes {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-empty {
  margin: auto;
  color: var(--muted);
  font-size: 0.9rem;
}

.chat-msg {
  max-width: 72%;
  align-self: flex-start;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
}
.chat-msg .autor {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 2px;
}
.chat-msg .contenido { font-size: 0.9rem; word-wrap: break-word; }
.chat-msg .hora { font-size: 0.68rem; color: var(--muted); margin-top: 3px; }
.chat-msg.propio {
  align-self: flex-end;
  background: rgba(45, 212, 167, 0.12);
  border-color: rgba(45, 212, 167, 0.35);
}
.chat-msg.propio .autor { color: var(--text); }

.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  position: relative;
}
.chat-input-bar .input { flex: 1; }
.chat-menciones {
  position: absolute;
  left: 14px;
  bottom: calc(100% + 4px);
  width: min(240px, 80%);
  max-height: 200px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  z-index: 60;
}
.chat-mencion-item {
  padding: 7px 12px;
  cursor: pointer;
  font-size: 0.85rem;
}
.chat-mencion-item:hover, .chat-mencion-item.activo { background: rgba(45, 212, 167, 0.12); }

@media (max-width: 767px) {
  .chat-layout { height: calc(100vh - 180px); }
  .chat-sidebar { width: 120px; }
  .chat-msg { max-width: 88%; }
}
