/* Work item detail — inline expansion panel.
 *
 * The expanded panel sits in a sibling <tr class="wi-detail-row"> inserted
 * by wi_detail_toggle_controller.js. Its inner turbo-frame lazy-loads the
 * WorkItemsController#detail partial.
 */

@layer components {
  /* Detail-panel toggle, lives in the actions cell of _wi_row.html.erb.
     Sized to match .wi-more-btn so the right-edge action cluster aligns. */
  .wi-row-expand {
    width: 26px;
    height: 26px;
    display: inline-grid;
    place-items: center;
    border: 0;
    background: transparent;
    color: var(--rd-fg-muted);
    border-radius: var(--rd-radius-sm);
    cursor: pointer;
    flex: 0 0 auto;
    margin-right: 2px;
    transition: background var(--rd-dur-fast) var(--rd-ease),
                color var(--rd-dur-fast) var(--rd-ease);
  }
  .wi-row-expand:hover {
    background: var(--rd-bg-hover);
    color: var(--rd-fg);
  }
  .wi-row-expand.is-open {
    color: var(--rd-accent);
  }
  .wi-row-expand svg { display: block; grid-area: 1 / 1; }
  .wi-row-expand .wi-row-expand-icon-open { display: none; }
  .wi-row-expand.is-open .wi-row-expand-icon-closed { display: none; }
  .wi-row-expand.is-open .wi-row-expand-icon-open { display: block; }

  /* Expanded row gets a subtle accent stripe on the left */
  .tree-table tbody tr.wi-row-expanded > td:first-child {
    box-shadow: inset 3px 0 0 var(--rd-accent);
  }

  /* The inserted detail TR. Scope to direct-child td so nested tables
     (e.g. the allocation-table) keep their own cell padding. */
  .tree-table tbody tr.wi-detail-row > td {
    padding: 0;
    background: var(--rd-bg-sunken);
    border-bottom: 1px solid var(--rd-border);
  }
  .tree-table tbody tr.wi-detail-row:hover > td {
    background: var(--rd-bg-sunken);
  }
  .tree-table tbody tr.wi-detail-row > td:first-child {
    box-shadow: inset 3px 0 0 var(--rd-accent);
  }

  /* ------------------------------------------------------------------ */
  /* Two-column panel                                                   */
  /* ------------------------------------------------------------------ */
  .wi-detail {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 0;
    animation: wi-detail-fade-in 200ms cubic-bezier(.2,.7,.3,1);
    /* One counter spans both columns so the section index runs continuously
       across the panel (left first, then right). */
    counter-reset: wi-section;
  }
  @keyframes wi-detail-fade-in {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
  }

  @media (max-width: 1100px) {
    .wi-detail { grid-template-columns: 1fr; }
  }

  .wi-main {
    padding: 20px 24px 22px;
    min-width: 0;
    border-right: 1px solid var(--rd-border);
  }
  .wi-rail {
    padding: 18px 20px 22px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
  }

  @media (max-width: 1100px) {
    .wi-main { border-right: 0; border-bottom: 1px solid var(--rd-border); }
  }
  @media (max-width: 720px) {
    .wi-main { padding: 16px 16px 18px; }
    .wi-rail { padding: 14px 16px 20px; }
  }

  /* Loading placeholder rendered before the frame resolves */
  .wi-detail-loading {
    padding: 32px;
    display: flex;
    justify-content: center;
    gap: 6px;
  }
  .wi-detail-loading-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--rd-fg-faint);
    animation: wi-detail-loading-pulse 1.2s infinite ease-in-out;
  }
  .wi-detail-loading-dot:nth-child(2) { animation-delay: 0.15s; }
  .wi-detail-loading-dot:nth-child(3) { animation-delay: 0.3s; }
  @keyframes wi-detail-loading-pulse {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40%           { opacity: 1;   transform: scale(1); }
  }

  /* ------------------------------------------------------------------ */
  /* Main column                                                        */
  /* ------------------------------------------------------------------ */
  .wi-detail-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
  }
  .wi-crumb {
    font-family: var(--rd-font-mono);
    font-size: var(--rd-text-xs);
    color: var(--rd-fg-subtle);
    letter-spacing: 0.02em;
  }
  .wi-detail-head-actions {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 4px;
  }
  .wi-icon-btn {
    width: 24px;
    height: 24px;
    display: inline-grid;
    place-items: center;
    color: var(--rd-fg-subtle);
    background: transparent;
    border: 0;
    border-radius: var(--rd-radius-sm);
    cursor: pointer;
    transition: background var(--rd-dur-fast) var(--rd-ease),
                color var(--rd-dur-fast) var(--rd-ease);
  }
  .wi-icon-btn:hover {
    color: var(--rd-fg);
    background: var(--rd-bg-hover);
  }

  .wi-title-wrap {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 14px;
  }
  .wi-detail-check {
    margin-top: 2px;
    width: 22px;
    height: 22px;
    display: inline-grid;
    place-items: center;
    color: var(--rd-fg-subtle);
    background: transparent;
    border: 0;
    border-radius: var(--rd-radius-sm);
    cursor: pointer;
    flex: 0 0 auto;
    transition: color var(--rd-dur-fast) var(--rd-ease),
                background var(--rd-dur-fast) var(--rd-ease);
  }
  .wi-detail-check:hover { background: var(--rd-bg-hover); color: var(--rd-fg); }
  .wi-detail-check.is-done { color: var(--rd-success); }
  .wi-detail-check-static { cursor: default; }
  .wi-detail-check-static:hover { background: transparent; }

  .wi-title-edit {
    flex: 1;
    min-width: 0;
  }
  .wi-detail .wi-title {
    display: block;
    font-size: var(--rd-text-lg);
    font-weight: 600;
    letter-spacing: -0.015em;
    line-height: 1.25;
    color: var(--rd-fg);
    min-width: 0;
    padding: 2px 6px;
    margin: 0 -6px;
    border-radius: var(--rd-radius-sm);
    cursor: text;
    transition: background var(--rd-dur-fast) var(--rd-ease),
                box-shadow var(--rd-dur-fast) var(--rd-ease);
  }
  .wi-detail .wi-title:hover {
    background: var(--rd-bg-hover);
    box-shadow: inset 0 0 0 1px var(--rd-border);
  }
  .wi-title-edit.is-done .wi-title {
    color: var(--rd-fg-muted);
    text-decoration: line-through;
    text-decoration-color: var(--rd-fg-faint);
    text-decoration-thickness: 1px;
  }
  .wi-title-input {
    font-size: var(--rd-text-lg);
    font-weight: 600;
    letter-spacing: -0.015em;
    line-height: 1.25;
    width: 100%;
    padding: 2px 6px;
    margin: 0 -6px;
    background: var(--rd-bg-raised);
    color: var(--rd-fg);
    border: 1px solid var(--rd-accent);
    border-radius: var(--rd-radius-sm);
    outline: none;
  }

  /* Section blocks */
  .wi-section { margin-top: 22px; }
  .wi-section-head {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: var(--rd-text-xs);
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--rd-fg);
    padding-bottom: 8px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--rd-border);
  }
  /* Numbered section prefix — runs continuously across the whole panel via
     the counter on .wi-detail. */
  .wi-main .wi-section-head::before,
  .wi-main .cm-thread-head::before,
  .wi-rail .rail-label::before {
    counter-increment: wi-section;
    content: counter(wi-section, decimal-leading-zero);
    font-family: var(--rd-font-mono);
    font-weight: 500;
    letter-spacing: 0;
    color: var(--rd-fg-faint);
  }
  /* Comments thread head shares the section-head treatment when it lives
     inside the work-item detail panel. Project-overview comments keep their
     smaller, recessive default. */
  .wi-main .cm-thread-head {
    font-size: var(--rd-text-xs);
    color: var(--rd-fg);
    padding-bottom: 8px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--rd-border);
  }
  .wi-section-head .count {
    font-family: var(--rd-font-mono);
    font-size: var(--rd-text-2xs);
    color: var(--rd-fg-subtle);
    font-weight: 500;
    letter-spacing: 0;
  }
  .wi-section-head .add {
    margin-left: auto;
    color: var(--rd-fg-subtle);
    font-size: var(--rd-text-xs);
    font-weight: 500;
    letter-spacing: 0;
    text-transform: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: transparent;
    border: 0;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: var(--rd-radius-sm);
  }
  .wi-section-head .add:hover { color: var(--rd-accent); }
  .wi-section-head .wi-section-link {
    margin-left: auto;
    font-size: var(--rd-text-xs);
    font-weight: 500;
    letter-spacing: 0;
    text-transform: none;
    color: var(--rd-fg-subtle);
    text-decoration: none;
  }
  .wi-section-head .wi-section-link:hover { color: var(--rd-accent); }
  .wi-section-empty {
    font-size: var(--rd-text-sm);
    color: var(--rd-fg-subtle);
    font-style: italic;
    margin: 0;
  }

  /* --- Activity feed --- */
  .wi-activity {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
  }
  .wi-activity-item {
    display: grid;
    grid-template-columns: 16px 1fr;
    gap: 10px;
    position: relative;
    font-size: var(--rd-text-sm);
  }
  .wi-activity-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--rd-fg-faint);
    margin: 6px auto 0;
    position: relative;
  }
  .wi-activity-dot::before {
    content: "";
    position: absolute;
    top: 12px; bottom: -16px; left: 50%;
    width: 1px;
    background: var(--rd-border);
    transform: translateX(-50%);
  }
  .wi-activity-item:last-child .wi-activity-dot::before { display: none; }
  .wi-activity-body { min-width: 0; }
  .wi-activity-line {
    color: var(--rd-fg);
    line-height: var(--rd-leading-snug);
  }
  .wi-activity-actor {
    font-weight: 500;
  }
  .wi-activity-action {
    color: var(--rd-fg-muted);
    margin-left: 4px;
  }
  .wi-activity-changes {
    list-style: none;
    padding: 4px 0 0 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
  }
  .wi-activity-change {
    font-size: var(--rd-text-xs);
    color: var(--rd-fg-muted);
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: baseline;
  }
  .wi-activity-change-field {
    font-weight: 500;
    color: var(--rd-fg-subtle);
  }
  .wi-activity-change-old {
    color: var(--rd-fg-subtle);
    text-decoration: line-through;
    text-decoration-thickness: 1px;
  }
  .wi-activity-change-arrow { color: var(--rd-fg-faint); }
  .wi-activity-change-new { color: var(--rd-fg); }
  .wi-activity-change-more {
    font-size: var(--rd-text-xs);
    color: var(--rd-fg-subtle);
    font-style: italic;
  }
  .wi-activity-when {
    display: block;
    font-size: var(--rd-text-xs);
    color: var(--rd-fg-subtle);
    margin-top: 2px;
  }

  /* --- Custom fields --- */
  .wi-fields-group + .wi-fields-group {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--rd-border);
  }
  .wi-fields-group-title {
    font-size: var(--rd-text-sm);
    font-weight: 600;
    color: var(--rd-fg);
    margin: 0 0 4px;
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .wi-fields-tenant-badge {
    font-size: var(--rd-text-2xs);
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 1px 6px;
    background: var(--rd-info-soft);
    color: var(--rd-info);
    border-radius: var(--rd-radius-sm);
  }
  .wi-fields-list {
    display: grid;
    grid-template-columns: minmax(0, 140px) minmax(0, 1fr);
    gap: 6px 16px;
    margin: 0;
  }
  .wi-fields-row {
    display: contents;
  }
  .wi-fields-label {
    font-size: var(--rd-text-sm);
    color: var(--rd-fg-subtle);
    font-weight: 500;
  }
  .wi-fields-value {
    font-size: var(--rd-text-sm);
    color: var(--rd-fg);
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
  }
  .wi-fields-chip {
    display: inline-block;
    padding: 1px 7px;
    font-size: var(--rd-text-xs);
    font-weight: 500;
    border-radius: var(--rd-radius-sm);
    background: var(--rd-bg-hover);
    color: var(--rd-fg-muted);
  }
  .wi-fields-chip-on {
    background: var(--rd-success-soft);
    color: var(--rd-success);
  }
  .wi-fields-chip-off {
    background: var(--rd-bg-hover);
    color: var(--rd-fg-muted);
  }
  .wi-fields-chip-info {
    background: var(--rd-info-soft);
    color: var(--rd-info);
  }
  .wi-fields-chip-accent {
    background: var(--rd-accent-soft);
    color: var(--rd-accent);
  }

  /* --- Dependencies --- */
  .wi-deps-conflict-badge {
    font-size: var(--rd-text-2xs);
    font-weight: 600;
    letter-spacing: 0.05em;
    padding: 1px 6px;
    background: var(--rd-danger-soft);
    color: var(--rd-danger);
    border-radius: var(--rd-radius-sm);
  }
  /* "Depends on" and "Depended on by" are two halves of one thought, so
     give them just a hint of breathing room — the parent "Dependencies"
     header already separates this block from everything around it. */
  .wi-deps-group + .wi-deps-group {
    margin-top: 14px;
  }
  .wi-deps-group-title {
    font-size: var(--rd-text-xs);
    font-weight: 600;
    color: var(--rd-fg-muted);
    margin: 0 0 8px;
    display: flex;
    align-items: center;
    gap: 6px;
  }
  .wi-deps-count {
    font-family: var(--rd-font-mono);
    font-weight: 500;
    color: var(--rd-fg-subtle);
    font-size: var(--rd-text-2xs);
  }
  .wi-deps-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
  .wi-deps-item {
    display: flex;
    flex-direction: column;
    font-size: var(--rd-text-sm);
    background: var(--rd-bg-raised);
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-md);
  }
  .wi-deps-item.is-violated {
    border-color: oklch(0.68 0.22 27 / 0.35);
    background: var(--rd-danger-soft);
  }
  .wi-deps-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
  }
  .wi-deps-chip {
    display: inline-flex;
    align-items: center;
    padding: 1px 6px;
    font-family: var(--rd-font-mono);
    font-size: var(--rd-text-2xs);
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--rd-fg-muted);
    background: var(--rd-bg-hover);
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-sm);
    white-space: nowrap;
  }
  button.wi-deps-chip-editable {
    cursor: pointer;
    margin: 0;
    font-family: var(--rd-font-mono);
    transition: background var(--rd-dur-fast) var(--rd-ease),
                color var(--rd-dur-fast) var(--rd-ease),
                border-color var(--rd-dur-fast) var(--rd-ease);
  }
  button.wi-deps-chip-editable:hover {
    color: var(--rd-fg);
    border-color: var(--rd-border-strong);
    background: var(--rd-bg-raised);
  }
  button.wi-deps-chip-editable.is-open {
    color: var(--rd-accent);
    background: var(--rd-accent-soft);
    border-color: var(--rd-accent);
  }
  .wi-deps-edit-form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 8px;
    padding: 8px 10px 10px;
    border-top: 1px solid var(--rd-border);
    background: var(--rd-bg-hover);
    border-bottom-left-radius: var(--rd-radius-md);
    border-bottom-right-radius: var(--rd-radius-md);
  }
  .wi-deps-edit-label {
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: var(--rd-text-xs);
    font-weight: 500;
    color: var(--rd-fg-muted);
  }
  .wi-deps-edit-label > span {
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-size: var(--rd-text-2xs);
    color: var(--rd-fg-subtle);
  }
  .wi-deps-edit-select,
  .wi-deps-edit-lag {
    padding: 5px 8px;
    font-size: var(--rd-text-sm);
    background: var(--rd-bg-raised);
    color: var(--rd-fg);
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-sm);
    font-family: inherit;
  }
  .wi-deps-edit-select { min-width: 160px; }
  .wi-deps-edit-lag { width: 80px; font-variant-numeric: tabular-nums; }
  .wi-deps-edit-select:focus,
  .wi-deps-edit-lag:focus {
    outline: none;
    border-color: var(--rd-accent);  }
  .wi-deps-edit-actions {
    display: flex;
    gap: 6px;
    margin-left: auto;
  }
  .wi-deps-type {
    display: inline-grid;
    place-items: center;
    width: 18px;
    height: 18px;
    border-radius: var(--rd-radius-sm);
    font-family: var(--rd-font-mono);
    font-size: var(--rd-text-2xs);
    font-weight: 600;
    flex: 0 0 auto;
    background: var(--rd-bg-hover);
    color: var(--rd-fg-muted);
  }
  .wi-deps-title {
    flex: 1;
    min-width: 0;
    color: var(--rd-fg);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .wi-deps-title:hover { color: var(--rd-accent); }
  .wi-deps-status {
    font-size: var(--rd-text-2xs);
    font-weight: 600;
    letter-spacing: 0.04em;
    padding: 1px 6px;
    border-radius: var(--rd-radius-sm);
  }
  .wi-deps-status-done {
    background: var(--rd-success-soft);
    color: var(--rd-success);
  }
  .wi-deps-status-overdue {
    background: var(--rd-danger-soft);
    color: var(--rd-danger);
  }
  .wi-deps-due {
    font-family: var(--rd-font-mono);
    font-size: var(--rd-text-xs);
    color: var(--rd-fg-subtle);
  }
  .wi-deps-warning {
    color: var(--rd-danger);
    display: inline-flex;
    align-items: center;
  }

  /* --- Financials --- */
  .wi-finances-summary {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 14px;
  }
  /* The detail panel stacks the rail under the main column at <=1100px,
     so the inline detail panel can still hold 4 stats up to that point;
     below ~900px (or at any width inside an overlay where the wrapper is
     narrower than 720px), drop to two columns to keep the values readable. */
  @media (max-width: 900px) {
    .wi-finances-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  }
  .wi-finances-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 9px 11px;
    background: var(--rd-bg-raised);
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-md);
    min-width: 0;
  }
  .wi-finances-stat-label {
    font-size: var(--rd-text-2xs);
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--rd-fg-subtle);
  }
  .wi-finances-stat-value {
    font-family: var(--rd-font-mono);
    font-size: var(--rd-text-md);
    font-weight: 600;
    color: var(--rd-fg);
    letter-spacing: -0.01em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .wi-finances-stat-value.is-muted { color: var(--rd-fg-subtle); }
  .wi-finances-stat-value.is-positive { color: var(--rd-success); }
  .wi-finances-stat-value.is-negative { color: var(--rd-danger); }
  .wi-finances-stat-note {
    font-size: var(--rd-text-xs);
    color: var(--rd-fg-muted);
  }
  .wi-finances-allocs-head {
    font-size: var(--rd-text-2xs);
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--rd-fg-subtle);
    margin-bottom: 6px;
  }
  .wi-finances-allocs-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
  .wi-finances-alloc {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 4px 8px;
    font-size: var(--rd-text-sm);
    background: var(--rd-bg-raised);
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-sm);
  }
  .wi-finances-alloc-name {
    flex: 1;
    color: var(--rd-fg);
  }
  .wi-finances-alloc-pct {
    font-family: var(--rd-font-mono);
    color: var(--rd-fg-muted);
    font-variant-numeric: tabular-nums;
  }
  .wi-finances-alloc-amt {
    font-family: var(--rd-font-mono);
    color: var(--rd-fg);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
  }

  /* --- Rail: empty placeholder --- */
  .rail-value-empty {
    color: var(--rd-fg-subtle);
    font-style: italic;
  }

  /* --- Description: inline click-to-edit rich text --- */
  .wi-desc { position: relative; }

  .wi-desc-display {
    font-size: var(--rd-text-base);
    color: var(--rd-fg);
    line-height: var(--rd-leading-normal);
    padding: 8px 10px;
    margin: 0 -10px;
    border-radius: var(--rd-radius-md);
    cursor: text;
    min-height: 40px;
    transition: background var(--rd-dur-fast) var(--rd-ease),
                box-shadow var(--rd-dur-fast) var(--rd-ease);
  }
  .wi-desc-display:hover {
    background: var(--rd-bg-hover);
    box-shadow: inset 0 0 0 1px var(--rd-border);
  }
  .wi-desc-display:focus-visible {
    outline: none;
    background: var(--rd-bg-hover);
    box-shadow: inset 0 0 0 1px var(--rd-accent);
  }
  .wi-desc-display .lexxy-content > *:first-child { margin-top: 0; }
  .wi-desc-display .lexxy-content > *:last-child  { margin-bottom: 0; }
  .wi-desc-display .lexxy-content p { margin: 0 0 6px; }
  .wi-desc-display .lexxy-content p:last-child { margin-bottom: 0; }

  .wi-desc-placeholder {
    color: var(--rd-fg-subtle);
    font-style: italic;
  }

  /* Edit form — matches the comment composer frame */
  .wi-desc-edit {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-lg);
    background: var(--rd-bg-raised);
    transition: border-color var(--rd-dur-fast) var(--rd-ease),
                box-shadow var(--rd-dur-fast) var(--rd-ease);
  }
  .wi-desc-edit:focus-within {
    border-color: var(--rd-accent);
  }
  .wi-desc-edit-body {
    min-width: 0;
  }
  .wi-desc-edit-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 10px;
    background: var(--rd-bg);
    border-bottom-left-radius: calc(var(--rd-radius-lg) - 1px);
    border-bottom-right-radius: calc(var(--rd-radius-lg) - 1px);
  }
  .wi-desc-edit-submit {
    display: inline-flex;
    gap: 6px;
    align-items: center;
  }
  .cm-compose-hint-sep {
    margin: 0 2px;
    color: var(--rd-fg-faint);
  }

  /* Steps list */
  .wi-steps {
    display: flex;
    flex-direction: column;
    gap: 1px;
    background: var(--rd-border);
    border-radius: var(--rd-radius-md);
    overflow: hidden;
    border: 1px solid var(--rd-border);
  }
  .wi-step {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    background: var(--rd-bg-raised);
    font-size: var(--rd-text-sm);
    transition: background var(--rd-dur-fast) var(--rd-ease);
  }
  .wi-step:hover { background: var(--rd-bg-hover); }
  .wi-step .title {
    flex: 1;
    min-width: 0;
    color: var(--rd-fg);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-decoration: none;
  }
  .wi-step .title:hover { color: var(--rd-accent); }
  .wi-step.is-done .title {
    color: var(--rd-fg-muted);
    text-decoration: line-through;
  }
  .wi-step .num {
    font-family: var(--rd-font-mono);
    font-size: var(--rd-text-xs);
    color: var(--rd-fg-subtle);
  }
  .wi-step-check {
    width: 18px;
    height: 18px;
    display: inline-grid;
    place-items: center;
    color: var(--rd-fg-subtle);
    background: transparent;
    border: 0;
    border-radius: var(--rd-radius-sm);
    cursor: pointer;
    flex: 0 0 auto;
  }
  .wi-step-check:hover { background: var(--rd-bg-active); color: var(--rd-fg); }
  .wi-step.is-done .wi-step-check { color: var(--rd-success); }
  .wi-step .step-due { font-size: var(--rd-text-xs); }

  /* Drag-to-reorder handle — fades in on hover so it doesn't clutter. */
  .wi-step-drag-handle {
    width: 14px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    padding: 0;
    background: transparent;
    color: var(--rd-fg-faint);
    cursor: grab;
    opacity: 0;
    flex: 0 0 auto;
    transition: opacity 80ms ease, color 80ms ease;
  }
  .wi-step:hover .wi-step-drag-handle,
  .wi-step:focus-within .wi-step-drag-handle {
    opacity: 1;
    color: var(--rd-fg-muted);
  }
  .wi-step-drag-handle:active { cursor: grabbing; }
  .wi-steps .sortable-ghost  { opacity: 0.35; }
  .wi-steps .sortable-chosen { background: var(--rd-bg-hover); }
  .wi-steps .sortable-drag   { box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18); }

  /* Inline-edit title inside a step row */
  .wi-step-title-edit {
    flex: 1;
    min-width: 0;
  }
  .wi-step .inline-editable.title {
    display: block;
    padding: 2px 6px;
    margin: -2px -6px;
    border-radius: var(--rd-radius-sm);
    cursor: text;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background var(--rd-dur-fast) var(--rd-ease);
  }
  .wi-step .inline-editable.title:hover { background: var(--rd-bg-active); }
  .wi-step .inline-edit-input {
    width: 100%;
    font: inherit;
    color: var(--rd-fg);
    background: var(--rd-bg-raised);
    border: 1px solid var(--rd-accent);
    border-radius: var(--rd-radius-sm);
    padding: 2px 6px;
    outline: none;
  }

  /* Remove-step button on the right of each step row — mirrors deps remove */
  .wi-step-remove-form {
    display: inline-flex;
    margin: 0;
    padding: 0;
    flex: 0 0 auto;
  }
  .wi-step-remove {
    width: 22px;
    height: 22px;
    display: inline-grid;
    place-items: center;
    background: transparent;
    border: 0;
    color: var(--rd-fg-subtle);
    border-radius: var(--rd-radius-sm);
    cursor: pointer;
    opacity: 0;
    transition: background var(--rd-dur-fast) var(--rd-ease),
                color var(--rd-dur-fast) var(--rd-ease),
                opacity 80ms ease;
  }
  .wi-step:hover .wi-step-remove,
  .wi-step:focus-within .wi-step-remove {
    opacity: 1;
  }
  .wi-step-remove:hover {
    background: var(--rd-danger-soft);
    color: var(--rd-danger);
  }

  /* ------------------------------------------------------------------ */
  /* Rail (right column)                                                */
  /* ------------------------------------------------------------------ */
  .wi-rail .rail-grp {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 10px;
  }
  .wi-rail .rail-label {
    font-size: var(--rd-text-xs);
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--rd-fg);
    padding: 0 0 6px;
    margin-bottom: 6px;
    border-bottom: 1px solid var(--rd-border);
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .wi-rail .rail-sublabel {
    font-size: var(--rd-text-2xs);
    color: var(--rd-fg-subtle);
    padding: 0 4px;
    margin-bottom: 2px;
  }
  .wi-rail .rail-value {
    font-size: var(--rd-text-sm);
    color: var(--rd-fg);
    padding: 4px 6px;
    border-radius: var(--rd-radius-sm);
    cursor: text;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 28px;
    margin-left: -6px;
    margin-right: -6px;
    transition: background var(--rd-dur-fast) var(--rd-ease),
                box-shadow var(--rd-dur-fast) var(--rd-ease);
  }
  .wi-rail .inline-editable-wrapper.rail-value:hover,
  .wi-rail .rail-value.inline-editable-wrapper:hover {
    background: var(--rd-bg-hover);
    box-shadow: inset 0 0 0 1px var(--rd-border);
  }
  .wi-rail .rail-value-static { cursor: default; }
  .wi-rail .rail-value-static:hover { background: transparent; box-shadow: none; }
  .wi-rail .rail-value-num {
    font-family: var(--rd-font-mono);
    font-variant-numeric: tabular-nums;
    font-size: var(--rd-text-sm);
  }
  .wi-rail .rail-value-danger .rail-value-num,
  .wi-rail .rail-value-danger { color: var(--rd-danger); }
  .wi-rail .rail-note {
    font-size: var(--rd-text-xs);
    color: var(--rd-fg-muted);
    padding: 0 6px;
    margin-top: 4px;
  }
  .wi-rail .rail-dates {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
  }
  /* Inside the dates grid, drop the rail-value side bleed so each cell's
     hover highlight stays inside its column and the value text lines up
     under its sublabel (both land at the sublabel's 6px inset). */
  .wi-rail .rail-dates .rail-value {
    margin-left: 0;
    margin-right: 0;
  }
  /* The trigger button supplies its own padding/hover highlight, so let it
     fill the rail-value's negative-margin slot rather than nesting another
     6px of padding inside. The trigger also carries .inline-editable, which
     adds its own -4px hover-bleed margin we don't want here — zero it out
     so the user icon lines up with the other rail values. */
  .wi-rail .rail-assignees {
    padding: 0;
  }
  .wi-rail .rail-assignees .inline-assignee-trigger {
    margin: 0;
  }
  .wi-rail .rail-assignees .inline-assignee-wrapper {
    width: 100%;
  }
  .wi-rail .rail-sync {
    font-size: var(--rd-text-sm);
    color: var(--rd-fg-muted);
  }
  .wi-rail .rail-sync-link {
    margin-left: auto;
    color: var(--rd-fg-subtle);
    display: inline-flex;
    align-items: center;
  }
  .wi-rail .rail-sync-link:hover { color: var(--rd-accent); }

  /* Inline editable inside the rail: give inputs the full field width */
  .wi-rail .inline-edit-input {
    font: inherit;
    color: var(--rd-fg);
    background: var(--rd-bg-raised);
    border: 1px solid var(--rd-accent);
    border-radius: var(--rd-radius-sm);
    outline: none;
    padding: 4px 6px;
    width: 100%;
  }

  /* --- Shared section editing chrome --- */
  .wi-section-editing-pill {
    margin-left: 8px;
    font-size: var(--rd-text-2xs);
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 1px 8px;
    background: var(--rd-accent-soft);
    color: var(--rd-accent);
    border-radius: var(--rd-radius-sm);
  }
  .wi-section-edit-foot {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--rd-border);
  }
  .wi-form-errors {
    padding: 8px 12px;
    margin-bottom: 12px;
    background: var(--rd-danger-soft);
    color: var(--rd-danger);
    border: 1px solid oklch(0.68 0.22 27 / 0.3);
    border-radius: var(--rd-radius-md);
    font-size: var(--rd-text-sm);
  }

  /* --- Custom fields: edit form --- */
  .wi-fields-group-edit + .wi-fields-group-edit {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--rd-border);
  }
  .wi-fields-group-desc {
    font-size: var(--rd-text-xs);
    color: var(--rd-fg-muted);
    margin: 0 0 8px;
  }
  .wi-fields-input-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 10px;
  }
  .wi-fields-input-row:last-child { margin-bottom: 0; }
  .wi-fields-input-label {
    font-size: var(--rd-text-sm);
    font-weight: 500;
    color: var(--rd-fg);
  }
  .wi-fields-input-field input[type="text"],
  .wi-fields-input-field input[type="number"],
  .wi-fields-input-field input[type="date"],
  .wi-fields-input-field select,
  .wi-fields-input-field textarea {
    width: 100%;
    padding: 6px 10px;
    background: var(--rd-bg-raised);
    color: var(--rd-fg);
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-sm);
    font-size: var(--rd-text-sm);
    font-family: inherit;
  }
  .wi-fields-input-field input[type="text"]:focus,
  .wi-fields-input-field input[type="number"]:focus,
  .wi-fields-input-field input[type="date"]:focus,
  .wi-fields-input-field select:focus,
  .wi-fields-input-field textarea:focus {
    outline: none;
    border-color: var(--rd-accent);    transform: none;
  }
  .wi-fields-input-field .form-control {
    padding: 6px 10px;
    background: var(--rd-bg-raised);
    color: var(--rd-fg);
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-sm);
    font-size: var(--rd-text-sm);
    font-weight: 400;
    box-shadow: none;
    transform: none;
  }
  .wi-fields-input-field .form-control::placeholder {
    color: var(--rd-fg-subtle);
    font-weight: 400;
  }
  .wi-fields-input-field select.form-control {
    padding-inline-end: 32px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a4a4a4' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 14px;
  }

  /* Boolean toggle — redesign variant */
  .wi-fields-input-field .toggle-group {
    display: flex;
    gap: 8px;
  }
  .wi-fields-input-field .toggle-option {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--rd-bg-raised);
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-sm);
    color: var(--rd-fg);
    font-size: var(--rd-text-sm);
    cursor: pointer;
    box-shadow: none;
    transform: none;
    transition: background var(--rd-dur-fast) var(--rd-ease),
                border-color var(--rd-dur-fast) var(--rd-ease);
  }
  .wi-fields-input-field .toggle-option:hover {
    background: var(--rd-bg-hover);
  }
  .wi-fields-input-field .toggle-option:has(input:checked) {
    border-color: var(--rd-accent);
    background: var(--rd-accent-soft);
  }
  .wi-fields-input-field .toggle-option input[type="radio"] {
    margin: 0;
    accent-color: var(--rd-accent);
  }
  .wi-fields-input-field .toggle-label {
    font-weight: 500;
  }

  /* Multi-select picker — redesign variant */
  .wi-fields-input-field .multi-select-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .wi-fields-input-field .multi-select-selected {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-height: 0;
    align-items: center;
  }
  .wi-fields-input-field .multi-select-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 4px 3px 10px;
    background: var(--rd-accent-soft);
    color: var(--rd-accent);
    border: 1px solid color-mix(in oklch, var(--rd-accent) 25%, transparent);
    border-radius: var(--rd-radius-sm);
    font-size: var(--rd-text-sm);
    font-weight: 500;
  }
  .wi-fields-input-field .multi-select-tag-name {
    font-weight: 500;
  }
  .wi-fields-input-field .multi-select-tag-remove {
    display: inline-grid;
    place-items: center;
    width: 16px;
    height: 16px;
    padding: 0;
    background: transparent;
    border: 0;
    color: inherit;
    font-size: var(--rd-text-base);
    line-height: 1;
    cursor: pointer;
    border-radius: 0;
    transition: background var(--rd-dur-fast) var(--rd-ease);
  }
  .wi-fields-input-field .multi-select-tag-remove:hover {
    background: color-mix(in oklch, var(--rd-accent) 20%, transparent);
    color: var(--rd-accent);
  }
  .wi-fields-input-field .multi-select-none {
    color: var(--rd-fg-subtle);
    font-style: italic;
    font-size: var(--rd-text-sm);
  }
  .wi-fields-input-field .multi-select-search-wrapper {
    position: relative;
  }
  .wi-fields-input-field .multi-select-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 100;
    max-height: 240px;
    overflow-y: auto;
    background: var(--rd-bg-raised);
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-sm);
    box-shadow: var(--rd-shadow-md);
  }
  .wi-fields-input-field .multi-select-dropdown-item {
    display: block;
    width: 100%;
    padding: 6px 10px;
    background: transparent;
    border: 0;
    text-align: left;
    cursor: pointer;
    font-size: var(--rd-text-sm);
    color: var(--rd-fg);
    transition: background var(--rd-dur-fast) var(--rd-ease);
  }
  .wi-fields-input-field .multi-select-dropdown-item:hover,
  .wi-fields-input-field .multi-select-dropdown-item:focus {
    outline: none;
    background: var(--rd-bg-hover);
  }
  .wi-fields-input-field .multi-select-dropdown-empty {
    padding: 8px 10px;
    text-align: center;
    color: var(--rd-fg-subtle);
    font-style: italic;
    font-size: var(--rd-text-sm);
  }

  /* Combobox dropdown (predictive text) — redesign variant */
  .wi-fields-input-field .combobox {
    position: relative;
    width: 100%;
  }
  .wi-fields-input-field .combobox-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 100;
    max-height: 240px;
    overflow-y: auto;
    margin-top: 0;
    background: var(--rd-bg-raised);
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-sm);
    box-shadow: var(--rd-shadow-md);
  }
  .wi-fields-input-field .combobox-dropdown-item {
    display: block;
    width: 100%;
    padding: 6px 10px;
    background: transparent;
    border: 0;
    text-align: left;
    cursor: pointer;
    font-size: var(--rd-text-sm);
    font-weight: 400;
    color: var(--rd-fg);
    transition: background var(--rd-dur-fast) var(--rd-ease);
  }
  .wi-fields-input-field .combobox-dropdown-item:hover,
  .wi-fields-input-field .combobox-dropdown-item:focus,
  .wi-fields-input-field .combobox-dropdown-item--selected {
    outline: none;
    background: var(--rd-bg-hover);
  }
  .wi-fields-input-field .combobox-dropdown-empty {
    padding: 8px 10px;
    text-align: center;
    color: var(--rd-fg-subtle);
    font-style: italic;
    font-size: var(--rd-text-sm);
  }

  /* --- Dependencies: remove button + add search --- */
  .wi-deps-remove-form {
    display: inline-flex;
    margin: 0;
    padding: 0;
  }
  .wi-deps-remove {
    margin-left: auto;
    width: 22px;
    height: 22px;
    display: inline-grid;
    place-items: center;
    background: transparent;
    border: 0;
    color: var(--rd-fg-subtle);
    border-radius: var(--rd-radius-sm);
    cursor: pointer;
    transition: background var(--rd-dur-fast) var(--rd-ease),
                color var(--rd-dur-fast) var(--rd-ease);
  }
  .wi-deps-remove:hover {
    background: var(--rd-danger-soft);
    color: var(--rd-danger);
  }

  .wi-deps-add {
    margin-top: 8px;
    position: relative;
  }
  .wi-deps-add-input-wrap {
    position: relative;
  }
  .wi-deps-add-hint {
    margin: 6px 2px 0;
    font-size: var(--rd-text-xs);
    color: var(--rd-fg-subtle);
    font-style: italic;
  }
  .wi-deps-add-input {
    width: 100%;
    padding: 6px 10px;
    background: var(--rd-bg-raised);
    color: var(--rd-fg);
    border: 1px dashed var(--rd-border-strong);
    border-radius: var(--rd-radius-md);
    font-size: var(--rd-text-sm);
    font-family: inherit;
  }
  .wi-deps-add-input::placeholder { color: var(--rd-fg-subtle); }
  .wi-deps-add-input:focus {
    outline: none;
    border-style: solid;
    border-color: var(--rd-accent);  }
  .wi-deps-add-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 20;
    background: var(--rd-bg-raised);
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-md);
    box-shadow: var(--rd-shadow-pop);
    max-height: 260px;
    overflow-y: auto;
    padding: 4px;
  }
  .wi-deps-add-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 6px 8px;
    background: transparent;
    border: 0;
    border-radius: var(--rd-radius-sm);
    cursor: pointer;
    text-align: left;
    font-size: var(--rd-text-sm);
    color: var(--rd-fg);
  }
  .wi-deps-add-item:hover,
  .wi-deps-add-item.is-active {
    background: var(--rd-bg-hover);
  }
  .wi-deps-add-item.is-active {
    background: var(--rd-accent-soft);
  }
  .wi-deps-add-item-title {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .wi-deps-add-empty {
    padding: 10px 12px;
    font-size: var(--rd-text-sm);
    color: var(--rd-fg-subtle);
    font-style: italic;
  }
  .wi-deps-readonly-hint {
    font-size: var(--rd-text-xs);
    color: var(--rd-fg-subtle);
    font-style: italic;
    margin: 6px 0 0;
  }

  /* --- Financials: edit form chrome --- */
  .wi-finances-form .form-section {
    border: 0;
    background: transparent;
    padding: 0;
  }
  .wi-finances-form .form-section h2 {
    font-size: var(--rd-text-sm);
    font-weight: 600;
    color: var(--rd-fg);
    margin: 0 0 4px;
  }
  .wi-finances-form .form-section-help {
    font-size: var(--rd-text-xs);
    color: var(--rd-fg-muted);
    margin: 0 0 10px;
  }
  .wi-finances-form .allocation-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
  }
  .wi-finances-form .allocation-row-fields {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 110px 110px auto;
    gap: 8px;
    width: 100%;
    align-items: center;
  }
  .wi-finances-form .form-select,
  .wi-finances-form .form-control {
    width: 100%;
    padding: 6px 10px;
    background: var(--rd-bg-raised);
    color: var(--rd-fg);
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-sm);
    font-size: var(--rd-text-sm);
    font-family: inherit;
  }
  .wi-finances-form .form-select:focus,
  .wi-finances-form .form-control:focus {
    outline: none;
    border-color: var(--rd-accent);  }
  .wi-finances-form .allocation-empty-state {
    padding: 10px 0;
    font-size: var(--rd-text-sm);
    color: var(--rd-fg-subtle);
    font-style: italic;
  }
  .wi-finances-form .allocation-summary {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--rd-border);
  }
  .wi-finances-form .allocation-totals {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: var(--rd-text-sm);
    color: var(--rd-fg-muted);
    margin-top: 6px;
  }
  .wi-finances-form .allocation-total-label {
    color: var(--rd-fg-subtle);
    margin-right: 4px;
  }
  .wi-finances-form .allocation-total-value {
    color: var(--rd-fg);
    font-family: var(--rd-font-mono);
    font-variant-numeric: tabular-nums;
  }
  .wi-finances-form .btn {
    padding: 4px 10px;
    font-size: var(--rd-text-xs);
    font-weight: 500;
    border-radius: var(--rd-radius-sm);
    border: 1px solid var(--rd-border);
    background: var(--rd-bg-raised);
    color: var(--rd-fg);
    cursor: pointer;
  }
  .wi-finances-form .btn:hover { background: var(--rd-bg-hover); }

  /* --- Focus overlay --- */
  .wi-overlay-bg {
    position: fixed;
    inset: 0;
    background: oklch(0.1 0.008 250 / 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 40;
    animation: wi-overlay-fade 180ms var(--rd-ease);
  }
  @keyframes wi-overlay-fade {
    from { opacity: 0; }
    to   { opacity: 1; }
  }

  .wi-overlay {
    position: fixed;
    top: 32px;
    left: 50%;
    transform: translateX(-50%);
    /* Match the page content max-width so focus mode is at least as roomy
       as the inline (in-table) expansion. */
    width: min(1560px, calc(100vw - 64px));
    max-height: calc(100vh - 64px);
    background: var(--rd-bg-sunken);
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-xl);
    box-shadow: var(--rd-shadow-pop);
    z-index: 41;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: wi-overlay-in 220ms var(--rd-ease);
  }
  @keyframes wi-overlay-in {
    from { opacity: 0; transform: translate(-50%, 8px) scale(0.98); }
    to   { opacity: 1; transform: translate(-50%, 0) scale(1); }
  }

  .wi-overlay-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--rd-border);
    flex: 0 0 auto;
  }
  .wi-overlay-title {
    font-size: var(--rd-text-sm);
    font-weight: 600;
    color: var(--rd-fg-muted);
    letter-spacing: 0.02em;
  }
  .wi-overlay-head-actions {
    margin-left: auto;
    display: inline-flex;
    gap: 4px;
  }

  .wi-overlay-body {
    overflow-y: auto;
    flex: 1;
    min-height: 0;
  }
  /* Overlay's detail panel: wider rail, more generous padding, no
     entrance animation (already inherited from .wi-overlay). */
  .wi-overlay-body .wi-detail {
    grid-template-columns: minmax(0, 1fr) 340px;
    animation: none;
  }
  .wi-overlay-body .wi-main { padding: 24px 28px 32px; }
  .wi-overlay-body .wi-rail { padding: 22px 22px 32px; }

  @media (max-width: 900px) {
    .wi-overlay {
      top: 16px;
      width: calc(100vw - 32px);
      max-height: calc(100vh - 32px);
    }
    .wi-overlay-body .wi-detail { grid-template-columns: 1fr; }
    .wi-overlay-body .wi-main,
    .wi-overlay-body .wi-rail { padding: 20px 22px; }
  }

  /* ------------------------------------------------------------------ */
  /* Embedded forms (schedule mode + fee allocations) inside wi-section  */
  /* ------------------------------------------------------------------ */
  .wi-section-schedule .wi-section-head-note {
    margin-left: auto;
    font-size: var(--rd-text-2xs);
    color: var(--rd-fg-subtle);
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }

  /* The reused _form_section partial wraps itself in a heavy comic-card
     form-section. Flatten that styling so it blends into the slim panel.
     (The schedule editor renders its form directly — no form-section.) */
  .wi-section-finances .form-section {
    background: transparent;
    border: 0;
    box-shadow: none;
    padding: 0;
    margin: 0;
    transform: none;
  }
  .wi-section-finances .form-section:hover {
    transform: none;
    box-shadow: none;
  }
  .wi-section-finances .form-section > h2 {
    display: none;
  }
  .wi-section-finances .form-section .form-section-help {
    margin-bottom: 10px;
    font-size: var(--rd-text-xs);
    color: var(--rd-fg-muted);
  }

  /* Schedule mode: top-row mode select */
  .wi-section-schedule .wi-schedule-mode-row {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
  }
  .wi-section-schedule .wi-schedule-label {
    font-size: var(--rd-text-2xs);
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--rd-fg-subtle);
    margin: 0;
  }
  .wi-section-schedule .form-select,
  .wi-section-schedule .form-control {
    background: var(--rd-bg);
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-sm);
    color: var(--rd-fg);
    font-size: var(--rd-text-sm);
    padding: 6px 10px;
    width: 100%;
    box-shadow: none;
    transform: none;
    font-weight: 400;
  }
  .wi-section-schedule .form-select:focus,
  .wi-section-schedule .form-control:focus {
    outline: none;
    border-color: var(--rd-accent);    transform: none;
  }
  .wi-section-schedule .wi-schedule-info {
    margin-top: 10px;
    padding: 8px 10px;
    background: var(--rd-bg-raised);
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-md);
    font-size: var(--rd-text-xs);
    color: var(--rd-fg-muted);
  }
  .wi-section-schedule .wi-schedule-info strong {
    color: var(--rd-fg);
    font-weight: 600;
    font-family: var(--rd-font-mono);
    font-variant-numeric: tabular-nums;
  }

  /* Re-skin the allocation table so it fits a tight panel */
  .wi-section-schedule .allocation-table-container {
    margin-top: 12px;
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-md);
    overflow: hidden;
    background: var(--rd-bg-raised);
  }
  .wi-section-schedule .allocation-table {
    border: 0;
    box-shadow: none;
    background: transparent;
    margin: 0;
    width: 100%;
    table-layout: fixed;
  }
  .wi-section-schedule .allocation-table thead tr {
    background: var(--rd-bg-sunken, var(--rd-bg));
    color: var(--rd-fg-subtle);
  }
  .wi-section-schedule .allocation-table th {
    padding: 8px 14px;
    font-size: var(--rd-text-2xs);
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--rd-border);
    text-align: left;
    vertical-align: middle;
  }
  .wi-section-schedule .allocation-table tbody td {
    padding: 8px 14px;
    border-top: 1px solid var(--rd-border);
    font-size: var(--rd-text-sm);
    vertical-align: middle;
  }
  .wi-section-schedule .allocation-table tbody tr:first-child td { border-top: 0; }
  .wi-section-schedule .allocation-table tbody tr:hover { background: var(--rd-bg-hover); }

  /* Assignee column: avatar + name on a single baseline.
     Use an inline-flex wrapper so the td keeps its table-cell layout
     (padding + vertical-align), and the avatar/name stay on one row. */
  .wi-section-schedule .allocation-member {
    min-width: 0;
  }
  .wi-section-schedule .allocation-member-inner {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    max-width: 100%;
  }
  .wi-section-schedule .allocation-member .rd-av {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 0;
    margin: 0;
    font-size: var(--rd-text-2xs);
    font-weight: 600;
    color: #fff;
    display: grid;
    place-items: center;
    background: var(--rd-fg-faint);
    flex: 0 0 auto;
  }
  .wi-section-schedule .allocation-member .member-name {
    font-weight: 500;
    color: var(--rd-fg);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
  }

  /* Hours / percentage / appetite columns share the same input chrome */
  .wi-section-schedule .allocation-hours,
  .wi-section-schedule .allocation-percentage { width: 150px; }
  .wi-section-schedule .allocation-appetite { width: 170px; }

  .wi-section-schedule .input-with-suffix {
    display: flex;
    align-items: stretch;
    width: 100%;
    height: 30px;
  }
  .wi-section-schedule .input-with-suffix input,
  .wi-section-schedule .input-with-suffix .form-control {
    width: 100%;
    flex: 1 1 auto;
    border: 1px solid var(--rd-border);
    border-right: 0;
    border-radius: var(--rd-radius-sm) 0 0 var(--rd-radius-sm);
    background: var(--rd-bg);
    color: var(--rd-fg);
    font-size: var(--rd-text-sm);
    font-weight: 400;
    padding: 0 8px;
    box-shadow: none;
    transform: none;
    margin: 0;
    min-width: 0;
    height: 100%;
    line-height: 1;
  }
  .wi-section-schedule .input-with-suffix input:focus,
  .wi-section-schedule .input-with-suffix .form-control:focus {
    outline: none;
    border-color: var(--rd-accent);    transform: none;
    z-index: 1;
    position: relative;
  }
  .wi-section-schedule .input-with-suffix .input-suffix {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin: 0;
    width: 36px;
    height: 100%;
    background: var(--rd-bg-raised);
    border: 1px solid var(--rd-border);
    border-left: 0;
    border-radius: 0 var(--rd-radius-sm) var(--rd-radius-sm) 0;
    box-shadow: none;
    color: var(--rd-fg-subtle);
    font-size: var(--rd-text-xs);
    font-weight: 500;
    text-transform: lowercase;
    letter-spacing: 0;
    flex: 0 0 auto;
  }

  /* Appetite override dropdown: match the schedule input chrome so it
     doesn't fall back to the global `.rd-select` raised bg + larger radius. */
  .wi-section-schedule .allocation-appetite .rd-select,
  .wi-section-schedule .allocation-appetite select.form-select,
  .wi-section-schedule select.form-select-sm {
    width: 100%;
    height: 30px;
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-sm);
    background-color: var(--rd-bg);
    color: var(--rd-fg);
    font-size: var(--rd-text-sm);
    padding: 0 28px 0 10px;
    box-shadow: none;
    transform: none;
    font-weight: 400;
    line-height: 1;
  }

  .wi-section-schedule .allocation-total-bar {
    background: var(--rd-bg-sunken, var(--rd-bg));
    border: 0;
    border-top: 1px solid var(--rd-border);
    box-shadow: none;
    padding: 8px 12px;
    font-size: var(--rd-text-xs);
    color: var(--rd-fg-muted);
    font-weight: 500;
  }
  .wi-section-schedule .allocation-total-value {
    color: var(--rd-fg);
    font-family: var(--rd-font-mono);
    font-variant-numeric: tabular-nums;
    font-weight: 600;
  }


  /* Fee allocation editor scoping inside wi-section-finances.
     The editor stays narrow — a row with a cost-center select, a percent
     input, the resolved amount, and a remove button doesn't earn full panel
     width. Capping it keeps the controls grouped instead of floating apart. */
  .wi-section-finances .allocation-rows {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 12px;
    max-width: 560px;
  }
  .wi-section-finances .allocation-row {
    background: var(--rd-bg-raised);
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-md);
    padding: 8px 12px;
  }
  .wi-section-finances .allocation-row-fields {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 96px 96px 28px;
    gap: 10px;
    align-items: center;
  }
  .wi-section-finances .allocation-row-cost-center .rd-select {
    width: 100%;
  }
  /* On narrow panels (mobile inline detail or stacked rail) the four-column
     grid becomes too tight; let the cost-center select span the full row. */
  @media (max-width: 560px) {
    .wi-section-finances .allocation-row-fields {
      grid-template-columns: minmax(0, 1fr) auto 28px;
      grid-template-rows: auto auto;
      row-gap: 8px;
    }
    .wi-section-finances .allocation-row-cost-center {
      grid-column: 1 / -1;
    }
  }
  .wi-section-finances .allocation-row-actions {
    width: auto;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .wi-section-finances .allocation-row-actions .rd-btn-ghost {
    width: 24px;
    height: 24px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--rd-fg-subtle);
    background: transparent;
    border: 0;
  }
  .wi-section-finances .allocation-row-actions .rd-btn-ghost:hover {
    color: var(--rd-danger);
    background: var(--rd-bg-hover);
    border-radius: var(--rd-radius-sm);
  }
  .wi-section-finances .allocation-row .form-select,
  .wi-section-finances .allocation-row .form-control {
    background: var(--rd-bg);
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-sm);
    color: var(--rd-fg);
    font-size: var(--rd-text-sm);
    padding: 5px 8px;
    box-shadow: none;
    transform: none;
    width: 100%;
    font-weight: 400;
  }
  .wi-section-finances .allocation-row .form-select:focus,
  .wi-section-finances .allocation-row .form-control:focus {
    outline: none;
    border-color: var(--rd-accent);    transform: none;
  }
  /* Percentage column shares the schedule-table suffix chrome */
  .wi-section-finances .allocation-row .input-with-suffix {
    display: inline-flex;
    align-items: stretch;
    width: 100%;
  }
  .wi-section-finances .allocation-row .input-with-suffix input,
  .wi-section-finances .allocation-row .input-with-suffix .form-control {
    border: 1px solid var(--rd-border);
    border-right: 0;
    border-radius: var(--rd-radius-sm) 0 0 var(--rd-radius-sm);
    width: 100%;
    flex: 1 1 auto;
    margin: 0;
    min-width: 0;
  }
  .wi-section-finances .allocation-row .input-with-suffix .input-suffix {
    display: inline-flex;
    align-items: center;
    padding: 0 8px;
    margin: 0;
    background: var(--rd-bg-raised);
    border: 1px solid var(--rd-border);
    border-left: 0;
    border-radius: 0 var(--rd-radius-sm) var(--rd-radius-sm) 0;
    box-shadow: none;
    color: var(--rd-fg-subtle);
    font-size: var(--rd-text-xs);
    font-weight: 500;
    text-transform: lowercase;
    letter-spacing: 0;
  }
  .wi-section-finances .allocation-row-amount {
    width: auto;
    text-align: right;
    padding-right: 4px;
    font-family: var(--rd-font-mono);
    font-variant-numeric: tabular-nums;
    font-size: var(--rd-text-sm);
    color: var(--rd-fg);
  }
  .wi-section-finances .allocation-empty-state {
    padding: 10px 12px;
    border: 1px dashed var(--rd-border);
    border-radius: var(--rd-radius-md);
    margin-top: 10px;
    color: var(--rd-fg-muted);
    font-size: var(--rd-text-sm);
    max-width: 560px;
  }
  .wi-section-finances .allocation-summary {
    margin-top: 14px;
    padding: 10px 12px;
    background: transparent;
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-md);
    max-width: 560px;
  }
  .wi-section-finances .allocation-totals {
    display: flex;
    justify-content: space-between;
    font-size: var(--rd-text-xs);
    color: var(--rd-fg-muted);
    margin-top: 8px;
  }
  .wi-section-finances .allocation-total-value {
    color: var(--rd-fg);
    font-family: var(--rd-font-mono);
    font-variant-numeric: tabular-nums;
  }
  .wi-section-finances .progress-bar {
    background: var(--rd-bg-raised);
    border: 1px solid var(--rd-border);
    border-radius: 999px;
    height: 6px;
    overflow: hidden;
    box-shadow: none;
    margin-top: 0;
    margin-bottom: 0;
  }
  .wi-section-finances .progress-segment {
    height: 100%;
    border-radius: 999px;
    transition: width 0.2s ease;
  }
  .wi-section-finances .progress-segment-blue,
  .wi-section-finances .progress-segment-positive {
    background: var(--rd-accent);
  }
  .wi-section-finances .progress-segment-positive {
    background: var(--rd-success);
  }
  .wi-section-finances .btn.btn-secondary,
  .wi-section-finances .btn.btn-sm,
  .wi-section-schedule .btn.btn-secondary,
  .wi-section-schedule .btn.btn-sm {
    background: var(--rd-bg-raised);
    color: var(--rd-fg);
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-sm);
    padding: 4px 10px;
    font-size: var(--rd-text-xs);
    box-shadow: none;
    transform: none;
    text-transform: none;
    letter-spacing: normal;
    font-weight: 500;
    margin-top: 8px;
  }
  .wi-section-finances .btn.btn-ghost,
  .wi-section-schedule .btn.btn-ghost {
    background: transparent;
    border: 0;
    color: var(--rd-fg-subtle);
    padding: 0 4px;
    box-shadow: none;
  }
  .wi-section-finances .btn.btn-ghost:hover,
  .wi-section-schedule .btn.btn-ghost:hover {
    color: var(--rd-danger);
    background: transparent;
  }

  /* Tighten the locked-notice callout so it doesn't shout inside the panel */
  .wi-section-finances .rd-callout {
    padding: 8px 10px;
    margin-top: 10px;
    font-size: var(--rd-text-xs);
    line-height: var(--rd-leading-snug);
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }
  .wi-section-finances .form-section-help .rd-badge {
    font-size: var(--rd-text-2xs);
    padding: 1px 6px;
    margin-left: 6px;
    vertical-align: middle;
  }

  /* Allocation warning callout inside the panel */
  .wi-section-schedule .allocation-warning .callout {
    margin-top: 10px;
    padding: 8px 10px;
    background: var(--rd-warning-soft, oklch(0.95 0.06 80));
    color: var(--rd-warning, oklch(0.55 0.18 75));
    border: 1px solid var(--rd-border);
    border-radius: var(--rd-radius-sm);
    font-size: var(--rd-text-xs);
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }

  .wi-section-edit-foot-inline {
    margin-top: 12px;
    padding-top: 10px;
  }
}

/* Body lock when overlay is open — outside @layer so it wins against any
   layered utility rules. */
body.wi-overlay-open {
  overflow: hidden;
}
