/* ================================================================
   Outprime — Doc Panel Extras
   Extends hud_theme.css with: shell grid, tab nav, form controls,
   lookups, toolbars, switches, radios, status chip, modals.
   Load AFTER hud_theme.css.
   Uses existing tokens: --text, --muted, --line, --accent, --accent2,
                         --mono, --ui, --bg, --bg2, --shadow, --shadow2
   ================================================================ */


/* ─── Outer panel hook ───
   If your wrapper uses id="docPanel" class="open" you already get width
   rules from hud_theme.css. This just makes sure a bare .doc-panel class
   also works (for preview / standalone pages).                        */
.doc-panel:not(#docPanel) {
    height: 100%;
    display: flex;
    flex-direction: column;
    background: rgba(255, 255, 255, .6);
    border-right: 1px solid var(--line);
    overflow: hidden;
    flex: 1;
    min-width: 0;
    position: relative;
}


/* ─── Shell: left tab-nav + content ─── */
/* minmax(0, 1fr) is CRITICAL — prevents grid cells from being forced
   wider than the container by wide children (tables, long text, etc).
   Without it, the 1fr column refuses to shrink below its min-content
   width and the Items tab blows out horizontally.                   */
.doc-shell {
    flex: 1 1 auto;
    display: grid;
    grid-template-columns: 170px minmax(0, 1fr);
    min-height: 0;
    min-width: 0;
    overflow: hidden;
}


/* ─── Doc nav (tabs on the left inside the doc) ─── */
.doc-nav {
    border-right: 1px solid var(--line);
    background: rgba(255, 255, 255, .45);
    backdrop-filter: blur(8px);
    padding: 10px 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.doc-nav button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    text-align: left;
    padding: 7px 14px;
    border: 0;
    background: transparent;
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--muted);
    border-left: 2px solid transparent;
    cursor: pointer;
    transition: background .12s, color .12s, border-color .12s;
    position: relative;
}

.doc-nav button:hover {
    background: rgba(37, 99, 235, .04);
    color: var(--text);
}

.doc-nav button.active {
    background: rgba(37, 99, 235, .06);
    color: var(--accent);
    border-left-color: var(--accent);
    font-weight: 600;
}

.doc-nav .nav-num {
    font-size: 9px;
    opacity: .5;
    letter-spacing: .5px;
    min-width: 14px;
}

.doc-nav button.active .nav-num {
    opacity: 1;
}


/* ─── Doc body padding + shrink rules ───
   min-width: 0 is the flex/grid "escape hatch" that lets this cell
   shrink below its intrinsic content width. Combined with overflow-x:auto,
   any too-wide child (typically a data table) scrolls inside the pane
   instead of breaking the whole layout.                              */
.doc-body {
    padding: 18px 22px 16px;
    min-width: 0;
    min-height: 0;
    overflow-x: auto;
}

/* Sections need the same escape hatch so they don't propagate width up */
.doc-body .doc-section {
    min-width: 0;
}

/* Wide tables (Items, Warranty, etc.) scroll horizontally inside their
   section rather than blowing out the whole doc-panel.                */
.doc-body .doc-table {
    max-width: 100%;
}


/* ─── Section title with bottom rule ─── */
.doc-section-title {
    padding-bottom: 6px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 0;
}

.doc-divider {
    height: 1px;
    background: var(--line);
    margin: 20px 0;
}


/* ─── Fields: slightly wider label column ─── */
.doc-field {
    grid-template-columns: 150px 1fr;
    padding: 5px 0;
    margin-bottom: 0;
    min-height: 28px;
}

.doc-label {
    font-family: var(--mono);
    font-size: 9px;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--muted);
    padding-top: 2px;
}


/* ─── Inputs / selects / textarea ─── */
.doc-input,
.doc-select,
.doc-textarea {
    width: 100%;
    border: 0;
    border-bottom: 1px dashed rgba(223, 228, 241, .7);
    background: transparent;
    padding: 3px 3px;
    font-family: var(--ui);
    font-size: 12px;
    font-weight: 500;
    color: var(--text);
    outline: 0;
    border-radius: 3px 3px 0 0;
    transition: background .15s, border-color .15s;
}

.doc-input:hover,
.doc-select:hover,
.doc-textarea:hover {
    background: rgba(37, 99, 235, .04);
    border-bottom-color: rgba(37, 99, 235, .35);
}

.doc-input:focus,
.doc-select:focus,
.doc-textarea:focus {
    border-bottom: 1px solid var(--accent);
    background: rgba(37, 99, 235, .05);
}

