/* Draw Session — canvas-focus layout (loaded via draw_session.php) */

.drill-canvas-stage {
    position: relative;
    margin: 0 0 12px;
}

.drill-maker.drill-maker--canvas-focus {
    display: block;
    height: clamp(480px, calc(100vh - 200px), 720px);
    min-height: 480px;
}

.drill-maker--canvas-focus .canvas-container {
    width: 100%;
    height: 100%;
    border-radius: 12px;
    border: 1px solid #334155;
}

/* Context header: breadcrumb + ⋮ menu */
.draw-ctx-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 0 0 10px;
    min-height: 40px;
}

.draw-ctx-page-title {
    margin: 0;
    flex: 1 1 auto;
    min-width: 0;
    font-size: 1.15rem;
    font-weight: 700;
    line-height: 1.35;
}

.draw-ctx-page-title.draw-ctx-breadcrumb {
    font-size: 1.05rem;
    font-weight: 600;
}

.draw-ctx-menu {
    position: relative;
    flex-shrink: 0;
}

.draw-ctx-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid #334155;
    border-radius: 8px;
    background: #1e293b;
    color: #cbd5e1;
    cursor: pointer;
    touch-action: manipulation;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.draw-ctx-menu-btn:hover {
    background: #334155;
    border-color: #475569;
    color: #f8fafc;
}

.draw-ctx-menu-btn[aria-expanded="true"] {
    background: #1e3a8a;
    border-color: #3b82f6;
    color: #bfdbfe;
}

.fs-5 { font-size: 1.25rem; line-height: 1; }

.draw-ctx-menu-panel {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 1100;
    width: min(92vw, 520px);
    max-height: min(70vh, 560px);
    overflow-y: auto;
    padding: 10px;
    border-radius: 12px;
    background: #1e293b;
    border: 1px solid #475569;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}

.draw-ctx-menu-panel[hidden] { display: none !important; }

.draw-ctx-menu-panel .form-section-wrap {
    margin: 0;
}

/* Session Details — the optional session-wide coaching labels. */
#session-details-wrap {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid #334155;
}

#session-details-wrap[hidden] { display: none !important; }

/* Toggle and picker share the header strip: a select cannot sit in a button. */
.session-details-head {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* Narrow bases so the picker drops onto its own line in a slim panel rather
   than squeezing the toggle down to an ellipsis. */
.session-details-head .form-section-toggle {
    flex: 1 1 150px;
    min-width: 0;
}

.session-label-picker-slot {
    flex: 1 1 170px;
    min-width: 0;
}

.session-label-picker-slot select {
    width: 100%;
    background: #111c31;
    color: #e2e8f0;
    border: 1px solid #334155;
    border-radius: 8px;
    padding: 7px 9px;
    font-size: 12px;
}

/* .form-section is the shared 2/3-column form grid. This section holds full
   width cards, not form-groups, so opt it out: inside that grid a card would
   only ever be a third of the body wide. */
#session-details-body.form-section {
    display: block;
    border-top: none;
    padding: 0;
}

#session-details-body.form-section[hidden],
.form-section-wrap.is-collapsed #session-details-body.form-section { display: none; }

.session-label-cards {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    /* Never let a card push the section wider than the panel it lives in. */
    min-width: 0;
    max-width: 100%;
}

.session-label-card {
    position: relative;
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: 10px;
    padding: 12px 14px 14px;
}

/* The two labels that name a bundle. auto-fit measures the card, not the
   viewport, so they sit side by side when there is room and stack when the
   floating panel is narrow — which a media query cannot see. */
.session-label-card-head {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
    /* Clear the remove button pinned in the corner. */
    padding: 0 32px 10px 0;
    margin-bottom: 12px;
    border-bottom: 1px solid #1e293b;
}

.session-label-card-body {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 12px 16px;
    /* Each field is as tall as its own content — without this a short field
       stretches to match the tallest one in its row. */
    align-items: start;
}

