/* COS Editor — styles for /coseditor (npops). Colour tokens come from main.css. */
:root {
    --line: #34353b;
    --muted: #8d8d92;
    --green: #5aa469;
    --formbg: #18181a;
    --formborder: #3a3b40;
    --formfocus: var(--primary);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

/* Layout: full-bleed under the site header */
.ce-shell { display: flex; align-items: stretch; min-height: calc(100vh - 3.25rem); font-size: 15px; line-height: 1.45; }
.ce-sidebar {
    flex: 0 0 320px;
    background: var(--bgsecondary);
    border-right: 1px solid var(--line);
    padding: 1rem .75rem;
}
.ce-sidebar h2 {
    margin: 0 0 .6rem .5rem;
    font-size: .72rem; letter-spacing: .08em; text-transform: uppercase;
    color: var(--muted); font-weight: 600;
}
.ce-sidebar ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .25rem; }
.ce-provider {
    width: 100%; display: flex; align-items: center; gap: .65rem;
    padding: .55rem .75rem; margin: 0;
    background: transparent; color: var(--text);
    border: 1px solid transparent; border-radius: 6px;
    text-align: left; cursor: pointer; font: inherit;
}
.ce-provider:hover { background: rgba(255,255,255,.04); }
.ce-provider.active { background: var(--secondary); border-color: var(--primary); color: var(--white); }
.ce-provider-logo {
    flex: 0 0 auto; width: 56px; height: 36px; padding: 4px 6px;
    display: flex; align-items: center; justify-content: center;
    background: var(--white); border-radius: 5px;
}
.ce-provider-logo img { display: block; max-width: 100%; max-height: 100%; object-fit: contain; }
.ce-provider-logo.no-logo {
    background: var(--linkbg); color: var(--link);
    font-size: .72rem; font-weight: 700; letter-spacing: .06em;
}
.ce-provider-text { display: flex; flex-direction: column; min-width: 0; }
.ce-provider-name { font-weight: 600; }
.ce-provider-label { font-size: .8rem; color: var(--muted); }
.ce-provider.active .ce-provider-label { color: var(--text); }

.ce-main { flex: 1; min-width: 0; padding: 1.5rem; position: relative; }
.ce-main.dragging::after {
    content: "Drop .xml or patch .zip";
    position: absolute; inset: .75rem;
    display: flex; align-items: center; justify-content: center;
    border: 2px dashed var(--primary); border-radius: 10px;
    background: rgba(31,31,33,.88); color: var(--white); font-size: 1.1rem;
    pointer-events: none;
}
.ce-card {
    max-width: 1000px;
    background: var(--bgsecondary);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 1.25rem 1.5rem 1.5rem;
}
.ce-card-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.ce-card-head h2 { margin: 0; font-size: 1.25rem; color: var(--white); }
.ce-card-head p { margin: .15rem 0 0; color: var(--muted); font-size: .85rem; }

/* Buttons */
.ce-toolbar { display: flex; flex-wrap: wrap; gap: .5rem; }
.ce-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    padding: .5rem .9rem; margin: 0;
    border-radius: 6px; border: 1px solid var(--linkbghover);
    background: var(--linkbg); color: var(--link);
    font: inherit; font-size: .85rem; cursor: pointer;
    transition: background .15s ease;
}
.ce-btn:hover { background: var(--linkbghover); color: var(--white); }
.ce-btn.primary {
    background: var(--primary); border-color: var(--primary); color: var(--white);
    font-weight: 600; padding: .65rem 1.4rem; font-size: .95rem;
}
.ce-btn.primary:hover { background: var(--secondary); }
.ce-btn.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.ce-btn.ghost:hover { background: rgba(255,255,255,.05); }
.ce-btn:disabled { opacity: .6; cursor: progress; }
.ce-btn input[type=file] { display: none; }
.ce-link { background: none; border: 0; padding: 0; margin: 0 0 0 .5rem; color: var(--link); cursor: pointer; font: inherit; text-decoration: underline; }

.ce-baseinfo {
    display: flex; align-items: center; flex-wrap: wrap;
    margin-bottom: 1rem; padding: .5rem .75rem;
    background: var(--linkbg); border: 1px solid var(--linkbghover); border-radius: 6px;
    font-size: .85rem;
}

