/* Modal for moving a whole pack of works (/shared/js/order-phase-modal.js).
   Shared by both panels: the pack is moved from the admin card and from the workplace.
   The project has no common .modal-backdrop rule — every modal describes its own
   backdrop, so it is written out here in full.
   Dark theme is named differently: admin — admin-theme-dark, workplace — dark-theme. */

body .modal-backdrop.order-phase-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    display: flex;
    justify-content: center;
    align-items: center;
    /* Above the job order with the tooth chart (12000) and the picker (12500). */
    z-index: 12600;
    padding: 16px;
    /* Blocked row tint and the warning strip are derived from danger. */
    --op-danger-tint: rgba(255, 77, 79, 0.07);
    --op-danger-border: rgba(255, 77, 79, 0.28);
}

body.admin-theme-dark .modal-backdrop.order-phase-backdrop,
body.dark-theme .modal-backdrop.order-phase-backdrop {
    --op-danger-tint: rgba(248, 113, 113, 0.10);
    --op-danger-border: rgba(248, 113, 113, 0.30);
}

body .modal-backdrop.order-phase-backdrop > .modal.order-phase-modal {
    display: flex;
    flex-direction: column;
    width: min(760px, 100%);
    max-height: min(90vh, 780px);
    overflow: hidden;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-table, 10px);
    background: var(--color-bg-surface);
    color: var(--color-text-primary);
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.18);
    text-align: left;
}

body.admin-theme-dark .modal-backdrop.order-phase-backdrop > .modal.order-phase-modal,
body.dark-theme .modal-backdrop.order-phase-backdrop > .modal.order-phase-modal {
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
}

/* Header: the action on the left, the size of the pack on the right. */
body .modal-backdrop.order-phase-backdrop .modal-header {
    display: flex;
    align-items: baseline;
    gap: 12px;
    flex: none;
    padding: 13px 16px 12px;
    border-bottom: 1px solid var(--color-divider-soft, var(--color-border));
    font-size: 15px;
    font-weight: 600;
}

.order-phase-count {
    margin-left: auto;
    font-size: 12px;
    font-weight: 400;
    color: var(--color-text-muted);
    white-space: nowrap;
}

body .modal-backdrop.order-phase-backdrop .modal-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1 1 auto;
    min-height: 0;
    padding: 12px 16px 14px;
    overflow-y: auto;
    /* Room for the scrollbar so fields are not cut off. */
    scrollbar-gutter: stable;
}

body .modal-backdrop.order-phase-backdrop .modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    flex: none;
    padding: 10px 16px;
    border-top: 1px solid var(--color-divider-soft, var(--color-border));
    background: var(--color-bg-surface-alt);
}

body .modal-backdrop.order-phase-backdrop .modal-footer .btn { margin: 0; }
body .modal-backdrop.order-phase-backdrop .modal-footer .btn:disabled {
    opacity: .45;
    cursor: not-allowed;
}

.order-phase-hint {
    margin: 0;
    font-size: 12px;
    color: var(--color-text-muted);
}

/* Section card: frame plus head. Three type levels — SECTION (11px caps),
   field label (11.5px muted), content (13px primary). */
.order-phase-card {
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-bg-surface-alt);
}
.order-phase-card[hidden] { display: none; }

.order-phase-card__head {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 34px;
    padding: 5px 12px;
    border-bottom: 1px solid var(--color-divider-soft, var(--color-border));
}

.order-phase-cap {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-text-muted);
    white-space: nowrap;
}

.order-phase-card__note {
    margin-left: auto;
    min-width: 0;
    font-size: 11.5px;
    color: var(--color-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.order-phase-card__body { padding: 10px 12px; }

/* Target of the move: two halves of one card with an «or» fork between them.
   The half that is not chosen dims — the two ways are mutually exclusive. */
.order-phase-target__half { padding: 9px 12px 10px; }
.order-phase-target__half[hidden] { display: none; }
.order-phase-target__half + .order-phase-target__half {
    position: relative;
    border-top: 1px solid var(--color-divider-soft, var(--color-border));
}
.order-phase-target__or {
    position: absolute;
    top: -9px;
    left: 12px;
    height: 17px;
    padding: 0 7px;
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--color-border);
    border-radius: 999px;
    background: var(--color-bg-surface-alt);
    font-size: 10px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--color-text-muted);
}
.order-phase-target__lbl {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 7px;
    margin-bottom: 8px;
}
.order-phase-target__lbl b {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-primary);
}
.order-phase-target__lbl span {
    font-size: 11.5px;
    color: var(--color-text-muted);
}
.order-phase-target__half.is-off { opacity: 0.4; }

