/* The Schedule tab (public/admin/scheduleUi.js). Uses the Command Center's own colors (inbox.html :root). */
#scheduleModule {
  display: block;
  position: relative;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 12px 16px calc(96px + env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
}

.sch-toolbar { display: grid; gap: 8px; margin-bottom: 8px; }
.sch-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
.sch-row .button, .sch-view { min-height: 40px; }
.sch-step { min-width: 40px; padding: 0 10px; font-size: 20px; line-height: 1; }
.sch-range { position: relative; display: inline-flex; align-items: center; min-height: 40px; padding: 0 6px; font-weight: 650; cursor: pointer; min-width: 0; }
.sch-range-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sch-date-input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }
.sch-tools { display: flex; gap: 8px; margin-left: auto; }
.sch-filter-button.sch-on { border-color: var(--accent); color: var(--accent-dark); background: var(--accent-soft); }
.sch-views { display: flex; flex-wrap: wrap; gap: 4px; padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.sch-view { border: 0; background: transparent; color: var(--text); padding: 0 12px; border-radius: 8px; font: inherit; font-size: 14px; cursor: pointer; }
.sch-view.sch-active { background: var(--accent); color: #fff; font-weight: 650; }
.sch-search { flex: 1 1 200px; min-width: 0; min-height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: var(--panel); color: var(--text); }
.sch-status { margin: 0 0 6px; min-height: 18px; color: var(--muted); font-size: 13px; }
.sch-note { margin: 0 0 8px; padding: 8px 12px; border-radius: 8px; background: var(--new); color: var(--text); font-size: 14px; line-height: 1.35; }
.sch-sunday-note { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.sch-sunday-note .button { min-height: 44px; }
.sch-error { color: var(--warn); }
.sch-ok { color: var(--accent-dark); }
.sch-empty { margin: 8px 0; color: var(--muted); }

/* Schedule list: weekday and date on the left, a card per booking. */
.sch-list { display: grid; gap: 4px; }
.sch-day { display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.sch-day-label { display: grid; justify-items: center; align-content: start; gap: 0; color: var(--muted); }
.sch-day-week { font-size: 13px; text-transform: uppercase; letter-spacing: .03em; }
.sch-day-num { font-size: 24px; font-weight: 700; color: var(--text); line-height: 1.1; }
.sch-day-month { font-size: 12px; }
.sch-today-day .sch-day-num { color: #fff; background: var(--accent); border-radius: 999px; width: 38px; height: 38px; display: grid; place-items: center; }
.sch-day-cards { display: grid; gap: 8px; min-width: 0; }
.sch-past-day { opacity: .62; }

.sch-card {
  --lead: #7a8790;
  display: grid; gap: 2px; align-content: start; text-align: left; width: 100%; min-width: 0; padding: 9px 12px 10px 14px;
  border: 1px solid var(--line); border-left: 5px solid var(--lead); border-radius: 10px;
  background: color-mix(in srgb, var(--lead) 9%, var(--panel)); color: var(--text); font: inherit; cursor: pointer;
}
.sch-card:focus-visible, .sch-view:focus-visible, .sch-person:focus-visible { outline: 3px solid var(--accent-border); outline-offset: 2px; }
.sch-card-time { font-size: 13px; color: var(--muted); font-weight: 600; }
.sch-card-title { font-weight: 700; overflow-wrap: anywhere; }
.sch-card-customer { overflow-wrap: anywhere; }
.sch-card-crew, .sch-card-address { font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.sch-card-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.sch-tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); color: var(--text); }
.sch-tag-warn, .sch-tag-flag { border-color: #e5b49a; background: #fff1e8; color: var(--warn); }
.sch-tag-cancel { background: #f1f1f1; color: var(--muted); }
.sch-tag-quiet { color: var(--muted); }
.sch-past { opacity: .6; }
.sch-cancelled .sch-card-title, .sch-cancelled .sch-card-customer, .sch-cancelled .sch-card-time { text-decoration: line-through; }
.sch-cancelled { opacity: .7; }
.sch-block {
  background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--lead) 14%, var(--panel)) 0 8px, var(--panel) 8px 16px);
  border-style: dashed; border-left-style: solid;
}

/* Time grids: Day, 3 day, Week and Staff. Only the calendar scrolls sideways. */
.sch-grid-wrap { overflow-x: auto; overflow-y: visible; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); -webkit-overflow-scrolling: touch; max-width: 100%; }
.sch-grid { --colmin: 120px; display: grid; grid-template-columns: 52px repeat(var(--cols), minmax(var(--colmin), 1fr)); width: 100%; min-width: calc(52px + var(--cols) * var(--colmin)); }
.sch-view-day .sch-grid { --colmin: 220px; }
.sch-view-3day .sch-grid { --colmin: 140px; }
.sch-view-week .sch-grid { --colmin: 108px; }
.sch-view-staff .sch-grid { --colmin: 150px; }
.sch-corner, .sch-col-head { position: sticky; top: 0; z-index: 3; background: var(--panel); border-bottom: 1px solid var(--line); }
.sch-col-head { --lead: transparent; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; padding: 8px; font-weight: 650; font-size: 14px; border-left: 1px solid var(--line); min-width: 0; }
.sch-col-title { overflow-wrap: anywhere; }
.sch-col-sub { flex-basis: 100%; font-weight: 400; font-size: 12px; color: var(--muted); }
.sch-today-head { color: var(--accent-dark); }
.sch-allday-label { font-size: 11px; color: var(--muted); padding: 6px 4px; border-bottom: 1px solid var(--line); }
.sch-allday { display: grid; gap: 4px; padding: 3px; border-left: 1px solid var(--line); border-bottom: 1px solid var(--line); min-height: 14px; }
.sch-gutter { position: relative; }
.sch-hour { position: absolute; right: 6px; transform: translateY(-50%); font-size: 11px; color: var(--muted); white-space: nowrap; }
.sch-hour:first-child { transform: none; }
.sch-col { position: relative; border-left: 1px solid var(--line); }
.sch-line { position: absolute; left: 0; right: 0; border-top: 1px solid #eef2f3; }
.sch-shift { position: absolute; left: 0; right: 0; background: color-mix(in srgb, var(--accent) 7%, transparent); border-left: 3px solid var(--accent-border); }
.sch-now { position: absolute; left: 0; right: 0; border-top: 2px solid #d64545; z-index: 2; }
.sch-col .sch-card, .sch-allday .sch-card { position: absolute; overflow: hidden; padding: 4px 6px 4px 8px; gap: 0; border-left-width: 4px; font-size: 12.5px; line-height: 1.25; z-index: 1; }
.sch-allday .sch-card { position: relative; }
.sch-compact .sch-card-title { font-size: 12.5px; }
.sch-compact .sch-card-time, .sch-compact .sch-card-customer { font-size: 12px; }
.sch-card-flag { position: absolute; top: 2px; right: 4px; width: 16px; height: 16px; border-radius: 50%; background: var(--warn); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }

/* Team schedule. */
.sch-team { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 860px; font-size: 13px; }
.sch-team th, .sch-team td { border-bottom: 1px solid var(--line); border-left: 1px solid var(--line); padding: 6px 8px; vertical-align: top; text-align: left; }
.sch-team thead th { position: sticky; top: 0; background: var(--panel); z-index: 2; font-weight: 650; white-space: nowrap; }
.sch-team tbody th { position: sticky; left: 0; background: var(--panel); z-index: 1; min-width: 132px; }
.sch-team-cell { min-width: 112px; display: table-cell; }
.sch-team-cell > span { display: block; }
.sch-working { background: color-mix(in srgb, var(--accent) 5%, var(--panel)); }
.sch-off { color: var(--muted); }
.sch-team-hours { font-weight: 600; }
.sch-team-jobs, .sch-team-load { color: var(--muted); }
.sch-team-warn { color: var(--warn); font-weight: 600; }
.sch-team-alert { box-shadow: inset 3px 0 0 var(--warn); }
.sch-person { --lead: #7a8790; display: grid; grid-template-columns: 12px 1fr; align-items: center; column-gap: 6px; border: 0; background: none; font: inherit; text-align: left; padding: 6px 0; min-height: 44px; cursor: pointer; color: var(--text); }
.sch-person-role { grid-column: 2; color: var(--muted); font-size: 12px; font-weight: 400; }
.sch-dot { --lead: inherit; width: 10px; height: 10px; border-radius: 50%; background: var(--lead); display: inline-block; flex: none; }

/* The "+" button. */
.sch-fab { position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: calc(20px + env(safe-area-inset-bottom)); width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 30px; line-height: 1; box-shadow: 0 6px 18px rgba(15, 40, 45, .28); cursor: pointer; z-index: 30; }
.sch-fab:focus-visible { outline: 3px solid var(--accent-border); outline-offset: 3px; }

/* Sheets: full screen on a phone, a panel on the Fold open and the desktop. */
.sch-backdrop { position: fixed; inset: 0; background: rgba(15, 25, 30, .38); z-index: 1000; display: grid; place-items: center; padding: 16px; }
.sch-sheet { width: min(560px, 100%); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; background: var(--panel); border-radius: 14px; box-shadow: 0 16px 40px rgba(15, 25, 30, .3); overflow: hidden; }
.sch-sheet-wide { width: min(760px, 100%); }
.sch-sheet-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.sch-sheet-head h2 { margin: 0; font-size: 18px; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.sch-sheet-body { overflow-y: auto; padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); }
.sch-sheet .button { min-height: 44px; }
.sch-form { display: grid; gap: 12px; }
.sch-fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px 12px; margin: 0; display: grid; gap: 10px; min-width: 0; }
.sch-fieldset legend { font-weight: 700; padding: 0 4px; }
.sch-field { display: grid; gap: 4px; min-width: 0; }
.sch-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.sch-hint { font-size: 13px; color: var(--muted); margin: 0; }
.sch-field input, .sch-field select, .sch-field textarea, .sch-form > select, .sch-product-row select, .sch-product-row input, .sch-override-add input, .sch-override-add select, .sch-tier-row input, .sch-customer input, .sch-week-times input {
  min-height: 44px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: var(--panel); color: var(--text); min-width: 0; width: 100%;
}
.sch-field textarea { min-height: 72px; resize: vertical; }
.sch-two, .sch-three { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.sch-three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.sch-check { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.sch-check input { width: 22px; height: 22px; }
.sch-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.sch-actions-stack { display: grid; }
.sch-link { border: 0; background: none; color: var(--accent-dark); text-decoration: underline; padding: 0 4px; min-height: 44px; font: inherit; cursor: pointer; justify-self: start; }
.sch-danger { color: var(--warn); border-color: #e5b49a; }
.sch-details { display: grid; gap: 8px; margin: 0 0 12px; }
.sch-detail-row { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 8px; }
.sch-detail-row dt { color: var(--muted); font-size: 14px; }
.sch-detail-row dd { margin: 0; overflow-wrap: anywhere; }
.sch-warnings { margin: 0; padding: 8px 12px 8px 28px; border-radius: 8px; background: #fff4e5; color: var(--warn); display: grid; gap: 4px; }
.sch-preview { display: grid; gap: 6px; padding: 10px 12px; border-radius: 10px; background: var(--panel-soft); border: 1px solid var(--line); }
.sch-preview p { margin: 0; }
.sch-preview ul { margin: 4px 0 0; }
.sch-length { margin: 0; font-weight: 600; }
.sch-form-message { margin: 0; color: var(--warn); min-height: 0; }
.sch-results { display: grid; gap: 4px; }
.sch-result { display: grid; gap: 2px; text-align: left; padding: 10px 12px; min-height: 44px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); font: inherit; cursor: pointer; color: var(--text); }
.sch-result span { color: var(--muted); font-size: 14px; }
.sch-chosen { margin: 0; font-weight: 650; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.sch-new-customer { display: grid; gap: 10px; }
.sch-customer { display: grid; gap: 8px; }
.sch-products { display: grid; gap: 6px; }
.sch-product-row { display: grid; grid-template-columns: minmax(0, 1fr) 76px auto; gap: 6px; align-items: center; }
.sch-week-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; justify-content: space-between; }
.sch-week-times { display: flex; gap: 6px; flex: 1 1 200px; }
.sch-change-list, .sch-overrides { margin: 0; padding-left: 18px; display: grid; gap: 4px; }
.sch-lead-row { display: grid; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.sch-swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.sch-swatch { width: 36px; height: 36px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.sch-swatch.sch-active { border-color: var(--text); box-shadow: 0 0 0 2px var(--panel) inset; }
.sch-lead-row input[type=color] { width: 56px; height: 40px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.sch-install { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.sch-tiers { display: grid; gap: 6px; }
.sch-tier-row { display: grid; grid-template-columns: auto 84px auto 84px auto; gap: 6px; align-items: center; }
.sch-override-add { display: grid; gap: 6px; grid-template-columns: 90px minmax(0, 1fr) 120px; }
.sch-override-add input[placeholder^="Note"] { grid-column: 1 / -1; }
.sch-override-add .button { grid-column: 1 / -1; justify-self: start; }
/* Book several days (pass 3): one card per day; the group's tag on cards. */
.sch-tag-group { border-color: #c9b98a; background: #faf5e6; color: #6b5512; }
.sch-group-days { display: grid; gap: 10px; }
.sch-group-day { display: grid; gap: 10px; padding: 10px 12px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); min-width: 0; }
.sch-group-day-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; }
.sch-group-result { display: grid; gap: 4px; }
.sch-group-result p { margin: 0; }
.sch-group-actions, .sch-job-time { margin-top: 12px; }
.sch-group-actions .sch-label { margin: 0; }
.sch-group-move { display: flex; flex-wrap: wrap; gap: 8px; }
.sch-group-move select { flex: 1 1 200px; min-height: 44px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: var(--panel); color: var(--text); min-width: 0; }

@media (max-width: 760px) {
  #scheduleModule { padding: 8px 16px calc(96px + env(safe-area-inset-bottom)); }
  .sch-row { gap: 6px; }
  .sch-row-nav { flex-wrap: nowrap; }
  .sch-range { flex: 1 1 auto; justify-content: flex-end; padding: 0; font-size: 15px; }
  .sch-view-pick { flex: 1 1 120px; display: flex; align-items: center; gap: 6px; min-width: 0; }
  .sch-view-pick .sch-label { flex: none; }
  .sch-view-select { flex: 1; min-width: 0; min-height: 44px; padding: 0 8px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: var(--panel); color: var(--text); }
  .sch-tools { margin-left: 0; }
  .sch-search { flex: 1 1 100%; }
  .sch-backdrop { padding: 0; place-items: stretch; }
  .sch-sheet, .sch-sheet-wide { width: 100%; max-height: 100dvh; height: 100dvh; border-radius: 0; }
  .sch-three { grid-template-columns: minmax(0, 1fr); }
  .sch-tier-row { grid-template-columns: auto minmax(0, 1fr) auto minmax(0, 1fr); }
  .sch-tier-row .sch-link { grid-column: 1 / -1; }
  .sch-override-add { grid-template-columns: 1fr 1fr; }
  .sch-detail-row { grid-template-columns: 84px minmax(0, 1fr); }
  .sch-wide-only { display: none !important; }
}
@media (min-width: 761px) {
  .sch-narrow-only { display: none !important; }
}
@media (max-width: 400px) {
  .sch-two { grid-template-columns: minmax(0, 1fr); }
  .sch-day { grid-template-columns: 40px minmax(0, 1fr); gap: 8px; }
  .sch-view-week .sch-grid { --colmin: 104px; }
}
@media (hover: hover) and (pointer: fine) {
  .sch-card:hover { border-color: var(--lead); }
}
.sch-packed { display: grid; gap: 6px; }
@media (max-width: 1180px) {
  .sch-row .button, .sch-view, .sch-search, .sch-range { min-height: 44px; }
}
/* Chips in the time grids: one line each, cut with an ellipsis, never broken mid-word. */
.sch-compact > span:not(.sch-card-flag) { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; overflow-wrap: normal; }
.sch-compact .sch-card-title { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* Admin pages (pass 2): Services, Add-ons and discounts, Staff. */
.sch-admin-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 6px; }
.sch-admin-head h2 { margin: 0; font-size: 20px; flex: 1 1 auto; min-width: 0; }
.sch-admin-head .button { min-height: 44px; }
.sch-admin-body { display: grid; gap: 12px; }
.sch-admin-section { display: grid; gap: 8px; }
.sch-admin-section h3 { margin: 6px 0 0; font-size: 16px; }
.sch-section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.sch-service-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.sch-service { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 12px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.sch-service > .sch-actions { grid-column: 1 / -1; }
.sch-service .sch-actions .button { min-height: 44px; min-width: 44px; }
.sch-service-main { display: grid; gap: 2px; min-width: 0; }
.sch-service-main strong { overflow-wrap: anywhere; }
.sch-archived { opacity: .6; }
.sch-dragging { outline: 2px dashed var(--accent); }
.sch-thumb { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; display: grid; place-items: center; }
.sch-thumb-empty { background: var(--accent-soft); color: var(--accent-dark); font-weight: 700; font-size: 20px; }
.sch-avatar { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; display: grid; place-items: center; font-weight: 700; }
.sch-avatar-large { width: 96px; height: 96px; }
.sch-checks { display: flex; flex-wrap: wrap; gap: 0 14px; }
.sch-avail-row, .sch-question-row, .sch-limit-row { display: grid; gap: 6px; align-items: center; }
.sch-avail-row { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr) auto; }
.sch-question-row { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto auto; }
.sch-limit-row { grid-template-columns: minmax(0, 1fr) auto 80px; }
.sch-avail-row select, .sch-avail-row input, .sch-question-row input, .sch-question-row select, .sch-limit-row input, .sch-week-day input {
  min-height: 44px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: var(--panel); color: var(--text); min-width: 0; width: 100%;
}
.sch-images { display: grid; gap: 8px; }
.sch-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.sch-figure { margin: 0; display: grid; gap: 4px; justify-items: start; }
.sch-figure img { width: 100%; max-width: 240px; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.sch-week { display: grid; gap: 8px; }
.sch-week-day { display: grid; gap: 6px; padding: 8px 0; border-bottom: 1px solid var(--line); }
@media (min-width: 761px) {
  .sch-service { grid-template-columns: auto minmax(0, 1fr) auto; }
  .sch-service > .sch-actions { grid-column: auto; justify-content: flex-end; }
}
@media (max-width: 760px) {
  .sch-avail-row { grid-template-columns: 1fr 1fr; }
  .sch-avail-row select { grid-column: 1 / -1; }
  .sch-question-row { grid-template-columns: 1fr 1fr; }
  .sch-question-row input[type=text] { grid-column: 1 / -1; }
}
.sch-week-day .sch-week-times { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; align-items: center; gap: 6px; min-width: 0; }
.sch-week-day input[type=time] { min-width: 0; width: 100%; }

/* Pass 3: booking links on the Services page. */
.sch-link-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; min-width: 0; }
.sch-link-row code { font-size: 13px; overflow-wrap: anywhere; background: var(--panel-soft); padding: 2px 6px; border-radius: 6px; }
.sch-link-row .button { min-height: 44px; min-width: 64px; }
