/*
 * devpanel.css
 *
 * Dev switch in the header and the API inspector panel (devpanel.js).
 * The panel floats on the right; #app gets the same width as padding so the
 * POS reflows beside it instead of being covered. Dialogs and the GB UI end at
 * the panel's edge, so requests stay visible while they are open.
 * Below 900px the panel becomes a full-screen sheet over the POS.
 */

:root {
    --dev-w: 0px;
}

html.dev-open {
    --dev-w: var(--dev-panel-w, 460px);
}

#app {
    transition: padding-right var(--dur-enter) var(--ease);
}

html.dev-open #app {
    padding-right: var(--dev-w);
}

html.dev-resizing,
html.dev-resizing * {
    cursor: col-resize !important;
    user-select: none;
}

html.dev-resizing #app {
    transition: none;
}

/* Fixed layers stop at the panel */
html.dev-open .dialog-overlay,
html.dev-open .gb-ui-overlay,
html.dev-open .cart-backdrop.is-open,
html.dev-open .detail-side.is-open {
    right: var(--dev-w);
}

/* Narrower POS column: let the basket / detail sheet stay beside the main column */
html.dev-open .view-main {
    flex-basis: 400px;
}

/* Starts at 320px so it still fits beside the main column, then grows back to its usual 420px when there is room.
   Once it wraps under the main column (row narrower than 400 + 16 + 320) the cap lifts and it fills the row. */
html.dev-open .view-side {
    flex: 999 1 320px;
    max-width: max(420px, (400px + 16px + 320px - 100%) * 999);
}

/* The POS is narrower beside the panel: both header ends may shrink, and staying equal keeps the tab bar centred */
html.dev-open .app-header__brand,
html.dev-open .app-header__end {
    min-width: 0;
}

/* ---------- Header switch ---------- */

.app-header__end {
    gap: 10px;
}

.dev-switch {
    position: relative;
    height: 46px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0 8px 0 14px;
    border: 0;
    border-radius: var(--r-pill);
    background: var(--surface);
    color: var(--text-2);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    flex: none;
    transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.dev-switch:hover {
    color: var(--ink);
}

.dev-switch:focus-visible {
    outline: 3px solid var(--accent-ring);
    outline-offset: 2px;
}

/* On: the pill stays white (it sits on the grey ground); only the label and the toggle turn accent */
.dev-switch.is-on {
    color: var(--accent-strong);
}

.dev-switch__track {
    width: 34px;
    height: 20px;
    padding: 2px;
    border-radius: var(--r-pill);
    background: var(--track-off);
    display: flex;
    transition: background-color var(--dur-fast) var(--ease);
}

.dev-switch__knob {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--surface);
    box-shadow: 0 1px 3px rgba(20, 22, 27, .18);
    transition: transform var(--dur-fast) var(--ease);
}

.dev-switch.is-on .dev-switch__track {
    background: var(--accent);
}

.dev-switch.is-on .dev-switch__knob {
    transform: translateX(14px);
}

.dev-switch__badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: var(--r-pill);
    background: var(--accent);
    color: var(--on-fill);
    font-size: var(--fs-micro);
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 0 2px var(--ground);
}


/* Tablets, where the tab bar shares the header: round icon button, on = accent tint (like the active tab) */
@media (min-width: 768px) and (max-width: 1023px) {
    .dev-switch__label,
    .dev-switch__track {
        display: none;
    }

    .dev-switch {
        width: 46px;
        padding: 0;
        justify-content: center;
    }

    /* No toggle to show the state here, so on = tint + accent ring, like a selected pill */
    .dev-switch.is-on {
        background: var(--accent-tint);
        box-shadow: inset 0 0 0 1.5px var(--accent-ring);
    }
}

/* ---------- Panel shell ---------- */

