:root {
  --brand-primary: #2563eb;
  --brand-primary-soft: rgba(37, 99, 235, 0.08);
  --topbar-height: 4.75rem;
  --color-bg: #bec5d0;
  --color-surface: #d3d8e0;
  --color-surface-alt: #ccd1da;
  --color-border: #c0c7d1;
  --color-border-subtle: #ccd2da;
  --text-primary: #1a1f28;
  --text-secondary: #4a5568;
  --text-muted: #717d8e;
  --success: #0f8a3f;
  --success-soft: rgba(15, 138, 63, 0.1);
  --warning: #b45309;
  --warning-soft: rgba(180, 83, 9, 0.1);
  --danger: #c41e1e;
  --danger-soft: rgba(196, 30, 30, 0.08);
  --shadow-soft: 0 1px 3px rgba(0, 0, 0, 0.06), 0 2px 8px rgba(0, 0, 0, 0.04);
  --radius-lg: 0.85rem;
}

html {
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

body.selvik-body {
  background: var(--color-bg);
  color: var(--text-primary);
  font-family: "Inter", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
  width: 100%;
}

* {
  box-sizing: border-box;
}

/* Force tables to not exceed viewport */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.selvik-body.theme-public {
  background: #c2c8d2;
  color: #1a1f28;
}

.selvik-body.theme-public main {
  color: inherit;
}

.auth-page main {
  min-height: 100vh;
  display: flex;
  align-items: center;
}

a,
button {
  cursor: pointer;
}

a {
  color: var(--brand-primary);
  text-decoration: none;
}

a:hover {
  color: #1d4ed8;
}

main {
  color: var(--text-primary);
}

.app-shell {
  min-height: calc(100vh - 4.75rem);
}

.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-soft);
  color: var(--text-primary);
}

.card-header {
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface-alt);
}

.card.bg-transparent {
  box-shadow: none;
  border-color: transparent;
}

.badge-soft {
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  font-weight: 600;
  font-size: 0.75rem;
}

.badge-soft-success {
  background: var(--success-soft);
  color: var(--success);
}

.badge-soft-warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.badge-soft-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge.badge-warning-readable {
  background: #d97706;
  color: #111827;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.7rem;
  padding: 0.25rem 0.75rem;
  text-transform: capitalize;
}

.status-active {
  background: var(--success-soft);
  color: var(--success);
}

.status-prospect {
  background: rgba(37, 99, 235, 0.1);
  color: #1d4ed8;
}

.status-negotiating {
  background: var(--warning-soft);
  color: #92400e;
}

.status-lead {
  background: rgba(126, 58, 242, 0.1);
  color: #6d28d9;
}

.status-closing {
  background: var(--danger-soft);
  color: var(--danger);
}

.topbar.navbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding-block: 0.85rem;
  color: var(--text-primary);
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

.topbar .container-fluid {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.topbar .navbar-collapse {
  flex: 1 1 auto;
}

.topbar .navbar-nav {
  width: 100%;
}


.navbar-brand {
  color: var(--text-primary);
  font-weight: 600;
  letter-spacing: 0.01em;
}

.navbar-brand:hover {
  color: var(--text-primary);
}

.brand-title {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.75rem;
  background: var(--color-surface-alt);
  color: var(--text-primary);
  font-weight: 700;
  font-size: 1.25rem;
}

.navbar .nav-link {
  color: var(--text-secondary);
  font-weight: 500;
  border-radius: 0.75rem;
  padding: 0.55rem 0.95rem;
  transition: background 0.2s ease, color 0.2s ease;
}

.navbar .nav-link:hover,
.navbar .nav-link:focus {
  color: var(--text-primary);
  background: rgba(0, 0, 0, 0.04);
}

.navbar .nav-link.active,
.navbar .nav-link.active:hover {
  background: var(--color-surface-alt);
  color: var(--text-primary);
  font-weight: 700;
}

.navbar .dropdown-menu {
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
}

.navbar .dropdown-item {
  color: var(--text-secondary);
}

.navbar .dropdown-item:hover {
  color: var(--text-primary);
  background: rgba(0, 0, 0, 0.04);
}

.navbar-toggler {
  border: none;
  background-color: rgba(0, 0, 0, 0.05);
}

.navbar-toggler:focus {
  box-shadow: none;
}

.navbar-toggler-icon {
  filter: none;
}

.btn-icon {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 999px;
  border: 1px solid transparent;
  color: var(--text-secondary);
  background: var(--color-surface-alt);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease, background 0.2s ease;
}

.btn-icon:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--text-primary);
}

