/* ==========================================================================
   Shared UI layer — loaded by every page after Tailwind.
   Adds design tokens, accessible focus states, toasts, the notification
   panel, skeleton loaders and small polish that Tailwind classes don't cover.
   ========================================================================== */

:root {
  --ui-bg: #0b1120;
  --ui-surface: #0f172a;
  --ui-surface-2: #1e293b;
  --ui-border: #1e293b;
  --ui-border-strong: #334155;
  --ui-text: #e2e8f0;
  --ui-muted: #94a3b8;
  --ui-accent: #3b82f6;
  --ui-accent-2: #a855f7;
  --ui-success: #10b981;
  --ui-warning: #f59e0b;
  --ui-danger: #f43f5e;
  --ui-radius: 14px;
  --ui-shadow: 0 20px 45px -15px rgba(2, 6, 23, 0.75);
  --ui-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body { text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased; }
::selection { background: rgba(59, 130, 246, 0.35); color: #fff; }

/* Visible keyboard focus everywhere (mouse clicks stay clean) */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--ui-accent);
  outline-offset: 2px;
  border-radius: 8px;
}

/* Thin, theme-matched scrollbars */
* { scrollbar-width: thin; scrollbar-color: #334155 transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: #334155; border-radius: 999px; }
*::-webkit-scrollbar-track { background: transparent; }

button:disabled, [aria-disabled="true"] { cursor: not-allowed; }
img { image-rendering: auto; }
img[src=""], img:not([src]) { visibility: hidden; }

/* Number inputs without spinners */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; }

/* Utility guarantee: .hidden is always hidden regardless of cascade order */
.hidden, [hidden] { display: none !important; }

/* Modals: smooth entrance */
.fixed.inset-0:not(.hidden) > div { animation: ui-pop 0.18s var(--ui-ease); }
@keyframes ui-pop { from { opacity: 0; transform: translateY(6px) scale(0.985); } to { opacity: 1; transform: none; } }

/* Cards lift slightly on hover */
.ui-lift { transition: transform 0.2s var(--ui-ease), border-color 0.2s, box-shadow 0.2s; }
.ui-lift:hover { transform: translateY(-2px); box-shadow: var(--ui-shadow); }

/* Mobile: let wide headers wrap instead of overflowing */
@media (max-width: 768px) {
  header > div { flex-wrap: wrap; gap: 0.75rem; }
  header > div > div { flex-wrap: wrap; row-gap: 0.5rem; }
  table { display: block; overflow-x: auto; white-space: nowrap; }
}

/* ---------- Toasts ---------- */
.ui-toasts {
  position: fixed; z-index: 9999; right: 16px; bottom: 16px;
  display: flex; flex-direction: column; gap: 10px; max-width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}
