/* ═══════════════════════════════════════════════════════════════════
   TOP GLASS VISUALIZER — Shared stylesheet (admin + frontend)
═══════════════════════════════════════════════════════════════════ */

/* ── FRONTEND: Container layout ─────────────────────────────────── */

.tgv-container {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    max-width: 1200px;
    margin: 0 auto;
    font-family: inherit;
}

/* ── FRONTEND: Visualizer column ──────────────────────────────────── */

:root {
    /* How far from the top of the viewport the sticky image settles on desktop —
       tune if your theme's own sticky header is a different height than this. */
    --tgv-sticky-offset: 100px;
}

.tgv-visualizer-col {
    flex: 3 1 500px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    /* align-self: flex-start keeps this column only as tall as its own content —
       without it, a flex row stretches every column to the tallest sibling's
       height, which would make "sticky" a no-op (there'd be nowhere to scroll
       the column within). Sticky on desktop: the colour lists are long inline
       content there, so the preview stays in view while you scroll past them.
       Mobile turns this back off below — its picker opens as an overlay instead,
       so there's nothing to keep the image in view for. */
    align-self: flex-start;
    position: sticky;
    top: var(--tgv-sticky-offset);
    z-index: 20;
    background: #fff;
}

.tgv-visualizer-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 3 / 2; /* adjust to match your base kitchen photo's typical proportions */
    min-height: 220px; /* safety net if aspect-ratio can't be computed yet (e.g. very old browsers) */
    background-color: #f0ece6;
    overflow: hidden;
    border-radius: 6px;
}

.tgv-empty-notice {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #999;
    font-size: 15px;
    text-align: center;
    pointer-events: none;
}

.tgv-disclaimer {
    margin: 0;
    font-size: 12px;
    line-height: 1.5;
    color: #888;
    font-style: italic;
}

/* ── FRONTEND: Canvas stack ─────────────────────────────────────── */

.tgv-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
}

/* ── FRONTEND: Controls panel ───────────────────────────────────── */

.tgv-controls {
    flex: 1 1 260px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-self: flex-start;
}

/* Each group (Kitchen Panels, Splashbacks) is its own bordered card, rather than
   both sharing one outer border — this also happens to be exactly the box that
   becomes a bottom sheet on mobile (see the mobile media query below). */
.tgv-control-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #fff;
    border: 1px solid #e0dbd4;
    border-radius: 6px;
    padding: 24px 20px;
}

.tgv-group-title {
    margin: 0 0 4px;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #555;
    border-bottom: 1px solid #eee;
    padding-bottom: 8px;
}

/* ── FRONTEND: Colour grid ──────────────────────────────────────── */

.tgv-color-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(68px, 1fr));
    gap: 10px;
}

.tgv-color-option {
    cursor: pointer;
    text-align: center;
    transition: transform 0.15s;
}

.tgv-color-option:hover {
    transform: translateY(-2px);
}

.tgv-color-option.active .tgv-color-swatch {
    outline: 3px solid #2c2c2c;
    outline-offset: 2px;
}

.tgv-color-swatch {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    width: 100%;
    height: 56px;
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.12);
    overflow: hidden;
    padding-bottom: 4px;
}

.tgv-color-label {
    font-size: 10px;
    font-weight: 600;
    color: #fff;
    text-shadow: 0 0 4px rgba(0, 0, 0, 0.7), 0 0 2px rgba(0, 0, 0, 0.9);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    line-height: 1.2;
    word-break: break-word;
    padding: 0 3px;
    pointer-events: none;
}

/* ── FRONTEND: Splashback range picker (step 1: range, step 2: colour) ──── */

.tgv-range-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 10px;
}

.tgv-range-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 10px 6px;
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 6px;
    cursor: pointer;
    text-align: center;
    transition: transform 0.15s, border-color 0.15s;
}

.tgv-range-card:hover {
    transform: translateY(-2px);
    border-color: #2c2c2c;
}

.tgv-range-swatch {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.12);
    flex-shrink: 0;
}

.tgv-range-name {
    font-size: 12px;
    font-weight: 600;
    color: #333;
}

.tgv-family-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tgv-back-btn {
    align-self: flex-start;
    background: none;
    border: none;
    padding: 0;
    font-size: 12px;
    font-weight: 600;
    color: #555;
    cursor: pointer;
    text-decoration: none !important; /* theme button styles otherwise underline it */
}

.tgv-back-btn:hover {
    color: #2c2c2c;
}

.tgv-family-title {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #333;
}

/* ── FRONTEND: Custom colour picker (Panels + Splashback) ───────────────── */

.tgv-custom-color-row {
    margin-top: 4px;
}

