/* ============================================================
   TAWSELO UI PRIMITIVES · v1.0
   Requires: tokens.css (load first)
   Documentation: docs/DESIGN_SYSTEM.md
   ------------------------------------------------------------
   Class prefix is `ts-` (Tawselo System). The legacy landing
   page owns the `tw-` prefix — never reuse it here.
   Everything is opt-in: no element selectors, no resets, no
   global side effects beyond ::selection and reduced-motion.
   ============================================================ */

::selection { background: var(--color-selection); }

/* ---- Buttons ------------------------------------------------
   One primary per view. Sentence case, verb-first labels.
   Heights: 36 (sm) · 44 (md, default) · 52 (lg).             */
.ts-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-family: var(--font-sans);
  font-size: var(--text-button-size);
  font-weight: var(--text-button-weight);
  letter-spacing: var(--text-button-tracking);
  line-height: 1;
  color: #fff;
  background: var(--color-action);
  border: 0;
  padding: 13px 20px; /* -> 44px height */
  border-radius: var(--radius-md);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: transform var(--motion-instant) ease, filter var(--motion-instant) ease,
              background var(--motion-instant) ease, box-shadow var(--motion-instant) ease;
}
.ts-btn:hover { filter: brightness(1.05); color: #fff; }
.ts-btn:active { transform: scale(.96); }
.ts-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.ts-btn--secondary {
  color: var(--color-ink);
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  padding: 12px 19px;
}
.ts-btn--secondary:hover { filter: none; background: var(--color-gray-50); color: var(--color-ink); }

.ts-btn--tonal { color: var(--color-link); background: var(--color-action-tint); }
.ts-btn--tonal:hover { filter: none; background: var(--color-orange-200); color: var(--color-link); }

.ts-btn--ghost { color: var(--color-body); background: transparent; padding-inline: 14px; }
.ts-btn--ghost:hover { filter: none; background: var(--color-gray-100); color: var(--color-body); }

.ts-btn--danger { background: var(--color-danger); }

.ts-btn--sm { font-size: 13px; padding: 11px 14px; border-radius: 8px; }  /* -> 36px */
.ts-btn--lg { font-size: 17px; padding: 17px 26px; border-radius: 12px; } /* -> 52px */

.ts-btn:disabled,
.ts-btn--disabled {
  color: var(--color-faint);
  background: var(--color-gray-100);
  border: 0;
  cursor: not-allowed;
  filter: none;
  transform: none;
}

/* Loading: spinner + aria-busy="true"; clicks suppressed via
   pointer-events. The inline spinner rides currentColor so it works
   on every variant (keeps spinning under reduced motion, matching
   .ts-spinner — an ongoing-state cue, not decoration). */
.ts-btn--loading { pointer-events: none; }
.ts-btn__spinner {
  width: 14px; height: 14px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  animation: ts-spin .8s linear infinite;
}

/* ---- Forms -------------------------------------------------- */
.ts-label {
  display: block;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  color: var(--color-ink);
  margin-bottom: 6px;
}
.ts-input,
.ts-select,
.ts-textarea {
  display: block;
  width: 100%;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--color-ink);
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  padding: 11px 13px;
  transition: border-color var(--motion-instant) ease, box-shadow var(--motion-instant) ease;
}
.ts-input::placeholder,
.ts-textarea::placeholder { color: var(--color-faint); }
.ts-input:focus,
.ts-select:focus,
.ts-textarea:focus {
  outline: none;
  border-color: var(--focus-border);
  box-shadow: var(--focus-ring);
}
.ts-input.is-invalid,
.ts-select.is-invalid,
.ts-textarea.is-invalid { border: 1.5px solid var(--color-danger); }
/* Mono inputs for IDs / codes / amounts (numbers-in-mono rule). */
.ts-input--mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.ts-field-error {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--color-danger);
  margin-top: 6px;
}
.ts-field-help {
  font-size: 12px;
  color: var(--color-faint);
  margin-top: 6px;
}

/* Checkbox & radio ride the accent color; switch is custom. */
.ts-checkbox, .ts-radio { accent-color: var(--color-action); width: 18px; height: 18px; }
.ts-switch {
  appearance: none;
  width: 38px; height: 22px;
  border-radius: var(--radius-full);
  background: var(--color-border-strong);
  position: relative;
  cursor: pointer;
  transition: background var(--motion-base) var(--ease-standard);
}
.ts-switch::after {
  content: '';
  position: absolute;
  left: 2px; top: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform var(--motion-base) var(--ease-tawselo);
}
.ts-switch:checked { background: var(--color-success); }
.ts-switch:checked::after { transform: translateX(16px); }
.ts-switch:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* ---- Cards --------------------------------------------------- */
.ts-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-1);
}
.ts-card--flat { box-shadow: var(--shadow-0); }
.ts-card--hover { transition: transform var(--motion-base) var(--ease-tawselo), box-shadow var(--motion-base) var(--ease-tawselo); }
.ts-card--hover:hover { transform: translateY(-5px); box-shadow: var(--shadow-lift); }

