/* ==========================================================================
   SD Manager — Activities, forms, session history, calendar activity filter
   Builds on tokens from style.css and calendar.css. Mobile-first.
   ========================================================================== */

.tag--muted { background: var(--neutral-soft); color: var(--text-muted); }

/* .link-btn is also used on <button>; drop the browser's button chrome. */
button.link-btn {
  border: 0;
  background: none;
  text-align: left;
}

/* ---------- Modal form (native <dialog>) ---------- */

/* Phones: full screen, sized to the visible viewport (--vvh/--vvt set in form-dialog.js)
   so the on-screen keyboard never covers the footer. */
.modal {
  top: var(--vvt, 0px);
  bottom: auto;
  width: 100%;
  max-width: 100%;
  height: var(--vvh, 100dvh);
  max-height: var(--vvh, 100dvh);
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

.modal[open] {
  display: flex;
  animation: sheet-in 0.25s var(--ease);
}

.modal::backdrop {
  background: rgb(7 15 29 / 0.55);
  backdrop-filter: blur(2px);
}

.modal-form {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 0;
}

/* Fixed regions (header, optional toolbar, footer) never shrink; only the body scrolls. */
.modal-header,
.modal-toolbar,
.modal-footer {
  flex: none;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--surface);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.modal-toolbar {
  position: relative;
  z-index: 1;
  padding-top: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  transition: box-shadow 0.2s var(--ease);
}

/* Depth cue once the fields scroll under the fixed area. */
.modal.is-scrolled .modal-toolbar,
.modal.is-scrolled .modal-header:not(:has(+ .modal-toolbar)) {
  box-shadow: 0 6px 12px -10px rgb(15 27 45 / 0.35);
}

[data-theme="dark"] .modal.is-scrolled .modal-toolbar,
[data-theme="dark"] .modal.is-scrolled .modal-header:not(:has(+ .modal-toolbar)) {
  box-shadow: 0 6px 14px -8px rgb(0 0 0 / 0.7);
}

.modal-title {
  font-size: 18px;
  font-weight: 750;
  letter-spacing: -0.01em;
}

.modal-sub {
  margin-top: 2px;
  font-size: 13px;
  color: var(--text-muted);
}

.modal-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 16px max(16px, env(safe-area-inset-right, 0px)) 24px max(16px, env(safe-area-inset-left, 0px));
  /* Focused fields scroll fully into view, clear of the fixed edges. */
  scroll-padding-block: 16px;
}

.modal-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.form-error {
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  border-radius: 12px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13.5px;
  font-weight: 600;
}

/* ---------- Form controls ---------- */

.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

.field { min-width: 0; }

.field-label {
  display: block;
  margin-bottom: 6px;
  padding: 0;
  font-size: 13px;
  font-weight: 650;
  color: var(--text-2);
}

.req { color: var(--danger); }

.input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* avoids iOS zoom */
  transition: border-color 0.15s, box-shadow 0.15s;
}

textarea.input { min-height: 84px; resize: vertical; }
select.input { padding-right: 32px; }

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.input[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 18%, transparent);
}

.input:disabled { opacity: 0.6; }

.field-hint {
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--text-muted);
}

/* Inline message for one field (dialogs with inlineErrors): icon + text, never color alone. */
.field-error {
  display: flex;
  gap: 6px;
  align-items: flex-start;
  margin-top: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--danger);
}
.field-error .icon { flex: none; width: 16px; height: 16px; margin-top: 1px; }

/* Informational note at the top of a form (e.g. a resumed save, 5d.7): icon + text. */
.form-notice {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin: 0 0 4px;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--info) 35%, transparent);
  border-radius: 12px;
  background: var(--info-soft);
  color: var(--text);
  font-size: 13.5px;
}
.form-notice .icon { flex: none; width: 18px; height: 18px; margin-top: 1px; color: var(--info); }

.field-static {
  min-height: 44px;
  padding: 10px 0;
  font-weight: 600;
}

.form-group {
  min-width: 0;
  margin: 20px 0 0;
  padding: 16px 0 0;
  border: 0;
  border-top: 1px solid var(--border);
}

.form-group:disabled { opacity: 0.75; }

.form-group-title {
  margin-bottom: 12px;
  padding: 0;
  font-size: 14px;
  font-weight: 750;
}

.form-group > .seg,
.form-group > .field-hint { margin-bottom: 14px; }
.form-group > .form-grid + .field,
.form-group > .form-grid + .form-grid { margin-top: 14px; }

/* Radio "segmented" choice */
.seg--form { flex-wrap: wrap; }