.tgv-picker-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #555;
    cursor: pointer;
}

.tgv-picker-label input[type="color"] {
    width: 44px;
    height: 36px;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 2px;
    cursor: pointer;
    background: none;
}

/* Shows the picked colour + its hex code — drawn entirely with our own CSS/JS
   rather than relying on the native colour input's own swatch rendering, which
   some themes' generic input styling can override or hide. Diagonal stripes =
   no custom colour picked yet; JS sets a solid background + text once one is. */
.tgv-custom-hex {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 76px;
    height: 36px;
    padding: 0 10px;
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    font-family: monospace;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.03em;
    color: #999;
    background: repeating-linear-gradient(45deg, #f2f2f2, #f2f2f2 6px, #e6e6e6 6px, #e6e6e6 12px);
}

/* ── FRONTEND: AI Kitchen Preview button + modal ─────────────────────── */

.tgv-ai-tool-row {
    margin-top: 4px;
}

.tgv-ai-tool-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px 16px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, #6b4fd6, #2c7be5);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.tgv-ai-tool-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(44, 123, 229, 0.35);
}

.tgv-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    /* Deliberately very high — many themes give their own sticky header/nav a
       z-index in the hundreds or thousands, which would otherwise render on top
       of this modal instead of underneath it. */
    z-index: 999998;
}

.tgv-modal-backdrop.tgv-modal-open {
    opacity: 1;
    pointer-events: auto;
}

.tgv-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -48%);
    width: min(560px, calc(100vw - 32px));
    max-height: 85vh;
    overflow-y: auto;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    padding: 28px 24px;
    z-index: 999999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.tgv-modal.tgv-modal-open {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%);
}

.tgv-modal-close {
    position: absolute;
    top: 12px;
    right: 14px;
    /* !important throughout: the theme's own button styling (padding, min-width,
       border-radius) otherwise wins and stretches this into a wide pill instead
       of a small circle. */
    width: 32px !important;
    height: 32px !important;
    min-width: 32px !important;
    padding: 0 !important;
    box-sizing: border-box !important;
    border: none;
    background: #f2f2f2;
    border-radius: 50% !important;
    font-size: 20px;
    line-height: 1;
    color: #555;
    cursor: pointer;
}

.tgv-modal-title {
    margin: 0 0 12px;
    font-size: 20px;
    font-weight: 700;
    color: #0c1f3f;
    padding-right: 30px;
}

.tgv-modal-steps {
    margin: 0 0 18px;
    padding-left: 20px;
    font-size: 13px;
    line-height: 1.6;
    color: #555;
}

.tgv-modal-steps li {
    margin-bottom: 4px;
}

