/* ============================================================
   Trendsic Dynamics — Worker App
   components.css · component library built on tokens.css
   Vanilla CSS, framework-agnostic. Pair with Bootstrap 5
   utilities if you like; nothing here depends on it.
   Load order:  tokens.css  →  components.css
   ============================================================ */

/* ---- Reset-ish base ---------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  -webkit-font-smoothing: antialiased;
}

@keyframes ts-spin  { to { transform: rotate(360deg); } }
@keyframes ts-pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* Any element scoped to a theme reasserts the base text color so it
   recomputes from that theme's tokens (inheritance alone would keep
   the ancestor's already-computed color). */
[data-theme] { color: var(--text); }

/* Generic spinner ring */
.ts-spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2.5px solid color-mix(in srgb, var(--primary) 28%, transparent);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: ts-spin .8s linear infinite;
  flex-shrink: 0;
}

/* ============================================================
   TYPOGRAPHY HELPERS
   ============================================================ */
.ts-display { font-size: var(--fs-display); font-weight: var(--fw-extra); letter-spacing: var(--ls-tight); line-height: var(--lh-tight); color: var(--text); }
.ts-title   { font-size: var(--fs-title);   font-weight: var(--fw-extra); letter-spacing: -.01em; line-height: var(--lh-tight); color: var(--text); }
.ts-h3      { font-size: var(--fs-h3);      font-weight: var(--fw-bold); color: var(--text); }
.ts-body    { font-size: var(--fs-body);    font-weight: var(--fw-regular); color: var(--text-2); }
.ts-muted   { color: var(--text-3); }
.ts-mono    { font-family: var(--font-mono); font-size: var(--fs-mono); font-weight: var(--fw-medium); }
.ts-mono-label {
  font-family: var(--font-mono); font-size: var(--fs-mono); font-weight: var(--fw-semibold);
  letter-spacing: .04em; text-transform: uppercase; color: var(--text-3);
}

/* ============================================================
   BUTTONS  ·  .ts-btn + variant + (block | sm)
   states: :hover  :active(pressed)  :disabled  .is-loading
   Min height = glove-friendly 56px (48px for --sm row actions).
   ============================================================ */
.ts-btn {
  -webkit-appearance: none; appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: var(--btn-h); padding: 0 var(--sp-6);
  border: 0; border-radius: var(--r-input);
  font-family: var(--font-sans); font-size: var(--fs-row); font-weight: var(--fw-bold);
  line-height: 1; cursor: pointer; user-select: none;
  transition: transform var(--dur-fast) var(--ease), background var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.ts-btn:active { transform: translateY(1px) scale(.99); }
.ts-btn:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 45%, transparent); outline-offset: 2px; }
.ts-btn--block { width: 100%; }
.ts-btn--sm { min-height: var(--btn-h-sm); font-size: var(--fs-sm); border-radius: 13px; }
.ts-btn--xs { min-height: 36px; padding: 0 var(--sp-4); font-size: var(--fs-xs); border-radius: var(--r-md); }
.ts-btn .ts-btn__icon { width: 20px; height: 20px; flex-shrink: 0; }

/* Primary (brand-blue) */
.ts-btn--primary { background: var(--primary); color: var(--on-primary); box-shadow: var(--sh-btn); }
.ts-btn--primary:hover  { background: var(--primary-press); }
.ts-btn--primary:active { background: var(--primary-press); }

/* Success (complete) */
.ts-btn--success { background: var(--success); color: #fff; box-shadow: var(--sh-btn-success); }
.ts-btn--success:hover { filter: brightness(1.05); }

/* Secondary (outlined) */
.ts-btn--secondary {
  background: var(--surface); color: var(--primary-on-tint);
  border: 1.5px solid var(--border-strong);
}
.ts-btn--secondary:hover { background: var(--surface-2); }

/* Ghost / neutral */
.ts-btn--ghost {
  background: var(--surface-2); color: var(--text-2);
  border: 1.5px solid var(--border);
}
.ts-btn--ghost:hover { background: var(--surface-3); }

/* Danger (flag) */
.ts-btn--danger {
  background: var(--danger-tint); color: var(--danger-on);
  border: 1.5px solid color-mix(in srgb, var(--danger) 35%, transparent);
}

/* Disabled */
.ts-btn:disabled, .ts-btn.is-disabled {
  background: var(--surface-3); color: var(--text-4);
  box-shadow: none; border-color: transparent; cursor: not-allowed; transform: none;
}

/* Loading — hides label, shows spinner */
.ts-btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.ts-btn.is-loading::after {
  content: ""; position: absolute; width: 20px; height: 20px;
  border: 2.6px solid rgba(255,255,255,.45); border-top-color: #fff;
  border-radius: 50%; animation: ts-spin .8s linear infinite;
}
.ts-btn--secondary.is-loading::after,
.ts-btn--ghost.is-loading::after { border-color: color-mix(in srgb, var(--primary) 30%, transparent); border-top-color: var(--primary); }

/* ============================================================
   CARDS  ·  .ts-card  (soft floating rounded surface)
   ============================================================ */
.ts-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: var(--sp-4);
}
.ts-card--flush { padding: 0; overflow: hidden; }
.ts-card--accent { border: 2px solid var(--accent); box-shadow: var(--sh-pop); }
.ts-card__title { font-size: var(--fs-sm); font-weight: var(--fw-bold); color: var(--text); }