.session-label-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.session-label-name {
    color: #94a3b8;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    /* break-word, never `anywhere`: `anywhere` also drops the min-content size
       to one character, which collapses the element inside any flex or grid
       parent that can shrink it. */
    overflow-wrap: break-word;
}

/* The four competence stages. Checkboxes rather than a multi-select: this
   panel is used on a tablet, where there is no Ctrl-click. */
.session-label-stages {
    /* Two up when the column allows it, one up when it does not, so the four
       stages stay a compact block instead of a tall thin strip. */
    display: grid;
    /* 180px, not 140px: the longest stage name is "Unconscious incompetence",
       which needs ~150px plus the checkbox. */
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    align-content: start;
    gap: 2px 10px;
    background: #111c31;
    border: 1px solid #334155;
    border-radius: 6px;
    padding: 6px;
}

/* Grid, not flex: a `1fr` text track always fills the row, where a flex item
   with `flex-basis: auto` settles at its content width instead. */
.session-label-stage {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: start;
    gap: 7px;
    padding: 4px;
    border-radius: 4px;
    font-size: 12px;
    line-height: 1.3;
    color: #cbd5e1;
    cursor: pointer;
}

.session-label-stage:hover { background: #1b2b47; }
.session-label-stage input {
    /* Line up with the first line of a wrapped label. */
    margin: 1px 0 0;
    width: 14px;
    height: 14px;
    accent-color: #3b82f6;
}
.session-label-stage span { min-width: 0; overflow-wrap: break-word; }
.session-label-stage:has(input:checked) { color: #bfdbfe; }

/* Optional suggestion dropdown above a field. Picking sets a name or adds a
   line; the field underneath stays free text either way. */
.session-label-suggest {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    background: #16233c;
    color: #94a3b8;
    border: 1px dashed #334155;
    border-radius: 6px;
    padding: 4px 6px;
    font-family: inherit;
    font-size: 11px;
}

.session-label-suggest:focus { outline: none; border-color: #3b82f6; color: #cbd5e1; }

.session-label-field input,
.session-label-field textarea {
    width: 100%;
    background: #111c31;
    color: #e2e8f0;
    border: 1px solid #334155;
    border-radius: 6px;
    padding: 7px 9px;
    font-family: inherit;
    font-size: 12px;
    line-height: 1.5;
    resize: vertical;
    /* Height is set from the content by autoSize(). */
    overflow: hidden;
}

.session-label-field.is-header input {
    font-size: 13px;
    font-weight: 600;
    color: #bfdbfe;
}

.session-label-field input:focus,
.session-label-field textarea:focus {
    outline: none;
    border-color: #3b82f6;
    background: #0b1526;
}

.session-label-field input::placeholder,
.session-label-field textarea::placeholder { color: #475569; }

/* Pinned to the card corner so it never competes with the header fields for
   width — that squeeze is what shrank the inputs to a single character. */
.session-label-remove {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 24px;
    height: 24px;
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: 6px;
    color: #64748b;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
}

.session-label-remove:hover { color: #ef4444; border-color: #ef4444; }

.session-label-empty { color: #64748b; font-size: 12px; margin: 12px 0 0; }

.draw-ctx-menu-panel .drill-tabs-wrap--inline {
    margin: 0 0 10px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.draw-ctx-menu-panel .drill-tabs-wrap--inline[hidden] {
    display: none !important;
}

.draw-ctx-menu-panel .drill-tabs-wrap--inline:not([hidden]) {
    display: flex;
}

.draw-ctx-menu-panel .drill-tabs-row {
    display: flex;
    /* flex-start so the row stays top-aligned when the library
       search dropdown expands the actions column in-flow. */
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 6px;
}

.draw-ctx-menu-panel .drill-tabs {
    flex: 1 1 auto;
    min-width: 0;
}

.draw-ctx-menu-panel .drill-tabs-actions {
    flex-shrink: 0;
}

.draw-ctx-menu-panel .drill-tabs-status {
    margin: 0;
    font-size: 11px;
}

/* Hidden tool counter — DOM kept for updateToolCounter() */
.tool-counter-section--hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* Shared floating panel chrome (tools only) */
.float-panel {
    position: fixed;
    z-index: 9000;
    display: flex;
    flex-direction: column;
    max-height: min(82vh, 580px);
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.97);
    border: 1px solid #475569;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    touch-action: none;
    user-select: none;
    /* Never invisible — kept on-screen by clampPanel() */
    visibility: visible !important;
    opacity: 1 !important;
}

.float-panel[hidden] { display: none !important; }

/* ── Chrome = full-width drag strip ── */
.float-panel-chrome {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: 0 10px;
    border-bottom: 1px solid #334155;
    border-radius: 12px 12px 0 0;
    flex-shrink: 0;
    min-height: 34px;
    cursor: grab;
    touch-action: none;
    transition: background 0.12s;
}

.float-panel-chrome:active { cursor: grabbing; background: rgba(59,130,246,0.07); }
.float-panel-chrome:hover  { background: rgba(148,163,184,0.06); }

/* Six-dot drag indicator centred in the strip */
.float-panel-chrome::before {
    content: '⠿ ⠿';
    font-size: 11px;
    letter-spacing: 4px;
    color: #475569;
    pointer-events: none;
    user-select: none;
}

/* Keep old handle/title selectors inert in case old DOM is cached */
.float-panel-drag-handle { display: none !important; }
.float-panel-title        { display: none !important; }

.float-panel--tools.tools-panel {
    top: 12px;
    left: 12px;
    width: 210px;
    padding: 0;
    overflow: hidden;
    gap: 0;
}

.float-panel--tools .tools-panel-body {
    overflow-y: auto;
    padding: 6px 8px 10px;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.float-panel--tools .tools-panel-body::-webkit-scrollbar { width: 6px; }
.float-panel--tools .tools-panel-body::-webkit-scrollbar-thumb { background: #475569; border-radius: 4px; }

.tool-tabs-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 8px 4px;
    border-bottom: 1px solid #334155;
    flex-shrink: 0;
}

.tool-tabs-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    flex: 1 1 auto;
    min-width: 0;
}

/* Undo/redo: the actions tool-group has no matching tab, so the tabbed panel
   hides it at every width. They ride at the end of the tab strip instead —
   reachable from every tab and outside the scrolling body. Sized to the 10px
   tabs rather than to a full tool-button. Desktop hides them: Ctrl+Z / Ctrl+Y
   (or Ctrl+Shift+Z) cover it. */
.tool-tabs-actions {
    display: none;
    gap: 4px;
    flex: 0 0 auto;
    margin-left: auto;
}
@media (max-width: 768px) {
    .tool-tabs-actions { display: flex; }
}

.tool-tabs-actions .tool-button.tool-tab-action {
    width: 24px;
    height: 24px;
    min-width: 0;
    min-height: 0;
    aspect-ratio: auto;
    flex: 0 0 auto;
    padding: 0;
    border-radius: 6px;
    color: #94a3b8;
    /* the 44px tap target below lives outside the box */
    overflow: visible;
}
.tool-tabs-actions .tool-button.tool-tab-action svg {
    width: 14px;
    height: 14px;
}
/* A 24px square is well under the 44px a finger needs, and these only show on
   touch widths — so grow the hit area without growing the button. */
.tool-tabs-actions .tool-button.tool-tab-action::after {
    content: '';
    position: absolute;
    inset: -10px;
}

.tool-tab {
    flex: 1 1 auto;
    min-width: 0;
    padding: 5px 6px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: #94a3b8;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    cursor: pointer;
    touch-action: manipulation;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
    text-align: center;
}

.tool-tab:hover { color: #e2e8f0; background: rgba(148, 163, 184, 0.08); }

.tool-tab.active {
    color: #f8fafc;
    background: #0f172a;
    border-color: #475569;
    box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.35) inset;
}

.tool-tab-gk.active        { color: #93c5fd; border-color: #3b82f6; }
.tool-tab-obstacles.active { color: #fcd34d; border-color: #f59e0b; }
.tool-tab-drawing.active   { color: #6ee7b7; border-color: #10b981; }
.tool-tab-actions.active   { color: #fca5a5; border-color: #ef4444; }

.tools-panel--tabbed .tool-group-label-toggle {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.tools-panel--tabbed .tool-group-divider { display: none; }

.tools-panel--tabbed .tool-group:not(.is-tab-active) { display: none; }

.tools-panel--tabbed .tool-group.is-tab-active {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tools-panel--tabbed .tools-panel-filter { display: none; }

/* Phone overrides DISABLED — the desktop-parity lock in draw_session.php now
   renders the desktop layout at `zoom: 100vw/1024` on small screens. Restore
   by dropping the `and (min-width: 99999px)` guard. */
@media (max-width: 768px) and (min-width: 99999px) {
    .drill-maker.drill-maker--canvas-focus {
        height: clamp(400px, 55vh, 560px);
        min-height: 400px;
    }

    .float-panel--tools.tools-panel {
        width: min(88vw, 210px);
        max-height: min(52vh, 380px);
    }

    /* 4-column compact grid on mobile */
    .float-panel--tools .tools-panel-body {
        padding: 5px 6px 8px;
    }

    .float-panel--tools .tools-panel-body .tool-group-body {
        grid-template-columns: repeat(4, 1fr);
        gap: 3px;
    }

    /* Smaller square buttons */
    .float-panel--tools .tool-button {
        border-radius: 6px;
        min-height: 0;
    }

    .float-panel--tools .tool-button img,
    .float-panel--tools .tool-button svg {
        width: 60%;
        height: 60%;
    }

    .float-panel--tools .tool-button--wide {
        grid-column: 1 / -1;
        font-size: 11px;
        min-height: 32px;
        gap: 5px;
    }

    .float-panel--tools .tool-button--wide img,
    .float-panel--tools .tool-button--wide svg {
        width: 16px;
        height: 16px;
    }

    .draw-ctx-menu-panel {
        width: min(96vw, 520px);
        right: 0;
        left: auto;
    }

    .tool-tabs-nav { padding: 3px 5px; gap: 3px; }
    .tool-tabs-list { gap: 3px; }
    .tool-tab { font-size: 9px; padding: 3px 4px; }
    .tool-tabs-actions { gap: 3px; }
    .tool-tabs-actions .tool-button.tool-tab-action { width: 22px; height: 22px; }
    .tool-tabs-actions .tool-button.tool-tab-action svg { width: 13px; height: 13px; }
}

/* Phones and tablets (the zoomed desktop-parity layout, see draw_session.php).
   At a 390px phone the page is zoomed to ~0.38, which left the tools panel
   ~80px wide: "Obstacles" was clipped and undo/redo sat on top of it. --fp
   grows the panel back to the size it has at 0.75 zoom (no change on tablets
   at 768px or wider). Tabs keep one row, undo/redo get their own row with
   finger-sized buttons. Width is a real layout size, so dragging and
   clampPanel() still work. */
@media (max-width: 768px) {
    .float-panel--tools.tools-panel {
        --fp: max(1, calc(0.75 / var(--gk-lock-scale, 1)));
        width: calc(210px * var(--fp));
    }
    .float-panel--tools .float-panel-chrome { min-height: calc(30px * var(--fp)); }
    .float-panel--tools .tool-tabs-nav { flex-wrap: wrap; gap: calc(4px * var(--fp)); padding: calc(6px * var(--fp)) calc(8px * var(--fp)); }
    /* iOS Safari enlarges small text on its own, so the labels can come out
       far bigger than set here: let the tabs wrap onto more rows rather than
       run into each other. */
    .float-panel--tools .tool-tabs-list { flex: 1 1 100%; flex-wrap: wrap; gap: calc(3px * var(--fp)); }
    .float-panel--tools .tool-tab { flex: 1 1 auto; max-width: 100%; font-size: calc(10px * var(--fp)); line-height: 1.2; padding: calc(5px * var(--fp)) calc(4px * var(--fp)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .float-panel--tools .tool-tabs-actions { flex: 1 1 100%; margin-left: 0; gap: calc(6px * var(--fp)); }
    .float-panel--tools .tool-tabs-actions .tool-button.tool-tab-action { flex: 1 1 0; width: auto; height: calc(30px * var(--fp)); border-radius: calc(6px * var(--fp)); }
    .float-panel--tools .tool-tabs-actions .tool-button.tool-tab-action svg { width: calc(16px * var(--fp)); height: calc(16px * var(--fp)); }
    .float-panel--tools .tool-tabs-actions .tool-button.tool-tab-action::after { inset: 0; }
    .float-panel--tools .tools-panel-body { padding: calc(6px * var(--fp)) calc(8px * var(--fp)) calc(10px * var(--fp)); }
    .float-panel--tools .tool-group-body { gap: calc(4px * var(--fp)); }
}
/* Phones: five a row, so Obstacles fits in two rows instead of scrolling. */
@media (max-width: 640px) {
    .float-panel--tools .tool-group-body { grid-template-columns: repeat(5, 1fr) !important; }
    .float-panel--tools .tool-group-body .tool-button img,
    .float-panel--tools .tool-group-body .tool-button svg { width: 60%; height: 60%; object-fit: contain; }
}

/* Tablets and phones: the page is drawn at desktop size and zoomed down
   (--gk-lock-scale), which shrank this panel to a sliver on a phone. Undo the
   zoom for the panel alone so it is real size, as wide as the screen allows,
   two columns of fields on a tablet and one on a phone. */
@media (max-width: 1024px) {
    .draw-ctx-menu-panel {
        zoom: calc(1 / var(--gk-lock-scale, 1));
        width: min(calc(100vw - 16px), 620px);
        max-height: 75vh;
        padding: 8px;
    }
    /* The tools panel is a fixed layer on the page; the menu lives in the header's own
       stacking context and cannot rise above it, so the tools step aside while it is open. */
    body:has(.draw-ctx-menu-panel:not([hidden])) .float-panel { visibility: hidden !important; }
    /* Same for the session focus modal (js/drill-focus-suggest.js): at the
       page's zoom its pills and checkboxes were too small to tap on a phone. */
    #gk-focus-suggest-overlay, .gk-dlg-overlay { zoom: calc(1 / var(--gk-lock-scale, 1)); }
    .draw-ctx-menu-panel .session-label-picker-slot select { max-width: 100%; }
    .draw-ctx-menu-panel .form-section { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; padding: .8rem .9rem; }
    .draw-ctx-menu-panel .form-section .form-group label { font-size: 11px; margin-bottom: 3px; }
    .draw-ctx-menu-panel .form-section input,
    .draw-ctx-menu-panel .form-section select,
    .draw-ctx-menu-panel .form-section textarea,
    .draw-ctx-menu-panel .drill-desc-preview { font-size: 15px; min-height: 38px; }
    .draw-ctx-menu-panel .selected-focus-container,
    .draw-ctx-menu-panel .selected-goalkeepers-container { display: flex; flex-wrap: wrap; gap: 4px; min-height: 0; padding: 4px; }
    .draw-ctx-menu-panel .selected-focus-container > *,
    .draw-ctx-menu-panel .selected-goalkeepers-container > * { margin: 0; }
}
@media (max-width: 600px) {
    .draw-ctx-menu-panel .form-section { grid-template-columns: minmax(0, 1fr); }
    /* 16px: iOS zooms into any smaller field on focus. */
    .draw-ctx-menu-panel .form-section input,
    .draw-ctx-menu-panel .form-section select,
    .draw-ctx-menu-panel .form-section textarea { font-size: 16px; }
}