.doc-input[readonly],
.doc-input:disabled,
.doc-textarea[readonly],
.doc-textarea:disabled {
    color: var(--muted);
    cursor: default;
    border-bottom-style: dotted;
    border-bottom-color: var(--line);
}

.doc-input[readonly]:hover,
.doc-input:disabled:hover,
.doc-textarea[readonly]:hover {
    background: transparent;
    border-bottom-color: var(--line);
}

.doc-textarea {
    resize: vertical;
    min-height: 42px;
    padding: 6px 8px;
    border: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    border-radius: 5px;
    line-height: 1.5;
    font-family: var(--ui);
}

.doc-textarea:hover {
    border-color: rgba(37, 99, 235, .25);
}

.doc-textarea:focus {
    border: 1px solid var(--accent);
}

.doc-select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%23596276' d='M0 0h10L5 6z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 4px center;
    padding-right: 18px;
}


/* ─── Lookup (input + buttons) ─── */
.doc-lookup {
    display: flex;
    align-items: center;
    gap: 6px;
}

.doc-lookup .doc-input,
.doc-lookup .doc-select {
    flex: 1;
    min-width: 0;
}

.doc-lookup-btn {
    font-family: var(--mono);
    font-size: 9px;
    letter-spacing: 1px;
    text-transform: uppercase;
    padding: 4px 10px;
    background: rgba(255, 255, 255, .9);
    border: 1px solid var(--line);
    color: var(--muted);
    cursor: pointer;
    clip-path: polygon(5px 0%, 100% 0%, 100% calc(100% - 5px), calc(100% - 5px) 100%, 0% 100%, 0% 5px);
    transition: all .15s;
    white-space: nowrap;
    line-height: 1.4;
}

.doc-lookup-btn:hover:not(:disabled) {
    border-color: rgba(37, 99, 235, .4);
    color: var(--accent);
    background: rgba(37, 99, 235, .06);
}

.doc-lookup-btn.primary {
    border-color: rgba(37, 99, 235, .45);
    color: var(--accent);
    background: rgba(37, 99, 235, .04);
}

.doc-lookup-btn.primary:hover {
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    color: #fff;
    border-color: transparent;
}

.doc-lookup-btn:disabled {
    opacity: .4;
    cursor: not-allowed;
}


/* ─── Switch ─── */
.doc-switch {
    position: relative;
    display: inline-block;
    width: 30px;
    height: 17px;
}

.doc-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.doc-switch-track {
    position: absolute;
    inset: 0;
    background: var(--line);
    border-radius: 9px;
    cursor: pointer;
    transition: background .15s;
}

.doc-switch-track::before {
    content: "";
    position: absolute;
    left: 2px;
    top: 2px;
    width: 13px;
    height: 13px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(11, 18, 32, .2);
    transition: transform .18s;
}

.doc-switch input:checked+.doc-switch-track {
    background: linear-gradient(135deg, var(--accent), var(--accent2));
}

.doc-switch input:checked+.doc-switch-track::before {
    transform: translateX(13px);
}


/* ─── Radio ─── */
.doc-radio {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.doc-radio input[type="radio"],
.doc-radio input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    margin: 0;
    border: 1px solid var(--muted);
    border-radius: 50%;
    display: grid;
    place-items: center;
    cursor: pointer;
    background: #fff;
    transition: border-color .15s;
}

.doc-radio input[type="checkbox"] {
    border-radius: 3px;
}

.doc-radio input:checked {
    border-color: var(--accent);
}

.doc-radio input[type="radio"]:checked::after {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
}

.doc-radio input[type="checkbox"]:checked::after {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 1px;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
}

.doc-radio-label {
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: .8px;
    text-transform: uppercase;
    color: var(--muted);
}


/* ─── Toolbar (above tables) ─── */
.doc-toolbar {
    display: flex;
    align-items: stretch;
    margin-bottom: 12px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, .85);
    backdrop-filter: blur(6px);
    width: fit-content;
    clip-path: polygon(6px 0%, 100% 0%, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0% 100%, 0% 6px);
}

.doc-toolbar button {
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: .8px;
    text-transform: uppercase;
    padding: 7px 11px;
    border: 0;
    border-right: 1px solid var(--line);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: background .12s, color .12s;
}

.doc-toolbar button:hover:not(:disabled) {
    background: rgba(37, 99, 235, .05);
    color: var(--accent);
}

.doc-toolbar button:disabled {
    opacity: .4;
    cursor: not-allowed;
}

