/* ===== PhoneFix Design System (v2) ===== */

:root {
  /* Colors */
  --pf-primary: #3b82f6;
  --pf-primary-hover: #2563eb;
  --pf-primary-light: #eff6ff;
  --pf-success: #22c55e;
  --pf-success-light: #f0fdf4;
  --pf-warning: #f59e0b;
  --pf-warning-light: #fffbeb;
  --pf-danger: #ef4444;
  --pf-danger-light: #fef2f2;
  --pf-surface: #ffffff;
  --pf-bg: #f1f5f9;
  --pf-bg-soft: #f8fbff;
  --pf-text: #1e293b;
  --pf-text-muted: #64748b;
  --pf-border: #e2e8f0;

  /* Layout */
  --pf-radius: 12px;
  --pf-radius-sm: 8px;
  --pf-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --pf-shadow-lg: 0 4px 12px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.06);
  --pf-sidebar-w: 64px;
  --pf-sidebar-w-expanded: 240px;
  --pf-bottomnav-h: 60px;
  --pf-pos-dock-w: 33.333vw;
  --pf-transition: 0.2s ease;
}

/* ===== Base ===== */

.app-body {
  background:
    radial-gradient(circle at 12% 8%, rgba(59, 130, 246, 0.1), transparent 34%),
    radial-gradient(circle at 90% 4%, rgba(34, 197, 94, 0.08), transparent 28%),
    linear-gradient(180deg, var(--pf-bg-soft) 0%, var(--pf-bg) 36%, var(--pf-bg) 100%);
  color: var(--pf-text);
  font-size: 0.95rem;
  min-height: 100vh;
}

.app-body:not([data-role="admin"]) .admin-only {
  display: none !important;
}

/* ===== Card Overrides ===== */

.app-body .card {
  background: linear-gradient(180deg, #ffffff 0%, #fcfdff 100%);
  border: 1px solid var(--pf-border);
  border-radius: var(--pf-radius);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06), var(--pf-shadow);
}

.app-body .card-header {
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
  border-bottom: 1px solid var(--pf-border);
}

/* ===== Desktop Sidebar ===== */

.app-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--pf-sidebar-w);
  background: var(--pf-surface);
  border-right: 1px solid var(--pf-border);
  display: flex;
  flex-direction: column;
  z-index: 1040;
  transition: width var(--pf-transition);
  overflow: hidden;
}

.app-sidebar--expanded {
  width: var(--pf-sidebar-w-expanded);
  box-shadow: var(--pf-shadow-lg);
}

.app-sidebar__brand {
  height: 56px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid var(--pf-border);
  font-weight: 700;
  font-size: 1.1rem;
  white-space: nowrap;
  overflow: hidden;
  flex-shrink: 0;
}

.app-sidebar__brand-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1.25rem;
}

.app-sidebar__brand-logo {
  width: 32px;
  height: 32px;
  object-fit: contain;
  display: block;
}

.app-sidebar__brand-text {
  margin-left: 12px;
  opacity: 0;
  transition: opacity var(--pf-transition);
}

.app-sidebar--expanded .app-sidebar__brand-text {
  opacity: 1;
}

.app-sidebar__nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px;
}

.app-sidebar__item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--pf-radius-sm);
  color: var(--pf-text-muted);
  text-decoration: none;
  white-space: nowrap;
  margin-bottom: 2px;
  transition: background var(--pf-transition), color var(--pf-transition);
  min-height: 44px;
  position: relative;
}

.app-sidebar__item:hover {
  background: var(--pf-primary-light);
  color: var(--pf-primary);
}

.app-sidebar__item--active {
  background: var(--pf-primary-light);
  color: var(--pf-primary);
  font-weight: 600;
}

.app-sidebar__item--active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 4px;
  border-radius: 0 4px 4px 0;
  background: var(--pf-primary);
}

.app-sidebar__icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1.15rem;
}

.app-sidebar__label {
  margin-left: 14px;
  font-size: 0.875rem;
  opacity: 0;
  transition: opacity var(--pf-transition);
}

