/**
 * SandboxCafe 統合設定パネル CSS
 * ステップ形式のUI、プリセット機能、設定状況の可視化
 * API選択・WebApp生成機能
 */

/* =========================
   API選択・WebApp生成セクション
   ========================= */
.api-selection-section {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 2rem;
    border: 1px solid #e9ecef;
}

.api-selection-buttons {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.api-select-btn {
    background: #007bff;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
}

.api-select-btn:hover {
    background: #0056b3;
    transform: translateY(-2px);
}

.api-select-btn.secondary {
    background: #6c757d;
}

.api-select-btn.secondary:hover {
    background: #545b62;
}

.api-list-container,
.apikey-selection-container,
.webapp-customization {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    margin-top: 1rem;
    border: 1px solid #dee2e6;
}

.api-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #dee2e6;
}

.api-list-stats {
    font-size: 0.9rem;
    color: #6c757d;
}

.api-list {
    display: grid;
    gap: 1rem;
}

.api-item {
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    background: white;
}

.api-item:hover {
    border-color: #007bff;
    box-shadow: 0 2px 8px rgba(0, 123, 255, 0.1);
}

.api-item.selected {
    border-color: #007bff;
    background: #f8f9ff;
}

.api-item-header {
    display: flex;
    justify-content: between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.api-item-name {
    font-weight: 600;
    color: #333;
}

.api-item-category {
    background: #e9ecef;
    color: #6c757d;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
}

.api-item-description {
    color: #666;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.api-item-stats {
    display: flex;
    gap: 1rem;
    font-size: 0.8rem;
    color: #6c757d;
}

.apikey-item {
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    background: white;
    margin-bottom: 1rem;
}

.apikey-item:hover {
    border-color: #28a745;
    box-shadow: 0 2px 8px rgba(40, 167, 69, 0.1);
}

.apikey-item.selected {
    border-color: #28a745;
    background: #f8fff9;
}

.apikey-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.apikey-item-name {
    font-weight: 600;
    color: #333;
}

.apikey-item-tier {
    background: #28a745;
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
}

.apikey-item-stats {
    font-size: 0.8rem;
    color: #6c757d;
}

.loading {
    text-align: center;
    padding: 2rem;
    color: #6c757d;
}

.webapp-customization .form-group {
    margin-bottom: 1rem;
}

.webapp-customization label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #333;
}

.webapp-customization .form-input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    font-size: 1rem;
}

.webapp-customization .form-input:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

/* =========================
   パネル切り替えセクション
   ========================= */
.panel-toggle-section {
    background: linear-gradient(135deg, #e3f2fd 0%, #f3e5f5 100%);
    border: 2px solid #2196f3;
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 4px 16px rgba(33, 150, 243, 0.1);
}

.toggle-info h4 {
    margin: 0 0 0.5rem 0;
    color: #1976d2;
    font-size: 1.2rem;
}

.toggle-info p {
    margin: 0;
    color: #666;
    line-height: 1.5;
}

/* =========================
   統合設定パネル
   ========================= */
.config-panel {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.config-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 2rem;
    text-align: center;
    position: relative;
}

.config-header h3 {
    margin: 0 0 0.5rem 0;
    font-size: 1.5rem;
}

.config-header p {
    margin: 0;
    opacity: 0.9;
}

.config-header button {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    border-radius: 6px;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.config-header button:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* =========================
   ステップインジケーター
   ========================= */
.step-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
}

.step-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 120px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.step-number {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #e9ecef;
    color: #6c757d;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    margin-bottom: 0.5rem;
    transition: all 0.3s ease;
}

.step-label {
    font-size: 0.875rem;
    color: #6c757d;
    text-align: center;
    transition: color 0.3s ease;
}

.step-item.active .step-number {
    background: #28a745;
    color: white;
}

.step-item.active .step-label {
    color: #28a745;
    font-weight: 600;
}

.step-item.current .step-number {
    background: #007bff;
    color: white;
    transform: scale(1.1);
}

.step-item.current .step-label {
    color: #007bff;
    font-weight: 600;
}

.step-item.completed .step-number {
    background: #28a745;
    color: white;
    font-size: 1.2rem;
}

.step-item.completed .step-label {
    color: #28a745;
    font-weight: 600;
}

.step-connector {
    flex: 1;
    height: 2px;
    background: #e9ecef;
    margin: 0 1rem;
    margin-top: -20px;
    min-width: 50px;
}

/* =========================
   ステップコンテンツ
   ========================= */
.config-step {
    display: none;
    padding: 2rem;
    min-height: 500px;
}

.config-step.active {
    display: block;
}

.step-header {
    text-align: center;
    margin-bottom: 2rem;
}

.step-header h4 {
    margin: 0 0 0.5rem 0;
    color: #333;
    font-size: 1.3rem;
}

.step-header p {
    margin: 0;
    color: #666;
    line-height: 1.5;
}

.step-content {
    max-width: 800px;
    margin: 0 auto;
}

.step-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid #e9ecef;
}

