*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --border: #e2e5ee;
  --text: #1a1d26;
  --text-sub: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #ef4444;
  --warning: #f59e0b;
  --success: #10b981;
  --info: #6366f1;
  --radius: 8px;
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); line-height: 1.6; }
.hidden { display: none !important; }
.screen { min-height: 100vh; }

/* === Auth === */
.auth-card { max-width: 400px; margin: 20vh auto; text-align: center; background: var(--card); padding: 48px 32px; border-radius: 16px; box-shadow: 0 4px 24px rgba(0,0,0,.08); }
.auth-card h1 { font-size: 32px; margin-bottom: 4px; }
.subtitle { color: var(--text-sub); margin-bottom: 32px; }
.auth-note { margin-top: 16px; font-size: 13px; color: var(--text-sub); }

/* === Buttons === */
.btn { display: inline-flex; align-items: center; justify-content: center; padding: 8px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); color: var(--text); font-size: 14px; cursor: pointer; transition: all .15s; }
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #dc2626; }
.btn-lg { padding: 12px 28px; font-size: 16px; }
.btn-sm { padding: 4px 12px; font-size: 13px; }
.btn-back { margin-bottom: 16px; }

/* === Header === */
header { display: flex; align-items: center; justify-content: space-between; padding: 12px 24px; background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.logo { font-size: 20px; cursor: pointer; }
.header-right { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--text-sub); }

/* === Main === */
main { max-width: 1100px; margin: 0 auto; padding: 24px; }

/* === Input Section === */
.input-section { background: var(--card); padding: 24px; border-radius: var(--radius); border: 1px solid var(--border); margin-bottom: 24px; }
.input-section h2 { font-size: 18px; margin-bottom: 16px; }
.form-row { display: flex; gap: 8px; }
.form-row input[type="url"] { flex: 1; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 15px; outline: none; }
.form-row input[type="url"]:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.form-options { display: flex; gap: 20px; margin-top: 12px; align-items: center; font-size: 14px; color: var(--text-sub); }
.form-options input[type="number"] { width: 80px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 4px; margin-left: 6px; }

