/**
 * D3 Visualizer — wizard chrome.
 *
 * Styles the wizard UI only. The visualization preview is styled entirely by
 * the CSS that d3w-render.js generates from the template specification, so
 * nothing here may leak into it.
 */

.d3w-wizard {
    max-width: 1180px;
    margin: 0 auto;
    color: #1f2937;
}

.d3w-wizard-title {
    font-size: 1.7em;
    font-weight: 700;
    margin: 0 0 6px;
}

.d3w-intro {
    margin: 0 0 20px;
    color: #4b5563;
}

/* Content hidden visually but available to assistive technology. */
.d3w-sr-only {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* A visible focus indicator on every interactive element. */
.d3w-wizard a:focus,
.d3w-wizard button:focus,
.d3w-wizard input:focus,
.d3w-wizard select:focus,
.d3w-wizard textarea:focus {
    outline: 3px solid #1d4ed8;
    outline-offset: 2px;
}

.d3w-wizard a:focus:not(:focus-visible),
.d3w-wizard button:focus:not(:focus-visible),
.d3w-wizard input:focus:not(:focus-visible),
.d3w-wizard select:focus:not(:focus-visible),
.d3w-wizard textarea:focus:not(:focus-visible) {
    outline: none;
}

.d3w-wizard a:focus-visible,
.d3w-wizard button:focus-visible,
.d3w-wizard input:focus-visible,
.d3w-wizard select:focus-visible,
.d3w-wizard textarea:focus-visible {
    outline: 3px solid #1d4ed8;
    outline-offset: 2px;
}

/* ---------------------------------------------------------------------------
   Step progress
   --------------------------------------------------------------------------- */

.d3w-progress {
    margin-bottom: 24px;
}

.d3w-progress-list {
    display: flex;
    flex-wrap: wrap;
    list-style: none;
    margin: 0;
    padding: 0;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    overflow: hidden;
}

.d3w-progress-step {
    flex: 1 1 200px;
    border-right: 1px solid #d1d5db;
}

.d3w-progress-step:last-child {
    border-right: 0;
}

.d3w-progress-step > a,
.d3w-progress-step > span {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: #f3f4f6;
    color: #4b5563;
    text-decoration: none;
    height: 100%;
    box-sizing: border-box;
}

.d3w-progress-step > a:hover {
    background: #e5e7eb;
    text-decoration: none;
}

.d3w-progress-step.is-current > a,
.d3w-progress-step.is-current > span {
    background: #1d4ed8;
    color: #ffffff;
}

.d3w-progress-step.is-done > a,
.d3w-progress-step.is-done > span {
    background: #dcfce7;
    color: #14532d;
}

.d3w-progress-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, .16);
    font-weight: 700;
}

.d3w-progress-step.is-current .d3w-progress-number {
    background: rgba(255, 255, 255, .28);
}

.d3w-progress-step.is-done .d3w-progress-number {
    background: #15803d;
    color: #ffffff;
}

.d3w-progress-title {
    display: block;
    font-weight: 600;
}

.d3w-progress-sub {
    display: block;
    font-size: .82em;
    opacity: .85;
}

/* ---------------------------------------------------------------------------
   Step 1 — template chooser
   --------------------------------------------------------------------------- */

.d3w-type-fieldset {
    border: 0;
    margin: 0;
    padding: 0;
}

.d3w-type-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 18px;
    margin: 16px 0 28px;
}

.d3w-type-radio {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.d3w-type-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 6px;
    height: 100%;
    padding: 24px 18px;
    border: 3px solid #e5e7eb;
    border-radius: 8px;
    background: #f9fafb;
    cursor: pointer;
    box-sizing: border-box;
}

.d3w-type-card:hover {
    border-color: #93c5fd;
    background: #f0f7ff;
}

.d3w-type-radio:checked + .d3w-type-card {
    border-color: #1d4ed8;
    background: #eff6ff;
}

/* The selection is marked by more than colour (WCAG 1.4.1). */
.d3w-type-radio:checked + .d3w-type-card::after {
    content: "\2713";
    display: inline-block;
    margin-top: 4px;
    font-weight: 800;
    color: #1d4ed8;
}

.d3w-type-radio:focus-visible + .d3w-type-card,
.d3w-type-radio:focus + .d3w-type-card {
    outline: 3px solid #1d4ed8;
    outline-offset: 3px;
}

.d3w-type-radio:focus:not(:focus-visible) + .d3w-type-card {
    outline: none;
}

/* The visualization icons are drawn on a square 48x48 viewBox. */
.d3w-type-icon {
    display: block;
    width: 56px;
    height: 56px;
}

.d3w-type-icon svg {
    display: block;
    width: 100%;
    height: 100%;
}

