/* ================================================================
   app-modules.css — Estilos de módulos ARBITRAR
   Componentes compartidos + estilos por módulo
   Compatible con dark mode (usa variables de app.css)
   ================================================================ */

/* ── TABLAS ─────────────────────────────────────────────────── */

.mod-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  min-width: 500px;
}

.mod-table thead tr {
  border-bottom: 2px solid var(--border);
}

.mod-table th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  background: var(--bg-card);
  position: sticky;
  top: 0;
  z-index: 1;
}

.mod-table th.center,
.mod-table td.center { text-align: center; }

.mod-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.mod-table tbody tr:hover {
  background: var(--hover-bg, rgba(0,0,0,0.02));
}

[data-theme="dark"] .mod-table tbody tr:hover {
  background: rgba(255,255,255,0.03);
}

.mod-table td {
  padding: 10px 16px;
  vertical-align: middle;
}

.mod-table td.muted {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.mod-table td.bold { font-weight: 600; }
.mod-table td.mono { font-family: monospace; font-size: 0.78rem; }

.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
}

/* ── BADGES / PILLS ────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.badge-dev         { background: #EF44441a; color: #EF4444; }
.badge-admin       { background: #F59E0B1a; color: #F59E0B; }
.badge-conciliador { background: #3B82F61a; color: #3B82F6; }
.badge-asistente   { background: #6B72801a; color: #6B7280; }
.badge-operador    { background: #3B82F61a; color: #3B82F6; }
.badge-abogado     { background: #8B5CF61a; color: #8B5CF6; }

.badge-activo      { background: #10B9811a; color: #10B981; }
.badge-inactivo    { background: #EF44441a; color: #EF4444; }
.badge-pendiente   { background: #F59E0B1a; color: #F59E0B; }
.badge-enviado     { background: #3B82F61a; color: #3B82F6; }

.badge-success     { background: #10B9811a; color: #10B981; }
.badge-warning     { background: #F59E0B1a; color: #F59E0B; }
.badge-danger      { background: #EF44441a; color: #EF4444; }
.badge-info        { background: #06B6D41a; color: #06B6D4; }

/* ── TABS (pills) ──────────────────────────────────────────── */

.mod-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.mod-tab {
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.mod-tab:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.mod-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ── EMPTY / LOADING STATES ────────────────────────────────── */

.mod-empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.mod-empty i {
  font-size: 2.5rem;
  margin-bottom: 16px;
  display: block;
  opacity: 0.5;
}

.mod-empty p {
  font-size: 0.88rem;
  margin: 0 0 8px;
}

.mod-empty .sub {
  font-size: 0.78rem;
}

.mod-loading {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

.mod-loading::before {
  content: '';
  display: block;
  width: 32px;
  height: 32px;
  margin: 0 auto 12px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.mod-error {
  text-align: center;
  padding: 40px 24px;
  color: #EF4444;
}

.mod-error i {
  font-size: 2rem;
  margin-bottom: 12px;
  display: block;
}

/* ── MODALES ANIMADOS ──────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
  padding: 20px;
}

.modal-overlay > .premium-card {
  animation: modalSlideIn 0.3s ease;
  max-height: 90vh;
  overflow-y: auto;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes modalSlideIn {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-title {
  font-family: Outfit, sans-serif;
  font-size: 1.1rem;
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 24px;
}

/* ── FORM GROUPS ───────────────────────────────────────────── */

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text-main);
}

.form-group label .required {
  color: #EF4444;
  margin-left: 2px;
}

.form-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 3px;
  line-height: 1.4;
}

.form-control.error {
  border-color: #EF4444;
  box-shadow: 0 0 0 2px rgba(239,68,68,0.15);
}

.form-error-msg {
  font-size: 0.75rem;
  color: #EF4444;
  margin-top: 3px;
}

.form-row {
  display: flex;
  gap: 12px;
}

.form-row > * { flex: 1; }

