/* ==========================================================================
   Components
   Staff components that Bootstrap does not provide, shared by templates
   across pages: the deadline chip, the page header, empty states, lists, feeds,
   KPI tiles. Tokens come from tokens.css; restyles of Bootstrap classes
   belong in bootstrap-theme.css, the app frame in shell.css.
   ========================================================================== */

/* ==========================================================================
   The deadline chip
   ========================================================================== */

/* Deadline chip — the single time-pressure signal shared by the service list,
   detail and dashboard (services/partials/deadline_chip.html). Icon + date +
   optional qualifier; coloured by proximity via the semantic status tokens
   (--deadline-chip--overdue == danger, --warning == due today/within 2 days,
   --neutral otherwise). Proximity is classified in service_extras.py. */
.deadline-chip {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 var(--space-1);
  padding: var(--space-1) var(--space-2);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  line-height: 1.2;
  border-radius: var(--radius-md);
  max-width: 100%;
}

.deadline-chip__date {
  white-space: nowrap;
}

.deadline-chip__icon {
  font-size: 0.85em;
  line-height: 1;
}

.deadline-chip__qualifier {
  font-weight: var(--font-weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.deadline-chip--neutral {
  background: var(--color-status-neutral-bg);
  color: var(--color-status-neutral-text);
}

.deadline-chip--warning {
  background: var(--color-status-warning-bg);
  color: var(--color-status-warning-text);
}

.deadline-chip--overdue {
  background: var(--color-status-danger-bg);
  color: var(--color-status-danger-text);
}

/* Screen reader only content */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   Empty State Component
   Shared empty-state pattern for list pages with no data.
   ========================================================================== */

.empty-state {
    text-align: center;
    padding: var(--space-12, 3rem) var(--space-4, 1rem);
}

.empty-state-icon {
    font-size: 3rem;
    color: var(--text-tertiary);
    opacity: 0.4;
    margin-bottom: var(--space-4, 1rem);
}

.empty-state-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--space-2, 0.5rem);
}

.empty-state-description {
    color: var(--text-tertiary);
    font-size: var(--font-size-sm);
    max-width: 400px;
    margin: 0 auto var(--space-4, 1rem);
}

.empty-state-actions {
    display: flex;
    gap: var(--space-2, 0.5rem);
    justify-content: center;
}

/* Inline: one muted line inside a card, lane or panel. No side padding, so it
   lines up with the rest of a card body; a host without its own inset (a
   dashboard card, a capacity row) adds it in its page sheet. */
.empty-state--inline {
    display: flex;
    align-items: baseline;
    gap: var(--space-2);
    padding: var(--space-3) 0;
    text-align: start;
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

.empty-state--inline .empty-state-icon {
    flex: 0 0 auto;
    margin: 0;
    font-size: inherit;
    opacity: 1;
    color: var(--text-tertiary);
}

.empty-state-text {
    margin: 0;
}

.empty-state-text strong {
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
}

/* ==========================================================================
   Page Header Component
   Rendered by base.html from the page_* blocks: an optional back link,
   the title with an optional badge beside it, a subtitle, and actions.
   ========================================================================== */

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-4, 1rem);
    margin-bottom: var(--space-6, 1.5rem);
}

.page-header-content {
    flex: 1;
    min-width: 0;
}

.page-header-back {
    margin-bottom: var(--space-1, 0.25rem);
}

.page-header-heading {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-2, 0.5rem);
    margin-bottom: var(--space-1, 0.25rem);
}

.page-header-title {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-black);
    margin: 0;
    line-height: var(--line-height-tight);
    overflow-wrap: break-word;
}

.page-header-subtitle {
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    margin: 0;
}

.page-header-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2, 0.5rem);
    flex-shrink: 0;
    /* Alone on its line, the group still must not outgrow the page: capped, its buttons wrap. */
    max-width: 100%;
}

@media (max-width: 767px) {
    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .page-header-actions {
        width: 100%;
    }
}


/* ==========================================================================
   Avatar
   Circular initials/photo bubble. Default 28px (navbar size), with --sm
   and --lg variants for list rows and detail pages.
   ========================================================================== */

.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-full);
    background: var(--color-brand-light);
    color: var(--text-brand);
    font-size: 11px;
    font-weight: var(--font-weight-bold);
    line-height: 1;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    overflow: hidden;
    flex-shrink: 0;
    user-select: none;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ==========================================================================
   Touch Target Utility
   ========================================================================== */

/* The 44px tap-target floor (WCAG 2.5.8 AA asks for 24px). -mobile applies it
   below 992px only, for btn-sm controls that stay compact on a desktop: the
   staff UI has no phone-only breakpoint, so tablets get it too. */