/* Stat / KPI card contents */
.ts-stat-label { font-size: 12px; color: var(--color-muted); margin-bottom: 6px; }
.ts-stat-value { font-family: var(--font-mono); font-size: 24px; font-weight: 600; color: var(--color-ink); font-variant-numeric: tabular-nums; }
.ts-stat-delta { font-size: 12px; font-weight: 600; margin-top: 6px; }
.ts-stat-delta--up { color: var(--color-success); }
.ts-stat-delta--down { color: var(--color-danger); }

/* ---- Badges · tags · status ---------------------------------- */
.ts-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: var(--radius-full);
  white-space: nowrap;
}
.ts-badge--success { color: var(--color-success-text); background: var(--color-success-bg); }
.ts-badge--warning { color: var(--color-warning-text); background: var(--color-warning-bg); }
.ts-badge--danger  { color: var(--color-danger-text);  background: var(--color-danger-bg); }
.ts-badge--info    { color: var(--color-info-text);    background: var(--color-info-bg); }
.ts-badge--neutral { color: var(--color-body);         background: var(--color-gray-100); }

/* Square-ish tags for categories/attributes (radius-sm, weight 600) */
.ts-tag {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--color-body);
  background: var(--color-gray-100);
  padding: 4px 9px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}
.ts-tag--brand { color: var(--color-link); background: var(--color-action-tint); }

.ts-status-dot {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--color-faint); /* offline default */
}
.ts-status-dot--online { background: var(--color-success); }
.ts-status-dot--busy   { background: var(--color-warning); }

/* ---- Alert / inline notice --------------------------------------
   Tinted panel for flash messages & validation summaries. Pair with
   role="alert" (danger/warning) or role="status" (success/info).   */
.ts-alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.55;
  border: 1px solid;
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
}
.ts-alert__icon { flex-shrink: 0; margin-block-start: 2px; }
.ts-alert__title { font-weight: 700; }
.ts-alert--success { color: var(--color-success-text); background: var(--color-success-bg); border-color: var(--color-success); }
.ts-alert--warning { color: var(--color-warning-text); background: var(--color-warning-bg); border-color: var(--color-warning); }
.ts-alert--danger  { color: var(--color-danger-text);  background: var(--color-danger-bg);  border-color: var(--color-danger); }
.ts-alert--info    { color: var(--color-info-text);    background: var(--color-info-bg);    border-color: var(--color-info); }

/* ---- Page header --------------------------------------------------
   Title + optional subtitle on the start side, actions on the end.  */
.ts-page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-block-end: var(--space-6);
}
.ts-page-header__title {
  font-family: var(--font-sans);
  font-size: var(--text-h2-size);
  font-weight: var(--text-h2-weight);
  letter-spacing: var(--text-h2-tracking);
  line-height: 1.15;
  color: var(--color-ink);
  margin: 0;
}
.ts-page-header__subtitle {
  font-size: 13.5px;
  color: var(--color-muted);
  margin: var(--space-1) 0 0;
}
.ts-page-header__actions { display: flex; align-items: center; gap: var(--space-2); }

/* ---- Tables ---------------------------------------------------
   Numbers & IDs in mono, right-aligned, tabular-nums.           */
