/* ============================================================
   NDB Support — Estilos principales
   ============================================================ */

/* ── Variables ── */
:root {
  --sidebar-width: 240px;
  --sidebar-collapsed: 0px;
  --sidebar-bg: #1a2940;
  --sidebar-hover: rgba(255,255,255,0.08);
  --sidebar-active: rgba(255,255,255,0.15);
  --topbar-height: 56px;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --body-bg: #f0f2f5;
  --bg-surface: #ffffff;
  --bg-surface-2: #f8fafc;
  --text-primary: #1e293b;
  --text-muted: #64748b;
  --text-faint: #94a3b8;
  --border-color: #e2e8f0;
  --border-light: #f1f5f9;
  --card-radius: 10px;
  --font-base: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

/* ── Reset / Base ── */
* { box-sizing: border-box; }
body {
  font-family: var(--font-base);
  background: var(--body-bg);
  color: var(--text-primary);
  font-size: 14px;
}

/* ── Layout wrapper ── */
.wrapper { min-height: 100vh; }

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.25s ease, width 0.25s ease;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 1000;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  color: #fff;
}

.sidebar-logo {
  max-height: 36px;
  max-width: 130px;
  object-fit: contain;
  flex-shrink: 0;
}

.sidebar-logo-fallback {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: rgba(255,255,255,0.15);
  color: #fff;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-tenant-name {
  color: #fff;
  line-height: 1.2;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  text-decoration: none;
  gap: 8px;
}

.sidebar-menu {
  flex: 1;
  padding: 12px 8px;
}

.sidebar-menu .nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  color: rgba(255,255,255,0.65);
  padding: 9px 12px;
  border-radius: 7px;
  font-size: 13.5px;
  transition: all 0.15s;
  margin-bottom: 2px;
}

.sidebar-menu .nav-link:hover {
  color: #fff;
  background: var(--sidebar-hover);
}

.sidebar-menu .nav-link.active {
  color: #fff;
  background: var(--sidebar-active);
  font-weight: 600;
}

.sidebar-menu .nav-link i {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

.nav-section-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.35);
  padding: 16px 12px 6px;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.65);
}

/* ============================================================
   SIDEBAR COLAPSADO — Desktop
   ============================================================ */
body.sidebar-collapsed .sidebar {
  width: 68px;
}

body.sidebar-collapsed .sidebar-header {
  padding: 20px 12px 16px;
  justify-content: center;
}

body.sidebar-collapsed .sidebar-logo {
  max-width: 40px;
  max-height: 40px;
}

body.sidebar-collapsed .sidebar-tenant-name {
  display: none;
}

body.sidebar-collapsed .sidebar-menu {
  padding: 12px 8px;
}

body.sidebar-collapsed .sidebar-menu .nav-link {
  justify-content: center;
  padding: 10px;
}

body.sidebar-collapsed .sidebar-menu .nav-link span {
  display: none;
}

body.sidebar-collapsed .nav-section-title {
  text-align: center;
  padding-left: 0;
  padding-right: 0;
  font-size: 0;
}

body.sidebar-collapsed .nav-section-title::after {
  content: '—';
  font-size: 12px;
  letter-spacing: 0;
}

body.sidebar-collapsed .sidebar-footer {
  display: none;
}

/* ============================================================
   MAIN CONTENT / TOPBAR
   ============================================================ */
.main-content {
  min-width: 0;
  background: var(--body-bg);
}

.topbar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  height: var(--topbar-height);
  position: sticky;
  top: 0;
  z-index: 999;
}

.topbar .btn-link {
  color: var(--text-muted);
}

.sidebar-toggle {
  display: block;
}

.page-content {
  min-height: calc(100vh - var(--topbar-height) - 48px);
}

.page-footer {
  border-top: 1px solid var(--border-color);
  background: var(--bg-surface);
}

.page-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
  --bs-card-bg: var(--bg-surface);
  border-radius: var(--card-radius);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
}

.card-header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-light);
  padding: 12px 16px;
  font-size: 14px;
}

/* ============================================================
   STAT CARDS — Dashboard
   ============================================================ */
.stat-card {
  background: var(--bg-surface);
  border-radius: var(--card-radius);
  border: 1px solid var(--border-color);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: box-shadow 0.15s;
}