/* Form */
.ce-form {
    display: grid;
    grid-template-columns: 170px minmax(0, 1fr);
    column-gap: 1rem; row-gap: .35rem;
    align-items: start;
}
.ce-label { display: flex; flex-direction: column; padding-top: .5rem; text-wrap: nowrap; }
.ce-label span { color: var(--text); }
.ce-key { font-size: .7rem; color: var(--muted); font-family: ui-monospace, Consolas, monospace; }
.ce-field { min-width: 0; padding-bottom: .4rem; }
.ce-control { display: flex; gap: .4rem; }
.ce-control input, .ce-control textarea {
    flex: 1; width: 100%; min-width: 0; margin: 0;
    height: auto; padding: .5rem .65rem;
    background: var(--formbg); color: var(--white);
    border: 1px solid var(--formborder); border-radius: 6px;
    font: inherit; font-family: ui-monospace, Consolas, monospace; font-size: .9rem;
}
.ce-control textarea { resize: vertical; min-height: 4.5rem; }
.ce-control input:focus, .ce-control textarea:focus { outline: none; border-color: var(--formfocus); box-shadow: 0 0 0 2px rgba(134,126,86,.3); }
.ce-control .invalid { border-color: var(--red); }
/* Masked text field — used instead of type=password so password managers don't treat this as a login form. */
.ce-control .ce-masked { -webkit-text-security: disc; }
/* Hook so JS can undo any browser autofill that slips through. */
@keyframes ceAutofill { from { opacity: 1; } to { opacity: 1; } }
.ce-control input:-webkit-autofill { animation-name: ceAutofill; animation-duration: 1ms; }
.ce-control input[readonly] { cursor: text; }
/* Field group heading (e.g. T2G / QEC / Options) spanning both columns. */
.ce-group {
    grid-column: 1 / -1;
    margin: .9rem 0 .35rem; padding-bottom: .35rem;
    border-bottom: 1px solid var(--line);
    color: var(--primary); font-size: .75rem; font-weight: 700;
    letter-spacing: .08em; text-transform: uppercase;
}
.ce-group:first-child { margin-top: 0; }
/* Fields whose "IsUse" switch is off. */
.ce-off { opacity: .5; }
.ce-off:focus-within { opacity: 1; }
/* True / False switch. */
.ce-bool {
    display: inline-flex; padding: 3px; gap: 3px;
    background: var(--formbg); border: 1px solid var(--formborder); border-radius: 7px;
}
.ce-bool.invalid { border-color: var(--red); }
.ce-bool-opt {
    margin: 0; padding: .35rem 1.1rem;
    background: transparent; color: var(--muted);
    border: 0; border-radius: 5px;
    font: inherit; font-size: .85rem; font-family: ui-monospace, Consolas, monospace; cursor: pointer;
}
.ce-bool-opt:hover { color: var(--white); }
.ce-bool-opt[aria-checked="true"] { background: var(--secondary); color: var(--white); box-shadow: inset 0 0 0 1px var(--primary); }
.ce-bool-opt:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.ce-reveal {
    flex: 0 0 auto; margin: 0; padding: 0 .75rem;
    background: transparent; color: var(--muted);
    border: 1px solid var(--formborder); border-radius: 6px;
    font: inherit; font-size: .8rem; cursor: pointer;
}
.ce-reveal:hover { color: var(--white); }
.ce-error { color: var(--red); font-size: .78rem; min-height: 0; }
.ce-error:empty { display: none; }

.ce-actions { display: flex; justify-content: center; margin-top: 1.25rem; }

/* Preview */
.ce-preview { margin-top: 1.5rem; border-top: 1px solid var(--line); padding-top: 1rem; }
.ce-preview summary { cursor: pointer; color: var(--muted); font-size: .85rem; user-select: none; }
.ce-preview summary:hover { color: var(--text); }
.ce-tabs { display: flex; flex-wrap: wrap; gap: .25rem; margin: .75rem 0 .5rem; }
.ce-tab {
    margin: 0; padding: .3rem .7rem;
    background: transparent; color: var(--muted);
    border: 1px solid var(--line); border-radius: 999px;
    font: inherit; font-size: .78rem; cursor: pointer;
}
.ce-tab.active { color: var(--white); border-color: var(--primary); background: var(--secondary); }
.ce-preview pre {
    margin: 0; padding: .9rem 1rem; overflow-x: auto;
    background: var(--formbg); border: 1px solid var(--line); border-radius: 6px;
    color: var(--text); font-size: .8rem; line-height: 1.5;
}

.ce-note { max-width: 860px; margin-top: .9rem; color: var(--muted); font-size: .78rem; }

/* Toast */
.ce-toast {
    position: fixed; right: 1rem; bottom: 1rem; z-index: 50;
    max-width: min(420px, calc(100vw - 2rem));
    padding: .75rem 1rem; border-radius: 8px;
    background: var(--bgsecondary); color: var(--white);
    border: 1px solid var(--line); border-left: 4px solid var(--link);
    box-shadow: 0 6px 24px rgba(0,0,0,.4);
    opacity: 0; transform: translateY(8px); pointer-events: none;
    transition: opacity .2s ease, transform .2s ease;
}
.ce-toast.show { opacity: 1; transform: none; }
.ce-toast.success { border-left-color: var(--green); }
.ce-toast.error { border-left-color: var(--red); }

/* Narrow screens */
@media (max-width: 720px) {
    .ce-shell { flex-direction: column; min-height: 0; }
    .ce-sidebar { flex: none; border-right: 0; border-bottom: 1px solid var(--line); padding: .75rem 1rem; }
    .ce-sidebar ul { flex-direction: row; flex-wrap: wrap; }
    .ce-sidebar li { flex: 0 0 auto; }
    .ce-main { padding: 1rem; }
    .ce-card { padding: 1rem; }
    .ce-form { grid-template-columns: 1fr; }
    .ce-label { padding-top: .25rem; flex-direction: row; align-items: baseline; gap: .5rem; }
    .ce-actions .ce-btn { width: 100%; }
}