.doc-toolbar button .material-symbols-rounded,
.doc-toolbar button .material-icons-outlined {
    font-size: 14px;
    line-height: 1;
}

.doc-toolbar .sep {
    width: 1px;
    background: var(--line);
    margin: 4px 4px;
    align-self: stretch;
}

.doc-toolbar>button:last-child,
.doc-toolbar>.sep+button {
    border-right: 0;
}

.doc-toolbar .danger {
    color: #b91c1c;
}

.doc-toolbar .danger:hover {
    background: rgba(220, 38, 38, .06);
    color: #991b1b;
}


/* ─── Table extras ─── */
.doc-table td.mono {
    font-family: var(--mono);
    font-size: 10px;
    color: var(--muted);
}

.doc-table td.num {
    font-variant-numeric: tabular-nums;
    font-size: 11px;
}

.doc-table tbody tr.selected td {
    background: rgba(37, 99, 235, .08);
    color: var(--text);
}

.doc-table .checkbox-cell {
    width: 28px;
}

.doc-table input[type="checkbox"],
.doc-table input[type="radio"] {
    accent-color: var(--accent);
    cursor: pointer;
}


/* ─── Status chip (amber, sits next to the doc badge) ─── */
.status-chip {
    font-family: var(--mono);
    font-size: 9px;
    font-weight: 600;
    letter-spacing: .8px;
    text-transform: uppercase;
    padding: 2px 7px;
    border: 1px solid rgba(217, 119, 6, .4);
    color: #d97706;
    background: rgba(217, 119, 6, .08);
    border-radius: 3px;
}

.status-chip.ok {
    border-color: rgba(22, 163, 74, .4);
    color: #16a34a;
    background: rgba(22, 163, 74, .08);
}

.status-chip.danger {
    border-color: rgba(185, 28, 28, .4);
    color: #b91c1c;
    background: rgba(185, 28, 28, .08);
}


/* ─── Tab pane switching ─── */
.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
    animation: paneIn .18s ease;
}

@keyframes paneIn {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}


/* ─── Grow helper (used in topbar) ─── */
.grow {
    flex: 1;
}


/* ─── Warn / danger colors for inline use ─── */
:root {
    --warn: #d97706;
    --danger: #b91c1c;
}


/* ─── Modals (HUD-styled, clip-path corners) ─── */
.doc-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(11, 18, 32, .45);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 24px;
    animation: modalBackIn .18s ease;
}

.doc-modal-backdrop.open {
    display: flex;
}

@keyframes modalBackIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.doc-modal {
    background: rgba(255, 255, 255, .98);
    border: 1px solid var(--line);
    box-shadow: 0 24px 60px rgba(11, 18, 32, .2), 0 4px 12px rgba(11, 18, 32, .08);
    width: 100%;
    max-width: 720px;
    max-height: 85vh;
    display: grid;
    grid-template-rows: auto 1fr auto;
    overflow: hidden;
    /*clip-path: polygon(12px 0%, 100% 0%, 100% calc(100% - 12px), calc(100% - 12px) 100%, 0% 100%, 0% 12px);*/
    animation: modalIn .22s ease;
    position: relative;
}

.doc-modal.lg {
    max-width: 960px;
}

.doc-modal.xl {
    max-width: 1200px;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

/* HUD corner accents on modal */
.doc-modal::before,
.doc-modal::after {
    content: "";
    position: absolute;
    width: 14px;
    height: 14px;
    pointer-events: none;
    z-index: 5;
}

.doc-modal::before {
    top: 0;
    left: 0;
    /*border-top: 2px solid var(--accent);
    border-left: 2px solid var(--accent);*/
}

.doc-modal::after {
    bottom: 0;
    right: 0;
    /*border-bottom: 2px solid var(--accent2);
    border-right: 2px solid var(--accent2);*/
}

.doc-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, .7);
    backdrop-filter: blur(6px);
}

.doc-modal-title {
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--text);
}

.doc-modal-body {
    padding: 18px 22px;
    overflow-y: auto;
}