.tap-target {
  min-height: 44px;
  min-width: 44px;
}

@media (max-width: 991.98px) {
  .tap-target-mobile {
    min-height: 44px;
    min-width: 44px;
  }
}

/* ==========================================================================
   Utilities Bootstrap does not ship
   ========================================================================== */

/* Keeps the line breaks of user-entered text. */
.text-pre-wrap {
  white-space: pre-wrap;
}

/* Micro type below .small, for feed meta, chip labels and inline icons. */
.fs-xs {
  font-size: var(--font-size-xs);
}

.fs-2xs {
  font-size: 0.7rem;
}

.fs-3xs {
  font-size: 0.65rem;
}

.fs-4xs {
  font-size: 0.6rem;
}

/* ==========================================================================
   Toolbar
   The one filter / view bar above a list or a planning body. No chrome: it
   is a row of labelled controls, not a card.

     <form class="toolbar" role="search">            (or a div)
       <div class="toolbar__field toolbar__field--grow">
         <label class="form-label">…</label> <input class="form-control">
       </div>
       <div class="toolbar__field toolbar__field--switch">form-switch</div>
       components/toolbar_actions.html (Search + Clear, after the fields)
       <div class="toolbar__end">pinned right: a week navigator, a view
         switch…</div>
     </form>

   Controls keep Bootstrap's default size so a pillbox lines up with a native
   select. `.toolbar__summary` is a result count read beside the controls.
   `.toolbar--collapsible` + components/toolbar_toggle.html fold every field
   but the `--primary` one behind a button below 992px (static/js/toolbar.js).
   ========================================================================== */

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.toolbar__field {
    flex: 0 1 13rem;
    min-width: 9rem;
}

.toolbar__field--grow { flex: 1 1 16rem; }

/* Keeps From / To date inputs paired on the same row instead of splitting
   across lines when the toolbar wraps. */
.toolbar__date-pair {
    display: flex;
    gap: var(--space-2);
    flex: 0 1 22rem;
    min-width: 17rem;
}

.toolbar__date-pair > .toolbar__field {
    flex: 1 1 0;
    min-width: 8rem;
}

/* A switch has no label above it: centre it on the controls' row. */
.toolbar__field--switch {
    flex: 0 0 auto;
    min-width: 0;
    padding-bottom: var(--space-2);
}

.toolbar__summary {
    align-self: center;
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
}

.toolbar__actions {
    display: flex;
    gap: var(--space-2);
}

.toolbar__end {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--space-2);
    margin-inline-start: auto;
}

.toolbar__toggle { display: none; }

.toolbar__chevron { transition: transform var(--transition-fast); }

@media (max-width: 991.98px) {
    .toolbar__field { flex-grow: 1; }

    .toolbar--collapsible .toolbar__toggle {
        display: block;
        flex: 1 1 100%;
    }

    /* `.toolbar__end` (a week navigator) stays visible, as on the Planning views that do not fold. */
    .toolbar--collapsible:not(.is-open) > :not(.toolbar__toggle, .toolbar__field--primary, .toolbar__end) {
        display: none;
    }

    .toolbar--collapsible .toolbar__field--primary { flex-basis: 100%; }

    .toolbar.is-open .toolbar__chevron { transform: rotate(180deg); }

    .toolbar__toggle-button { min-height: 44px; }

    /* The summary must not push the chevron off the button. */
    .toolbar__toggle-summary { max-width: 55%; }
}

@media print {
    .toolbar { display: none; }
}

/* ==========================================================================
   Week navigator (components/week_nav.html)
   A Bootstrap button group (previous, today, next) and the week's range.
   ========================================================================== */

.week-nav {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
}

.week-nav__label {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
    white-space: nowrap;
}

/* ==========================================================================
   Segmented control
   A Bootstrap .btn-group.segmented of .btn-outline-secondary:
   - a view held in page state: input.btn-check radios, each with its label.btn;
   - a view that is its own URL: a.btn links, the current one .active with
     aria-current="page".
   Quiet at rest; the selected segment takes the subtle primary fill.
   ========================================================================== */

.segmented > .btn {
    --bs-btn-color: var(--bs-secondary-color);
    --bs-btn-border-color: var(--bs-border-color);
    --bs-btn-hover-color: var(--bs-emphasis-color);
    --bs-btn-hover-bg: var(--bs-tertiary-bg);
    --bs-btn-hover-border-color: var(--bs-border-color);
    --bs-btn-active-color: var(--bs-primary-text-emphasis);
    --bs-btn-active-bg: var(--bs-primary-bg-subtle);
    --bs-btn-active-border-color: var(--bs-primary-border-subtle);
}

