/* ===== Prompt Templates Page Styles ===== */

/* Layout Structure */
.main-layout {
    display: flex;
    min-height: calc(100vh - 80px);
    background: var(--bg-primary);
    margin-top: 80px;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    padding: 24px 20px;
    box-shadow: var(--shadow-sm);
    position: fixed;
    top: 80px;
    height: calc(100vh - 80px);
    overflow-y: auto;
    transition: all 0.3s ease;
}


/* Filter Section */
.filter-section {
    margin-bottom: 24px;
}

.filter-title {
    font-size: 0.875rem;
    margin-bottom: 12px;
    font-weight: 600;
    color: var(--text-primary);
    text-align: left;
}

/* Search Box */
.search-box {
    position: relative;
    margin-bottom: 20px;
}

.search-input {
    width: 100%;
    padding: 12px 16px 12px 40px;
    border: 1px solid var(--border-medium);
    border-radius: 8px;
    font-size: 0.9rem;
    background: var(--bg-card);
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(255, 97, 86, 0.1);
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary);
    font-size: 0.9rem;
}

/* Filter Subgroups */
.filter-subgroup {
    margin-bottom: 16px;
}

.filter-subtitle {
    font-size: 0.75rem;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-secondary);
    text-align: left;
}

.filter-options {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-wrap: wrap;
}

.filter-option {
    padding: 6px 8px;
    margin-left: 12px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.75rem;
    border: 1px solid var(--border-light);
    display: inline-block;
    text-align: left;
    white-space: nowrap;
    width: auto;
    font-weight: 500;
}

.filter-option i {
    margin-right: 4px;
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.filter-option:hover {
    background: rgba(255, 97, 86, 0.1);
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.filter-option.active {
    background: transparent;
    color: var(--primary-color);
    border-color: var(--primary-color);
    font-weight: 600;
}

.filter-option.active i {
    color: var(--primary-color);
}

.filter-option:hover i {
    color: var(--primary-color);
}


/* Main Content */
.main-content {
    flex: 1;
    padding: 30px;
    margin-left: 280px;
    overflow-y: auto;
    min-width: 0;
    width: calc(100vw - 280px);
    max-width: calc(100vw - 280px);
}

.content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

.content-title {
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.025em;
}



/* Templates Section */
.templates-section {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 20px;
    border: 1px solid var(--border-light);
}

.templates-container {
    width: 100%;
}

/* Loading State */
.loading-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
    width: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

.loading-spinner {
    margin-bottom: 20px;
}

.loading-spinner i {
    font-size: 2rem;
    color: var(--primary-color);
}

.loading-state h3 {
    margin: 0 0 10px 0;
    font-size: 1.2rem;
    color: var(--text-primary);
}

.loading-state p {
    margin: 0;
    font-size: 0.9rem;
}

/* Error State */
.error-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
    width: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

.error-icon i {
    font-size: 2rem;
    color: var(--error-color);
    margin-bottom: 20px;
}

.error-state h3 {
    margin: 0 0 10px 0;
    font-size: 1.2rem;
    color: var(--text-primary);
}

.error-state p {
    margin: 0 0 20px 0;
    font-size: 0.9rem;
}

/* Enhanced Error Message Styles */
.error-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    background: var(--bg-card);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    margin: 20px;
    grid-column: 1 / -1;
}

.error-message .error-icon {
    margin-bottom: 20px;
}

.error-message .error-icon i {
    font-size: 4rem;
    color: #ff6b6b;
}

.error-message h3 {
    margin: 0 0 8px 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.error-message .error-main {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.error-message .error-detail {
    color: var(--text-secondary);
    margin-bottom: 24px;
    line-height: 1.5;
}

.error-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.error-action-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 12px 24px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-sm);
}

.error-action-btn:hover {
    background: var(--primary-dark, #2563eb);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.error-action-btn:nth-child(2) {
    background: transparent;
    color: var(--text-secondary);
    border: 2px solid var(--border-light);
}

.error-action-btn:nth-child(2):hover {
    background: var(--bg-card);
    color: var(--primary-color);
    border-color: var(--primary-color);
}

/* Templates Grid */
.templates-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr); /* デフォルト: 3列 */
    gap: 20px;
    margin-top: 20px;
}