.doc-modal-footer {
    padding: 10px 16px;
    border-top: 1px solid var(--line);
    background: rgba(244, 246, 251, .6);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

.doc-modal-footer .link-btn {
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    padding: 5px 10px;
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    border-bottom: 1px solid transparent;
    transition: color .12s, border-color .12s;
}

.doc-modal-footer .link-btn:hover {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.doc-modal-footer .link-btn.primary {
    color: var(--accent);
    border-bottom-color: rgba(37, 99, 235, .4);
}

.doc-modal-footer .link-btn.primary:hover {
    border-bottom-color: var(--accent);
}

.doc-modal-footer .link-btn:disabled {
    opacity: .4;
    cursor: not-allowed;
}


/* ─── Tariff modal inner grid ─── */
.tariff-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 14px 18px;
    align-items: center;
    max-width: 560px;
    margin: 0 auto;
}

.tariff-grid .doc-lookup,
.tariff-grid .doc-input {
    grid-column: 2 / 3;
}


/* ─── Doc topbar tweaks (status chip, search already in base) ─── */
.doc-topbar .status-chip {
    margin-left: 4px;
}

.doc-topbar .tbl-search-clear {
    cursor: pointer;
    display: block;
}

.doc-topbar .tbl-search-clear:hover {
    color: var(--text);
}


/* ─── Clause cards (new structured clause system) ─── */

.doc-clause-section .doc-section-header {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    flex-wrap: nowrap;
}

/* All direct children share the same line-height so flex centering is exact */
.doc-clause-section .doc-section-header > * {
    line-height: 1.2;
    margin-top: 0;
    margin-bottom: 0;
}

.doc-clause-section .doc-section-header .doc-section-title {
    padding: 0;
    border-bottom: none;
    flex-shrink: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.doc-clause-status {
    flex-shrink: 0;
    line-height: 1.2;
    white-space: nowrap;
}

.doc-clause-body-text {
    font-family: var(--ui);
    font-size: 13px;
    line-height: 1.6;
    color: var(--text);
    padding: 4px 0;
}

.doc-clause-inline-editor textarea {
    font-family: var(--ui);
    font-size: 13px;
    line-height: 1.6;
    width: 100%;
    box-sizing: border-box;
}

.doc-add-clause-btn {
    margin-top: 14px;
    width: 100%;
    justify-content: center;
    border: 1px dashed var(--line);
    border-radius: 6px;
    padding: 10px;
    color: var(--muted);
    font-size: 13px;
    gap: 6px;
}

.doc-add-clause-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(37, 99, 235, .04);
}


/* ─── Template Editor ─── */

.tpl-editor-section {
    padding: 0 20px 16px;
    flex-shrink: 0;
}

.tpl-editor-section + .tpl-editor-section {
    border-top: 1px solid var(--line);
    padding-top: 16px;
}

.tpl-revisions-section {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.tpl-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 0 10px;
}

.tpl-section-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .06em;
    color: var(--text-muted, var(--muted));
}

/* Clause list in template editor — reuses doc-section card styles */
.tpl-clause-list {
    padding: 16px 20px 20px;
}

.tpl-clause-empty,
.tpl-revision-empty {
    font-size: 13px;
    color: var(--text-muted, var(--muted));
    padding: 10px 0;
}

/* Variant block inside clause card body */
.tpl-variant-block {
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
}
.tpl-variant-block:last-of-type {
    border-bottom: none;
}
.tpl-variant-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.tpl-party-badge {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--accent, #2563eb);
    background: color-mix(in srgb, var(--accent, #2563eb) 10%, transparent);
    border: 1px solid color-mix(in srgb, var(--accent, #2563eb) 25%, transparent);
    border-radius: 3px;
    padding: 2px 6px;
}
.tpl-clause-textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border, var(--line));
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    font-family: var(--mono, monospace);
    font-size: 12px;
    line-height: 1.55;
    resize: vertical;
    box-sizing: border-box;
    transition: border-color .15s;
}
.tpl-clause-textarea:focus {
    outline: none;
    border-color: var(--accent, #2563eb);
}
.tpl-variant-footer {
    text-align: right;
    margin-top: 6px;
}

/* Add-variant bar */
.tpl-add-variant-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: 10px;
    border-top: 1px dashed var(--line);
    margin-top: 6px;
}
.tpl-party-select {
    padding: 4px 8px;
    border: 1px solid var(--border, var(--line));
    border-radius: 5px;
    background: var(--bg);
    color: var(--text);
    font-size: 12px;
}

/* Commit bar */
.tpl-commit-bar {
    flex-shrink: 0;
    padding: 10px 20px;
    border-top: 1px solid var(--line);
    background: var(--bg2, var(--bg));
}

.tpl-commit-inner {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* Revision list */
.tpl-revision-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tpl-revision-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 10px;
    border-radius: 6px;
    border: 1px solid var(--line);
    font-size: 13px;
}

.tpl-revision-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
}

.tpl-revision-ver {
    font-weight: 600;
    color: var(--accent);
    min-width: 32px;
}

.tpl-revision-label {
    flex: 1;
}

.tpl-revision-date {
    color: var(--text-muted, var(--muted));
    font-size: 11px;
}

.tpl-revision-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.tpl-revision-btn {
    font-size: 12px !important;
    padding: 4px 10px !important;
    border: 1px solid var(--line) !important;
    border-radius: 4px !important;
}

/* Lookup objects + other fields section (document/template-level, above clauses) */
.tpl-lookup-objects-wrap {
    flex-shrink: 0;
}

.tpl-lookup-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tpl-lookup-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 6px;
    border: 1px solid var(--line);
    font-size: 13px;
}