.topbar-search {
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 0.25rem 0.75rem 0.25rem 2.4rem;
  color: var(--text-secondary);
  min-width: 12rem;
}

.topbar-search .form-control {
  background: transparent;
  border: none;
  color: inherit;
  padding: 0;
  height: 2rem;
}

.topbar-search .form-control::placeholder {
  color: var(--text-muted);
}

.topbar-search .form-control:focus {
  box-shadow: none;
  outline: none;
}

.topbar-search i {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.95rem;
}

.topbar-actions {
  margin-left: auto;
}


.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  background: rgba(0, 0, 0, 0.04);
  border-radius: 999px;
  padding: 0.45rem 1rem;
  color: var(--text-primary);
}

.user-chip__name {
  font-weight: 600;
  font-size: 0.95rem;
}

.avatar-circle {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.06);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Marca en topbar (modo móvil) */
.topbar-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: 0.5rem;
}

.topbar-brand .brand-mark {
  width: 2.3rem;
  height: 2.3rem;
  border-radius: 0.7rem;
  font-size: 1.15rem;
}

.topbar-brand .brand-title {
  font-size: 1.25rem;
  letter-spacing: 0.1em;
}

.table-dark {
  --bs-table-bg: transparent;
  --bs-table-striped-bg: rgba(0, 0, 0, 0.02);
  color: var(--text-primary);
}

.table-dark tbody tr:hover {
  background: rgba(0, 0, 0, 0.03);
}

.table-responsive {
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
}

.table thead th {
  border-bottom-width: 1px;
  border-color: var(--color-border);
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  text-transform: uppercase;
  color: var(--text-secondary);
  background: var(--color-surface-alt);
  font-weight: 600;
}

.table > :not(caption) > * > * {
  border-bottom-color: rgba(0, 0, 0, 0.06);
}

/* Tabla de ficha de producto: campos claramente diferenciados */
.product-detail-table {
  border-collapse: separate;
  border-spacing: 0;
}

