#templates-section .export-templates-page,
.export-templates-page {
    padding: 0;
    max-width: none;
    margin: 0;
}

.tpl-title {
    margin: 0 0 6px;
    font-size: 20px;
    letter-spacing: -0.2px;
}

.tpl-lead {
    margin: 0 0 18px;
    color: var(--text-secondary);
    font-size: 14px;
}

.tpl-filter {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 10px;
    width: 100%;
    box-sizing: border-box;
    padding: 12px;
    margin-bottom: 14px;
    background: var(--primary-lighter);
    border: 1px solid #d6e6f8;
    border-radius: 12px;
}

.tpl-search {
    flex: 1 1 240px;
    min-width: 200px;
    height: 38px;
    display: flex;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.tpl-search:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.12);
}

.tpl-search input {
    flex: 1;
    min-width: 0;
    height: 100%;
    padding: 0 12px;
    border: 0;
    background: transparent;
    font-size: 14px;
    font-family: inherit;
    color: var(--text-primary);
}

.tpl-search input:focus {
    outline: none;
}

.tpl-filter .btn {
    height: 38px;
    padding: 0 14px;
    border-radius: 8px;
    font-size: 14px;
}

.tpl-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    min-height: 24px;
    margin: 0 2px 10px;
    color: var(--text-secondary);
    font-size: 13px;
    flex-wrap: wrap;
}

.tpl-meta strong {
    color: var(--text-primary);
    font-weight: 600;
}

.tpl-meta .audit-pager {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tpl-meta .audit-pager[hidden] {
    display: none;
}

.tpl-meta .audit-pager span {
    color: var(--text-secondary);
    font-size: 13px;
}

.tpl-table-wrap {
    border: 1px solid var(--border-light);
    border-radius: 12px;
    background: #fff;
    overflow: hidden;
}

.tpl-table {
    width: 100%;
    border-collapse: collapse;
}

.tpl-table th {
    padding: 8px 12px;
    background: #f7f9fc;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    text-align: left;
    white-space: nowrap;
}

.tpl-table td {
    padding: 6px 12px;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 400;
}

.tpl-table tbody tr:nth-child(even) td {
    background: #f9f9f9;
}

.tpl-table tbody tr:hover td {
    background: var(--primary-lighter);
}

.tpl-table .mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
}

.tpl-pill {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 400;
    line-height: 1.6;
    white-space: nowrap;
}

.tpl-pill-active {
    background: var(--success-light);
    color: var(--success-hover);
}

.tpl-pill-inactive {
    background: var(--danger-light);
    color: var(--danger-color);
}

.tpl-actions {
    display: flex;
    gap: 8px;
    white-space: nowrap;
}

.tpl-action-btn {
    height: 24px;
    padding: 0 10px;
    border: 1px solid #d6e6f8;
    border-radius: 6px;
    background: #fff;
    color: var(--primary-color);
    font-size: 12px;
    cursor: pointer;
    font-family: inherit;
}

.tpl-action-btn:hover:not(:disabled) {
    background: var(--primary-lighter);
}

.tpl-action-btn.danger {
    border-color: #ffccc7;
    color: var(--danger-color);
}

.tpl-action-btn.danger:hover:not(:disabled) {
    background: #fff1f0;
}

.tpl-action-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.empty-state {
    padding: 36px 16px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
}

.readonly-banner {
    margin-bottom: 12px;
    padding: 10px 12px;
    border: 1px solid #ffe58f;
    border-radius: 8px;
    background: #fffbe6;
    color: #ad6800;
    font-size: 13px;
    display: none;
}

.toast-message {
    position: fixed;
    top: 16px;
    right: 16px;
    min-width: 240px;
    max-width: 400px;
    padding: 12px 16px;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    z-index: 10000;
    transform: translateX(120%);
    opacity: 0;
    transition: transform 0.25s ease-out, opacity 0.25s ease-out;
    color: #fff;
    font-size: 14px;
}

.toast-message.toast-show {
    transform: translateX(0);
    opacity: 1;
}

.toast-message.toast-success { background: var(--success-color); }
.toast-message.toast-error { background: var(--danger-color); }

.tpl-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
    display: none;
    align-items: flex-start;
    justify-content: center;
    z-index: 9999;
    padding: 24px 16px;
    overflow: auto;
}

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

.tpl-modal-card {
    background: #fff;
    border-radius: 12px;
    width: 560px;
    max-width: 100%;
    margin: 0 auto;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.16);
    padding: 14px 16px 12px;
}

.tpl-modal-card h3 {
    margin: 0 0 10px;
    font-size: 17px;
    color: var(--text-primary);
}

.tpl-meta-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px 10px;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-light);
}