.step-actions .btn + .btn {
    margin-left: 1rem;
}

.step-actions .btn-large {
    padding: 1rem 2rem;
    font-size: 1.1rem;
    font-weight: 600;
}

/* =========================
   API選択エリア
   ========================= */
.api-selection-area {
    margin-bottom: 2rem;
}

.api-search {
    margin-bottom: 1.5rem;
}

.api-search input {
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
    display: block;
}

.api-list {
    min-height: 300px;
}

.api-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.api-card {
    background: #f8f9fa;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    padding: 1.5rem;
    transition: all 0.3s ease;
    cursor: pointer;
    position: relative;
}

.api-card:hover {
    border-color: #007bff;
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.15);
}

.api-card.selected {
    border-color: #28a745;
    background: #f8fff9;
    box-shadow: 0 4px 16px rgba(40, 167, 69, 0.2);
}

.api-card.test-api {
    border-color: #ffc107;
    background: #fffdf5;
}

.api-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.api-title {
    margin: 0;
    color: #333;
    font-size: 1.1rem;
}

.test-badge {
    background: #ffc107;
    color: #856404;
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.preset-badge {
    background: #28a745;
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.preset-api {
    border-color: #28a745;
    background: #f8fff9;
    box-shadow: 0 2px 8px rgba(40, 167, 69, 0.1);
}

.preset-api:hover {
    border-color: #28a745;
    box-shadow: 0 4px 16px rgba(40, 167, 69, 0.25);
}

.preset-api .api-title {
    color: #28a745;
}

.api-description {
    color: #666;
    margin: 0 0 1rem 0;
    line-height: 1.4;
}

.api-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.875rem;
    color: #6c757d;
    margin-bottom: 1rem;
}

.api-card-actions {
    position: absolute;
    bottom: 1rem;
    right: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.select-api-btn {
    width: 100%;
}

.one-click-setup-btn {
    font-size: 0.8rem;
    padding: 0.4rem 0.8rem;
    white-space: nowrap;
}

.loading-message,
.no-apis-message,
.api-error-message {
    text-align: center;
    padding: 3rem;
    color: #666;
}

.no-apis-icon,
.error-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.no-apis-actions {
    margin-top: 1.5rem;
}

.no-apis-actions .btn + .btn {
    margin-left: 1rem;
}

/* =========================
   APIキー状況表示
   ========================= */
.selected-api-card {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.api-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.api-header h5 {
    margin: 0;
    color: #333;
}

.api-desc {
    color: #666;
    margin: 0 0 1rem 0;
}

.api-params strong {
    display: block;
    margin-bottom: 0.5rem;
    color: #333;
}

.param-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.param-tag {
    background: #e3f2fd;
    color: #1976d2;
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    font-size: 0.875rem;
}

.api-key-status-ok,
.api-key-status-warning,
.api-key-status-error {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.api-key-status-ok {
    background: #f8fff9;
    border: 1px solid #d4edda;
}

.api-key-status-warning {
    background: #fffdf5;
    border: 1px solid #ffeaa7;
}

.api-key-status-error {
    background: #ffebee;
    border: 1px solid #f8d7da;
}

.status-icon {
    font-size: 2rem;
    flex-shrink: 0;
}

.status-info h5 {
    margin: 0 0 0.5rem 0;
    color: #333;
}

.status-info p {
    margin: 0 0 1rem 0;
    color: #666;
}

/* =========================
   WEBアプリ設定エリア
   ========================= */
.webapp-config-area {
    margin-bottom: 2rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.template-selection h5 {
    margin: 0 0 1rem 0;
    color: #333;
}

.template-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.template-card {
    background: #f8f9fa;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    padding: 1rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}

.template-card:hover {
    border-color: #007bff;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.15);
}

.template-card.selected {
    border-color: #28a745;
    background: #f8fff9;
    box-shadow: 0 4px 16px rgba(40, 167, 69, 0.2);
}

.template-preview {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.template-info h6 {
    margin: 0 0 0.5rem 0;
    color: #333;
}

.template-info p {
    margin: 0;
    color: #666;
    font-size: 0.875rem;
}

.select-template-btn {
    position: absolute;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
}

.preview-area {
    margin-top: 2rem;
}

.preview-header h6 {
    margin: 0 0 1rem 0;
    color: #333;
}

.preview-content {
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 1rem;
    background: #f8f9fa;
}

.mock-webapp {
    background: white;
    border-radius: 8px;
    padding: 1rem;
    min-height: 200px;
}

.mock-webapp.basic {
    border: 1px solid #ddd;
}

.mock-webapp.modern {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.mock-webapp.medical {
    border: 2px solid #28a745;
    background: #f8fff9;
}

.mock-header {
    font-weight: bold;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid currentColor;
}

.mock-form {
    margin-bottom: 1rem;
}

.mock-input {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    padding: 0.5rem;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}

.mock-button {
    background: #007bff;
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    text-align: center;
    font-size: 0.875rem;
}

/* =========================
   設定サマリー
   ========================= */
.config-summary {
    margin-bottom: 2rem;
}

.config-summary h5 {
    margin: 0 0 1rem 0;
    color: #333;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
}

.summary-item {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 1rem;
}

.summary-label {
    font-weight: 600;
    color: #666;
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
}

.summary-value {
    color: #333;
    font-size: 1rem;
}

.generation-options {
    margin-bottom: 2rem;
}

.checkbox-wrapper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    cursor: pointer;
}

.checkbox-wrapper input[type="checkbox"] {
    width: 18px;
    height: 18px;
}

/* =========================
   設定状況可視化
   ========================= */
.config-progress {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 1rem;
    margin-top: 1rem;
    backdrop-filter: blur(10px);
}

.progress-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.progress-text {
    font-weight: 600;
    color: white;
}

.progress-status {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.85rem;
}

.progress-bar {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    height: 8px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 10px;
    transition: width 0.3s ease, background-color 0.3s ease;
}

.config-warnings {
    background: #fff8e1;
    border: 1px solid #ffb74d;
    border-radius: 8px;
    margin: 1rem 2rem;
    padding: 1rem;
}

.warning-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #e65100;
}

.warning-icon {
    font-size: 1.2rem;
}

.warning-title {
    font-size: 0.9rem;
}

.warning-list {
    display: grid;
    gap: 0.5rem;
}

.warning-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    background: rgba(255, 183, 77, 0.1);
    border-radius: 6px;
    font-size: 0.85rem;
    color: #bf360c;
}

.warning-item-icon {
    font-size: 1rem;
}

.warning-item-text {
    flex: 1;
}

/* =========================
   生成結果表示
   ========================= */
.generation-result {
    padding: 2rem;
    text-align: center;
}

.result-header h4 {
    margin: 0 0 1rem 0;
    color: #28a745;
    font-size: 1.5rem;
}

.result-success {
    background: #f8fff9;
    border: 2px solid #28a745;
    border-radius: 12px;
    padding: 2rem;
    margin-bottom: 2rem;
}

.result-url h5 {
    margin: 0 0 1rem 0;
    color: #333;
}

.url-display {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 2rem;
}

.url-input {
    flex: 1;
    padding: 1rem;
    border: 2px solid #28a745;
    border-radius: 8px;
    background: white;
    color: #333;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
}

.btn-copy {
    flex-shrink: 0;
}

.result-actions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 2rem;
}

.result-info {
    text-align: left;
    background: white;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 1rem;
}

.result-info p {
    margin: 0.5rem 0;
    color: #666;
}

.result-actions {
    display: flex;
    justify-content: center;
    gap: 1rem;
}

/* =========================
   アニメーション
   ========================= */
@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.preset-notification {
    animation: fadeIn 0.3s ease-out;
}

/* =========================
   ワンクリック設定モーダル
   ========================= */
.one-click-modal,
.one-click-progress-modal,
.one-click-error-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.one-click-modal-backdrop,
.progress-modal-backdrop,
.error-modal-backdrop {
    position: absolute;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.one-click-modal-content,
.progress-modal-content,
.error-modal-content {
    position: relative;
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    animation: modalSlideIn 0.3s ease-out;
    margin: 2rem;
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-50px) scale(0.9);
        opacity: 0;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.modal-header,
.progress-header,
.error-header {
    padding: 2rem 2rem 1rem 2rem;
    text-align: center;
    border-bottom: 1px solid #e9ecef;
}

.modal-header h4,
.progress-header h4,
.error-header h4 {
    margin: 0 0 0.5rem 0;
    color: #333;
    font-size: 1.3rem;
}

.modal-subtitle {
    color: #666;
    font-size: 0.9rem;
}

.modal-body,
.progress-body,
.error-body {
    padding: 2rem;
}

.config-preview {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.preview-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.preview-item:last-child {
    margin-bottom: 0;
}

.preview-label {
    font-weight: 600;
    color: #333;
}

.preview-value {
    color: #007bff;
    font-weight: 500;
}

.auto-actions {
    border-top: 1px solid #e9ecef;
    padding-top: 1.5rem;
}

.auto-actions h5 {
    margin: 0 0 1rem 0;
    color: #333;
    font-size: 1rem;
}

.auto-actions ul {
    margin: 0;
    padding-left: 1.2rem;
    line-height: 1.6;
}

.auto-actions li {
    color: #28a745;
    margin-bottom: 0.5rem;
}

.modal-actions,
.error-actions {
    padding: 1rem 2rem 2rem 2rem;
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    border-top: 1px solid #e9ecef;
}

/* 進捗モーダル */
.progress-message {
    text-align: center;
    font-size: 1.1rem;
    color: #333;
    margin-bottom: 2rem;
}

.progress-bar-container {
    background: #e9ecef;
    border-radius: 10px;
    height: 12px;
    overflow: hidden;
    margin-bottom: 1rem;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #007bff, #28a745);
    border-radius: 10px;
    transition: width 0.3s ease;
}

.progress-percentage {
    text-align: center;
    font-weight: 600;
    color: #007bff;
    font-size: 1.2rem;
}

/* エラーモーダル */
.error-body p {
    margin-bottom: 1rem;
    line-height: 1.5;
}

.error-actions {
    justify-content: center;
}

/* =========================
   レスポンシブデザイン
   ========================= */
@media (max-width: 768px) {
    .panel-toggle-section {
        flex-direction: column;
        text-align: center;
        gap: 1rem;
    }
    
    .step-indicator {
        flex-direction: column;
        gap: 1rem;
    }
    
    .step-connector {
        width: 2px;
        height: 30px;
        margin: 0.5rem 0;
        margin-left: 0;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .api-grid,
    .template-options,
    .summary-grid {
        grid-template-columns: 1fr;
    }
    
    .url-display {
        flex-direction: column;
        align-items: stretch;
    }
    
    .result-actions-grid {
        grid-template-columns: 1fr;
    }
    
    .step-actions {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }
    
    .config-header button {
        position: static;
        margin-top: 1rem;
    }
}