/* 後台模塊管理專用樣式 */

/* 統計面板 */
.stats-panel {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stats-panel .stat-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: 1rem;
    border: 2px solid var(--border-light);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.stats-panel .stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    transform: translateX(-100%);
    transition: var(--transition);
}

.stats-panel .stat-card:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.stats-panel .stat-card:hover::before {
    transform: translateX(0);
}

.stats-panel .stat-icon {
    font-size: 2.5rem;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border-radius: 50%;
    color: white;
    text-shadow: 0 1px 3px rgba(0,0,0,0.3);
    flex-shrink: 0;
}

.stats-panel .stat-info {
    flex: 1;
}

.stats-panel .stat-number {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-color);
    line-height: 1;
    margin-bottom: 0.25rem;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
}

.stats-panel .stat-label {
    color: var(--text-light);
    font-size: 0.9rem;
    font-weight: 500;
}

/* 頁面選擇器面板 */
.page-selector-panel {
    background: white;
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-light);
}

.selector-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.selector-header h3 {
    color: var(--text-color);
    margin: 0;
    font-size: 1.3rem;
}

.selector-actions {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

.selector-actions input,
.selector-actions select {
    padding: 0.5rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    min-width: 150px;
    background: white;
    transition: var(--transition);
}

.selector-actions input:focus,
.selector-actions select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* 頁面網格 */
.pages-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.page-grid-item {
    background: var(--background-alt);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1rem;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.page-grid-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    transform: translateX(-100%);
    transition: var(--transition);
}

.page-grid-item:hover {
    border-color: var(--primary-color);
    background: #f0f4ff;
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.page-grid-item:hover::before {
    transform: translateX(0);
}

.page-grid-item.selected {
    border-color: var(--primary-color);
    background: var(--primary-color);
    color: white;
    box-shadow: var(--shadow-lg);
}

.page-grid-item.selected::before {
    transform: translateX(0);
    background: rgba(255,255,255,0.3);
}

.page-grid-item h4 {
    margin: 0 0 0.5rem 0;
    font-size: 1.1rem;
    color: inherit;
    font-weight: 600;
}

.page-grid-item p {
    margin: 0;
    font-size: 0.9rem;
    opacity: 0.8;
    line-height: 1.4;
}

.page-widget-count {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.page-grid-item.selected .page-widget-count {
    background: white;
    color: var(--primary-color);
}

/* 當前頁面資訊 */
.current-page-info {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 2rem;
    position: relative;
    overflow: hidden;
}

.current-page-info::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="20" cy="20" r="2" fill="rgba(255,255,255,0.1)"/><circle cx="80" cy="80" r="2" fill="rgba(255,255,255,0.1)"/><circle cx="40" cy="70" r="1" fill="rgba(255,255,255,0.1)"/><circle cx="60" cy="30" r="1" fill="rgba(255,255,255,0.1)"/></svg>');
    opacity: 0.3;
}

.page-info-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    position: relative;
    z-index: 1;
}

.page-info-header h3 {
    margin: 0;
    font-size: 1.3rem;
    text-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.page-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.page-actions .btn {
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    backdrop-filter: blur(10px);
}

.page-actions .btn:hover {
    background: rgba(255,255,255,0.3);
    border-color: rgba(255,255,255,0.5);
    color: white;
    text-decoration: none;
}

/* 模塊容器 */
.widgets-container {
    background: white;
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-light);
}

.widgets-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-light);
}

.widgets-header h3 {
    margin: 0;
    color: var(--text-color);
    font-size: 1.3rem;
}

.widgets-toolbar {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

.view-toggle {
    display: flex;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: white;
}

.view-btn {
    padding: 0.5rem 1rem;
    border: none;
    background: transparent;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-light);
    font-weight: 500;
}

.view-btn:hover {
    background: var(--background-alt);
    color: var(--text-color);
}

.view-btn.active {
    background: var(--primary-color);
    color: white;
}

.sort-options select {
    padding: 0.5rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    min-width: 120px;
    background: white;
    color: var(--text-color);
    transition: var(--transition);
}

.sort-options select:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* 模塊列表 */
.widgets-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.widgets-list.grid-view {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.widget-item {
    background: var(--background-alt);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: var(--transition);
    cursor: grab;
    position: relative;
    overflow: hidden;
}

.widget-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    transform: translateX(-100%);
    transition: var(--transition);
}

.widget-item:hover {
    border-color: var(--primary-color);
    background: #f0f4ff;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.widget-item:hover::before {
    transform: translateX(0);
}

.widget-item.dragging {
    opacity: 0.7;
    transform: rotate(2deg);
    z-index: 1000;
    cursor: grabbing;
    box-shadow: var(--shadow-xl);
}

.widgets-list.grid-view .widget-item {
    flex-direction: column;
    text-align: center;
    padding: 1.5rem;
}

.widget-drag-handle {
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: grab;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    user-select: none;
}

