/* =========================================================
   🌐 ESTILOS RESPONSIVOS POLIUTECH
   ========================================================= */

/* === Base general (solo pequeños ajustes visuales globales) === */
html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  background-color: #ffffff;
  font-family: "Inter", "Segoe UI", sans-serif;
  color: #222;
}

/* === SELECTOR Y PALETA DE TEMA === */
.theme-toggle {
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.48);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.18);
  font-size: 1.25rem;
  line-height: 1;
  transition: background-color .18s ease, transform .18s ease, box-shadow .18s ease;
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
  background: rgba(255, 255, 255, 0.24);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.26);
  transform: translateY(-1px) rotate(8deg);
  outline: 2px solid #ffc107;
  outline-offset: 2px;
}

.theme-toggle-icon { pointer-events: none; }

html[data-bs-theme="dark"] {
  color-scheme: dark;
  --bs-body-bg: #0f172a;
  --bs-body-color: #e5e7eb;
  --bs-secondary-bg: #172033;
  --bs-tertiary-bg: #1e293b;
  --bs-border-color: #39465c;
  --bs-emphasis-color: #f8fafc;
  --bs-secondary-color: #aeb9ca;
  --bs-link-color: #7db7ff;
  --bs-link-hover-color: #a9d0ff;
}

html[data-bs-theme="dark"] body,
html[data-bs-theme="dark"] body.auth-page {
  background-color: #0b1220;
  color: #e5e7eb;
}

html[data-bs-theme="dark"] .app-content,
html[data-bs-theme="dark"] .auth-content {
  background: #0f172a !important;
  color: #e5e7eb;
}

.topbar-logo {
  width: 58px !important;
  height: 48px !important;
  padding: 2px;
  object-fit: contain !important;
  background: #fff;
  border-radius: 8px;
}

.topbar-logo-dark { display: none; }
html[data-bs-theme="dark"] .topbar-logo-light { display: none; }
html[data-bs-theme="dark"] .topbar-logo-dark {
  display: block;
  width: 58px !important;
  background: #081b35;
  box-shadow: none;
}

html[data-bs-theme="dark"] .topbar,
html[data-bs-theme="dark"] .side-menu {
  background: #081b35;
  border-color: #183a62;
}

html[data-bs-theme="dark"] .card,
html[data-bs-theme="dark"] .modal-content,
html[data-bs-theme="dark"] .offcanvas,
html[data-bs-theme="dark"] .dropdown-menu,
html[data-bs-theme="dark"] .list-group-item,
html[data-bs-theme="dark"] .accordion-item,
html[data-bs-theme="dark"] .toast,
html[data-bs-theme="dark"] .bg-white,
html[data-bs-theme="dark"] .bg-light {
  background-color: #172033 !important;
  color: #e5e7eb;
  border-color: #39465c !important;
}

html[data-bs-theme="dark"] .card-header,
html[data-bs-theme="dark"] .card-footer,
html[data-bs-theme="dark"] .modal-header,
html[data-bs-theme="dark"] .modal-footer,
html[data-bs-theme="dark"] .accordion-button {
  background-color: #1e293b;
  color: #f1f5f9;
  border-color: #39465c;
}

html[data-bs-theme="dark"] .card-title,
html[data-bs-theme="dark"] h1,
html[data-bs-theme="dark"] h2,
html[data-bs-theme="dark"] h3,
html[data-bs-theme="dark"] h4,
html[data-bs-theme="dark"] h5,
html[data-bs-theme="dark"] h6,
html[data-bs-theme="dark"] label,
html[data-bs-theme="dark"] .form-label {
  color: #f1f5f9;
}