/* ============================================================
   STATUS CHIPS  ·  .ts-chip + .ts-chip--{success|warn|danger|info}
   Pill with leading dot. Consistent status semantics everywhere.
   ============================================================ */
.ts-chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 12px; border-radius: var(--r-pill);
  font-size: var(--fs-xs); font-weight: var(--fw-bold); line-height: 1;
  white-space: nowrap;
}
.ts-chip__dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.ts-chip--success { background: var(--success-tint); color: var(--success-on); }
.ts-chip--warn    { background: var(--warn-tint);    color: var(--warn-on); }
.ts-chip--danger  { background: var(--danger-tint);  color: var(--danger-on); }
.ts-chip--info    { background: var(--info-tint);    color: var(--info-on); }
.ts-chip--neutral { background: var(--surface-3);    color: var(--text-2); }
.ts-chip .ts-chip__dot { color: var(--success); }       /* dot inherits explicit color below */
.ts-chip--success .ts-chip__dot { background: var(--success); }
.ts-chip--warn .ts-chip__dot    { background: var(--warn); }
.ts-chip--danger .ts-chip__dot  { background: var(--danger); }
.ts-chip--info .ts-chip__dot    { background: var(--info); }

/* ============================================================
   SYNC BADGES  ·  .ts-badge  (mono, for pending/synced/syncing)
   ============================================================ */
.ts-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: var(--r-sm);
  font-family: var(--font-mono); font-size: var(--fs-mono-sm); font-weight: var(--fw-semibold);
  letter-spacing: .02em; line-height: 1;
}
.ts-badge__dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.ts-badge--synced  { background: var(--success-tint); color: var(--success-on); }
.ts-badge--pending { background: var(--warn-tint);    color: var(--warn-on); }
.ts-badge--syncing { background: var(--info-tint);    color: var(--info-on); }
.ts-badge--syncing .ts-badge__spin {
  width: 11px; height: 11px; border: 2px solid currentColor; border-top-color: transparent;
  border-radius: 50%; animation: ts-spin .8s linear infinite;
}

/* ============================================================
   RESTRICTED / LOCKED  ·  .ts-restricted
   Treatment for info the current worker isn't permitted to see.
   ============================================================ */
.ts-restricted {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: var(--r-md);
  background: var(--surface-3); border: 1px dashed var(--border-strong);
  color: var(--text-2); font-size: var(--fs-xs); font-weight: var(--fw-semibold);
}
.ts-restricted__panel {              /* full locked state inside a card */
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  text-align: center; padding: 8px 6px 4px;
}
.ts-restricted__icon {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--surface-3); display: flex; align-items: center; justify-content: center;
  color: var(--text-3);
}

/* ============================================================
   LIST ROWS  ·  .ts-row  (visits, queue items)
   modifiers: .is-done (dimmed, struck)  .is-next (emphasized)
   ============================================================ */
