@layer components {
  #modal,
  #modal.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: var(--z-modal);
  }

  #modal.hidden,
  #modal.modal.hidden {
    display: none;
    pointer-events: none;
  }

  #modal:not(.hidden) {
    pointer-events: auto;
  }

  #modal .modal-card:focus {
    outline: none;
  }

  #modal .modal-card,
  #modal .modal-content {
    position: relative;
    margin: 0;
    transform: none !important;
    top: auto !important;
    left: auto !important;
    width: min(92vw, 1080px);
    max-height: min(88vh, 860px);
    background: #ffffff;
    border: 1px solid var(--panel-border);
    border-radius: 20px;
    box-shadow: var(--elevation-3);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    filter: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  body.modal-open {
    overflow: hidden;
  }

  #modal .modal-head {
    padding: 16px 20px 12px;
    border-bottom: 1px solid #e2e8f0;
    background: #ffffff;
  }

  #modal #modalForm {
    padding: 14px 20px 0;
    overflow: auto;
    min-height: 0;
  }

  #modal .modal-actions {
    padding: 12px 20px;
    border-top: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    background: #ffffff;
  }

  #modal .modal-card.modal-compact,
  #modal .modal-content.modal-compact {
    width: min(92vw, 760px);
  }

  #modal .modal-card.modal-accounts-user,
  #modal .modal-content.modal-accounts-user {
    width: min(94vw, 720px);
    max-height: min(88vh, 640px);
    border-radius: 14px;
  }

  #modal .modal-card.modal-accounts-user .modal-head,
  #modal .modal-content.modal-accounts-user .modal-head {
    padding: 10px 14px 8px;
    flex-shrink: 0;
  }

  #modal .modal-card.modal-accounts-user .modal-title-wrap,
  #modal .modal-content.modal-accounts-user .modal-title-wrap {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
  }

  #modal .modal-card.modal-accounts-user #modalTitle,
  #modal .modal-content.modal-accounts-user #modalTitle {
    margin: 0;
    font-size: 15px;
    font-weight: 650;
    line-height: 1.25;
    color: #0f172a;
  }

  #modal .modal-card.modal-accounts-user #modalMeta.modal-meta--subtitle,
  #modal .modal-content.modal-accounts-user #modalMeta.modal-meta--subtitle {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: #64748b;
    line-height: 1.3;
  }

  #modal .modal-card.modal-accounts-user .modal-close-btn,
  #modal .modal-content.modal-accounts-user .modal-close-btn {
    width: 28px;
    height: 28px;
    min-width: 28px;
    padding: 0;
    font-size: 14px;
    line-height: 1;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    background: #fff;
    color: #64748b;
  }

  #modal .modal-card.modal-accounts-user .modal-close-btn:hover,
  #modal .modal-content.modal-accounts-user .modal-close-btn:hover {
    background: #f8fafc;
    color: #334155;
  }

  #modal .modal-card.modal-accounts-user #modalForm,
  #modal .modal-content.modal-accounts-user #modalForm {
    padding: 10px 14px 4px;
    overflow: auto;
    min-height: 0;
  }

  #modal .modal-card.modal-accounts-user .modal-actions,
  #modal .modal-content.modal-accounts-user .modal-actions {
    position: sticky;
    bottom: 0;
    z-index: 2;
    padding: 8px 14px;
    gap: 6px;
    flex-shrink: 0;
    box-shadow: 0 -1px 0 #e8edf2;
  }

  #modal .modal-card.modal-accounts-user .modal-actions .btn,
  #modal .modal-content.modal-accounts-user .modal-actions .btn {
    min-height: 32px;
    padding: 0 12px;
    font-size: 13px;
  }

  #modal .modal-card.modal-product-detail,
  #modal .modal-card.modal-product-center,
  #modal .modal-card.modal-order-detail,
  #modal .modal-content.modal-product-detail,
  #modal .modal-content.modal-product-center,
  #modal .modal-content.modal-order-detail {
    width: min(94vw, 1100px);
    transition: background-color 120ms ease, border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease, opacity 120ms ease;
  }

  #modal .modal-card.modal-order-detail,
  #modal .modal-content.modal-order-detail {
    width: min(94vw, 790px);
    max-height: min(86vh, 740px);
  }

  #modal .modal-card.modal-order-detail .modal-head,
  #modal .modal-content.modal-order-detail .modal-head {
    padding: 14px 20px 10px;
  }

  #modal .modal-card.modal-order-detail .modal-head h2,
  #modal .modal-content.modal-order-detail .modal-head h2 {
    font-size: var(--text-title);
  }

  #modal .modal-card.modal-order-detail #modalForm,
  #modal .modal-content.modal-order-detail #modalForm {
    padding: 10px 14px 0;
  }

  #modal .modal-card.modal-order-detail .modal-actions,
  #modal .modal-content.modal-order-detail .modal-actions {
    padding: 8px 14px;
  }

  #modal .order-detail-modal {
    position: relative;
    padding: 10px;
    border-radius: 14px;
    display: grid;
    gap: 10px;
  }

  #modal .order-detail-watermark {
    right: 10px;
    top: 10px;
    width: 58px;
    height: 58px;
    opacity: 0.05;
  }

  #modal .order-detail-summary {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 28px;
    align-items: start;
  }

  #modal .order-detail-summary-left,
  #modal .order-detail-summary-right {
    display: grid;
    gap: 8px;
    align-content: start;
  }

  #modal .order-detail-row {
    display: grid;
    grid-template-columns: 88px minmax(0, 1fr);
    align-items: center;
    column-gap: 12px;
    min-height: 26px;
    min-width: 0;
  }

  #modal .order-detail-label {
    color: #64748b;
    font-size: 12.5px;
    font-weight: 500;
    line-height: 1.3;
    white-space: nowrap;
  }

  #modal .order-detail-value {
    color: #0f172a;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.35;
    min-width: 0;
    font-variant-numeric: tabular-nums;
  }

  #modal .order-detail-money-row .order-detail-value {
    text-align: right;
  }

  #modal .order-detail-table-section {
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 9px;
    display: grid;
    gap: 8px;
  }

  #modal .order-detail-table-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }

  #modal .order-detail-table-head h4 {
    margin: 0;
    font-size: 13px;
    color: #475569;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }

  #modal .order-detail-table-wrap {
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
  }

  #modal .order-detail-table {
    min-width: 780px;
    width: 100%;
    font-size: 13px;
  }

  #modal .order-detail-table th,
  #modal .order-detail-table td {
    padding: 9px 10px;
    white-space: nowrap;
  }

  #modal .order-detail-table th {
    font-size: 12.5px;
    letter-spacing: 0;
    text-transform: none;
  }

  #modal .order-detail-table td:last-child,
  #modal .order-detail-table th:last-child {
    max-width: 200px;
  }

  #modal .order-detail-modal .status,
  #modal .order-detail-modal .cod-badge {
    font-size: 12px;
  }

  #modal .order-detail-modal .brand-logo-sm {
    width: 20px;
    height: 20px;
    border-radius: 5px;
  }

  #modal .modal-card.pos-modal,
  #modal .modal-content.pos-modal,
  #modal .pos-modal {
    width: min(92vw, 1120px) !important;
    max-height: min(80vh, 700px) !important;
    padding: 0 !important;
    background: #ffffff;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    filter: none;
  }

  #modal .modal-card.pos-modal .modal-head,
  #modal .modal-content.pos-modal .modal-head {
    padding: 14px 18px 10px;
  }

  #modal .modal-card.pos-modal #modalForm,
  #modal .modal-content.pos-modal #modalForm {
    padding: 0 !important;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  #modal .modal-card.pos-modal .pos-order-layout,
  #modal .modal-content.pos-modal .pos-order-layout {
    gap: 14px !important;
    align-items: start !important;
  }

  #modal .pos-shell {
    position: relative;
  }

  #modal .pos-watermark {
    right: 14px;
    top: 8px;
    width: 72px;
    height: 72px;
    opacity: 0.045;
  }

  #modal .modal-card.pos-modal .pos-left,
  #modal .modal-content.pos-modal .pos-left,
  #modal .modal-card.pos-modal .pos-right,
  #modal .modal-content.pos-modal .pos-right {
    gap: 8px !important;
  }

  #modal .modal-card.pos-modal .pos-modal-footer,
  #modal .modal-content.pos-modal .pos-modal-footer {
    border-top: 1px solid #e2e8f0;
    background: #ffffff;
    min-height: 58px;
    padding: 8px 14px;
  }

  #modal .modal-card.pos-modal .pos-footer-actions,
  #modal .modal-content.pos-modal .pos-footer-actions {
    gap: 8px;
  }

  #modal .modal-card.pos-modal #posCancel,
  #modal .modal-content.pos-modal #posCancel {
    min-width: 104px;
    border-color: #cbd5e1;
    background: #ffffff;
    color: #334155;
  }

  #modal .modal-card.pos-modal #posSave,
  #modal .modal-content.pos-modal #posSave {
    min-width: 132px;
    box-shadow: none;
  }

  #modal .modal-card-loading {
    position: relative;
  }

  #modal .modal-card-loading::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.15),
      rgba(255, 255, 255, 0.4),
      rgba(255, 255, 255, 0.15)
    );
    background-size: 220% 100%;
    animation: shimmer 1s linear infinite;
    pointer-events: none;
    border-radius: inherit;
  }

  .modal-actions .btn.primary,
  #modal .modal-actions .btn.primary {
    min-width: 72px;
    background: linear-gradient(120deg, var(--primary, #3b82f6), var(--primary-strong, #2563eb)) !important;
    color: #fff !important;
    -webkit-text-fill-color: #fff !important;
  }
}