/* ── STATUS DOTS ───────────────────────────────────────────── */

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}

.status-dot.active   { background: #10B981; }
.status-dot.inactive { background: #EF4444; }
.status-dot.pending  { background: #F59E0B; }

.status-text {
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.status-text.active   { color: #10B981; }
.status-text.inactive { color: #EF4444; }

/* ── KPI CARDS ─────────────────────────────────────────────── */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

.kpi-card {
  text-align: center;
  padding: 20px 16px;
}

.kpi-card .kpi-icon {
  font-size: 1.3rem;
  margin-bottom: 8px;
  display: block;
}

.kpi-card .kpi-value {
  font-size: 2rem;
  font-weight: 800;
  font-family: Outfit, sans-serif;
  color: var(--text-main);
  line-height: 1;
}

.kpi-card .kpi-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ── ICON BUTTONS (table actions) ──────────────────────────── */

.btn-icon {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.82rem;
}

.btn-icon:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light, #EFF6FF);
}

.btn-icon.danger:hover {
  border-color: #EF4444;
  color: #EF4444;
  background: #EF44441a;
}

/* ── AVATAR ────────────────────────────────────────────────── */

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.75rem;
  flex-shrink: 0;
}

.user-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ── HEADER DE MÓDULO ──────────────────────────────────────── */

.mod-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.mod-header .modulo-titulo { margin: 0; }

.mod-subtext {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 20px;
}

/* ── GRID CARDS ────────────────────────────────────────────── */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.card-grid.narrow {
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
}

.card-grid.wide {
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}

/* ── CHART CONTAINERS ──────────────────────────────────────── */

.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.chart-card {
  padding: 20px;
}

.chart-card h4 {
  font-family: Outfit, sans-serif;
  font-size: 0.9rem;
  margin-bottom: 12px;
  color: var(--text-main);
}

/* ── CONFIG FIELDS ─────────────────────────────────────────── */

.cfg-field {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 12px;
  align-items: start;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.cfg-field:last-child { border-bottom: none; }

.cfg-field label {
  font-size: 0.82rem;
  font-weight: 600;
  padding-top: 8px;
  color: var(--text-main);
}

.cfg-field .cfg-key {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 400;
  margin-left: 6px;
  font-family: monospace;
}

/* ── CALENDARIO ────────────────────────────────────────────── */

.cal-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.cal-nav h3 {
  font-family: Outfit, sans-serif;
  margin: 0;
  min-width: 200px;
  text-align: center;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  min-width: 600px;
}

.cal-header {
  text-align: center;
  padding: 8px;
  font-weight: 700;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.cal-day {
  padding: 6px;
  min-height: 80px;
  border-radius: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  transition: border-color 0.2s;
}

.cal-day:hover { border-color: var(--primary); }

.cal-day.today {
  border: 2px solid var(--primary);
  background: var(--primary-light, #EFF6FF);
}

[data-theme="dark"] .cal-day.today {
  background: rgba(59,130,246,0.1);
}

.cal-day-num {
  font-size: 0.78rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.cal-day.today .cal-day-num {
  color: var(--primary);
  font-weight: 800;
}

.cal-day.empty {
  background: var(--bg-body);
  border-color: transparent;
}

.cal-event {
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.68rem;
  font-weight: 600;
  margin-bottom: 2px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-left: 3px solid;
  transition: opacity 0.2s;
}

.cal-event:hover { opacity: 0.8; }

/* ── SEMANA (calendario) ───────────────────────────────────── */

.cal-week-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 12px;
}

.cal-week-day {
  min-height: 200px;
}

.cal-week-day-header {
  font-weight: 700;
  font-size: 0.85rem;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.cal-week-day.today .cal-week-day-header {
  color: var(--primary);
}

.cal-event-count {
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
}

/* ── CHAT (ayuda) ──────────────────────────────────────────── */

.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 120px);
  position: sticky;
  top: 80px;
}

.chat-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-avatar {
  width: 36px;
  height: 36px;
  background: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.9rem;
}

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

.chat-msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.84rem;
  line-height: 1.45;
}

.chat-msg.bot {
  align-self: flex-start;
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border);
}

.chat-msg.user {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
}

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

/* ── FAQ ACCORDION ─────────────────────────────────────────── */

.faq details {
  border-bottom: 1px solid var(--border);
}

.faq details:last-child { border-bottom: none; }

.faq summary {
  padding: 14px 20px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.88rem;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: color 0.2s;
}

.faq summary:hover { color: var(--primary); }

.faq summary::-webkit-details-marker { display: none; }

.faq summary i {
  font-size: 0.7rem;
  color: var(--text-muted);
  transition: transform 0.3s;
}

.faq details[open] summary i {
  transform: rotate(180deg);
}

.faq .faq-answer {
  padding: 0 20px 14px;
  font-size: 0.84rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ── GUIDE CARDS (ayuda) ───────────────────────────────────── */

.guide-card {
  padding: 16px;
  transition: border-color 0.2s;
}

.guide-card:hover { border-color: var(--primary); }

.guide-card-content {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.guide-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1rem;
}

.guide-title {
  font-weight: 700;
  font-family: Outfit, sans-serif;
  font-size: 0.88rem;
  margin-bottom: 4px;
}

.guide-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.45;
}

/* ── WIZARD STEPPER (marketing) ────────────────────────────── */

.wizard-stepper {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 24px;
}

.wizard-step {
  display: flex;
  align-items: center;
  gap: 6px;
}

.wizard-step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-muted);
}

.wizard-step.active .wizard-step-num {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.wizard-step.done .wizard-step-num {
  background: #10B981;
  color: #fff;
  border-color: #10B981;
}

.wizard-step-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.wizard-step.active .wizard-step-label {
  font-weight: 700;
  color: var(--text-main);
}

.wizard-connector {
  width: 40px;
  height: 1px;
  background: var(--border);
}

/* ── PLANTILLA CARDS ───────────────────────────────────────── */

.plt-card {
  padding: 18px;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s;
}

.plt-card:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
}

.plt-card-content {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.plt-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1.1rem;
}

.plt-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 4px;
}

.plt-docid {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: monospace;
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── FOLDER CARDS (carpetas) ───────────────────────────────── */

.carp-card {
  padding: 18px;
}

.carp-card-content {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.carp-icon {
  width: 42px;
  height: 42px;
  background: #F59E0B1a;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #F59E0B;
  font-size: 1.2rem;
}

.carp-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.carp-actions .btn { flex: 1; text-align: center; }

/* ── BOT WA DASHBOARD ──────────────────────────────────────── */

.bot-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.bot-status-card {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.bot-wa-icon {
  width: 44px;
  height: 44px;
  background: #25D3661a;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #25D366;
  font-size: 1.3rem;
}

/* ── AYUDA LAYOUT ──────────────────────────────────────────── */

.ayuda-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 24px;
  align-items: start;
}

.ayuda-section-title {
  font-family: Outfit, sans-serif;
  font-size: 0.95rem;
  margin-bottom: 12px;
  color: var(--text-muted);
}

/* ── RESPONSIVE ────────────────────────────────────────────── */

@media (max-width: 1100px) {
  .chart-grid { grid-template-columns: 1fr; }
  .bot-grid { grid-template-columns: 1fr; }
  .ayuda-layout { grid-template-columns: 1fr; }
  .cfg-field { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .card-grid { grid-template-columns: 1fr; }
  .cal-week-grid { grid-template-columns: 1fr; }
  .mod-tabs { gap: 4px; }
  .mod-tab { padding: 5px 10px; font-size: 0.78rem; }
  .wizard-stepper { flex-wrap: wrap; }
  .wizard-connector { display: none; }
  .form-row { flex-direction: column; }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi-card { padding: 14px 10px; }
  .kpi-card .kpi-value { font-size: 1.5rem; }
}
