/* Shared model library/editor: all geometry is expressed in millimetres in data. */
.template-library-dialog {
    width: min(1180px, calc(100vw - 2rem));
    max-width: none;
    height: min(820px, calc(100dvh - 2rem));
    max-height: calc(100dvh - 2rem);
    padding: 0;
    border: 1px solid var(--line, #e4e5ec);
    border-radius: 1rem;
    background: var(--surface, #fff);
    overflow: hidden;
}
.template-library-dialog [hidden] { display: none !important; }
.template-library-shell { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.template-library-header {
    display: flex; justify-content: space-between; align-items: center; gap: 1rem;
    padding: 1rem 1.3rem; border-bottom: 1px solid var(--line, #e4e5ec); flex-shrink: 0;
}
.template-library-header > .icon-button, .template-library-heading > .icon-button { flex-shrink: 0; }
.template-library-heading { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.template-library-heading h2 { margin: 0; font-size: 1.2rem; }
.template-library-heading p { margin: .2rem 0 0; color: var(--ink-soft); font-size: .78rem; }
.template-library-body { min-height: 0; flex: 1; overflow: auto; padding: 1.2rem 1.3rem; }
.template-library-message { margin: .65rem 1.3rem 0; padding: .65rem .8rem; color: #9d2838; background: #fff0f1; border-radius: .5rem; font-size: .83rem; flex-shrink: 0; }
.template-library-message.is-success { color: #217347; background: #eefaf2; }
.template-library-toolbar { display: flex; align-items: end; gap: .65rem; flex-wrap: wrap; margin-bottom: 1.1rem; }
.template-library-toolbar .template-library-search { flex: 1 1 230px; }
.template-library-dialog label { display: flex; flex-direction: column; gap: .3rem; color: var(--ink-soft); font-size: .74rem; font-weight: 600; }
.template-library-dialog input:not([type="file"]), .template-library-dialog select, .template-library-dialog textarea {
    width: 100%; min-width: 0; min-height: 36px; padding: .42rem .55rem;
    color: var(--ink); background: white; border: 1px solid var(--line, #daddE8); border-radius: .4rem;
    font: inherit; font-size: .82rem; font-weight: 400;
}
.template-library-dialog input:focus, .template-library-dialog select:focus, .template-library-dialog textarea:focus { outline: 2px solid var(--primary, #6754e9); outline-offset: 1px; }
.template-library-dialog button { cursor: pointer; }
.template-library-dialog button:disabled { cursor: wait; opacity: .55; }
.template-library-dialog .button { min-height: 36px; font-size: .79rem; }
.template-library-country { max-width: 195px; }
.template-library-filters { display: flex; gap: .4rem; margin: 0 0 1rem; flex-wrap: wrap; }
.template-library-chip { border: 1px solid var(--line); border-radius: 2rem; padding: .32rem .7rem; font: inherit; font-size: .73rem; color: var(--ink-soft); background: white; }
.template-library-chip[aria-pressed="true"] { color: var(--primary-dark); background: var(--primary-soft); border-color: var(--primary); }
.template-library-section { margin-bottom: 1.6rem; }
.template-library-section h3 { font-size: .91rem; margin: 0 0 .7rem; }
.template-library-section h3 small { margin-left: .35rem; color: var(--ink-faint); font-size: .74rem; font-weight: normal; }
.template-library-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(235px, 1fr)); gap: .8rem; }
.template-library-card { position: relative; display: flex; flex-direction: column; min-width: 0; padding: .85rem; border: 1px solid var(--line); border-radius: .7rem; background: white; }
.template-library-card.is-current { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.template-library-thumb { display: flex; align-items: center; justify-content: center; height: 116px; padding: .5rem; border-radius: .4rem; margin-bottom: .7rem; background: #f6f7fa; overflow: hidden; }
.template-library-thumb img { display: block; max-width: 100%; max-height: 100%; background: white; box-shadow: 0 1px 5px #15172816; }
.template-library-card h4 { margin: 0 1.7rem .25rem 0; font-size: .87rem; overflow-wrap: anywhere; }
.template-library-card p { margin: .12rem 0; font-size: .74rem; color: var(--ink-soft); }
.template-library-card .template-library-countries { display: flex; align-items: center; flex-wrap: wrap; gap: .3rem; margin: .35rem 0 .1rem; min-height: 14px; }
.template-library-country-flag { width: 21px; height: 14px; object-fit: cover; border-radius: 2px; box-shadow: 0 0 0 1px #17172b12; }
.template-library-country-code { padding: .05rem .2rem; border: 1px solid var(--line); border-radius: 2px; font-size: .58rem; }
.template-library-favorite { position: absolute; top: .55rem; right: .55rem; z-index: 1; width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 50%; background: white; color: var(--ink-faint); font-size: 1rem; }
.template-library-favorite[aria-pressed="true"] { color: #a36500; background: #fff6dd; border-color: #ebd394; }
.template-library-badge { display: inline-block; align-self: flex-start; font-size: .66rem; margin-top: .35rem; padding: .16rem .42rem; color: #217347; background: #eaf8ee; border-radius: .3rem; }
.template-library-badge.is-muted { color: var(--ink-soft); background: #f0f1f5; }
.template-library-card details { margin: .4rem 0; font-size: .71rem; color: var(--ink-soft); }
.template-library-card summary { cursor: pointer; }
.template-library-actions { display: flex; gap: .35rem; flex-wrap: wrap; padding-top: .65rem; margin-top: auto; }
.template-library-actions .button { flex: 1; padding: .4rem .55rem; min-height: 32px; white-space: nowrap; font-size: .72rem; }
.template-library-actions .button:only-child { width: 100%; }
.template-library-link { border: 0; background: none; color: var(--primary-dark); padding: .3rem 0; text-align: left; font: inherit; font-size: .72rem; }
.template-library-empty { text-align: center; color: var(--ink-soft); padding: 2rem 1rem; font-size: .85rem; }
.template-library-note { margin: 1.1rem 0 0; color: var(--ink-faint); font-size: .75rem; }
.template-library-import { padding: .9rem 1rem; margin-bottom: 1rem; background: var(--surface-tint); border-radius: .6rem; font-size: .84rem; }
.template-library-import p { margin: 0 0 .55rem; }
.template-format-sheet { display: grid; gap: 3px; height: 94px; width: 70px; padding: 5px; background: white; border: 1px solid #d7dae4; box-shadow: 0 2px 5px #1517280d; }
.template-format-sheet i { border: 1px dotted #aeb4c6; border-radius: 1px; }
.template-editor { display: flex; flex-direction: column; min-height: 100%; }
.template-editor-topbar { display: flex; gap: .6rem; align-items: end; flex-wrap: wrap; margin-bottom: 1rem; }
.template-editor-topbar { position: sticky; top: -1.2rem; z-index: 3; background: white; padding: .4rem 0 .65rem; }
.template-editor-topbar label { flex: 1; min-width: 180px; }
.template-editor-grid { display: grid; grid-template-columns: 235px minmax(250px, 1fr) 215px; gap: 1rem; flex: 1; align-items: start; }
.template-editor-sidebar { display: flex; flex-direction: column; gap: .85rem; min-width: 0; }
.template-editor-sidebar h3, .template-editor-properties h3 { margin: 0 0 .5rem; font-size: .82rem; }
.template-editor-geometry { padding: .6rem; background: var(--surface-soft); border: 1px solid var(--line); border-radius: .5rem; }
.template-editor-geometry summary { cursor: pointer; font-size: .82rem; font-weight: 600; }
.template-editor-input-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-top: .6rem; }
.template-editor-input-grid label { font-size: .68rem; }
.template-editor-add { display: flex; flex-wrap: wrap; gap: .35rem; }
.template-editor-add .button { min-height: 30px; font-size: .71rem; padding: .38rem .5rem; flex: 1; }
.template-editor-elements { display: flex; flex-direction: column; gap: .3rem; max-height: 230px; overflow: auto; }
.template-editor-element-row { display: flex; align-items: center; gap: .3rem; border: 1px solid var(--line); border-radius: .4rem; background: white; }
.template-editor-element-row.is-selected { border-color: var(--primary); background: var(--primary-soft); }
.template-editor-element-row button { border: 0; background: none; color: var(--ink); padding: .5rem; font: inherit; font-size: .75rem; }
.template-editor-element-row button:first-child { flex: 1; min-width: 0; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.template-editor-element-row .template-remove { flex-shrink: 0; color: var(--ink-soft); }
.template-editor-workspace { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding: 1.25rem; min-height: 300px; background: #f2f3f7; border-radius: .7rem; overflow: hidden; }
.template-editor-canvas { position: relative; width: 100%; max-width: 630px; flex-shrink: 0; background: white; box-shadow: 0 3px 16px #222b431c; outline: 1px dashed #aeb4c6; }
.template-editor-preview { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.template-editor-preview[hidden] + .template-editor-selection { background: transparent; }
.template-editor-box { position: absolute; display: flex; align-items: flex-start; overflow: hidden; border: 1px dashed #939bad99; background: transparent; color: #6d7689; cursor: move; touch-action: none; padding: 0; }
.template-editor-box.is-selected { border: 1px solid var(--primary); box-shadow: 0 0 0 1px var(--primary); background: #6754e908; z-index: 1; }
.template-editor-box.is-invalid { border-color: #c32c45; background: #c32c4512; }
.template-editor-box span { font-family: Helvetica, Arial, sans-serif; pointer-events: none; font-weight: 400; width: 100%; white-space: normal; line-height: 1.1; }
.template-editor-box img { display: block; max-width: 100%; max-height: 100%; object-fit: contain; pointer-events: none; }
.template-editor-canvas.has-preview .template-editor-box span, .template-editor-canvas.has-preview .template-editor-box img { visibility: hidden; }
.template-editor-workspace > p { margin: .75rem 0 0; color: var(--ink-faint); font-size: .71rem; text-align: center; }
.template-editor-rotated { margin: 1rem 0 0; width: 100%; text-align: center; }
.template-editor-rotated figcaption { color: var(--ink-faint); font-size: .7rem; margin-bottom: .4rem; }
.template-editor-rotated img { max-width: 100%; max-height: 140px; border: 1px dashed #aeb4c6; background: white; }
.template-editor-validation { color: #ab2740; margin: .6rem 0 0; font-size: .74rem; overflow-wrap: anywhere; }
.template-editor-properties { min-width: 0; padding: .7rem; border: 1px solid var(--line); border-radius: .5rem; }
.template-editor-properties > label { margin-bottom: .65rem; }
.template-editor-properties textarea { resize: vertical; min-height: 60px; }
.template-editor-properties .button { margin-top: .55rem; width: 100%; }
.template-editor-palette { display: flex; flex-wrap: wrap; gap: .25rem; }
.template-editor-palette button { border: 1px solid var(--line); border-radius: .3rem; background: white; color: var(--ink-soft); font: inherit; font-size: .68rem; padding: .3rem .4rem; overflow-wrap: anywhere; max-width: 100%; }
.template-editor-saved { padding: .6rem .8rem; background: #eefaf2; color: #217347; border-radius: .4rem; font-size: .8rem; margin-bottom: 1rem; }
.template-integration pre { white-space: pre-wrap; overflow-wrap: anywhere; padding: 1rem; border-radius: .6rem; background: #171a29; color: #ebedf8; font-size: .76rem; max-height: 340px; overflow: auto; }
.template-integration h3 { font-size: .92rem; }
.template-integration-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.template-integration p { color: var(--ink-soft); font-size: .83rem; }
@media (max-width: 1000px) {
    .template-editor-grid { grid-template-columns: 200px minmax(220px, 1fr); }
    .template-editor-properties { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .65rem; }
    .template-editor-properties h3 { grid-column: 1 / -1; }
    .template-editor-properties > label { margin: 0; }
}
@media (max-width: 640px) {
    .template-library-dialog { width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border: 0; border-radius: 0; }
    .template-library-header { padding: .8rem; }
    .template-library-heading h2 { font-size: 1.02rem; }
    .template-library-body { padding: .8rem; }
    .template-library-grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
    .template-library-country { max-width: none; flex: 1; }
    .template-editor-grid { display: flex; flex-direction: column; }
    .template-editor-sidebar, .template-editor-properties, .template-editor-workspace { width: 100%; }
    .template-editor-workspace { min-height: 200px; order: -1; }
    .template-editor-properties { grid-template-columns: 1fr 1fr; }
    .template-editor-topbar .button { flex: 1; }
    .template-library-message { margin-left: .8rem; margin-right: .8rem; }
}
