/*
 * The editor's own chrome.
 *
 * The editor used to render the database: a list-group of raw enum values with
 * every form field open at once, and thirty appearance controls in one flat
 * <details>. What follows is the shell that turns it into a screen — a closed
 * row per block, a tabbed panel behind it, and a catalogue you can search.
 */

/* ------------------------------------------------------------ the shell */
.ed-bar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    margin-bottom: 16px;
    background: #fff;
    border: 1px solid rgba(17, 24, 39, .1);
    border-radius: 14px;
    box-shadow: 0 6px 20px -18px rgba(17, 24, 39, .8);
}

.ed-bar__state {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .02em;
}

.ed-bar__state--live { background: #dcfce7; color: #15803d; }
.ed-bar__state--draft { background: #fef3c7; color: #92400e; }
.ed-bar__state::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.ed-bar__link {
    flex: 1 1 220px;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 9px;
    background: rgba(17, 24, 39, .04);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12.5px;
}

.ed-bar__link span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-bar__spacer { flex: 1 1 auto; }

/* ------------------------------------------------------------ block row */
.ed-blocks { display: flex; flex-direction: column; gap: 10px; list-style: none; padding: 0; margin: 0; }

.ed-block {
    border: 1px solid rgba(17, 24, 39, .12);
    border-radius: 13px;
    background: #fff;
    overflow: hidden;
    transition: border-color .15s ease, box-shadow .15s ease;
}

.ed-block:has(.ed-modal[open]) {
    border-color: var(--brand-primary);
    box-shadow: 0 10px 30px -20px rgba(17, 24, 39, .9);
}

.ed-block--off { opacity: .62; }
.ed-block--off .ed-block__name { text-decoration: line-through; }

.ed-block__row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }

.ed-block__handle {
    cursor: grab;
    color: #98a2b3;
    font-size: 17px;
    line-height: 1;
    padding: 2px 4px;
}

.ed-block__icon {
    flex: none;
    width: 34px;
    height: 34px;
    border-radius: 9px;
    display: grid;
    place-items: center;
    color: #fff;
    font-size: 15px;
}

.ed-block__id { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.ed-block__name { font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-block__type { font-size: 11.5px; color: #6b7280; }

/* The number that decides whether the button stays, gets renamed or goes. */
.ed-block__clicks {
    flex: none;
    display: flex;
    align-items: baseline;
    gap: 4px;
    padding: 3px 9px;
    border-radius: 999px;
    background: rgba(17, 24, 39, .05);
    font-size: 12px;
    color: #374151;
    font-variant-numeric: tabular-nums;
}

.ed-block__clicks b { font-size: 13.5px; }
.ed-block__clicks--zero { opacity: .55; }

.ed-block__actions { flex: none; display: flex; align-items: center; gap: 4px; }

.ed-icon-btn {
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(17, 24, 39, .12);
    border-radius: 8px;
    background: #fff;
    color: #4b5563;
    font-size: 13px;
    cursor: pointer;
}

.ed-icon-btn:hover { background: rgba(17, 24, 39, .05); color: #111827; }
.ed-icon-btn--danger:hover { background: #fee2e2; color: #b91c1c; border-color: #fca5a5; }

/* The visibility switch: the field existed in the entity all along. */
.ed-switch { position: relative; width: 40px; height: 23px; flex: none; }
.ed-switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.ed-switch__track {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 999px;
    background: #d1d5db;
    transition: background .16s ease;
}
.ed-switch__track::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 17px;
    height: 17px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .35);
    transition: transform .16s ease;
}
.ed-switch input:checked + .ed-switch__track { background: #16a34a; }
.ed-switch input:checked + .ed-switch__track::after { transform: translateX(17px); }
.ed-switch input:focus-visible + .ed-switch__track { outline: 2px solid var(--brand-primary); outline-offset: 2px; }

/* ---------------------------------------------------------- the panel */
.ed-block__panel { border-top: 1px solid rgba(17, 24, 39, .1); }

.ed-block__summary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 12.5px;
    font-weight: 600;
    color: #4b5563;
    list-style: none;
}

.ed-block__summary::-webkit-details-marker { display: none; }
.ed-block__summary:hover { color: var(--brand-primary); }
.ed-block__chevron { margin-left: auto; font-size: 11px; transition: transform .15s ease; }
.ed-modal[open] > .ed-block__summary { border-bottom: 1px solid rgba(17, 24, 39, .08); }
.ed-modal[open] .ed-block__chevron { transform: rotate(180deg); }

.ed-tabs {
    display: flex;
    gap: 2px;
    padding: 8px 10px 0;
    overflow-x: auto;
    scrollbar-width: none;
    border-bottom: 1px solid rgba(17, 24, 39, .1);
}

.ed-tabs::-webkit-scrollbar { display: none; }

.ed-tab {
    flex: none;
    padding: 7px 12px;
    border: 0;
    border-bottom: 2px solid transparent;
    background: none;
    color: #6b7280;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.ed-tab:hover { color: #111827; }
.ed-tab[aria-selected="true"] { color: var(--brand-primary); border-bottom-color: var(--brand-primary); }

.ed-panel-body { padding: 14px; }
.ed-pane { display: none; }
.ed-pane[data-active="true"] { display: block; }

.ed-fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px 14px;
}

.ed-fields > .ed-field--wide { grid-column: 1 / -1; }
.ed-field label, .ed-panel-body .form-label { font-size: 12px; font-weight: 600; color: #374151; margin-bottom: 3px; }
.ed-panel-body .form-text { font-size: 11.5px; }
.ed-panel-body .form-control, .ed-panel-body .form-select { font-size: 14px; }
.ed-panel-body .form-check { display: flex; align-items: center; gap: 7px; }
.ed-panel-body .form-check-input { margin: 0; }

/* WCAG feedback while the colour is being picked, not after publishing. */
.ed-contrast {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 11px;
    border-radius: 9px;
    font-size: 12.5px;
    background: rgba(17, 24, 39, .04);
    color: #374151;
}

.ed-contrast b { font-variant-numeric: tabular-nums; }
.ed-contrast--pass { background: #dcfce7; color: #14532d; }
.ed-contrast--warn { background: #fef3c7; color: #78350f; }
.ed-contrast--fail { background: #fee2e2; color: #7f1d1d; }

/* ------------------------------------------------------- icon picker */
.ed-icons {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
    gap: 5px;
    max-height: 152px;
    overflow-y: auto;
    padding: 7px;
    margin-top: 7px;
    border: 1px solid rgba(17, 24, 39, .12);
    border-radius: 9px;
    background: #fbfbfa;
}

.ed-icons button {
    aspect-ratio: 1;
    border: 1px solid transparent;
    border-radius: 7px;
    background: #fff;
    color: #4b5563;
    cursor: pointer;
    font-size: 14px;
}

.ed-icons button:hover { border-color: var(--brand-primary); color: var(--brand-primary); }
.ed-icons button[aria-pressed="true"] { background: var(--brand-primary); color: #fff; }

/* ------------------------------------------------------- the catalogue */
.ed-catalogue { border: 1px solid rgba(17, 24, 39, .12); border-radius: 13px; background: #fff; padding: 14px; }
.ed-catalogue__search { margin-bottom: 12px; }
.ed-catalogue__group + .ed-catalogue__group { margin-top: 14px; }

.ed-catalogue__label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: #6b7280;
    margin-bottom: 7px;
}

.ed-catalogue__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 8px; }

.ed-chip {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 9px 11px;
    border: 1px solid rgba(17, 24, 39, .12);
    border-radius: 10px;
    background: #fff;
    text-align: left;
    font-size: 13px;
    font-weight: 600;
    color: #1f2937;
    cursor: pointer;
    transition: border-color .14s ease, transform .14s ease;
}

.ed-chip:hover { border-color: var(--brand-primary); transform: translateY(-1px); }
.ed-chip i { width: 20px; text-align: center; font-size: 15px; }
.ed-chip[hidden] { display: none; }
.ed-catalogue__group[hidden] { display: none; }

.ed-empty { padding: 22px; text-align: center; color: #6b7280; font-size: 13.5px; }

/* -------------------------------------------------------------- themes */
.th-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }

.th-card {
    border: 1px solid rgba(17, 24, 39, .12);
    border-radius: 14px;
    overflow: hidden;
    background: #fff;
    display: flex;
    flex-direction: column;
}

.th-card__preview {
    min-height: 128px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 8px;
}

.th-card__dot { width: 30px; height: 30px; border-radius: 50%; background: currentColor; opacity: .35; }
.th-card__btn { padding: 8px 10px; text-align: center; font-size: 12px; font-weight: 700; }
/* The name and the actions used to share one row, so a theme called
   "Minimal Claro" was shown as "Minim…". The name gets the line. */
.th-card__foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 11px 12px;
    border-top: 1px solid rgba(17, 24, 39, .1);
}

.th-card__name { flex: 1 0 100%; font-weight: 600; font-size: 13.5px; line-height: 1.3; }

.th-badge {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .07em;
    text-transform: uppercase;
    padding: 2px 7px;
    border-radius: 999px;
    background: rgba(17, 24, 39, .07);
    color: #4b5563;
}

@media (prefers-reduced-motion: reduce) {
    .ed-chip:hover { transform: none; }
    .ed-switch__track, .ed-switch__track::after { transition: none; }
}

/* A colour that inherits the theme is shown dimmed: the swatch below a ticked
   "Do tema" is not what the button will use. */
.ed-field:has(input[type="checkbox"]:checked) input[type="color"] {
    opacity: .35;
    filter: grayscale(.6);
}

.ed-field input[type="color"] { width: 100%; max-width: 72px; height: 34px; padding: 3px; }
.ed-field .form-check { margin-top: 4px; }
.ed-field .form-check-label { font-size: 11.5px; font-weight: 500; color: #6b7280; }

/* --------------------------------------------------- the panel as a dialog */
/* Closed, the <details> is one line at the bottom of the block row. Open, its
   summary becomes the dialog header and the box (.ed-dialog) is fixed over
   the page with a backdrop behind it. Nothing relies on flex on <details> or
   on a negative z-index: both break on mobile Safari. */
.ed-block__summary-open, .ed-block__close, .ed-dialog__backdrop, .ed-dialog__foot { display: none; }

/* Without JavaScript the panes are all shown; the controller hides the rest. */
/* MONO-04/MONO-05: the single-link notice and the offer to become one. */
.ed-mono { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; margin-bottom: 14px; padding: 12px 14px; border-radius: 10px; background: #eef2ff; border: 1px solid #c7d2fe; font-size: 13.5px; }
.ed-mono--offer { background: #f8fafc; border-color: rgba(17, 24, 39, .12); }
.ed-mono__text { display: flex; flex-direction: column; gap: 2px; flex: 1 1 260px; min-width: 0; }
.ed-mono form { margin: 0; }
.ed-sections { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid rgba(17, 24, 39, .12); overflow-x: auto; scrollbar-width: none; }
.ed-sections::-webkit-scrollbar { display: none; }
.ed-section {
    flex: none; display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 14px; margin-bottom: -1px;
    border: 0; border-bottom: 2px solid transparent; background: none;
    color: #6b7280; font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.ed-section:hover { color: #111827; }
.ed-section[aria-selected="true"] { color: var(--brand-primary); border-bottom-color: var(--brand-primary); }
.ed-section__count { min-width: 20px; padding: 1px 6px; border-radius: 999px; background: rgba(17, 24, 39, .08); font-size: 11.5px; text-align: center; }
.ed-section[aria-selected="true"] .ed-section__count { background: var(--brand-primary); color: #fff; }

/* The live sample at the top of a block's dialog: the card's own ground
   around one button, so colours read as they will on the page. */
.ed-sample {
    flex: none;
    padding: 14px 18px;
    background: var(--card-bg-color, #f3f4f6);
    color: var(--card-text-color, inherit);
    border-bottom: 1px solid rgba(17, 24, 39, .1);
}
.ed-sample .tt-block { margin: 0; }
.ed-sample .card-blocks { display: block; }

/* The one save button, under whichever tab is open. */
.ed-save { position: sticky; bottom: 0; z-index: 5; padding: 10px 0 4px; background: linear-gradient(to top, #fff 70%, rgba(255, 255, 255, 0)); }

/* The catalogue modal is opened from the panel header; closed, it takes no
   room at all. */
.ed-catalogue-modal:not([open]) { display: none; }
.ed-catalogue--dialog { border: 0; padding: 0; }

.ed-modal[open] .ed-dialog__backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(17, 24, 39, .45);
}

.ed-modal[open] .ed-dialog {
    position: fixed;
    z-index: 2001;
    top: 4vh;
    left: 50%;
    transform: translateX(-50%);
    width: min(760px, 96vw);
    max-height: 92vh;
    max-height: 92dvh;
    display: flex;
    flex-direction: column;
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 30px 80px -30px rgba(17, 24, 39, .8);
    overflow: hidden;
}

/* The summary is the header: it is drawn at the top of the box. */
.ed-modal[open] > .ed-block__summary {
    position: fixed;
    z-index: 2002;
    top: 4vh;
    left: 50%;
    transform: translateX(-50%);
    width: min(760px, 96vw);
    box-sizing: border-box;
    padding: 12px 16px;
    font-size: 14px;
    color: #111827;
    background: #f9fafb;
    border-radius: 16px 16px 0 0;
    border-bottom: 1px solid rgba(17, 24, 39, .08);
    cursor: default;
}
.ed-modal[open] .ed-dialog { padding-top: 46px; }
.ed-modal[open] .ed-block__summary-closed,
.ed-modal[open] .ed-block__chevron { display: none; }
.ed-modal[open] .ed-block__summary-open { display: inline; }
.ed-modal[open] .ed-block__summary-open b { font-weight: 700; }
.ed-modal[open] .ed-block__close { display: inline-block; margin-left: auto; padding: 6px; cursor: pointer; color: #6b7280; font-size: 16px; }
.ed-modal[open] .ed-block__close:hover { color: #111827; }

.ed-modal[open] .ed-tabs { flex: none; background: #fff; }
.ed-modal[open] .ed-panel-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: #fff;
}
.ed-modal[open] .ed-dialog__foot {
    flex: none;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 10px 16px;
    border-top: 1px solid rgba(17, 24, 39, .1);
    background: #f9fafb;
}

body.ed-dialog-open { overflow: hidden; }

@media (min-width: 1200px) {
    .ed-modal[open] .ed-dialog,
    .ed-modal[open] > .ed-block__summary { left: 4vw; transform: none; width: min(720px, 56vw); }
}

@media (max-width: 575.98px) {
    .ed-modal[open] .ed-dialog,
    .ed-modal[open] > .ed-block__summary { top: 0; left: 0; transform: none; width: 100vw; border-radius: 0; }
    .ed-modal[open] .ed-dialog { height: 100vh; height: 100dvh; max-height: none; }
}

/* A block a failed save pointed at. */
.ed-block--invalid { border-color: #dc2626; }
.ed-block__badge {
    padding: 2px 8px;
    border-radius: 999px;
    background: #fee2e2;
    color: #991b1b;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .03em;
}
