/* Motion Profile Calculator (templates/tools/motion_profile.html, issue #165).
   The charts themselves are styled by plot-engine.css; this file covers the
   input grid, the results and the phase colours. */

:root {
    --mp-band-accel: rgba(251,191,36,0.07);
    --mp-band-decel: rgba(148,163,184,0.085);
    --mp-band-dwell: rgba(255,255,255,0.03);
    --mp-seg-accel: rgba(251,191,36,0.17);
    --mp-seg-cruise: rgba(255,255,255,0.045);
    --mp-seg-decel: rgba(148,163,184,0.2);
    --mp-seg-dwell: rgba(255,255,255,0.06);
}
[data-theme="light"] {
    --mp-band-accel: rgba(245,158,11,0.085);
    --mp-band-decel: rgba(100,116,139,0.09);
    --mp-band-dwell: rgba(26,26,46,0.04);
    --mp-seg-accel: rgba(245,158,11,0.22);
    --mp-seg-cruise: rgba(26,26,46,0.05);
    --mp-seg-decel: rgba(100,116,139,0.22);
    --mp-seg-dwell: rgba(26,26,46,0.08);
}

/* Linear | Rotary switch in the section header */
.mp-seg {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-input);
}
.mp-seg button {
    font: 500 var(--text-sm) var(--font-body);
    color: var(--fg-muted);
    background: transparent;
    border: 0;
    padding: 4px 10px;
    cursor: pointer;
}
.mp-seg button + button { border-left: 1px solid var(--border); }
.mp-seg button[aria-checked="true"] { background: var(--accent-subtle); color: var(--accent-text); }
.mp-seg button:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -2px; }

/* Solve for: a row of three tabs above the Move card. On a phone they
   take the full width, in three equal segments. */
.mp-solve-station { margin-bottom: 0.625rem; }
.mp-solve-row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.mp-solve-lead { font-size: var(--text-sm); font-weight: 500; color: var(--fg-secondary); }
.mp-solve button { padding: 6px 14px; }
@media (max-width: 640px) {
    .mp-solve { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); flex: 1 1 100%; }
    .mp-solve button { padding: 6px 4px; }
}
/* The answer comes first in Results, marked as the answer. */
.mp-out.is-solved { order: -1; }
.mp-out.is-solved .value-field-inner { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-subtle); }
.mp-out.is-solved .mp-cap { color: var(--accent-text); }
/* Disabled on the Acceleration tab (one acceleration for both ramps) and
   Low jerk on either solve tab. */
.mp-cell.is-off .value-field-inner { opacity: 0.55; }
.mp-presets button:disabled { color: var(--fg-muted); cursor: not-allowed; opacity: 0.55; }
.mp-presets button:disabled:hover { color: var(--fg-muted); background: var(--bg-input); }

/* Inputs: a strict grid, sized by the card (the sidebar makes the viewport
   a poor guide). Two columns when narrow, the two-row layout when wide:
     Distance | Max speed | Acceleration | Deceleration
     Presets  | Jerk      | Smoothing    | Dwell                              */
#mp-move, #mp-results .stn-card { container-type: inline-size; }
.mp-fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.875rem;
    align-items: start;
}
.mp-cell { min-width: 0; }
.mp-cell .value-field, .mp-out .value-field { margin-bottom: 0; }
.mp-cell--presets, .mp-cell--smoothing { grid-column: 1 / -1; }
/* Narrow: Dwell sits beside Jerk and Smoothing takes the full row below. */
.mp-cell--smoothing { order: 1; }
@container (min-width: 700px) {
    .mp-fields { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .mp-cell--presets { grid-column: 1; grid-row: 2; align-self: stretch; }
    .mp-cell--jerk { grid-column: 2; grid-row: 2; }
    .mp-cell--smoothing { grid-column: 3; grid-row: 2; order: 0; }
    .mp-cell--dwell { grid-column: 4; grid-row: 2; }
}

/* Smoothing is not a value_field include (it holds a slider), but it has to
   sit in the same grid and look the same. */
.mp-field label {
    display: block;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--fg-secondary);
    margin-bottom: 4px;
}
.mp-field-inner {
    display: flex;
    align-items: stretch;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    overflow: hidden;
    transition: all 0.2s cubic-bezier(.16,1,.3,1);
}
.mp-field-inner:hover { border-color: var(--border-hover); }
.mp-field-inner:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-subtle); }
.mp-field-inner input[type="range"] {
    flex: 1;
    min-width: 0;
    margin: 0 0.25rem 0 0.625rem;
    accent-color: var(--accent-text);
}
.mp-field-inner .mp-smoothing-number { flex: 0 0 3rem; text-align: right; padding-left: 0; padding-right: 0.5rem; }
.mp-unit-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 2.5rem;
    border-left: 1px solid var(--border);
    background: rgba(255,255,255,0.02);
    color: var(--fg-muted);
    font: 500 var(--text-sm) var(--font-mono);
}
[data-theme="light"] .mp-unit-cell { background: rgba(0,0,0,0.03); }
/* Moves per minute has no copy button, so it should not look clickable. */
.mp-plain-output .value-field-input { cursor: default; }