/* ==========================================================================
   Services Table View
   ========================================================================== */

.services-table-container {
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.services-table {
    margin-bottom: 0;
    font-size: var(--font-size-sm);
}

.services-table-header {
    background: var(--bg-tertiary);
}

/* Typography comes from the global `.table thead th` eyebrow rule. */
.services-table-header th {
    border: none;
    border-bottom: 1px solid var(--border-color);
    padding: var(--space-3);
    vertical-align: middle;
}

.services-table-header .sortable {
    cursor: pointer;
    user-select: none;
}

.services-table-header .sortable:hover {
    color: var(--text-primary);
    background: var(--bg-secondary);
}

.services-table-header .sort-icon {
    font-size: 0.65rem;
    opacity: 0.4;
    transition: all var(--transition-fast);
}

.services-table-header .sortable:hover .sort-icon {
    opacity: 0.8;
}

.services-table-header .sortable.sorted-asc,
.services-table-header .sortable.sorted-desc {
    color: var(--text-primary);
    background: var(--bg-secondary);
}

.services-table-header .sortable.sorted-asc .sort-icon,
.services-table-header .sortable.sorted-desc .sort-icon {
    opacity: 1;
    color: var(--color-primary);
}

.services-table-header .sortable[aria-sort="ascending"] .sort-icon {
    transform: rotate(0deg);
}

.services-table-header .sortable[aria-sort="descending"] .sort-icon {
    transform: rotate(180deg);
}

.services-table-header .sortable:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
}

.services-table td {
    padding: var(--space-3);
    vertical-align: middle;
    border: none;
}

.service-id-cell {
    font-weight: var(--font-weight-semibold);
    min-width: 80px;
}

.contact-phone {
    color: var(--text-tertiary);
    font-size: 0.75rem;
}

.professional-name {
    color: var(--text-primary);
    font-weight: var(--font-weight-medium);
}

/* Responsive table behavior. The old per-column hide classes
   (.created-col/.task-col/.address-cell etc.) were dropped with the retired
   service card/table view; the ticket list — the remaining .services-table
   consumer — hides its columns with Bootstrap .d-none utilities. */
@media (max-width: 767px) {
    .services-table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .services-table td {
        padding: var(--space-2);
    }
}

@media (max-width: 575px) {
    .services-table-container {
        border-radius: var(--radius-md);
    }

    .services-table th,
    .services-table td {
        padding: var(--space-2);
    }
}


/* ==========================================================================
   Checklist / Markdown Checkboxes
   ========================================================================== */

.checklist {
    list-style: none;
    padding-left: 0;
    margin: 0.25rem 0;
}

.checklist-item {
    display: flex;
    align-items: flex-start;
    padding: 0.2rem 0;
}

.checklist-item label {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    cursor: pointer;
    margin: 0;
}

.checklist-item input[type="checkbox"] {
    margin-top: 0.2rem;
    cursor: pointer;
    flex-shrink: 0;
}

.checklist-item.checked span {
    text-decoration: line-through;
    opacity: 0.6;
}

.form-actions {
    display: flex;
    gap: var(--space-3);
    justify-content: flex-end;
    margin-top: var(--space-6);
    padding-top: var(--space-4);
    border-top: 1px solid var(--border-color);
}

@media (max-width: 768px) {
    .form-actions {
        flex-direction: column;
    }
}

/* A global restyle of a Bootstrap class, from a modal that no longer exists.
   The checker baselines both rules; removing them is a visual change. */
.form-check-label {
    cursor: pointer;
    padding: var(--space-2) 0;
    width: 100%;
}

.form-check-input:checked + .form-check-label {
    color: var(--color-primary);
}

/* ==========================================================================
   Media / Feed Components
   Shared thumbnails, picker toggles, and inline media used by the service
   feed (services/components/*) and the ticket media picker (core/components/*).
   ========================================================================== */

/* Fixed-size media thumbnail. Pair with Bootstrap .rounded .border; the size
   modifier sets the box, and images cover it. */
.media-thumb {
    object-fit: cover;
    flex-shrink: 0;
}
.media-thumb--lg { width: 80px; height: 80px; }  /* ticket media picker */
.media-thumb--md { width: 56px; height: 56px; }  /* service feed row */

/* Export selection row label. The min-width reset is what lets .text-truncate
   inside actually truncate — a flex item defaults to min-width:auto and grows
   past the row instead. */
.export-selection__label {
    min-width: 0;
    cursor: pointer;
}

/* Centered play glyph overlaid on a video thumbnail (pair with Bootstrap
   .position-absolute .top-50 .start-50 .translate-middle .text-white). */
