/* ============================================================
   gestor-wl / styles.css
   Variables dinámicas — se sobreescriben desde JS con el
   branding del cliente cargado de Firestore.
   ============================================================ */

/* ── Variables base (fallback mientras carga el branding) ─── */
:root {
  /* Branding — sobrescritos dinámicamente */
  --primary:        #3b82f6;
  --primary-rgb:    59,130,246;
  --primary-dark:   #1d4ed8;
  --accent:         #06b6d4;
  --sidebar-bg:     #1a2236;
  --sidebar-txt:    #c8d3e8;
  --sidebar-act:    #3b82f6;
  --sidebar-w:      240px;

  /* Layout */
  --bg:             #f4f6f9;
  --surface:        #ffffff;
  --text:           #1e293b;
  --text-muted:     #64748b;
  --border:         #e2e8f0;
  --shadow:         0 1px 4px rgba(0,0,0,.07);
  --shadow-md:      0 4px 16px rgba(0,0,0,.1);
  --radius:         8px;
  --radius-lg:      12px;
  --font:           'Inter', system-ui, sans-serif;

  /* Status */
  --green:   #16a34a;
  --red:     #dc2626;
  --yellow:  #d97706;
  --blue:    #2563eb;
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ── PRELOADER ──────────────────────────────────────────────── */
.page-preloader {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(10, 14, 26, 0.55);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex; align-items: center; justify-content: center;
  transition: opacity .3s ease;
}
.page-preloader.hidden {
  opacity: 0; pointer-events: none;
  /* keep backdrop-filter active during fade, then hide */
  animation: preloader-out .3s ease forwards;
}
@keyframes preloader-out {
  from { opacity: 1; }
  to   { opacity: 0; visibility: hidden; }
}
/* Hide old logo/text elements if still in HTML */
.preloader-logo, .preloader-spinner { display: none !important; }

/* The single spinner ring */
.page-preloader::after {
  content: '';
  width: 36px; height: 36px;
  border: 2.5px solid rgba(255,255,255,.12);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── AUTH PAGE ──────────────────────────────────────────────── */
.auth-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--sidebar-bg); padding: 20px;
}
.auth-card {
  background: var(--surface); border-radius: var(--radius-lg);
  padding: 36px 32px; width: 100%; max-width: 420px;
  box-shadow: var(--shadow-md);
}
.auth-brand {
  text-align: center; margin-bottom: 28px;
}
.auth-brand-logo {
  height: 48px; max-width: 180px; object-fit: contain; margin-bottom: 10px;
}
.auth-brand-name {
  font-size: 22px; font-weight: 800; color: var(--text); letter-spacing: -.5px;
}
.auth-brand-sub { font-size: 13px; color: var(--text-muted); margin-top: 3px; }
.auth-tabs {
  display: flex; border-bottom: 2px solid var(--border); margin-bottom: 22px;
}
.tab-btn {
  flex: 1; padding: 9px; background: none; border: none;
  font-size: 14px; font-weight: 500; color: var(--text-muted);
  border-bottom: 2px solid transparent; margin-bottom: -2px;
  transition: color .15s, border-color .15s;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.auth-form { display: none; }
.auth-form.active { display: block; }
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block; font-size: 12px; font-weight: 600;
  color: var(--text-muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .5px;
}
.form-control {
  width: 100%; padding: 10px 13px;
  border: 1.5px solid var(--border); border-radius: var(--radius);
  font-size: 14px; color: var(--text); background: var(--surface);
  transition: border-color .15s, box-shadow .15s; outline: none;
}
.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(var(--primary-rgb), .12);
}
.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.auth-footer { margin-top: 12px; text-align: right; }
.link-btn {
  background: none; border: none; color: var(--primary);
  font-size: 12px; cursor: pointer; text-decoration: underline;
}
.auth-alert {
  padding: 10px 13px; border-radius: var(--radius);
  font-size: 13px; margin-bottom: 14px;
}
.auth-alert.error   { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }
.auth-alert.success { background: #f0fdf4; color: #16a34a; border: 1px solid #bbf7d0; }
.auth-alert.hidden  { display: none; }

/* ── BUTTONS ────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: .55rem 1.1rem; border-radius: var(--radius);
  font-size: 14px; font-weight: 500; border: none;
  transition: filter .15s, opacity .15s; white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn:not(:disabled):hover { filter: brightness(1.07); }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-danger    { background: #dc2626; color: #fff; }
.btn-warning   { background: #d97706; color: #fff; }
.btn-success   { background: #16a34a; color: #fff; }
.btn-ghost     { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-sm        { padding: .35rem .75rem; font-size: 12px; }
.btn-lg        { padding: .75rem 1.5rem; font-size: 15px; }
.btn-block     { width: 100%; justify-content: center; }
.btn-loader, .btn-text { display: flex; align-items: center; gap: 6px; }
.hidden { display: none !important; }

/* ── LAYOUT ─────────────────────────────────────────────────── */
.app-layout { display: flex; min-height: 100vh; }

/* ── SIDEBAR ────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w); background: var(--sidebar-bg);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; height: 100vh;
  z-index: 100; transition: transform .25s;
  overflow-y: auto; overflow-x: hidden;
}
.sidebar-brand {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,.07);
  flex-shrink: 0;
}
.brand-logo-img  { height: 32px; max-width: 140px; object-fit: contain; }
.brand-logo-text {
  font-size: 18px; font-weight: 800; color: #fff;
  letter-spacing: -.5px; line-height: 1;
}
.brand-logo-text span { color: var(--primary); }
.sidebar-close {
  background: none; border: none; color: rgba(255,255,255,.4);
  display: none; padding: 4px;
}
.sidebar-nav   { flex: 1; padding: 10px 0; overflow-y: auto; }
.nav-section-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1px; color: rgba(255,255,255,.3);
  padding: 14px 16px 5px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 16px; color: var(--sidebar-txt);
  font-size: 13.5px; font-weight: 400;
  transition: background .15s, color .15s;
  position: relative;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active {
  background: rgba(var(--primary-rgb), .18);
  color: #fff; font-weight: 600;
}
.nav-item.active::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--primary); border-radius: 0 2px 2px 0;
}
.nav-icon { display: flex; align-items: center; justify-content: center; opacity: .75; flex-shrink: 0; width: 18px; }
.nav-icon i { font-size: 15px; line-height: 1; position: relative; top: 1px; }
.nav-item.active .nav-icon, .nav-item:hover .nav-icon { opacity: 1; }
.nav-badge {
  margin-left: auto; background: var(--primary); color: #fff;
  font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 10px;
}
.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,.07);
  padding: 12px 14px; flex-shrink: 0;
}
.user-info { color: rgba(255,255,255,.7); font-size: 12px; margin-bottom: 8px; line-height: 1.5; }
.user-info strong { color: #fff; font-size: 13px; }
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.5); z-index: 99;
}

/* ── MAIN CONTENT ───────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w); flex: 1;
  display: flex; flex-direction: column; min-height: 100vh;
}
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 24px; height: 56px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-menu-btn {
  display: none; background: none; border: none;
  color: var(--text-muted); padding: 6px;
}
.topbar-title { font-size: 16px; font-weight: 600; color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.page-content { flex: 1; padding: 24px; }

/* ── PAGES ──────────────────────────────────────────────────── */
.page          { display: none; }
.page.active   { display: block; }
.page-heading  {
  font-size: 20px; font-weight: 700; color: var(--text);
  margin-bottom: 20px;
}
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px; margin-bottom: 20px;
}
.page-header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── CARDS / STATS ──────────────────────────────────────────── */
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px; margin-bottom: 22px;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 18px 20px;
}
.stat-value {
  font-size: 26px; font-weight: 800; line-height: 1;
  margin-bottom: 5px; color: var(--text);
}
.stat-value.primary { color: var(--primary); }
.stat-value.green   { color: var(--green);   }
.stat-value.red     { color: var(--red);     }
.stat-value.yellow  { color: var(--yellow);  }
.stat-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.stat-icon  { font-size: 24px; margin-bottom: 8px; }