/* Phase route: chips with arrows between them, cancel stands aside after «↷».
   States: current (all works are here), reachable, partial, no transition. */
.order-phase-route {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 6px 3px;
}
/* A chip never shrinks below its own name: when the width runs out the route
   wraps to the next line instead of scrolling sideways. */
.order-phase-step {
    --ph: var(--color-bg-surface);
    --ph-fg: var(--color-text-primary);
    flex: 0 1 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    min-height: 42px;
    padding: 5px 7px;
    border: 1px solid transparent;
    border-radius: 7px;
    background: var(--ph);
    color: var(--ph-fg);
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.15;
    text-align: center;
    cursor: pointer;
}
.order-phase-step__cap {
    font-size: 10px;
    font-weight: 400;
    opacity: 0.82;
    white-space: nowrap;
}
.order-phase-step.is-pending { opacity: .6; cursor: progress; }
.order-phase-step.is-current { box-shadow: 0 0 0 1px var(--color-bg-surface-alt), 0 0 0 2px var(--color-text-muted); }
.order-phase-step.is-current:disabled { cursor: default; }
.order-phase-step.is-reachable:hover { filter: brightness(1.06); }
.order-phase-step.is-partial { border-color: var(--ph-fg); border-style: dashed; }
.order-phase-step.is-blocked { opacity: .32; cursor: not-allowed; filter: grayscale(.4); }
.order-phase-step.is-active { box-shadow: 0 0 0 1px var(--color-bg-surface-alt), 0 0 0 3px var(--color-accent); }
.order-phase-step.is-active .order-phase-step__cap { opacity: 1; }

.order-phase-route__arrow,
.order-phase-route__aside {
    align-self: center;
    flex: none;
    padding: 0 1px;
    font-size: 11px;
    color: var(--color-text-muted);
}
.order-phase-route__aside { margin-left: 8px; }
/* Cancel stands aside but wraps together with its own arrow. */
.order-phase-route__cancel {
    display: inline-flex;
    align-items: stretch;
    gap: 3px;
}

/* Stage tiles sit by their content, not in a grid of equally wide cells.
   Same control as the single-work transition modal. */