.media-thumb__play {
    text-shadow: 0 0 4px rgba(0, 0, 0, 0.7);
    pointer-events: none;
}

/* Circular add/remove-from-ticket toggle pinned to a picker thumbnail (pair
   with Bootstrap .btn .position-absolute .top-0 .end-0 .p-0 .border-0). */
.media-toggle-check {
    width: 24px;
    height: 24px;
    margin: 2px;
    border-radius: 50%;
    line-height: 24px;
    font-size: 0.75rem;
    background: rgba(255, 255, 255, 0.85);
    color: #adb5bd;
}
.media-toggle-check.is-active {
    background: var(--bs-success, #198754);
    color: #fff;
}

/* Inline native audio player strip in feed rows and picker cells. */
.media-audio {
    height: 32px;
}

/* A document's file name under its picker thumbnail. */
.media-picker-filename { max-width: 80px; }

/* An attachment thumbnail in a message bubble. */
.message-attachment-thumb { max-width: 48px; max-height: 48px; }

/* A chosen image, previewed before upload. */
.upload-preview-thumb { max-width: 150px; max-height: 150px; }

/* Ticket media-picker cell and its context/meta line. */
.media-picker-cell { width: 120px; }
.media-picker-meta {
    font-size: 0.7rem;
    line-height: 1.2;
}

/* The media viewer modal (components/media_viewer.html). */
.media-viewer__stage { min-height: 200px; }
.media-viewer__media { max-height: 70vh; }
.media-viewer__nav {
    width: 40px;
    height: 40px;
    z-index: 1;
}

/* Preserve author line breaks in transcript / note text. */
.text-preline {
    white-space: pre-line;
}

/* ==========================================================================
   Customer Message Thread
   Chat thread + operator composer on the service-detail Communication card and
   the standalone communication history page (both render customer_message_row).
   Shared here — not in service_detail's page-scoped sd- block — because the row
   partial is used on both pages.
   ========================================================================== */

/* Scrollable live-poll thread wrapper (service_detail only; history paginates). */
.customer-message-thread {
    max-height: 360px;
    overflow-y: auto;
}

/* Chat bubble width cap. */
.message-bubble {
    max-width: 85%;
}

/* Inline photo/video attachment in a bubble. */
.message-media {
    max-width: 160px;
    max-height: 160px;
    object-fit: cover;
}

/* Message body: keep author line breaks, slightly smaller than base. */
.message-text {
    white-space: pre-line;
    font-size: 0.875rem;
}

/* Operator composer tap targets (services/components/message_composer.html). */
#message-composer-form .btn-group .btn,
#message-composer-form .form-select {
    min-height: 44px;
}
#message-composer-form textarea,
#message-composer-form button[type="submit"] {
    min-height: 48px;
}
#message-composer-form button[type="submit"] {
    min-width: 96px;
}

/* ==========================================================================
   Service list — one markup, two presentations
   Hoisted from service_list.html's inline <style> (chunk 3 left it inline for
   this consolidation). Mobile-first: base rules render every service as a
   stacked card; at >=992px the `.svc-list--table` modifier switches to aligned
   columns while `.svc-list--cards` keeps the card layout. Below 992px the
   modifier is ignored (cards only) and the Cards/Table toggle is hidden. The
   class is flipped client-side and persisted in localStorage — no `view=` param.
   ========================================================================== */

.svc-list__head { display: none; }

.svc-list__items {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(19rem, 1fr));
    gap: var(--space-4);
}

.svc-item {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-4);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: box-shadow var(--transition-fast), border-color var(--transition-fast);
}
.svc-item:hover { box-shadow: var(--shadow-md); border-color: var(--border-color-dark); }
.svc-item:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

.svc-cell { display: flex; gap: var(--space-2); align-items: baseline; min-width: 0; }
.svc-cell__value { min-width: 0; flex: 1; }

/* Card-mode row labels (from data-label); the table header carries them instead. */
.svc-cell[data-label]::before {
    content: attr(data-label);
    flex: 0 0 6.5rem;
    color: var(--text-tertiary);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding-top: 1px;
}

.svc-id { color: var(--text-primary); }
/* The address is the row's subject and carries the one fw-semibold; the task
   is supporting text. */
.svc-address-text { display: block; color: var(--text-primary); }
.svc-task-text { color: var(--text-secondary); }
.svc-duration { color: var(--text-secondary); font-size: var(--font-size-sm); }
.svc-age { color: var(--text-secondary); font-weight: var(--font-weight-semibold); }
.svc-cell--deadline .svc-cell__value {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1);
}

/* The row's time-pressure signal is the shared .deadline-chip component
   (above); with the status badge it is the only colour a row
   carries, and it folds in the old ACTIONS overdue triangle. */