.d3w-type-name {
    font-weight: 700;
}

.d3w-type-desc {
    font-size: .84em;
    color: #4b5563;
    line-height: 1.4;
}

/* ---------------------------------------------------------------------------
   Step 2 — layout
   --------------------------------------------------------------------------- */

/* One full-width column. The preview belongs to Step 4, where it gets the whole
   page instead of competing with the options for room. */
.d3w-step3-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 24px;
}

.d3w-preview-box {
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 12px;
    background: #ffffff;
    overflow-x: auto;
    min-height: 180px;
}

.d3w-preview-error {
    color: #b91c1c;
    font-weight: 600;
}

/* ---------------------------------------------------------------------------
   Forms
   --------------------------------------------------------------------------- */

.d3w-section {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 16px 20px 20px;
    margin: 0 0 20px;
    background: #ffffff;
}

.d3w-section-title {
    font-size: 1.02em;
    font-weight: 700;
    margin: 0 0 12px;
    padding: 0;
    color: #111827;
    border: 0;
    width: auto;
}

.d3w-grid-2,
.d3w-grid-3 {
    display: grid;
    gap: 0 20px;
}

.d3w-grid-2 {
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
}

.d3w-grid-3 {
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.d3w-field {
    margin-bottom: 14px;
}

.d3w-field > label {
    display: block;
    font-size: .88em;
    font-weight: 600;
    margin-bottom: 4px;
    color: #374151;
}

.d3w-field-check {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 8px;
    align-items: center;
}

.d3w-field-check input[type="checkbox"] {
    margin: 0;
    width: 17px;
    height: 17px;
}

.d3w-field-check > label {
    margin: 0;
    grid-column: 2;
}

.d3w-field-check .d3w-help {
    grid-column: 2;
}

.d3w-help {
    display: block;
    font-size: .8em;
    color: #6b7280;
    line-height: 1.45;
    margin-top: 3px;
}

.d3w-help code {
    font-size: .95em;
    word-break: break-all;
}

.d3w-error {
    color: #b91c1c;
    font-size: .85em;
    font-weight: 600;
    margin: 4px 0 0;
}

.d3w-required {
    color: #b91c1c;
}

.d3w-color-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.d3w-color-row input[type="color"] {
    width: 44px;
    height: 34px;
    padding: 2px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    background: #ffffff;
    cursor: pointer;
    flex-shrink: 0;
}

.d3w-color-text {
    max-width: 100px;
}

.d3w-range-label {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
}

.d3w-range-value {
    font-weight: 700;
    color: #1d4ed8;
    font-size: .88em;
}

input[type="range"].d3w-range {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: #d1d5db;
    border-radius: 3px;
    cursor: pointer;
    margin: 6px 0;
}

input[type="range"].d3w-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #1d4ed8;
    cursor: pointer;
}

input[type="range"].d3w-range::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border: 0;
    border-radius: 50%;
    background: #1d4ed8;
    cursor: pointer;
}

.d3w-csv {
    font-family: "Courier New", monospace;
    font-size: .86em;
    white-space: pre;
    overflow-wrap: normal;
    overflow-x: auto;
}

/* Disabled dependent controls stay legible. */
.d3w-section input:disabled,
.d3w-section select:disabled {
    background: #f3f4f6;
    color: #6b7280;
}

/* ---------------------------------------------------------------------------
   Colour presets
   --------------------------------------------------------------------------- */

.d3w-palette-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.d3w-palette-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #ffffff;
    color: #374151;
    font-size: .86em;
    font-weight: 600;
    cursor: pointer;
}

.d3w-palette-btn:hover {
    border-color: #1d4ed8;
    background: #f0f7ff;
}

.d3w-palette-swatches {
    display: inline-flex;
    border-radius: 3px;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, .18);
}

.d3w-palette-swatches span {
    display: block;
    width: 14px;
    height: 14px;
}

.d3w-reset-btn {
    margin-inline-start: auto;
}

/* ---------------------------------------------------------------------------
   Data editor
   --------------------------------------------------------------------------- */

.d3w-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
}

.d3w-tab {
    padding: 7px 16px;
    border: 1px solid #d1d5db;
    border-radius: 6px 6px 0 0;
    background: #f3f4f6;
    color: #374151;
    font-size: .88em;
    font-weight: 600;
    cursor: pointer;
}

.d3w-tab[aria-selected="true"] {
    background: #1d4ed8;
    border-color: #1d4ed8;
    color: #ffffff;
}

.d3w-grid-scroll {
    overflow-x: auto;
    margin-bottom: 12px;
}

.d3w-data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .84em;
}