.tpl-meta-grid .field:nth-child(2) {
    max-width: 140px;
    justify-self: start;
}

.tpl-modal-card .field {
    margin-bottom: 10px;
    min-width: 0;
}

.tpl-meta-grid .field {
    margin-bottom: 0;
}

.tpl-modal-card .field-columns > label {
    display: block;
    margin-bottom: 4px;
    color: var(--text-secondary);
    font-size: 12px;
}

.tpl-modal-card .field > input,
.tpl-modal-card .field > select {
    width: 100%;
    height: 32px;
    padding: 0 8px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-sizing: border-box;
    font-family: inherit;
    font-size: 13px;
    background: #fff;
    color: var(--text-primary);
}

.tpl-modal-card .field > input:focus,
.tpl-modal-card .field > select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.12);
}

.tpl-modal-card .field > input:disabled {
    background: #f7f9fc;
    color: var(--text-secondary);
}

.tpl-modal-card .field > select.tpl-select-sm {
    width: 100%;
    min-width: 0;
    max-width: none;
}

.tpl-modal-card .field-columns {
    margin-bottom: 0;
}

.tpl-modal-hint {
    margin-top: 4px;
    color: var(--text-secondary);
    font-size: 12px;
    line-height: 1.4;
}

.picker-block {
    margin-top: 4px;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    overflow: hidden;
}

.picker-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 10px;
    background: #f7f9fc;
    border-bottom: 1px solid var(--border-light);
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 600;
}

.picker-head-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.picker-head-actions button {
    height: 26px;
    padding: 0 8px;
    border: 1px solid #d6e6f8;
    border-radius: 6px;
    background: #fff;
    color: var(--primary-color);
    font-size: 12px;
    cursor: pointer;
    font-family: inherit;
}

.picker-head-actions button:hover:not(:disabled) {
    background: var(--primary-lighter);
}

.picker-head-actions button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.picker-tools {
    display: flex;
    gap: 8px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-light);
}

.picker-tools .tpl-search {
    flex: 1;
    height: 32px;
    min-width: 0;
}

.picker-tools select {
    flex: none;
    width: 130px;
    height: 32px;
    padding: 0 8px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: inherit;
    font-size: 13px;
    background: #fff;
}

.picker-list {
    max-height: 240px;
    overflow: auto;
}

.group-head {
    padding: 6px 10px;
    background: #fafbfd;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
}

.group-head button {
    height: 22px;
    padding: 0 6px;
    border: 1px solid #d6e6f8;
    border-radius: 4px;
    background: #fff;
    color: var(--primary-color);
    font-size: 11px;
    cursor: pointer;
    font-family: inherit;
}

.group-head button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.field-check {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 6px 10px;
    border: 0;
    border-bottom: 1px solid #f0f0f0;
    background: transparent;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
    color: var(--text-primary);
    font-size: 13px;
    box-sizing: border-box;
}

.field-check:hover {
    background: var(--primary-lighter);
}

.field-check input[type="checkbox"] {
    flex: 0 0 auto;
    width: 14px;
    height: 14px;
    margin: 0 2px 0 0;
    padding: 0;
    accent-color: var(--primary-color);
}

.field-check > span {
    flex: 1 1 auto;
    min-width: 0;
    line-height: 1.35;
    padding-left: 2px;
}

.selected-list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 260px;
    overflow: auto;
}

@media (max-width: 560px) {
    .tpl-meta-grid {
        grid-template-columns: 1fr;
    }
}

.selected-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    border-bottom: 1px solid #f0f0f0;
}

.selected-item .ord {
    flex: none;
    width: 20px;
    color: var(--text-tertiary);
    font-size: 12px;
    text-align: right;
}

.selected-item .alias-wrap {
    flex: 1 1 auto;
    min-width: 0;
}

.selected-item .default-name {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.selected-item input[type="text"] {
    width: 100%;
    height: 30px;
    padding: 0 8px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-sizing: border-box;
    font-family: inherit;
    font-size: 13px;
}

.selected-item input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(0, 102, 204, 0.12);
}

.selected-item .mini-actions {
    flex: none;
    display: flex;
    gap: 4px;
}

.selected-item .mini-actions button {
    height: 26px;
    min-width: 28px;
    padding: 0 6px;
    border: 1px solid #d6e6f8;
    border-radius: 4px;
    background: #fff;
    color: var(--primary-color);
    font-size: 12px;
    cursor: pointer;
    font-family: inherit;
}

.selected-item .mini-actions button.danger {
    border-color: #ffccc7;
    color: var(--danger-color);
}

.selected-item .mini-actions button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.column-empty {
    padding: 16px 10px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
}

.tpl-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border-light);
}