/* Quiet row actions — neutral links; filled orange is reserved for New Service. */
.svc-action-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    text-decoration: none;
    white-space: nowrap;
}
.svc-action-link + .svc-action-link { margin-left: var(--space-3); }
.svc-action-link:hover { color: var(--color-primary); text-decoration: underline; }

/* ---- Card presentation (mobile) ----
   The label/value rows above are the tablet shape. Below 992px the card drops
   the label column entirely and lays the same cells out as a card: identity
   line, customer, when/how long, then the details. Two cells share each of the
   compact lines, so the cell order here is set by grid position, not the DOM.
   The service list overrides this with its own card (`.svc-list--services`
   below); the review and appointment lists still use this shape. */
@media (max-width: 991.98px) {
    .svc-item {
        display: grid;
        /* The right track is capped rather than auto-sized: the status cell's
           next-step hint is free text and would otherwise squeeze the id. */
        grid-template-columns: minmax(0, 1fr) minmax(0, 40%);
        column-gap: var(--space-3);
        row-gap: var(--space-1);
        align-items: start;
    }

    .svc-cell { display: block; }
    .svc-cell[data-label]::before { content: none; }

    /* Identity line, then the customer as the card's title. */
    .svc-cell--id { grid-area: 1 / 1; }
    /* The status cell carries the next-step hint under the badge; cap it so a
       long hint wraps instead of eating the id column. */
    .svc-cell--status {
        grid-area: 1 / 2;
        justify-self: end;
        text-align: right;
    }
    /* Location is the card's title, under the identity line. */
    .svc-cell--address { grid-area: 2 / 1 / auto / -1; }

    /* When + how long share a line; both are always rendered. */
    .svc-cell--appointment { grid-area: 3 / 1; }
    .svc-cell--duration { grid-area: 3 / 2; justify-self: end; }

    /* Everything after row 3 auto-places full width, in DOM order. */
    .svc-cell--professional,
    .svc-cell--task,
    .svc-cell--deadline,
    .svc-cell--actions { grid-column: 1 / -1; }

    .svc-id { font-size: var(--font-size-lg); }
    .svc-address-text { font-size: var(--font-size-base); }
    .svc-task-text { font-size: var(--font-size-sm); }

    /* These two links are the card's only actions — as bare text they were
       ~20px tall. Give them the 44px floor and split the row. */
    .svc-cell--actions {
        margin-top: var(--space-2);
    }
    .svc-cell--actions .svc-cell__value {
        display: flex;
        gap: var(--space-2);
    }
    .svc-action-link {
        flex: 1;
        justify-content: center;
        min-height: 44px;
        padding: 0 var(--space-3);
        border: 1px solid var(--border-color);
        border-radius: var(--radius-md);
    }
    .svc-action-link + .svc-action-link { margin-left: 0; }
}

/* ---- Service list card (service_results.html), every width ----
   Title (address) / subtitle (task) / status badge top-right / one meta line,
   no field labels: the card is the phone fallback of the table and reads like
   a row, not a form. The four meta cells sit in a `.svc-meta` wrapper that the
   table presentation flattens with `display: contents`. */
.svc-list--services .svc-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: var(--space-3);
    row-gap: var(--space-1);
    align-items: start;
}
.svc-list--services .svc-cell { display: block; }
.svc-list--services .svc-cell--service { grid-area: 1 / 1; }
.svc-list--services .svc-cell--status {
    grid-area: 1 / 2;
    justify-self: end;
    text-align: right;
}
.svc-list--services .svc-cell--address { grid-area: 2 / 1 / auto / -1; }
.svc-list--services .svc-meta,
.svc-list--services .svc-cell--actions { grid-column: 1 / -1; }

.svc-list--services .svc-task-text {
    font-size: var(--font-size-md);
    line-height: var(--line-height-tight);
    color: var(--text-primary);
}
.svc-list--services .svc-service-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem;
    margin-top: 2px;
    font-size: var(--font-size-meta);
    color: var(--text-secondary);
}
.svc-list--services .svc-id {
    /* Inherits the meta line's size; the card rule's font-size-lg would make
       the id larger than the task title. */
    font-size: inherit;
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
}
.svc-list--services .svc-meta-sep { color: var(--text-tertiary); }
.svc-list--services .svc-next-step {
    font-size: var(--font-size-meta);
    color: var(--text-secondary);
}
.svc-list--services .svc-address-text {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}
.svc-list--services .svc-appointment-stack,
.svc-list--services .svc-deadline-stack {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1) var(--space-2);
}
.svc-list--services .svc-duration {
    font-size: var(--font-size-meta);
    color: var(--text-secondary);
}

