/* Template library page shell */
.mado-portal-shell--action-template-library .mado-portal-shell__content-frame.is-standard {
    box-sizing: border-box;
    width: 100%;
    max-width: var(--mado-portal-page-wide-max-width, 1240px);
    margin-left: auto;
    margin-right: auto;
    padding-left: var(--mado-portal-page-gutter-x, clamp(18px, 2.4vw, 32px));
    padding-right: var(--mado-portal-page-gutter-x, clamp(18px, 2.4vw, 32px));
}

.mado-portal-shell--action-template-library .mado-portal-container.mado-template-library-container {
    box-sizing: border-box;
    width: 100%;
    max-width: none;
    margin: 0 auto;
}

.mado-template-library-container {
    width: 100%;
}

.mado-template-library-shell {
    width: 100%;
    box-sizing: border-box;
    margin: 0 auto 28px;
    padding: var(--mado-portal-panel-padding, 30px);
    background: #ffffff;
    border: 1px solid #d7e3ee;
    border-radius: 22px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.06);
    color: #0f172a;
}

.mado-template-library-shell *,
.mado-template-library-shell *::before,
.mado-template-library-shell *::after,
.mado-template-modal *,
.mado-template-modal *::before,
.mado-template-modal *::after {
    box-sizing: border-box;
}

.mado-template-library-intro {
    display: grid;
    gap: 10px;
    margin-bottom: 20px;
}

.mado-template-library-heading-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.mado-template-library-heading {
    margin: 0;
    color: #111827;
}

.mado-template-library-description {
    margin: 0;
    color: #64748b;
    font-size: 14px;
    line-height: 1.7;
}

/* Match the existing Site Q&A soft green help chip. */
.mado-template-library-heading-row > #mado-template-help-btn.mado-template-library-help-btn {
    -webkit-appearance: none;
    appearance: none;
    position: relative;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 24px;
    width: 24px;
    height: 24px;
    min-width: 24px;
    min-height: 24px;
    margin: 0;
    padding: 0;
    overflow: visible;
    border: 1px solid #72c79c;
    border-radius: 999px;
    background: #e8fbf1;
    color: #15803d;
    box-shadow: 0 6px 14px rgba(21, 128, 61, 0.12);
    font-family: var(--mado-portal-font-family, "Noto Sans JP", "Noto Sans", system-ui, sans-serif);
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
    text-decoration: none;
    vertical-align: middle;
    cursor: pointer;
}

.mado-template-library-heading-row > #mado-template-help-btn.mado-template-library-help-btn .mado-site-qa__help-chip-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    border-radius: inherit;
    background: transparent;
    color: inherit;
    font: inherit;
    line-height: 1;
    pointer-events: none;
}

.mado-template-library-heading-row > #mado-template-help-btn.mado-template-library-help-btn:hover,
.mado-template-library-heading-row > #mado-template-help-btn.mado-template-library-help-btn:focus-visible,
.mado-template-library-heading-row > #mado-template-help-btn.mado-template-library-help-btn.is-open {
    border-color: #16a34a;
    background: #16a34a;
    color: #ffffff;
    box-shadow: 0 10px 18px rgba(21, 128, 61, 0.22);
    transform: translateY(-1px);
}

.mado-template-library-heading-row > #mado-template-help-btn.mado-template-library-help-btn:focus-visible {
    outline: 2px solid #16a34a;
    outline-offset: 2px;
}

.mado-template-library-notice {
    max-width: 720px;
    padding: 16px;
    border-radius: 6px;
}

.mado-template-library-notice--warning {
    background: #fff7ed;
    border: 1px solid #f59e0b;
    color: #7c2d12;
}

.mado-template-library-notice--error {
    background: #fef2f2;
    border: 1px solid #dc2626;
    color: #7f1d1d;
}

.mado-template-library-notice__actions {
    margin-top: 12px;
}