.product-detail-table tbody tr {
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.product-detail-table tbody tr:nth-child(odd) {
  background: rgba(0, 0, 0, 0.02);
}

.product-detail-table th {
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 0.6rem 1rem;
  border-right: 1px solid rgba(0, 0, 0, 0.06);
  width: 32%;
  white-space: nowrap;
}

.product-detail-table td {
  font-weight: 500;
  padding: 0.6rem 1rem;
}

.product-detail-table tbody tr:first-child th,
.product-detail-table tbody tr:first-child td {
  border-top-left-radius: 0.9rem;
  border-top-right-radius: 0.9rem;
}

.product-detail-table tbody tr:last-child th,
.product-detail-table tbody tr:last-child td {
  border-bottom-left-radius: 0.9rem;
  border-bottom-right-radius: 0.9rem;
}

.text-muted {
  color: var(--text-secondary) !important;
}

.btn-outline-secondary {
  color: var(--text-primary);
  border-color: var(--color-border);
}

.btn-outline-secondary:hover {
  background: rgba(0, 0, 0, 0.04);
  border-color: #cbd5e1;
}

@media (max-width: 991.98px) {
  .topbar {
    padding-inline: 0.75rem;
  }

  .topbar .container-fluid {
    position: static;
  }

  .topbar-search {
    width: 100%;
  }

  /* Mantener visibles las acciones (carrito, usuario) en móvil */
  .topbar-actions {
    display: flex !important;
  }

  .navbar .nav-link {
    width: 100%;
  }

  .user-chip {
    width: auto;
    justify-content: flex-start;
  }
}

/* Quote Cart Button Styles */
.btn-icon {
  position: relative;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-icon:hover {
  background: rgba(0, 0, 0, 0.08);
}

.btn-icon i {
  font-size: 1.25rem;
}

.quote-cart-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #ef4444;
  color: white;
  border-radius: 999px;
  min-width: 18px;
  height: 18px;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0 4px;
}

/* Sidebar Layout */
.app-layout {
  display: flex;
  min-height: calc(100vh - var(--topbar-height));
  padding-top: var(--topbar-height);
}

.sidebar {
  width: 220px;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  height: calc(100vh - var(--topbar-height));
  display: flex;
  flex-direction: column;
  z-index: 1050;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sidebar-nav {
  padding: 1rem 0;
  flex: 1 1 auto;
  overflow-y: auto;
}

.sidebar-nav .nav-link {
  padding: 0.875rem 1.5rem;
  color: #0f1318;
  display: flex;
  align-items: center;
  gap: 0.875rem;
  transition: all 0.2s;
  text-decoration: none;
  border-left: 3px solid transparent;
  font-weight: 600;
  font-size: 0.92rem;
}

.sidebar-nav .nav-link:hover {
  background: rgba(0, 0, 0, 0.06);
  color: #0a0d11;
}

.sidebar-nav .nav-link.active {
  background: rgba(0, 0, 0, 0.08);
  color: #050709;
  border-left-color: #050709;
  font-weight: 700;
}

.sidebar-nav .nav-link i {
  font-size: 1.25rem;
  width: 1.25rem;
  text-align: center;
}

.sidebar-nav-group {
  margin: 0;
}

.sidebar-nav-group > summary {
  list-style: none;
}

.sidebar-nav-group > summary::-webkit-details-marker {
  display: none;
}

.sidebar-nav-group__chevron {
  font-size: 0.9rem;
  opacity: 0.75;
  transition: transform 0.2s ease;
}

.sidebar-nav-group[open] .sidebar-nav-group__chevron {
  transform: rotate(180deg);
}

.sidebar-subnav {
  padding: 0.25rem 0 0.5rem;
}

.sidebar-subnav .nav-link.nav-link--sub {
  padding-top: 0.65rem;
  padding-bottom: 0.65rem;
  padding-left: 3.15rem;
  font-size: 0.92rem;
}

.sidebar-subnav .nav-link.nav-link--sub i {
  font-size: 1.05rem;
}

@media (min-width: 992px) {
  body.sidebar-collapsed .sidebar-nav-group__chevron {
    display: none;
  }
}

.sidebar-footer {
  padding: 0.75rem 1.5rem 1.25rem;
  border-top: 1px solid var(--color-border);
}

.sidebar-logout-form {
  margin: 0;
}

.sidebar-logout-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  border-radius: 999px;
  border: 1px solid rgba(220, 38, 38, 0.3);
  background: rgba(220, 38, 38, 0.06);
  color: #dc2626;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.55rem 1.1rem;
}

.sidebar-logout-btn i {
  font-size: 1.1rem;
}

.sidebar-logout-btn:hover {
  background: rgba(220, 38, 38, 0.12);
  color: #b91c1c;
}

/* Botón para colapsar sidebar (desktop) */
.sidebar-collapse-toggle {
  margin-left: auto;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid var(--color-border);
  color: var(--text-secondary);
}

.sidebar-collapse-toggle:hover {
  background: rgba(0, 0, 0, 0.08);
  color: var(--text-primary);
}

/* Modo colapsado: sidebar estrecho solo con iconos */
@media (min-width: 992px) {
  body.sidebar-collapsed .sidebar {
    width: 72px;
  }

  body.sidebar-collapsed .main-content {
    margin-left: 72px;
  }

  body.sidebar-collapsed .sidebar-header .brand-title,
  body.sidebar-collapsed .sidebar-nav .nav-link span {
    display: none;
  }

  body.sidebar-collapsed .sidebar-nav .nav-link {
    justify-content: center;
    padding-inline: 0;
  }
}

.main-content {
  margin-left: 220px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1100; /* por encima de sidebar (1050) y overlay (1049) */
}

/* Móvil */
@media (max-width: 991.98px) {
  .sidebar {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    transform: translateX(-100%);
  }
  
  .sidebar.show {
    transform: translateX(0);
  }
  
  .main-content {
    margin-left: 0;
  }
  
  .sidebar-overlay {
    display: none;
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1049;
  }
  
  .sidebar-overlay.show {
    display: block;
  }
}

/* ============================================
   Bootstrap overrides for light theme
   ============================================ */

/* Force all body text to be dark */
body, .card, .card-body, .card-title, .card-text,
.list-group-item, .modal-body, .offcanvas-body,
h1, h2, h3, h4, h5, h6,
p, span, div, td, th, li, label, small {
  color: var(--text-primary);
}

.text-muted, small.text-muted {
  color: var(--text-secondary) !important;
}

.text-body-secondary {
  color: var(--text-secondary) !important;
}

/* Form controls */
.form-control,
.form-select {
  background: var(--color-surface);
  border-color: var(--color-border);
  color: var(--text-primary);
}

.form-control:focus,
.form-select:focus {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 0.2rem rgba(37, 99, 235, 0.15);
  background: var(--color-surface);
}

.form-control::placeholder {
  color: var(--text-muted);
}

.form-label {
  color: var(--text-primary);
  font-weight: 600;
}

/* Buttons */
.btn-outline-danger {
  color: var(--danger);
  border-color: var(--danger);
  background: transparent;
}

.btn-outline-danger:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn-outline-secondary {
  color: var(--text-primary);
  border-color: var(--color-border);
  background: var(--color-surface);
}

.btn-outline-secondary:hover {
  background: var(--color-surface-alt);
  border-color: var(--color-border);
  color: var(--text-primary);
}

.btn-primary {
  background: var(--brand-primary);
  border-color: var(--brand-primary);
  color: #fff;
}

.btn-primary:hover {
  background: #1e40af;
  border-color: #1e40af;
  color: #fff;
}

/* Tables */
.table {
  color: var(--text-primary);
  --bs-table-bg: transparent;
  --bs-table-color: var(--text-primary);
}

.table > :not(caption) > * > * {
  color: var(--text-primary);
  background-color: transparent;
  border-bottom-color: var(--color-border);
}

.table-striped > tbody > tr:nth-of-type(odd) > * {
  background-color: rgba(0, 0, 0, 0.02);
  color: var(--text-primary);
}

.table-hover > tbody > tr:hover > * {
  background-color: rgba(37, 99, 235, 0.05);
  color: var(--text-primary);
}

/* Badge overrides */
.badge.bg-primary { background-color: var(--brand-primary) !important; color: #fff !important; }
.badge.bg-success { background-color: var(--success) !important; color: #fff !important; }
.badge.bg-warning { background-color: var(--warning) !important; color: #fff !important; }
.badge.bg-danger { background-color: var(--danger) !important; color: #fff !important; }
.badge.bg-info { background-color: #0284c7 !important; color: #fff !important; }
.badge.bg-secondary { background-color: #6b7280 !important; color: #fff !important; }

/* Text color utilities */
.text-primary { color: var(--brand-primary) !important; }
.text-success { color: var(--success) !important; }
.text-warning { color: var(--warning) !important; }
.text-danger { color: var(--danger) !important; }
.text-info { color: #0284c7 !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-dark { color: var(--text-primary) !important; }

/* Links */
a {
  color: var(--brand-primary);
}

a:hover {
  color: #1e40af;
}

.table a {
  color: var(--brand-primary);
  font-weight: 500;
}

.table a:hover {
  color: #1e40af;
  text-decoration: underline;
}

/* Card header/title */
.card-title {
  color: var(--text-primary) !important;
  font-weight: 600;
}

.card-header {
  color: var(--text-primary);
}

/* Dropdown menus */
.dropdown-menu {
  background: var(--color-surface);
  border-color: var(--color-border);
  box-shadow: var(--shadow-soft);
}

.dropdown-item {
  color: var(--text-primary);
}

.dropdown-item:hover {
  background: var(--color-surface-alt);
  color: var(--text-primary);
}

/* Modal */
.modal-content {
  background: var(--color-surface);
  border-color: var(--color-border);
  color: var(--text-primary);
}

.modal-header {
  border-bottom-color: var(--color-border);
}

.modal-footer {
  border-top-color: var(--color-border);
}

/* Alerts */
.alert {
  border-radius: var(--radius-lg);
}

/* Nav tabs/pills */
.nav-tabs .nav-link {
  color: var(--text-secondary);
}

.nav-tabs .nav-link.active {
  color: var(--text-primary);
  background: var(--color-surface);
  border-color: var(--color-border);
}

.nav-pills .nav-link {
  color: var(--text-secondary);
}

.nav-pills .nav-link.active {
  background: var(--brand-primary);
  color: #fff;
}

/* Accordion */
.accordion-button {
  background: var(--color-surface);
  color: var(--text-primary);
}

.accordion-button:not(.collapsed) {
  background: var(--color-surface-alt);
  color: var(--text-primary);
}

/* Pagination */
.page-link {
  color: var(--text-primary);
  background: var(--color-surface);
  border-color: var(--color-border);
}

.page-item.active .page-link {
  background: var(--brand-primary);
  border-color: var(--brand-primary);
  color: #fff;
}

/* Quote Cart: ocultar acciones por defecto hasta que JS determine si hay items */
.quote-cart-actions-main,
.quote-cart-actions {
  display: none;
}