.dev-panel {
    position: fixed;
    top: 12px;
    right: 12px;
    bottom: 12px;
    width: calc(var(--dev-w) - 12px);
    z-index: var(--z-dev-panel);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-radius: var(--r-26);
    box-shadow: var(--shadow-sheet);
    font-size: var(--fs-secondary);
    animation: dev-slide-in var(--dur-enter) var(--ease);
}

@keyframes dev-slide-in {
    from {
        transform: translateX(28px);
        opacity: 0;
    }
}

.dev-resize {
    position: absolute;
    top: 24px;
    bottom: 24px;
    left: -8px;
    width: 14px;
    cursor: col-resize;
    z-index: 2;
    touch-action: none;
}

.dev-resize::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 5px;
    width: 4px;
    height: 48px;
    margin-top: -24px;
    border-radius: var(--r-pill);
    background: var(--scrim);
    opacity: 0;
    transition: opacity var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
}

.dev-resize:hover::after,
.dev-resize:focus-visible::after,
html.dev-resizing .dev-resize::after {
    opacity: 1;
    background: var(--accent-ring);
}

.dev-resize:focus-visible {
    outline: none;
}

/* ---------- Head ---------- */

.dev-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 14px 12px 18px;
}

.dev-head__icon {
    width: 40px;
    height: 40px;
    border-radius: var(--r-14);
    background: var(--accent-tint);
    color: var(--accent-strong);
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
}

.dev-head__text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    line-height: 1.25;
}

.dev-head__title {
    font-weight: 800;
    font-size: var(--fs-button);
    color: var(--ink);
}

.dev-head__sub {
    font-size: var(--fs-caption);
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dev-head__actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: none;
}

.dev-head__actions .btn--sm {
    height: 34px;
    padding: 0 12px;
}

.dev-head__close {
    width: 36px;
    height: 36px;
}

/* ---------- Filters ---------- */

.dev-filters {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0 14px 12px;
    border-bottom: 1px solid var(--hairline);
}

.dev-chips {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
    margin: 0 -14px;
    padding: 0 14px;
}

.dev-chips::-webkit-scrollbar {
    display: none;
}

