/* ── 基礎 ─────────────────────────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
    background: #f5f5f5;
    color: #333;
    line-height: 1.6;
}

/* ── 導覽列 ───────────────────────────────────── */
.navbar {
    background: #2c3e50;
    color: #fff;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
}
.nav-brand a {
    color: #fff;
    text-decoration: none;
    font-size: 1.2rem;
    font-weight: 600;
}
.nav-links {
    display: flex;
    align-items: center;
    gap: 1rem;
}
.nav-links a { color: #ccc; text-decoration: none; }
.nav-links a:hover { color: #fff; }
.nav-user { color: #ecf0f1; font-size: 0.9rem; }
.nav-stats { color: #95a5a6; font-size: 0.8rem; font-weight: normal; margin-left: 0.3rem; }

/* ── 容器 ─────────────────────────────────────── */
.container {
    max-width: 960px;
    margin: 2rem auto;
    padding: 0 1rem;
}

/* ── 卡片 ─────────────────────────────────────── */
.card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}
.card h2 {
    margin-bottom: 1rem;
    color: #2c3e50;
    font-size: 1.25rem;
}

/* ── 按鈕 ─────────────────────────────────────── */
.btn {
    display: inline-block;
    padding: 0.5rem 1.2rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.95rem;
    text-decoration: none;
    transition: background 0.2s;
}
.btn-primary { background: #3498db; color: #fff; }
.btn-primary:hover { background: #2980b9; }
.btn-success { background: #27ae60; color: #fff; }
.btn-success:hover { background: #219a52; }
.btn-danger { background: #e74c3c; color: #fff; }
.btn-danger:hover { background: #c0392b; }
.btn-secondary { background: #95a5a6; color: #fff; }
.btn-secondary:hover { background: #7f8c8d; }
.btn-sm { padding: 0.3rem 0.8rem; font-size: 0.85rem; }
.btn-block { width: 100%; text-align: center; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ── 表單 ─────────────────────────────────────── */
.form-group {
    margin-bottom: 1rem;
}
.form-group label {
    display: block;
    margin-bottom: 0.3rem;
    font-weight: 500;
    color: #555;
}
.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.95rem;
    font-family: inherit;
}
.form-group textarea {
    resize: vertical;
    min-height: 200px;
}
.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 2px rgba(52,152,219,0.2);
}

/* ── 登入頁 ───────────────────────────────────── */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #2c3e50, #3498db);
}
.login-container {
    background: #fff;
    padding: 2rem;
    border-radius: 12px;
    width: 480px;
    max-width: 95vw;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
}
.login-container h1 {
    text-align: center;
    color: #2c3e50;
    margin-bottom: 0.5rem;
    font-size: 1.5rem;
}
.login-stats {
    text-align: center;
    color: #999;
    font-size: 0.8rem;
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
}
.login-stats-dot::before {
    content: "·";
    font-weight: bold;
}

/* ── OAuth 社群登入按鈕 ──────────────────────── */
.oauth-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin-bottom: 1rem;
}
.btn-oauth {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    padding: 0.65rem 1rem;
    border-radius: 4px;
    font-size: 0.95rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: box-shadow 0.2s, background 0.2s;
    border: 1px solid #ddd;
}
.btn-google {
    background: #fff;
    color: #444;
}
.btn-google:hover {
    background: #f8f8f8;
    box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}
.btn-facebook {
    background: #1877F2;
    color: #fff;
    border-color: #1877F2;
}
.btn-facebook:hover {
    background: #166FE5;
    box-shadow: 0 1px 4px rgba(24,119,242,0.3);
}
.btn-oauth-disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.btn-oauth-disabled:hover {
    box-shadow: none !important;
}
.oauth-divider {
    display: flex;
    align-items: center;
    margin: 1rem 0;
    color: #999;
    font-size: 0.85rem;
}
.oauth-divider::before,
.oauth-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: #ddd;
}
.oauth-divider span {
    padding: 0 0.8rem;
    white-space: nowrap;
}

/* ── Tab ──────────────────────────────────────── */
.tab-group {
    display: flex;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid #eee;
}
.tab {
    flex: 1;
    padding: 0.6rem;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 1rem;
    color: #999;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}
.tab.active {
    color: #3498db;
    border-bottom-color: #3498db;
}

/* ── 錯誤訊息 ─────────────────────────────────── */
.error-msg {
    background: #fee;
    color: #c0392b;
    padding: 0.6rem 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}
.success-msg {
    background: #efd;
    color: #27ae60;
    padding: 0.6rem 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

/* ── 自助檢查提示詞區塊 ──────────────────────── */
.prompt-block {
    position: relative;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 1rem;
    margin-top: 1rem;
}
.prompt-block pre {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 0.85rem;
    max-height: 300px;
    overflow-y: auto;
    font-family: "Noto Sans TC", monospace;
}
.copy-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
    background: #3498db;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}
.copy-btn:hover { background: #2980b9; }
.copy-btn.copied { background: #27ae60; }

/* ── 檢查結果標記 ─────────────────────────────── */
.marker-required { color: #e74c3c; font-weight: bold; }
.marker-confirm { color: #e67e22; font-weight: bold; }
.marker-optional { color: #3498db; font-weight: bold; }

/* ── 進度條 ───────────────────────────────────── */
.progress-container {
    margin: 1.5rem 0;
}
.progress-bar-bg {
    background: #e0e0e0;
    border-radius: 10px;
    height: 24px;
    overflow: hidden;
}
.progress-bar {
    background: linear-gradient(90deg, #3498db, #2ecc71);
    height: 100%;
    border-radius: 10px;
    transition: width 0.5s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 0.8rem;
    font-weight: 600;
    min-width: 40px;
}

.step-list {
    list-style: none;
    margin-top: 1.5rem;
}
.step-item {
    padding: 0.7rem 1rem;
    margin-bottom: 0.3rem;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: #f8f9fa;
}
.step-item.active { background: #ebf5fb; border-left: 3px solid #3498db; }
.step-item.done { background: #eafaf1; border-left: 3px solid #27ae60; }
.step-item.error { background: #fdedec; border-left: 3px solid #e74c3c; }
.step-icon { font-size: 1.1rem; width: 24px; text-align: center; }

/* ── 報告 ─────────────────────────────────────── */
.report-section {
    margin-bottom: 1.5rem;
}
.report-section h3 {
    color: #2c3e50;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid #eee;
    padding-bottom: 0.3rem;
}
.genogram-preview {
    text-align: center;
    margin: 1rem 0;
}
.genogram-preview img {
    max-width: 100%;
    border: 1px solid #ddd;
    border-radius: 4px;
}
.download-group {
    display: flex;
    gap: 1rem;
    margin: 1rem 0;
}

/* ── 歷史任務 ─────────────────────────────────── */
.task-table {
    width: 100%;
    border-collapse: collapse;
}
.task-table th, .task-table td {
    padding: 0.6rem 0.8rem;
    border-bottom: 1px solid #eee;
    text-align: left;
    font-size: 0.9rem;
}
.task-table th {
    background: #f8f9fa;
    color: #555;
    font-weight: 600;
}
.status-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 3px;
    font-size: 0.8rem;
    font-weight: 500;
}
.status-pending { background: #ffeaa7; color: #856404; }
.status-checking, .status-generating { background: #81ecec; color: #0c5460; }
.status-checked { background: #74b9ff; color: #004085; }
.status-completed { background: #55efc4; color: #155724; }
.status-failed { background: #fab1a0; color: #721c24; }

/* ── 回饋 ─────────────────────────────────────── */
.feedback-section {
    border-top: 2px solid #eee;
    padding-top: 1.5rem;
    margin-top: 1.5rem;
}

/* ── Loading spinner ──────────────────────────── */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #ddd;
    border-top-color: #3498db;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 可收合區塊 ───────────────────────────────── */
.collapsible {
    cursor: pointer;
    user-select: none;
}
.collapsible:hover { color: #3498db; }
.arrow {
    font-size: 0.75rem;
    margin-left: 0.3rem;
    display: inline-block;
    transition: transform 0.2s;
}

/* ── 編輯器 ───────────────────────────────────── */
.editor-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid #ddd;
    margin-bottom: 0;
}
.editor-tab {
    padding: 0.5rem 1.2rem;
    border: none;
    background: #f0f0f0;
    cursor: pointer;
    font-size: 0.9rem;
    color: #666;
    border-radius: 6px 6px 0 0;
    margin-bottom: -2px;
    border-bottom: 2px solid #ddd;
    transition: all 0.2s;
}
.editor-tab.active {
    background: #fff;
    color: #2c3e50;
    font-weight: 600;
    border-bottom-color: #fff;
    border-left: 2px solid #ddd;
    border-right: 2px solid #ddd;
    border-top: 2px solid #3498db;
}
.editor-pane {}
.editor-pane textarea {
    width: 100%;
    padding: 1rem;
    border: 1px solid #ddd;
    border-top: none;
    border-radius: 0 0 6px 6px;
    font-size: 0.95rem;
    font-family: "Noto Sans TC", sans-serif;
    line-height: 1.8;
    resize: vertical;
    min-height: 350px;
}
.editor-pane textarea:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 2px rgba(52,152,219,0.15);
}
.editor-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0;
    font-size: 0.85rem;
}
.editor-actions {
    display: flex;
    gap: 0.8rem;
    margin-top: 0.5rem;
}
.preview-box {
    padding: 1rem;
    border: 1px solid #ddd;
    border-top: none;
    border-radius: 0 0 6px 6px;
    background: #fafafa;
    min-height: 350px;
    max-height: 600px;
    overflow-y: auto;
    font-size: 0.95rem;
    line-height: 1.8;
    font-family: "Noto Sans TC", sans-serif;
}

/* ── 輔助 ─────────────────────────────────────── */
.text-center { text-align: center; }
.text-muted { color: #999; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.inline-form {
    display: flex;
    gap: 0.5rem;
    align-items: end;
}
.inline-form .form-group { flex: 1; margin-bottom: 0; }

/* ── 編輯工具列 ──────────────────────────────────── */
.edit-toolbar { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }

/* ── 資料 Tab ────────────────────────────────────── */
.data-tabs {
    display: flex;
    border-bottom: 2px solid #ddd;
    margin-bottom: 0;
}
.data-tab {
    padding: 0.5rem 1.2rem;
    border: none;
    background: #f0f0f0;
    cursor: pointer;
    font-size: 0.9rem;
    color: #666;
    border-radius: 6px 6px 0 0;
    margin-bottom: -2px;
    border-bottom: 2px solid #ddd;
    transition: all 0.2s;
}
.data-tab.active {
    background: #fff;
    color: #2c3e50;
    font-weight: 600;
    border-bottom-color: #fff;
    border-left: 2px solid #ddd;
    border-right: 2px solid #ddd;
}
.data-tab.tab-persons.active { border-top: 3px solid #3498db; }
.data-tab.tab-relationships.active { border-top: 3px solid #27ae60; }
.data-tab.tab-emotional.active { border-top: 3px solid #e67e22; }
.data-tab.tab-households.active { border-top: 3px solid #8e44ad; }

/* ── 資料面板 ────────────────────────────────────── */
.data-panel { display: none; padding: 1rem 0; }
.data-panel.active { display: block; }

/* ── 可編輯表格 ──────────────────────────────────── */
.table-scroll { overflow-x: auto; }
.edit-table { width: 100%; border-collapse: collapse; }
.edit-table th {
    background: #f0f4f8;
    padding: 0.6rem 0.5rem;
    font-size: 0.85rem;
    text-align: left;
    border-bottom: 2px solid #ccc;
    white-space: nowrap;
}
.edit-table td { padding: 0.5rem 0.4rem; border-bottom: 2px solid #e0e0e0; }
.edit-table input,
.edit-table select {
    width: 100%;
    padding: 0.4rem;
    border: 1px solid #ddd;
    border-radius: 3px;
    font-size: 0.85rem;
    font-family: inherit;
}
.edit-table input:focus,
.edit-table select:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 1px rgba(52,152,219,0.2);
}
.edit-table input[type="number"] { width: 60px; }
.edit-table select { min-width: 70px; }
.btn-regen { font-size: 1rem; padding: 0.6rem 1.5rem; }
.edit-table input[type="checkbox"] { width: auto; transform: scale(1.3); cursor: pointer; }
.edit-table td.col-notes input { min-width: 120px; }
.btn-delete {
    color: #e74c3c;
    cursor: pointer;
    border: none;
    background: none;
    font-size: 0.85rem;
    padding: 0.2rem 0.5rem;
}
.btn-delete:hover { text-decoration: underline; }

/* ── 操作按鈕（確認 + 刪除）────────────────────────── */
.col-actions { white-space: nowrap; text-align: center; }
.btn-action {
    display: inline-block;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.8rem;
    padding: 0.25rem 0.6rem;
    margin: 0 2px;
    transition: background 0.2s;
}
.btn-action-confirm { background: #27ae60; color: #fff; }
.btn-action-confirm:hover { background: #219a52; }
.btn-action-delete { background: #e74c3c; color: #fff; }
.btn-action-delete:hover { background: #c0392b; }

/* ── 新增行高亮 ──────────────────────────────────────── */
.row-new { background: #fef9e7; }

/* ── 多選 Tag ────────────────────────────────────── */
.multi-select-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    align-items: center;
}
.multi-tag {
    display: inline-flex;
    align-items: center;
    background: #e8f4fd;
    color: #2c3e50;
    padding: 0.15rem 0.5rem;
    border-radius: 3px;
    font-size: 0.8rem;
}
.multi-tag-remove {
    cursor: pointer;
    color: #e74c3c;
    margin-left: 0.2rem;
    font-weight: bold;
}
.multi-add-select {
    padding: 0.2rem;
    font-size: 0.8rem;
    border: 1px dashed #aaa;
    border-radius: 3px;
    color: #888;
    min-width: 100px;
}

/* ── 驗證結果 ────────────────────────────────────── */
.warning-msg {
    background: #fff3cd;
    color: #856404;
    padding: 0.6rem 1rem;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}
.info-msg {
    background: #d1ecf1;
    color: #0c5460;
    padding: 0.6rem 1rem;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}
.warning-msg ul, .info-msg ul, .error-msg ul {
    margin: 0.3rem 0 0 1.2rem;
    padding: 0;
}
.warning-msg li, .info-msg li, .error-msg li {
    margin-bottom: 0.2rem;
}

/* ── 狀態：editing ───────────────────────────────── */
.status-editing { background: #dfe6e9; color: #2d3436; }

/* ── 管理後台 ─────────────────────────────────────── */
.nav-admin { color: #f39c12 !important; font-weight: 600; }
.nav-admin:hover { color: #e67e22 !important; }

.admin-header {
    margin-bottom: 1.5rem;
}
.admin-header h1 {
    color: #2c3e50;
    font-size: 1.5rem;
    margin-bottom: 0.8rem;
}
.admin-nav {
    display: flex;
    gap: 0;
    border-bottom: 2px solid #ddd;
}
.admin-nav-link {
    padding: 0.5rem 1.2rem;
    text-decoration: none;
    color: #666;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    font-size: 0.95rem;
    transition: all 0.2s;
}
.admin-nav-link:hover { color: #2c3e50; }
.admin-nav-link.active {
    color: #2c3e50;
    font-weight: 600;
    border-bottom-color: #3498db;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stats-grid-sm {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
}
.stat-card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    padding: 1rem;
    text-align: center;
}
.stat-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: #2c3e50;
}
.stat-label {
    font-size: 0.8rem;
    color: #999;
    margin-top: 0.2rem;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.admin-table th {
    background: #f0f4f8;
    padding: 0.5rem;
    text-align: left;
    border-bottom: 2px solid #ddd;
    white-space: nowrap;
    font-weight: 600;
    color: #555;
}
.admin-table td {
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid #eee;
}
.admin-table tr:hover td { background: #f8f9fa; }

.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 500;
}
.badge-admin { background: #ffeaa7; color: #856404; }
.badge-user { background: #dfe6e9; color: #636e72; }
.badge-on { background: #55efc4; color: #155724; }
.badge-off { background: #fab1a0; color: #721c24; }

.user-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.settings-grid {
    display: grid;
    gap: 0.8rem;
}
.setting-row {
    display: flex;
    align-items: center;
    gap: 1rem;
}
.setting-row > label:first-child {
    min-width: 160px;
    font-weight: 500;
    color: #555;
}
.toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}
.toggle-label {
    font-size: 0.85rem;
    color: #666;
}

.pricing-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1rem;
}
.pricing-col h3 {
    font-size: 0.9rem;
    color: #555;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid #eee;
    padding-bottom: 0.3rem;
}

/* ── 通知 badge ──────────────────────────────────── */
.notif-badge {
    display: inline-block;
    background: #e74c3c;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    line-height: 18px;
    text-align: center;
    border-radius: 9px;
    padding: 0 4px;
    margin-left: 4px;
    vertical-align: middle;
}
.badge-info { background: #d1ecf1; color: #0c5460; }
.badge-warning { background: #fff3cd; color: #856404; }
.badge-warning-solid { background: #f39c12; color: #fff; }