.ts-row {
  display: flex; align-items: center; gap: var(--sp-3);
  min-height: var(--touch-min);
  padding: var(--sp-3) 15px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card);
}
.ts-row__lead {            /* route number / icon tile */
  width: 44px; height: 44px; border-radius: var(--r-md); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-3); color: var(--text-3);
  font-family: var(--font-mono); font-weight: var(--fw-bold); font-size: 15px;
}
.ts-row__lead--info    { background: var(--info-tint);    color: var(--info-on); }
.ts-row__lead--success { background: var(--success-tint); color: var(--success); }
.ts-row__lead svg { width: 22px; height: 22px; }   /* size inline icons used as the row lead (Schedule, Done rows) */
.ts-row__body  { flex: 1; min-width: 0; }
.ts-row__title { font-size: var(--fs-row); font-weight: var(--fw-bold); color: var(--text); }
.ts-row__sub   { font-size: var(--fs-xs); font-weight: var(--fw-medium); color: var(--text-3); }
.ts-row__chevron { color: var(--border-strong); flex-shrink: 0; }
.ts-row.is-done { opacity: .65; }
.ts-row.is-done .ts-row__title { text-decoration: line-through; text-decoration-color: var(--border-strong); }
.ts-row.is-next {
  border: 2px solid var(--accent); border-radius: var(--r-card);
  box-shadow: var(--sh-pop); position: relative;
}
.ts-row__flag {            /* "NEXT UP" tab floating on an emphasized card */
  position: absolute; top: -11px; left: 16px;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: var(--r-pill);
  background: var(--accent); color: var(--on-primary);
  font-size: var(--fs-mono-sm); font-weight: var(--fw-bold); letter-spacing: .03em;
}
[data-theme="dark"] .ts-row__flag { color: var(--bg); }

/* ============================================================
   CHECK ROW  ·  .ts-checkrow  (glove-friendly tap target, 56px)
   states: .is-checked
   ============================================================ */
.ts-checkrow {
  display: flex; align-items: center; gap: 13px;
  min-height: 56px; padding: 11px 16px;
  border-radius: var(--r-input);
  background: var(--surface); border: 1.5px solid var(--border-strong);
  font-size: var(--fs-body); font-weight: var(--fw-semibold); color: var(--text);
  cursor: pointer; transition: background var(--dur) var(--ease);
}
.ts-checkrow:active { background: var(--surface-2); }
.ts-checkrow__box {
  width: 26px; height: 26px; border-radius: var(--r-sm); flex-shrink: 0;
  border: 2px solid var(--border-strong); background: transparent;
  display: flex; align-items: center; justify-content: center;
}
.ts-checkrow__box svg { width: 15px; height: 15px; display: none; }
.ts-checkrow.is-checked {
  background: var(--success-tint); border-color: color-mix(in srgb, var(--success) 30%, transparent);
  color: var(--success-on); text-decoration: line-through;
}
.ts-checkrow.is-checked .ts-checkrow__box { background: var(--success); border-color: var(--success); }
.ts-checkrow.is-checked .ts-checkrow__box svg { display: block; }

/* ============================================================
   INPUTS  ·  .ts-field / .ts-input / .ts-textarea / .ts-select
   states: :focus(.is-focus)  :disabled
   ============================================================ */
.ts-field { display: flex; flex-direction: column; gap: 7px; }
.ts-label { font-size: var(--fs-xs); font-weight: var(--fw-semibold); color: var(--text-2); }
.ts-input, .ts-select, .ts-textarea {
  -webkit-appearance: none; appearance: none;
  width: 100%; font-family: var(--font-sans); font-size: var(--fs-body); color: var(--text);
  background: var(--surface-2); border: 1.5px solid var(--border); border-radius: var(--r-input);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur) var(--ease);
}
.ts-input, .ts-select { height: var(--field-h); padding: 0 16px; }
.ts-textarea { min-height: 82px; padding: 13px 15px; line-height: var(--lh-body); resize: vertical; }
.ts-input::placeholder, .ts-textarea::placeholder { color: var(--text-3); }
.ts-input:focus, .ts-select:focus, .ts-textarea:focus, .is-focus {
  outline: none; background: var(--surface);
  border-color: var(--primary);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 14%, transparent);
}
.ts-input:disabled, .ts-textarea:disabled { color: var(--text-4); background: var(--surface-3); }
.ts-select { background-image: none; cursor: pointer; }
/* input with trailing affordance (e.g. Show password) */
.ts-input-affix { position: relative; display: flex; align-items: center; }
.ts-input-affix .ts-input { padding-right: 64px; }
.ts-input-affix__btn {
  position: absolute; right: 16px; border: 0; background: transparent;
  color: var(--primary); font-weight: var(--fw-semibold); font-size: var(--fs-xs); cursor: pointer;
}

/* ============================================================
   TOGGLE / SWITCH  ·  .ts-toggle  (customer-visible etc.)
   state: .is-on
   ============================================================ */
