/* Template selection workspace */
.template-modal-content {
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: min(90vh, 760px);
}

.template-modal-header {
    flex: 0 0 auto;
    padding: 1.25rem 1.5rem 1rem;
    border-bottom: 1px solid #e5e7eb;
}

.template-close-btn {
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.75rem;
}

.template-modal-body {
    flex: 1 1 auto;
    min-height: 0;
    padding: 1rem 1.5rem;
    overflow: hidden;
}

.template-filter-bar {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    padding-bottom: 0.75rem;
    scrollbar-width: thin;
}

.template-filter-btn {
    flex: 0 0 auto;
    min-height: 40px;
    padding: 0.5rem 0.9rem;
    border: 1px solid #e5e7eb;
    border-radius: 999px;
    color: #4b5563;
    background: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    transition: 0.15s ease;
}

.template-filter-btn:hover,
.template-filter-btn.active {
    border-color: #818cf8;
    color: #4338ca;
    background: #eef2ff;
}

.template-workspace {
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(310px, 0.95fr);
    gap: 1rem;
    height: calc(100% - 52px);
    min-height: 0;
}

.template-list-pane,
.template-detail-pane {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.template-cards-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    padding: 2px;
}

.template-card {
    width: 100%;
    min-height: 150px;
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.9rem;
    border-width: 2px;
    border-radius: 0.9rem;
    text-align: left;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.template-card:hover {
    border-color: #818cf8;
    box-shadow: 0 6px 18px rgba(79, 70, 229, 0.1);
}

.template-card:focus-visible {
    outline: 3px solid rgba(99, 102, 241, 0.35);
    outline-offset: 2px;
}

.template-card.selected {
    border-color: #4f46e5;
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.14);
}

.template-card-icon {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.65rem;
    font-size: 1.2rem;
}

.template-card-main,
.template-card-heading {
    min-width: 0;
    display: flex;
}

.template-card-main {
    flex: 1;
    flex-direction: column;
}

.template-card-heading {
    align-items: flex-start;
    gap: 0.35rem;
    padding-right: 1.2rem;
}

.template-card-title {
    color: #1f2937;
    font-size: 0.84rem;
    font-weight: 700;
    line-height: 1.3;
}

.template-recommended {
    flex: 0 0 auto;
    padding: 0.12rem 0.35rem;
    border-radius: 999px;
    color: #4338ca;
    background: #e0e7ff;
    font-size: 0.58rem;
    font-weight: 700;
}

.template-card-desc {
    margin-top: 0.3rem;
    color: #6b7280;
    font-size: 0.7rem;
    line-height: 1.45;
}

.template-card-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 0.55rem;
    margin-top: auto;
    padding-top: 0.7rem;
    color: #4b5563;
    font-size: 0.63rem;
    font-weight: 600;
}

.template-card-stats span {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
}

.template-card-check {
    position: absolute;
    top: 0.65rem;
    right: 0.65rem;
    width: 22px;
    height: 22px;
    display: none;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    color: white;
    background: #4f46e5;
    font-size: 0.65rem;
}

.template-card.selected .template-card-check {
    display: inline-flex;
}

.template-detail-pane {
    padding: 1rem;
    border: 1px solid #e5e7eb;
    border-radius: 0.9rem;
    background: #f9fafb;
}

.template-detail-empty {
    height: 100%;
    min-height: 260px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    text-align: center;
}

.template-detail-heading {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.template-detail-icon {
    font-size: 1.6rem;
}

.template-detail-heading h4 {
    color: #1f2937;
    font-size: 1rem;
    font-weight: 700;
}

.template-detail-heading p {
    margin-top: 0.2rem;
    color: #6b7280;
    font-size: 0.75rem;
}

.template-detail-summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    margin-top: 1rem;
}

.template-detail-summary span {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.6rem 0.3rem;
    border: 1px solid #e0e7ff;
    border-radius: 0.65rem;
    color: #6b7280;
    background: #fff;
    font-size: 0.62rem;
}

.template-detail-summary strong {
    color: #4338ca;
    font-size: 1rem;
}

.template-task-preview,
.template-date-field,
.template-mode-fieldset {
    margin-top: 1rem;
}

.template-task-preview h5,
.template-mode-fieldset legend,
.template-date-field > span {
    color: #374151;
    font-size: 0.75rem;
    font-weight: 700;
}

.template-task-preview ul {
    display: grid;
    gap: 0.35rem;
    margin-top: 0.5rem;
}

.template-task-preview li {
    display: flex;
    align-items: flex-start;
    gap: 0.4rem;
    color: #4b5563;
    font-size: 0.7rem;
}

.template-task-more {
    color: #6366f1 !important;
    font-weight: 600;
}

.template-date-field {
    display: grid;
    gap: 0.4rem;
}

.template-date-field > span {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.template-date-field input {
    min-height: 44px;
    width: 100%;
    padding: 0.55rem 0.7rem;
    border: 1px solid #d1d5db;
    border-radius: 0.6rem;
    background: #fff;
    font-size: 0.8rem;
}

.template-date-field small {
    color: #9ca3af;
    font-size: 0.65rem;
}

.template-mode-fieldset {
    display: grid;
    gap: 0.5rem;
}

.template-mode-option {
    min-height: 52px;
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    padding: 0.6rem 0.7rem;
    border: 1px solid #d1d5db;
    border-radius: 0.65rem;
    background: #fff;
    cursor: pointer;
}

.template-mode-option:has(input:checked) {
    border-color: #6366f1;
    background: #eef2ff;
}

.template-mode-option-danger:has(input:checked) {
    border-color: #f87171;
    background: #fef2f2;
}

.template-mode-option input {
    margin-top: 0.15rem;
}

.template-mode-option span {
    display: flex;
    flex-direction: column;
}

.template-mode-option strong {
    color: #374151;
    font-size: 0.75rem;
}

.template-mode-option small {
    margin-top: 0.12rem;
    color: #6b7280;
    font-size: 0.65rem;
}

.template-modal-footer {
    flex: 0 0 auto;
    display: flex;
    justify-content: flex-end;
    gap: 0.65rem;
    padding: 0.9rem 1.5rem;
    border-top: 1px solid #e5e7eb;
    background: rgba(255, 255, 255, 0.98);
}

@media (max-width: 767px) {
    .modal-overlay:has(.template-modal-content) {
        align-items: stretch;
        padding: 0;
    }

    .template-modal-content {
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
    }

    .template-modal-header {
        padding: 0.9rem 1rem 0.75rem;
    }

    .template-modal-body {
        padding: 0.75rem 1rem;
        overflow-y: auto;
    }

    .template-workspace {
        display: block;
        height: auto;
    }

    .template-list-pane,
    .template-detail-pane {
        overflow: visible;
    }

    .template-cards-grid {
        grid-template-columns: 1fr;
    }

    .template-card {
        min-height: 138px;
    }

    .template-detail-pane {
        margin-top: 1rem;
    }

    .template-detail-empty {
        min-height: 150px;
    }

    .template-modal-footer {
        padding: 0.75rem 1rem max(0.75rem, env(safe-area-inset-bottom));
    }

    .template-modal-footer button:last-child {
        flex: 1;
    }
}

@media (max-width: 390px) {
    .template-card-stats {
        gap-right: 0.35rem;
    }

    .template-modal-footer {
        gap: 0.45rem;
    }

    .template-modal-footer button {
        padding-left: 0.8rem;
        padding-right: 0.8rem;
    }
}
