/* =============================================================================
   Duwest Mobility — Custom Styles
   Version: 1.0.0
   ============================================================================= */

/* ---------- CSS Variables ---------- */
:root {
  --dw-primary: #1B5E20;
  --dw-secondary: #4CAF50;
  --dw-accent: #FF8F00;
  --dw-dark: #1a1a2e;
  --dw-light: #f8f9fa;
  --dw-text: #333333;
  --dw-sidebar-width: 260px;
  --dw-sidebar-bg: #1a1a2e;
  --dw-sidebar-hover: rgba(255, 255, 255, 0.08);
  --dw-sidebar-active: rgba(76, 175, 80, 0.15);
  --dw-transition: 0.25s ease;
}

/* ---------- Global ---------- */
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: var(--dw-text);
  background-color: var(--dw-light);
}

/* ---------- Custom Scrollbar ---------- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #b0bec5;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #90a4ae;
}

/* ---------- Login Page ---------- */
.login-bg {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--dw-primary) 0%, var(--dw-dark) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  width: 100%;
  max-width: 420px;
  border: none;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.login-logo {
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: 4px;
  color: var(--dw-primary);
}

.login-subtitle {
  font-size: 1.1rem;
  font-weight: 300;
  color: #6c757d;
  letter-spacing: 2px;
}

.login-card .btn-primary {
  background-color: var(--dw-primary);
  border-color: var(--dw-primary);
}

.login-card .btn-primary:hover {
  background-color: #2E7D32;
  border-color: #2E7D32;
}

.login-footer {
  color: rgba(255, 255, 255, 0.5);
  font-size: 0.8rem;
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--dw-sidebar-width);
  height: 100vh;
  background-color: var(--dw-sidebar-bg);
  z-index: 1040;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform var(--dw-transition);
}

.sidebar-brand {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand-text {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 3px;
  color: #ffffff;
}

.sidebar-brand-sub {
  font-size: 0.75rem;
  font-weight: 300;
  color: rgba(255, 255, 255, 0.5);
  letter-spacing: 2px;
  text-transform: uppercase;
}

.sidebar-nav {
  padding: 0.75rem 0;
}

.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 1.5rem;
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.9rem;
  font-weight: 400;
  border-left: 3px solid transparent;
  transition: all var(--dw-transition);
  text-decoration: none;
}

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

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

.sidebar-nav .nav-link.active {
  color: var(--dw-secondary);
  background-color: var(--dw-sidebar-active);
  border-left-color: var(--dw-secondary);
  font-weight: 500;
}

.sidebar-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.35);
  font-size: 0.75rem;
}

/* ---------- Main Content ---------- */
.main-content {
  margin-left: var(--dw-sidebar-width);
  min-height: 100vh;
  transition: margin-left var(--dw-transition);
}

/* ---------- Top Navbar ---------- */
.top-navbar {
  background-color: #ffffff;
  border-bottom: 1px solid #e9ecef;
  padding: 0.6rem 1.5rem;
}

.top-navbar .navbar-toggler {
  border: none;
  color: var(--dw-text);
  font-size: 1.3rem;
  padding: 0.25rem 0.5rem;
}

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

.notification-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  font-size: 0.6rem;
  padding: 0.2rem 0.4rem;
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background-color: var(--dw-primary);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 600;
}

/* ---------- KPI Cards ---------- */
.kpi-card {
  border: none;
  border-radius: 10px;
  transition: box-shadow var(--dw-transition), transform var(--dw-transition);
}

.kpi-card:hover {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
}

.kpi-card .kpi-icon {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}

.kpi-card .kpi-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--dw-text);
}

.kpi-card .kpi-label {
  font-size: 0.8rem;
  color: #6c757d;
  font-weight: 400;
}

/* ---------- Section Containers ---------- */
.content-section {
  display: none;
  padding: 1.5rem;
}

.content-section.active {
  display: block;
}

/* ---------- Data Tables ---------- */
.table > thead > tr > th {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #6c757d;
  border-bottom-width: 1px;
  white-space: nowrap;
}

/* Sortable columns */
.table th.sortable {
  cursor: pointer;
  user-select: none;
  transition: color var(--dw-transition);
}
.table th.sortable:hover {
  color: var(--dw-primary);
}
.table th.sortable .sort-icon {
  font-size: 0.7rem;
  margin-left: 4px;
  opacity: 0.35;
}
.table th.sortable.sort-asc .sort-icon,
.table th.sortable.sort-desc .sort-icon {
  opacity: 1;
  color: var(--dw-primary);
}
.table th.sortable.sort-asc .sort-icon::before {
  content: "\f148"; /* bi-arrow-up */
}
.table th.sortable.sort-desc .sort-icon::before {
  content: "\f128"; /* bi-arrow-down */
}