.app-sidebar--expanded .app-sidebar__label {
  opacity: 1;
}

.app-sidebar__footer {
  padding: 12px 16px;
  border-top: 1px solid var(--pf-border);
  white-space: nowrap;
  overflow: hidden;
  flex-shrink: 0;
}

.app-sidebar__pin {
  position: absolute;
  top: 12px;
  right: 8px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--pf-text-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--pf-transition);
  font-size: 0.85rem;
}

.app-sidebar--expanded .app-sidebar__pin {
  opacity: 1;
}

.app-sidebar__pin:hover {
  background: var(--pf-primary-light);
  color: var(--pf-primary);
}

.app-sidebar__pin--active {
  color: var(--pf-primary);
}

/* ===== Main Content ===== */

.app-content {
  min-height: 100vh;
  padding: 20px;
  transition: margin-left var(--pf-transition), margin-right var(--pf-transition);
}

.app-content > * {
  animation: pfPageIn 0.22s ease-out;
}

.app-content-stage.is-shell-hidden {
  display: none !important;
}

.app-main-frame {
  width: 100%;
  height: calc(100vh - 40px);
  min-height: 520px;
  border: 0;
  border-radius: var(--pf-radius);
  background: #fff;
  box-shadow: var(--pf-shadow);
  opacity: 1;
  transition: opacity 0.18s ease;
}

.app-main-frame.is-loading {
  opacity: 0.04;
}

@keyframes pfPageIn {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Desktop: offset for sidebar */
@media (min-width: 992px) {
  .app-content {
    margin-left: var(--pf-sidebar-w);
  }
  .app-content--sidebar-expanded {
    margin-left: var(--pf-sidebar-w-expanded);
  }
  .app-content--with-pos-dock {
    margin-right: var(--pf-pos-dock-w);
  }
}

/* Mobile: offset for bottom nav */
@media (max-width: 991.98px) {
  .app-content {
    padding-bottom: calc(var(--pf-bottomnav-h) + env(safe-area-inset-bottom, 0px) + 16px);
  }
  .app-main-frame {
    display: none !important;
  }
}

/* ===== Desktop POS Dock ===== */

.app-pos-dock {
  display: none;
}

@media (min-width: 992px) {
  .app-pos-dock {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: var(--pf-pos-dock-w);
    background: #fff;
    border-left: 1px solid var(--pf-border);
    box-shadow: -8px 0 24px rgba(15, 23, 42, 0.08);
    z-index: 1030;
    flex-direction: column;
    overflow: hidden;
  }

  .app-pos-dock__head {
    height: 56px;
    flex-shrink: 0;
    padding: 10px 12px;
    border-bottom: 1px solid var(--pf-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
  }

  .app-pos-dock__title {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--pf-text);
    font-size: 0.95rem;
    font-weight: 700;
  }

  .app-pos-dock__title i {
    color: var(--pf-primary);
  }

  .app-pos-dock__frame {
    width: 100%;
    height: calc(100% - 56px);
    border: 0;
    background: #fff;
    opacity: 1;
    transition: opacity 0.18s ease;
  }

  .app-pos-dock__frame.is-loading {
    opacity: 0.02;
  }

  .app-pos-dock__loading {
    position: absolute;
    top: 56px;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
    background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px;
    text-align: center;
    transition: opacity 0.18s ease;
    pointer-events: none;
  }

  .app-pos-dock__loading.is-hidden {
    opacity: 0;
  }

  .app-pos-dock__loading-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--pf-text);
    margin-bottom: 8px;
  }

  .app-pos-dock__loading-meta {
    font-size: 0.84rem;
    color: var(--pf-text-muted);
  }
}

/* ===== Mobile Bottom Nav ===== */

.app-bottomnav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--pf-bottomnav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--pf-border);
  display: flex;
  align-items: stretch;
  z-index: 1040;
}