/* Filters */
.mado-template-filter-form {
    margin-bottom: 22px;
}

.mado-template-filter-grid {
    display: grid;
    grid-template-columns: minmax(220px, 1.3fr) minmax(160px, 0.8fr) minmax(160px, 0.8fr) auto;
    gap: 14px;
    align-items: end;
}

.mado-template-filter-label {
    display: block;
    margin-bottom: 5px;
    color: #334155;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.4;
}

.mado-template-filter-control {
    width: 100%;
    min-height: 38px;
    padding: 7px 10px;
    color: #0f172a;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-family: inherit;
    font-size: 15px;
    line-height: 1.4;
}

/*
 * Common portal CSS applies `font: inherit` to form controls with a stronger
 * selector. Keep this page-specific selector strong enough so search text,
 * selected values and option text stay the same size.
 */
body.mado-portal-account-page
.mado-portal-shell--action-template-library
.mado-template-filter-form
input.mado-template-filter-control {
    font-family: inherit;
    font-size: 15px;
    line-height: 1.4;
}

body.mado-portal-account-page
.mado-portal-shell--action-template-library
.mado-template-filter-form
input.mado-template-filter-control::placeholder {
    color: #64748b;
    font-family: inherit;
    font-size: 15px;
    opacity: 1;
}

body.mado-portal-account-page
.mado-portal-shell--action-template-library
.mado-template-filter-form
select.mado-template-filter-control {
    -moz-appearance: none;
    -webkit-appearance: none;
    appearance: none;
    padding: 7px 40px 7px 11px;
    background-color: #ffffff;
    background-image: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2210%22%20height%3D%226%22%20viewBox%3D%220%200%2010%206%22%3E%3Cpath%20d%3D%22M1%201l4%204%204-4%22%20fill%3D%22none%22%20stroke%3D%22%23334155%22%20stroke-width%3D%221.5%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
    background-size: 10px 6px;
    font-family: inherit;
    font-size: 15px;
    line-height: 1.4;
}

body.mado-portal-account-page
.mado-portal-shell--action-template-library
.mado-template-filter-form
select.mado-template-filter-control option {
    font-family: inherit;
    font-size: 15px;
}

.mado-template-filter-control--compact {
    width: 96px;
    min-width: 96px;
    min-height: 32px;
    padding-top: 4px;
    padding-bottom: 4px;
    font-size: 15px;
}

.mado-template-filter-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.mado-template-filter-search-btn {
    min-width: 72px;
    min-height: 38px;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.4;
    box-shadow: none;
}

.mado-template-filter-reset-chip {
    min-height: 38px;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    line-height: 1.4;
}