.order-phase-stages {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.stage-tile {
    --ph: var(--color-bg-surface);
    --ph-fg: var(--color-text-primary);
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    min-height: 38px;
    padding: 5px 12px;
    border: 1px solid transparent;
    border-radius: 7px;
    background: var(--ph);
    color: var(--ph-fg);
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.15;
    text-align: center;
    cursor: pointer;
    min-width: 0;
}
.stage-tile small { font-size: 10px; font-weight: 500; opacity: .8; white-space: nowrap; }
.stage-tile:hover { filter: brightness(1.06); }
.stage-tile.is-active { box-shadow: 0 0 0 1px var(--color-bg-surface-alt), 0 0 0 3px var(--color-accent); }
.stage-tile--current { background: transparent; color: var(--color-text-primary); border: 1px dashed var(--color-text-muted); cursor: default; }
.stage-tile--current:hover { filter: none; }
.stage-tile--current small { color: var(--color-text-muted); opacity: 1; }

/* Preview */
.order-phase-result.is-loading { opacity: .55; transition: opacity .12s ease; pointer-events: none; }

.order-phase-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.order-phase-table th {
    padding: 0 8px 5px;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    text-align: left;
    color: var(--color-text-muted);
    border-bottom: 1px solid var(--color-divider-soft, var(--color-border));
}
.order-phase-table td {
    padding: 3px 8px;
    border-bottom: 1px solid var(--color-divider-soft, var(--color-border));
    vertical-align: middle;
}
.order-phase-table tr:last-child td { border-bottom: 0; }
.order-phase-table th:first-child,
.order-phase-table td:first-child { width: 34px; padding-left: 2px; }
.order-phase-table .switch { margin: 0; }

.order-phase-num {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    color: var(--color-text-muted);
}
.order-phase-from { color: var(--color-text-muted); }
.order-phase-to { font-weight: 500; }
.order-phase-to i {
    font-style: normal;
    margin-right: 5px;
    font-weight: 400;
    color: var(--color-text-muted);
}
.order-phase-same { color: var(--color-text-muted); }
.order-phase-table tr.is-blocked td { background: var(--op-danger-tint); }
.order-phase-table tr.is-blocked td:first-child { box-shadow: inset 2px 0 0 var(--color-danger); }
.order-phase-blocked { color: var(--color-danger); font-size: 12px; }

.order-phase-warn {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 8px 0 0;
    padding: 7px 10px;
    border: 1px solid var(--op-danger-border);
    border-radius: 6px;
    background: var(--op-danger-tint);
    font-size: 12px;
    line-height: 1.4;
    color: var(--color-danger);
}
.order-phase-warn svg { flex: none; margin-top: 1px; }

/* Segmented switches: rectangular and framed, like a field — not a floating pill. */
.order-phase-seg {
    display: inline-flex;
    gap: 2px;
    padding: 2px;
    border: 1px solid var(--color-border);
    border-radius: 7px;
    background: var(--color-bg-subtle, var(--color-bg-surface));
}
.order-phase-seg > button {
    height: 24px;
    padding: 0 11px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    font: inherit;
    font-size: 12px;
    color: var(--color-text-muted);
    white-space: nowrap;
    cursor: pointer;
}
.order-phase-seg > button:hover { color: var(--color-text-primary); }
.order-phase-seg > button.is-active {
    background: var(--color-accent);
    color: var(--color-on-accent);
    font-weight: 500;
}
.order-phase-seg--head { margin-left: auto; }
.order-phase-seg--fill { display: flex; width: 100%; }
.order-phase-seg--fill > button { flex: 1 1 0; padding: 0 6px; }

/* Plan fields: one grid, one step, labels above the controls. */
.order-phase-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: start;
    gap: 12px 14px;
    margin-top: 10px;
}
.order-phase-grid[hidden] { display: none; }
.order-phase-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}
.order-phase-field[hidden] { display: none; }
.order-phase-card__body > .order-phase-field { margin-top: 10px; }
.order-phase-lbl {
    display: block;
    font-size: 11.5px;
    color: var(--color-text-muted);
}
.order-phase-note[hidden] { display: none; }
.order-phase-note {
    display: flex;
    align-items: center;
    min-height: 30px;
    font-size: 12px;
    color: var(--color-text-muted);
}

/* Date field: the calendar button lives inside the input, not as a square beside it. */
.order-phase-modal .dmy-date-field { position: relative; display: block; }
.order-phase-modal .dmy-date-field .form-control {
    width: 100%;
    padding: 0 34px 0 10px;
    font-variant-numeric: tabular-nums;
}
.order-phase-modal .dmy-date-field .dmy-date-calendar-btn {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 26px;
    height: 26px;
    min-width: 0;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: var(--color-text-muted);
}
.order-phase-modal .dmy-date-field .dmy-date-calendar-btn:hover {
    background: var(--color-bg-hover);
    color: var(--color-text-primary);
}

.order-phase-modal .form-control {
    height: 30px;
    margin: 0;
    padding: 0 10px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-bg-surface);
    color: var(--color-text-primary);
    font: inherit;
    font-size: 13px;
}

/* Time wheels keep their own component; here they only get the field's rhythm. */
.order-phase-modal .courier-trip-wheels-xaxis { gap: 8px; }
.order-phase-modal .courier-trip-wheels-xaxis[hidden] { display: none; }
.order-phase-modal .time-wheel-host { margin-top: 2px; }

.order-phase-switchrow {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 30px;
    font-size: 13px;
}
.order-phase-switchrow .switch { margin: 0; }