.tpl-lookup-row .material-symbols-rounded {
    font-size: 16px;
    color: var(--muted);
}

.tpl-lookup-label {
    font-weight: 600;
}

.tpl-lookup-meta {
    flex: 1;
    color: var(--text-muted, var(--muted));
    font-size: 11px;
    text-align: right;
}

.tpl-lookup-remove {
    flex-shrink: 0;
}

.tpl-lookup-empty {
    font-size: 13px;
    color: var(--text-muted, var(--muted));
    padding: 6px 0;
}


/* ─── Import dialog ─── */

.import-drop-zone {
    border: 2px dashed var(--line);
    border-radius: 10px;
    padding: 32px 24px;
    text-align: center;
    cursor: default;
    transition: border-color .15s, background .15s;
}

.import-drop-zone.drag-over {
    border-color: var(--accent);
    background: rgba(37, 99, 235, .04);
}

.import-drop-icon {
    font-size: 40px;
    color: var(--text-muted, var(--muted));
    display: block;
    margin-bottom: 10px;
}

.import-drop-label {
    font-size: 15px;
    font-weight: 500;
    margin-bottom: 6px;
}

.import-drop-sub {
    font-size: 12px;
    color: var(--text-muted, var(--muted));
    margin-bottom: 10px;
}

.import-choose-btn {
    display: inline-block;
}

.import-drop-hint {
    margin-top: 10px;
    font-size: 11px;
    color: var(--text-muted, var(--muted));
}

@keyframes import-spin {
    to { transform: rotate(360deg); }
}

.import-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--line);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: import-spin .8s linear infinite;
    margin: 0 auto;
}


/* ═══════════════════════════════════════════════════════════════════════════
   Elementor-style block editor — layout, tree panel, element blocks
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── Body → layout override ─────────────────────────────────────────────── */

/* When .doc-layout is present (document editor), kill body padding/scroll
   and let the child containers manage their own overflow.                 */
.doc-body:has(.doc-layout) {
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.doc-layout {
    display: flex;
    flex-direction: row;
    flex: 1;
    min-height: 0;
    height: 100%;
}

/* Editor scroll area */
.doc-editor-area {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 18px 22px 24px;
}


/* ─── Tree sidebar ──────────────────────────────────────────────────────── */

.doc-tree {
    width: 220px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--line);
    background: rgba(244, 246, 251, .6);
    overflow: hidden;
    transition: width .2s ease;
}

.doc-tree.collapsed {
    width: 36px;
}

.doc-tree.collapsed .doc-tree-body,
.doc-tree.collapsed .doc-tree-footer,
.doc-tree.collapsed .doc-palette,
.doc-tree.collapsed .doc-tree-clause-name,
.doc-tree.collapsed .doc-tree-el {
    display: none;
}

.doc-tree.collapsed .doc-tree-header {
    justify-content: center;
    padding: 8px 4px;
}

.doc-tree.collapsed .doc-tree-header-icon,
.doc-tree.collapsed .doc-tree-header-label {
    display: none;
}

.doc-tree.collapsed .doc-tree-collapse {
    margin-left: 0;
}

.doc-tree-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--muted);
    flex-shrink: 0;
    white-space: nowrap;
}

.doc-tree-body {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    padding: 4px 0;
}

.doc-tree-footer {
    border-top: 1px solid var(--line);
    padding: 6px 8px;
    flex-shrink: 0;
}

/* Clause row */
.doc-tree-clause {
    border-left: 2px solid transparent;
    transition: border-color .12s, background .12s;
}

.doc-tree-clause.active {
    border-left-color: var(--accent);
    background: rgba(37, 99, 235, .05);
}

.doc-tree-clause-header {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 8px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text);
    user-select: none;
}

.doc-tree-clause-header:hover {
    background: rgba(37, 99, 235, .04);
}

.doc-tree-toggle-icon {
    font-size: 16px !important;
    color: var(--muted);
    flex-shrink: 0;
}

.doc-tree-clause-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11px;
}

