/* ============================================================
   GoCRM — Estilos base y layout
   ============================================================ */

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --sidebar: #0f172a;
  --sidebar-hover: rgba(255, 255, 255, 0.06);
  --primary: #4f46e5;
  --primary-600: #4338ca;
  --primary-soft: #eef2ff;
  --text: #0f172a;
  --muted: #64748b;
  --muted-2: #94a3b8;
  --border: #e2e8f0;
  --border-soft: #eef2f7;
  --success: #15803d;
  --success-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --info: #1d4ed8;
  --info-bg: #dbeafe;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.08);
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow-x: hidden;
  max-width: 100vw;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, p { margin: 0; }
a { color: var(--primary); text-decoration: none; }
button { font-family: inherit; }
::selection { background: #c7d2fe; }

/* Scrollbars discretos y estándar */
.view,
.modal-body,
.table-wrap {
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}
.view::-webkit-scrollbar,
.modal-body::-webkit-scrollbar,
.table-wrap::-webkit-scrollbar { width: 9px; height: 9px; }
.view::-webkit-scrollbar-track,
.modal-body::-webkit-scrollbar-track,
.table-wrap::-webkit-scrollbar-track {
  background: transparent;
}
.view::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb,
.table-wrap::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 999px;
}
.view::-webkit-scrollbar-thumb:hover,
.modal-body::-webkit-scrollbar-thumb:hover,
.table-wrap::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

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

.app {
  display: flex;
  flex-direction: row;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

.sidebar {
  width: 252px;
  min-width: 252px;
  max-width: 252px;
  flex-shrink: 0;
  background: var(--sidebar);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  z-index: 60;
  transition: margin-left 0.2s ease, opacity 0.2s ease;
}

.app.sidebar-collapsed .sidebar {
  margin-left: -252px;
  opacity: 0;
  pointer-events: none;
}

.main {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 20px 18px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  font-size: 20px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, #6366f1, #4f46e5 55%, #4338ca);
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.4);
  flex: none;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { color: #fff; font-size: 17px; letter-spacing: 0.2px; }
.brand-text span { color: #94a3b8; font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.09em; margin-top: 2px; }

.nav { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; }

.sidebar-backdrop { display: none; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 13px;
  border-radius: 10px;
  color: #cbd5e1;
  font-size: 13.5px;
  font-weight: 600;
  transition: background 0.15s, color 0.15s;
}

.nav-item svg { width: 18px; height: 18px; flex: none; opacity: 0.85; }
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.35);
}
.nav-item.active svg { opacity: 1; }

.sidebar-foot {
  margin-top: auto;
  padding: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.db-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #94a3b8;
  font-weight: 600;
}

.db-status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.18);
}

/* ---------------- Topbar ---------------- */

.topbar {
  height: 74px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-title { min-width: 0; }
.topbar-title h1 { font-size: 19px; font-weight: 700; letter-spacing: -0.2px; }
.topbar-title p { font-size: 12.5px; color: var(--muted); margin-top: 1px; }

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 14px;
}

.date-chip {
  font-size: 12.5px;
  font-weight: 600;
  color: #475569;
  background: #f1f5f9;
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
}

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

.user-chip .avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
  font-size: 12.5px;
  font-weight: 800;
}

.user-info { display: flex; flex-direction: column; line-height: 1.2; }
.user-info strong { font-size: 13px; }
.user-info span { font-size: 11.5px; color: var(--muted); }

/* ---------------- Vista ---------------- */

.view {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 24px 28px 56px;
  display: flex;
  flex-direction: column;
}

.view:not(.view-tpv) > * {
  flex-shrink: 0;
}

.view.view-tpv {
  padding: 4px 6px;
  overflow: hidden !important;
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
}

.app.tpv-active .topbar {
  display: none !important;
}

.topbar.tpv-compact {
  height: 46px;
  padding: 0 16px;
}

.topbar.tpv-compact .topbar-title h1 {
  font-size: 16px;
}

.topbar.tpv-compact .topbar-title p {
  display: none;
}

.only-mobile { display: none !important; }

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

@media (max-width: 900px) {
  html, body {
    overflow-x: hidden !important;
    overflow-x: clip !important;
    max-width: 100vw !important;
    width: 100% !important;
    position: relative;
    touch-action: pan-y !important;
  }

  .app {
    display: flex;
    overflow-x: hidden !important;
    overflow-x: clip !important;
    max-width: 100vw !important;
    width: 100% !important;
    min-width: 0 !important;
  }

  .main {
    overflow-x: hidden !important;
    overflow-x: clip !important;
    overflow-y: hidden !important;
    max-width: 100vw !important;
    width: 100% !important;
    min-width: 0 !important;
    height: 100% !important;
  }

  .view {
    flex: 1 1 auto;
    padding: 8px 10px 85px 10px !important;
    overflow-x: hidden !important;
    overflow-x: clip !important;
    overflow-y: auto !important;
    max-width: 100vw !important;
    width: 100% !important;
    min-width: 0 !important;
    height: auto !important;
    min-height: 0 !important;
    box-sizing: border-box !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    touch-action: pan-y !important;
  }

  .view.view-tpv {
    padding: 6px 6px 85px 6px !important;
    overflow-x: hidden !important;
    overflow-x: clip !important;
    overflow-y: auto !important;
    height: auto !important;
    min-height: 100% !important;
    max-width: 100vw !important;
    width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y !important;
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 264px;
    margin-left: 0 !important;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: 0 0 40px rgba(2, 6, 23, 0.35);
  }

  .app.sidebar-collapsed .sidebar {
    margin-left: 0 !important;
  }

  .app.sidebar-open .sidebar {
    transform: translateX(0) !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    visibility: visible !important;
    z-index: 999 !important;
  }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 990;
  }

  .app.sidebar-open .sidebar-backdrop {
    display: block !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    visibility: visible !important;
    z-index: 990 !important;
  }

  .topbar {
    padding: 0 12px;
    height: 56px;
    width: 100%;
    max-width: 100vw;
    min-width: 0 !important;
    overflow-x: clip !important;
    box-sizing: border-box;
  }
  .topbar-title h1 { font-size: 16px; }
  .topbar-title p { display: none; }
  .date-chip { display: none; }
  .user-info { display: none; }
}

@media (max-width: 767px) {
  .only-mobile { display: block !important; }
  div.only-mobile { display: flex !important; }
  button.only-mobile, a.only-mobile, span.only-mobile { display: inline-flex !important; }
}