/* ── CARDS ──────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden;
  margin-bottom: 20px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.card-title { font-size: 14px; font-weight: 600; color: var(--text); }
.card-body  { padding: 18px; }

/* ── TABLES ─────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.data-table th {
  padding: 9px 12px; text-align: left; font-size: 11px;
  font-weight: 700; text-transform: uppercase; letter-spacing: .6px;
  color: var(--text-muted); background: #f8fafc;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.data-table td {
  padding: 11px 12px; border-bottom: 1px solid var(--border);
  color: var(--text); vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #f8fafc; }
.table-empty {
  text-align: center; padding: 40px 20px !important;
  color: var(--text-muted); font-size: 14px;
}
.actions-cell { display: flex; gap: 5px; align-items: center; }

/* ── BADGES ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 600;
}
.badge-success { background: #dcfce7; color: #16a34a; }
.badge-danger  { background: #fee2e2; color: #dc2626; }
.badge-warning { background: #fef3c7; color: #d97706; }
.badge-info    { background: #dbeafe; color: #2563eb; }
.badge-neutral { background: #f1f5f9; color: #64748b; }
.badge-purple  { background: #f3e8ff; color: #7c3aed; }

/* ── FORMS ──────────────────────────────────────────────────── */
.form-row {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 14px; margin-bottom: 14px;
}
.form-group-full { margin-bottom: 14px; }
.input, select.input, textarea.input {
  width: 100%; padding: 9px 12px;
  border: 1.5px solid var(--border); border-radius: var(--radius);
  font-size: 13.5px; color: var(--text); background: var(--surface);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus, select.input:focus, textarea.input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(var(--primary-rgb), .1);
}
.input-label {
  display: block; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-muted); margin-bottom: 5px;
}
textarea.input { resize: vertical; line-height: 1.6; }