/* Element children list */
.doc-tree-els {
    overflow: hidden;
    transition: max-height .18s ease;
    max-height: 500px;
}

.doc-tree-els.collapsed {
    max-height: 0;
}

.doc-tree-el {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px 3px 28px;
    font-size: 11px;
    color: var(--muted);
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.doc-tree-el:hover {
    color: var(--text);
    background: rgba(37, 99, 235, .04);
}

.doc-tree-el .material-symbols-rounded {
    font-size: 13px !important;
    flex-shrink: 0;
    opacity: .65;
}

/* Palette (add elements to selected clause) */
.doc-palette {
    border-top: 1px solid var(--line);
    padding: 8px;
    flex-shrink: 0;
    opacity: .45;
    pointer-events: none;
    transition: opacity .15s;
}

.doc-palette.active {
    opacity: 1;
    pointer-events: auto;
}

.doc-palette-title {
    font-family: var(--mono);
    font-size: 9px;
    letter-spacing: .8px;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 6px;
}

.doc-palette-btns {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.doc-palette-btn {
    display: flex;
    align-items: center;
    gap: 7px;
    width: 100%;
    padding: 5px 8px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: rgba(255, 255, 255, .7);
    color: var(--text);
    font-size: 12px;
    cursor: pointer;
    transition: background .12s, border-color .12s, color .12s;
    text-align: left;
}

.doc-palette-btn:hover {
    border-color: rgba(37, 99, 235, .4);
    background: rgba(37, 99, 235, .05);
    color: var(--accent);
}

.doc-palette-btn .material-symbols-rounded {
    font-size: 14px !important;
    color: var(--muted);
}

.doc-palette-btn:hover .material-symbols-rounded {
    color: var(--accent);
}


/* ─── Element editor (inside clause body) ────────────────────────────────── */

.el-editor {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 6px 0;
}

/* Individual element block */
.el-block {
    border: 1px solid var(--line);
    border-radius: 6px;
    overflow: hidden;
    background: rgba(255, 255, 255, .7);
    transition: border-color .15s, box-shadow .15s;
}

.el-block:focus-within {
    border-color: rgba(37, 99, 235, .35);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, .08);
}

.el-block-text  { border-left: 3px solid #2563eb; }
.el-block-table { border-left: 3px solid #7c3aed; }
.el-block-image { border-left: 3px solid #0891b2; }

/* Element toolbar (type badge + move/delete) */
.el-toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-bottom: 1px solid var(--line);
    background: rgba(244, 246, 251, .7);
}

.el-type-badge {
    display: flex;
    align-items: center;
    gap: 4px;
    font-family: var(--mono);
    font-size: 9px;
    letter-spacing: .8px;
    text-transform: uppercase;
    color: var(--muted);
}

.el-type-badge .material-symbols-rounded {
    font-size: 14px !important;
}

/* Icon buttons used throughout element editor */
.el-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 3px 5px;
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    border-radius: 4px;
    font-size: 12px;
    gap: 4px;
    transition: background .12s, color .12s;
    font-family: var(--ui);
}

.el-btn:hover {
    background: rgba(37, 99, 235, .07);
    color: var(--accent);
}

.el-btn .material-symbols-rounded {
    font-size: 16px !important;
    line-height: 1;
}

/* ── Text element ─── */
.el-text-content {
    padding: 10px 12px;
    min-height: 60px;
    font-family: var(--ui);
    font-size: 13px;
    line-height: 1.65;
    color: var(--text);
    outline: none;
    white-space: pre-wrap;
    word-break: break-word;
}

.el-text-content:empty::before {
    content: attr(data-placeholder);
    color: var(--muted);
    pointer-events: none;
}

/* ── Table element ─── */
.el-table-wrap {
    overflow-x: auto;
    padding: 8px;
}

.el-table {
    border-collapse: collapse;
    min-width: 100%;
    font-size: 12px;
}

.el-table th,
.el-table td {
    border: 1px solid var(--line);
    padding: 5px 8px;
    text-align: left;
    min-width: 60px;
    outline: none;
}

.el-table thead th {
    background: rgba(244, 246, 251, .8);
    font-weight: 600;
    font-size: 11px;
    color: var(--text);
    letter-spacing: .03em;
}

.el-table th[contenteditable="true"]:focus,
.el-table td[contenteditable="true"]:focus {
    background: rgba(37, 99, 235, .05);
    box-shadow: inset 0 0 0 1px rgba(37, 99, 235, .3);
}

.el-table-add-col,
.el-table-row-del {
    width: 28px;
    text-align: center;
    border: none;
    background: transparent;
}

.el-table tfoot td {
    border: none;
    padding: 4px 0;
}

.el-add-row {
    font-size: 11px;
    color: var(--muted);
    padding: 2px 6px;
}

.el-add-row:hover {
    color: var(--accent);
}

/* ── Image element ─── */
.el-image-wrap {
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.el-image-controls {
    display: flex;
    gap: 8px;
}

.el-image-url,
.el-image-caption {
    flex: 1;
    padding: 5px 8px;
    border: 1px solid var(--line);
    border-radius: 5px;
    font-size: 12px;
    font-family: var(--ui);
    color: var(--text);
    background: rgba(255, 255, 255, .85);
    outline: none;
    transition: border-color .15s;
}

.el-image-url:focus,
.el-image-caption:focus {
    border-color: var(--accent);
}

.el-image-preview {
    max-width: 100%;
    max-height: 220px;
    border-radius: 4px;
    border: 1px solid var(--line);
    object-fit: contain;
    align-self: flex-start;
}

/* ── Add-element bar (bottom of each editor) ─── */
.el-add-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 4px 2px;
    border-top: 1px dashed var(--line);
    margin-top: 2px;
}

.el-add-label {
    font-family: var(--mono);
    font-size: 9px;
    letter-spacing: .8px;
    text-transform: uppercase;
    color: var(--muted);
    margin-right: 2px;
    white-space: nowrap;
}

.el-add-type {
    font-size: 11px;
    border: 1px solid var(--line) !important;
    border-radius: 4px !important;
    padding: 3px 8px !important;
    background: rgba(255, 255, 255, .8) !important;
    color: var(--muted) !important;
}

.el-add-type:hover {
    border-color: rgba(37, 99, 235, .4) !important;
    color: var(--accent) !important;
    background: rgba(37, 99, 235, .05) !important;
}

/* ── Insert-field toolbar + picker (text elements, when fieldRegistry supplied) ─── */
.el-text-wrap {
    display: flex;
    flex-direction: column;
}

.el-text-insert-bar {
    display: flex;
    justify-content: flex-end;
    padding: 4px 8px 0;
    position: relative;
}

.el-insert-field-btn {
    font-size: 11px;
    border: 1px solid var(--line) !important;
    border-radius: 4px !important;
    padding: 3px 8px !important;
    color: var(--muted) !important;
}

.el-insert-field-btn:hover {
    border-color: rgba(37, 99, 235, .4) !important;
    color: var(--accent) !important;
}

.el-insert-field-dialog {
    position: absolute;
    right: 8px;
    top: 100%;
    z-index: 5;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 6px;
    min-width: 180px;
    max-height: 260px;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: rgba(255, 255, 255, .97);
    box-shadow: 0 4px 16px rgba(0, 0, 0, .12);
}

.el-insert-field-group-label {
    font-family: var(--mono);
    font-size: 9px;
    letter-spacing: .6px;
    text-transform: uppercase;
    color: var(--muted);
    padding: 6px 6px 2px;
}

.el-insert-field-item {
    text-align: left;
    border: 0;
    background: transparent;
    color: var(--text);
    font-size: 12px;
    padding: 5px 6px;
    border-radius: 4px;
    cursor: pointer;
}

.el-insert-field-item:hover {
    background: rgba(37, 99, 235, .08);
    color: var(--accent);
}

.el-insert-field-empty {
    font-size: 12px;
    color: var(--muted);
    font-style: italic;
    padding: 6px;
    max-width: 200px;
}

/* ── Inline field chips (template editor) ─── */

.el-inline-field-chip {
    display: inline-flex;
    align-items: center;
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1.4;
    padding: 1px 6px;
    margin: 0 1px;
    border-radius: 4px;
    background: rgba(37, 99, 235, .1);
    color: var(--accent);
    border: 1px solid rgba(37, 99, 235, .25);
    cursor: pointer;
    user-select: none;
}

.el-inline-field-chip:hover {
    background: rgba(37, 99, 235, .18);
}

.el-inline-field-chip-unknown {
    background: rgba(220, 38, 38, .08);
    color: #dc2626;
    border-color: rgba(220, 38, 38, .3);
}

.el-inline-field-chip-unknown:hover {
    background: rgba(220, 38, 38, .15);
}

.el-field-property-item {
    display: flex;
    align-items: center;
    gap: 6px;
    text-align: left;
    border: 0;
    background: transparent;
    color: var(--text);
    font-size: 12px;
    padding: 5px 6px;
    border-radius: 4px;
    cursor: pointer;
}

.el-field-property-item .material-symbols-rounded {
    font-size: 16px;
    color: var(--muted);
}

.el-field-property-item.active .material-symbols-rounded {
    color: var(--accent);
}

.el-field-property-item:hover {
    background: rgba(37, 99, 235, .08);
    color: var(--accent);
}

.el-field-property-label {
    font-family: var(--mono);
    font-size: 9px;
    letter-spacing: .6px;
    text-transform: uppercase;
    color: var(--muted);
    padding: 2px 6px;
}

.el-field-property-type {
    margin: 0 6px 6px;
    font-size: 12px;
    padding: 5px 6px;
    border-radius: 4px;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--text);
}

.el-field-property-required {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text);
    padding: 2px 6px 4px;
    cursor: pointer;
}