.tgv-ai-prompt-wrap {
    margin-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tgv-ai-prompt-label {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #777;
}

.tgv-ai-prompt-output {
    width: 100%;
    font-family: monospace;
    font-size: 12.5px;
    line-height: 1.5;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    resize: vertical;
    background: #fafafa;
    color: #333;
}

.tgv-ai-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.tgv-ai-copy-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.tgv-ai-copied-note {
    font-size: 12px;
    font-weight: 700;
    color: #2c7be5;
}

.tgv-ai-disclaimer {
    margin: 16px 0 0;
    font-size: 11px;
    line-height: 1.5;
    color: #999;
    font-style: italic;
}

/* ── MOBILE: trigger buttons + bottom sheet (hidden on desktop) ──────── */

.tgv-trigger-bar,
.tgv-sheet-close,
.tgv-sheet-backdrop,
.tgv-ai-tool-row-mobile {
    display: none;
}

/* ── RESPONSIVE ─────────────────────────────────────────────────── */

@media (max-width: 768px) {
    .tgv-container {
        flex-direction: column;
    }

    .tgv-visualizer-col,
    .tgv-controls {
        /* align-self: flex-start (set in the base rules above) means something
           different once .tgv-container switches to flex-direction: column here —
           on the desktop row layout it caps *height* (cross-axis), but in a column
           layout the cross-axis is *width*, so left unchanged it shrinks both the
           image and the controls down to their own content width and left-aligns
           them, leaving a blank gap on the right. Force both back to full width. */
        align-self: stretch;
    }

    .tgv-visualizer-col {
        /* flex-basis is along the main axis, which is now vertical (column) —
           the desktop 500px width hint would otherwise be read as a height. */
        flex: 1 1 auto;
        padding-bottom: 4px;
        /* Sticky (set in the base rule above) only earns its keep on desktop, where
           the colour lists are long inline content you scroll past. On mobile the
           picker opens as a bottom-sheet overlay instead — there's nothing to scroll
           the image out from under, so undo it here rather than pin space forever. */
        position: static;
        top: auto;
        z-index: auto;
    }

    .tgv-controls {
        gap: 8px;
    }

    /* The AI tool button lives inside the Kitchen Panels card on desktop — on
       mobile that's buried inside a bottom sheet, so swap to a standalone
       compact version sitting right below the trigger buttons instead. */
    #tgv-panel-ai-row {
        display: none;
    }

    .tgv-ai-tool-row-mobile {
        display: block;
        margin-top: 10px;
    }

    .tgv-ai-tool-row-mobile .tgv-ai-tool-btn {
        padding: 10px 14px;
        font-size: 13px;
    }

    /* Compact "current colour" buttons replace the inline swatch grids; tapping
       one opens the matching .tgv-control-group below as a bottom sheet. */
    .tgv-trigger-bar {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .tgv-trigger {
        display: flex;
        align-items: center;
        gap: 10px;
        width: 100%;
        background: #fff;
        border: 1px solid #e0dbd4;
        border-radius: 8px;
        padding: 10px 14px;
        cursor: pointer;
        text-align: left;
        font: inherit;
    }

    .tgv-trigger-swatch {
        width: 32px;
        height: 32px;
        border-radius: 50%;
        border: 1px solid rgba(0, 0, 0, 0.12);
        flex-shrink: 0;
    }

    .tgv-trigger-text {
        display: flex;
        flex-direction: column;
        flex: 1;
        min-width: 0;
    }

    .tgv-trigger-label {
        font-size: 11px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.06em;
        /* !important: the theme's own button styling (this is a <button>) competes
           for text colour here, so this needs to win regardless of load order. */
        color: #fff !important;
    }

    .tgv-trigger-value {
        font-size: 14px;
        font-weight: 600;
        color: #222;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .tgv-trigger-chevron {
        font-size: 20px;
        line-height: 1;
        color: #fff !important;
        flex-shrink: 0;
    }

    /* Each colour group becomes a bottom sheet, off-screen until opened. */
    .tgv-control-group {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        max-height: 78vh;
        overflow-y: auto;
        background: #fff;
        border: none;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.2);
        padding: 44px 20px calc(20px + env(safe-area-inset-bottom, 0px));
        transform: translateY(110%);
        transition: transform 0.3s ease;
        /* Deliberately very high — see .tgv-modal-backdrop above; a theme's own
           sticky header would otherwise render on top of this bottom sheet. */
        z-index: 99999;
    }

    .tgv-control-group.tgv-sheet-open {
        transform: translateY(0);
    }

    .tgv-sheet-close {
        display: block;
        position: absolute;
        top: 10px;
        right: 14px;
        /* !important throughout: see .tgv-modal-close for why — the theme's own
           button styling otherwise stretches this into a wide pill. */
        width: 32px !important;
        height: 32px !important;
        min-width: 32px !important;
        padding: 0 !important;
        box-sizing: border-box !important;
        border: none;
        background: #f2f2f2;
        border-radius: 50% !important;
        font-size: 20px;
        line-height: 1;
        color: #555;
        cursor: pointer;
    }

    .tgv-sheet-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
        z-index: 99998;
    }

    .tgv-sheet-backdrop.tgv-sheet-open {
        opacity: 1;
        pointer-events: auto;
    }
}

/* ═══════════════════════════════════════════════════════════════════
   ADMIN STYLES
═══════════════════════════════════════════════════════════════════ */

.tgv-admin-wrap .tgv-section {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 20px 24px;
    margin-bottom: 24px;
}

.tgv-admin-wrap .tgv-section h2 {
    margin-top: 0;
    padding-bottom: 10px;
    border-bottom: 2px solid #f0f0f0;
}