.table > tbody > tr {
  transition: background-color 0.15s ease;
}

.table > tbody > tr:hover {
  background-color: rgba(76, 175, 80, 0.04);
}

.table td {
  vertical-align: middle;
  font-size: 0.875rem;
}

/* ---------- Product Cards ---------- */
.product-card {
  border: 1px solid #e9ecef;
  border-radius: 10px;
  transition: box-shadow var(--dw-transition), transform var(--dw-transition);
  overflow: hidden;
}

.product-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  transform: translateY(-2px);
}

.product-img-placeholder {
  height: 160px;
  background-color: #e9ecef;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #adb5bd;
  font-size: 3rem;
}

/* ---------- Visit Card ---------- */
.visit-card {
  border-left: 4px solid var(--dw-secondary);
  border-radius: 0 8px 8px 0;
  transition: box-shadow var(--dw-transition);
}

.visit-card:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.visit-time {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--dw-primary);
  min-width: 60px;
}

/* ---------- FAB Button ---------- */
.fab-btn {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background-color: var(--dw-primary);
  color: #ffffff;
  border: none;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(27, 94, 32, 0.4);
  transition: all var(--dw-transition);
  z-index: 1030;
}

.fab-btn:hover {
  background-color: #2E7D32;
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(27, 94, 32, 0.5);
}

/* ---------- Calendar ---------- */
.cal-month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-top: 1px solid #e9ecef;
  border-left: 1px solid #e9ecef;
}
.cal-month-grid .cal-header {
  padding: 8px 4px;
  text-align: center;
  font-weight: 600;
  font-size: 0.75rem;
  color: #6c757d;
  background-color: #f8f9fa;
  border-right: 1px solid #e9ecef;
  border-bottom: 1px solid #e9ecef;
}
.cal-month-grid .cal-day {
  min-height: 90px;
  padding: 4px 6px;
  border-right: 1px solid #e9ecef;
  border-bottom: 1px solid #e9ecef;
  cursor: pointer;
  transition: background 0.15s;
}
.cal-month-grid .cal-day:hover {
  background-color: #f0faf0;
}
.cal-month-grid .cal-day.other-month {
  background-color: #fafafa;
  color: #ccc;
}
.cal-month-grid .cal-day.today {
  background-color: rgba(76, 175, 80, 0.08);
}
.cal-day-number {
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 2px;
}
.cal-day.today .cal-day-number {
  background: var(--dw-primary);
  color: #fff;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.cal-event {
  font-size: 0.68rem;
  padding: 1px 4px;
  border-radius: 3px;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.cal-week-grid {
  display: grid;
  grid-template-columns: 60px repeat(7, 1fr);
  border-top: 1px solid #e9ecef;
  border-left: 1px solid #e9ecef;
}
.cal-week-grid .cal-header {
  padding: 8px 4px;
  text-align: center;
  font-weight: 600;
  font-size: 0.75rem;
  color: #6c757d;
  background-color: #f8f9fa;
  border-right: 1px solid #e9ecef;
  border-bottom: 1px solid #e9ecef;
}
.cal-week-grid .cal-hour {
  padding: 4px 6px;
  font-size: 0.7rem;
  color: #999;
  text-align: right;
  border-right: 1px solid #e9ecef;
  border-bottom: 1px solid #e9ecef;
  min-height: 48px;
}
.cal-week-grid .cal-slot {
  border-right: 1px solid #e9ecef;
  border-bottom: 1px solid #e9ecef;
  min-height: 48px;
  padding: 2px;
  position: relative;
}
.cal-week-grid .cal-slot:hover {
  background-color: #f0faf0;
}
.cal-week-grid .cal-slot.today-col {
  background-color: rgba(76, 175, 80, 0.04);
}

.cal-day-grid {
  border-top: 1px solid #e9ecef;
  border-left: 1px solid #e9ecef;
}
.cal-day-grid .cal-day-row {
  display: grid;
  grid-template-columns: 60px 1fr;
  border-bottom: 1px solid #e9ecef;
}
.cal-day-grid .cal-hour {
  padding: 4px 6px;
  font-size: 0.7rem;
  color: #999;
  text-align: right;
  border-right: 1px solid #e9ecef;
  min-height: 48px;
}
.cal-day-grid .cal-slot {
  min-height: 48px;
  padding: 2px 6px;
  border-right: 1px solid #e9ecef;
}
.cal-day-grid .cal-slot:hover {
  background-color: #f0faf0;
}

/* ---------- Calendar drag & drop ---------- */
.cal-event[draggable="true"],
.cal-event-row[draggable="true"] {
  cursor: grab;
}
.cal-event-dragging {
  opacity: 0.45;
}
.cal-slot-dragover,
.cal-day.cal-slot-dragover {
  outline: 2px dashed #4CAF50;
  outline-offset: -2px;
  background-color: rgba(76, 175, 80, 0.08) !important;
}

/* ---------- Filter Bar ---------- */
.filter-bar {
  background-color: #ffffff;
  border-radius: 10px;
  border: 1px solid #e9ecef;
  padding: 1rem 1.25rem;
}

/* ---------- Tab Overrides ---------- */
.nav-tabs .nav-link {
  color: #6c757d;
  font-size: 0.875rem;
  font-weight: 500;
}

.nav-tabs .nav-link.active {
  color: var(--dw-primary);
  font-weight: 600;
}

/* ---------- Sidebar Backdrop (mobile) ---------- */
.sidebar-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 1035;
}