.mado-template-display-options {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.mado-template-display-options__label {
    color: #334155;
    font-size: 13px;
    font-weight: 700;
}

.mado-template-display-options__choice {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: #334155;
    font-size: 13px;
    line-height: 1.4;
}

.mado-template-display-options__per-page {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

/* Template list */
.mado-template-list-section {
    margin-top: 24px;
}

.mado-template-list-heading {
    margin: 0 0 16px;
    color: #111827;
    font-size: 16px;
    font-weight: 700;
    line-height: 1.5;
}

.mado-template-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.mado-template-card {
    display: grid;
    gap: 12px;
    padding: 16px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.04);
    cursor: default;
}

.mado-template-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.mado-template-card-title {
    margin: 0;
    color: #111827;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.55;
}

.mado-template-card-variant,
.mado-template-card-category,
.mado-template-card-industry,
.mado-template-detail-chip {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    padding: 2px 7px;
    border-radius: 999px;
    background: #f1f5f9;
    color: #475569;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.4;
    white-space: nowrap;
}

.mado-template-card-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.mado-template-preview {
    display: grid;
    gap: 6px;
    color: #334155;
    font-size: 14px;
    line-height: 1.7;
}

.mado-template-preview-item {
    min-width: 0;
    font-size: inherit;
    line-height: inherit;
}

.mado-template-preview-item--question,
.mado-template-preview-item--patterns {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
}

.mado-template-preview-item--question {
    -webkit-line-clamp: 2;
}

.mado-template-preview-item--patterns {
    -webkit-line-clamp: 1;
}

.mado-template-preview-item strong {
    color: #1e293b;
    font-size: inherit;
}

.mado-template-preview-answer {
    margin-top: 4px;
    padding: 10px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    color: #334155;
    font-size: 14px;
    line-height: 1.7;
}

.mado-template-preview-answer p {
    margin: 0 0 0.6em;
}

.mado-template-preview-answer p:last-child {
    margin-bottom: 0;
}

.mado-template-preview-memo {
    padding: 10px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    white-space: pre-wrap;
}

.mado-template-detail {
    display: grid;
    gap: 14px;
    padding-top: 12px;
    border-top: 1px solid #e2e8f0;
    color: #334155;
    font-size: 14px;
    line-height: 1.7;
}

.mado-template-detail[hidden] {
    display: none;
}

.mado-template-detail-section {
    display: grid;
    gap: 8px;
    font-size: inherit;
    line-height: inherit;
}

.mado-template-detail-section h4 {
    margin: 0;
    color: #1e293b;
    font-size: 14px;
    font-weight: 700;
    line-height: 1.5;
}

.mado-template-detail-section p,
.mado-template-detail-section ul,
.mado-template-detail-section li,
.mado-template-detail-section .mado-template-preview-answer {
    font-size: 14px;
    line-height: 1.7;
}

.mado-template-detail-section p,
.mado-template-detail-section ul {
    margin: 0;
}

.mado-template-detail-section ul {
    padding-left: 20px;
}

.mado-template-detail-memo {
    margin: 0;
    white-space: pre-wrap;
    font-family: var(--mado-portal-font-family, "Noto Sans JP", "Noto Sans", system-ui, sans-serif);
    font-size: 14px;
    line-height: 1.7;
}

.mado-template-card-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    width: 100%;
    margin-top: 2px;
}

.mado-template-card-actions .mado-template-accordion-toggle {
    grid-column: 2;
    justify-self: center;
}

.mado-template-card-actions .mado-template-use-btn {
    grid-column: 3;
    justify-self: end;
}

.mado-template-accordion-toggle {
    -webkit-appearance: none;
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    min-width: 32px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: #334155;
    box-shadow: none;
    cursor: pointer;
}

.mado-template-accordion-toggle:hover {
    background: #f1f5f9;
    color: #0f172a;
}

.mado-template-accordion-toggle:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.mado-template-accordion-toggle__sign,
.mado-template-accordion-toggle__sign svg {
    display: block;
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.mado-template-action-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.3;
}

.mado-template-action-button.is-applied {
    border-color: #16a34a;
    background: #16a34a;
    color: #ffffff;
}

.mado-template-load-more {
    display: none;
    margin-top: 24px;
    text-align: center;
}

.mado-template-load-more-btn {
    min-height: 38px;
    padding: 8px 22px;
    border-radius: 6px;
}

.mado-template-loading {
    display: none;
    padding: 20px;
    text-align: center;
}

.mado-template-empty {
    display: none;
    padding: 38px;
    text-align: center;
    background: #f8fafc;
    border: 1px dashed #cbd5e1;
    border-radius: 8px;
}

.mado-template-state-text {
    margin: 0;
    color: #64748b;
    font-size: 14px;
    line-height: 1.7;
}

/* Template modals */
.mado-template-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 10000;
    padding: 40px 20px;
    overflow-y: auto;
    background: rgba(15, 23, 42, 0.5);
    animation: mado-template-fade-in 0.2s ease-in;
}

.mado-template-modal--detail {
    z-index: 10001;
}