/* Global spotlight (command palette) — unlayered, above #modal */
.command-palette-overlay.spotlight-overlay {
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.spotlight-modal.command-palette-modal {
  width: min(640px, 96vw);
  border-radius: 20px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(248, 250, 252, 0.96));
  box-shadow: 0 28px 70px rgba(15, 23, 42, 0.2);
  overflow: hidden;
}

.spotlight-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-right: 12px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.16);
}

.spotlight-input.command-palette-input {
  font-size: 17px;
  padding: 16px 18px;
  border-bottom: 0;
  flex: 1;
  min-width: 0;
}

.spotlight-hint {
  font-size: 11px;
  font-weight: 600;
  color: #94a3b8;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(148, 163, 184, 0.12);
  flex-shrink: 0;
}

.spotlight-footer {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 14px 10px;
  font-size: 11px;
  color: #64748b;
  border-top: 1px solid rgba(148, 163, 184, 0.12);
  background: rgba(248, 250, 252, 0.65);
}

.spotlight-item.command-palette-item {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
}

.spotlight-ico {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  background: rgba(15, 23, 42, 0.05);
  border: 1px solid rgba(148, 163, 184, 0.14);
}

.spotlight-body {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.spotlight-title {
  font-size: 14px;
  font-weight: 650;
  color: #0f172a;
  line-height: 1.25;
}

.spotlight-meta {
  font-size: 12px;
  color: #64748b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.spotlight-hit {
  background: rgba(250, 204, 21, 0.38);
  color: inherit;
  border-radius: 3px;
  padding: 0 2px;
}

.spotlight-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #1d4ed8;
  background: rgba(219, 234, 254, 0.85);
  border-radius: 999px;
  padding: 3px 8px;
  flex-shrink: 0;
}

.spotlight-item.is-active .spotlight-ico {
  border-color: rgba(59, 130, 246, 0.35);
  background: rgba(239, 246, 255, 0.95);
}

body.dark .spotlight-modal.command-palette-modal {
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.98), rgba(15, 23, 42, 0.92));
  border-color: rgba(148, 163, 184, 0.22);
}

body.dark .spotlight-title {
  color: #f8fafc;
}

body.dark .spotlight-meta,
body.dark .spotlight-footer,
body.dark .spotlight-hint {
  color: #94a3b8;
}

body.dark .spotlight-hit {
  background: rgba(234, 179, 8, 0.32);
}

body.dark .spotlight-badge {
  color: #93c5fd;
  background: rgba(30, 58, 138, 0.45);
}