.ts-toggle {
  width: 48px; height: 28px; border-radius: var(--r-pill); flex-shrink: 0;
  background: var(--border-strong); border: 0; padding: 0; position: relative; cursor: pointer;
  transition: background var(--dur) var(--ease);
}
.ts-toggle::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%; background: #fff;
  transition: transform var(--dur) var(--ease);
}
.ts-toggle.is-on { background: var(--primary); }
.ts-toggle.is-on::after { transform: translateX(20px); }

/* ============================================================
   BOTTOM TAB BAR  ·  .ts-tabbar / .ts-tab
   Thumb-reach nav. Active tab uses primary. 5 tabs max (Crew
   tab appears only for crew leads).
   ============================================================ */
.ts-tabbar {
  display: flex; justify-content: space-around; align-items: center;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 10px 4px max(22px, env(safe-area-inset-bottom));
  box-shadow: var(--sh-tab);
}
.ts-tab {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  min-width: 56px; min-height: var(--touch-min);
  border: 0; background: transparent; cursor: pointer;
  color: var(--text-3); font-size: var(--fs-mono-sm); font-weight: var(--fw-semibold);
  font-family: var(--font-sans);
}
.ts-tab__icon { width: 24px; height: 24px; }
.ts-tab.is-active { color: var(--primary); font-weight: var(--fw-bold); }

/* ============================================================
   BANNERS  ·  .ts-banner--{offline|syncing|info}
   Always-visible connectivity / sync state.
   ============================================================ */
.ts-banner {
  display: flex; align-items: center; gap: 11px;
  padding: 13px 18px; border-radius: var(--r-input);
}
.ts-banner__title { font-size: var(--fs-sm); font-weight: var(--fw-bold); line-height: 1.2; }
.ts-banner__sub   { font-size: var(--fs-xs); font-weight: var(--fw-medium); }
.ts-banner--offline { background: var(--warn-tint); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); }
.ts-banner--offline .ts-banner__title { color: var(--warn-on); }
.ts-banner--offline .ts-banner__sub   { color: var(--warn-on); opacity: .85; }
.ts-banner--offline .ts-banner__dot   { width: 10px; height: 10px; border-radius: 50%; background: var(--warn); flex-shrink: 0; }
.ts-banner--syncing { background: var(--info-tint); border: 1px solid color-mix(in srgb, var(--primary) 30%, transparent); }
.ts-banner--syncing .ts-banner__title { color: var(--info-on); }
.ts-banner--syncing .ts-banner__sub   { color: var(--info-on); opacity: .85; }
.ts-banner--info { background: var(--surface-2); border: 1px solid var(--border); }

/* ============================================================
   PROGRESS  ·  .ts-progress
   ============================================================ */
