/* ── Base ─────────────────────────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Sans", "Noto Sans JP", sans-serif;
    background: #f5f7fa;
    color: #1a1a2e;
    line-height: 1.5;
    padding-bottom: 40px;
}

header {
    background: linear-gradient(135deg, #1a1a2e, #16213e);
    color: #fff;
    padding: 20px 32px;
    position: relative;
}
header h1 { font-size: 1.5rem; font-weight: 700; }
header .subtitle { font-size: 0.85rem; opacity: 0.7; margin-top: 2px; }
header .header-links {
    position: absolute; right: 32px; top: 50%; transform: translateY(-50%);
    display: flex; gap: 16px;
}
header .back-link {
    color: #9bb5e8; text-decoration: none; font-size: 0.9rem;
}
header .back-link:hover { color: #fff; }

/* ── Tabs ────────────────────────────────────── */
.tabs {
    display: flex;
    background: #fff;
    border-bottom: 2px solid #e0e4ec;
    padding: 0 24px;
    overflow-x: auto;
}
.tab {
    padding: 12px 20px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 0.9rem;
    color: #666;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
    transition: all 0.15s;
}
.tab:hover { color: #1a1a2e; }
.tab.active {
    color: #1a1a2e;
    font-weight: 600;
    border-bottom-color: #4361ee;
}

.tab-content { display: none; padding: 24px; max-width: 1200px; margin: 0 auto; }
.tab-content.active { display: block; }

/* ── Toolbar ─────────────────────────────────── */
.toolbar {
    display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
    margin-bottom: 16px; padding: 12px 16px;
    background: #fff; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.toolbar label { font-size: 0.85rem; color: #555; display: flex; align-items: center; gap: 6px; }
.toolbar select, .toolbar input {
    padding: 6px 10px; border: 1px solid #d0d5dd; border-radius: 6px;
    font-size: 0.85rem; background: #f9fafb;
}
.btn {
    padding: 6px 16px; border: none; border-radius: 6px;
    background: #4361ee; color: #fff; cursor: pointer; font-size: 0.85rem;
    transition: background 0.15s;
}
.btn:hover { background: #3a56d4; }

/* ── Stats Grid ──────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
}
.stat-card {
    background: #fff; border-radius: 10px; padding: 20px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.stat-card h3 { font-size: 0.8rem; color: #888; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.stat-card .value { font-size: 2rem; font-weight: 700; color: #1a1a2e; }
.stat-card .sub { font-size: 0.8rem; color: #888; margin-top: 4px; }
.stat-card dl { margin-top: 8px; }
.stat-card dt { font-size: 0.75rem; color: #888; margin-top: 6px; }
.stat-card dd { font-size: 1.1rem; font-weight: 600; }

/* ── Table ────────────────────────────────────── */
.data-table {
    width: 100%; border-collapse: collapse; background: #fff;
    border-radius: 8px; overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    font-size: 0.85rem;
}
.data-table th {
    background: #f0f3f9; text-align: left; padding: 10px 12px;
    font-weight: 600; color: #444; border-bottom: 2px solid #e0e4ec;
    white-space: nowrap;
}
.data-table td {
    padding: 10px 12px; border-bottom: 1px solid #f0f0f0;
    vertical-align: top;
}
.data-table tr:hover td { background: #f8f9fc; }
.data-table .clickable { cursor: pointer; color: #4361ee; }
.data-table .clickable:hover { text-decoration: underline; }
.data-table .truncate { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.data-table .mono { font-family: "SF Mono", "Fira Code", monospace; font-size: 0.8rem; color: #666; }
.data-table .badge {
    display: inline-block; padding: 2px 8px; border-radius: 10px;
    font-size: 0.75rem; font-weight: 600;
}
.badge-pr { background: #e8f0fe; color: #1967d2; }
.badge-abs { background: #fef3e2; color: #b05c00; }
.badge-ok { background: #e6f4ea; color: #137333; }
.badge-err { background: #fce8e6; color: #c5221f; }

/* ── Pagination ──────────────────────────────── */
.pagination {
    display: flex; justify-content: center; align-items: center; gap: 12px;
    margin-top: 16px; font-size: 0.85rem;
}
.pagination button {
    padding: 6px 14px; border: 1px solid #d0d5dd; border-radius: 6px;
    background: #fff; cursor: pointer; font-size: 0.85rem;
}
.pagination button:disabled { opacity: 0.4; cursor: default; }
.pagination .page-info { color: #555; }

/* ── Modal ────────────────────────────────────── */
.modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 1000; }
.modal.hidden { display: none; }
.modal-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); }
.modal-content {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
    background: #fff; border-radius: 12px; padding: 28px;
    width: 90%; max-width: 900px; max-height: 85vh; overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-close {
    position: absolute; top: 12px; right: 16px;
    border: none; background: none; font-size: 1.5rem; cursor: pointer; color: #888;
}
.modal-close:hover { color: #333; }

/* ── Detail ───────────────────────────────────── */
.detail-section { margin-bottom: 20px; }
.detail-section h2 { font-size: 1.1rem; margin-bottom: 10px; border-bottom: 2px solid #e0e4ec; padding-bottom: 6px; }
.detail-section h3 { font-size: 0.95rem; margin: 12px 0 6px; color: #444; }
.detail-kv { display: grid; grid-template-columns: 160px 1fr; gap: 4px 12px; font-size: 0.85rem; }
.detail-kv dt { color: #888; font-weight: 500; }
.detail-kv dd { word-break: break-all; }
.detail-body {
    background: #f6f8fa; padding: 12px; border-radius: 6px;
    font-size: 0.85rem; line-height: 1.6; max-height: 300px; overflow-y: auto;
    white-space: pre-wrap; word-break: break-word;
}
.chunk-card {
    background: #f6f8fa; border: 1px solid #e0e4ec; border-radius: 8px;
    padding: 12px; margin-bottom: 10px;
}
.chunk-card .chunk-meta { font-size: 0.78rem; color: #888; margin-bottom: 6px; }
.chunk-card .chunk-text { font-size: 0.85rem; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.chunk-card .mesh-tags { margin-top: 6px; }
.chunk-card .mesh-tag {
    display: inline-block; padding: 1px 6px; margin: 2px;
    background: #e8f0fe; color: #1967d2; border-radius: 4px; font-size: 0.72rem;
}

/* ── Alert Summary Grid ──────────────────────── */
.alert-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.alert-summary-card {
    background: #fff; border-radius: 10px; padding: 16px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    border-left: 4px solid #e0e4ec;
}
.alert-card-error { border-left-color: #c5221f; }
.alert-card-warning { border-left-color: #e8a700; }
.alert-card-ok { border-left-color: #137333; }

.alert-site-name { font-weight: 700; font-size: 0.95rem; margin-bottom: 6px; }
.alert-counts { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; }
.alert-pr-count { font-size: 0.78rem; color: #888; }

.alert-badge-error {
    display: inline-block; padding: 2px 8px; border-radius: 10px;
    font-size: 0.75rem; font-weight: 600;
    background: #fce8e6; color: #c5221f;
}
.alert-badge-warning {
    display: inline-block; padding: 2px 8px; border-radius: 10px;
    font-size: 0.75rem; font-weight: 600;
    background: #fef7e0; color: #8a6d00;
}
.alert-badge-ok {
    display: inline-block; padding: 2px 8px; border-radius: 10px;
    font-size: 0.75rem; font-weight: 600;
    background: #e6f4ea; color: #137333;
}

.alert-total {
    font-size: 0.85rem; color: #666; margin-bottom: 16px;
    padding: 8px 16px; background: #fff; border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.alert-issues { display: flex; flex-wrap: wrap; gap: 4px; }

/* ── Action Panel ────────────────────────────── */
.action-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}
.action-card {
    background: #fff;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    border: 1px solid #e0e4ec;
}
.action-card-danger {
    border-color: #fecaca;
    background: #fef2f2;
}
.action-card-header h3 {
    font-size: 1rem;
    font-weight: 700;
    color: #1a1a2e;
    margin-bottom: 4px;
}
.action-desc {
    font-size: 0.82rem;
    color: #888;
    margin-bottom: 12px;
}
.action-controls {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}
.action-controls label {
    font-size: 0.82rem;
    color: #555;
    display: flex;
    align-items: center;
    gap: 4px;
}
.action-controls select,
.action-controls input[type="number"] {
    padding: 5px 8px;
    border: 1px solid #d0d5dd;
    border-radius: 6px;
    font-size: 0.82rem;
    background: #f9fafb;
}
.btn-danger {
    padding: 6px 16px;
    border: none;
    border-radius: 6px;
    background: #dc2626;
    color: #fff;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: background 0.15s;
}
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-danger:disabled { opacity: 0.6; cursor: not-allowed; }

/* ── Crawl Progress ─────────────────────────── */
.crawl-progress { margin-top: 12px; }
.crawl-progress.hidden { display: none; }
.progress-bar {
    height: 8px;
    background: #e0e4ec;
    border-radius: 4px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: #4361ee;
    border-radius: 4px;
    transition: width 0.5s ease;
    width: 0;
}
@keyframes progress-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}
.progress-fill[style*="width"] {
    animation: progress-pulse 2s infinite;
}
.progress-text {
    font-size: 0.82rem;
    color: #666;
    margin-top: 6px;
}

/* ── Toast ───────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s, transform 0.3s;
    z-index: 9999;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.hidden { display: none; }
.toast-success { background: #059669; color: #fff; display: block; }
.toast-error { background: #dc2626; color: #fff; display: block; }
.toast-info { background: #4361ee; color: #fff; display: block; }

/* ── Loading ──────────────────────────────────── */
.loading { text-align: center; padding: 40px; color: #888; }
.error-msg { text-align: center; padding: 20px; color: #c5221f; background: #fce8e6; border-radius: 8px; }

/* ── URL Details (Crawl Log) ─────────────────── */
.url-summary { margin-bottom: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.url-details-table { font-size: 0.82rem; }
.url-details-table td { padding: 6px 8px; }
.url-details-table th { padding: 6px 8px; font-size: 0.78rem; }
.url-cell { max-width: 250px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.url-cell a { color: #4361ee; text-decoration: none; }
.url-cell a:hover { text-decoration: underline; }

.text-ok { color: #059669; font-weight: 600; }
.text-err { color: #dc2626; font-weight: 600; }
.text-small { font-size: 0.75rem; color: #888; }

.badge-warn { background: #f59e0b; color: #fff; padding: 2px 8px; border-radius: 4px; font-size: 0.75rem; font-weight: 600; }
.badge-ok { background: #059669; color: #fff; }
.badge-abs { background: #6366f1; color: #fff; }