.app-bottomnav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: none;
  color: var(--pf-text-muted);
  text-decoration: none;
  font-size: 0.7rem;
  padding: 4px 2px;
  min-height: 44px;
  transition: color var(--pf-transition);
  -webkit-tap-highlight-color: transparent;
}

.app-bottomnav__item:hover,
.app-bottomnav__item:active {
  color: var(--pf-primary);
}

.app-bottomnav__item--active {
  color: var(--pf-primary);
  font-weight: 600;
}

.app-bottomnav__icon {
  font-size: 1.3rem;
  line-height: 1;
}

/* ===== Bottom Sheet (Mobile "More" Menu) ===== */

.app-bottomsheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 1050;
}

body.app-mobile-more-open {
  overflow: hidden;
}

.app-bottomsheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 75vh;
  background: var(--pf-surface);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
  z-index: 1060;
  overflow-y: auto;
  padding: 8px 0 env(safe-area-inset-bottom, 8px);
}

.app-bottomsheet__handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: #cbd5e1;
  margin: 8px auto 12px;
}

.app-bottomsheet__item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 24px;
  color: var(--pf-text);
  text-decoration: none;
  font-size: 0.95rem;
  min-height: 48px;
  transition: background var(--pf-transition);
}

.app-bottomsheet__item:hover {
  background: var(--pf-primary-light);
}

.app-bottomsheet__item--active {
  color: var(--pf-primary);
  font-weight: 600;
}

.app-bottomsheet__item i {
  font-size: 1.2rem;
  width: 24px;
  text-align: center;
  color: var(--pf-text-muted);
}

.app-bottomsheet__item--active i {
  color: var(--pf-primary);
}

/* ===== Toast System ===== */

.toast-stack {
  position: fixed;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

/* Desktop: bottom-right */
@media (min-width: 992px) {
  .toast-stack {
    bottom: 24px;
    right: 24px;
    align-items: flex-end;
  }
}

/* Mobile: top-center */
@media (max-width: 991.98px) {
  .toast-stack {
    top: 12px;
    left: 12px;
    right: 12px;
    align-items: stretch;
  }
}

.app-toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--pf-radius-sm);
  box-shadow: var(--pf-shadow-lg);
  font-size: 0.9rem;
  pointer-events: auto;
  max-width: 420px;
  background: var(--pf-surface);
  color: var(--pf-text);
  border-left: 4px solid var(--pf-text-muted);
}

.app-toast--success { border-left-color: var(--pf-success); background: var(--pf-success-light); }
.app-toast--danger  { border-left-color: var(--pf-danger);  background: var(--pf-danger-light); }
.app-toast--warning { border-left-color: var(--pf-warning); background: var(--pf-warning-light); }
.app-toast--info    { border-left-color: var(--pf-primary); background: var(--pf-primary-light); }

