/* Shared design language for CRM, TB Market and administration surfaces. */
:root {
  /* primitives */
  --tbds-blue-50:#eff6ff; --tbds-blue-500:#3b82f6; --tbds-blue-600:#2563eb; --tbds-blue-700:#1d4ed8;
  --tbds-slate-50:#f8fafc; --tbds-slate-100:#f1f5f9; --tbds-slate-200:#e2e8f0; --tbds-slate-500:#64748b; --tbds-slate-900:#0f172a;
  --tbds-emerald-500:#10b981; --tbds-amber-500:#f59e0b; --tbds-red-500:#ef4444;
  --tbds-space-1:.25rem; --tbds-space-2:.5rem; --tbds-space-4:1rem; --tbds-space-5:1.25rem; --tbds-space-6:1.5rem;
  --tbds-radius-sm:.625rem; --tbds-radius-lg:1.125rem;
  --tbds-control-height:48px; --tbds-control-height-sm:36px; --tbds-control-radius:12px;
  --tbds-ease-out:cubic-bezier(.23,1,.32,1);
  --tbds-shadow-sm:0 1px 2px rgb(15 23 42 / .06),0 1px 3px rgb(15 23 42 / .04); --tbds-shadow-md:0 12px 28px rgb(15 23 42 / .10);
  /* semantic */
  --tbds-canvas:var(--bg,var(--tbds-slate-50)); --tbds-surface:var(--surface,#fff); --tbds-surface-muted:var(--surface-soft,var(--tbds-slate-50));
  --tbds-border:var(--border,var(--tbds-slate-200)); --tbds-text:var(--text,var(--tbds-slate-900)); --tbds-text-muted:var(--muted,var(--tbds-slate-500));
  --tbds-primary:var(--brand,var(--tbds-blue-600)); --tbds-primary-hover:var(--tbds-blue-700); --tbds-focus:color-mix(in srgb,var(--tbds-primary) 30%,transparent);
  /* component */
  --tbds-card-bg:var(--tbds-surface); --tbds-card-border:var(--tbds-border); --tbds-card-radius:var(--tbds-radius-lg); --tbds-card-shadow:var(--tbds-shadow-sm);
  --tbds-control-bg:var(--input-bg,var(--tbds-surface)); --tbds-control-border:var(--input-border,var(--tbds-border));
}
html[data-theme="dark"] { --tbds-primary-hover:#93c5fd; --tbds-shadow-sm:0 1px 2px rgb(0 0 0 / .2),0 12px 28px rgb(0 0 0 / .16); --tbds-shadow-md:0 18px 42px rgb(0 0 0 / .26); }
.market-body { --tbds-canvas:var(--mkt-page-bg,#f6f8fc); --tbds-surface:var(--mkt-surface,#fff); --tbds-surface-muted:var(--mkt-surface-soft,#f6f8fc); --tbds-border:var(--mkt-border,#e2e8f0); --tbds-text:var(--mkt-text,#172033); --tbds-text-muted:var(--mkt-muted,#68758a); --tbds-primary:var(--mkt-primary,#2563eb); }
.mkt-admin,.platform-admin { --tbds-canvas:var(--tb-bg,#081224); --tbds-surface:var(--tb-surface,#0f1c33); --tbds-surface-muted:var(--tb-card,#132540); --tbds-border:var(--tb-border,rgb(255 255 255 / .1)); --tbds-text:var(--tb-text,#fff); --tbds-text-muted:var(--tb-muted,#8fa3bf); --tbds-primary:var(--tb-primary,#3b82f6); }

/* Shared accessibility and interaction baseline. */
.tb-ui :where(a,button,input,select,textarea,summary):focus-visible { outline:3px solid var(--tbds-focus); outline-offset:2px; }
.tb-ui :where(button,.btn,input[type="submit"],input[type="button"]) { min-height:44px; }
.tb-ui :where(input:not([type="checkbox"]):not([type="radio"]),select,textarea) { border-color:var(--tbds-control-border); background-color:var(--tbds-control-bg); color:var(--tbds-text); }
.tb-ui :where(input:not([type="checkbox"]):not([type="radio"]),select,textarea):focus { border-color:var(--tbds-primary); box-shadow:0 0 0 .22rem var(--tbds-focus); }
.tb-ui .btn {
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:.4rem;
  min-height:44px;
  border-radius:var(--tbds-control-radius);
  line-height:1.2;
  text-align:center;
}
.tb-ui .btn.btn-sm {
  min-height:var(--tbds-control-height-sm);
  padding:.4rem .75rem;
  border-radius:10px;
}
/* Market and platform use named button families rather than Bootstrap.  Keep
   their colours, but give the controls the same operational geometry as CRM. */
.tb-ui :is(.mkt-btn,.tb-btn) {
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:.4rem;
  min-height:44px;
  border-radius:var(--tbds-control-radius);
  line-height:1.2;
  text-align:center;
}
.tb-ui :is(.mkt-btn-primary,.tb-btn-primary) { box-shadow:0 5px 14px color-mix(in srgb,currentColor 13%,transparent); }
.tb-ui :is(.mkt-btn,.tb-btn):active { transform:scale(.975); }
/* The CRM shell predates the shared layer and uses a more specific selector. */
body[data-tbos-module="crm"].tb-ui .btn { border-radius:var(--tbds-control-radius); }
.tb-ui :is(.form-control,.form-select) {
  min-height:var(--tbds-control-height);
  border-radius:var(--tbds-control-radius);
  transition:border-color 160ms ease,box-shadow 160ms ease,background-color 160ms ease;
}
.tb-ui :is(.form-control.form-control-sm,.form-select.form-select-sm) {
  min-height:var(--tbds-control-height-sm);
  border-radius:10px;
}
body[data-tbos-module="crm"].tb-ui :is(.form-control,.form-select) { border-radius:var(--tbds-control-radius); }
body[data-tbos-module="crm"].tb-ui :is(.form-control.form-control-sm,.form-select.form-select-sm) { border-radius:10px; }
.tb-ui .card,.tb-ui .glass-panel,.tb-ui .modal-content,.tb-ui .market-card { border-color:var(--tbds-card-border); border-radius:var(--tbds-card-radius); }
.tb-ui :is(.btn,.msc-save-btn,.bl-btn,.bl-add-btn) { transition:transform 160ms var(--tbds-ease-out),box-shadow 160ms ease,background-color 160ms ease,border-color 160ms ease; }
.tb-ui .btn-primary,.tb-ui .btn-success,.tb-ui .btn-danger { box-shadow:0 5px 14px color-mix(in srgb,currentColor 13%,transparent); }
.tb-ui .tb-ui-hot-action {
  border-color:color-mix(in srgb,var(--tbds-primary) 56%,transparent);
  box-shadow:0 8px 20px color-mix(in srgb,var(--tbds-primary) 24%,transparent);
}
.tb-ui :is(.btn,.msc-save-btn,.bl-btn,.bl-add-btn):active { transform:scale(.975); }
@media (hover:hover) and (pointer:fine) {
  .tb-ui .btn-primary:hover,.tb-ui .btn-success:hover,.tb-ui .btn-danger:hover,.tb-ui .tb-ui-hot-action:hover { transform:translateY(-1px); }
  .tb-ui :is(.mkt-btn-primary,.tb-btn-primary):hover { transform:translateY(-1px); }
  .tb-ui .tb-ui-hot-action:hover { box-shadow:0 11px 24px color-mix(in srgb,var(--tbds-primary) 29%,transparent); }
}

/* Reusable primitives for new or migrated templates. */
.tb-ui-panel { border:1px solid var(--tbds-card-border); border-radius:var(--tbds-card-radius); background:var(--tbds-card-bg); box-shadow:var(--tbds-card-shadow); }
.tb-ui-panel--padded { padding:var(--tbds-space-5); }
.tb-ui-eyebrow { margin:0 0 var(--tbds-space-1); color:var(--tbds-text-muted); font-size:.72rem; font-weight:750; letter-spacing:.07em; line-height:1.2; text-transform:uppercase; }
.tb-ui-title { margin:0; color:var(--tbds-text); font-size:clamp(1.1rem,2.6vw,1.5rem); font-weight:760; letter-spacing:-.025em; line-height:1.2; }
.tb-ui-muted { color:var(--tbds-text-muted)!important; }
.tb-ui-status { display:inline-flex; align-items:center; gap:.35rem; max-width:100%; min-height:1.75rem; padding:.25rem .55rem; overflow:hidden; border:1px solid transparent; border-radius:999px; font-size:.78rem; font-weight:700; line-height:1.15; text-overflow:ellipsis; white-space:nowrap; }
.tb-ui-status--info { border-color:color-mix(in srgb,var(--tbds-primary) 27%,transparent); background:color-mix(in srgb,var(--tbds-primary) 12%,transparent); color:var(--tbds-primary); }
.tb-ui-status--success { border-color:color-mix(in srgb,var(--tbds-emerald-500) 30%,transparent); background:color-mix(in srgb,var(--tbds-emerald-500) 12%,transparent); color:var(--tbds-emerald-500); }
.tb-ui-status--warning { border-color:color-mix(in srgb,var(--tbds-amber-500) 32%,transparent); background:color-mix(in srgb,var(--tbds-amber-500) 13%,transparent); color:var(--tbds-amber-500); }
.tb-ui-status--danger { border-color:color-mix(in srgb,var(--tbds-red-500) 30%,transparent); background:color-mix(in srgb,var(--tbds-red-500) 11%,transparent); color:var(--tbds-red-500); }
.tb-ui-empty,.tb-ui-state { display:grid; justify-items:start; gap:var(--tbds-space-2); padding:var(--tbds-space-6); border:1px dashed var(--tbds-card-border); border-radius:var(--tbds-card-radius); background:var(--tbds-surface-muted); color:var(--tbds-text-muted); }
.tb-ui-empty > :first-child,.tb-ui-state > :first-child { margin:0; color:var(--tbds-text); font-weight:700; }.tb-ui-empty > :last-child,.tb-ui-state > :last-child { margin:0; }
.tb-ui-skeleton { border-radius:var(--tbds-radius-sm); background:linear-gradient(90deg,var(--tbds-surface-muted) 25%,color-mix(in srgb,var(--tbds-text) 7%,var(--tbds-surface-muted)) 50%,var(--tbds-surface-muted) 75%); background-size:220% 100%; animation:tb-ui-shimmer 1.45s linear infinite; }
@keyframes tb-ui-shimmer { to { background-position:-220% 0; } }

/* Low-cost visual polish: static layers supply depth and identity without a
   paint-heavy animated background.  Operational content remains dominant. */
.tb-ui :is(.form-card,.table-card,.info-card,.page-card,.settings-overview-group) {
  background-image:linear-gradient(145deg,color-mix(in srgb,var(--tbds-primary) 4%,transparent),transparent 38%);
}
.tb-ui :is(.settings-overview-hero,.db-hero,.mw-hero) {
  background-image:
    radial-gradient(circle at 90% 12%,color-mix(in srgb,var(--tbds-primary) 18%,transparent) 0 2px,transparent 2.5px),
    radial-gradient(circle at 90% 12%,color-mix(in srgb,var(--tbds-primary) 10%,transparent) 0 64px,transparent 65px),
    linear-gradient(135deg,color-mix(in srgb,var(--tbds-primary) 11%,var(--tbds-surface)),var(--tbds-surface));
  background-size:18px 18px,auto,auto;
}
@media (hover:hover) and (pointer:fine) {
  .tb-ui :is(.settings-overview-card,.tb-ui-panel,.form-card,.table-card):hover { box-shadow:var(--tbds-shadow-md); }
}
@media (max-width:767px) { .tb-ui-panel--padded { padding:var(--tbds-space-4); }.tb-ui-empty,.tb-ui-state { padding:var(--tbds-space-5); } }
@media (prefers-reduced-motion:reduce) { .tb-ui *,.tb-ui *::before,.tb-ui *::after { scroll-behavior:auto!important; transition-duration:1ms!important; animation-duration:1ms!important; animation-iteration-count:1!important; } }

/* CRM order card: old pastel labels were designed against a dark panel. Keep
   their meaning in the light theme, but use accessible foreground colours. */
html[data-theme="light"] .order-detail-redesign .status-new,
html[data-theme="light"] .order-detail-redesign .client-characteristic-chip.is-normal,
html[data-theme="light"] .order-detail-redesign .history-comment-file-chip { color:#3730a3; }
html[data-theme="light"] .order-detail-redesign :is(.status-in_progress,.status-in_work,.status-reschedule) { color:#854d0e; }
html[data-theme="light"] .order-detail-redesign :is(.status-on_the_way,.timeline-comment-file-link) { color:#1d4ed8; }
html[data-theme="light"] .order-detail-redesign :is(.status-on_site,.status-arrived,.status-accepted,.status-offered,.status-ready,.status-completed,.status-paid) { color:#166534; }
html[data-theme="light"] .order-detail-redesign :is(.status-sd,.status-pending) { color:#6d28d9; }
html[data-theme="light"] .order-detail-redesign :is(.status-cancelled,.status-cancelled_pvm,.status-declined) { color:#b91c1c; }
html[data-theme="light"] .order-detail-redesign .timeline-title { color:var(--tbds-text); }
html[data-theme="light"] .order-detail-redesign .dropdown-item:hover,
html[data-theme="light"] .order-detail-redesign .dropdown-item:focus { color:#1e40af; }

/* A report is an operational form, so its light version must not retain any
   dark-only text or controls.  This also covers legacy inline result values. */
html[data-theme="light"] .report-modal-dialog :is(.rm-file-input,.rm-btn-secondary) { color:#334155; border-color:#cbd5e1; background:#f8fafc; }
html[data-theme="light"] .report-modal-dialog :is(.rm-file-input,.rm-btn-secondary):hover { color:#0f172a; border-color:#94a3b8; background:#f1f5f9; }
html[data-theme="light"] .report-modal-dialog .rm-section-body [style*="color"] { color:#111827 !important; }

/* Dashboard: light theme needs real surfaces and readable operational tags,
   not dark-mode translucent text pasted onto a white canvas. */
html[data-theme="light"] .db :is(.db-hero,.db-workday,.db-card,.db-toolbar) {
  background:var(--tbds-surface);
  border-color:var(--tbds-border);
  box-shadow:var(--tbds-shadow-sm);
}
html[data-theme="light"] .db :is(.db-eyebrow,.db-chip:hover) { color:#475569; }
html[data-theme="light"] .db :is(.db-stag.arrived,.db-stag.active,.db-stag.paid,.db-mbadge.active,.db-load-state.free) { color:#166534; }
html[data-theme="light"] .db :is(.db-stag.wait,.db-mbadge.idle,.db-load-state.busy) { color:#854d0e; }
html[data-theme="light"] .db :is(.db-stag.sd,.db-stag.new) { color:#5b21b6; }
html[data-theme="light"] .db :is(.db-no-master-tag,.db-mbadge.risk,.db-load-state.full) { color:#b91c1c; }

/* Orders are the primary mobile work queue.  The template intentionally keeps
   most panels transparent, so only the actionable state labels need an
   explicit light-theme foreground to avoid dark-mode pastel text on white. */
html[data-theme="light"] .orders-page .orders-next-action { color:#1d4ed8; }
html[data-theme="light"] .orders-page .orders-next-action.is-urgent { color:#b91c1c; }
html[data-theme="light"] .orders-page .orders-next-action.is-warning { color:#854d0e; }
html[data-theme="light"] .orders-page .orders-next-action.is-success { color:#166534; }
html[data-theme="light"] .orders-page :is(.order-review-badge.is-reviewable,.kcard-readiness.is-warning) { color:#9a3412; }
html[data-theme="light"] .orders-page :is(.order-review-badge.is-non-reviewable,.kcard-readiness.is-success) { color:#166534; }
html[data-theme="light"] .orders-page .kcard-readiness.is-urgent { color:#b91c1c; }
html[data-theme="light"] .orders-page .orders-bulk-bar {
  border-color:#bfdbfe;
  box-shadow:var(--tbds-shadow-md);
  color:var(--tbds-text);
}
html[data-theme="light"] .orders-page :is(.orders-check-trigger,.orders-filter-preset-btn,.orders-view-chip:hover) {
  color:#334155;
  background:#fff;
  border-color:#cbd5e1;
}

/* The stand-alone service-centre order card predates the shared theme.  Its
   nested work, history and document panels must follow the surrounding light
   surface as well, otherwise the page turns into a patchwork of dark blocks. */
html[data-theme="light"] .scd-shell :is(.scd-card,.scd-line-item,.scd-event,.scd-line-kv-item) {
  background:var(--tbds-surface-muted);
  border-color:var(--tbds-border);
  color:var(--tbds-text);
}
html[data-theme="light"] .scd-shell :is(.scd-line-title,.scd-line-kv-item strong) { color:var(--tbds-text); }
html[data-theme="light"] .scd-shell :is(.scd-line-sub,.scd-finance-breakdown .scd-stat-card p,.scd-event .text-muted) { color:var(--tbds-text-muted)!important; }
html[data-theme="light"] .scd-shell .scd-file-item img { background:var(--tbds-slate-100); border-color:var(--tbds-border); }
html[data-theme="light"] .scd-shell .scd-badge.status-theme-new { color:#1d4ed8; }
html[data-theme="light"] .scd-shell .scd-badge.status-theme-diagnostic { color:#6d28d9; }
html[data-theme="light"] .scd-shell .scd-badge.status-theme-info { color:#0e7490; }
html[data-theme="light"] .scd-shell :is(.scd-badge.status-theme-pending,.scd-badge.status-theme-warning) { color:#854d0e; }
html[data-theme="light"] .scd-shell .scd-badge.status-theme-success { color:#166534; }
html[data-theme="light"] .scd-shell .scd-badge.status-theme-danger { color:#b91c1c; }

/* Anchored actions must remain reachable after a mobile navigation bar. */
@media (max-width:767.98px) {
  body[data-tbos-module="crm"] :where(.page-head,.section-head,[id]) { scroll-margin-top:12px; }
  body[data-tbos-module="crm"] .order-detail-redesign .report-modal-dialog { padding-bottom:max(16px,env(safe-area-inset-bottom,0px)); }

  /* Compact service forms: keep the confirmation action visible above the
     mobile navigation without making the entire form artificially sticky. */
  .tb-ui .city-form-actions {
    position:sticky;
    bottom:calc(76px + env(safe-area-inset-bottom,0px));
    z-index:4;
    margin-inline:-.35rem;
    padding:.75rem .35rem calc(.15rem + env(safe-area-inset-bottom,0px));
    background:color-mix(in srgb,var(--tbds-canvas) 90%,transparent);
    backdrop-filter:blur(10px);
  }
  .tb-ui .city-form-actions > :is(button,.btn) { flex:1 1 10rem; }
  .tb-ui .city-finance-section { padding:1rem!important; }
  .tb-ui :is(.compensation-actions,.completed-orders-actions) {
    position:sticky;
    bottom:calc(76px + env(safe-area-inset-bottom,0px));
    z-index:4;
    margin-inline:-.35rem;
    padding:.75rem .35rem calc(.15rem + env(safe-area-inset-bottom,0px));
    background:color-mix(in srgb,var(--tbds-canvas) 90%,transparent);
    backdrop-filter:blur(10px);
  }
  .tb-ui :is(.compensation-actions,.completed-orders-actions) > :is(button,.btn) { flex:1 1 12rem; }
  .tb-ui :is(.bot-settings-actions,.voice-intake-actions) {
    position:sticky;
    bottom:calc(76px + env(safe-area-inset-bottom,0px));
    z-index:4;
    margin-inline:-.35rem;
    padding:.75rem .35rem calc(.15rem + env(safe-area-inset-bottom,0px));
    background:color-mix(in srgb,var(--tbds-canvas) 90%,transparent);
    backdrop-filter:blur(10px);
  }
  .tb-ui :is(.bot-settings-actions,.voice-intake-actions) > :is(button,.btn) { flex:1 1 12rem; }
  .tb-ui .finance-settings-actions {
    position:sticky;
    bottom:calc(76px + env(safe-area-inset-bottom,0px));
    z-index:4;
    margin-inline:-.35rem;
    padding:.75rem .35rem calc(.15rem + env(safe-area-inset-bottom,0px));
    background:color-mix(in srgb,var(--tbds-canvas) 90%,transparent);
    backdrop-filter:blur(10px);
  }
  .tb-ui .finance-settings-actions > :is(button,.btn) { flex:1 1 12rem; }
  .tb-ui :is(.msc-actions,.motivation-posts-actions) {
    position:sticky;
    bottom:calc(76px + env(safe-area-inset-bottom,0px));
    z-index:4;
    margin-inline:-.35rem;
    padding:.75rem .35rem calc(.15rem + env(safe-area-inset-bottom,0px));
    background:color-mix(in srgb,var(--tbds-canvas) 90%,transparent);
    backdrop-filter:blur(10px);
  }
  .tb-ui :is(.msc-actions,.motivation-posts-actions) > :is(button,.btn) { flex:1 1 12rem; }
  .tb-ui [data-finance-table] .table-responsive { overflow:visible; }
  .tb-ui [data-finance-table] table,
  .tb-ui [data-finance-table] tbody,
  .tb-ui [data-finance-table] tr,
  .tb-ui [data-finance-table] td { display:block; width:100%; }
  .tb-ui [data-finance-table] thead { position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0 0 0 0); clip-path:inset(50%); white-space:nowrap; }
  .tb-ui [data-finance-table] tbody { display:grid; gap:.75rem; }
  .tb-ui [data-finance-table] tbody tr { border:1px solid var(--tbds-border); border-radius:var(--tbds-radius-lg); background:var(--tbds-surface); box-shadow:var(--tbds-shadow-sm); padding:.35rem 1rem; }
  .tb-ui [data-finance-table] tbody td { display:grid; grid-template-columns:minmax(8.5rem,.9fr) minmax(0,1.1fr); gap:.75rem; align-items:center; min-width:0; padding:.58rem 0; border:0; color:var(--tbds-text); overflow-wrap:anywhere; }
  .tb-ui [data-finance-table] tbody td + td { border-top:1px solid color-mix(in srgb,var(--tbds-border) 72%,transparent); }
  .tb-ui [data-finance-table] tbody td::before { content:attr(data-finance-label); color:var(--tbds-text-muted); font-size:.72rem; font-weight:700; }
  .tb-ui [data-finance-table] .form-check-input { justify-self:start; min-width:1.25rem; min-height:1.25rem; margin:0; }

  /* City settings contain eight desktop columns.  On phones the same record
     becomes a labelled card, avoiding a fragile horizontal-table workflow. */
  .tb-ui [data-city-list] .table-responsive { overflow:visible; }
  .tb-ui [data-city-list] table,
  .tb-ui [data-city-list] tbody,
  .tb-ui [data-city-list] tr,
  .tb-ui [data-city-list] td { display:block; width:100%; }
  .tb-ui [data-city-list] thead { position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0 0 0 0); clip-path:inset(50%); white-space:nowrap; }
  .tb-ui [data-city-list] tbody { display:grid; gap:.75rem; padding:.75rem; }
  .tb-ui [data-city-list] tbody tr { border:1px solid var(--tbds-border); border-radius:var(--tbds-radius-lg); background:var(--tbds-surface); box-shadow:var(--tbds-shadow-sm); padding:.35rem 1rem; }
  .tb-ui [data-city-list] tbody td { display:grid; grid-template-columns:minmax(7.5rem,.8fr) minmax(0,1.2fr); gap:.5rem; align-items:start; min-width:0; padding:.58rem 0; border:0; color:var(--tbds-text); overflow-wrap:anywhere; }
  .tb-ui [data-city-list] tbody td + td { border-top:1px solid color-mix(in srgb,var(--tbds-border) 72%,transparent); }
  .tb-ui [data-city-list] tbody td::before { content:attr(data-city-label); color:var(--tbds-text-muted); font-size:.72rem; font-weight:700; }
  .tb-ui [data-city-list] tbody td.text-end { text-align:start!important; }
  .tb-ui [data-city-list] tbody td.text-end .btn { width:100%; }
  .tb-ui [data-city-list] tbody td[colspan] { display:block; text-align:center; }
  .tb-ui [data-city-list] tbody td[colspan]::before { content:none; }
}