/* Card-style scroll region: wide tables scroll inside, page never does. */
.ts-table-wrap {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  overflow-x: auto;
}
.ts-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  font-family: var(--font-sans);
  font-size: 13.5px;
  color: var(--color-ink);
}
.ts-table thead th {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--color-faint);
  text-align: start;
  background: var(--color-gray-50);
  border-bottom: 1px solid var(--color-border);
  padding: 12px 18px;
}
.ts-table tbody td {
  padding: 13px 18px;
  border-bottom: 1px solid var(--color-gray-100);
  vertical-align: middle;
}
.ts-table tbody tr:last-child td { border-bottom: 0; }
.ts-table .ts-num,
.ts-table .ts-id {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.ts-table .ts-num { text-align: end; }

/* Standalone mono/number utility — JetBrains Mono + tabular figures for
   totals, amounts, IDs and codes anywhere outside a .ts-table (the
   "numbers in mono" rule). Inside .ts-table, .ts-num additionally
   end-aligns (rule above). Replaces view-local helpers like .loyalty-num. */
.ts-num,
.ts-mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---- Pagination -------------------------------------------------
   <nav aria-label> region: summary on the start side, page links on
   the end. Current page is an orange fill; numbers in tabular-nums. */
.ts-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-3);
  font-family: var(--font-sans);
}
.ts-pagination__summary { font-size: 12px; color: var(--color-muted); }
.ts-pagination__summary strong {
  font-weight: 600;
  color: var(--color-body);
  font-variant-numeric: tabular-nums;
}
.ts-pagination__pages { display: flex; align-items: center; gap: var(--space-1); }
.ts-pagination__gap { padding-inline: var(--space-1); font-size: 12px; color: var(--color-faint); }
.ts-page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--color-body);
  text-decoration: none;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  transition: background var(--motion-instant) ease, color var(--motion-instant) ease;
}
.ts-page-link:hover { background: var(--color-gray-100); color: var(--color-ink); }
.ts-page-link:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.ts-page-link--current { background: var(--color-action); color: #fff; font-weight: 600; }
.ts-page-link--current:hover { background: var(--color-action); color: #fff; }
.ts-page-link--disabled { color: var(--color-faint); pointer-events: none; }

/* ---- Icon (inline SVG helper) ----------------------------------- */
.ts-icon { flex-shrink: 0; }

/* ---- Overline / eyebrow --------------------------------------- */
.ts-overline {
  font-size: var(--text-overline-size);
  font-weight: var(--text-overline-weight);
  letter-spacing: var(--text-overline-tracking);
  text-transform: uppercase;
  color: var(--color-muted);
}
.ts-overline--brand { color: var(--color-link); }
.ts-overline--on-dark { color: var(--color-orange-on-dark); }

/* ---- Modal ----------------------------------------------------- */
.ts-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4,20,47,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  z-index: 1050;
}
.ts-modal {
  width: 100%;
  max-width: 400px;
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-3);
  overflow: hidden;
}
.ts-modal__body { padding: 22px 22px 0; }
.ts-modal__title { font-size: 18px; font-weight: 700; color: var(--color-ink); }
.ts-modal__text { font-size: 14px; color: var(--color-muted); margin-top: 8px; line-height: 1.5; }
.ts-modal__actions { display: flex; gap: 10px; justify-content: flex-end; padding: 22px; }

/* ---- Toast ------------------------------------------------------ */
.ts-toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: var(--color-navy-900);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: var(--shadow-2);
  color: #fff;
}
.ts-toast__icon {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--color-success);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.ts-toast__icon--danger { background: var(--color-danger); }
.ts-toast__title { font-size: 13.5px; font-weight: 600; color: #fff; }
.ts-toast__text { font-size: 12px; color: var(--color-dark-muted); }

/* ---- Empty state ------------------------------------------------ */
.ts-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-6);
}
.ts-empty__icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: var(--color-gray-100);
  color: var(--color-faint);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-3);
}
.ts-empty__title { font-size: 14px; font-weight: 600; color: var(--color-ink); }
.ts-empty__text { font-size: 12.5px; color: var(--color-faint); margin-top: 4px; max-width: 240px; line-height: 1.5; }

/* ---- Loading: spinner & skeleton -------------------------------- */
@keyframes ts-spin { to { transform: rotate(360deg); } }
.ts-spinner {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 3px solid var(--color-orange-200);
  border-top-color: var(--color-action);
  animation: ts-spin .8s linear infinite;
}
@keyframes ts-shimmer {
  0%   { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}
.ts-skeleton {
  height: 12px;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, #EEF1F6 25%, var(--color-gray-50) 37%, #EEF1F6 63%);
  background-size: 400px 100%;
  animation: ts-shimmer 1.4s linear infinite;
}

/* ---- Sidebar navigation (dark navy chrome) ----------------------- */
.ts-sidenav {
  background: var(--color-navy-900);
  color: var(--color-dark-nav);
  padding: var(--space-4);
}
.ts-sidenav__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--color-dark-nav);
  text-decoration: none;
  transition: color var(--motion-instant) ease, background var(--motion-instant) ease;
}
.ts-sidenav__item:hover { color: #fff; }
.ts-sidenav__item--active { background: var(--color-action); color: #fff; font-weight: 600; }
.ts-sidenav__item--active:hover { color: #fff; }
.ts-sidenav__divider { border-top: 1px solid var(--color-dark-divider); margin: var(--space-4) 0; }

/* ---- New-order / live-event pulse --------------------------------- */
@keyframes ts-pulsering {
  0%   { box-shadow: 0 0 0 0 rgba(255,77,13,.4); }
  70%  { box-shadow: 0 0 0 12px rgba(255,77,13,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,77,13,0); }
}
.ts-pulse { animation: ts-pulsering 1.8s ease-out infinite; }

/* ---- Reduced motion: swap movement for simple fades ---------------- */
@media (prefers-reduced-motion: reduce) {
  .ts-btn, .ts-card--hover, .ts-switch, .ts-switch::after, .ts-sidenav__item, .ts-page-link { transition: none; }
  .ts-card--hover:hover { transform: none; }
  .ts-btn:active { transform: none; }
  .ts-pulse, .ts-skeleton { animation: none; }
}