.dev-chip {
    flex: none;
    height: 32px;
    padding: 0 12px;
    border: 0;
    border-radius: var(--r-pill);
    background: var(--control);
    color: var(--text-2);
    font: inherit;
    font-size: var(--fs-secondary);
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.dev-chip:hover {
    background: var(--hover);
}

.dev-chip[aria-pressed="true"] {
    background: var(--accent-tint);
    color: var(--accent-strong);
    font-weight: 700;
}

.dev-chip__count {
    font-size: var(--fs-micro);
    font-weight: 700;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.dev-chip[aria-pressed="true"] .dev-chip__count {
    color: var(--accent-strong);
    opacity: .75;
}

.dev-filters__row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.dev-search {
    flex: 1;
    min-width: 0;
    height: 38px;
    padding: 0 12px;
    border-radius: var(--r-pill);
    background: var(--control);
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 8px;
}

.dev-search:focus-within {
    box-shadow: 0 0 0 2px var(--accent-ring);
}

.dev-search input {
    flex: 1;
    min-width: 0;
    height: 100%;
    border: 0;
    background: transparent;
    font: inherit;
    font-size: var(--fs-secondary);
    color: var(--ink);
    outline: none;
}

/* ---------- Timeline ---------- */

.dev-list {
    position: relative;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0 10px 28px;
}

.dev-empty {
    margin: 28px 8px;
    padding: 22px;
    border-radius: var(--r-20);
    background: var(--surface-2);
    display: flex;
    flex-direction: column;
    gap: 6px;
    text-align: center;
}

.dev-empty__title {
    font-weight: 800;
    font-size: var(--fs-body);
    color: var(--ink);
}

.dev-empty__text {
    color: var(--muted);
    line-height: 1.5;
}

.dev-group__head {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    padding: 14px 8px 6px;
    background: var(--surface);
}

.dev-group__label {
    font-size: var(--fs-caption);
    font-weight: 800;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--text-2);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dev-group__time {
    font-size: var(--fs-caption);
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    flex: none;
}

.dev-steps {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.dev-step {
    border-radius: var(--r-18);
    animation: dev-step-in var(--dur-enter) var(--ease);
}

@keyframes dev-step-in {
    from {
        transform: translateY(6px);
        opacity: 0;
    }
}

.dev-step.is-open {
    box-shadow: inset 0 0 0 1.5px var(--accent-ring);
    margin: 4px 0;
}

.dev-row {
    width: 100%;
    display: grid;
    grid-template-columns: 18px 28px minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    padding: 9px 10px 9px 6px;
    border: 0;
    border-radius: var(--r-18);
    background: transparent;
    font: inherit;
    color: inherit;
    text-align: left;
    cursor: pointer;
    transition: background-color var(--dur-fast) var(--ease);
}

.dev-row:hover {
    background: var(--surface-2);
}

.dev-step.is-open .dev-row:hover {
    background: transparent;
}

.dev-row:focus-visible {
    outline: 3px solid var(--accent-ring);
    outline-offset: -3px;
}

.dev-row__num {
    font-size: var(--fs-micro);
    font-weight: 700;
    color: var(--muted);
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.dev-dir {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--control);
    color: var(--text-2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.dev-dir--info {
    background: transparent;
    box-shadow: inset 0 0 0 1.5px var(--hairline);
    color: var(--muted);
}

.dev-row__main {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.dev-row__top {
    display: flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
}

.dev-method {
    flex: none;
    padding: 1px 6px;
    border-radius: var(--r-6);
    background: var(--control);
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: var(--fs-micro);
    font-weight: 700;
    letter-spacing: .02em;
}

.dev-row__name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 700;
    font-size: var(--fs-body);
    color: var(--ink);
}

.dev-row__sub {
    display: flex;
    align-items: baseline;
    gap: 6px;
    min-width: 0;
    font-size: var(--fs-caption);
    color: var(--muted);
}

.dev-row__channel {
    flex: none;
    font-weight: 600;
}

.dev-row__path {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: var(--font-mono);
    font-size: var(--fs-micro);
}

.dev-row__outcome {
    font-size: var(--fs-caption);
    font-weight: 700;
    color: var(--warning-text);
}

.dev-row__end {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 3px;
}

.dev-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 9px;
    border-radius: var(--r-pill);
    font-size: var(--fs-micro);
    font-weight: 700;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.dev-status--ok {
    background: var(--success-tint);
    color: var(--success-text);
}

.dev-status--warn {
    background: var(--warning-tint);
    color: var(--warning-text);
}

.dev-status--error {
    background: var(--error-tint);
    color: var(--error-text);
}

.dev-status--pending,
.dev-status--info {
    background: var(--control);
    color: var(--text-2);
}

.dev-status__spin {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    border: 2px solid currentColor;
    border-right-color: transparent;
    animation: sf-spin .8s linear infinite;
}

.dev-row__time {
    font-size: var(--fs-micro);
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.dev-newbelow {
    position: absolute;
    left: 50%;
    bottom: 18px;
    transform: translateX(-50%);
    height: 34px;
    padding: 0 16px;
    border: 0;
    border-radius: var(--r-pill);
    background: var(--ink);
    color: var(--on-fill);
    font: inherit;
    font-size: var(--fs-secondary);
    font-weight: 700;
    box-shadow: var(--shadow-float);
    cursor: pointer;
    z-index: 2;
}

/* ---------- Detail ---------- */

.dev-detail {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 2px 12px 14px;
    container-type: inline-size;
}

.dev-explain {
    border-radius: var(--r-16);
    background: var(--accent-tint);
}

.dev-explain[open] {
    padding-bottom: 12px;
}

.dev-explain__summary {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 0 12px 0 14px;
    list-style: none;
    color: var(--accent-strong);
    cursor: pointer;
    border-radius: var(--r-16);
}

.dev-explain__summary::-webkit-details-marker {
    display: none;
}

.dev-explain__summary:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--accent-ring);
}

.dev-explain__icon,
.dev-explain__chevron {
    flex: none;
}

.dev-explain__title {
    flex: 1;
    min-width: 0;
    font-weight: 800;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dev-explain[open] .dev-explain__title {
    white-space: normal;
}

.dev-explain__more {
    flex: none;
    font-size: var(--fs-caption);
    font-weight: 700;
    opacity: .75;
}

.dev-explain__chevron {
    transition: transform var(--dur-fast) var(--ease);
}

.dev-explain[open] .dev-explain__chevron {
    transform: rotate(180deg);
}

.dev-explain__text,
.dev-explain__tip {
    padding: 0 14px;
}

.dev-explain__text {
    margin: 0;
    color: var(--text-2);
    line-height: 1.5;
}

.dev-explain__tip {
    margin: 8px 0 0;
    color: var(--text-2);
    line-height: 1.5;
    font-size: var(--fs-caption);
}

.dev-explain__tip strong {
    display: inline-block;
    margin-right: 6px;
    font-size: var(--fs-micro);
    font-weight: 800;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--accent-strong);
}

.dev-facts {
    display: grid;
    grid-template-columns: 70px minmax(0, 1fr);
    gap: 5px 12px;
    margin: 0;
    padding: 0 2px;
}

.dev-facts > div {
    display: contents;
}

.dev-facts dt {
    font-size: var(--fs-caption);
    font-weight: 600;
    color: var(--muted);
}

.dev-facts dd {
    margin: 0;
    font-size: var(--fs-caption);
    color: var(--text-2);
    overflow-wrap: anywhere;
    line-height: 1.45;
}

.dev-mono {
    font-family: var(--font-mono);
    font-size: var(--fs-micro);
}

.dev-facts__error {
    color: var(--error-text) !important;
    font-weight: 600;
}

.dev-tabs {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
}

.dev-tabs__list {
    display: inline-flex;
    gap: 2px;
    padding: 3px;
    border-radius: var(--r-pill);
    background: var(--control);
}

.dev-tab {
    height: 30px;
    padding: 0 12px;
    border: 0;
    border-radius: var(--r-pill);
    background: transparent;
    color: var(--text-2);
    font: inherit;
    font-size: var(--fs-caption);
    font-weight: 600;
    cursor: pointer;
}

.dev-tab[aria-selected="true"] {
    background: var(--surface);
    color: var(--accent-strong);
    font-weight: 700;
    box-shadow: 0 1px 3px rgba(20, 22, 27, .12);
}

.dev-tabs__actions {
    display: flex;
    gap: 2px;
    margin-left: auto;
}

.dev-link {
    height: 30px;
    padding: 0 10px;
    border: 0;
    border-radius: var(--r-pill);
    background: transparent;
    color: var(--accent-strong);
    font: inherit;
    font-size: var(--fs-caption);
    font-weight: 700;
    cursor: pointer;
}

.dev-link:hover {
    background: var(--accent-tint);
}

/* Narrow panel: tighter tabs and actions keep them on one line */
@container (max-width: 370px) {
    .dev-tab {
        padding: 0 7px;
    }

    .dev-link {
        padding: 0 6px;
    }

    .dev-tabs {
        gap: 4px;
    }
}

.dev-body {
    padding: 10px 8px;
    border-radius: var(--r-14);
    background: var(--code-bg);
    overflow-x: auto;
    max-height: 62vh;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.dev-none {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 6px;
    color: var(--muted);
    font-size: var(--fs-caption);
}

.dev-none .spinner-inline {
    width: 14px;
    height: 14px;
    border-width: 2px;
}

/* ---------- JSON tree ---------- */

.jt {
    font-family: var(--font-mono);
    font-size: var(--fs-caption);
    line-height: 1.6;
    color: var(--text-2);
}

.jt-children {
    margin-left: 6px;
    padding-left: 10px;
    border-left: 1px solid var(--code-line);
}

.jt-row {
    display: flex;
    align-items: baseline;
    gap: 2px;
    min-width: 0;
    padding: 0 4px;
    border-radius: var(--r-6);
}

.jt-row--branch {
    cursor: pointer;
}

.jt-row:hover {
    background: rgba(20, 22, 27, .045);
}

.jt-row--close:hover {
    background: transparent;
}

.jt-caret {
    width: 12px;
    flex: none;
    align-self: center;
    display: inline-flex;
    color: var(--code-punct);
    transition: transform var(--dur-fast) var(--ease);
}

.jt-caret.is-open {
    transform: rotate(90deg);
}

.jt-key {
    flex: none;
    color: var(--code-key);
    font-weight: 600;
}

.jt-key--index {
    color: var(--code-null);
    font-weight: 500;
}

.jt-colon {
    flex: none;
    margin-right: 5px;
    color: var(--code-punct);
}

.jt-brace {
    flex: none;
    color: var(--code-punct);
}

.jt-summary {
    flex: none;
    padding: 0 4px;
    color: var(--code-null);
    font-family: var(--font);
    font-size: var(--fs-micro);
    font-style: italic;
}

.jt-val {
    min-width: 0;
    overflow-wrap: anywhere;
}

.jt-val--string {
    color: var(--code-string);
}

.jt-val--number {
    color: var(--code-number);
}

.jt-val--bool {
    color: var(--code-bool);
    font-weight: 600;
}

.jt-val--null {
    color: var(--code-null);
    font-style: italic;
}

.jt-tag {
    flex: none;
    margin-left: 8px;
    padding: 0 7px;
    border-radius: var(--r-pill);
    background: var(--surface);
    box-shadow: inset 0 0 0 1px var(--code-line);
    color: var(--muted);
    font-family: var(--font);
    font-size: var(--fs-micro);
    font-weight: 700;
    line-height: 18px;
    white-space: nowrap;
}

.jt-act {
    flex: none;
    height: 20px;
    margin-left: 6px;
    padding: 0 6px;
    border: 0;
    border-radius: var(--r-6);
    background: transparent;
    color: var(--accent-strong);
    font-family: var(--font);
    font-size: var(--fs-micro);
    font-weight: 700;
    cursor: pointer;
}

.jt-act:hover {
    background: var(--accent-tint);
}

.jt-copy {
    margin-left: auto;
    opacity: 0;
}

.jt-row:hover > .jt-copy,
.jt-copy:focus-visible {
    opacity: 1;
}

@media (hover: none) {
    .jt-copy {
        display: none;
    }
}

.dev-code--plain {
    margin: 0;
    padding: 2px 4px;
    white-space: pre-wrap;
    word-break: break-all;
    font-family: var(--font-mono);
    font-size: var(--fs-caption);
    line-height: 1.6;
    color: var(--text-2);
}

/* ---------- Phones and portrait tablets: full-screen sheet over the POS ---------- */

@media (max-width: 900px) {
    html.dev-open {
        --dev-w: 0px;
    }

    .dev-panel {
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        width: auto;
        border-radius: 0;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        animation-name: dev-sheet-in;
    }

    @keyframes dev-sheet-in {
        from {
            transform: translateY(24px);
            opacity: 0;
        }
    }

    .dev-resize {
        display: none;
    }

    .dev-head {
        padding: 14px 12px 12px 16px;
    }

    .dev-head__close {
        width: 44px;
        height: 44px;
    }

    .dev-body {
        max-height: none;
    }
}

@media (max-width: 420px) {
    .dev-head__icon {
        display: none;
    }

    .dev-head__actions .btn--sm {
        padding: 0 10px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .dev-panel,
    .dev-step {
        animation: none;
    }

    #app {
        transition: none;
    }
}