.d3w-data-table th,
.d3w-data-table td {
    border: 1px solid #d1d5db;
    padding: 6px 8px;
    text-align: left;
    vertical-align: middle;
}

.d3w-data-table thead th {
    background: #f3f4f6;
    font-weight: 700;
    white-space: nowrap;
}

.d3w-grid-input {
    width: 100%;
    min-width: 110px;
    font-size: 1em;
    padding: 4px 6px;
    box-sizing: border-box;
}

.d3w-grid-remove {
    color: #b91c1c;
    font-weight: 800;
    background: none;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    padding: 2px 9px;
    cursor: pointer;
    line-height: 1.4;
}

.d3w-grid-remove:hover {
    background: #fee2e2;
    border-color: #b91c1c;
}

/* ---------------------------------------------------------------------------
   Step 3
   --------------------------------------------------------------------------- */

.d3w-csv-strip {
    background: #1f2937;
    color: #e5e7eb;
    border-radius: 6px;
    padding: 8px 12px;
    margin-bottom: 12px;
    font-size: .84em;
    overflow-x: auto;
}

.d3w-csv-strip-label {
    display: block;
    font-size: .82em;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: #9ca3af;
    margin-bottom: 3px;
}

.d3w-csv-strip code {
    color: #86efac;
    background: none;
    padding: 0;
    white-space: nowrap;
}

.d3w-annotations {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 10px;
    margin: 0 0 24px;
}

.d3w-annotation {
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 10px 12px;
    background: #f9fafb;
}

.d3w-annotation dt {
    display: flex;
    align-items: center;
    gap: 7px;
    font-weight: 700;
    margin-bottom: 3px;
}

.d3w-annotation dd {
    margin: 0;
    font-size: .84em;
    color: #4b5563;
    line-height: 1.45;
}

.d3w-annotation-swatch {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
    flex-shrink: 0;
    border: 1px solid rgba(0, 0, 0, .18);
}

/* ---------------------------------------------------------------------------
   Actions
   --------------------------------------------------------------------------- */

.d3w-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    padding-top: 20px;
    margin-top: 8px;
    border-top: 1px solid #e5e7eb;
}

/* Respect a reduced-motion preference throughout the wizard. */
@media (prefers-reduced-motion: reduce) {
    .d3w-wizard *,
    .d3w-wizard *::before,
    .d3w-wizard *::after {
        transition-duration: .01ms !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
    }
}

/* Next comes first in the DOM (so Enter submits it); show Previous first. */
.d3w-actions-reorder {
    flex-direction: row-reverse;
}

.d3w-actions-reorder .d3w-action-prev {
    margin-inline-end: auto;
}

/* ---------------------------------------------------------------------------
   Image grid extras
   --------------------------------------------------------------------------- */

.d3w-row-thumb {
    display: block;
    width: 56px;
    height: 40px;
    object-fit: cover;
    border-radius: 3px;
    background: #e5e7eb;
}

.d3w-image-cell {
    display: flex;
    gap: 6px;
    align-items: center;
}

.d3w-image-cell .d3w-grid-input {
    min-width: 180px;
}

.d3w-browse {
    flex: 0 0 auto;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    background: #f3f4f6;
    padding: 4px 10px;
    cursor: pointer;
    line-height: 1.4;
}

.d3w-browse:hover {
    background: #e5e7eb;
}

.d3w-media-modal .modal-body {
    padding: 0;
    max-height: 60vh;
    overflow: auto;
}

.d3w-media-frame {
    display: block;
    width: 100%;
    border: 0;
}

/* ---------------------------------------------------------------------------
   D3 Visualizer specifics
   --------------------------------------------------------------------------- */

.d3w-preview-box {
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 10px;
    background: #ffffff;
    overflow-x: auto;
    min-height: 200px;
}

.d3w-preview-box svg {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 0 auto;
}

.d3w-preview-controls {
    display: flex;
    gap: 8px;
    margin: 10px 0 0;
}

.d3w-csv-status {
    font-size: .85em;
    color: #15803d;
    margin: 6px 0 0;
    min-height: 1.2em;
}

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

.d3w-file-label {
    cursor: pointer;
}

.d3w-swatch {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
    margin-inline-end: 6px;
    vertical-align: middle;
    border: 1px solid rgba(0, 0, 0, .18);
}

.d3w-muted {
    color: #6b7280;
}


/* The hidden attribute must win. A template rule as ordinary as
   `.btn { display: inline-block }` out-specifies the browser default of
   `[hidden] { display: none }`, which leaves controls the wizard has
   deliberately hidden visible on the page and inert when clicked. */
.d3w-wizard [hidden],
.d3w-wizard[hidden] {
    display: none !important;
}