.tgv-field-wrap {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.tgv-thumb {
    display: block;
    width: 80px;
    height: 60px;
    object-fit: cover;
    border-radius: 3px;
    border: 1px solid #ddd;
}

.tgv-percent-field {
    width: 70px !important;
    margin-right: 4px;
}

/* ── Colour row ─────────────────────────────────────────────────── */

.tgv-color-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.tgv-color-row input[type="text"] {
    width: 160px;
}

.tgv-color-name {
    width: 220px !important;
}

.tgv-drag-handle {
    cursor: grab;
    color: #aaa;
    font-size: 16px;
    padding: 0 2px;
    user-select: none;
}

.tgv-drag-handle:active {
    cursor: grabbing;
}

.tgv-color-row.ui-sortable-helper {
    background: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.tgv-color-hex {
    width: 76px !important;
    font-family: monospace;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.tgv-color-row input[type="color"] {
    width: 44px;
    height: 34px;
    border: 1px solid #ccc;
    border-radius: 3px;
    padding: 2px;
    cursor: pointer;
    background: none;
}

.tgv-swatch-upload-wrap {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.tgv-swatch-thumb {
    width: 32px;
    height: 32px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    display: block;
}

.tgv-remove-swatch {
    color: #b32d2e;
    text-decoration: none;
    font-size: 14px;
    line-height: 1;
    padding: 0 2px;
}

.tgv-color-preview {
    display: inline-block;
    width: 32px;
    height: 32px;
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    vertical-align: middle;
    flex-shrink: 0;
}

.tgv-add-btn {
    margin-top: 4px !important;
}

/* ═══════════════════════════════════════════════════════════════════
   ADMIN: RAL Colour Editor
═══════════════════════════════════════════════════════════════════ */

.tgv-ral-intro {
    max-width: 900px;
}

.tgv-ral-editor {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 440px);
    gap: 24px;
    align-items: start;
}

/* ── Colour list ─────────────────────────────────────────────────── */

.tgv-ral-list-col {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 16px 18px;
}

.tgv-ral-search {
    width: 100%;
    margin-bottom: 8px;
}

.tgv-ral-family-title {
    margin: 18px 0 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid #eee;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #555;
}

.tgv-ral-family:first-child .tgv-ral-family-title {
    margin-top: 6px;
}

.tgv-ral-chips {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
    gap: 8px;
}

.tgv-ral-chip {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 5px 4px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
}

.tgv-ral-chip:hover {
    border-color: #2271b1;
}

.tgv-ral-chip.active {
    border-color: #2271b1;
    box-shadow: 0 0 0 2px #2271b1;
}

.tgv-ral-chip-swatch {
    width: 100%;
    height: 30px;
    border-radius: 3px;
    border: 1px solid rgba(0, 0, 0, 0.15);
}

.tgv-ral-chip-code {
    font-size: 11px;
    font-weight: 600;
    color: #333;
}

/* Red dot = this colour has been edited/tuned */
.tgv-ral-chip.tgv-ral-modified::after {
    content: '';
    position: absolute;
    top: 3px;
    right: 3px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #d63638;
    border: 1px solid #fff;
}

/* ── Preview + controls ──────────────────────────────────────────── */

.tgv-ral-panel {
    position: sticky;
    top: 42px; /* clears the WP admin bar */
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-height: calc(100vh - 60px);
    overflow-y: auto;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 16px;
}

.tgv-ral-preview .tgv-empty-notice {
    width: 84%;
    line-height: 1.5;
}

.tgv-ral-preview .tgv-empty-notice a {
    pointer-events: auto;
}

.tgv-ral-compare {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 18px;
}

.tgv-ral-compare-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    line-height: 1.4;
}

/* Diagonal stripes = nothing to show yet; JS sets a solid colour once there is */
.tgv-ral-compare-chip {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    border: 1px solid rgba(0, 0, 0, 0.2);
    background: repeating-linear-gradient(45deg, #f2f2f2, #f2f2f2 6px, #e6e6e6 6px, #e6e6e6 12px);
}

.tgv-ral-fields {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.tgv-ral-fields > .button {
    align-self: flex-start;
}

.tgv-ral-selected {
    margin: 0;
    padding: 0;
    font-size: 16px;
}

.tgv-ral-field-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.tgv-ral-field {
    display: block;
}

.tgv-ral-field-grow {
    flex: 1 1 180px;
}

.tgv-ral-label {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
    font-size: 13px;
    font-weight: 600;
}

.tgv-ral-label output {
    font-weight: 400;
    color: #2271b1;
    font-variant-numeric: tabular-nums;
}

.tgv-ral-field input[type="text"] {
    width: 100%;
}

.tgv-ral-field input[type="range"] {
    width: 100%;
}

.tgv-ral-field .description {
    margin: 2px 0 0;
    font-size: 12px;
}

.tgv-ral-hexwrap {
    display: flex;
    align-items: center;
    gap: 6px;
}

.tgv-ral-hexwrap input[type="color"] {
    width: 44px;
    height: 34px;
    padding: 2px;
    cursor: pointer;
}

.tgv-ral-hex {
    width: 92px !important;
    font-family: monospace;
    text-transform: uppercase;
}

.tgv-ral-inline {
    display: block;
    margin-top: 2px;
    font-size: 12px;
}

@media (max-width: 1100px) {
    .tgv-ral-editor {
        grid-template-columns: 1fr;
    }

    /* Preview first, list below — and not sticky once it's a single column */
    .tgv-ral-panel {
        position: static;
        max-height: none;
        order: -1;
    }
}