.ts-progress { height: 7px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.ts-progress__bar { display: block; height: 100%; border-radius: 4px; background: var(--success); }
.ts-progress__bar--info { background: var(--primary); }

/* ============================================================
   PHOTO THUMBNAILS  ·  .ts-thumb + .ts-thumb--add
   per-photo pending/synced/customer-visible state.
   Drop a real <img> in to replace the striped placeholder.
   ============================================================ */
.ts-thumb {
  position: relative; aspect-ratio: 1; border-radius: var(--r-input); overflow: hidden;
  background: repeating-linear-gradient(135deg, var(--surface-3), var(--surface-3) 7px, var(--surface-2) 7px, var(--surface-2) 14px);
}
.ts-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ts-thumb__state {       /* corner dot: synced / pending */
  position: absolute; top: 6px; left: 6px; width: 9px; height: 9px; border-radius: 50%;
  box-shadow: 0 0 0 2px var(--surface);
}
.ts-thumb__state--synced  { background: var(--success); }
.ts-thumb__state--pending { background: var(--warn); }
.ts-thumb__tag {         /* SYNCED / PENDING / SHOWN label */
  position: absolute; bottom: 6px; left: 6px;
  font-family: var(--font-mono); font-size: 9px; font-weight: var(--fw-semibold);
  padding: 2px 5px; border-radius: 5px; background: var(--surface);
}
.ts-thumb__tag--synced  { color: var(--success-on); }
.ts-thumb__tag--pending { color: var(--warn-on); }
.ts-thumb__visible {     /* customer-visible eye badge */
  position: absolute; top: 5px; right: 5px;
  display: inline-flex; align-items: center; gap: 3px;
  font-family: var(--font-mono); font-size: 8px; font-weight: var(--fw-semibold);
  color: #fff; background: var(--primary); padding: 3px 5px; border-radius: 5px;
}
.ts-thumb__visible svg { width: 11px; height: 11px; }
.ts-thumb--add {
  background: none; border: 2px dashed var(--border-strong);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  color: var(--primary);
}

/* ============================================================
   BOTTOM SHEET & MODAL  ·  .ts-sheet / .ts-modal-scrim / .ts-option
   ============================================================ */
.ts-modal-scrim {
  position: fixed; inset: 0; background: var(--scrim);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50;
}
.ts-sheet {
  width: 100%; max-width: 420px;
  background: var(--surface); border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: 18px 18px max(22px, env(safe-area-inset-bottom));
  box-shadow: 0 -10px 40px -10px rgba(10,12,40,.4);
}
.ts-sheet__handle { width: 44px; height: 5px; border-radius: 3px; background: var(--border-strong); margin: 0 auto 16px; }
.ts-sheet__title  { font-size: var(--fs-h3); font-weight: var(--fw-bold); color: var(--text); margin-bottom: 14px; }
/* selectable option (sheet list / category picker) */
.ts-option {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 52px; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 13px;
  font-size: var(--fs-body); font-weight: var(--fw-semibold); color: var(--text);
  cursor: pointer; transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.ts-option__radio { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border-strong); flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.ts-option__radio svg { width: 13px; height: 13px; display: none; }
.ts-option.is-selected { background: var(--primary-tint); border: 1.5px solid var(--primary); color: var(--primary-on-tint); }
.ts-option.is-selected .ts-option__radio { background: var(--primary); border-color: var(--primary); }
.ts-option.is-selected .ts-option__radio svg { display: block; }
.ts-option--danger.is-selected { background: var(--danger-tint); border-color: var(--danger); color: var(--danger-on); }
.ts-option--danger.is-selected .ts-option__radio { background: var(--danger); border-color: var(--danger); }

/* ============================================================
   PHONE FRAME & SCREEN CHROME  (mockup scaffolding)
   Used by the styleguide & per-screen mockups. Not needed in
   the real PWA — there the .ts-screen content fills the viewport.
   ============================================================ */
.ts-phone {
  width: 390px; border-radius: 44px; padding: 9px; flex-shrink: 0;
  background: var(--surface); border: 1px solid var(--border-strong);
  box-shadow: var(--sh-phone);
}
[data-theme="dark"] .ts-phone { background: #0B0C24; border-color: #2C2F63; }
.ts-screen {
  width: 100%; height: 800px; border-radius: 36px; overflow: hidden;
  background: var(--bg); color: var(--text); position: relative; display: flex; flex-direction: column;
}
.ts-statusbar {
  height: 46px; flex-shrink: 0; background: var(--surface);
  display: flex; align-items: center; justify-content: space-between; padding: 0 26px;
  font-weight: var(--fw-bold); font-size: 15px; color: var(--text);
}
.ts-statusbar__icons { display: flex; align-items: center; gap: 7px; }
.ts-signal { display: flex; align-items: flex-end; gap: 2px; }
.ts-signal span { width: 3px; border-radius: 1px; background: var(--text); }
.ts-signal span:nth-child(1){ height: 6px; } .ts-signal span:nth-child(2){ height: 9px; }
.ts-signal span:nth-child(3){ height: 12px; } .ts-signal span:nth-child(4){ height: 15px; }
.ts-battery { width: 24px; height: 12px; border: 1.5px solid var(--text); border-radius: 3px; padding: 1.5px; display: flex; }
.ts-battery span { background: var(--text); border-radius: 1px; }
.ts-appbar {
  height: 54px; flex-shrink: 0; background: var(--surface);
  display: flex; align-items: center; justify-content: space-between; padding: 0 18px;
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-sm); font-weight: var(--fw-bold); color: var(--text-2);
}
.ts-iconbtn {
  width: 40px; height: 40px; border-radius: var(--r-md); border: 0; cursor: pointer;
  background: var(--surface-3); color: var(--text);
  display: flex; align-items: center; justify-content: center;
}
.ts-scroll { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }

/* brand gradient utility (icon tiles, splash) */
.ts-brand-grad { background: linear-gradient(150deg, var(--ts-blue), var(--ts-blue-deep)); }
.ts-avatar {
  width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: var(--fw-bold); font-size: var(--fs-body);
  background: linear-gradient(150deg, var(--ts-blue), var(--ts-blue-deep));
}