/* Jerk and Smoothing describe the same thing. The one typed last drives;
   the other shows the equivalent, muted and tagged. */
.mp-calc { margin-left: 0.4rem; font-size: var(--text-xs); font-weight: 400; color: var(--fg-muted); }
.is-calculated .value-field-input { color: var(--fg-muted); }
.mp-cell.is-bad .value-field-inner,
.mp-cell.is-bad .mp-field-inner {
    border-color: var(--error-text);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--error-text) 16%, transparent);
}

/* Jerk presets: a 2x2 grid that fills one field cell (label + box). */
.mp-presets {
    height: 100%;
    min-height: 3.75rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-auto-rows: 1fr;
    gap: 1px;
    background: var(--border);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.mp-presets button {
    font: 500 var(--text-sm) var(--font-body);
    color: var(--fg-secondary);
    background: var(--bg-input);
    border: 0;
    padding: 0 6px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mp-presets button:hover { color: var(--fg); background: var(--bg-card); }
.mp-presets button:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -2px; }
.mp-presets button[aria-pressed="true"] { background: var(--accent-subtle); color: var(--accent-text); }

/* The plot. Reserve its height so nothing below moves when the script
   builds it (toolbar + stage + band strip + hint). */
.mp-plot { min-height: calc(clamp(420px, 62vh, 620px) + 106px); }
@media (max-width: 640px) { .mp-plot { min-height: 660px; } }
.plot-band--accel { fill: var(--mp-band-accel); }
.plot-band--decel { fill: var(--mp-band-decel); }
.plot-band--dwell { fill: var(--mp-band-dwell); }
.plot-seg--accel { background: var(--mp-seg-accel); }
.plot-seg--cruise { background: var(--mp-seg-cruise); }
.plot-seg--decel { background: var(--mp-seg-decel); }
.plot-seg--dwell { background: var(--mp-seg-dwell); }

/* Results */
/* An output field carries copy buttons and a unit list, so it needs more
   width than an input: one per row on a phone. */
.mp-outputs {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.75rem 0.875rem;
}
@container (min-width: 460px) {
    .mp-outputs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@container (min-width: 620px) {
    .mp-outputs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.mp-out { min-width: 0; }
/* main.css pins the copy controls of anything inside .station--results to
   the top corner, as a small chip: right for the Drivetrain's big result
   tiles, wrong for these ordinary bordered fields, where it floats above
   the value. Give them the full-height controls of a normal output field. */
#mp-results .value-field-copy-group { top: 0; right: 0; bottom: 0; background: none; }
#mp-results .value-field-copy { padding: 0 0.35rem 0 0.5rem; background: var(--bg-input); }
#mp-results .value-field-copy-menu { padding: 0 0.45rem 0 0.1rem; background: var(--bg-input); }
/* Limit indication: one plain line under each peak value. */
.mp-cap { margin: 4px 0 0; min-height: 1.5em; font-size: var(--text-sm); color: var(--fg-muted); }
.mp-cap.is-low { color: var(--accent-text); }
.mp-phases {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1px;
    margin-top: 0.75rem;
    background: var(--border);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
@container (min-width: 520px) {
    .mp-phases { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.mp-phase { background: var(--bg-card); padding: 8px 10px; display: grid; gap: 1px; }
.mp-phase-k { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.06em; color: var(--fg-muted); }
.mp-phase-v { font: 500 var(--text-base) var(--font-mono); font-variant-numeric: tabular-nums; }
.mp-notes { margin-top: 0.75rem; display: grid; gap: 4px; font-size: var(--text-sm); color: var(--fg-secondary); }
.mp-notes p { margin: 0; }
.mp-notes b { font-weight: 500; color: var(--fg); }
/* Waiting for an answer: the numbers on screen are no longer current. */
#mp-results .value-field-input, .mp-phase-v { transition: opacity 0.15s; }
#mp-results.is-pending .value-field-input,
#mp-results.is-pending .mp-phase-v { opacity: 0.45; }

/* How it works */
.mp-explain { font-size: var(--text-sm); color: var(--fg-secondary); line-height: 1.7; }
.mp-explain code { color: var(--fg); white-space: nowrap; }
.mp-cases {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 0.625rem;
    margin: 0.75rem 0;
}
.mp-case {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    display: grid;
    gap: 4px;
    align-content: start;
}
.mp-case h3 { margin: 0; font-size: var(--text-base); color: var(--fg); }
.mp-case p { margin: 0; line-height: 1.5; }
.mp-case-when { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--accent-text); }
.mp-link {
    font: inherit;
    color: var(--link);
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
    text-align: left;
    text-decoration: underline;
    text-underline-offset: 3px;
}
.mp-case .mp-link { margin-top: 4px; }

@media (prefers-reduced-motion: reduce) {
    #mp-results .value-field-input, .mp-phase-v { transition: none; }
}
