/* Editor chrome — loosely matches the root site's look (Inter, blue accent),
   kept self-contained (no cross-folder @import) so control/ stays a
   standalone static subsystem, same pattern as calendar/static/style.css. */

:root {
    --primary: #2f66f3;
    --primary-dark: #1f4fce;
    --text: #1b2430;
    --muted: #667085;
    --bg: #f5f7fb;
    --surface: #ffffff;
    --border: #e3e7ef;
    --border-strong: #cdd4e0;
    --shadow: 0 1px 3px rgba(20, 30, 60, 0.08);
    --r: 12px;
    --r-lg: 16px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
}

body {
    font-family: "Inter", system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

a { color: var(--primary); }

.ctrl-topbar {
    flex: 0 0 auto;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.ctrl-topbar h1 {
    font-size: 16px;
    margin: 0;
}
.ctrl-topbar .ctrl-kicker {
    font-size: 12px;
    color: var(--muted);
    margin: 0 0 2px 0;
}
.ctrl-topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.ctrl-databanner {
    flex: 0 0 auto;
    z-index: 19;
    padding: 8px 24px;
    background: #fff6dd;
    border-bottom: 1px solid #f0ddaa;
    color: #6b5410;
    font-size: 12.5px;
    line-height: 1.4;
}
.ctrl-databanner a { color: inherit; font-weight: 600; text-decoration: underline; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--r);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-danger { color: #c62828; border-color: #f0c4c4; }
.btn-danger:hover { border-color: #c62828; color: #c62828; }

.ctrl-layout {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
}

#editor-column {
    flex: 0 0 520px;
    min-width: 320px;
    max-width: 75%;
    overflow-y: auto;
    height: 100%;
    padding: 20px 12px 40px 24px;
}

#ctrl-resizer {
    flex: 0 0 9px;
    cursor: col-resize;
    background: transparent;
    position: relative;
}
#ctrl-resizer::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 4px;
    width: 1px;
    background: var(--border-strong);
}
#ctrl-resizer:hover::after,
#ctrl-resizer:active::after {
    background: var(--primary);
    width: 2px;
    left: 3.5px;
}

#preview-column {
    flex: 1 1 auto;
    min-width: 320px;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 20px 24px 0 12px;
}

@media (max-width: 980px) {
    html, body { height: auto; overflow: visible; }
    .ctrl-layout { flex-direction: column; height: auto; }
    #editor-column, #preview-column {
        flex: 1 1 auto;
        max-width: 100%;
        height: auto;
        overflow: visible;
        padding: 16px;
    }
    #ctrl-resizer { display: none; }
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow);
    padding: 16px 18px;
    margin-bottom: 16px;
}
.panel > h2 {
    font-size: 14px;
    margin: 0 0 12px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.panel.collapsible { padding: 0; }
.panel-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 18px;
    cursor: pointer;
    user-select: none;
}
.panel-head h3 { margin: 0; font-size: 14px; flex: 1; }
.panel-chevron { font-size: 11px; color: var(--muted); transition: transform 0.15s; display: inline-block; }
.panel.collapsed .panel-chevron { transform: rotate(-90deg); }
.panel-body { padding: 0 18px 16px 18px; }
.panel.collapsed .panel-body { display: none; }

.field-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 14px;
}
label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 8px;
    min-width: 0;
}
label.full { grid-column: 1 / -1; }
input, select, textarea {
    width: 100%;
    min-width: 0;
    font: inherit;
    font-size: 13px;
    padding: 7px 9px;
    border-radius: 8px;
    border: 1px solid var(--border-strong);
    background: #fff;
    color: var(--text);
}
input[type="checkbox"],
input[type="radio"] {
    width: auto;
    min-width: auto;
}
textarea { resize: vertical; min-height: 60px; font-family: inherit; }

.radio-row { display: flex; gap: 14px; flex-wrap: wrap; }
.radio-row label { flex-direction: row; align-items: center; font-size: 13px; color: var(--text); }
.radio-row input { width: auto; }