.seg-option {
  display: flex;
  flex: 1;
  min-width: max-content;
}

.seg-option span {
  display: grid;
  flex: 1;
  place-items: center;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 650;
  color: var(--text-2);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.seg-option:hover span { background: var(--surface-hover); }
.seg-option input:checked + span { background: var(--accent); color: var(--on-accent); }
.seg-option input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Weekday toggles */
.weekday-picker {
  margin: 0;
  padding: 0;
  border: 0;
}

.weekday-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.weekday-opt span[aria-hidden] {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-2);
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.weekday-opt:hover span[aria-hidden] { background: var(--surface-hover); }

.weekday-opt input:checked + span {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}

.weekday-opt input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.weekday-picker[aria-invalid="true"] .weekday-row,
.weekday-opt input[aria-invalid="true"] + span { border-color: var(--danger); }

.appearance-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.appearance-text {
  flex: 1;
  min-width: 120px;
  font-size: 14px;
  color: var(--text-2);
}

.scope-note {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 6px 8px;
  margin-bottom: 4px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--info-soft);
  font-size: 13.5px;
  color: var(--text-2);
}

.scope-note > .icon { margin-top: 3px; color: var(--info); }
.scope-note > span { flex: 1; min-width: 200px; }
.scope-note .link-btn { min-height: 32px; }
.scope-note--warn { background: var(--warning-soft); }
.scope-note--warn > .icon { color: var(--warning); }

/* ---------- Activities page ---------- */

.acts .page-header { align-items: flex-end; }

.acts-tabs {
  width: 100%;
  margin-bottom: 16px;
}

.acts-tabs button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
}

.acts-tabs .icon { width: 17px; height: 17px; }
.acts .seg button { white-space: nowrap; }

.acts-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.search-field {
  position: relative;
  flex: 1;
  min-width: 220px;
}

.search-field .icon {
  position: absolute;
  left: 13px;
  top: 50%;
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  transform: translateY(-50%);
  pointer-events: none;
}

.search-field .input { padding-left: 40px; }

.seg-count {
  margin-left: 4px;
  font-size: 12px;
  opacity: 0.75;
}

.acts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.act-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.act-card-top {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.act-card-heading {
  flex: 1;
  min-width: 0;
}

.act-card-title {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
}

.act-card-title a { border-radius: 6px; }
.act-card-title a:hover { color: var(--accent-text); text-decoration: underline; text-underline-offset: 3px; }

.act-card-sub {
  margin-top: 2px;
  font-size: 13px;
  color: var(--text-muted);
}

.act-meta {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13.5px;
  color: var(--text-2);
}

.act-meta li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.act-meta .icon { margin-top: 3px; color: var(--text-muted); }

.act-stats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
}

.act-stats-label {
  margin-right: 2px;
  font-weight: 650;
  color: var(--text-muted);
}

.act-actions,
.ev-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.act-actions { margin-top: auto; }
.act-actions .btn .icon,
.ev-card-actions .btn .icon,
.act-hero-actions .btn .icon,
.sched-item .btn .icon,
.hist-actions .btn .icon { width: 16px; height: 16px; }

/* Detail */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 650;
  color: var(--accent-text);
}

.back-link .icon { width: 18px; height: 18px; }

.act-hero { margin-bottom: 16px; }

.act-hero-main {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.act-hero-text {
  flex: 1;
  min-width: min(100%, 240px);
}

.act-hero-text .eyebrow { display: flex; align-items: center; gap: 8px; }
.act-hero-text .eyebrow .tag { text-transform: none; letter-spacing: 0.02em; }

.act-facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px 20px;
  margin-top: 12px;
}

.act-facts dt {
  font-size: 12px;
  font-weight: 650;
  color: var(--text-muted);
}

.act-facts dd {
  font-size: 14px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.act-desc {
  max-width: 70ch;
  margin-top: 12px;
  font-size: 14px;
  color: var(--text-2);
}

.act-hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.act-hero-note {
  margin-top: 10px;
  font-size: 12.5px;
}

.act-detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}

.sched-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sched-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-2);
}

.sched-item.is-ended { opacity: 0.7; }

.sched-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent-text);
}

.sched-icon .icon { width: 18px; height: 18px; }
.sched-body { flex: 1; min-width: 0; }
.sched-title { font-weight: 650; }

.sched-meta {
  margin-top: 2px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.card.act-log {
  margin-top: 16px;
  padding: 0;
}

.act-log summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 18px;
  font-weight: 650;
  cursor: pointer;
  list-style: none;
}