.svc-list--services .svc-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    column-gap: var(--space-2);
    row-gap: var(--space-1);
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}
.svc-list--services .svc-meta .svc-cell {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
}
/* An empty meta cell (no appointment) is dropped from the line rather than
   shown as a dash; the separator skips it too. Scoped under .svc-meta so it
   outranks the meta cells' inline-flex (a 0-wide flex item still takes a gap). */
.svc-list--services .svc-meta .svc-cell--empty { display: none; }
.svc-list--services .svc-meta .svc-cell:not(.svc-cell--empty) + .svc-cell::before {
    content: "\00b7";
    color: var(--text-tertiary);
}

/* The two actions are the card's only controls: quiet outline, 44px floor. */
.svc-list--services .svc-cell--actions { margin-top: var(--space-2); }
.svc-list--services .svc-cell--actions .svc-cell__value {
    display: flex;
    gap: var(--space-2);
}
.svc-list--services .svc-action-link {
    flex: 1;
    justify-content: center;
    min-height: 44px;
    padding: 0 var(--space-3);
    border: 1px solid var(--border-color-light);
    border-radius: var(--radius-md);
}
.svc-list--services .svc-action-link:hover {
    color: var(--text-primary);
    border-color: var(--border-color-dark);
    text-decoration: none;
}
.svc-list--services .svc-action-link + .svc-action-link { margin-left: 0; }

/* ---- Table presentation (desktop only) ---- */
@media (min-width: 992px) {
    /* The minimums must fit the narrowest table: at 992-1199px the
       .container leaves ~934px, so tracks + 6 gaps + padding + border stay
       under it (52.25rem = 836px of tracks; these floors sum to 50.75rem) or
       overflow:hidden clips the actions. Each floor is its column's widest
       unbreakable content (badges, chips, the header word plus sort icon) in
       English and Spanish; longer text wraps. test_service_list_table_fits.py
       measures it. */
    .svc-list--table {
        --svc-cols:
            minmax(12rem, 2.2fr)    /* service (task + #ID + customer + ref) */
            minmax(6.75rem, 0.85fr) /* status */
            minmax(6.5rem, 0.95fr)  /* appointment + duration */
            minmax(6rem, 0.95fr)    /* professional */
            minmax(6.5rem, 1.35fr)  /* address */
            minmax(6.5rem, 1fr)     /* age / deadline */
            minmax(6.5rem, 0.9fr);  /* actions */
        background: var(--bg-primary);
        border: 1px solid var(--border-color);
        border-radius: var(--radius-md);
        overflow: hidden;
    }

    .svc-list--table .svc-list__head,
    .svc-list--table .svc-item {
        display: grid;
        grid-template-columns: var(--svc-cols);
        gap: var(--space-3);
        align-items: center;
        padding: var(--space-3);
    }

    .svc-list--table .svc-list__head {
        background: var(--bg-tertiary);
        border-bottom: 1px solid var(--border-color);
        font-size: var(--font-size-xs);
        font-weight: var(--font-weight-semibold);
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: var(--text-secondary);
    }

    .svc-list--table .svc-list__items { display: block; }

    .svc-list--table .svc-item {
        flex-direction: initial;
        border: 0;
        border-bottom: 1px solid var(--border-color-light);
        border-radius: 0;
        box-shadow: none;
        background: transparent;
        font-size: var(--font-size-sm);
    }
    .svc-list--table .svc-item:last-child { border-bottom: 0; }
    .svc-list--table .svc-item:hover { box-shadow: none; background: var(--bg-secondary); }

    .svc-list--table .svc-cell {
        display: flex;
        align-items: center;
        grid-area: auto;
        text-align: left;
        justify-self: stretch;
    }
    .svc-list--table .svc-cell::before { content: none; }

    /* Undo the service-list card: the meta wrapper flattens into the row grid
       and the cells take the header's column order (the DOM is the card's
       reading order — subject first, then the meta line). */
    .svc-list--table .svc-meta { display: contents; }
    .svc-list--table .svc-meta .svc-cell { display: flex; gap: 0; }
    .svc-list--table .svc-meta .svc-cell:not(.svc-cell--empty) + .svc-cell::before { content: none; }
    /* An empty cell keeps its column and shows the table's "none" marker. */
    .svc-list--table .svc-cell--empty .svc-cell__value::before {
        content: "\2014";
        color: var(--text-tertiary);
    }
    /* Only the service list's DOM differs from its header order; the
       appointment and review lists already emit cells in header order. */
    .svc-list--table.svc-list--services .svc-cell--service { order: 1; }
    .svc-list--table.svc-list--services .svc-cell--status { order: 2; }
    .svc-list--table.svc-list--services .svc-cell--appointment { order: 3; }
    .svc-list--table.svc-list--services .svc-cell--professional { order: 4; }
    .svc-list--table.svc-list--services .svc-cell--address { order: 5; }
    .svc-list--table.svc-list--services .svc-cell--deadline { order: 6; }
    .svc-list--table.svc-list--services .svc-cell--actions { order: 7; }
    .svc-list--table .svc-cell--actions { margin-top: 0; }
    .svc-list--table .svc-cell--actions .svc-cell__value {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: var(--space-2);
    }
    .svc-list--table .svc-id,
    .svc-list--table .svc-task-text,
    .svc-list--table .svc-address-text { font-size: inherit; line-height: inherit; }
    .svc-list--table.svc-list--services .svc-task-text { font-size: var(--font-size-md); line-height: var(--line-height-tight); }
    .svc-list--table.svc-list--services .svc-address-text { font-size: var(--font-size-sm); }
    .svc-list--table .svc-action-link {
        flex: initial;
        min-height: 0;
        padding: 0;
        border: 0;
        border-radius: 0;
    }
    .svc-list--table .svc-action-link--schedule {
        padding: 0.2rem 0.55rem;
        border: 1px solid var(--border-color-dark);
        border-radius: var(--radius-sm);
        color: var(--text-primary);
        font-weight: var(--font-weight-semibold);
        font-size: var(--font-size-meta);
    }
    .svc-list--table .svc-action-link--schedule:hover {
        background: var(--bg-tertiary);
        color: var(--text-primary);
        text-decoration: none;
    }
    .svc-list--table .svc-action-link:hover { color: var(--color-primary); text-decoration: underline; }
    .svc-list--table .svc-action-link + .svc-action-link { margin-left: 0; }

    /* Sortable header controls (header row is hidden below 992px). The
       control is a real <button> (sort_header.html), reset to read as the
       header text it replaced. */
    .svc-list--table .svc-col { display: inline-flex; align-items: center; gap: var(--space-2); }
    .svc-list--table .sortable {
        display: inline-flex;
        align-items: center;
        gap: var(--space-2);
        padding: 0;
        margin: 0;
        border: 0;
        background: none;
        font: inherit;
        color: inherit;
        text-align: inherit;
        text-transform: inherit;
        letter-spacing: inherit;
        cursor: pointer;
        user-select: none;
    }
    .svc-list--table .sortable:hover { color: var(--text-primary); }
    .svc-list--table .sort-icon { font-size: 0.65rem; opacity: 0.4; transition: opacity var(--transition-fast); }
    .svc-list--table .sortable:hover .sort-icon { opacity: 0.8; }
    .svc-list--table .sortable.sorted-asc,
    .svc-list--table .sortable.sorted-desc { color: var(--text-primary); }
    .svc-list--table .sortable.sorted-asc .sort-icon,
    .svc-list--table .sortable.sorted-desc .sort-icon { opacity: 1; color: var(--color-primary); }
    .svc-list--table .sortable:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
}