.stat-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--text-primary);
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Soft color backgrounds */
.bg-primary-soft  { background: #eff6ff; }
.bg-warning-soft  { background: #fffbeb; }
.bg-success-soft  { background: #f0fdf4; }
.bg-danger-soft   { background: #fef2f2; }
.bg-info-soft     { background: #f0f9ff; }
.bg-purple-soft   { background: #f5f3ff; }
.text-purple      { color: #7c3aed; }

/* ============================================================
   TABLAS
   ============================================================ */
.table th {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  border-bottom: 1px solid var(--border-color);
}

.table td {
  vertical-align: middle;
  border-bottom: 1px solid var(--border-light);
  padding: 10px 12px;
}

.cursor-pointer { cursor: pointer; }

/* ============================================================
   AVATAR
   ============================================================ */
.avatar-sm {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}

/* ============================================================
   MENSAJES DEL TICKET
   ============================================================ */
.message-card {
  border-left: 3px solid var(--border-color);
}

.message-agent {
  border-left-color: #f59e0b;
}

.message-internal {
  border-left-color: var(--text-faint);
  background: var(--bg-surface-2);
}

.message-internal .card-header {
  background: var(--border-light);
}

/* ============================================================
   NOTA GENERAL DEL TICKET
   ============================================================ */
.note-card {
  border-left-color: #0ea5e9;
}

.note-card .card-header {
  background: rgba(14, 165, 233, 0.08);
}

[data-theme="dark"] .note-card .card-header {
  background: rgba(14, 165, 233, 0.12);
}

/* Cabeceras colapsables (descripción, conversaciones y nota general) */
.card-header[data-bs-toggle="collapse"] {
  cursor: pointer;
  user-select: none;
}

.collapse-chevron {
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

[aria-expanded="false"] .collapse-chevron {
  transform: rotate(-90deg);
}

/* ============================================================
   PREVISUALIZACIÓN DE ADJUNTOS
   ============================================================ */
.preview-body img {
  display: block;
  max-width: 100%;
  max-height: 80vh;
  margin: 0 auto;
  object-fit: contain;
  background: var(--bg-surface-2);
}

.preview-body iframe {
  width: 100%;
  height: 80vh;
  border: 0;
}

/* ============================================================
   PRIORIDADES — Crear ticket
   ============================================================ */
/* ============================================================
   AUTH
   ============================================================ */
.auth-body {
  background: linear-gradient(135deg, #1a2940 0%, #2563eb 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-container {
  width: 100%;
  max-width: 420px;
}

.auth-card {
  background: var(--bg-surface);
  border-radius: 16px;
  padding: 36px 32px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}

.auth-header {
  margin-bottom: 24px;
}

.auth-icon {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: var(--primary-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: var(--primary);
  margin: 0 auto;
}

/* ============================================================
   UTILIDADES
   ============================================================ */
.x-small { font-size: 11px; }

.input-group-text {
  background: var(--bg-surface-2);
  border-color: var(--border-color);
  color: var(--text-muted);
}

/* Mejorar inputs focus */
.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

/* Btn primary override */
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
}
.btn-primary:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
}

/* ============================================================
   RESPONSIVE — Mobile sidebar
   ============================================================ */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    z-index: 1050;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,0.2);
  }

  .sidebar-toggle {
    display: block !important;
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1040;
  }

  .sidebar-overlay.show {
    display: block;
  }
}

/* ============================================================
   TEMA CLARO / OSCURO
   ============================================================ */
[data-theme="dark"] {
  color-scheme: dark;
  --sidebar-bg: #111c31;
  --body-bg: #0f172a;
  --bg-surface: #1e293b;
  --bg-surface-2: #26334d;
  --text-primary: #e2e8f0;
  --text-muted: #94a3b8;
  --text-faint: #64748b;
  --border-color: #334155;
  --border-light: #2b3a4e;
  --primary-soft: rgba(37, 99, 235, 0.18);
}

[data-theme="dark"] .text-muted { color: var(--text-muted) !important; }
[data-theme="dark"] .form-text,
[data-theme="dark"] .attachment-feedback { color: var(--text-muted); }
[data-theme="dark"] .card {
  --bs-card-color: var(--text-primary);
  --bs-card-cap-color: var(--text-primary);
}
[data-theme="dark"] .card-title { color: var(--text-primary) !important; }
[data-theme="dark"] .bg-light { background-color: var(--bg-surface-2) !important; }
[data-theme="dark"] .bg-white { background-color: var(--bg-surface) !important; }
[data-theme="dark"] .text-dark { color: var(--text-primary) !important; }
[data-theme="dark"] .table-hover tbody tr:hover { color: var(--text-primary); }

[data-theme="dark"] .table {
  --bs-table-bg: transparent;
  --bs-table-color: var(--text-primary);
  color: var(--text-primary);
}
[data-theme="dark"] .table-light {
  --bs-table-bg: var(--bg-surface-2);
  --bs-table-color: var(--text-primary);
  background: var(--bg-surface-2) !important;
}
[data-theme="dark"] .table-light > tr > th,
[data-theme="dark"] .table-light > tr > td,
[data-theme="dark"] .table > :not(caption) > * > .table-light,
[data-theme="dark"] .table > :not(caption) > * > .table-light > * {
  background: var(--bg-surface-2) !important;
  color: var(--text-primary) !important;
}
[data-theme="dark"] .table-hover {
  --bs-table-hover-bg: rgba(255, 255, 255, 0.05);
  --bs-table-hover-color: var(--text-primary);
}
[data-theme="dark"] .table-hover tbody tr:hover {
  background: var(--bs-table-hover-bg);
  color: var(--text-primary);
}
[data-theme="dark"] .table th {
  color: var(--text-primary) !important;
}

[data-theme="dark"] .page-link {
  --bs-pagination-bg: var(--bg-surface);
  --bs-pagination-color: var(--text-primary);
  --bs-pagination-border-color: var(--border-color);
  background: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--border-color);
}
[data-theme="dark"] .page-link:hover {
  --bs-pagination-hover-bg: var(--bg-surface-2);
  --bs-pagination-hover-color: var(--text-primary);
  --bs-pagination-hover-border-color: var(--border-color);
  background: var(--bg-surface-2);
  color: var(--text-primary);
}
[data-theme="dark"] .page-item.disabled .page-link {
  --bs-pagination-disabled-bg: var(--bg-surface-2);
  --bs-pagination-disabled-color: var(--text-muted);
  background: var(--bg-surface-2);
  color: var(--text-muted);
}
[data-theme="dark"] .page-item.active .page-link {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select {
  background-color: var(--bg-surface-2);
  border-color: var(--border-color);
  color: var(--text-primary);
}
[data-theme="dark"] .form-control::placeholder { color: var(--text-muted); }
[data-theme="dark"] .form-control:focus,
[data-theme="dark"] .form-select:focus { background-color: var(--bg-surface-2); color: var(--text-primary); }

[data-theme="dark"] .dropdown-menu { background: var(--bg-surface); border-color: var(--border-color); }
[data-theme="dark"] .dropdown-item { color: var(--text-primary); }
[data-theme="dark"] .dropdown-item:hover,
[data-theme="dark"] .dropdown-item:focus { background: var(--bg-surface-2); color: var(--text-primary); }
[data-theme="dark"] .dropdown-divider { border-top-color: var(--border-color); }
[data-theme="dark"] .dropdown-header { color: var(--text-muted); }

/* Modales */
[data-theme="dark"] .modal-content {
  background: var(--bg-surface);
  border-color: var(--border-color);
  color: var(--text-primary);
}
[data-theme="dark"] .modal-header {
  border-bottom-color: var(--border-color);
  color: var(--text-primary);
}
[data-theme="dark"] .modal-header .btn-close {
  filter: invert(1);
}
[data-theme="dark"] .modal-footer {
  border-top-color: var(--border-color);
}
[data-theme="dark"] .modal-body label,
[data-theme="dark"] .modal-body .form-label {
  color: var(--text-primary);
}
[data-theme="dark"] .modal-body .form-text {
  color: var(--text-muted);
}

/* Fondos suaves adaptados al tema oscuro */
[data-theme="dark"] .bg-primary-soft { background: rgba(37, 99, 235, 0.16); }
[data-theme="dark"] .bg-warning-soft { background: rgba(245, 158, 11, 0.16); }
[data-theme="dark"] .bg-success-soft { background: rgba(34, 197, 94, 0.16); }
[data-theme="dark"] .bg-danger-soft  { background: rgba(239, 68, 68, 0.16); }
[data-theme="dark"] .bg-info-soft    { background: rgba(6, 182, 212, 0.16); }
[data-theme="dark"] .bg-purple-soft  { background: rgba(124, 58, 237, 0.18); }

/* Kanban (usa estilos inline, por eso !important) */
[data-theme="dark"] .kanban-col-wrap { background: var(--bg-surface-2) !important; }
[data-theme="dark"] .kanban-col-wrap > div > span[style*="color:#374151"] { color: var(--text-primary) !important; }
[data-theme="dark"] .kcard { background: var(--bg-surface) !important; border-color: var(--border-color) !important; }
[data-theme="dark"] .kcard p { color: var(--text-primary) !important; }
[data-theme="dark"] .kcard [style*="background:#f1f5f9"] { background: rgba(148, 163, 184, 0.18) !important; color: #cbd5e1 !important; }

/* Auth (login) */
[data-theme="dark"] .auth-card .text-muted { color: var(--text-muted) !important; }
[data-theme="dark"] .auth-body {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%) !important;
}

.auth-theme-toggle {
  position: fixed;
  top: 14px;
  right: 18px;
  z-index: 1050;
  color: var(--text-muted);
}
.auth-theme-toggle:hover { color: var(--text-primary); }

/* ============================================================
   PRINT — Reportes
   ============================================================ */
@media print {
  .sidebar, .topbar, form, .btn, .page-footer { display: none !important; }
  .main-content { margin: 0 !important; }
  .card { border: 1px solid #ccc !important; box-shadow: none !important; }
}

/* Lista de archivos seleccionados en inputs de adjuntos */
.attachment-feedback {
  margin-top: 0.35rem;
  word-break: break-word;
  color: var(--text-muted);
}
.attachment-feedback .bi { flex-shrink: 0; }