html[data-bs-theme="dark"] .text-dark { color: #f1f5f9 !important; }
html[data-bs-theme="dark"] .text-muted,
html[data-bs-theme="dark"] .text-secondary { color: #aeb9ca !important; }

html[data-bs-theme="dark"] .table {
  --bs-table-color: #e5e7eb;
  --bs-table-bg: #172033;
  --bs-table-border-color: #39465c;
  --bs-table-striped-bg: #1d293d;
  --bs-table-striped-color: #f1f5f9;
  --bs-table-hover-bg: #24334b;
  --bs-table-hover-color: #fff;
  color: #e5e7eb;
  border-color: #39465c !important;
}

html[data-bs-theme="dark"] .table th,
html[data-bs-theme="dark"] .table thead th {
  background-color: #24334b !important;
  color: #f8fafc;
  border-color: #46546a !important;
}

html[data-bs-theme="dark"] .table td,
html[data-bs-theme="dark"] .table tbody tr,
html[data-bs-theme="dark"] .table tbody tr:nth-child(even) {
  background-color: transparent;
  color: #e5e7eb;
  border-color: #39465c !important;
}

html[data-bs-theme="dark"] .form-control,
html[data-bs-theme="dark"] .form-select,
html[data-bs-theme="dark"] .form-check-input,
html[data-bs-theme="dark"] .input-group-text {
  background-color: #0f172a;
  color: #f1f5f9;
  border-color: #526078;
}

html[data-bs-theme="dark"] .form-control::placeholder { color: #8491a5; opacity: 1; }
html[data-bs-theme="dark"] .form-control:focus,
html[data-bs-theme="dark"] .form-select:focus {
  background-color: #111c30;
  color: #fff;
  border-color: #6ba9f4;
  box-shadow: 0 0 0 .25rem rgba(79, 143, 224, .22);
}

html[data-bs-theme="dark"] .dropdown-item { color: #e5e7eb; }
html[data-bs-theme="dark"] .dropdown-item:hover,
html[data-bs-theme="dark"] .dropdown-item:focus,
html[data-bs-theme="dark"] .list-group-item:hover {
  background-color: #293a55 !important;
  color: #fff;
}

html[data-bs-theme="dark"] footer {
  background: #0b1220;
  border-color: #39465c !important;
}

html[data-bs-theme="dark"] .container,
html[data-bs-theme="dark"] .container-fluid,
html[data-bs-theme="dark"] main,
html[data-bs-theme="dark"] section {
  color: #e5e7eb;
}

html[data-bs-theme="dark"] hr,
html[data-bs-theme="dark"] .border,
html[data-bs-theme="dark"] .border-top,
html[data-bs-theme="dark"] .border-bottom,
html[data-bs-theme="dark"] .border-start,
html[data-bs-theme="dark"] .border-end {
  border-color: #39465c !important;
}

html[data-bs-theme="dark"] .btn-outline-primary,
html[data-bs-theme="dark"] .btn-outline-secondary,
html[data-bs-theme="dark"] .btn-outline-success,
html[data-bs-theme="dark"] .btn-outline-danger,
html[data-bs-theme="dark"] .btn-outline-warning,
html[data-bs-theme="dark"] .btn-outline-info,
html[data-bs-theme="dark"] .btn-outline-dark {
  background-color: #172033;
}

html[data-bs-theme="dark"] .btn-outline-primary { color: #80b9ff; border-color: #4d91e5; }
html[data-bs-theme="dark"] .btn-outline-secondary { color: #d1d8e4; border-color: #7c899e; }
html[data-bs-theme="dark"] .btn-outline-success { color: #65d69a; border-color: #36a66c; }
html[data-bs-theme="dark"] .btn-outline-danger { color: #ff8d98; border-color: #dc5967; }
html[data-bs-theme="dark"] .btn-outline-warning { color: #ffd45c; border-color: #d7a717; }
html[data-bs-theme="dark"] .btn-outline-info { color: #67d9ee; border-color: #29a9c0; }
html[data-bs-theme="dark"] .btn-outline-dark { color: #edf2f7; border-color: #8491a5; }

html[data-bs-theme="dark"] .btn-outline-primary:hover,
html[data-bs-theme="dark"] .btn-outline-secondary:hover,
html[data-bs-theme="dark"] .btn-outline-success:hover,
html[data-bs-theme="dark"] .btn-outline-danger:hover,
html[data-bs-theme="dark"] .btn-outline-warning:hover,
html[data-bs-theme="dark"] .btn-outline-info:hover,
html[data-bs-theme="dark"] .btn-outline-dark:hover {
  color: #fff;
  filter: brightness(1.2);
}

html[data-bs-theme="dark"] .pagination .page-link {
  background: #172033;
  color: #8fc1ff;
  border-color: #39465c;
}

html[data-bs-theme="dark"] .nav-tabs { border-color: #39465c; }
html[data-bs-theme="dark"] .nav-tabs .nav-link { color: #a9d0ff; }
html[data-bs-theme="dark"] .nav-tabs .nav-link.active {
  background: #172033;
  color: #fff;
  border-color: #526078 #526078 #172033;
}

html[data-bs-theme="dark"] .alert-light {
  background: #24334b;
  color: #edf2f7;
  border-color: #526078;
}

html[data-bs-theme="dark"] code,
html[data-bs-theme="dark"] pre { color: #f5a9d0; }

html[data-bs-theme="dark"] ::-webkit-scrollbar { width: 12px; height: 12px; }
html[data-bs-theme="dark"] ::-webkit-scrollbar-track { background: #0b1220; }
html[data-bs-theme="dark"] ::-webkit-scrollbar-thumb {
  background: #526078;
  border: 3px solid #0b1220;
  border-radius: 10px;
}
html[data-bs-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: #718096; }

@media (max-width: 991.98px) {
  .theme-toggle { width: 40px; height: 40px; font-size: 1.1rem; }
  .topbar-brand span { display: none; }
}

/* Centrado y alineación general */
.container {
  margin-left: auto;
  margin-right: auto;
  max-width: 1300px;
}

/* Sombras y bordes suaves */
.card {
  border-radius: 0.75rem;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}
.card-title {
  font-weight: 600;
  color: #0C3C78;
}

/* === TABLAS === */
.table {
  font-size: 0.95rem;
  border-collapse: separate;
  border-spacing: 0;
}
.table th {
  background-color: #f1f3f5;
  font-weight: 600;
  color: #333;
}
.table td {
  vertical-align: middle;
}
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 0.5rem;
}

.horizontal-scroll-shell {
  position: relative;
}

.horizontal-scroll-shell .table-responsive {
  scroll-behavior: smooth;
}

.horizontal-scroll-button {
  position: fixed;
  top: var(--horizontal-scroll-button-top, 50%);
  z-index: 4400;
  display: none;
  width: 46px;
  height: 112px;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(12, 60, 120, 0.28);
  border-radius: 8px;
  background: rgba(255, 193, 7, 0.58);
  color: #0c3c78;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.22);
  font-size: 2.2rem;
  font-weight: 800;
  line-height: 1;
  transform: translateY(-50%);
  opacity: 0.72;
  backdrop-filter: blur(3px);
}

.horizontal-scroll-button:hover,
.horizontal-scroll-button:focus {
  background: rgba(255, 205, 57, 0.82);
  color: #082a54;
  opacity: 0.96;
}

.horizontal-scroll-button.is-visible {
  display: flex;
}

.horizontal-scroll-button.is-left {
  left: var(--horizontal-scroll-button-left, 8px);
}

.horizontal-scroll-button.is-right {
  right: var(--horizontal-scroll-button-right, 8px);
}

.horizontal-scroll-button:disabled {
  opacity: 0.38;
  cursor: default;
  pointer-events: none;
}

.horizontal-scroll-hint {
  position: absolute;
  right: 12px;
  bottom: 10px;
  z-index: 19;
  display: none;
  padding: 0.28rem 0.55rem;
  border-radius: 8px;
  background: rgba(12, 60, 120, 0.86);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.18);
}

.horizontal-scroll-hint.is-visible {
  display: inline-flex;
}
.table th, .table td {
  white-space: nowrap;
  text-align: center;
  padding: 0.6rem 0.8rem;
}

/* === BOTONES === */
.btn {
  border-radius: 0.4rem;
  font-weight: 500;
}
.btn-outline-primary:hover {
  background-color: #0C3C78;
  color: white;
}
.btn-outline-success:hover {
  background-color: #43a047;
  color: white;
}
.btn-outline-danger:hover {
  background-color: #e53935;
  color: white;
}
.btn-outline-warning:hover {
  background-color: #f01fff;
  color: white;
}

/* === GRÁFICAS === */
canvas {
  max-height: 260px;
}
.card-body canvas {
  display: block;
  margin: 0 auto;
}

/* =========================================================
   📱 MOBILE (pantallas menores a 768px)
   ========================================================= */
@media (max-width: 768px) {

  /* Centrado general */
  body {
    padding: 0 !important;
  }

  main, .container, .card {
    margin-left: auto !important;
    margin-right: auto !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  /* Página de inicio o pantallas vacías */
  .main-content, .inicio, .welcome-section {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 85vh;
    text-align: center;
    padding: 1rem;
  }

  /* Cards y métricas */
  .card {
    margin-bottom: 1rem;
  }
  .card-body {
    padding: 1rem 0.8rem;
  }
  .card-title {
    font-size: 1rem;
    text-align: center;
  }

  /* Tablas */
  .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .table th, .table td {
    white-space: nowrap;
    font-size: 0.85rem;
  }

  /* Formularios del cotizador */
  #frm-cotizacion .form-control, 
  #frm-cotizacion .form-select {
    font-size: 0.9rem;
  }
  #frm-cotizacion label {
    font-weight: 600;
    font-size: 0.85rem;
  }
  #frm-cotizacion .card {
    margin-bottom: 1rem;
  }
  .btn, button {
    font-size: 0.9rem !important;
  }

  /* Campos alineados verticalmente */
  #frm-cotizacion .row > div {
    margin-bottom: 0.5rem;
  }

  /* Inputs con mejor tactilidad */
  input, select, textarea {
    border-radius: 0.4rem !important;
  }

  /* Ajuste gráfico y dashboard */
  .card-body canvas {
    max-height: 200px;
  }
  .row > [class*='col-'] {
    margin-bottom: 1rem;
  }
}

/* =========================================================
   💻 TABLETS (768–1024px)
   ========================================================= */
@media (min-width: 769px) and (max-width: 1024px) {
  .card-body canvas {
    max-height: 230px;
  }
  .table th, .table td {
    font-size: 0.9rem;
  }
}
/* === CORRECCIÓN DE BORDES EN TABLAS === */
.table {
  border-collapse: collapse !important;
  border: 1px solid #dee2e6 !important;
}

.table th, .table td {
  border: 1px solid #dee2e6 !important;
}

.table thead th {
  background-color: #f1f3f5;
  border-bottom: 2px solid #dee2e6 !important;
}

.table tbody tr:nth-child(even) {
  background-color: #fafafa;
}

.bg-light {
  background-color: #ffffff !important;
}

/* Campos de conceptos: permitir texto completo sin truncado visual */
.quote-items-table th,
.quote-items-table td {
  white-space: normal !important;
}

.quote-items-table .item-concept-col {
  min-width: 24rem;
}

.quote-items-table .item-desc-col {
  min-width: 16rem;
}

.quote-textarea {
  min-height: 5.5rem;
  resize: vertical;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.quote-row-actions {
  display: inline-flex;
  gap: 0.25rem;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

+/* Editor de cotizaciones: secciones estables y conceptos reordenables. */
.quote-edit-shell {
  max-width: 1480px;
}

.quote-edit-card {
  overflow: visible;
}

.quote-edit-section {
  margin-bottom: 1.25rem;
  padding: 1.25rem;
  border: 1px solid var(--bs-border-color, #d9e0e8);
  border-radius: 1rem;
  background: var(--bs-body-bg, #fff);
}

.quote-edit-section-header {
  display: flex;
  align-items: center;
  gap: .8rem;
  margin-bottom: 1.2rem;
}

.quote-edit-section-number {
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--bs-primary, #0d6efd);
  color: #fff;
  font-weight: 700;
}

.quote-edit-items {
  display: grid;
  gap: 1rem;
}

.quote-edit-item {
  overflow: hidden;
  border: 1px solid var(--bs-border-color, #d9e0e8);
  border-radius: .9rem;
  background: var(--bs-body-bg, #fff);
  box-shadow: 0 3px 12px rgba(15, 23, 42, .07);
  transition: border-color .18s ease, box-shadow .18s ease, opacity .18s ease;
}

.quote-edit-item:hover {
  border-color: rgba(var(--bs-primary-rgb, 13, 110, 253), .45);
  box-shadow: 0 7px 20px rgba(15, 23, 42, .1);
}

.quote-edit-item-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  min-height: 3.4rem;
  padding: .65rem .8rem;
  border-bottom: 1px solid var(--bs-border-color, #d9e0e8);
  background: var(--bs-tertiary-bg, #f5f7fa);
}

.quote-edit-item-header .min-w-0 {
  min-width: 0;
}

.quote-drag-handle {
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  width: 2.35rem;
  height: 2.35rem;
  padding: 0;
  border: 1px solid var(--bs-border-color, #cad3df);
  border-radius: .55rem;
  background: var(--bs-body-bg, #fff);
  color: var(--bs-secondary-color, #596577);
  cursor: grab;
  touch-action: none;
  user-select: none;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -.32rem;
  line-height: 1;
}

.quote-drag-handle:hover,
.quote-drag-handle:focus-visible {
  border-color: var(--bs-primary, #0d6efd);
  color: var(--bs-primary, #0d6efd);
  outline: 3px solid rgba(var(--bs-primary-rgb, 13, 110, 253), .15);
}

.quote-drag-handle:active,
.quote-edit-item.is-dragging .quote-drag-handle {
  cursor: grabbing;
}

.quote-edit-item.is-dragging {
  z-index: 20;
  opacity: .65;
  border-color: var(--bs-primary, #0d6efd);
  box-shadow: 0 14px 32px rgba(13, 110, 253, .22);
}

.quote-is-dragging {
  cursor: grabbing;
  user-select: none;
}

.quote-edit-item-body {
  padding: 1rem;
}

.quote-edit-actions {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: .35rem;
}

.item-concept-preview {
  display: inline-block;
  max-width: min(58vw, 52rem);
  color: var(--bs-body-color, #212529);
  font-size: .9rem;
  font-weight: 600;
}

.quote-edit-empty {
  padding: 1.25rem;
  border: 2px dashed var(--bs-border-color, #cad3df);
  border-radius: .8rem;
  color: var(--bs-secondary-color, #596577);
  text-align: center;
}

.quote-edit-reason {
  border-color: rgba(var(--bs-info-rgb, 13, 202, 240), .5);
  background: rgba(var(--bs-info-rgb, 13, 202, 240), .055);
}

.quote-edit-save-bar {
  position: sticky;
  z-index: 30;
  bottom: .75rem;
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .8rem 1rem;
  border: 1px solid var(--bs-border-color, #d9e0e8);
  border-radius: .85rem;
  background: color-mix(in srgb, var(--bs-body-bg, #fff) 94%, transparent);
  box-shadow: 0 8px 28px rgba(15, 23, 42, .16);
  backdrop-filter: blur(10px);
}

html[data-bs-theme="dark"] .quote-edit-section,
html[data-bs-theme="dark"] .quote-edit-item,
html[data-bs-theme="dark"] .quote-drag-handle,
html[data-bs-theme="dark"] .quote-edit-save-bar {
  background-color: #172033;
  border-color: #39465c;
}

html[data-bs-theme="dark"] .quote-edit-item-header {
  background-color: #1e293b;
  border-color: #39465c;
}

html[data-bs-theme="dark"] .quote-edit-reason {
  background-color: rgba(13, 202, 240, .08);
}

@media (max-width: 767.98px) {
  .quote-edit-section {
    padding: .9rem;
    border-radius: .8rem;
  }

  .quote-edit-item-header {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .quote-edit-item-header .min-w-0 {
    min-width: 0;
    width: calc(100% - 3.2rem);
  }

  .quote-edit-actions {
    width: 100%;
    padding-left: 3.1rem;
  }

  .item-concept-preview {
    max-width: calc(100vw - 9rem);
  }

  .quote-edit-save-bar {
    bottom: .35rem;
    flex-wrap: wrap;
  }

  .quote-edit-save-bar .small {
    width: 100%;
  }

  .quote-edit-save-bar .btn {
    flex: 1 1 0;
  }
}

.quote-concept-display {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  text-align: left;
}

/* Dashboard: las graficas principales necesitan usar todo el espacio del panel. */
.dashboard-charts-row {
  max-width: none !important;
  width: 100% !important;
}

.dashboard-monthly-chart {
  position: relative !important;
  width: 100% !important;
  height: calc(100% - 42px) !important;
  min-height: 0 !important;
}

.dashboard-status-chart {
  position: relative !important;
  width: 100% !important;
  height: calc(100% - 42px) !important;
  min-height: 0 !important;
}

.dashboard-charts-row #chartMensual,
.dashboard-charts-row #chartEstatus {
  display: block !important;
  width: 100% !important;
  height: 100% !important;
  max-height: none !important;
  margin: 0 !important;
}

/* Cotizador web: boton grande de voz */
.voice-launch-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.9rem;
  border: 0;
  border-radius: 1rem;
  padding: 0.9rem 1.25rem;
  background: linear-gradient(135deg, #0C3C78 0%, #155899 55%, #2f7fc6 100%);
  color: #fff;
  box-shadow: 0 14px 30px rgba(12, 60, 120, 0.22);
  transition: transform 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease;
}

.voice-launch-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 36px rgba(12, 60, 120, 0.28);
  filter: saturate(1.05);
}

.voice-launch-btn:active {
  transform: translateY(0);
}

.voice-launch-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3.1rem;
  height: 3.1rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  font-size: 1.65rem;
  line-height: 1;
}

.voice-launch-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.05;
}

.voice-launch-text strong {
  font-size: 1.08rem;
  letter-spacing: 0.01em;
}

.voice-launch-text small {
  margin-top: 0.18rem;
  font-size: 0.78rem;
  opacity: 0.9;
}

@media (max-width: 768px) {
  .voice-launch-btn {
    width: 100%;
    justify-content: center;
    padding: 0.95rem 1.1rem;
  }

  .voice-launch-text {
    align-items: flex-start;
  }
}