/* Review queue service-list variant. */
.review-reason-line { display: flex; align-items: flex-start; gap: var(--space-2); margin-top: var(--space-1); }

@media (min-width: 992px) {
    .svc-list--table.review-list { --svc-cols: minmax(8rem, 1.1fr) minmax(6.75rem, .75fr) minmax(8rem, 1fr) minmax(11rem, 1.6fr) minmax(7rem, .9fr) minmax(5rem, .6fr) minmax(8rem, .85fr); }
    .svc-list--table.review-list .svc-cell--professional { display: flex; }
}
@media (max-width: 991.98px) {
    .review-list .svc-cell--client, .review-list .svc-cell--reason, .review-list .svc-cell--professional, .review-list .svc-cell--updated { grid-column: 1 / -1; }
}

/* ==========================================================================
   Appointment list — the `.svc-list` shape with appointment columns
   The appointment list reuses every rule above; only the column tracks and
   the card-mode cell placement differ, because it shows different fields.
   The professional column needs no override: every `.svc-list` table shows it.
   ========================================================================== */

@media (min-width: 992px) {
    .svc-list--table.apt-list {
        --svc-cols:
            minmax(6rem, 0.8fr)    /* when */
            minmax(7.5rem, 0.8fr)  /* status (widest Spanish badge) */
            minmax(7.75rem, 0.8fr) /* field status (widest Spanish badge) */
            minmax(7rem, 1fr)      /* professional */
            minmax(8rem, 1.2fr)    /* service */
            minmax(8rem, 1.3fr)    /* address */
            minmax(5rem, 0.7fr);   /* actions */
    }
}