.ui-toast {
  pointer-events: auto; display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px; border-radius: 12px; font-size: 13px; line-height: 1.4; color: var(--ui-text);
  background: rgba(15, 23, 42, 0.96); border: 1px solid var(--ui-border-strong); box-shadow: var(--ui-shadow);
  backdrop-filter: blur(8px); animation: ui-toast-in 0.22s var(--ui-ease);
}
.ui-toast.leaving { animation: ui-toast-out 0.18s ease forwards; }
.ui-toast i { margin-top: 2px; }
.ui-toast--success { border-color: rgba(16, 185, 129, 0.45); }
.ui-toast--success i { color: var(--ui-success); }
.ui-toast--error { border-color: rgba(244, 63, 94, 0.5); }
.ui-toast--error i { color: var(--ui-danger); }
.ui-toast--warning { border-color: rgba(245, 158, 11, 0.5); }
.ui-toast--warning i { color: var(--ui-warning); }
.ui-toast--info i { color: var(--ui-accent); }
.ui-toast button { margin-left: auto; color: var(--ui-muted); padding: 0 2px; }
.ui-toast button:hover { color: #fff; }
@keyframes ui-toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes ui-toast-out { to { opacity: 0; transform: translateX(16px); } }

/* ---------- Notification bell & panel ---------- */
.ui-bell { position: relative; display: inline-flex; }
.ui-bell__btn {
  position: relative; width: 38px; height: 38px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--ui-surface-2); border: 1px solid var(--ui-border-strong); color: var(--ui-text); transition: background 0.15s;
}
.ui-bell__btn:hover { background: #273449; }
.ui-bell__badge {
  position: absolute; top: -6px; right: -6px; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 999px;
  background: var(--ui-danger); color: #fff; font-size: 10px; font-weight: 800; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 0 2px var(--ui-surface);
}
.ui-bell__badge[hidden] { display: none; }
.ui-bell__btn.has-unread i { animation: ui-ring 1.2s ease 1; transform-origin: top center; }
@keyframes ui-ring { 0%, 100% { transform: rotate(0); } 20% { transform: rotate(14deg); } 40% { transform: rotate(-12deg); } 60% { transform: rotate(8deg); } 80% { transform: rotate(-4deg); } }

.ui-panel {
  position: absolute; right: 0; top: calc(100% + 10px); z-index: 60; width: min(380px, calc(100vw - 24px));
  background: rgba(15, 23, 42, 0.98); border: 1px solid var(--ui-border-strong); border-radius: 16px; box-shadow: var(--ui-shadow);
  overflow: hidden; animation: ui-pop 0.16s var(--ui-ease); text-align: left;
}
.ui-panel[hidden] { display: none; }
.ui-panel__head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--ui-border); }
.ui-panel__head h3 { font-size: 13px; font-weight: 800; color: #fff; }
.ui-panel__head button { font-size: 11px; color: #93c5fd; font-weight: 600; }
.ui-panel__head button:hover { color: #fff; }
.ui-panel__list { max-height: 420px; overflow-y: auto; }
.ui-panel__empty { padding: 32px 16px; text-align: center; color: var(--ui-muted); font-size: 12px; }
.ui-note {
  display: grid; grid-template-columns: 30px 1fr auto; gap: 10px; padding: 12px 14px; border-bottom: 1px solid rgba(30, 41, 59, 0.7);
  cursor: pointer; transition: background 0.12s; color: var(--ui-text); text-decoration: none;
}
.ui-note:hover { background: rgba(30, 41, 59, 0.55); }
.ui-note.unread { background: rgba(59, 130, 246, 0.07); }
.ui-note__icon { width: 30px; height: 30px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 12px; background: rgba(59, 130, 246, 0.14); color: #93c5fd; }
.ui-note__icon.t-low_stock, .ui-note__icon.t-return_requested { background: rgba(245, 158, 11, 0.14); color: #fcd34d; }
.ui-note__icon.t-out_of_stock, .ui-note__icon.t-refund { background: rgba(244, 63, 94, 0.14); color: #fda4af; }
.ui-note__icon.t-order_placed, .ui-note__icon.t-payment { background: rgba(16, 185, 129, 0.14); color: #6ee7b7; }
.ui-note__icon.t-promotion { background: rgba(168, 85, 247, 0.16); color: #d8b4fe; }
.ui-note__title { font-size: 12.5px; font-weight: 700; color: #fff; line-height: 1.3; }
.ui-note__msg { font-size: 11.5px; color: var(--ui-muted); margin-top: 2px; line-height: 1.4; }
.ui-note__time { font-size: 10px; color: #64748b; white-space: nowrap; }
.ui-note__dot { width: 7px; height: 7px; border-radius: 999px; background: var(--ui-accent); margin-top: 6px; justify-self: end; }

/* ---------- Search autocomplete ---------- */
.ui-suggest {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 45; overflow: hidden;
  background: rgba(15, 23, 42, 0.98); border: 1px solid var(--ui-border-strong); border-radius: 14px; box-shadow: var(--ui-shadow);
}
.ui-suggest[hidden] { display: none; }
.ui-suggest__label { padding: 8px 12px 4px; font-size: 10px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: #64748b; }
.ui-suggest__item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; cursor: pointer; font-size: 13px; color: var(--ui-text); }
.ui-suggest__item:hover, .ui-suggest__item.active { background: rgba(59, 130, 246, 0.14); }
.ui-suggest__item img { width: 34px; height: 34px; border-radius: 8px; object-fit: cover; background: var(--ui-surface-2); }
.ui-suggest__item mark { background: transparent; color: #93c5fd; font-weight: 700; }
.ui-suggest__price { margin-left: auto; font-size: 12px; color: var(--ui-muted); font-variant-numeric: tabular-nums; }

/* ---------- Filter chips ---------- */
.ui-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--ui-surface-2); color: #cbd5e1; border: 1px solid var(--ui-border-strong); transition: all 0.15s; white-space: nowrap;
}
.ui-chip:hover { color: #fff; border-color: #475569; }
.ui-chip.active { background: rgba(59, 130, 246, 0.18); border-color: rgba(59, 130, 246, 0.6); color: #dbeafe; }
.ui-chip .count { font-size: 10px; color: #64748b; font-weight: 700; }
.ui-chip.active .count { color: #93c5fd; }
.ui-chip.disabled { opacity: 0.4; pointer-events: none; text-decoration: line-through; }

/* ---------- Skeleton loaders ---------- */
.ui-skeleton { position: relative; overflow: hidden; background: #172033; border-radius: 10px; }
.ui-skeleton::after {
  content: ''; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(148, 163, 184, 0.08), transparent);
  animation: ui-shimmer 1.3s infinite;
}
@keyframes ui-shimmer { to { transform: translateX(100%); } }

/* ---------- Status pills (returns, stock) ---------- */
.ui-pill { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; text-transform: capitalize; border: 1px solid transparent; }
.ui-pill--requested { background: rgba(245, 158, 11, 0.12); color: #fcd34d; border-color: rgba(245, 158, 11, 0.3); }
.ui-pill--approved { background: rgba(59, 130, 246, 0.12); color: #93c5fd; border-color: rgba(59, 130, 246, 0.3); }
.ui-pill--received { background: rgba(168, 85, 247, 0.12); color: #d8b4fe; border-color: rgba(168, 85, 247, 0.3); }
.ui-pill--refunded, .ui-pill--ok { background: rgba(16, 185, 129, 0.12); color: #6ee7b7; border-color: rgba(16, 185, 129, 0.3); }
.ui-pill--rejected, .ui-pill--out { background: rgba(244, 63, 94, 0.12); color: #fda4af; border-color: rgba(244, 63, 94, 0.3); }
.ui-pill--closed { background: rgba(100, 116, 139, 0.15); color: #cbd5e1; border-color: rgba(100, 116, 139, 0.35); }
.ui-pill--low { background: rgba(245, 158, 11, 0.12); color: #fcd34d; border-color: rgba(245, 158, 11, 0.3); }

/* ---------- Range slider ---------- */
.ui-range { -webkit-appearance: none; appearance: none; width: 100%; height: 4px; border-radius: 999px; background: #334155; }
.ui-range::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 999px; background: var(--ui-accent); border: 2px solid #fff; cursor: pointer; }
.ui-range::-moz-range-thumb { width: 14px; height: 14px; border-radius: 999px; background: var(--ui-accent); border: 2px solid #fff; cursor: pointer; }

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}

/* ---------- Charts (admin analytics) ---------- */
:root, .viz-root {
  --viz-1: #3987e5;          /* categorical slot 1, dark-surface step */
  --viz-muted: #8b8a84;      /* previous period / comparison */
  --viz-grid: rgba(148, 163, 184, 0.12);
  --viz-cross: rgba(226, 232, 240, 0.35);
  --viz-surface: #1e293b;
}
.viz-axis { font-size: 10.5px; fill: #94a3b8; font-variant-numeric: tabular-nums; }
.viz-tip {
  position: absolute; z-index: 5; pointer-events: none; min-width: 150px;
  padding: 8px 10px; border-radius: 10px; background: rgba(15, 23, 42, 0.96); border: 1px solid #334155;
  box-shadow: var(--ui-shadow); font-size: 11.5px; color: #e2e8f0;
}
.viz-tip__date { font-size: 10.5px; color: #94a3b8; margin-bottom: 4px; }
.viz-tip__row { display: flex; align-items: center; gap: 6px; }
.viz-tip__row strong { margin-left: auto; padding-left: 12px; color: #fff; font-variant-numeric: tabular-nums; }
.viz-key { display: inline-block; width: 14px; height: 2px; border-radius: 2px; background: var(--viz-1, #3987e5); }
.viz-key--dashed { background: repeating-linear-gradient(90deg, var(--viz-muted, #8b8a84) 0 4px, transparent 4px 7px); }
details > summary::-webkit-details-marker { display: none; }
