/* ── Reset & Variables ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green:       #3D7A5E;
  --green-mid:   #5E9E7E;
  --green-light: #EAF4EF;
  --green-dark:  #2A5A42;
  --border:      #C5DBD2;
  --bg:          #F0F5F2;
  --surface:     #FFFFFF;
  --text:        #1A1A1A;
  --muted:       #6B7280;
  --danger:      #C0392B;
  --warning:     #E07820;
  --sidebar-w:   220px;
  --header-h:    56px;
}

body {
  font-family: 'Noto Sans JP', 'Hiragino Kaku Gothic ProN', 'Meiryo', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

a { color: var(--green); text-decoration: none; }
a:hover { text-decoration: underline; }

input, select, textarea, button {
  font-family: inherit;
  font-size: 14px;
}

/* ── App Layout ────────────────────────────────────────────────────── */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--green-dark);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.app-header .logo {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.02em;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
.app-header .logo span { opacity: 0.7; font-weight: 400; }
.header-spacer { flex: 1; }
.header-user { font-size: 0.82rem; opacity: 0.85; }
.btn-logout {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  padding: 4px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: background 0.15s;
}
.btn-logout:hover { background: rgba(255,255,255,0.25); }

.app-body {
  display: flex;
  padding-top: var(--header-h);
  min-height: 100vh;
}

/* ── Sidebar ───────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: fixed;
  top: var(--header-h);
  left: 0;
  bottom: 0;
  overflow-y: auto;
  padding: 16px 0;
}

.sidebar-section {
  padding: 6px 16px 2px;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--text);
  font-size: 0.88rem;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.12s, border-color 0.12s;
  text-decoration: none;
}
.nav-item:hover { background: var(--green-light); text-decoration: none; }
.nav-item.active {
  background: var(--green-light);
  border-left-color: var(--green);
  color: var(--green-dark);
  font-weight: 600;
}
.nav-item svg { opacity: 0.6; flex-shrink: 0; }
.nav-item.active svg { opacity: 1; }

/* ── Main Content ──────────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 28px 32px;
  max-width: 1100px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.page-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--green-dark);
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ── Cards ─────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: 0 1px 6px rgba(61,122,94,0.06);
}
.card-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--green-dark);
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--green-light);
}

/* ── Form Elements ─────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(61,122,94,0.12);
}
.form-textarea { resize: vertical; min-height: 80px; }
.form-hint { font-size: 0.77rem; color: var(--muted); margin-top: 4px; }

/* ── Buttons ───────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 20px;
  border-radius: 8px;
  border: none;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  text-decoration: none;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--green-dark); text-decoration: none; }

.btn-secondary { background: var(--green-light); color: var(--green-dark); border: 1px solid var(--border); }
.btn-secondary:hover { background: #d6ecdf; text-decoration: none; }

.btn-danger { background: #fde8e8; color: var(--danger); border: 1px solid #f5b7b1; }
.btn-danger:hover { background: #fcd0d0; text-decoration: none; }

.btn-outline { background: transparent; color: var(--green); border: 1px solid var(--green); }
.btn-outline:hover { background: var(--green-light); text-decoration: none; }

.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-lg { padding: 12px 28px; font-size: 1rem; }
.btn-full { width: 100%; justify-content: center; }

/* ── Progress & Status ─────────────────────────────────────────────── */
.progress-box {
  background: var(--green-light);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
  margin-bottom: 20px;
}
.progress-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--green-dark);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.progress-steps { display: flex; flex-direction: column; gap: 8px; }
.progress-step {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--muted);
}
.progress-step.active { color: var(--green-dark); font-weight: 600; }
.progress-step.done   { color: var(--green); }
.step-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
}
.progress-step.active .step-dot { background: var(--green); animation: pulse 1s infinite; }
.progress-step.done .step-dot   { background: var(--green); }

@keyframes pulse {
  0%,100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.6; transform: scale(0.85); }
}

