/* ==========================================================================
   Frame Manager editor stylesheet (inc/edit.css)
   Editor chrome + interactive live mode (frame borders, resize dividers,
   modal, toast). Only loaded when the page is NOT in strict read-only mode
   (?preset=...&view=1), where view.css alone is served. Base + view styles
   live in inc/view.css (always loaded).
   ========================================================================== */

/* --------------------------------------------------------------------------
   Header
   -------------------------------------------------------------------------- */
.app-header {
    position: relative;
    z-index: 10;
    min-height: 60px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 16px;
    background: var(--surface);
    backdrop-filter: blur(18px) saturate(1.4);
    -webkit-backdrop-filter: blur(18px) saturate(1.4);
    border-bottom: 1px solid var(--stroke);
}

.brand { display: flex; align-items: center; gap: 12px; margin-right: 16px; }
.brand-logo {
    width: 26px;
    height: 26px;
    display: block;
    filter: drop-shadow(0 2px 6px color-mix(in srgb, var(--accent) 50%, transparent));
}
.brand-text h1 { font-size: 15px; font-weight: 650; letter-spacing: .01em; line-height: 1.15; }
.brand-text span { font-size: 11.5px; color: var(--text-3); opacity: .78; letter-spacing: .04em; }

.spacer { flex: 1; }
.sep { width: 1px; height: 20px; background: var(--stroke-strong); margin: 0 4px; flex-shrink: 0; }

.preset-label {
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: .09em;
    text-transform: uppercase;
    color: var(--text-3);
    flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border: 1px solid var(--stroke);
    background: var(--surface-2);
    color: var(--text);
    padding: 8px 15px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 500;
    line-height: 1;
    letter-spacing: .01em;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: transform .15s ease, background .18s ease, border-color .18s ease, box-shadow .18s ease;
}
.btn:hover {
    border-color: var(--stroke-strong);
    background: var(--surface-3);
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(0, 0, 0, .12);
}
.btn:active { transform: translateY(0) scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }

/* armed state (e.g. swap mode) */
.btn.active {
    border-color: var(--accent);
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.btn.active:hover { background: color-mix(in srgb, var(--accent) 18%, transparent); }

.btn-accent {
    border-color: transparent;
    background: var(--grad);
    color: #fff;
    box-shadow: 0 4px 18px color-mix(in srgb, var(--accent) 40%, transparent);
}
.btn-accent:hover {
    border-color: transparent;
    background: var(--grad);
    box-shadow: 0 6px 24px color-mix(in srgb, var(--accent) 55%, transparent);
    transform: translateY(-1px);
}

.btn-danger { color: var(--danger); }
.btn-danger:hover {
    background: color-mix(in srgb, var(--danger) 12%, transparent);
    border-color: color-mix(in srgb, var(--danger) 45%, transparent);
}

.btn:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.dirty-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--warn);
    box-shadow: 0 0 8px var(--warn);
    margin-left: 2px;
}

/* --------------------------------------------------------------------------
   Inputs & select
   -------------------------------------------------------------------------- */