.app-toast__close {
  margin-left: auto;
  border: none;
  background: none;
  color: var(--pf-text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0 4px;
  line-height: 1;
  flex-shrink: 0;
}

.app-toast__close:hover {
  color: var(--pf-text);
}

/* ===== Dashboard ===== */

.dash-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.stat-card {
  background: var(--pf-surface);
  border-radius: 10px;
  box-shadow: var(--pf-shadow);
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.stat-card__label {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--pf-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.stat-card__value {
  font-size: clamp(1.15rem, 5.2vw, 1.55rem);
  font-weight: 700;
  line-height: 1.1;
  color: var(--pf-text);
  overflow-wrap: anywhere;
}

.stat-card__value--money {
  font-size: clamp(1.05rem, 4.8vw, 1.35rem);
}

.stat-card .d-flex > div:first-child {
  min-width: 0;
}

.stat-card__icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.stat-card__icon--blue    { background: var(--pf-primary-light); color: var(--pf-primary); }
.stat-card__icon--green   { background: var(--pf-success-light); color: var(--pf-success); }
.stat-card__icon--yellow  { background: var(--pf-warning-light); color: var(--pf-warning); }
.stat-card__icon--red     { background: var(--pf-danger-light);  color: var(--pf-danger); }

.dash-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 24px;
}

@media (max-width: 420px) {
  .app-content {
    padding: 16px;
  }
  .dash-stats {
    gap: 8px;
  }
  .stat-card {
    padding: 12px 10px;
    border-radius: 9px;
  }
  .stat-card__label {
    font-size: 0.68rem;
    letter-spacing: 0.015em;
  }
  .stat-card__value {
    font-size: clamp(1rem, 5.4vw, 1.35rem);
  }
  .stat-card__value--money {
    font-size: clamp(0.95rem, 5vw, 1.2rem);
  }
  .stat-card__icon {
    width: 28px;
    height: 28px;
    border-radius: 7px;
    font-size: 0.95rem;
  }
}

.action-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px 16px;
  background: var(--pf-surface);
  border: 1px solid var(--pf-border);
  border-radius: var(--pf-radius);
  box-shadow: var(--pf-shadow);
  text-decoration: none;
  color: var(--pf-text);
  font-weight: 500;
  font-size: 0.9rem;
  min-height: 110px;
  transition: box-shadow var(--pf-transition), transform var(--pf-transition);
}

.action-card:hover {
  box-shadow: var(--pf-shadow-lg);
  transform: translateY(-2px);
  color: var(--pf-primary);
}

.action-card__icon {
  font-size: 2rem;
  color: var(--pf-primary);
}

@media (max-width: 420px) {
  .dash-actions {
    gap: 10px;
  }
  .action-card {
    padding: 16px 10px;
    min-height: 96px;
    font-size: 0.82rem;
    border-radius: 12px;
  }
  .action-card__icon {
    font-size: 1.6rem;
  }
}

@media (min-width: 576px) {
  .dash-stats {
    gap: 12px;
  }
  .stat-card {
    padding: 16px 14px;
    border-radius: 12px;
  }
  .stat-card__label {
    font-size: 0.76rem;
  }
  .stat-card__value {
    font-size: clamp(1.2rem, 3.1vw, 1.65rem);
  }
  .stat-card__icon {
    width: 36px;
    height: 36px;
    font-size: 1.05rem;
  }
  .dash-actions {
    gap: 14px;
  }
}

@media (min-width: 992px) {
  .dash-stats {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
  }
  .stat-card {
    padding: 20px;
    border-radius: var(--pf-radius);
  }
  .stat-card__label {
    font-size: 0.8rem;
    letter-spacing: 0.03em;
  }
  .stat-card__value {
    font-size: 1.75rem;
  }
  .stat-card__value--money {
    font-size: clamp(1.05rem, 2vw, 1.45rem);
  }
  .stat-card__icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    font-size: 1.2rem;
  }
  .dash-actions {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
  }
}

/* ===== Login Page ===== */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--pf-bg);
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--pf-surface);
  border-radius: var(--pf-radius);
  box-shadow: var(--pf-shadow-lg);
  padding: 40px 32px;
}

.login-card__brand {
  text-align: center;
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.login-card__brand-logo {
  max-width: 128px;
  max-height: 44px;
  object-fit: contain;
  display: block;
}

.login-card__brand-fallback {
  line-height: 1;
}

.login-card__subtitle {
  text-align: center;
  color: var(--pf-text-muted);
  font-size: 0.9rem;
  margin-bottom: 32px;
}

/* ===== Barcode Scanner (same styles as base.html) ===== */

body.barcode-scanner-open { overflow: hidden; }

.barcode-scanner-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 15, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 2000;
}

.barcode-scanner-sheet {
  width: min(520px, 100%);
  background: #fff;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.3);
}

.barcode-scanner-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #eceff3;
  gap: 10px;
  flex-wrap: wrap;
}

.barcode-scanner-title {
  font-weight: 600;
  color: #212529;
}

.barcode-scanner-device {
  max-width: 180px;
  font-size: 0.85rem;
  padding: 0.2rem 0.4rem;
}

.barcode-scanner-view {
  position: relative;
  width: 100%;
  background: #000;
  aspect-ratio: 3 / 4;
}