/* ── MODAL ──────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.55); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; opacity: 0; visibility: hidden;
  transition: opacity .2s, visibility .2s;
}
.modal-overlay.show { opacity: 1; visibility: visible; }
.modal {
  background: var(--surface); border-radius: var(--radius-lg);
  width: 100%; max-height: calc(100dvh - 40px);
  display: flex; flex-direction: column;
  transform: translateY(16px) scale(.98);
  transition: transform .2s; overflow: hidden;
}
.modal-overlay.show .modal { transform: translateY(0) scale(1); }
.modal-sm  { max-width: 420px; }
.modal-md  { max-width: 560px; }
.modal-lg  { max-width: 720px; }
.modal-xl  { max-width: 900px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-title { font-size: 16px; font-weight: 700; }
.modal-close {
  width: 32px; height: 32px; border-radius: 50%;
  background: #f1f5f9; border: none; color: var(--text-muted);
  font-size: 17px; display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.modal-close:hover { background: #e2e8f0; }
.modal-body {
  flex: 1; overflow-y: auto; padding: 20px;
}
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 14px 20px; border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── TOASTS ─────────────────────────────────────────────────── */
.toast-wrap {
  position: fixed; bottom: 20px; right: 20px;
  z-index: 9000; display: flex; flex-direction: column; gap: 8px;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 16px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500; color: #fff;
  box-shadow: var(--shadow-md); min-width: 240px; max-width: 360px;
  animation: toastIn .2s ease;
}
.toast.success { background: #16a34a; }
.toast.error   { background: #dc2626; }
.toast.info    { background: #2563eb; }
.toast.warning { background: #d97706; }
@keyframes toastIn { from { opacity:0; transform:translateY(10px); } }

/* ── SEARCH / FILTERS ───────────────────────────────────────── */
.search-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px; background: var(--surface);
  border: 1.5px solid var(--border); border-radius: 40px;
  transition: border-color .15s;
}
.search-bar:focus-within { border-color: var(--primary); }
.search-bar input {
  background: none; border: none; outline: none;
  font-size: 13px; color: var(--text); width: 100%;
}
.search-bar input::placeholder { color: var(--text-muted); }
.filter-bar {
  display: flex; gap: 10px; flex-wrap: wrap;
  align-items: center; margin-bottom: 16px;
}

/* ── KANBAN (CRM) ───────────────────────────────────────────── */
.kanban-wrap {
  display: flex; gap: 14px; overflow-x: auto; padding-bottom: 8px;
  -webkit-overflow-scrolling: touch;
}
.kanban-col {
  flex: 0 0 280px; background: #f1f5f9;
  border-radius: var(--radius-lg); padding: 12px;
  min-height: 200px;
}
.kanban-col-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px; padding-bottom: 10px;
  border-bottom: 2px solid var(--border);
}
.kanban-col-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .6px; color: var(--text-muted);
}
.kanban-col-count {
  background: var(--border); color: var(--text-muted);
  border-radius: 10px; font-size: 11px; font-weight: 700;
  padding: 2px 7px;
}
.kanban-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; margin-bottom: 8px;
  cursor: pointer; transition: box-shadow .15s, border-color .15s;
}
.kanban-card:hover {
  box-shadow: var(--shadow-md);
  border-color: rgba(var(--primary-rgb), .3);
}
.kanban-card-name  { font-weight: 600; font-size: 13.5px; margin-bottom: 4px; }
.kanban-card-sub   { font-size: 12px; color: var(--text-muted); }
.kanban-card-footer {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border);
}

/* ── DROPDOWN ───────────────────────────────────────────────── */
.empresa-select {
  padding: 6px 10px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 13px;
  background: var(--surface); color: var(--text); outline: none;
  cursor: pointer; max-width: 200px;
}

/* ── BACKEND STATUS ─────────────────────────────────────────── */
.backend-status {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-muted);
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--border);
}
.status-dot.online  { background: var(--green); box-shadow: 0 0 5px rgba(22,163,74,.4); }
.status-dot.offline { background: var(--red); }

/* ── ACCESOS DIRECTOS (Dashboard) ───────────────────────────── */
.shortcuts-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px; margin-bottom: 24px;
}
.shortcut-btn {
  display: flex; align-items: center; gap: 13px;
  padding: 14px 16px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  color: var(--text); text-align: left; width: 100%;
  transition: border-color .2s, box-shadow .2s, transform .15s;
}
.shortcut-btn:hover {
  border-color: rgba(var(--primary-rgb), .4);
  box-shadow: var(--shadow-md); transform: translateY(-1px);
}
.shortcut-icon {
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.shortcut-name { font-weight: 600; font-size: 13.5px; margin-bottom: 2px; }
.shortcut-desc { font-size: 11px; color: var(--text-muted); }

/* ── RESPONSIVE ─────────────────────────────────────────────── */
@media (max-width: 900px) {
  .form-row { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: flex; }
  .sidebar-overlay.open { display: block; }
  .main-content { margin-left: 0; }
  .topbar-menu-btn { display: flex; }
  .page-content { padding: 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .shortcuts-grid { grid-template-columns: 1fr 1fr; }
  .modal-overlay { padding: 12px; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .shortcuts-grid { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .filter-bar  { flex-direction: column; }
}