input[type="text"],
input[type="password"],
select {
    background: var(--surface-2);
    border: 1px solid var(--stroke);
    color: var(--text);
    border-radius: 12px;
    padding: 8px 12px;
    font: inherit;
    font-size: 13.5px;
    outline: none;
    width: 100%;
    transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
input::placeholder { color: var(--text-3); }
input[readonly] {
    opacity: .85;
    background: var(--surface-3);
    cursor: default;
}
input:focus,
select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

select {
    appearance: none;
    -webkit-appearance: none;
    max-width: 210px;
    padding-right: 34px;
    cursor: pointer;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%239aa4c2' stroke-width='1.6' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

/* --------------------------------------------------------------------------
   Form fields
   -------------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 4px; }
.field span {
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: .09em;
    text-transform: uppercase;
    color: var(--text-3);
}

/* --------------------------------------------------------------------------
   Save-inline bar
   -------------------------------------------------------------------------- */
.save-inline {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px 16px;
    background: var(--surface);
    backdrop-filter: blur(18px) saturate(1.4);
    -webkit-backdrop-filter: blur(18px) saturate(1.4);
    border-bottom: 1px solid var(--stroke);
    flex-shrink: 0;
}
.save-inline[hidden] { display: none; }
.save-inline .field { min-width: 0; }
#preset-name-input { min-width: 210px; }
#preset-password-input { min-width: 160px; }

/* --------------------------------------------------------------------------
   Hint bar
   -------------------------------------------------------------------------- */
.hintbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 16px;
    background: var(--surface);
    backdrop-filter: blur(18px) saturate(1.4);
    -webkit-backdrop-filter: blur(18px) saturate(1.4);
    border-bottom: 1px solid var(--stroke);
    color: var(--text-2);
    font-size: 12.5px;
    flex-shrink: 0;
}
.hintbar[hidden] { display: none; }
.hintbar .hint-icon { color: var(--accent); }
.hintbar b { color: var(--text); font-weight: 600; }
.hintbar code {
    color: var(--accent);
    background: var(--surface-3);
    border: 1px solid var(--stroke);
    padding: 1px 8px;
    border-radius: 999px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 11px;
    font-weight: 500;
}

/* Dividers: base sizing lives in view.css. Edit mode adds the visible line + grip. */
.divider::before {
    content: "";
    position: absolute;
    background: var(--stroke);
    transition: background .15s ease;
}
.divider-row::before { top: 0; bottom: 0; left: 50%; width: 1.5px; transform: translateX(-50%); }
.divider-col::before { left: 0; right: 0; top: 50%; height: 1.5px; transform: translateY(-50%); }

/* edit mode: resize lines are clearly visible */
body.editing .divider-row::before { background: color-mix(in srgb, var(--accent) 45%, transparent); width: 2px; }
body.editing .divider-col::before { background: color-mix(in srgb, var(--accent) 45%, transparent); height: 2px; }

/* drag in progress: full accent line */
body.resizing .divider-row::before { background: var(--accent); width: 2px; }
body.resizing .divider-col::before { background: var(--accent); height: 2px; }

/* grip pill on hover / drag */
.divider::after {
    content: "";
    position: absolute;
    background: var(--accent);
    border-radius: 999px;
    box-shadow: 0 0 10px color-mix(in srgb, var(--accent) 60%, transparent);
    opacity: 0;
    transition: opacity .18s ease, transform .18s ease;
}
.divider-row::after {
    top: 50%; left: 50%;
    width: 4px; height: 34px;
    transform: translate(-50%, -50%) scale(.6);
}
.divider-col::after {
    top: 50%; left: 50%;
    width: 34px; height: 4px;
    transform: translate(-50%, -50%) scale(.6);
}
.divider:hover::after,
.divider.active::after {
    opacity: .9;
    transform: translate(-50%, -50%) scale(1);
}

body.resizing { user-select: none; }
body.resizing-row { cursor: ew-resize; }
body.resizing-col { cursor: ns-resize; }

/* --------------------------------------------------------------------------
   Frames
   -------------------------------------------------------------------------- */
.leaf { position: relative; width: 100%; height: 100%; min-width: 0; min-height: 0; }

.leaf-editor {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    overflow: auto;
    /* flat blueprint-holo grid, purely decorative, no glow, no gradient */
    background-color: color-mix(in srgb, var(--bg) 62%, var(--surface-2));
    background-image:
        linear-gradient(to right, color-mix(in srgb, var(--accent) 5%, transparent) 1px, transparent 1px),
        linear-gradient(to bottom, color-mix(in srgb, var(--accent) 5%, transparent) 1px, transparent 1px),
        linear-gradient(to right, color-mix(in srgb, var(--accent) 2.5%, transparent) 1px, transparent 1px),
        linear-gradient(to bottom, color-mix(in srgb, var(--accent) 2.5%, transparent) 1px, transparent 1px);
    background-size: 26px 26px, 26px 26px, 130px 130px, 130px 130px;
    background-position: center;
}

.editor-inner {
    position: relative;
    width: min(340px, 94%);
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 28px;
    background: var(--surface-2);
    border: 1px solid var(--stroke-strong);
    border-radius: var(--radius-l);
    box-shadow: var(--shadow-1);
    transition: border-color .2s ease, box-shadow .2s ease;
}
.editor-inner:focus-within {
    border-color: color-mix(in srgb, var(--accent) 48%, transparent);
    box-shadow: var(--shadow-1), 0 0 0 4px color-mix(in srgb, var(--accent) 10%, transparent);
}
.editor-inner input[type="text"] {
    background: var(--surface);
}

/* preset picker, icon top-right of editor card */
.btn-preset-pick {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 2;
    width: 26px;
    height: 26px;
    padding: 0;
    border: 1px solid var(--stroke);
    border-radius: 999px;
    background: var(--surface-3);
    color: var(--text-2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color .15s ease, border-color .15s ease, background .15s ease;
}
.btn-preset-pick:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--surface-2);
}