.form-actions { display: flex; gap: 8px; margin-top: 16px; }
.preview-result { background: #f0f9ff; border: 1px solid #bae6fd; border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.preview-count { font-size: 20px; margin: 8px 0; }
.preview-strategies { margin-top: 8px; }
.strategy-list { display: flex; flex-wrap: wrap; gap: 8px; }
.strategy-item { display: inline-block; padding: 4px 10px; border-radius: 4px; font-size: 13px; background: #f0f0f0; color: var(--text-sub); }
.strategy-item.strategy-hit { background: #dbeafe; color: var(--primary); }
.preview-sample-list { max-height: 200px; overflow-y: auto; font-size: 13px; color: var(--text-sub); margin-top: 8px; border-top: 1px solid var(--border); padding-top: 8px; }
.preview-sample-list div { padding: 2px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* === History === */
.history-section { background: var(--card); padding: 24px; border-radius: var(--radius); border: 1px solid var(--border); }
.history-section h2 { font-size: 18px; margin-bottom: 16px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; padding: 10px 12px; border-bottom: 2px solid var(--border); font-weight: 600; color: var(--text-sub); font-size: 13px; }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
tr:hover td { background: #f9fafb; }
td a { color: var(--primary); text-decoration: none; }
td a:hover { text-decoration: underline; }

.loading { text-align: center; padding: 32px; color: var(--text-sub); }
.empty-msg { text-align: center; padding: 32px; color: var(--text-sub); }

/* === Badges === */
.badge { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 12px; font-weight: 600; }
.badge-queued { background: #e5e7eb; color: #374151; }
.badge-running { background: #dbeafe; color: #1d4ed8; }
.badge-completed { background: #d1fae5; color: #065f46; }
.badge-partial_failed { background: #fef3c7; color: #92400e; }
.badge-failed { background: #fee2e2; color: #991b1b; }

.severity-high { color: var(--danger); font-weight: 600; }
.severity-medium { color: var(--warning); font-weight: 600; }
.severity-low { color: var(--info); }
.severity-info { color: var(--text-sub); }

/* === Detail === */
#detail-header { margin-bottom: 20px; }
#detail-header h2 { font-size: 16px; word-break: break-all; margin-bottom: 8px; }
.detail-meta { display: flex; gap: 16px; align-items: center; font-size: 14px; color: var(--text-sub); }
.detail-ai-summary { margin-top: 8px; font-size: 13px; color: var(--text-sub); }
.detail-warnings { margin-top: 8px; }
.job-warning { font-size: 13px; color: #b45309; background: #fffbeb; border: 1px solid #fde68a; border-radius: var(--radius); padding: 6px 10px; margin-bottom: 4px; }

.detail-tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 16px; }
.tab { padding: 8px 20px; border: none; background: none; font-size: 14px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; color: var(--text-sub); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* === Issues === */
#issues-filters { display: flex; gap: 12px; margin-bottom: 16px; }
#issues-filters select { padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; }

.issue-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 8px; }
.issue-card-layout { display: flex; gap: 16px; }
.issue-card-left { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 90px; flex-shrink: 0; padding-top: 2px; }
.issue-card-right { flex: 1; min-width: 0; }
.source-badge { font-size: 11px; padding: 3px 10px; border-radius: 4px; background: #f3f4f6; color: var(--text-sub); font-weight: 600; white-space: nowrap; text-align: center; }
.source-badge-fixed_rule { background: #ede9fe; color: #5b21b6; }
.source-badge-gemini_text { background: #dbeafe; color: #1d4ed8; }
.source-badge-gemini_image { background: #fce7f3; color: #9d174d; }
.severity-badge { font-size: 11px; font-weight: 600; }
.issue-message { font-size: 14px; margin-bottom: 6px; line-height: 1.5; }
.issue-evidence { font-size: 13px; color: var(--text-sub); background: #f9fafb; padding: 10px 14px; border-radius: 4px; margin-top: 6px; white-space: pre-wrap; word-break: break-word; line-height: 1.6; border-left: 3px solid var(--border); }
.issue-suggestion { font-size: 13px; color: var(--success); margin-top: 8px; line-height: 1.5; }
.issue-url { font-size: 12px; margin-top: 8px; word-break: break-all; }
.issue-url a { color: var(--primary); text-decoration: none; }
.issue-url a:hover { text-decoration: underline; }

.ai-check-badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.ai-check-completed-clean { background: #d1fae5; color: #065f46; }
.ai-check-completed-issues { background: #fef3c7; color: #92400e; }
.ai-check-skipped { background: #e5e7eb; color: #374151; }
.ai-check-error { background: #fee2e2; color: #991b1b; }
.ai-check-missing { background: #eef2ff; color: #4338ca; }

.page-row td { vertical-align: top; }
.page-detail-row td { background: #fafbff; }
.page-detail-card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); padding: 16px; }
.page-detail-meta { display: grid; gap: 8px; font-size: 13px; color: var(--text-sub); margin-bottom: 12px; }
.page-detail-text-block { margin-top: 8px; }
.page-detail-label { font-size: 12px; font-weight: 600; color: var(--text-sub); margin-bottom: 6px; }
.page-detail-text { white-space: pre-wrap; word-break: break-word; font-size: 13px; line-height: 1.65; background: #f9fafb; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; max-height: 320px; overflow-y: auto; }

/* === Keywords Management === */
.keywords-section { background: var(--card); padding: 24px; border-radius: var(--radius); border: 1px solid var(--border); }
.keywords-section h2 { font-size: 18px; margin-bottom: 8px; }
.section-desc { font-size: 13px; color: var(--text-sub); margin-bottom: 16px; }
.prompt-section { background: var(--card); padding: 24px; border-radius: var(--radius); border: 1px solid var(--border); }
.prompt-section h2 { font-size: 18px; margin-bottom: 8px; }
#prompt-textarea { width: 100%; font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace; font-size: 13px; line-height: 1.6; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); resize: vertical; min-height: 300px; }
.prompt-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; }
.prompt-actions .text-sub { font-size: 12px; color: var(--text-sub); }
.keyword-add-form { background: #f9fafb; padding: 16px; border-radius: var(--radius); border: 1px solid var(--border); margin-bottom: 16px; }
.keyword-add-form .form-row { display: flex; gap: 8px; align-items: center; }
.keyword-add-form input[type="text"] { padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; }
.keyword-add-form select { padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; }
#keywords-table td:last-child { white-space: nowrap; }

/* === Progress bar === */
.progress-bar { display: inline-block; width: 100px; height: 6px; background: #e5e7eb; border-radius: 3px; overflow: hidden; vertical-align: middle; margin-right: 6px; }
.progress-bar-fill { height: 100%; background: var(--primary); border-radius: 3px; transition: width .3s; }

/* === Reference Documents === */
.refdocs-section { background: var(--card); padding: 24px; border-radius: var(--radius); border: 1px solid var(--border); }
.refdocs-section h2 { font-size: 18px; margin-bottom: 8px; }
.refdoc-upload-area { background: #f9fafb; padding: 20px; border-radius: var(--radius); border: 1px solid var(--border); margin-bottom: 20px; }
.refdoc-upload-area h3 { font-size: 15px; margin-bottom: 12px; }
.upload-tabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--border); }
.upload-tab { padding: 6px 16px; border: none; background: none; font-size: 13px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; color: var(--text-sub); }
.upload-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.upload-tab-content { padding-top: 8px; }
.upload-hint { font-size: 12px; color: var(--text-sub); margin-top: 8px; }
.refdoc-upload-area input[type="text"],
.refdoc-upload-area textarea { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; font-family: inherit; }
.refdoc-upload-area textarea { resize: vertical; min-height: 120px; }

.refdoc-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 8px; }
.refdoc-card-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.refdoc-card-info { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.refdoc-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.refdoc-badge-builtin { font-size: 11px; padding: 2px 8px; border-radius: 4px; background: #dbeafe; color: #1d4ed8; font-weight: 600; white-space: nowrap; }
.refdoc-badge-user { font-size: 11px; padding: 2px 8px; border-radius: 4px; background: #d1fae5; color: #065f46; font-weight: 600; white-space: nowrap; }
.refdoc-card-actions { display: flex; gap: 6px; flex-shrink: 0; }
.refdoc-card-meta { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--text-sub); margin-top: 6px; }
.refdoc-content-preview { margin-top: 10px; padding: 12px; background: #f9fafb; border-radius: var(--radius); font-size: 13px; white-space: pre-wrap; word-break: break-word; max-height: 400px; overflow-y: auto; line-height: 1.6; border: 1px solid var(--border); }

/* === Responsive === */
@media (max-width: 768px) {
  .form-row { flex-direction: column; }
  .form-options { flex-direction: column; gap: 8px; }
  .detail-meta { flex-direction: column; gap: 4px; }
  .issue-card-layout { flex-direction: column; gap: 8px; }
  .issue-card-left { flex-direction: row; min-width: auto; }
  header { padding: 12px 16px; }
  main { padding: 16px; }
}