@media (max-width: 991.98px) {
    /* Card shape: when + status headline, field status and professional on the
       second line, then service, address and the actions row full width. */
    .apt-list .svc-cell--when { grid-area: 1 / 1; }
    .apt-list .svc-cell--status {
        grid-area: 1 / 2;
        justify-self: end;
        text-align: right;
    }
    .apt-list .svc-cell--professional { grid-area: 2 / 1; }
    .apt-list .svc-cell--field-status {
        grid-area: 2 / 2;
        justify-self: end;
        text-align: right;
    }
    /* Rows are explicit: the base rule puts the address on row 2, which here
       belongs to the professional and the field status. */
    .apt-list .svc-cell--service { grid-area: 3 / 1 / auto / -1; }
    .apt-list .svc-cell--address { grid-area: 4 / 1 / auto / -1; }
    .apt-list .svc-cell--actions { grid-area: 5 / 1 / auto / -1; }

    .apt-list .apt-when { font-size: var(--font-size-lg); }
}

/* ==========================================================================
   KPI Card (components/kpi_card.html)
   Card with a 4px left accent bar, an icon tile and a large number.
   Lives here, not in a page stylesheet, because the component is included
   from several pages.
   ========================================================================== */

.kpi-card-accent {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--color-brand);
    border-radius: var(--radius-md);
    padding: var(--space-4) var(--space-5, 1.25rem);
    text-decoration: none;
    color: inherit;
    transition: all var(--transition-normal);
    height: 100%;
}

/* Only a linked card lifts: a lift on a plain card promises a click. */
a.kpi-card-accent:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    text-decoration: none;
    color: inherit;
}

.kpi-card-accent:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

.kpi-card-accent__icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-xl);
    flex-shrink: 0;
}

.kpi-card-accent__body {
    min-width: 0;
}

.kpi-card-accent__value {
    font-size: var(--font-size-3xl);
    font-weight: var(--font-weight-black);
    line-height: 1;
    color: var(--text-primary);
}

.kpi-card-accent__label {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-extrabold);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-top: var(--space-1);
}

.kpi-card-accent__subtitle {
    font-size: var(--font-size-xs);
    color: var(--text-tertiary);
    margin-top: var(--space-1);
}

/* Compact: a strip of tiles above a list or beside a map. A long Spanish
   label wraps rather than overflows a narrow tile. */
.kpi-card-accent--compact {
    gap: var(--space-3);
    padding: var(--space-3);
}

.kpi-card-accent--compact .kpi-card-accent__icon {
    width: 36px;
    height: 36px;
    font-size: var(--font-size-sm);
}

.kpi-card-accent--compact .kpi-card-accent__value {
    font-size: var(--font-size-2xl);
}

.kpi-card-accent--compact .kpi-card-accent__label {
    overflow-wrap: anywhere;
}

.kpi-card-accent.orange {
    border-left-color: var(--color-brand);
}

.kpi-card-accent.orange .kpi-card-accent__icon {
    background: var(--color-brand-light);
    color: var(--text-brand);
}

.kpi-card-accent.amber {
    border-left-color: var(--color-warning);
}

.kpi-card-accent.amber .kpi-card-accent__icon {
    background: var(--color-status-warning-bg);
    color: var(--color-status-warning-text);
}

.kpi-card-accent.blue {
    border-left-color: var(--color-info);
}

.kpi-card-accent.blue .kpi-card-accent__icon {
    background: var(--color-status-info-bg);
    color: var(--color-status-info-text);
}

.kpi-card-accent.green {
    border-left-color: var(--color-success);
}

.kpi-card-accent.green .kpi-card-accent__icon {
    background: var(--color-status-success-bg);
    color: var(--color-status-success-text);
}

.kpi-card-accent.red {
    border-left-color: var(--color-danger);
}

.kpi-card-accent.red .kpi-card-accent__icon {
    background: var(--color-status-danger-bg);
    color: var(--color-status-danger-text);
}

[data-bs-theme="dark"] {
    .kpi-card-accent {
        background: var(--bg-secondary);
    }
}

@media (max-width: 575.98px) {
    .kpi-card-accent {
        padding: var(--space-3);
    }

    .kpi-card-accent__icon {
        width: 36px;
        height: 36px;
        font-size: var(--font-size-sm);
    }

    .kpi-card-accent__value,
    .kpi-card-accent--compact .kpi-card-accent__value {
        font-size: var(--font-size-xl);
    }

    .kpi-card-accent__label {
        font-size: 0.625rem;
    }

    .kpi-card-accent__subtitle {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .kpi-card-accent {
        transition: none;
    }

    a.kpi-card-accent:hover {
        transform: none;
    }
}