.widget-drag-handle:hover {
    color: var(--primary-color);
    background: rgba(102,126,234,0.1);
}

.widget-drag-handle:active {
    cursor: grabbing;
}

.widgets-list.grid-view .widget-drag-handle {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
}

.widget-icon {
    font-size: 2rem;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
    border-radius: 50%;
    color: white;
    text-shadow: 0 1px 3px rgba(0,0,0,0.3);
    flex-shrink: 0;
}

.widgets-list.grid-view .widget-icon {
    width: 60px;
    height: 60px;
    font-size: 2.5rem;
    margin-bottom: 1rem;
}

.widget-info {
    flex: 1;
    min-width: 0;
}

.widgets-list.grid-view .widget-info {
    flex: none;
    width: 100%;
}

.widget-info h4 {
    margin: 0 0 0.5rem 0;
    color: var(--text-color);
    font-size: 1.1rem;
    font-weight: 600;
}

.widget-info p {
    margin: 0 0 0.3rem 0;
    color: var(--text-light);
    font-size: 0.9rem;
    line-height: 1.4;
}

.widget-info small {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.widget-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.widgets-list.grid-view .widget-actions {
    margin-top: 1rem;
    justify-content: center;
}

.widget-actions .btn-icon {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    background: transparent;
    color: var(--text-muted);
}

.widget-actions .btn-icon:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.widget-actions .btn-icon:nth-child(1) { /* 編輯 */
    background: rgba(72, 187, 120, 0.1);
    color: #38a169;
    border: 1px solid rgba(72, 187, 120, 0.2);
}

.widget-actions .btn-icon:nth-child(1):hover {
    background: #38a169;
    color: white;
    border-color: #38a169;
}

.widget-actions .btn-icon:nth-child(2) { /* 預覽 */
    background: rgba(66, 153, 225, 0.1);
    color: #3182ce;
    border: 1px solid rgba(66, 153, 225, 0.2);
}

.widget-actions .btn-icon:nth-child(2):hover {
    background: #3182ce;
    color: white;
    border-color: #3182ce;
}

.widget-actions .btn-icon:nth-child(3) { /* 刪除 */
    background: rgba(245, 101, 101, 0.1);
    color: #e53e3e;
    border: 1px solid rgba(245, 101, 101, 0.2);
}

.widget-actions .btn-icon:nth-child(3):hover {
    background: #e53e3e;
    color: white;
    border-color: #e53e3e;
}

/* 空狀態 */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-muted);
    background: var(--background-alt);
    border-radius: var(--radius-lg);
    border: 2px dashed var(--border-color);
}

.empty-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state h3 {
    color: var(--text-light);
    margin-bottom: 0.5rem;
    font-size: 1.3rem;
}

.empty-state p {
    margin-bottom: 2rem;
    line-height: 1.6;
    color: var(--text-muted);
}

/* 模塊類型選擇 */
.widget-categories {
    display: grid;
    gap: 2rem;
}

.widget-category {
    margin-bottom: 2rem;
}

.widget-category h4 {
    background: var(--background-alt);
    margin: 0;
    padding: 1rem 1.5rem;
    color: var(--text-color);
    font-size: 1.1rem;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
}

.category-title {
    margin-bottom: 1rem;
    color: #4a5568;
}

.widget-types {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.search-input {
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-right: 1rem;
}

.config-tab-content {
    display: none;
}

.config-tab-content.active {
    display: block;
}

.widget-type-card {
    padding: 1rem;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
    background: white;
}

.widget-type-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    transform: translateX(-100%);
    transition: var(--transition);
}

.widget-type-card:hover {
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
    transform: translateY(-2px);
}

.widget-type-card:hover::before {
    transform: translateX(0);
}