.preset-drop {
    position: absolute;
    top: 40px;
    right: 6px;
    z-index: 10;
    min-width: 160px;
    background: var(--surface-2);
    border: 1px solid var(--stroke-strong);
    border-radius: var(--radius-m);
    box-shadow: var(--shadow-2);
    padding: 4px;
    display: none;
    flex-direction: column;
}
.preset-drop.open { display: flex; }

.preset-item {
    display: block;
    width: 100%;
    padding: 7px 12px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 12.5px;
    text-align: left;
    cursor: pointer;
    white-space: nowrap;
    transition: background .12s ease;
}
.preset-item:hover {
    background: var(--surface-3);
    color: var(--accent);
}

.frame-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

.btn-icon {
    padding: 0;
    width: 31px;
    height: 31px;
    min-width: 0;
}
.btn-swap-frame svg {
    display: block;
    width: 15px;
    height: 15px;
    opacity: .7;
    transition: opacity .15s ease;
}
.btn-swap-frame:hover svg {
    opacity: 1;
}

.flash { animation: flashBg 1.5s ease; }
@keyframes flashBg {
    0%, 100% { border-color: var(--stroke-strong); }
    25%, 55% {
        border-color: var(--danger);
        box-shadow: 0 0 0 4px color-mix(in srgb, var(--danger) 25%, transparent);
    }
}

/* swap mode: pick source, then destination */
body.swapping .leaf-editor { cursor: pointer; }
body.swapping .leaf-editor::after {
    content: "⇄";
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 5;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--stroke-strong);
    color: var(--accent);
    font-size: 13px;
    box-shadow: var(--shadow-1);
    pointer-events: none;
}
.leaf-editor.swap-source {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
    background-color: color-mix(in srgb, var(--accent) 8%, transparent);
}
.leaf-editor.swap-source::after {
    content: "Source";
    width: auto;
    padding: 0 10px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .05em;
    color: var(--text);
}

/* live frames in interactive mode keep the subtle frame border; in strict
   read-only mode (view=1) edit.css is not loaded, so no border exists */
.leaf-live { box-shadow: inset 0 0 0 1px var(--stroke); }

/* --------------------------------------------------------------------------
   Modal
   -------------------------------------------------------------------------- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: color-mix(in srgb, var(--bg) 55%, transparent);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
}
.modal.show { opacity: 1; pointer-events: auto; }

.modal-card {
    width: min(360px, 94vw);
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 26px;
    background: var(--surface-2);
    border: 1px solid var(--stroke-strong);
    border-radius: var(--radius-l);
    box-shadow: var(--shadow-2);
    transform: translateY(10px) scale(.98);
    transition: transform .2s ease;
}
.modal.show .modal-card { transform: none; }
.modal-card h3 { font-size: 16px; font-weight: 650; }
.modal-desc { font-size: 13px; color: var(--text-2); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* --------------------------------------------------------------------------
   Toast
   -------------------------------------------------------------------------- */
#toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    z-index: 400;
    transform: translateX(-50%) translateY(14px);
    max-width: min(560px, 88vw);
    padding: 10px 16px;
    background: var(--surface-2);
    border: 1px solid var(--stroke-strong);
    border-radius: 999px;
    box-shadow: var(--shadow-2);
    color: var(--text);
    font-size: 13px;
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity .22s ease, transform .22s ease;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* --------------------------------------------------------------------------
   view=1 safety net
   view.css (always loaded) already provides the view=1 behaviour: no frame
   border until hover, resize lines on hover. Just keep this file from ever
   re-introducing chrome if it happens to load on a view=1 page.
   -------------------------------------------------------------------------- */
body.view-only .shared-bar,
body.view-only .shared-brand { display: none !important; }

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 760px) {
    .brand-text span { display: none; }
    .app-header { padding: 10px 12px; gap: 6px; }
    .hintbar { font-size: 11.5px; padding: 8px 12px; }
    .save-inline { padding: 10px 12px; }
    .editor-inner { padding: 20px; gap: 10px; }
    #toast { max-width: min(340px, 92vw); font-size: 12px; }
}
