/**
 * CRM — professional shell (Bootstrap 5 layer)
 */
:root {
  --crm-bg: #f4f6f9;
  --crm-surface: #ffffff;
  --crm-border: #e2e8f0;
  --crm-text: #1e293b;
  --crm-muted: #64748b;
  --crm-accent: #2563eb;
  --crm-accent-hover: #1d4ed8;
  --crm-radius: 0.5rem;
  --crm-shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --crm-shadow-lg: 0 10px 40px rgba(15, 23, 42, 0.08);
}

html {
  scroll-behavior: smooth;
}

body {
  background: var(--crm-bg);
  color: var(--crm-text);
  font-feature-settings: "kern" 1, "liga" 1;
}

body.crm-app {
  min-height: 100vh;
}

/* Navbar */
.navbar.crm-navbar {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%) !important;
  box-shadow: var(--crm-shadow);
  padding-top: 0.65rem;
  padding-bottom: 0.65rem;
}

.navbar.crm-navbar .navbar-brand,
.navbar.crm-navbar .nav-link {
  color: rgba(255, 255, 255, 0.92) !important;
}

.navbar.crm-navbar .nav-link:hover,
.navbar.crm-navbar .nav-link:focus {
  color: #fff !important;
}

.navbar.crm-navbar .dropdown-menu {
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius);
  box-shadow: var(--crm-shadow-lg);
}

/* Cards */
.card {
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius);
  box-shadow: var(--crm-shadow);
  background: var(--crm-surface);
}

.card-header {
  background: linear-gradient(180deg, #fafbfc 0%, #f1f5f9 100%);
  border-bottom: 1px solid var(--crm-border);
  font-weight: 600;
  color: var(--crm-text);
}

/* Tables */
.table {
  --bs-table-hover-bg: rgba(37, 99, 235, 0.04);
}

.table thead th {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--crm-muted);
  border-bottom-width: 1px;
}

/* Buttons */
.btn-primary {
  --bs-btn-bg: var(--crm-accent);
  --bs-btn-border-color: var(--crm-accent);
  --bs-btn-hover-bg: var(--crm-accent-hover);
  --bs-btn-hover-border-color: var(--crm-accent-hover);
}

/* Page title */
h1, h2, h3 {
  letter-spacing: -0.02em;
}

.container-fluid.py-4 > h2:first-child {
  font-weight: 700;
  color: var(--crm-text);
  margin-bottom: 1.25rem;
}

/* Forms */
.form-control:focus,
.form-select:focus {
  border-color: var(--crm-accent);
  box-shadow: 0 0 0 0.2rem rgba(37, 99, 235, 0.15);
}

/* Login / setup pages */
body.crm-auth {
  background: linear-gradient(160deg, #0f172a 0%, #1e3a5f 50%, #f4f6f9 50%);
  min-height: 100vh;
}

body.crm-auth .card {
  border: none;
  box-shadow: var(--crm-shadow-lg);
}

/* SweetAlert polish */
.swal2-popup {
  border-radius: var(--crm-radius) !important;
  font-family: inherit !important;
}

.swal2-confirm {
  border-radius: var(--crm-radius) !important;
}

.orders-actions-cell .btn-group .btn {
  padding: 0.2rem 0.45rem;
}

.orders-actions-cell .btn-group .btn i {
  pointer-events: none;
}

.tracking-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 155px;
  text-align: center;
}

.tracking-empty-btn {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.tracking-number-text {
  font-weight: 600;
  font-size: 0.85rem;
  line-height: 1.1;
  word-break: break-word;
}

.tracking-carrier-text {
  color: var(--crm-muted);
  font-size: 0.75rem;
  line-height: 1.1;
}

.tracking-actions {
  display: flex;
  justify-content: center;
  gap: 4px;
}

.tracking-actions .btn {
  --bs-btn-padding-y: 0.12rem;
  --bs-btn-padding-x: 0.3rem;
}

.tracking-modal-table th {
  white-space: nowrap;
}

/* Products list */
#productsTable thead tr:first-child th.sortable {
  cursor: pointer;
  user-select: none;
}

#productsTable thead tr:first-child th.sortable:hover {
  background: rgba(37, 99, 235, 0.06);
}

#productsTable thead .sort-indicator {
  font-size: 0.7em;
  opacity: 0.85;
}

.product-thumb {
  width: 48px;
  height: 48px;
  object-fit: contain;
  vertical-align: middle;
  background: #f1f5f9;
  border: 1px solid var(--crm-border);
  border-radius: 0.35rem;
  display: inline-block;
}

.product-thumb--placeholder {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--crm-muted);
  font-size: 1.25rem;
}

.product-image-hover-preview {
  position: fixed;
  z-index: 1090;
  pointer-events: none;
  padding: 10px;
  background: #fff;
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius);
  box-shadow: var(--crm-shadow-lg);
  max-width: min(500px, calc(100vw - 24px));
  max-height: min(500px, calc(100vh - 24px));
}

.product-image-hover-preview img {
  display: block;
  max-width: min(460px, calc(100vw - 44px));
  max-height: min(460px, calc(100vh - 44px));
  width: auto;
  height: auto;
  object-fit: contain;
}

/* Order edit — WP-style tracking postbox */
.postbox {
  background: var(--crm-surface);
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius);
  box-shadow: var(--crm-shadow);
  overflow: hidden;
}

.postbox-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 1rem;
  margin: 0;
  background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
  border-bottom: 1px solid var(--crm-border);
  cursor: pointer;
  user-select: none;
}

.postbox-header:hover {
  background: linear-gradient(180deg, #f1f5f9 0%, #e2e8f0 100%);
}

.postbox-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--crm-text);
}

.postbox-toggle {
  color: var(--crm-muted);
  transition: transform 0.2s ease;
}

.postbox-header[aria-expanded="false"] .postbox-toggle .bi-chevron-down {
  transform: rotate(-90deg);
}

.postbox-inner {
  padding: 1rem 1.1rem;
  background: var(--crm-surface);
}

.order-activity-item:last-child {
  border-bottom: none !important;
  padding-bottom: 0 !important;
  margin-bottom: 0 !important;
}