.widget-type-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.widget-type-name {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.widget-type-desc {
    font-size: 0.875rem;
    color: #666;
}

/* 模塊配置表單 */
.widget-config-container {
    display: flex;
    gap: 2rem;
    min-height: 500px;
}

.config-sidebar {
    width: 200px;
    flex-shrink: 0;
}

.config-tabs {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.config-tab {
    padding: 0.8rem 1rem;
    border: none;
    background: var(--background-alt);
    color: var(--text-light);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    text-align: left;
    font-size: 0.9rem;
    font-weight: 500;
}

.config-tab:hover {
    background: #edf2f7;
    color: var(--text-color);
}

.config-tab.active {
    background: var(--primary-color);
    color: white;
}

.config-content {
    flex: 1;
    background: var(--background-alt);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    overflow-y: auto;
    max-height: 500px;
}

/* 陣列欄位樣式 */
.array-field {
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem;
    background: white;
}

.array-items {
    margin-bottom: 1rem;
}

.array-item {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding: 1rem;
    background: var(--background-alt);
    border-radius: var(--radius-md);
    align-items: center;
    flex-wrap: wrap;
    border: 1px solid var(--border-light);
    transition: var(--transition);
}

.array-item:hover {
    border-color: var(--primary-color);
}

.array-item input,
.array-item select,
.array-item textarea {
    flex: 1;
    min-width: 150px;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    background: white;
    transition: var(--transition);
}

.array-item input:focus,
.array-item select:focus,
.array-item textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.array-item .btn-icon {
    flex-shrink: 0;
    margin-left: 0.5rem;
    width: 32px;
    height: 32px;
    background: rgba(245, 101, 101, 0.1);
    color: #e53e3e;
    border: 1px solid rgba(245, 101, 101, 0.2);
}

.array-item .btn-icon:hover {
    background: #e53e3e;
    color: white;
    border-color: #e53e3e;
}

.product-item {
    flex-direction: column;
    align-items: stretch;
}

.product-item input {
    margin-bottom: 0.5rem;
    min-width: auto;
}

/* 預覽系統 */
.preview-container {
    background: white;
    border-radius: var(--radius-lg);
    padding: 1rem;
    border: 2px solid var(--border-color);
    min-height: 300px;
    overflow: auto;
}

.preview-wrapper {
    transition: all 0.3s ease;
}

.preview-wrapper.desktop {
    max-width: 100%;
}

.preview-wrapper.tablet {
    max-width: 768px;
    margin: 0 auto;
}

.preview-wrapper.mobile {
    max-width: 375px;
    margin: 0 auto;
}

/* 響應式設計 */
@media (max-width: 1024px) {
    .widget-config-container {
        flex-direction: column;
    }
    
    .config-sidebar {
        width: 100%;
    }
    
    .config-tabs {
        flex-direction: row;
        overflow-x: auto;
        gap: 1rem;
        padding-bottom: 0.5rem;
    }
    
    .config-tab {
        white-space: nowrap;
        flex-shrink: 0;
    }
    
    .widgets-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    
    .view-toggle {
        justify-content: center;
    }
}

@media (max-width: 768px) {
    .stats-panel {
        grid-template-columns: 1fr;
    }
    
    .selector-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .selector-actions {
        flex-direction: column;
    }
    
    .pages-grid {
        grid-template-columns: 1fr;
    }
    
    .widgets-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .widgets-list.grid-view {
        grid-template-columns: 1fr;
    }
    
    .widget-item {
        flex-direction: column;
        text-align: center;
    }
    
    .widget-drag-handle {
        position: absolute;
        top: 0.5rem;
        right: 0.5rem;
    }
    
    .widget-types {
        grid-template-columns: 1fr;
    }
    
    .array-item {
        flex-direction: column;
        align-items: stretch;
    }
    
    .array-item input {
        min-width: auto;
        margin-bottom: 0.5rem;
    }
    
    .array-item .btn-icon {
        margin-left: 0;
        align-self: center;
    }
    
    .config-content {
        max-height: none;
    }
}

@media (max-width: 480px) {
    .page-selector-panel,
    .widgets-container {
        padding: 1rem;
    }
    
    .stats-panel .stat-card {
        padding: 1rem;
        flex-direction: column;
        text-align: center;
    }
    
    .stats-panel .stat-icon {
        width: 50px;
        height: 50px;
        font-size: 2rem;
        margin-bottom: 0.5rem;
    }
    
    .page-actions {
        flex-direction: column;
        width: 100%;
    }
    
    .page-actions .btn {
        width: 100%;
        justify-content: center;
    }
    
    .widget-actions {
        justify-content: center;
        margin-top: 1rem;
    }
    
    .config-tabs {
        flex-direction: column;
    }
}

/* 動畫效果 */
@keyframes slideInFromBottom {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInFromRight {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.widget-item,
.widget-type-card,
.page-grid-item {
    animation: slideInFromBottom 0.3s ease-out;
}

.stats-panel .stat-card {
    animation: slideInFromRight 0.4s ease-out;
}

.stats-panel .stat-card:nth-child(2) {
    animation-delay: 0.1s;
}

.stats-panel .stat-card:nth-child(3) {
    animation-delay: 0.2s;
}

/* 載入狀態 */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-light);
    border-top: 2px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.btn.loading {
    position: relative;
    color: transparent;
    pointer-events: none;
}

.btn.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top: 2px solid currentColor;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* 拖拽提示 */
.drag-hint {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 1rem 2rem;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    z-index: 10000;
    pointer-events: none;
    backdrop-filter: blur(10px);
}

/* 搜尋高亮 */
.search-highlight {
    background: yellow;
    padding: 0.1rem 0.2rem;
    border-radius: 2px;
}

/* 無障礙性增強 */
@media (prefers-reduced-motion: reduce) {
    .widget-item,
    .widget-type-card,
    .page-grid-item,
    .stats-panel .stat-card {
        animation: none;
        transition: none;
    }
}

/* 高對比度模式 */
@media (prefers-contrast: high) {
    .widget-item,
    .page-grid-item,
    .widget-type-card {
        border-width: 3px;
    }
    
    .widget-actions .btn-icon {
        border-width: 2px;
    }
}