.el-inline-field-chip.active-edit {
    background: rgba(37, 99, 235, .22);
    border-color: var(--accent);
}

/* ── Template detail — main column + docked field-property panel ─── */

.tpl-detail-layout {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 0;
}

.tpl-main-col {
    flex: 1;
    min-width: 0;
}

.tpl-field-panel {
    width: 0;
    flex-shrink: 0;
    align-self: stretch;
    position: sticky;
    top: 0;
    overflow: hidden;
    border-left: 1px solid transparent;
    background: rgba(244, 246, 251, .6);
    transition: width .18s ease;
}

.tpl-field-panel.open {
    width: 260px;
    border-left-color: var(--line);
}

.tpl-field-panel-inner {
    width: 260px; /* fixed so content doesn't reflow/wrap mid width-transition */
}

.tpl-field-panel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 8px 10px 14px;
    border-bottom: 1px solid var(--line);
}

.tpl-field-panel-title {
    flex: 1;
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .5px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tpl-field-panel-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px;
}

/* ── Scroll highlight animation ─── */
@keyframes elHighlight {
    0%   { box-shadow: 0 0 0 3px rgba(37, 99, 235, .45); }
    100% { box-shadow: none; }
}

.el-highlight {
    animation: elHighlight 1.5s ease forwards;
}


