/**
 * ============================================
 * medDevice Design System - Components
 * Cards, Buttons, Badges, Pills, Tables, Modals
 * ============================================
 */

/* ============================================
   CARDS
   ============================================ */

.card,
.md-card {
  background: var(--md-white, #ffffff);
  border: 1px solid var(--md-border, #e4e9f0);
  border-radius: var(--md-radius-md, 8px);
  margin-bottom: 20px;
  box-shadow: var(--md-shadow-sm, 0 1px 3px rgba(0, 0, 0, 0.06));
}

.card-header {
  background: var(--md-gray-50, #f8fafb);
  border-bottom: 1px solid var(--md-border, #e4e9f0);
  padding: 15px 20px;
  font-weight: 600;
  color: var(--md-text, #2c3e50);
  border-radius: var(--md-radius-md, 8px) var(--md-radius-md, 8px) 0 0;
}

.card-body {
  padding: 20px;
}

.card-footer {
  background: var(--md-gray-50, #f8fafb);
  border-top: 1px solid var(--md-border, #e4e9f0);
  padding: 15px 20px;
}

/* Stat Cards */
.md-stat-card {
  border: 1px solid var(--md-border, #e5e7eb);
  border-radius: 12px;
  background: var(--md-white, #ffffff);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.md-stat-card__body {
  padding: 14px 16px;
}

.md-stat-card__icon {
  font-size: 22px;
  opacity: 0.9;
}

.md-stat-card__label {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--md-text-light, #6b7c93);
}

.md-stat-card__value {
  margin: 4px 0 0 0;
  font-size: 22px;
  font-weight: 800;
  color: var(--md-text, #1a1f2e);
}

.md-stat-card--center .md-stat-card__icon {
  font-size: 26px;
  opacity: 0.35;
  margin-top: 8px;
}

.md-stat-card__footer {
  padding: 10px 16px;
  border-top: 1px solid var(--md-border, #e5e7eb);
  background: transparent;
}

.md-stat-card__footer a {
  color: var(--md-blue, #0f78a5);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
}

.md-stat-card__footer a:hover {
  color: var(--md-blue-hover, #0b5e82);
  text-decoration: underline;
}

/* System Cards */
.system-card {
  transition: box-shadow 0.2s ease;
}

.system-card:hover {
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
}

.system-card .card-title {
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
  color: var(--md-text, #2c3e50);
}

.system-card .card-title i {
  margin-right: 0.5rem;
}

/* Contract Cards */
.contract-card {
  border-left: 4px solid var(--md-blue, #0f78a5);
  transition: all 0.2s ease;
}

.contract-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.contract-card .badge {
  font-size: 0.8rem;
  padding: 0.35rem 0.65rem;
}

/* ============================================
   BUTTONS
   ============================================ */

.btn {
  font-weight: 500;
  transition: all 0.2s ease;
}

.btn-primary {
  background-color: var(--btn-primary, var(--md-blue, #0f78a5));
  border-color: var(--btn-primary, var(--md-blue, #0f78a5));
  color: #ffffff;
}

.btn-primary:hover {
  background-color: var(--md-blue-hover, #1487b8);
  border-color: var(--md-blue-hover, #1487b8);
  box-shadow: 0 2px 8px rgba(15, 120, 165, 0.25);
}

.btn-secondary {
  background-color: var(--md-gray-500, #6b7c93);
  border-color: var(--md-gray-500, #6b7c93);
  color: #ffffff;
}

.btn-secondary:hover {
  background-color: var(--md-gray-600, #556275);
  border-color: var(--md-gray-600, #556275);
}

.btn-outline-primary {
  background-color: transparent;
  border: 1px solid var(--btn-primary, var(--md-blue, #0f78a5));
  color: var(--btn-primary, var(--md-blue, #0f78a5));
}

.btn-outline-primary:hover {
  background-color: var(--btn-primary, var(--md-blue, #0f78a5));
  color: #ffffff;
}

.btn-outline-secondary {
  background-color: transparent;
  border: 1px solid var(--md-gray-400, #cbd5e1);
  color: var(--md-text, #2c3e50);
}

.btn-outline-secondary:hover {
  background-color: var(--md-gray-100, #f1f4f8);
  border-color: var(--md-gray-500, #94a3b8);
}

/* Button Sizes */
.btn-sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.875rem;
}

.btn-lg {
  padding: 0.5rem 1rem;
  font-size: 1.125rem;
}

/* Button Variants */
.btn-round {
  border-radius: 10px !important;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-icon.btn-icon-mini,
.btn-icon-mini {
  padding: 0.25rem 0.45rem !important;
  line-height: 1 !important;
}

.btn-neutral {
  box-shadow: none !important;
}

/* Action Buttons */
.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--md-border, #e4e9f0);
  border-radius: var(--md-radius-sm, 4px);
  background: var(--md-white, #ffffff);
  color: var(--md-text-muted, #6b7c93);
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s ease;
}

.action-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  text-decoration: none;
  border-color: var(--md-blue, #0f78a5);
  color: var(--md-blue, #0f78a5);
  background: var(--md-gray-50, #f8f9fc);
}

.action-btn:active {
  transform: translateY(0);
}

.action-btn-delete:hover {
  border-color: var(--md-danger, #e74c3c);
  color: var(--md-danger, #e74c3c);
  background: rgba(231, 76, 60, 0.06);
}

.action-btn i.fa-eye {
  color: var(--md-blue, #0f78a5);
}
.action-btn i.fa-edit {
  color: var(--md-warning, #f39c12);
}
.action-btn i.fa-trash {
  color: var(--md-danger, #e74c3c);
}
.action-btn:hover i {
  color: inherit;
}

.actions-buttons {
  gap: 0.375rem !important;
}

/* Focus States */
a:focus-visible,
button:focus-visible,
.btn:focus-visible {
  outline: 2px solid var(--md-blue, #0f78a5);
  outline-offset: 2px;
}

/* ============================================
   AVATARS
   ============================================ */

/* Avatar sizes - responsive and consistent */
.avatar-xs {
  width: 24px;
  height: 24px;
  object-fit: cover;
}

.avatar-sm {
  width: 28px;
  height: 28px;
  object-fit: cover;
}

.avatar-md {
  width: 32px;
  height: 32px;
  object-fit: cover;
}

.avatar-base {
  width: 40px;
  height: 40px;
  object-fit: cover;
}

.avatar-lg {
  width: 48px;
  height: 48px;
  object-fit: cover;
}

.avatar-xl {
  width: 64px;
  height: 64px;
  object-fit: cover;
}

.avatar-2xl {
  width: 80px;
  height: 80px;
  object-fit: cover;
}

.avatar-3xl {
  width: 120px;
  height: 120px;
  object-fit: cover;
}

/* Avatar shapes */
.avatar-circle {
  border-radius: 50%;
}

.avatar-rounded {
  border-radius: 6px;
}

.avatar-rounded-sm {
  border-radius: 4px;
}

/* Avatar border */
.avatar-border {
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: var(--md-white, #ffffff);
}

/* Combined utility class for common pattern */
.avatar {
  object-fit: cover;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: var(--md-white, #ffffff);
}

/* Logo utility */
.logo-sm {
  height: 28px;
  width: auto;
  object-fit: contain;
}

.logo-md {
  height: 36px;
  width: auto;
  object-fit: contain;
}

.logo-lg {
  height: 48px;
  width: auto;
  object-fit: contain;
}

/* ============================================
   BADGES & PILLS
   ============================================ */

.badge {
  font-weight: 500;
  letter-spacing: 0.3px;
}

.badge-lg {
  font-size: 0.9rem;
  padding: 0.5rem 0.75rem;
}

.room-badge {
  font-size: 0.85rem;
  padding: 0.35rem 0.65rem;
}

.room-badge i {
  margin-right: 0.25rem;
}

/* MD Pills */
.md-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: var(--md-gray-100, #f1f4f8);
  border: 1px solid var(--md-gray-200, #e4e9f0);
  color: var(--md-text, #2c3e50);
  white-space: nowrap;
}

.md-pill--primary {
  background: rgba(15, 120, 165, 0.1);
  border-color: rgba(15, 120, 165, 0.22);
  color: var(--md-blue, #0f78a5);
}

.md-pill--info {
  background: rgba(45, 127, 249, 0.1);
  border-color: rgba(45, 127, 249, 0.22);
  color: var(--md-primary, #2d7ff9);
}

.md-pill--success {
  background: rgba(39, 174, 96, 0.1);
  border-color: rgba(39, 174, 96, 0.22);
  color: var(--md-success, #27ae60);
}

.md-pill--warning {
  background: rgba(243, 156, 18, 0.1);
  border-color: rgba(243, 156, 18, 0.24);
  color: var(--md-warning, #f39c12);
}

.md-pill--danger {
  background: rgba(231, 76, 60, 0.08);
  border-color: rgba(231, 76, 60, 0.22);
  color: var(--md-danger, #e74c3c);
}

.md-pill--secondary {
  background: rgba(108, 117, 125, 0.1);
  border-color: rgba(108, 117, 125, 0.22);
  color: var(--md-text-light, #6b7c93);
}

/* ============================================
   TABLES
   ============================================ */

.table {
  color: var(--md-text, #2c3e50);
  background: var(--md-white, #ffffff);
}

.table thead th {
  background-color: var(--md-gray-50, #f8fafb);
  border-color: var(--md-border, #e4e9f0);
  color: var(--md-text, #2c3e50);
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.table tbody tr:hover {
  background-color: rgba(15, 120, 165, 0.04);
}

.table tbody td a {
  color: var(--md-blue, #0f78a5);
}

.table tbody td a:hover {
  color: var(--md-blue-hover, #1487b8);
  text-decoration: underline;
}

/* MD Table Container */
.md-table-container {
  background: var(--md-white, #ffffff);
  border-radius: 8px;
  overflow: hidden;
}

/* Sticky tables: overflow visible so position:sticky thead works (no clipping ancestor) */
.md-table-container:has(table.table-sticky-header),
.md-table-container:has(table.md-table-sticky) {
  overflow: visible !important;
}

/* Sticky Table Headers */
.table-sticky-wrapper {
  position: relative;
  overflow-x: auto;
  max-height: calc(100vh - 200px);
}

.table-sticky-header thead tr:first-child th {
  position: sticky;
  top: var(--md-fixed-header-height, 110px);
  background: var(--md-gray-50, #f8fafb);
  border-bottom: 2px solid var(--md-border, #e4e9f0);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  z-index: 101;
}

.table-sticky-header thead tr.filters th {
  position: sticky;
  top: calc(var(--md-fixed-header-height, 110px) + var(--md-sticky-table-header-row-height, 48px));
  background: var(--md-white, #ffffff);
  border-bottom: 2px solid var(--md-border, #e4e9f0);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  z-index: 100;
  padding: 8px;
}

.table-sticky-header thead tr.filters th input,
.table-sticky-header thead tr.filters th select {
  background: var(--md-white, #ffffff);
  border: 1px solid var(--md-border, #e4e9f0);
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 12px;
  width: 100%;
}

.table-sticky-header thead tr.filters th input:focus,
.table-sticky-header thead tr.filters th select:focus {
  outline: none;
  border-color: var(--md-blue, #0f78a5);
  box-shadow: 0 0 0 3px rgba(15, 120, 165, 0.1);
}

/* DataTables Scroller Override - disable sticky when scrollY/Scroller is active */
.dataTables_scrollHead table.table-sticky-header thead th,
.dataTables_scrollBody table.table-sticky-header thead th,
.dataTables_scrollHead table.table-sticky-header thead tr:first-child th,
.dataTables_scrollBody table.table-sticky-header thead tr:first-child th,
.dataTables_scrollHead table.table-sticky-header thead tr:nth-child(2) th,
.dataTables_scrollBody table.table-sticky-header thead tr:nth-child(2) th,
.dataTables_scrollHead table.table-sticky-header thead tr.filters th,
.dataTables_scrollBody table.table-sticky-header thead tr.filters th,
.dataTables_scrollHead table.md-table-sticky thead th,
.dataTables_scrollBody table.md-table-sticky thead th,
.dataTables_scrollHead table.md-table-sticky thead tr.md-table-filter th,
.dataTables_scrollBody table.md-table-sticky thead tr.md-table-filter th {
  position: static !important;
  top: auto !important;
  box-shadow: none !important;
}

/* MD Table Sticky */
.md-table-sticky thead th {
  position: sticky;
  top: var(--md-fixed-header-height, 110px);
  z-index: 6;
  background: var(--md-white, #ffffff);
  border-bottom: 1px solid var(--md-border, #e4e9f0);
}

.md-table-sticky thead tr.md-table-filter th {
  top: calc(var(--md-fixed-header-height, 110px) + var(--md-table-sticky-header-offset, 38px));
  z-index: 5;
  background: var(--md-gray-50, #f8fafb);
  border-bottom: 1px solid var(--md-border, #e4e9f0);
}

.md-table-filter .form-control {
  height: 30px;
  padding: 4px 8px;
  font-size: 12px;
  border-radius: 8px;
}

/* Mobile Card Layout for Tables */
@media (max-width: 768px) {
  .table-mobile-card {
    border: none;
  }

  .table-mobile-card tbody tr {
    display: block;
    margin-bottom: 1rem;
    border: 1px solid var(--md-border, #e4e9f0);
    border-radius: 8px;
    padding: 1rem;
    background: var(--md-white, #ffffff);
    box-shadow: var(--md-shadow-sm, 0 1px 3px rgba(0, 0, 0, 0.06));
  }

  .table-mobile-card tbody tr:hover {
    box-shadow: var(--md-shadow-md, 0 2px 8px rgba(0, 0, 0, 0.08));
  }

  .table-mobile-card tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border: none;
    border-bottom: 1px solid var(--md-border-light, #eaecef);
  }

  /* Respect Bootstrap d-none on mobile - hide columns marked as desktop-only */
  .table-mobile-card tbody td.d-none,
  .table-mobile-card tbody td.d-md-table-cell,
  .table-mobile-card tbody td.d-lg-table-cell {
    display: none !important;
  }

  .table-mobile-card tbody td:last-child {
    border-bottom: none;
    padding-top: 0.75rem;
    justify-content: flex-end;
  }

  .table-mobile-card tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--md-text-light, #6b7c93);
    font-size: var(--font-size-sm, 13px);
    flex-shrink: 0;
    margin-right: 1rem;
  }

  /* Prevent child elements from growing to fill the cell */
  .table-mobile-card tbody td > * {
    flex: 0 0 auto;
    max-width: 60%;
    text-align: right;
  }

  .table-mobile-card tbody td:last-child::before {
    content: none;
  }

  .table-mobile-card thead {
    display: none;
  }

  /* Hide colon for empty data-label */
  .table-mobile-card tbody td[data-label=""]::before {
    content: "";
    min-width: 0;
    margin-right: 0;
  }

  /* Hide filter rows in mobile card view */
  .table-mobile-card thead tr.filters,
  .table-mobile-card thead tr.md-table-filter {
    display: none !important;
  }

  /* Empty state in table (colspan cells) */
  .table-mobile-card tbody td[colspan] {
    display: block;
    text-align: center;
  }

  .table-mobile-card tbody td[colspan]::before {
    display: none;
  }

  /* Actions column - full width buttons */
  .table-mobile-card tbody td.td-actions,
  .table-mobile-card tbody td[data-label='Aktion'],
  .table-mobile-card tbody td[data-label='Aktionen'] {
    justify-content: center;
    gap: 0.5rem;
  }

  .table-mobile-card tbody td.td-actions .btn,
  .table-mobile-card tbody td[data-label='Aktion'] .btn,
  .table-mobile-card tbody td[data-label='Aktionen'] .btn {
    flex: 1;
    min-height: var(--md-touch-target-min, 44px);
  }
}

/* Auto-apply mobile card to tables with .table-responsive parent on mobile */
@media (max-width: 576px) {
  .table-responsive > .table:not(.no-mobile-card) tbody tr {
    display: block;
    margin-bottom: 0.75rem;
    border: 1px solid var(--md-border, #e4e9f0);
    border-radius: 8px;
    padding: 0.75rem;
    background: var(--md-white, #ffffff);
  }

  .table-responsive > .table:not(.no-mobile-card) thead {
    display: none;
  }

  .table-responsive > .table:not(.no-mobile-card) tbody td {
    display: block;
    padding: 0.25rem 0;
    border: none;
    text-align: left !important;
  }

  .table-responsive > .table:not(.no-mobile-card) tbody td:empty {
    display: none;
  }
}

/* ============================================
   TABLE SWIPE / TOUCH SCROLLING
   ============================================ */

/* Touch-friendly horizontal scrolling */
.table-responsive,
.table-sticky-wrapper {
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* Swipe indicator - gradient fade on right edge when scrollable */
@media (max-width: 768px) {
  .md-table-container {
    position: relative;
  }

  .md-table-container::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 30px;
    background: linear-gradient(to right, transparent, rgba(255, 255, 255, 0.9));
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 10;
  }

  .md-table-container.has-horizontal-scroll::after {
    opacity: 1;
  }

  .md-table-container.scrolled-to-end::after {
    opacity: 0;
  }

  /* Swipe hint animation */
  .md-swipe-hint {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(15, 120, 165, 0.1);
    border-radius: 20px;
    font-size: 12px;
    color: var(--md-blue, #0f78a5);
    margin-bottom: 8px;
    animation: swipeHintPulse 2s ease-in-out infinite;
  }

  .md-swipe-hint i {
    animation: swipeArrow 1.5s ease-in-out infinite;
  }

  @keyframes swipeHintPulse {
    0%,
    100% {
      opacity: 0.7;
    }
    50% {
      opacity: 1;
    }
  }

  @keyframes swipeArrow {
    0%,
    100% {
      transform: translateX(0);
    }
    50% {
      transform: translateX(5px);
    }
  }

  /* Show hint only when table is scrollable and not yet scrolled */
  .md-table-container.has-horizontal-scroll:not(.has-scrolled) .md-swipe-hint {
    display: inline-flex;
  }
}

/* ============================================
   MODALS - Clean Medical Design System
   ============================================ */

.modal-content {
  border-radius: 12px;
  border: none;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.15);
  background-color: var(--md-white, #ffffff);
  overflow: hidden;
}

.modal-header {
  background: linear-gradient(
    135deg,
    var(--md-primary, #3498db) 0%,
    var(--md-primary-dark, #2980b9) 100%
  );
  border-bottom: none;
  border-radius: 0;
  padding: 1rem 1.5rem;
  min-height: 56px;
}

.modal-header .modal-title {
  font-weight: 600;
  color: #ffffff;
  margin-bottom: 0;
  line-height: 1.4;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.modal-header .modal-title i,
.modal-header .modal-title .fa {
  opacity: 0.9;
}

.modal-header .btn-close {
  filter: brightness(0) invert(1);
  opacity: 0.8;
  transition: opacity 0.2s ease;
}

.modal-header .btn-close:hover {
  opacity: 1;
}

.modal-body {
  padding: 1.5rem;
  background: var(--md-white, #ffffff);
}

.modal-footer {
  background: var(--md-gray-50, #f8fafb);
  border-top: 1px solid var(--md-border, #e4e9f0);
  border-radius: 0;
  padding: 1rem 1.5rem;
  gap: 0.5rem;
}

.modal-backdrop.show {
  opacity: 0.4;
  backdrop-filter: blur(2px);
}

/* Modal Sizes */
.modal-lg {
  max-width: 800px;
}
.modal-xl {
  max-width: 1140px;
}

/* ----------------------------------------
   Modal Header Semantic Variants
   ---------------------------------------- */

/* Default / Edit - Primary Blue */
.modal-header--edit,
.modal-header--default {
  background: linear-gradient(
    135deg,
    var(--md-primary, #3498db) 0%,
    var(--md-primary-dark, #2980b9) 100%
  );
}

/* Create - Fresh Green */
.modal-header--create,
.modal-header--success {
  background: linear-gradient(135deg, var(--md-success, #27ae60) 0%, #1e8449 100%);
}

/* Delete / Danger - Soft Red */
.modal-header--delete,
.modal-header--danger {
  background: linear-gradient(135deg, var(--md-danger, #e74c3c) 0%, #c0392b 100%);
}

/* Warning - Amber */
.modal-header--warning {
  background: linear-gradient(135deg, var(--md-warning, #f39c12) 0%, #d68910 100%);
}

/* Info - Cyan */
.modal-header--info {
  background: linear-gradient(135deg, var(--md-info, #17a2b8) 0%, #138496 100%);
}

/* Neutral / View - Gray */
.modal-header--neutral,
.modal-header--view {
  background: linear-gradient(135deg, var(--md-gray-500, #6b7c93) 0%, var(--md-gray-600, #556275) 100%);
}

/* ----------------------------------------
   Modal Loading State
   ---------------------------------------- */

.modal.is-loading .modal-body {
  opacity: 0.5;
  pointer-events: none;
}

.modal-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: var(--md-text-muted, #6b7c93);
}

.modal-loading i {
  font-size: 2rem;
  margin-bottom: 1rem;
  color: var(--md-primary, #3498db);
}

/* ----------------------------------------
   Modal Form Styling
   ---------------------------------------- */

.modal-body .form-label {
  font-weight: 500;
  color: var(--md-text, #2c3e50);
  margin-bottom: 0.375rem;
  font-size: 0.875rem;
}

.modal-body .form-control,
.modal-body .form-select {
  border-radius: 6px;
  border-color: var(--md-border, #e4e9f0);
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

.modal-body .form-control:focus,
.modal-body .form-select:focus {
  border-color: var(--md-primary, #3498db);
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.15);
}

/* Modal Sections */
.modal-section {
  padding: 1rem 0;
  border-bottom: 1px solid var(--md-border, #e4e9f0);
}

.modal-section:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.modal-section-title {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--md-text-muted, #6b7c93);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.modal-section-title i {
  opacity: 0.7;
}

/* ----------------------------------------
   Modal Product/Entity Image Preview
   - Always at top of modal body
   - Consistent styling across all modals
   ---------------------------------------- */

.md-modal-image {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  margin: -1.5rem -1.5rem 1.5rem -1.5rem;
  background: var(--md-gray-50, #f8fafb);
  border-bottom: 1px solid var(--md-border, #e4e9f0);
}

.md-modal-image__thumb {
  flex-shrink: 0;
  width: 72px;
  height: 72px;
  border-radius: 8px;
  background: var(--md-white, #ffffff);
  border: 1px solid var(--md-border, #e4e9f0);
  object-fit: contain;
  padding: 4px;
}

.md-modal-image__placeholder {
  flex-shrink: 0;
  width: 72px;
  height: 72px;
  border-radius: 8px;
  background: var(--md-white, #ffffff);
  border: 1px solid var(--md-border, #e4e9f0);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--md-text-muted, #6b7c93);
}

.md-modal-image__placeholder i {
  font-size: 1.5rem;
  opacity: 0.5;
}

.md-modal-image__info {
  flex-grow: 1;
  min-width: 0;
}

.md-modal-image__title {
  font-weight: 600;
  color: var(--md-text, #2c3e50);
  margin: 0;
  font-size: 1rem;
  line-height: 1.3;
}

.md-modal-image__subtitle {
  font-size: 0.875rem;
  color: var(--md-text-muted, #6b7c93);
  margin: 0.25rem 0 0 0;
}

.md-modal-image__meta {
  font-size: 0.8125rem;
  color: var(--md-text-light, #95a5a6);
  margin: 0.375rem 0 0 0;
}

/* Hidden state for dynamic image preview */
.md-modal-image[hidden],
.md-modal-image.d-none {
  display: none !important;
}

/* Upload zone in modal */
.md-modal-upload {
  margin: -1.5rem -1.5rem 1.5rem -1.5rem;
  padding: 1.5rem;
  background: var(--md-gray-50, #f8fafb);
  border-bottom: 1px solid var(--md-border, #e4e9f0);
  text-align: center;
}

.md-modal-upload__dropzone {
  border: 2px dashed var(--md-border, #e4e9f0);
  border-radius: 8px;
  padding: 1.5rem;
  background: var(--md-white, #ffffff);
  cursor: pointer;
  transition:
    border-color 0.2s ease,
    background-color 0.2s ease;
}

.md-modal-upload__dropzone:hover,
.md-modal-upload__dropzone.dragover {
  border-color: var(--md-primary, #3498db);
  background: rgba(52, 152, 219, 0.05);
}

.md-modal-upload__dropzone i {
  font-size: 2rem;
  color: var(--md-text-muted, #6b7c93);
  margin-bottom: 0.5rem;
}

.md-modal-upload__text {
  font-size: 0.875rem;
  color: var(--md-text-muted, #6b7c93);
  margin: 0;
}

.md-modal-upload__preview {
  position: relative;
  display: inline-block;
}

.md-modal-upload__preview img {
  max-width: 150px;
  max-height: 150px;
  border-radius: 8px;
  border: 1px solid var(--md-border, #e4e9f0);
}

.md-modal-upload__remove {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--md-danger, #e74c3c);
  color: white;
  border: 2px solid white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.75rem;
}

/* Responsive modal image */
@media (max-width: 576px) {
  .md-modal-image {
    flex-direction: column;
    text-align: center;
    gap: 0.75rem;
  }

  .md-modal-image__thumb,
  .md-modal-image__placeholder {
    width: 64px;
    height: 64px;
  }
}

/* ----------------------------------------
   Mobile Fullscreen Modal
   Forces proper scrolling behavior on all modals on mobile
   ---------------------------------------- */

@media (max-width: 767.98px) {
  /* ALL modals on mobile: ensure scrollable body */
  .modal .modal-dialog {
    margin: 0 !important;
    max-width: 100% !important;
    height: 100% !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
  }

  .modal .modal-content {
    border-radius: 0 !important;
    height: 100% !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
  }

  .modal .modal-header {
    padding: 0.875rem 1rem !important;
    min-height: 52px;
    flex-shrink: 0 !important;
    border-radius: 0 !important;
  }

  .modal .modal-body {
    padding: 1rem !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    flex: 1 1 auto !important;
    min-height: 0 !important; /* Critical for flex scrolling */
  }

  .modal .modal-footer {
    padding: 0.875rem 1rem !important;
    flex-shrink: 0 !important;
    border-radius: 0 !important;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.08);
    background: var(--md-gray-50, #f8fafb) !important;
  }

  /* Form fields spacing on mobile */
  .modal .modal-body .form-label {
    font-size: 0.9rem;
  }

  .modal .modal-body .mb-3 {
    margin-bottom: 0.75rem !important;
  }

  .modal .modal-body .form-control,
  .modal .modal-body .form-select {
    font-size: 16px !important; /* Prevent iOS zoom on focus */
  }

  /* Multi-select smaller on mobile */
  .modal .modal-body select[multiple] {
    max-height: 100px !important;
  }

  /* Row gap reduction on mobile */
  .modal .modal-body .row {
    --bs-gutter-y: 0.5rem;
  }

  /* Button size in modal footer on mobile */
  .modal .modal-footer .btn {
    min-height: 44px;
    padding: 0.5rem 1rem;
  }
}

/* Very small mobile screens - extra compact */
@media (max-width: 480px) {
  .modal .modal-body {
    padding: 0.75rem !important;
  }

  .modal .modal-body .form-label {
    font-size: 0.85rem;
    margin-bottom: 0.25rem;
  }

  .modal .modal-body .mb-3 {
    margin-bottom: 0.5rem !important;
  }

  .modal .modal-body .form-text {
    font-size: 0.75rem;
  }

  /* Stack two-column layouts on very small screens */
  .modal .modal-body .col-md-6,
  .modal .modal-body .col-lg-6 {
    flex: 0 0 100% !important;
    max-width: 100% !important;
  }

  /* Multi-select even smaller on very small screens */
  .modal .modal-body select[multiple] {
    max-height: 80px !important;
  }

  /* Reduce textarea height */
  .modal .modal-body textarea {
    max-height: 80px;
  }
}

/* ============================================
   TOAST NOTIFICATIONS
   ============================================ */

.md-toast {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 10px;
  color: #fff;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
  animation: mdToastIn 0.25s ease-out;
  max-width: min(420px, calc(100vw - 40px));
  font-weight: 600;
}

.md-toast--success {
  background: var(--md-success, #27ae60);
}

.md-toast--error {
  background: var(--md-danger, #e74c3c);
}

.md-toast--info {
  background: var(--md-primary, #2d7ff9);
}

.md-toast__msg {
  line-height: 1.2;
}

@keyframes mdToastIn {
  from {
    transform: translateX(16px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* ============================================
   SYSTEM TILES (Grid)
   ============================================ */

.md-system-tiles-toolbar {
  position: sticky;
  top: var(--md-fixed-header-height, 110px);
  z-index: 7;
  background: var(--md-white, #ffffff);
  border: 1px solid var(--md-border, #e4e9f0);
  border-radius: 12px;
  padding: 10px 12px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  margin-bottom: 12px;
}

.md-system-tiles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 260px));
  justify-content: start;
  align-content: start;
  gap: 8px;
}

.md-system-tile {
  background: var(--md-white, #ffffff);
  border: 1px solid var(--md-border, #e4e9f0);
  border-radius: 12px;
  padding: 8px;
  transition: box-shadow 0.15s ease;
  min-height: 0;
  overflow: hidden;
}

.md-system-tile:hover {
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
}

.md-system-tile__media {
  margin: -8px -8px 8px -8px;
  width: calc(100% + 16px);
  aspect-ratio: 1 / 1;
  overflow: hidden;
}

.md-system-tile__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
  background: var(--md-gray-50, #f8fafb);
  border-bottom: 1px solid var(--md-border, #e4e9f0);
}

.md-system-tile__img--placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(15, 120, 165, 0.18), rgba(15, 120, 165, 0.08));
}

.md-system-tile__logo {
  height: 28px;
  width: auto;
  max-width: 70%;
  object-fit: contain;
}

.md-system-tile__title {
  font-weight: 800;
  color: var(--md-text, #2c3e50);
  text-decoration: none;
  display: inline-block;
  font-size: 13px;
  line-height: 1.15;
}

.md-system-tile__title:hover {
  color: var(--md-blue, #0f78a5);
}

.md-system-tile__meta {
  color: var(--md-gray-700, #44566c);
  font-size: 11px;
  margin-top: 3px;
}

.md-system-tile__row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  align-items: center;
}

.md-system-tile__actions {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.md-system-tile__actions .btn {
  padding: 4px 8px;
  line-height: 1;
}

.md-system-tile__actions .btn i {
  margin: 0;
}

/* Contact Tile Avatar (für Kontakte ohne grosses Bild) */
.md-contact-tile__avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: var(--md-white, #ffffff);
  margin-right: 10px;
  flex-shrink: 0;
}

/* Mobile Tiles: Gleiche Grösse wie Desktop, auto-fill */
/* Keine Änderung der Tile-Grösse - zeigt so viele wie passen */

/* ============================================
   ROTATE PHONE HINT (für Tabellen auf Mobile)
   ============================================ */

.md-rotate-hint {
  display: none;
  background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
  border: 1px solid #bae6fd;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 12px;
  text-align: center;
  color: #0369a1;
  font-size: 13px;
}

.md-rotate-hint i {
  margin-right: 8px;
  animation: md-rotate-wiggle 2s ease-in-out infinite;
}

@keyframes md-rotate-wiggle {
  0%,
  100% {
    transform: rotate(0deg);
  }
  25% {
    transform: rotate(15deg);
  }
  75% {
    transform: rotate(-15deg);
  }
}

/* Nur auf Mobile im Portrait-Modus anzeigen */
@media (max-width: 768px) and (orientation: portrait) {
  .md-rotate-hint {
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

/* Verstecken wenn Landscape */
@media (orientation: landscape) {
  .md-rotate-hint {
    display: none !important;
  }
}

/* Hide on larger screens regardless of orientation */
@media (min-width: 992px) {
  .md-rotate-hint {
    display: none !important;
  }
}

/* ============================================
   EMPTY STATES
   ============================================ */

.empty-state {
  padding: 3rem 1rem;
  text-align: center;
}

.empty-state i {
  color: var(--md-gray-400, #a0aec0);
}

.empty-state h5 {
  color: var(--md-text, #2c3e50);
  margin-bottom: 0.5rem;
}

.empty-state p {
  color: var(--md-text-muted, #6b7c93);
  margin-bottom: 1.5rem;
}

.empty-state-image {
  opacity: 0.7;
  transition: opacity 0.3s ease;
}

.empty-state:hover .empty-state-image {
  opacity: 1;
}

/* ============================================
   SKELETON LOADERS
   ============================================ */

.skeleton-card,
.skeleton-table,
.skeleton-list-item {
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}

.skeleton-line,
.skeleton-button,
.skeleton-icon {
  background: linear-gradient(90deg, var(--md-gray-100, #f1f4f8) 25%, var(--md-gray-200, #e4e9f0) 50%, var(--md-gray-100, #f1f4f8) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
  border-radius: var(--md-radius-sm, 4px);
}

.skeleton-line {
  height: 12px;
  margin-bottom: 8px;
}

.skeleton-title {
  height: 20px;
  width: 60%;
  margin-bottom: 15px;
}

.skeleton-text {
  width: 100%;
}

.skeleton-button {
  height: 36px;
  width: 100px;
  margin-top: 10px;
}

.skeleton-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
}

.skeleton-stat {
  height: 14px;
  width: 80%;
  margin-bottom: 5px;
}

.skeleton-number {
  height: 28px;
  width: 50%;
}

.skeleton-table-row {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.skeleton-table-row .skeleton-line {
  flex: 1;
}

.skeleton-list-item {
  padding: 15px;
  border-bottom: 1px solid var(--md-border, #e4e9f0);
}

@keyframes skeleton-shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

@keyframes skeleton-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

/* ============================================
   DRAG & DROP
   ============================================ */

.md-drop-zone.drag-over {
  background: #e3f2fd !important;
  border: 2px dashed #2196f3 !important;
  border-radius: 8px;
  min-height: 80px;
  position: relative;
}

.md-drop-zone.drag-over::after {
  content: 'Hier ablegen um zu verschieben';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(33, 150, 243, 0.92);
  color: white;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  pointer-events: none;
  white-space: nowrap;
  z-index: 10;
}

.md-system-item {
  cursor: grab;
}

.md-system-item:active {
  cursor: grabbing;
}

.md-system-item.dragging {
  opacity: 0.45;
}

/* ============================================
   FOCUS RING
   ============================================ */

.md-focus-ring {
  outline: 3px solid rgba(45, 127, 249, 0.55);
  outline-offset: 4px;
  border-radius: 12px;
  animation: mdFocusPulse 1.1s ease-out 1;
}

@keyframes mdFocusPulse {
  0% {
    outline-color: rgba(45, 127, 249, 0);
  }
  40% {
    outline-color: rgba(45, 127, 249, 0.55);
  }
  100% {
    outline-color: rgba(45, 127, 249, 0);
  }
}

/* ============================================
   BREADCRUMBS
   ============================================ */

.breadcrumb {
  background: transparent;
  padding: 0.75rem 0;
  margin-bottom: 1rem;
  border-radius: 0;
}

.breadcrumb-item + .breadcrumb-item::before {
  content: '\203A';
  color: var(--md-gray-400, #a0aec0);
  font-size: 1.2rem;
  padding: 0 0.5rem;
}

.breadcrumb-item a {
  color: var(--md-blue, #0f78a5);
  text-decoration: none;
  transition: color 0.2s ease;
}

.breadcrumb-item a:hover {
  color: var(--md-blue-hover, #1487b8);
  text-decoration: underline;
}

.breadcrumb-item.active {
  color: var(--md-text-muted, #6b7c93);
}

/* ============================================
   FOOTER
   ============================================ */

.es_footer {
  background: var(--md-white, #ffffff);
  border-top: 1px solid var(--md-border, #e4e9f0);
  padding: 20px;
  margin-top: 40px;
  text-align: center;
  color: var(--md-text-light, #6b7c93);
  font-size: 12px;
}

.es_footer a {
  color: var(--md-blue, #0f78a5);
  text-decoration: none;
}

.es_footer a:hover {
  color: var(--md-blue-hover, #1487b8);
  text-decoration: underline;
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 767px) {
  .card-stats .icon-big {
    font-size: 2em;
  }

  .card-stats .card-title {
    font-size: 24px;
  }

  .empty-state {
    padding: 2rem 1rem;
  }

  .empty-state i {
    font-size: 3rem !important;
  }
}

/* ============================================
   MOBILE TOUCH TARGETS (44px minimum)
   ============================================ */

@media (max-width: 576px) {
  /* Touch-Targets: WCAG 44px minimum */
  .btn,
  .btn-sm,
  .btn-outline-secondary.btn-sm {
    min-height: 44px;
    min-width: 44px;
    padding: 0.5rem 0.75rem;
  }

  /* Action buttons in tables */
  .action-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }

  .td-actions .btn,
  .actions-buttons .btn {
    min-width: 44px;
    min-height: 44px;
  }

  /* Range sliders - larger touch area */
  input[type='range'],
  .inventory-slider {
    height: 44px;
    cursor: pointer;
  }

  /* Inventory quantity input - responsive width */
  .inventory-qty-input {
    width: 60px !important;
    font-size: 1rem;
    min-height: 44px;
  }

  /* Table image column - visible on mobile */
  .td-image {
    display: table-cell !important;
  }

  /* Mobile card layout: image cell visible */
  .table-mobile-card tbody td.td-image {
    display: flex !important;
    justify-content: center;
    padding: 0.75rem 0;
  }
}

/* ============================================
   TOUCH DEVICE TARGETS (coarse pointer)
   ============================================ */

@media (hover: none) and (pointer: coarse) {
  .action-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }
}

/* ============================================
   HISTORY / TIMELINE COMPONENTS
   ============================================ */

.md-history-timeline {
  position: relative;
}

.md-history-timeline__content {
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--md-gray-300, #cbd5e1) transparent;
}

.md-history-timeline__content::-webkit-scrollbar {
  width: 6px;
}

.md-history-timeline__content::-webkit-scrollbar-thumb {
  background: var(--md-gray-300, #cbd5e1);
  border-radius: 3px;
}

.md-history-item {
  padding: 10px 12px;
  margin-bottom: 8px;
  background: var(--md-gray-50, #f8fafb);
  border-radius: 8px;
  border-left: 3px solid var(--md-gray-300, #cbd5e1);
  transition: background 0.15s ease;
}

.md-history-item:hover {
  background: var(--md-gray-100, #f1f4f8);
}

.md-history-item:last-child {
  margin-bottom: 0;
}

.md-history-item__header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  margin-bottom: 4px;
}

.md-history-item__user {
  color: var(--md-text, #2c3e50);
  font-weight: 600;
}

.md-history-item__date {
  color: var(--md-text-light, #6b7c93);
  font-size: 11px;
}

.md-history-item__body {
  font-size: 13px;
  color: var(--md-text, #2c3e50);
}

.md-history-item__action {
  font-weight: 500;
}

.md-history-item__comment {
  margin-top: 6px;
  padding: 8px 10px;
  background: var(--md-white, #ffffff);
  border-radius: 6px;
  border: 1px solid var(--md-border, #e4e9f0);
  font-size: 12px;
  color: var(--md-text, #2c3e50);
}

.md-history-item__change {
  margin-top: 4px;
  font-size: 12px;
  color: var(--md-text-light, #6b7c93);
}

.md-history-item__change del {
  color: var(--md-danger, #e74c3c);
  text-decoration: line-through;
}

.md-history-item__change strong {
  color: var(--md-success, #27ae60);
}

.md-history-item__value {
  margin-top: 4px;
  font-size: 12px;
  color: var(--md-text, #2c3e50);
}

/* History Action Type Border Colors */
.md-history-item--created {
  border-left-color: var(--md-success, #27ae60);
}

.md-history-item--updated {
  border-left-color: var(--md-info, #17a2b8);
}

.md-history-item--completed {
  border-left-color: var(--md-success, #27ae60);
}

.md-history-item--comment {
  border-left-color: var(--md-primary, #2d7ff9);
}

.md-history-item--status_changed {
  border-left-color: var(--md-warning, #f39c12);
}

/* ============================================
   CHECKLIST ITEM COMPONENTS
   ============================================ */

.md-checklist-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  margin-bottom: 6px;
  background: var(--md-gray-50, #f8fafb);
  border-radius: 6px;
  transition: background 0.15s ease;
}

.md-checklist-item:hover {
  background: var(--md-gray-100, #f1f4f8);
}

.md-checklist-item:last-child {
  margin-bottom: 0;
}

.md-checklist-item--completed {
  background: rgba(39, 174, 96, 0.08);
}

.md-checklist-item--completed:hover {
  background: rgba(39, 174, 96, 0.12);
}

.md-checklist-item .form-check {
  margin: 0;
  padding: 0;
}

.md-checklist-item .form-check-input {
  margin-top: 3px;
  margin-right: 8px;
  cursor: pointer;
}

.md-checklist-item .form-check-label {
  font-size: 13px;
  line-height: 1.4;
  cursor: pointer;
}

.md-checklist-item .delete-checklist-item {
  opacity: 0;
  transition: opacity 0.15s ease;
  flex-shrink: 0;
}

.md-checklist-item:hover .delete-checklist-item {
  opacity: 1;
}

/* Checklist Progress */
.md-checklist-progress {
  height: 4px;
  background: var(--md-gray-200, #e4e9f0);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 12px;
}

.md-checklist-progress__bar {
  height: 100%;
  background: var(--md-success, #27ae60);
  transition: width 0.3s ease;
}

/* Priority Colors (Text only) */
.prio-critical {
  color: var(--md-danger, #dc3545);
  font-weight: 600;
}

.prio-high {
  color: var(--md-warning, #fd7e14);
  font-weight: 600;
}

.prio-normal {
  color: var(--md-primary, #0d6efd);
}

.prio-low {
  color: var(--md-text-light, #6b7c93);
}

/* ==========================================================================
   Mobile Quick Actions
   ========================================================================== */

.mobile-quick-actions {
  width: 100%;
  padding: 8px 12px;
  background: rgba(15, 120, 165, 0.08);
  border-bottom: 1px solid rgba(15, 120, 165, 0.15);
}

.mobile-actions-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

@media (max-width: 400px) {
  .mobile-actions-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.mobile-action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 60px;
  padding: 8px 4px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--md-border, #e4e9f0);
  color: var(--md-text, #2c3e50);
  text-decoration: none;
  font-size: 10px;
  font-weight: 600;
  text-align: center;
  line-height: 1.2;
  transition: all 0.15s ease;
}

.mobile-action-btn i {
  font-size: 18px;
  color: var(--md-blue, #0f78a5);
}

.mobile-action-btn:hover,
.mobile-action-btn:focus,
.mobile-action-btn:active {
  background: var(--md-blue, #0f78a5);
  color: #ffffff;
  border-color: var(--md-blue, #0f78a5);
  text-decoration: none;
}

.mobile-action-btn:hover i,
.mobile-action-btn:focus i,
.mobile-action-btn:active i {
  color: #ffffff;
}

.mobile-action-btn span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============================================
   MOBILE NAVIGATION OFFCANVAS
   Bootstrap 5 Offcanvas customizations
   ============================================ */

/* Offcanvas customization */
#mobileNavOffcanvas {
  max-width: 320px;
  width: 85vw;
}

#mobileNavOffcanvas .offcanvas-header {
  background: var(--md-blue, #0f78a5);
  color: #ffffff;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

#mobileNavOffcanvas .offcanvas-title {
  font-size: 18px;
  font-weight: 600;
  color: #ffffff;
  margin: 0;
}

#mobileNavOffcanvas .btn-close {
  filter: invert(1) grayscale(100%) brightness(200%);
  opacity: 0.8;
}

#mobileNavOffcanvas .btn-close:hover {
  opacity: 1;
}

#mobileNavOffcanvas .offcanvas-body {
  padding: 0;
  background: var(--md-white, #ffffff);
}

/* Mobile Navigation List */
.mobile-nav-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.mobile-nav-list > li {
  border-bottom: 1px solid var(--md-border, #e4e9f0);
}

/* Mobile Nav Links */
.mobile-nav-link {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  color: var(--md-text, #2c3e50);
  text-decoration: none;
  font-size: 15px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.mobile-nav-link:hover,
.mobile-nav-link:focus {
  background: var(--md-gray-50, #f8fafb);
  color: var(--md-blue, #0f78a5);
  text-decoration: none;
}

.mobile-nav-list > li.active .mobile-nav-link {
  background: rgba(15, 120, 165, 0.08);
  color: var(--md-blue, #0f78a5);
  font-weight: 600;
  border-left: 3px solid var(--md-blue, #0f78a5);
}

/* Mobile Nav Sections (Dropdowns) */
.mobile-nav-section {
  border-bottom: 1px solid var(--md-border, #e4e9f0);
}

.mobile-nav-section-title {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  color: var(--md-text-secondary, #64748b);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--md-gray-50, #f8fafb);
}

.mobile-nav-submenu {
  list-style: none;
  padding: 0;
  margin: 0;
  background: var(--md-white, #ffffff);
}

.mobile-nav-submenu li {
  border-bottom: 1px solid rgba(228, 233, 240, 0.5);
}

.mobile-nav-submenu li:last-child {
  border-bottom: none;
}

.mobile-nav-sublink {
  display: flex;
  align-items: center;
  padding: 12px 20px 12px 40px;
  color: var(--md-text, #2c3e50);
  text-decoration: none;
  font-size: 14px;
  transition: all 0.2s ease;
}

.mobile-nav-sublink:hover,
.mobile-nav-sublink:focus {
  background: var(--md-gray-50, #f8fafb);
  color: var(--md-blue, #0f78a5);
  text-decoration: none;
}

/* Mobile Quick Actions in Offcanvas */
.mobile-nav-list .mobile-quick-actions {
  padding: 16px;
  background: var(--md-gray-50, #f8fafb);
  border-bottom: 2px solid var(--md-border, #e4e9f0);
}

/* Mobile Mode Switcher in Offcanvas */
.mobile-mode-switcher {
  padding: 12px 16px;
  background: var(--md-gray-50, #f8fafb);
  border-bottom: 1px solid var(--md-border, #e4e9f0);
}

.mobile-mode-switcher .mode-switcher {
  display: flex;
  gap: 8px;
}

/* Mobile Praxis Badge */
.mobile-praxis-badge {
  padding: 12px 20px;
  background: rgba(15, 120, 165, 0.05);
  border-bottom: 1px solid var(--md-border, #e4e9f0);
}

.mobile-praxis-badge .praxis-mode-badge {
  display: inline-block;
  font-size: 13px;
  font-weight: 600;
}

/* Mobile Nav Search */
.mobile-nav-search {
  padding: 16px 20px;
  background: var(--md-gray-50, #f8fafb);
}

.mobile-nav-search .input-group {
  border: 1px solid var(--md-border, #e4e9f0);
  border-radius: 6px;
  overflow: hidden;
  background: var(--md-white, #ffffff);
}

.mobile-nav-search .input-group-text {
  background: transparent;
  border: none;
  color: var(--md-text-secondary, #64748b);
}

.mobile-nav-search .form-control {
  border: none;
  box-shadow: none;
}

.mobile-nav-search .form-control:focus {
  box-shadow: none;
}

/* Dark Mode Support */
[data-theme='dark'] #mobileNavOffcanvas .offcanvas-body,
[data-theme='dark'] .mobile-nav-submenu {
  background: var(--md-dark-bg, #1a1f2e);
}

[data-theme='dark'] .mobile-nav-link,
[data-theme='dark'] .mobile-nav-sublink {
  color: var(--md-dark-text, #e2e8f0);
}

[data-theme='dark'] .mobile-nav-link:hover,
[data-theme='dark'] .mobile-nav-link:focus,
[data-theme='dark'] .mobile-nav-sublink:hover,
[data-theme='dark'] .mobile-nav-sublink:focus {
  background: var(--md-dark-hover, #2d3748);
  color: var(--md-blue-light, #60a5fa);
}

[data-theme='dark'] .mobile-nav-section-title {
  background: var(--md-dark-hover, #2d3748);
  color: var(--md-dark-text-secondary, #94a3b8);
}

[data-theme='dark'] .mobile-nav-list > li,
[data-theme='dark'] .mobile-nav-section {
  border-bottom-color: var(--md-dark-border, #374151);
}

/* Mobile Offcanvas Responsive */
@media (max-width: 576px) {
  #mobileNavOffcanvas {
    max-width: 100%;
    width: 100%;
  }
}

/* ============================================
   DETAIL CARD (CRM Detail View - Option B)
   Full-height card: Hero + Tabs + Content
   ============================================ */

.md-detail-card {
  background: var(--md-white, #ffffff);
  border: 1px solid var(--md-border, #e4e9f0);
  border-radius: var(--md-radius-lg, 12px);
  box-shadow: var(--md-shadow-sm, 0 1px 3px rgba(0, 0, 0, 0.06));
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - var(--md-fixed-header-height, 110px) - 40px);
  overflow: hidden;
}

/* Hero Section */
.md-detail-card__hero {
  border-bottom: 1px solid var(--md-border, #e4e9f0);
  flex-shrink: 0;
}

/* Tab Navigation */
.md-detail-card__tabs {
  flex-shrink: 0;
  background: var(--md-white, #ffffff);
  border-bottom: 1px solid var(--md-border, #e4e9f0);
  position: sticky;
  top: var(--md-fixed-header-height, 110px);
  z-index: 8;
}

.md-detail-card__tabs .nav-tabs {
  border-bottom: none;
  padding: 0 16px;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.md-detail-card__tabs .nav-tabs::-webkit-scrollbar {
  display: none;
}

.md-detail-card__tabs .nav-tabs .nav-link {
  white-space: nowrap;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--md-text-light, #6b7c93);
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  transition: all 0.15s ease;
}

.md-detail-card__tabs .nav-tabs .nav-link:hover {
  color: var(--md-text, #2c3e50);
  border-bottom-color: var(--md-gray-300, #cbd5e1);
  background: transparent;
}

.md-detail-card__tabs .nav-tabs .nav-link.active {
  color: var(--md-blue, #0f78a5);
  border-bottom-color: var(--md-blue, #0f78a5);
  background: transparent;
  font-weight: 600;
}

.md-detail-card__tabs .nav-tabs .nav-link .badge {
  font-size: 10px;
  padding: 2px 6px;
  margin-left: 6px;
  vertical-align: middle;
}

/* Tab Content Area - fills remaining space */
.md-detail-card__content {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px;
  overflow-y: auto;
}

.md-detail-card__content .tab-content {
  flex: 1;
}

.md-detail-card__content .tab-pane {
  animation: mdDetailFadeIn 0.15s ease;
}

@keyframes mdDetailFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Sticky Footer inside content area */
.md-detail-card__footer {
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  background: var(--md-white, #ffffff);
  border-top: 1px solid var(--md-border, #e4e9f0);
  padding: 12px 20px;
  margin: 0 -20px -20px;
  z-index: 5;
}

/* ----------------------------------------
   Detail Hero Strip
   ---------------------------------------- */

.md-detail-hero {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: var(--md-gray-50, #f8fafb);
  border-left: 4px solid var(--md-blue, #0f78a5);
}

.md-detail-hero__image {
  flex-shrink: 0;
}

.md-detail-hero__info {
  flex: 1;
  min-width: 0;
}

.md-detail-hero__header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.md-detail-hero__title {
  font-size: 18px;
  font-weight: 700;
  color: var(--md-text, #2c3e50);
  margin: 0;
  line-height: 1.3;
}

.md-detail-hero__chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.md-detail-hero__subtitle {
  font-size: 13px;
  color: var(--md-text-light, #6b7c93);
  margin-top: 2px;
}

.md-detail-hero__meta {
  margin-top: 8px;
}

.md-detail-hero__meta .md-meta-grid {
  gap: 6px 16px;
}

.md-detail-hero__kpis {
  flex-shrink: 0;
  display: flex;
  gap: 12px;
}

/* ----------------------------------------
   Meta Grid Column Variants
   ---------------------------------------- */

.md-meta-grid--2 {
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
}

.md-meta-grid--3 {
  grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
}

.md-meta-grid--4 {
  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
}

/* ----------------------------------------
   Detail Card Responsive
   ---------------------------------------- */

@media (max-width: 768px) {
  .md-detail-card {
    border-radius: 0;
    border-left: none;
    border-right: none;
    min-height: calc(100vh - var(--md-mobile-header-height, 100px) - 20px);
  }

  .md-detail-hero {
    flex-wrap: wrap;
    padding: 12px 16px;
    gap: 12px;
  }

  .md-detail-hero__title {
    font-size: 16px;
  }

  .md-detail-hero__kpis {
    width: 100%;
    justify-content: space-around;
    border-top: 1px solid var(--md-border, #e4e9f0);
    padding-top: 10px;
    margin-top: 4px;
  }

  .md-detail-card__tabs .nav-tabs .nav-link {
    padding: 8px 12px;
    font-size: 12px;
  }

  .md-detail-card__content {
    padding: 16px;
  }

  .md-meta-grid--3,
  .md-meta-grid--4 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

@media (max-width: 576px) {
  .md-detail-hero__kpis {
    flex-direction: column;
    gap: 8px;
  }

  .md-detail-card__tabs .nav-tabs .nav-link span.d-none {
    display: none !important;
  }

  .md-meta-grid--2,
  .md-meta-grid--3,
  .md-meta-grid--4 {
    grid-template-columns: 1fr !important;
  }
}

/* ----------------------------------------
   Detail Card Dark Mode
   ---------------------------------------- */

[data-theme='dark'] .md-detail-card {
  background: var(--md-white, #252b3d);
  border-color: var(--md-border, #3a4255);
}

[data-theme='dark'] .md-detail-card__tabs {
  background: var(--md-white, #252b3d);
  border-color: var(--md-border, #3a4255);
}

[data-theme='dark'] .md-detail-hero {
  background: var(--md-gray-50, #252b3d);
}

[data-theme='dark'] .md-detail-card__footer {
  background: var(--md-white, #252b3d);
  border-color: var(--md-border, #3a4255);
}

/* ----------------------------------------
   Detail Card Print
   ---------------------------------------- */

@media print {
  .md-detail-card {
    min-height: auto;
    border: none;
    box-shadow: none;
  }

  .md-detail-card__tabs {
    position: static;
  }

  .md-detail-card__content {
    overflow: visible;
  }

  .md-detail-card__footer {
    position: static;
  }
}