/* ---------- Responsive ---------- */
@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.show {
    transform: translateX(0);
  }

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

  .main-content {
    margin-left: 0;
  }

  /* Tight header on tablet */
  .top-navbar {
    padding: 0.5rem 1rem;
  }
}

/* Tablet & small laptop ≤ 767.98px */
@media (max-width: 767.98px) {
  .content-section {
    padding: 1rem 0.75rem;
  }

  .content-section h4 {
    font-size: 1.15rem;
  }

  /* KPI cards: shrink text */
  .kpi-card .kpi-value {
    font-size: 1.1rem;
  }
  .kpi-card .kpi-label {
    font-size: 0.7rem;
  }
  .kpi-card .card-body {
    padding: 0.6rem 0.5rem !important;
  }

  /* Tables: readable on small screens, allow horizontal scroll */
  .table-responsive {
    font-size: 0.8rem;
  }
  .table td, .table th {
    padding: 0.5rem 0.5rem;
    white-space: nowrap;
  }
  .table > thead > tr > th {
    font-size: 0.7rem;
  }

  /* Filter bar: compact padding */
  .filter-bar {
    padding: 0.75rem 0.75rem;
  }

  /* Action cards (modal): smaller + 2 cols */
  .action-card {
    height: 92px;
    padding: 0.75rem 0.4rem;
  }
  .action-card .fs-3 {
    font-size: 1.3rem !important;
  }
  .action-card .small {
    font-size: 0.7rem;
  }
  .action-card .action-card-sub {
    font-size: 0.6rem;
    bottom: 4px;
  }

  /* Client avatar shrink in modal */
  .client-avatar-lg {
    width: 48px;
    height: 48px;
    min-width: 48px;
  }
  .client-avatar-lg .fs-4 {
    font-size: 1rem !important;
  }

  /* Top navbar: hide user email on small phones */
  .top-navbar .dropdown-toggle .fw-medium,
  .top-navbar .dropdown .text-muted {
    display: none !important;
  }
  .top-navbar #pageTitle {
    font-size: 0.95rem;
  }

  /* Notification badge slimmer */
  .notification-badge {
    font-size: 0.55rem;
  }

  /* FAB smaller and closer to edge */
  .fab-btn {
    width: 48px;
    height: 48px;
    font-size: 1.2rem;
    bottom: 1rem;
    right: 1rem;
  }

  /* Modals: use full viewport width */
  .modal-dialog:not(.modal-sm) {
    margin: 0.5rem;
  }
  .modal-body {
    padding: 1rem !important;
  }
  .modal-header {
    padding: 0.75rem 1rem;
  }
  .modal-header .modal-title {
    font-size: 0.95rem;
  }

  /* Pagination smaller */
  .pagination-sm .page-link {
    padding: 0.2rem 0.45rem;
    font-size: 0.75rem;
  }

  /* Calendar: more compact */
  .cal-month-grid .cal-day {
    min-height: 70px !important;
    padding: 4px !important;
    font-size: 0.75rem !important;
  }
}

/* Medium breakpoint: hide secondary balance columns */
@media (max-width: 991.98px) {
  .hide-md {
    display: none !important;
  }
}

/* Phone ≤ 575.98px */
@media (max-width: 575.98px) {
  .content-section {
    padding: 0.75rem 0.5rem;
  }

  /* Sidebar: full width when open */
  .sidebar {
    width: 85vw;
    max-width: 300px;
  }
  :root {
    --dw-sidebar-width: 260px;
  }

  /* Top navbar title */
  .top-navbar #pageTitle {
    display: none;
  }
  .top-navbar {
    padding: 0.4rem 0.75rem;
  }

  /* KPI cards in 2-col at most */
  .kpi-card .card-body {
    padding: 0.5rem !important;
  }
  .kpi-card .kpi-value {
    font-size: 1rem;
  }

  /* Hide some table columns (marked with .hide-sm) to avoid squish */
  .hide-sm {
    display: none !important;
  }

  /* Modal action buttons: keep consistent height */
  .action-card {
    height: 84px;
  }

  /* Login card: edge-to-edge friendly */
  .login-card {
    border-radius: 8px;
    margin: 0 0.5rem;
  }
  .login-logo {
    font-size: 2rem;
  }

  /* Buttons stack full width */
  .btn-full-sm {
    width: 100%;
  }
}