/* ─── Dark theme ─────────────────────────────────────────────────────────── */

@media (prefers-color-scheme: dark) {
    .doc-tree { background: rgba(18, 24, 38, .5); }
    .el-block  { background: rgba(18, 24, 38, .45); }
    .el-toolbar { background: rgba(24, 32, 50, .6); }
    .el-table thead th { background: rgba(24, 32, 50, .7); }
    .el-image-url,
    .el-image-caption { background: rgba(18, 24, 38, .6); }
    .doc-palette-btn { background: rgba(18, 24, 38, .5); }
    .el-insert-field-dialog { background: rgba(24, 32, 50, .97); }
    .tpl-field-panel { background: rgba(18, 24, 38, .5); }
}

:root[data-theme="dark"] .doc-tree   { background: rgba(18, 24, 38, .5); }
:root[data-theme="dark"] .el-block   { background: rgba(18, 24, 38, .45); }
:root[data-theme="dark"] .el-toolbar { background: rgba(24, 32, 50, .6); }
:root[data-theme="dark"] .el-table thead th { background: rgba(24, 32, 50, .7); }
:root[data-theme="dark"] .el-image-url,
:root[data-theme="dark"] .el-image-caption { background: rgba(18, 24, 38, .6); }
:root[data-theme="dark"] .doc-palette-btn  { background: rgba(18, 24, 38, .5); }
:root[data-theme="dark"] .el-insert-field-dialog { background: rgba(24, 32, 50, .97); }
:root[data-theme="dark"] .tpl-field-panel { background: rgba(18, 24, 38, .5); }

:root[data-theme="light"] .doc-tree   { background: rgba(244, 246, 251, .6); }
:root[data-theme="light"] .el-block   { background: rgba(255, 255, 255, .7); }
:root[data-theme="light"] .el-toolbar { background: rgba(244, 246, 251, .7); }
:root[data-theme="light"] .el-table thead th { background: rgba(244, 246, 251, .8); }
:root[data-theme="light"] .el-image-url,
:root[data-theme="light"] .el-image-caption { background: rgba(255, 255, 255, .85); }
:root[data-theme="light"] .doc-palette-btn  { background: rgba(255, 255, 255, .7); }
:root[data-theme="light"] .el-insert-field-dialog { background: rgba(255, 255, 255, .97); }
:root[data-theme="light"] .tpl-field-panel { background: rgba(244, 246, 251, .6); }