/* Template Card */
.template-card {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    overflow: hidden;
    transition: all var(--transition-smooth);
    cursor: pointer;
    position: relative;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    min-height: 240px; /* height を min-height に変更 */
    height: auto; /* コンテンツに応じて高さを自動調整 */
}

.template-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-color);
}

.template-card-header {
    padding: 20px;
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.template-card-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 12px 0;
    line-height: 1.6;
    min-height: calc(1.1rem * 1.6 * 2 + 20px); /* 全カードで統一された最小高さ */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(5px);
    padding: 10px 12px;
    border-radius: 8px;
    word-break: break-all; /* 日本語を含むあらゆる文字で改行可能にする */
    overflow-wrap: break-word;
}

.template-card-description {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.5;
    margin: 0 0 12px 0;
    max-height: calc(0.9rem * 1.5 * 2.8 + 16px); /* font-size * line-height * 2.8行 + padding */
    overflow: hidden;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(5px);
    padding: 8px 12px;
    border-radius: 8px;
    flex: 1 1 auto; /* 内容に応じたサイズ、可変 */
    min-height: 50px; /* 最小高さを設定 */
}

.template-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px; /* 統一された余白 */
    margin-bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(5px);
    padding: 8px 12px;
    border-radius: 8px;
}

.template-category-tag {
    background: rgba(255, 255, 255, 0.9);
    color: #ff6156;
    border: 1px solid #ff6156;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.template-tag {
    background: rgba(255, 255, 255, 0.9);
    color: #3b82f6;
    border: 1px solid #3b82f6;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}


/* ダークモード対応 */
[data-theme="dark"] .template-card-title,
[data-theme="dark"] .template-card-description,
[data-theme="dark"] .template-card-meta {
    background: rgba(0, 0, 0, 0.85);
}

[data-theme="dark"] .template-category-tag,
[data-theme="dark"] .template-tag {
    background: rgba(0, 0, 0, 0.8);
}

/* No Results */
.no-results {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.no-results i {
    font-size: 2rem;
    color: var(--text-tertiary);
    margin-bottom: 20px;
}

.no-results h3 {
    margin: 0 0 10px 0;
    font-size: 1.2rem;
    color: var(--text-primary);
}

.no-results p {
    margin: 0;
    font-size: 0.9rem;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal-content {
    background: var(--bg-card);
    border-radius: 16px;
    width: 100%;
    max-width: 600px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border-light);
}

.modal-header h3 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all var(--transition-fast);
}

.modal-close:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.modal-actions {
    display: flex;
    gap: 10px;
    padding: 20px;
    border-top: 1px solid var(--border-light);
}

/* Responsive Design */
@media (max-width: 1665px) {
    .templates-grid {
        grid-template-columns: repeat(2, 1fr); /* 1240px～1665px: 2列 */
    }
}

@media (max-width: 1240px) {
    .templates-grid {
        grid-template-columns: 1fr; /* 1240px以下: 1列 */
        gap: 15px;
    }
}

/* Mobile Filter Toggle - Default hidden */
.mobile-filter-toggle {
    display: none;
}

@media (max-width: 1024px) {
    .sidebar {
        position: fixed;
        left: -280px;
        transition: left 0.3s ease;
        z-index: 1500;
        top: 0;
        height: 100vh;
        padding-top: 100px;
        box-shadow: var(--shadow-xl);
        width: 280px;
    }

    .sidebar.open {
        left: 0;
    }

    .main-content {
        padding: 16px;
        margin-left: 0;
        width: 100vw;
        max-width: 100vw;
    }

    .mobile-filter-toggle {
        display: block;
        position: fixed;
        bottom: 20px;
        right: 20px;
        background: var(--primary-color);
        color: white;
        border: none;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        font-size: 1.25rem;
        cursor: pointer;
        box-shadow: var(--shadow-lg);
        z-index: 1000;
        transition: all 0.2s ease;
    }

    .mobile-filter-toggle:hover {
        transform: scale(1.05);
    }
    
    .templates-grid {
        grid-template-columns: 1fr; /* 1024px以下: 1列維持 */
    }
}

@media (max-width: 480px) {
    /* 480px以下のメディアクエリ内容は必要に応じて追加 */
}