.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Alert ─────────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.88rem;
  margin-bottom: 16px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.alert-error   { background: #fde8e8; color: var(--danger);  border: 1px solid #f5b7b1; }
.alert-success { background: #e9f7ef; color: #1a6a3a;        border: 1px solid #a3d4b5; }
.alert-info    { background: #e8f0fe; color: #1a4a8a;        border: 1px solid #b0c8f0; }

/* ── People List (check form) ──────────────────────────────────────── */
.people-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.people-item {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: center;
}
.btn-remove-person {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  font-size: 1rem;
  line-height: 1;
}
.btn-remove-person:hover { color: var(--danger); background: #fde8e8; }

/* ── Score Badge ───────────────────────────────────────────────────── */
.score-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border-radius: 50%;
  font-size: 0.82rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.score-A { background: #1a7a4a; }
.score-B { background: #5E9E7E; }
.score-C { background: #d4a017; }
.score-D { background: #e07820; }
.score-E { background: #c0392b; }

.risk-chip {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  border: 1px solid;
}
.risk-高 { background:#fde8e8; color:#c0392b; border-color:#f5b7b1; }
.risk-中 { background:#fef3e8; color:#e07820; border-color:#ffd8a8; }
.risk-低 { background:#eaf4ef; color:#1a7a4a; border-color:#a9d4bc; }

/* ── History Table ─────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  background: var(--green-light);
  color: var(--green-dark);
  font-size: 0.78rem;
  font-weight: 700;
  text-align: left;
  padding: 10px 14px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--green-light);
  font-size: 0.85rem;
  vertical-align: middle;
}
tr:hover td { background: #fafcfb; }

.history-company { font-weight: 600; color: var(--text); }
.history-people  { font-size: 0.78rem; color: var(--muted); }
.history-date    { font-size: 0.78rem; color: var(--muted); white-space: nowrap; }
.history-user    { font-size: 0.78rem; color: var(--muted); }

/* ── Pagination ────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  justify-content: center;
}
.pagination-info { font-size: 0.82rem; color: var(--muted); }

/* ── Report Viewer ─────────────────────────────────────────────────── */
.report-frame-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-top: 20px;
}
.report-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--green-light);
  border-bottom: 1px solid var(--border);
}
.report-iframe {
  width: 100%;
  border: none;
  min-height: 80vh;
}

/* ── Network Visualization ─────────────────────────────────────────── */
.network-tree { display: flex; flex-direction: column; gap: 16px; }

.network-section-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--green-dark);
  padding: 8px 12px;
  background: var(--green-light);
  border-radius: 6px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.entity-list { display: flex; flex-direction: column; gap: 6px; padding-left: 12px; }
.entity-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: border-color 0.12s;
}
.entity-item:has(input:checked) { border-color: var(--green); background: var(--green-light); }
.entity-checkbox { margin-top: 2px; cursor: pointer; accent-color: var(--green); }
.entity-info { flex: 1; }
.entity-name { font-weight: 600; font-size: 0.88rem; }
.entity-role { font-size: 0.78rem; color: var(--muted); }
.entity-sub  { padding-left: 32px; }

.batch-check-bar {
  position: sticky;
  bottom: 0;
  background: var(--green-dark);
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 16px;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.15);
}
.batch-check-bar.hidden { display: none; }
.batch-count { font-size: 0.9rem; }
.batch-count strong { font-size: 1.1rem; }

/* ── Keyword Settings ──────────────────────────────────────────────── */
.keyword-category {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 14px;
  overflow: hidden;
}
.keyword-category-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--green-light);
  border-bottom: 1px solid var(--border);
}
.kw-cat-name { font-weight: 700; font-size: 0.9rem; flex: 1; }
.kw-cat-default { font-size: 0.72rem; color: var(--muted); }
.keyword-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 16px;
}
.keyword-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--green-light);
  color: var(--green-dark);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 0.8rem;
  font-weight: 600;
}
.keyword-chip.inactive { background: #f5f5f5; color: var(--muted); border-color: #ddd; }
.btn-remove-kw {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1;
  padding: 0 2px;
}
.btn-remove-kw:hover { color: var(--danger); }
.add-keyword-row {
  display: flex;
  gap: 8px;
  padding: 0 16px 12px;
}

/* ── Login Page ────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  background: var(--green-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px 40px 36px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.25);
}
.login-logo {
  text-align: center;
  margin-bottom: 28px;
}
.login-logo .brand { font-size: 1.5rem; font-weight: 700; color: var(--green-dark); }
.login-logo .sub   { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
.login-tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 24px;
}
.login-tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
}
.login-tab.active { color: var(--green-dark); border-bottom-color: var(--green); }
.login-panel { display: none; }
.login-panel.active { display: block; }

/* ── Stats Row ─────────────────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  text-align: center;
}
.stat-value { font-size: 1.8rem; font-weight: 700; color: var(--green-dark); }
.stat-label { font-size: 0.75rem; color: var(--muted); margin-top: 2px; }

/* ── Tabs (settings) ───────────────────────────────────────────────── */
.inner-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
}
.inner-tab {
  padding: 8px 18px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s;
}
.inner-tab.active { color: var(--green-dark); border-bottom-color: var(--green); }
.inner-panel { display: none; }
.inner-panel.active { display: block; }

/* ── Utility ───────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.flex   { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-4   { margin-top: 4px; }
.mt-8   { margin-top: 8px; }
.mt-16  { margin-top: 16px; }
.mb-8   { margin-bottom: 8px; }
.mb-16  { margin-bottom: 16px; }
.text-muted   { color: var(--muted); }
.text-small   { font-size: 0.8rem; }
.text-center  { text-align: center; }
.text-danger  { color: var(--danger); }
.text-success { color: #1a7a4a; }
.font-bold    { font-weight: 700; }
.w-full { width: 100%; }

@media (max-width: 768px) {
  .sidebar { display: none; }
  .main-content { margin-left: 0; padding: 16px; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .people-item { grid-template-columns: 1fr 1fr auto; }
}

/* ── Batch Check ────────────────────────────────────────────────────── */
.batch-import-row {
  display: flex;
  gap: 16px;
  align-items: stretch;
  flex-wrap: wrap;
}
.batch-import-card {
  flex: 1;
  min-width: 180px;
  background: var(--green-light);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.batch-import-icon  { font-size: 2rem; margin-bottom: 6px; }
.batch-import-label { font-weight: 600; font-size: 0.9rem; }
.batch-import-sep   { display: flex; align-items: center; color: var(--muted); font-size: 0.8rem; padding: 0 4px; }

.batch-item-list   { display: flex; flex-direction: column; gap: 6px; }
.batch-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg);
  border-radius: 6px;
  border: 1px solid var(--border);
}
.batch-item-type   { font-size: 1.1rem; flex-shrink: 0; }
.batch-item-label  { flex: 1; font-weight: 500; }
.batch-item-url    { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.batch-item-remove {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 0.9rem; padding: 2px 6px; border-radius: 4px;
}
.batch-item-remove:hover { background: #fde8e8; color: var(--danger); }

.batch-progress-bar-wrap {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 16px;
}
.batch-progress-bar {
  height: 100%;
  background: var(--green);
  border-radius: 4px;
  transition: width 0.3s ease;
}
.batch-progress-items { display: flex; flex-direction: column; gap: 6px; max-height: 360px; overflow-y: auto; }
.batch-progress-item  {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  background: var(--bg);
  border-radius: 6px;
  font-size: 0.85rem;
}
.bpi-icon   { font-size: 1rem; flex-shrink: 0; width: 20px; text-align: center; }
.bpi-label  { flex: 1; }
.bpi-status { flex-shrink: 0; font-weight: 600; }
.batch-progress-item[style*="cursor:pointer"]:hover { background: var(--green-light); }

.batch-result-table { width: 100%; border-collapse: collapse; }
.batch-result-table th, .batch-result-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.batch-result-table th { background: var(--green-light); font-weight: 600; color: var(--green-dark); }

.score-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 0.85rem;
}
.score-A { background: #d4edda; color: #1a5c30; }
.score-B { background: #c8e6c9; color: #2a7a4e; }
.score-C { background: #fff3cd; color: #856404; }
.score-D { background: #ffe0cc; color: #8a3800; }
.score-E { background: #f8d7da; color: #721c24; }

/* ── Modal ─────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-box {
  background: var(--surface);
  border-radius: 12px;
  padding: 28px;
  min-width: 360px;
  max-width: 480px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}
.modal-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 16px; color: var(--green-dark); }

.link-green { color: var(--green); text-decoration: underline; cursor: pointer; }
