/* ========================================
   ADMIN PORTAL MODAL SYSTEM
   ======================================== */

/* Prevent body scrolling when modal is open */
body.modal-open {
  overflow: hidden;
  touch-action: none;
}

/* Modal Overlay */
.modal {
  position: fixed;
  inset: 0;
  display: none;
  justify-content: center;
  align-items: center;
  padding: 32px;
  background: var(--modal-overlay, rgba(15, 23, 42, 0.85));
  z-index: 10000;
  overflow-y: auto;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.modal.active {
  display: flex;
  opacity: 1;
}

.modal[aria-hidden="false"] {
  display: flex;
}

.modal[aria-hidden="true"] {
  display: none;
}

/* Modal Content */
.modal-content {
  width: min(720px, 100%);
  max-height: calc(100vh - 64px);
  background: var(--modal-background, #ffffff);
  border-radius: var(--modal-radius, 18px);
  border: 1px solid rgba(148, 163, 184, 0.18);
  box-shadow:
    0 32px 48px -28px rgba(15, 23, 42, 0.45),
    0 18px 36px -30px rgba(15, 23, 42, 0.35);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform: translateY(12px);
  transition: transform 0.3s ease;
}

.modal.active .modal-content {
  transform: translateY(0);
}

.modal-content.large {
  width: min(900px, 100%);
}

.modal-content.medium {
  width: min(640px, 100%);
}

.modal-content.small {
  width: min(420px, 100%);
}

.modal-content.compact {
  width: min(360px, 100%);
}

.modal-content.fullscreen {
  width: min(95vw, 1080px);
  max-height: calc(100vh - 32px);
}

/* Modal Header */
.modal-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 24px 32px;
  background: var(--modal-header-bg, var(--modal-background, #ffffff));
  border-bottom: 1px solid var(--border-color, #e2e8f0);
}

.modal-title-container {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-color, #1f2937);
  font-size: 1.125rem;
  font-weight: 600;
}

.modal-title-container i {
  font-size: 1.375rem;
  color: var(--primary-color, #2563eb);
}

.modal-header .modal-title {
  margin: 0;
  font: inherit;
}

.modal-header .modal-subtitle {
  margin-left: auto;
  color: var(--text-muted, #64748b);
  font-size: 0.9rem;
}

.modal-header .close-modal {
  margin-left: auto;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(148, 163, 184, 0.12);
  color: var(--text-muted, #475569);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.modal-header .close-modal:hover {
  background: rgba(59, 130, 246, 0.16);
  color: var(--primary-color, #2563eb);
}

.modal-header .close-modal:focus-visible {
  outline: 2px solid var(--primary-color, #2563eb);
  outline-offset: 2px;
}

/* Modal Body */
.modal-body {
  flex: 1 1 auto;
  padding: 28px 32px;
  background: var(--modal-background, #ffffff);
  overflow-y: auto;
}

.modal-body::-webkit-scrollbar {
  width: 8px;
}

.modal-body::-webkit-scrollbar-track {
  background: rgba(241, 245, 249, 0.6);
  border-radius: 6px;
}

.modal-body::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.65);
  border-radius: 6px;
}

.modal-body .form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 18px;
}

.modal-body .status-message {
  margin-bottom: 20px;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(15, 23, 42, 0.02);
}

/* Modal Footer */
.modal-footer {
  padding: 20px 32px;
  background: var(--modal-footer-bg, #f8fafc);
  border-top: 1px solid var(--border-color, #e2e8f0);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: flex-end;
  align-items: center;
}

.modal-footer.center {
  justify-content: center;
}

.modal-footer.space-between {
  justify-content: space-between;
}

.modal-footer .btn {
  min-width: 132px;
  justify-content: center;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.modal-footer .btn + .btn {
  margin-left: 0;
}

.modal-footer .btn i {
  font-size: 0.95rem;
}

/* Ensure proper ordering: secondary (cancel) button first, action button second */
.modal-footer .btn-secondary {
  order: 1;
}

.modal-footer .btn-primary,
.modal-footer .btn-danger,
.modal-footer .btn-success {
  order: 2;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 24px;
}

.modal-actions .btn {
  min-width: 120px;
}

/* Modal Variants */
.modal.confirm-modal .modal-header {
  border-bottom-color: rgba(245, 158, 11, 0.24);
}

.modal.success-modal .modal-header {
  border-bottom-color: rgba(16, 185, 129, 0.24);
}

.modal.danger-modal .modal-header {
  border-bottom-color: rgba(239, 68, 68, 0.28);
}

/* Order Details Layout */
.order-details-modal .modal-content {
  width: min(900px, 100%);
}

.order-details-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.order-details-grid .full-width {
  grid-column: 1 / -1;
}

.detail-section {
  background: var(--card-background, #f9fafb);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 12px;
  padding: 18px 20px;
}

.detail-section h4 {
  margin: 0 0 12px;
  font-size: 0.98rem;
  color: var(--text-color, #1f2937);
}

.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.95rem;
  color: var(--text-muted, #475569);
}

.detail-value {
  font-weight: 600;
  color: var(--text-color, #1f2937);
}

.items-table {
  width: 100%;
  border-collapse: collapse;
  border-radius: 12px;
  overflow: hidden;
}

.items-table th,
.items-table td {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.18);
  text-align: left;
}

.items-table th {
  background: rgba(148, 163, 184, 0.12);
  font-size: 0.9rem;
  color: var(--text-muted, #475569);
}

.items-table td {
  font-size: 0.95rem;
  color: var(--text-color, #1f2937);
}

.items-table .text-right {
  text-align: right;
  white-space: nowrap;
}

/* Close Button Variants */
/* Toast / compact modals */
.modal-content.compact .modal-body {
  padding: 20px;
}

.modal-content.compact .modal-footer {
  padding: 16px 20px;
}

/* Dark Mode */
[data-theme="dark"] .modal {
  background: var(--modal-overlay, rgba(25, 29, 35, 0.82));
}

[data-theme="dark"] .modal-content {
  background: var(--modal-background, #23272f);
  border-color: rgba(148, 163, 184, 0.28);
  box-shadow:
    0 28px 52px -32px rgba(0, 0, 0, 0.72),
    0 22px 42px -36px rgba(15, 23, 42, 0.55);
}

[data-theme="dark"] .modal-header,
[data-theme="dark"] .modal-body {
  background: var(--modal-background, #23272f);
  color: var(--text-main, #e2e8f0);
  border-color: var(--border-color, #2f3542);
}

[data-theme="dark"] .modal-header .close-modal {
  background: rgba(148, 163, 184, 0.16);
  border-color: rgba(148, 163, 184, 0.35);
  color: var(--text-main, #e2e8f0);
}

[data-theme="dark"] .modal-header .close-modal:hover {
  background: rgba(96, 175, 255, 0.22);
  color: var(--primary-accent, #60afff);
}

[data-theme="dark"] .modal-footer {
  background: var(--modal-footer-bg, #1e2530);
  border-color: var(--border-color, #2f3542);
}

[data-theme="dark"] .detail-section {
  background: rgba(30, 41, 59, 0.65);
  border-color: rgba(71, 85, 105, 0.5);
}

[data-theme="dark"] .detail-row {
  color: var(--text-muted, #a3adc2);
}

[data-theme="dark"] .detail-value {
  color: var(--text-main, #e2e8f0);
}

[data-theme="dark"] .items-table th {
  background: rgba(148, 163, 184, 0.18);
  color: var(--text-muted, #a3adc2);
}

[data-theme="dark"] .items-table td {
  color: var(--text-main, #e2e8f0);
}

/* High Contrast */
@media (prefers-contrast: high) {
  .modal-content {
    border-width: 2px;
  }

  .modal-header .close-modal {
    border-width: 2px;
  }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  .modal,
  .modal-content,
  .modal-header .close-modal {
    transition: none;
  }
}

/* Responsive */
@media (max-width: 992px) {
  .modal {
    padding: 24px;
  }

  .modal-body {
    padding-inline: 24px;
  }

  .modal-footer {
    padding-inline: 24px;
  }
}

@media (max-width: 768px) {
  .modal {
    padding: 18px;
  }

  .modal-content {
    max-height: calc(100vh - 36px);
    border-radius: 16px;
  }

  .modal-header,
  .modal-body,
  .modal-footer {
    padding-inline: 20px;
  }

  .modal-footer {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .modal-footer .btn {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .modal {
    padding: 12px;
  }

  .modal-content {
    max-height: calc(100vh - 24px);
    border-radius: 14px;
  }

  .modal-header {
    padding-block: 18px;
  }

  .modal-header .close-modal {
    width: 34px;
    height: 34px;
  }

  .modal-body {
    padding-block: 20px;
  }
}

/* Utility Hooks */
.modal [data-grid="two"] {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.modal [data-grid="two"] > * {
  min-width: 0;
}

@media (max-width: 768px) {
  .modal [data-grid="two"] {
    grid-template-columns: 1fr;
  }
}

.modal .status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.12);
  color: var(--primary-color, #2563eb);
  font-weight: 600;
}

/* Legacy support for scripts that expect fade/slide classes */
.modal-content.fade-in,
.modal.fade-in {
  animation: modalFadeIn 0.28s ease;
}

.modal-content.slide-up,
.modal.slide-up {
  animation: modalSlideUp 0.28s ease;
}

.modal-content.scale-in,
.modal.scale-in {
  animation: modalScaleIn 0.28s ease;
}

@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modalSlideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes modalScaleIn {
  from { opacity: 0; transform: scale(0.94); }
  to { opacity: 1; transform: scale(1); }
}

/* Utility custom properties */
:root {
  --modal-overlay: rgba(15, 23, 42, 0.72);
  --modal-background: #ffffff;
  --modal-header-bg: #ffffff;
  --modal-footer-bg: #f8fafc;
  --modal-radius: 18px;
}

:root[data-theme="dark"] {
  --modal-overlay: rgba(25, 29, 35, 0.82);
  --modal-background: var(--bg-card, #23272f);
  --modal-header-bg: var(--modal-background, #23272f);
  --modal-footer-bg: var(--bg-highlight, #1e2530);
  --modal-radius: 18px;
}

/* ===============================
   Dark Mode Modal Styles
   =============================== */

/* Dark mode modal overlay */
:root[data-theme="dark"] .modal {
  background-color: var(--modal-overlay, rgba(25, 29, 35, 0.8));
}

/* Dark mode modal content */
:root[data-theme="dark"] .modal-content {
  background-color: var(--modal-background, var(--bg-card));
  color: var(--text-main);
  border: 1px solid var(--border);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

/* Dark mode modal header */
:root[data-theme="dark"] .modal-header {
  background: var(--modal-header-bg, var(--bg-highlight));
  border-bottom: 1px solid var(--border);
  color: var(--text-main);
}

:root[data-theme="dark"] .modal-header h2,
:root[data-theme="dark"] .modal-header h3 {
  color: var(--text-main);
}

/* Dark mode modal body */
:root[data-theme="dark"] .modal-body {
  background-color: var(--modal-background, var(--bg-card));
  color: var(--text-main);
}

/* Dark mode modal footer */
:root[data-theme="dark"] .modal-footer {
  background: var(--modal-footer-bg, var(--bg-highlight));
  border-top: 1px solid var(--border);
  color: var(--text-main);
}

/* Dark mode modal close button */
:root[data-theme="dark"] .modal-close {
  background: var(--bg-highlight);
  color: var(--text-main);
  border: 1px solid var(--border);
}

:root[data-theme="dark"] .modal-close:hover {
  background: var(--hover);
  color: var(--text-main);
}

/* Dark mode form elements in modals */
:root[data-theme="dark"] .modal input,
:root[data-theme="dark"] .modal select,
:root[data-theme="dark"] .modal textarea {
  background-color: var(--input-background, var(--bg-highlight));
  color: var(--text-main);
  border: 1px solid var(--input-border, var(--border));
}

:root[data-theme="dark"] .modal input:focus,
:root[data-theme="dark"] .modal select:focus,
:root[data-theme="dark"] .modal textarea:focus {
  border-color: var(--primary-accent);
  box-shadow: 0 0 0 3px rgba(96, 175, 255, 0.1);
}

/* Dark mode status messages in modals */
:root[data-theme="dark"] .modal .status-message.success {
  background: rgba(34, 209, 138, 0.15);
  color: var(--success);
  border: 1px solid rgba(34, 209, 138, 0.3);
}

:root[data-theme="dark"] .modal .status-message.error {
  background: rgba(255, 93, 93, 0.15);
  color: var(--error);
  border: 1px solid rgba(255, 93, 93, 0.3);
}

:root[data-theme="dark"] .modal .status-message.info {
  background: rgba(96, 175, 255, 0.15);
  color: var(--info);
  border: 1px solid rgba(96, 175, 255, 0.3);
}

/* Dark mode buttons in modals */
:root[data-theme="dark"] .modal .btn {
  background: var(--bg-highlight);
  color: var(--text-main);
  border: 1px solid var(--border);
}

:root[data-theme="dark"] .modal .btn:hover {
  background: var(--hover);
  border-color: var(--primary-accent);
  color: var(--primary-accent);
}

:root[data-theme="dark"] .modal .btn-primary {
  background: var(--primary-accent);
  color: var(--text-inverse);
  border-color: var(--primary-accent);
}

:root[data-theme="dark"] .modal .btn-primary:hover {
  background: var(--secondary-accent);
  border-color: var(--secondary-accent);
}

/* Dark mode order details modal */
:root[data-theme="dark"] .order-details-modal .modal-content {
  max-width: 800px;
  width: 90%;
}

:root[data-theme="dark"] .order-details-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

:root[data-theme="dark"] .detail-section {
  background: var(--bg-highlight);
  border-radius: 6px;
  padding: 15px;
  margin-bottom: 15px;
  border: 1px solid var(--border);
}

:root[data-theme="dark"] .detail-section h4 {
  margin-top: 0;
  margin-bottom: 12px;
  color: var(--text-main);
  font-size: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

:root[data-theme="dark"] .detail-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

:root[data-theme="dark"] .detail-label {
  font-weight: 500;
  color: var(--text-muted);
}

:root[data-theme="dark"] .detail-value {
  font-weight: 600;
  color: var(--text-main);
}

:root[data-theme="dark"] .address-block {
  margin-bottom: 15px;
}

:root[data-theme="dark"] .address-block p {
  margin: 0 0 4px 0;
  color: var(--text-main);
}

:root[data-theme="dark"] .notes-block {
  background-color: var(--bg-highlight);
  padding: 10px;
  border-radius: 4px;
  border: 1px solid var(--border);
  color: var(--text-main);
}

:root[data-theme="dark"] .order-details-actions {
  display: flex;
  justify-content: space-between;
  width: 100%;
}

@media (max-width: 768px) {
  :root[data-theme="dark"] .order-details-grid {
    grid-template-columns: 1fr;
  }
}