.act-log summary::-webkit-details-marker { display: none; }
.act-log summary .icon { color: var(--accent-text); }

.act-log-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 0 18px 0 38px;
  font-size: 13.5px;
}

.act-log-list li span { display: block; }
.act-log-what { font-weight: 600; }

.act-log-note {
  padding: 12px 18px 16px;
  font-size: 12px;
}

/* ---------- Session history ---------- */

.hist-filters {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.hist-filters .field:first-child:nth-last-child(4) { grid-column: 1 / -1; }

.hist-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  grid-column: 1 / -1;
}

.hist-statuses {
  display: flex;
  gap: 6px;
  margin-top: 12px;
  padding-bottom: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}

.hist-statuses::-webkit-scrollbar { display: none; }

.hist-summary {
  margin: 12px 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}

.hist-table-wrap { overflow-x: auto; }

.hist-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.hist-table th {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-align: left;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
}

.hist-table td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.hist-table tr.is-today td { background: color-mix(in srgb, var(--accent) 5%, transparent); }
.hist-date { font-weight: 650; white-space: nowrap; }

.hist-sub {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
}

.hist-activity {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.hist-actions { text-align: right; white-space: nowrap; }

.hist-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px 12px;
  text-align: center;
  color: var(--text-muted);
}

.hist-empty .icon { width: 26px; height: 26px; }

/* Phones: rows become stacked cards */
@media (max-width: 719px) {
  .hist-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .hist-table,
  .hist-table tbody,
  .hist-table tr,
  .hist-table td { display: block; }

  .hist-table tr {
    margin-bottom: 10px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface-2);
  }

  .hist-table td {
    display: grid;
    grid-template-columns: 92px minmax(0, 1fr);
    gap: 8px;
    padding: 5px 0;
    border: 0;
  }

  .hist-table td[data-label]::before {
    content: attr(data-label);
    font-size: 12px;
    font-weight: 650;
    color: var(--text-muted);
  }

  .hist-table tr.is-today td { background: none; }
  .hist-actions { display: block !important; padding-top: 8px !important; text-align: left; }
}

/* ---------- Calendar: activity multi-select ---------- */

.cal-filterbar {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 6px;
}

.cal-filterbar .cal-filters {
  flex: 1;
  min-width: 0;
  margin-bottom: 0;
}

.cal-act-filter {
  position: relative;
  display: flex;
  flex: none;
  align-items: center;
  gap: 4px;
  padding-top: 2px;
}

.chip-btn--menu {
  max-width: 46vw;
  padding: 0 12px;
}

.chip-btn--menu .chip-btn-label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip-btn--menu[aria-expanded="true"] .icon:last-child { transform: rotate(180deg); }

.chip-btn.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}

.icon-btn.cal-act-clear {
  width: 36px;
  height: 36px;
  border-radius: 999px;
}

.cal-act-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 15;
  width: min(340px, calc(100vw - 32px));
  max-height: min(420px, 60dvh);
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: popover-in 0.18s var(--ease);
}

.cal-act-menu fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.cal-act-menu-title {
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.cal-act-option {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 6px 10px;
  border-radius: 10px;
  cursor: pointer;
}

.cal-act-option:hover { background: var(--surface-hover); }

.cal-act-option input {
  width: 18px;
  height: 18px;
  margin: 0;
  flex: none;
  accent-color: var(--accent);
}

.cal-act-name {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.cal-act-menu-hint {
  margin-top: 4px;
  padding: 8px 10px 4px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}

/* ---------- Responsive ---------- */

@media (min-width: 560px) {
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field--wide { grid-column: 1 / -1; }
  .acts-tabs { width: auto; display: inline-flex; }
}

@media (min-width: 768px) {
  /* Tablets/desktop: centered card within the visible area (keyboard-aware on iPad). */
  .modal {
    top: var(--vvt, 0px);
    bottom: var(--vvb, 0px);
    width: min(680px, calc(100% - 48px));
    height: fit-content;
    max-height: min(860px, calc(var(--vvh, 100dvh) - 48px));
    margin: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
  }

  .modal-header,
  .modal-toolbar,
  .modal-body,
  .modal-footer { padding-inline: 24px; }
  .modal-header { padding-top: 20px; }
  .modal-body { padding-block: 20px 24px; }

  .hist-filters { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
  .hist-filters .field:first-child:nth-last-child(4) { grid-column: auto; }
  .hist-presets { grid-column: 1 / -1; }

  .chip-btn--menu { max-width: 260px; }
}

@media (min-width: 1200px) {
  .act-detail-grid { grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); align-items: start; }
}