.task-card {
    border: 1px solid var(--border);
    border-radius: var(--r);
    margin-bottom: 10px;
}
.task-card-head {
    border-radius: var(--r) var(--r) 0 0;
}
.task-card:not(.open) .task-card-head {
    border-radius: var(--r);
}
.task-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px;
    background: #fafbfe;
    cursor: pointer;
}
.task-card-head .tch-title { font-size: 13px; font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-card-head .tch-meta { font-size: 11px; color: var(--muted); white-space: nowrap; }
.task-card-actions { display: flex; gap: 4px; }
.task-card-body { padding: 12px; border-top: 1px solid var(--border); display: none; }
.task-card.open .task-card-body { display: block; }

.param-table-wrap { overflow-x: auto; margin: 8px 0; }
.param-table { border-collapse: collapse; width: 100%; font-size: 12px; }
.param-table th, .param-table td { border: 1px solid var(--border); padding: 4px 6px; }
.param-table th { background: #fafbfe; font-weight: 600; text-align: left; }
.param-table input { width: 100%; min-width: 70px; border: none; padding: 3px 4px; font-size: 12px; }
.param-table input:focus { outline: 1px solid var(--primary); border-radius: 4px; }

.gen-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 6px 0; font-size: 12px; }
.gen-row select, .gen-row input { font-size: 12px; padding: 4px 6px; }

.muted { color: var(--muted); font-size: 12px; }

.ctrl-preview-toolbar {
    flex: 0 0 auto;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 10px 14px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}
.ctrl-preview-toolbar select { font-size: 13px; }

#doc-preview-scroll {
    flex: 1 1 auto;
    overflow-y: auto;
    background: #dfe3ea;
    border-radius: var(--r-lg);
    padding: 24px;
    overflow-x: auto;
}

.embed-toggle-row { display: flex; gap: 16px; margin: 8px 0; font-size: 12px; }
.embed-editor { border: 1px dashed var(--border-strong); border-radius: 8px; padding: 10px; margin: 8px 0; }
.embed-table-grid { border: 1px solid var(--border-strong); border-radius: 8px; margin: 8px 0; }
.table-grid-row { display: flex; }
.table-grid-row:not(:last-child) input { border-bottom: 1px solid var(--border-strong); }
.table-grid-row input {
    flex: 1;
    width: auto;
    border: none;
    border-radius: 0;
}
.table-grid-row input:not(:last-child) { border-right: 1px solid var(--border-strong); }
.table-grid-row:first-child input:first-child { border-top-left-radius: 7px; }
.table-grid-row:first-child input:last-child { border-top-right-radius: 7px; }
.table-grid-row:last-child input:first-child { border-bottom-left-radius: 7px; }
.table-grid-row:last-child input:last-child { border-bottom-right-radius: 7px; }

.chips-row {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    margin: 6px 0;
}
.chip {
    font: inherit;
    font-size: 12px;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    padding: 3px 9px;
    border-radius: 999px;
    border: 1px solid var(--primary);
    background: #eaf0fe;
    color: var(--primary-dark);
    cursor: pointer;
    width: auto;
}
.chip:hover { background: var(--primary); color: #fff; }

.catalog-dropdown-wrap { position: relative; }
.catalog-panel {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    width: 340px;
    max-height: 70vh;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: 0 8px 28px rgba(20, 30, 60, 0.18);
    padding: 10px;
    z-index: 50;
}
.catalog-list { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.catalog-row {
    display: flex;
    align-items: center;
    gap: 6px;
    border-radius: 8px;
    padding: 4px 4px 4px 8px;
    flex-wrap: wrap;
}
.catalog-row.active { background: #eaf0fe; }
.catalog-row-name {
    flex: 1;
    text-align: left;
    background: none;
    border: none;
    padding: 6px 4px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    width: auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.catalog-row-name:hover { color: var(--primary); }
.catalog-row-actions { display: flex; gap: 2px; flex: none; }
.catalog-history-sub {
    flex-basis: 100%;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 6px 0 4px 8px;
    border-top: 1px dashed var(--border);
    margin-top: 4px;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(20, 30, 60, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.modal-box {
    background: var(--surface);
    border-radius: var(--r-lg);
    width: min(560px, 92vw);
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-body { padding: 16px 18px; overflow-y: auto; }

.library-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 4px;
    border-bottom: 1px solid var(--border);
}
.library-row-label { flex: 1; font-size: 13px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