.mado-template-modal__dialog {
    position: relative;
    margin: 0 auto;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 24px 70px rgba(15, 23, 42, 0.24);
    animation: mado-template-slide-up 0.24s ease-out;
}

.mado-template-modal__dialog--help {
    max-width: 720px;
    padding: 32px;
}

.mado-template-modal__dialog--detail {
    max-width: 840px;
    padding: 24px 28px 20px;
}

.mado-template-modal__close {
    position: absolute;
    top: 12px;
    right: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 0;
    background: transparent;
    color: #64748b;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

.mado-template-modal__close:hover,
.mado-template-modal__close:focus {
    color: #0f172a;
}

.mado-template-help-content {
    margin-top: 8px;
}

.mado-tpl-help {
    color: #334155;
    font-size: 16px;
    line-height: 1.8;
}

.mado-tpl-help h3 {
    margin: 0 0 16px;
    color: #111827;
    font-size: 20px;
    font-weight: 700;
}

.mado-tpl-help h4 {
    margin: 20px 0 12px;
    color: #111827;
    font-size: 16px;
    font-weight: 700;
}

.mado-tpl-help p {
    margin: 0 0 12px;
}

.mado-tpl-help ul {
    margin: 0 0 16px;
    padding-left: 24px;
}

.mado-tpl-help li {
    margin-bottom: 8px;
}

.mado-tpl-help-note {
    margin-top: 20px;
    padding: 12px 16px;
    background: #fff7ed;
    border-left: 4px solid #f59e0b;
    border-radius: 4px;
}

.mado-template-detail-header {
    margin-bottom: 12px;
}

.mado-template-detail-header-layout {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.mado-template-detail-id {
    margin-bottom: 4px;
    color: #64748b;
    font-size: 12px;
}

.mado-template-detail-title {
    margin: 0 0 6px;
    color: #111827;
    font-size: 18px;
    font-weight: 700;
    line-height: 1.45;
}

.mado-template-detail-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    color: #64748b;
    font-size: 12px;
}

.mado-template-detail-kind {
    color: #475569;
}

.mado-template-detail-body {
    max-height: 60vh;
    overflow-y: auto;
    padding: 16px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
}

.mado-template-detail-body h4 {
    margin: 0 0 8px;
    color: #111827;
    font-size: 14px;
    font-weight: 700;
}

.mado-template-detail-body p,
.mado-template-detail-body li {
    color: #374151;
    font-size: 13px;
    line-height: 1.7;
}

.mado-template-detail-body code {
    padding: 2px 4px;
    background: #e2e8f0;
    border-radius: 3px;
    font-size: 12px;
}

.mado-template-detail-answer {
    margin-top: 4px;
    padding: 12px;
    color: #111827;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 13px;
    line-height: 1.7;
}

.mado-template-detail-memo-full {
    margin: 0;
    white-space: pre-wrap;
    font-family: Consolas, Monaco, monospace;
    font-size: 12px;
    line-height: 1.7;
}

.mado-template-detail-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 16px;
}

.mado-template-detail-action {
    min-height: 34px;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
}

.mado-template-detail-use-button {
    min-height: 36px;
    padding: 8px 16px;
    font-size: 13px;
}

@keyframes mado-template-fade-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes mado-template-slide-up {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 980px) {
    .mado-template-filter-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .mado-template-list {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 782px) {
    .mado-template-library-shell {
        padding: 18px;
    }

    .mado-template-library-heading-row,
    .mado-template-card-header {
        display: grid;
    }

    .mado-template-filter-grid {
        grid-template-columns: 1fr;
    }

    .mado-template-filter-actions,
    .mado-template-filter-actions .button {
        width: 100%;
    }

    .mado-template-display-options__per-page {
        width: 100%;
        margin-left: 0;
    }

    .mado-template-modal {
        padding: 20px 12px;
    }

    .mado-template-modal__dialog--help,
    .mado-template-modal__dialog--detail {
        padding: 22px 18px 18px;
    }
}