.barcode-scanner-view video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.barcode-scanner-frame {
  position: absolute;
  inset: 12%;
  border: 2px solid rgba(255, 255, 255, 0.75);
  border-radius: 14px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}

.barcode-scanner-status {
  padding: 12px 16px 16px;
  color: #6c757d;
  font-size: 0.9rem;
  text-align: center;
}

.barcode-scanner-status.is-pulse {
  animation: barcodePulse 0.25s ease-out;
}

@keyframes barcodePulse {
  0%   { transform: scale(1);    color: #6c757d; }
  50%  { transform: scale(1.02); color: #0d6efd; }
  100% { transform: scale(1);    color: #6c757d; }
}

@media (max-width: 575px) {
  .barcode-scanner-sheet { border-radius: 12px; }
  .barcode-scanner-view { aspect-ratio: 3 / 5; }
}

/* ===== Page Header ===== */

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
}

.page-header__title {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-header__title i {
  color: var(--pf-primary);
}

.page-header__sub {
  font-size: 0.82rem;
  color: var(--pf-text-muted);
  margin: 2px 0 0;
}

/* ===== Page Card (main content wrapper) ===== */

.page-card {
  background: var(--pf-surface);
  border: 1px solid var(--pf-border);
  border-radius: var(--pf-radius);
  box-shadow: var(--pf-shadow);
}

.page-card__body {
  padding: 20px;
}

.page-card__header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--pf-border);
  font-weight: 600;
  font-size: 0.9rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

@media (max-width: 575.98px) {
  .page-card__body { padding: 14px; }
  .page-card__header { padding: 12px 14px; }
}

/* ===== Table Refinements ===== */

.app-body .table {
  font-size: 0.875rem;
  margin-bottom: 0;
}

.app-body .table-responsive {
  border: 1px solid var(--pf-border);
  border-radius: 10px;
  background: #fff;
}

.app-body .table th {
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--pf-text-muted);
  border-bottom-width: 1px;
  white-space: nowrap;
}

.app-body .table thead th,
.app-body .table thead.table-light th {
  background: #f8fbff !important;
  border-bottom-color: #dce7f7;
}

.app-body .table td {
  vertical-align: middle;
  border-color: #edf2f8;
}

.app-body .table-hover > tbody > tr {
  transition: background-color var(--pf-transition);
}

.app-body .table-hover > tbody > tr:hover {
  background: #f8fbff;
}

/* ===== Badge Refinements ===== */

.app-body .badge {
  font-weight: 500;
  font-size: 0.75rem;
  padding: 4px 8px;
  border-radius: 6px;
}

/* ===== Modal Refinements ===== */

.app-body .modal-content {
  border-radius: var(--pf-radius);
  border: none;
  box-shadow: var(--pf-shadow-lg);
}

.app-body .modal-header {
  border-bottom: 1px solid var(--pf-border);
  padding: 16px 20px;
}

.app-body .modal-title {
  font-size: 1rem;
  font-weight: 600;
}

.app-body .modal-body {
  padding: 20px;
}

.app-body .modal-footer {
  border-top: 1px solid var(--pf-border);
  padding: 12px 20px;
}

/* iPad portrait / tablet: make modals wider so form content is fully visible */
@media (min-width: 576px) and (max-width: 991.98px) {
  .modal-dialog.modal-xl,
  .modal-dialog.modal-lg {
    max-width: calc(100vw - 2rem);
    margin-left: 1rem;
    margin-right: 1rem;
  }
}

/* Desktop split mode: keep POS dock interactive when left-side modal opens */
@media (min-width: 992px) {
  body[data-has-pos-dock="1"] .modal-backdrop {
    right: var(--pf-pos-dock-w);
    z-index: 1050;
  }

  body[data-has-pos-dock="1"] .modal {
    right: var(--pf-pos-dock-w);
    z-index: 1060;
  }
}

/* ===== Button Refinements ===== */

.app-body .btn {
  border-radius: var(--pf-radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  min-height: 36px;
}

.app-body .btn-sm {
  font-size: 0.78rem;
  padding: 4px 10px;
  border-radius: 6px;
}

.app-body .btn-primary {
  background: linear-gradient(180deg, #4f8ff9 0%, #2f72f2 100%);
  border-color: #2f72f2;
}

.app-body .btn-primary:hover,
.app-body .btn-primary:focus {
  background: linear-gradient(180deg, #4486f7 0%, #2568e8 100%);
  border-color: #1f5dd9;
}

.app-body .btn-outline-primary {
  border-color: #b4cdfc;
  color: #2563eb;
}

.app-body .btn-outline-primary:hover,
.app-body .btn-outline-primary:focus {
  background: #eff6ff;
  border-color: #93baf9;
  color: #1d4ed8;
}

.app-body .btn-outline-secondary {
  border-color: #cdd7e5;
  color: #334155;
}

.app-body .btn-outline-danger {
  border-color: #f7b4b4;
  color: #dc2626;
}

/* ===== Form Refinements ===== */

.app-body .form-control,
.app-body .form-select {
  border-radius: var(--pf-radius-sm);
  border-color: var(--pf-border);
  font-size: 0.875rem;
}

.app-body .form-control:focus,
.app-body .form-select:focus {
  border-color: var(--pf-primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.app-body .form-label {
  font-weight: 500;
  font-size: 0.82rem;
  margin-bottom: 4px;
}

.app-body .input-group-text {
  border-color: var(--pf-border);
  background: #f8fafc;
  color: var(--pf-text-muted);
}

.app-body .nav-pills .nav-link {
  border-radius: 999px;
  color: var(--pf-text-muted);
  border: 1px solid transparent;
}

.app-body .nav-pills .nav-link.active,
.app-body .nav-pills .show > .nav-link {
  background: var(--pf-primary-light);
  color: #1d4ed8;
  border-color: #cfe0ff;
  font-weight: 600;
}

.app-body .nav-pills .nav-link:not(.active):hover {
  background: #f8fbff;
  border-color: #dce7f7;
}

/* ===== Alert Refinements ===== */

.app-body .alert {
  border-radius: var(--pf-radius-sm);
  font-size: 0.875rem;
}

/* ===== Pagination ===== */

.page-pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: 12px;
  border-top: 1px solid var(--pf-border);
  margin-top: 12px;
  font-size: 0.82rem;
}

/* ===== Filter Panel ===== */

.filter-panel {
  background: var(--pf-surface);
  border: 1px solid var(--pf-border);
  border-radius: var(--pf-radius);
  box-shadow: var(--pf-shadow);
  padding: 16px;
  margin-bottom: 16px;
}

.filter-panel.row {
  margin-left: 0;
  margin-right: 0;
}

/* ===== Empty State ===== */

.empty-state {
  text-align: center;
  color: var(--pf-text-muted);
  padding: 40px 20px;
  font-size: 0.9rem;
}

/* ===== Utility ===== */

.min-touch {
  min-width: 44px;
  min-height: 44px;
}

.sticky-actions {
  flex-wrap: wrap;
}

@media (max-width: 991.98px) {
  .sticky-actions {
    position: sticky;
    bottom: calc(var(--pf-bottomnav-h) + env(safe-area-inset-bottom, 0px) + 8px);
    z-index: 12;
    padding: 10px;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid var(--pf-border);
    border-radius: var(--pf-radius-sm);
    box-shadow: var(--pf-shadow);
  }
  .sticky-actions .btn {
    flex: 1 1 46%;
    min-height: 44px;
  }
}

.w-md-auto {
  width: 100%;
}

@media (min-width: 768px) {
  .w-md-auto {
    width: auto !important;
  }
}

/* ===== Stack Table ===== */

@media (max-width: 991.98px) {
  .stack-table thead {
    display: none;
  }

  .stack-table,
  .stack-table tbody,
  .stack-table tr,
  .stack-table td {
    display: block;
    width: 100%;
  }

  .stack-table tr {
    border: 1px solid var(--pf-border);
    border-radius: var(--pf-radius-sm);
    margin-bottom: 10px;
    background: var(--pf-surface);
    box-shadow: var(--pf-shadow);
    padding: 10px 12px;
  }

  .stack-table td {
    border: 0 !important;
    border-bottom: 1px dashed #edf2f8 !important;
    display: grid;
    grid-template-columns: minmax(84px, 35%) 1fr;
    gap: 8px;
    padding: 6px 0 !important;
    white-space: normal !important;
  }

  .stack-table td::before {
    content: attr(data-label);
    color: var(--pf-text-muted);
    font-size: 0.74rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }

  .stack-table td.no-label::before,
  .stack-table td[data-label=""]::before {
    content: "";
  }

  .stack-table td:last-child {
    border-bottom: 0 !important;
    padding-top: 10px !important;
  }

  .stack-table td:last-child.no-label,
  .stack-table td:last-child[data-label=""] {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
  }

  .stack-table td:last-child.no-label .btn-group,
  .stack-table td:last-child[data-label=""] .btn-group,
  .stack-table td:last-child.no-label .d-flex,
  .stack-table td:last-child[data-label=""] .d-flex {
    width: 100%;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 6px;
  }
}

/* ===== Loading Overlay ===== */

.pf-loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.2);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 2100;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--pf-transition);
}

.pf-loading-overlay.is-active {
  opacity: 1;
  pointer-events: auto;
}

.pf-loading-box {
  width: min(220px, calc(100vw - 32px));
  background: #fff;
  border: 1px solid var(--pf-border);
  border-radius: 14px;
  box-shadow: var(--pf-shadow-lg);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.pf-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid #dbeafe;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: pfSpin 0.8s linear infinite;
}

.pf-loading-text {
  color: var(--pf-text-muted);
  font-size: 0.84rem;
}

@keyframes pfSpin {
  to { transform: rotate(360deg); }
}

/* ===== Workbench Pages ===== */

.page-card .table-responsive {
  border-radius: 12px;
  background: #fff;
}

.page-card .btn-group.btn-group-sm {
  gap: 4px;
}

.page-card .btn-group.btn-group-sm > .btn {
  border-radius: 7px !important;
}

.page-card td .d-flex.flex-wrap.gap-1 {
  justify-content: flex-end;
}

.repair-board,
.repair-workbench {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.repair-board__hero,
.repair-workbench__hero {
  border: 1px solid #d5e5fb;
  border-radius: 16px;
  background:
    radial-gradient(circle at 5% 20%, rgba(59, 130, 246, 0.16), transparent 34%),
    linear-gradient(135deg, #ffffff 0%, #f7fbff 100%);
  padding: 18px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  box-shadow: 0 10px 28px rgba(37, 99, 235, 0.08);
}

.repair-board__hero-copy,
.repair-workbench__hero-copy {
  min-width: 0;
}

.repair-board__kicker,
.repair-workbench__kicker {
  font-size: 0.73rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #64748b;
  margin-bottom: 4px;
  font-weight: 700;
}

.repair-board__title,
.repair-workbench__title {
  margin: 0;
  font-size: 1.22rem;
  font-weight: 800;
  color: #0f172a;
  display: flex;
  align-items: center;
  gap: 8px;
}

.repair-board__title i,
.repair-workbench__title i {
  color: #2563eb;
}

.repair-board__sub,
.repair-workbench__sub {
  margin: 6px 0 0;
  font-size: 0.86rem;
  color: #64748b;
}

.repair-board__hero-actions,
.repair-workbench__hero-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.repair-board__filter {
  border-color: #d8e6fb;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.04);
}

.repair-board__filter .card-body {
  padding: 16px 18px;
  background: linear-gradient(180deg, #fbfdff 0%, #ffffff 100%);
}

.quick-tabs {
  white-space: nowrap;
  padding-bottom: 2px;
}

.quick-tabs .nav-link {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
}

.repair-board__list #list_summary {
  background: linear-gradient(180deg, #f8fbff 0%, #f4f8ff 100%);
  border-bottom: 1px solid #dce7f7;
  font-weight: 500;
}

.repair-board__ticket {
  font-weight: 700;
  color: #0f3a85;
  background: #e8f1ff;
  border: 1px solid #cfe0ff;
  padding: 2px 8px;
  border-radius: 999px;
}

.repair-board__table tbody tr td:first-child {
  font-weight: 700;
}

.repair-mobile-card {
  border: 1px solid #d6e4fa;
  border-radius: 14px;
  background: linear-gradient(180deg, #ffffff 0%, #f9fcff 100%);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.06);
  padding: 12px 12px 10px;
  margin-bottom: 10px;
}

.repair-mobile-card__head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.repair-mobile-card__name {
  font-weight: 700;
  color: #0f172a;
  line-height: 1.2;
}

.repair-mobile-card__meta {
  font-size: 0.76rem;
  color: #64748b;
  margin-top: 2px;
}

.repair-mobile-card__date {
  font-size: 0.76rem;
  color: #475569;
  background: #eef4ff;
  border: 1px solid #d6e4fa;
  padding: 2px 8px;
  border-radius: 999px;
}

.repair-mobile-card__device {
  margin-top: 10px;
  font-size: 0.86rem;
  color: #334155;
}

.repair-mobile-card__badges {
  margin-top: 8px;
}

.repair-mobile-card__actions {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.repair-mobile-card__actions .btn {
  min-height: 38px;
}

.repair-mobile-empty {
  border: 1px dashed #cfdced;
  border-radius: 12px;
  padding: 22px 12px;
  text-align: center;
  color: #64748b;
  background: #fbfdff;
}

.repair-step-card {
  position: relative;
  border-color: #d7e5fa;
}

.repair-step-card::before {
  content: attr(data-step);
  position: absolute;
  top: -10px;
  left: 14px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(180deg, #2f72f2 0%, #1d4ed8 100%);
  color: #fff;
  font-size: 0.74rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 16px rgba(37, 99, 235, 0.28);
  z-index: 3;
}

.repair-workbench .card-header.collapsible-header {
  padding-left: 52px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
  border-bottom-color: #dce7f7;
  font-weight: 700;
}

.repair-workbench .collapsible-header:hover {
  background: linear-gradient(180deg, #f8fbff 0%, #eff6ff 100%);
}

.repair-workbench .card-header .btn {
  min-height: 30px;
}

.repair-workbench #summary_box .card,
.repair-workbench #lock_box .alert,
.repair-workbench #customer_box .card,
.repair-workbench #front_info_box .card,
.repair-workbench #custody_action_box .card {
  border-radius: 14px;
  border-color: #d7e5fa;
}

.repair-workbench .alert {
  border-radius: 10px;
}

.repair-workbench textarea[readonly],
.repair-workbench input[readonly] {
  background: #f8fafc;
}

.repair-workbench #parts_table_wrap .table,
.repair-workbench #warranty_claims_list .table {
  font-size: 0.84rem;
}

@media (max-width: 991.98px) {
  .page-card .btn-group.btn-group-sm {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
  }
  .page-card .btn-group.btn-group-sm > .btn {
    flex: 1 1 calc(50% - 4px);
    min-height: 40px;
  }
  .page-card td .d-flex.flex-wrap.gap-1 .btn {
    flex: 1 1 calc(50% - 4px);
  }
  .repair-board__hero,
  .repair-workbench__hero {
    padding: 14px 14px 12px;
    flex-direction: column;
    align-items: stretch;
  }
  .repair-board__hero-actions,
  .repair-workbench__hero-actions {
    justify-content: stretch;
  }
  .repair-board__hero-actions > .btn,
  .repair-workbench__hero-actions > .btn {
    flex: 1 1 100%;
  }
  .repair-board__filter .card-body {
    padding: 12px;
  }
  .repair-mobile-card__actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .repair-workbench .btn-group {
    width: 100%;
  }
  .repair-workbench .btn-group .btn {
    flex: 1 1 46%;
  }
}