/* Touch-friendly tap targets everywhere */
@media (hover: none) and (pointer: coarse) {
  .nav-link, .action-card, .page-link {
    min-height: 44px;
  }
}

/* ---------- Utility ---------- */
.text-dw-primary {
  color: var(--dw-primary);
}

.text-dw-accent {
  color: var(--dw-accent);
}

.bg-dw-primary {
  background-color: var(--dw-primary);
}

.bg-dw-accent {
  background-color: var(--dw-accent);
}

/* ---------- Client Cards (Cartera) ---------- */
.client-card {
  border-radius: 12px;
  border: 1px solid #e9ecef;
  transition: box-shadow var(--dw-transition), transform var(--dw-transition);
  cursor: pointer;
}

.client-card:hover {
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
  transform: translateY(-3px);
}

.client-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.client-avatar-lg {
  width: 64px;
  height: 64px;
  min-width: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Action Cards (Client Modal) ---------- */
.action-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.25rem 0.75rem;
  border-radius: 12px;
  border: 2px solid;
  cursor: pointer;
  transition: all var(--dw-transition);
  text-align: center;
  height: 110px;
}

/* Sub-label (e.g. "(sin deuda)") floats at bottom without changing card size */
.action-card .action-card-sub {
  position: absolute;
  bottom: 6px;
  left: 0;
  right: 0;
  font-size: 0.65rem;
  line-height: 1;
  color: #6c757d;
}

/* Client Actions modal — compact width */
.modal-client-actions {
  max-width: 420px;
}
.modal-client-actions .client-avatar-lg {
  width: 48px;
  height: 48px;
  min-width: 48px;
}
.modal-client-actions .client-avatar-lg .fs-4 {
  font-size: 1rem !important;
}
.modal-client-actions h5 {
  font-size: 1rem;
}
.modal-client-actions .action-card {
  height: 92px;
  padding: 0.75rem 0.4rem;
}
.modal-client-actions .action-card .fs-3 {
  font-size: 1.3rem !important;
}
.modal-client-actions .action-card .small {
  font-size: 0.7rem;
}
/* Client Actions modal — compact action grid */
#clientActionsModal .row.g-2 {
  --bs-gutter-x: 0.3rem;
  --bs-gutter-y: 0.3rem;
}
#clientActionsModal .action-card {
  height: 69px;
  padding: 0.35rem 0.2rem;
  border-radius: 6px;
  border-width: 1px;
}
#clientActionsModal .action-card .fs-3 {
  font-size: 0.95rem !important;
  margin-bottom: 0 !important;
}
#clientActionsModal .action-card .fw-semibold.small {
  font-size: 0.6rem;
  line-height: 1.1;
}
#clientActionsModal .action-card .action-card-sub {
  font-size: 0.5rem;
  bottom: 2px;
}

.action-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.action-card.disabled,
.action-card[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed !important;
  pointer-events: none;
  background-color: #f8f9fa;
}
.action-card.disabled:hover,
.action-card[aria-disabled="true"]:hover {
  transform: none;
  box-shadow: none;
}

.action-card-blue {
  border-color: #1976D2;
  color: #1976D2;
}
.action-card-blue:hover {
  background-color: #E3F2FD;
}

.action-card-green {
  border-color: #2E7D32;
  color: #2E7D32;
}
.action-card-green:hover {
  background-color: #E8F5E9;
}

.action-card-amber {
  border-color: #FF8F00;
  color: #FF8F00;
}
.action-card-amber:hover {
  background-color: #FFF8E1;
}

.action-card-whatsapp {
  border-color: #25D366;
  color: #25D366;
}
.action-card-whatsapp:hover {
  background-color: #E8F8ED;
}

.action-card-teal {
  border-color: #00897B;
  color: #00897B;
}
.action-card-teal:hover {
  background-color: #E0F2F1;
}

.action-card-yellow {
  border-color: #F9A825;
  color: #F9A825;
}
.action-card-yellow:hover {
  background-color: #FFFDE7;
}

.action-card-red {
  border-color: #e53935;
  color: #e53935;
}
.action-card-red:hover {
  background-color: #FFEBEE;
}

/* ---------- Print ---------- */
@media print {
  .sidebar,
  .top-navbar,
  .fab-btn {
    display: none;
  }

  .main-content {
    margin-left: 0;
  }
}
