:root {
  --primary: #475569;
  --primary-dark: #334155;
  --accent: #3b82f6;
  --bg: #e8e8e6;
  --panel: #ffffff;
  --panel-elev: #fbfbfa;
  --border: #d6d3d1;
  --border-soft: #e7e5e4;
  --text: #1c1917;
  --muted: #78716c;
  --warn-bg: #fef9e7;
  --warn-border: #d97706;
  --good: #15803d;
  --mid: #b45309;
  --low: #a8a29e;
  --danger: #b91c1c;
  --sidebar-w: 280px;
  --sidebar-bg: #1c1917;
  --sidebar-fg: #e7e5e4;
  --sidebar-muted: #a8a29e;
  --sidebar-border: #292524;
  --shadow-sm: 0 1px 2px rgba(28, 25, 23, 0.04);
  --shadow-md: 0 2px 8px rgba(28, 25, 23, 0.06);
}

[data-theme="dark"] {
  --bg: #1c1917;
  --panel: #292524;
  --panel-elev: #1f1d1c;
  --border: #44403c;
  --border-soft: #292524;
  --text: #f5f5f4;
  --muted: #a8a29e;
  --warn-bg: #3f2e0c;
  --warn-border: #fbbf24;
  --good: #4ade80;
  --mid: #fbbf24;
  --low: #78716c;
  --danger: #fca5a5;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
}
[data-theme="dark"] tr.saved-row { background: #3a2f12; }
[data-theme="dark"] .row-actions button.active { background: #3a2f12; color: #fde68a; border-color: #78350f; }
[data-theme="dark"] .row-actions button.dnc-on { background: #3f1818; color: #fca5a5; border-color: #7f1d1d; }
[data-theme="dark"] .ai-comment { background: #1f2937; border-left-color: #60a5fa; }
[data-theme="dark"] .strategy-card { background: #1f1d1c; border-left-color: #60a5fa; }
[data-theme="dark"] .icp-card { background: #1f1d1c; }
[data-theme="dark"] .modal { background: rgba(0,0,0,0.75); }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============ Sidebar ============ */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.25s ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
}

.sidebar-header .tag {
  font-size: 11px;
  background: rgba(255,255,255,0.1);
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 6px;
  vertical-align: middle;
  font-weight: normal;
}

.sidebar-close {
  display: none;
  background: transparent;
  color: var(--sidebar-fg);
  border: 0;
  font-size: 24px;
  padding: 0 4px;
  cursor: pointer;
}

.sidebar-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--sidebar-border);
}

.side-label {
  display: block;
  font-size: 11px;
  color: var(--sidebar-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.side-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  user-select: none;
}

.side-head .badge {
  background: var(--primary);
  color: white;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
}

.side-body {
  font-size: 12px;
}

.collapsible[data-open="false"] .side-body,
.collapsible[data-open="false"] .side-btn { display: none; }

.side-btn {
  display: block;
  width: 100%;
  background: rgba(255,255,255,0.06);
  color: var(--sidebar-fg);
  border: 1px solid var(--sidebar-border);
  padding: 8px 10px;
  margin-top: 6px;
  font-size: 12px;
  border-radius: 6px;
  cursor: pointer;
  text-align: center;
  font-family: inherit;
}

.side-btn:hover { background: rgba(255,255,255,0.12); }
.side-btn.danger { color: #fca5a5; }
.side-btn.danger:hover { background: rgba(220,38,38,0.2); }

.file-label { display: block; }
.file-label input { display: none; }

#search-box, .sidebar input[type=text], .sidebar input[type=password], .sidebar select, .sidebar textarea {
  width: 100%;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--sidebar-border);
  color: var(--sidebar-fg);
  padding: 8px 10px;
  font-size: 13px;
  border-radius: 6px;
  font-family: inherit;
  margin-bottom: 6px;
}

.sidebar textarea { resize: vertical; }
#search-box::placeholder, .sidebar input::placeholder, .sidebar textarea::placeholder { color: var(--sidebar-muted); }
.sidebar select option { color: var(--text); }

.dash-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.dash-card {
  background: rgba(255,255,255,0.06);
  padding: 8px 10px;
  border-radius: 6px;
}

.dash-label {
  font-size: 10px;
  color: var(--sidebar-muted);
  text-transform: uppercase;
}

.dash-value {
  font-size: 20px;
  font-weight: 700;
  margin-top: 2px;
}

.side-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--sidebar-border);
  gap: 8px;
}

.side-item:last-child { border-bottom: 0; }
.side-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-item .phone { font-family: ui-monospace, monospace; font-size: 11px; color: var(--sidebar-muted); }
.side-item .x { background: transparent; border: 0; color: var(--sidebar-muted); cursor: pointer; font-size: 14px; padding: 0 4px; }
.side-item .x:hover { color: #fca5a5; }

.kv {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  font-size: 12px;
}

.empty {
  color: var(--sidebar-muted);
  font-size: 12px;
  font-style: italic;
  padding: 4px 0;
}

.sidebar-footer {
  margin-top: auto;
  padding: 14px 20px;
  border-top: 1px solid var(--sidebar-border);
  font-size: 11px;
  color: var(--sidebar-muted);
}

.sidebar-footer a { color: var(--sidebar-muted); }

.sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 99;
  background: var(--sidebar-bg);
  color: white;
  border: 0;
  width: 40px;
  height: 40px;
  font-size: 20px;
  border-radius: 6px;
  cursor: pointer;
}

/* ============ Main ============ */
.main-content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px;
}

header {
  background: var(--panel);
  color: var(--text);
  padding: 24px 0;
  border-bottom: 1px solid var(--border-soft);
}

header .lead { margin: 0; font-size: 14px; color: var(--muted); }
header .lead strong { color: var(--text); }

.notice {
  background: var(--warn-bg);
  border-left: 3px solid var(--warn-border);
  padding: 14px 20px;
  margin: 20px auto;
  font-size: 13px;
  border-radius: 8px;
  color: #78350f;
}

.notice ul { margin: 6px 0 0 0; padding-left: 18px; }

.panel {
  background: var(--panel);
  border-radius: 12px;
  padding: 22px 26px;
  margin: 16px 0;
  box-shadow: var(--shadow-sm);
}

.panel h2 {
  margin: 0 0 16px 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.01em;
}

textarea, input[type="text"], select {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--panel-elev);
  color: var(--text);
  transition: border-color 0.15s, background 0.15s;
}

textarea:focus, input[type="text"]:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--panel);
}

textarea { resize: vertical; }

button {
  background: var(--text);
  color: var(--panel);
  border: 0;
  padding: 11px 22px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 12px;
  font-family: inherit;
  transition: opacity 0.15s, transform 0.05s;
}

button:hover { opacity: 0.85; }
button:active { transform: translateY(1px); }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }

.samples {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.sample-label { font-size: 12px; color: var(--muted); }

.sample-btn {
  background: var(--panel-elev);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  margin-top: 0;
  border-radius: 999px;
}

.sample-btn:hover { background: var(--bg); border-color: var(--muted); opacity: 1; }

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.filters label {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  color: var(--muted);
  gap: 4px;
}

#icp-display {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.icp-card {
  background: var(--panel-elev);
  border: 1px solid var(--border-soft);
  padding: 14px 16px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.6;
}

.icp-card .label {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 6px;
  letter-spacing: 0.04em;
}

.classification-main { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.classification-main .label { font-size: 11px; color: var(--muted); font-weight: 600; letter-spacing: 0.04em; }
.category-name { font-size: 22px; font-weight: 700; color: var(--text); }
.confidence { font-size: 11px; padding: 3px 10px; border-radius: 999px; font-weight: 600; color: white; }
.confidence.high { background: var(--good); }
.confidence.medium { background: var(--mid); }
.confidence.low { background: var(--low); }
.classification-alt { margin-top: 10px; font-size: 12px; color: var(--muted); }

.strategy-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.strategy-card {
  background: var(--panel-elev);
  border: 1px solid var(--border-soft);
  border-left: 3px solid var(--accent);
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.6;
}
.strategy-card.warn {
  border-left-color: var(--danger);
}
.strategy-card .label {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.strategy-summary {
  margin-top: 14px;
  padding: 14px 16px;
  background: var(--bg);
  border-radius: 10px;
  font-size: 13px;
  color: var(--text);
}

.strategy-details {
  margin-top: 12px;
}
.strategy-details summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--accent);
  padding: 6px 0;
  user-select: none;
}
.strategy-details summary:hover { text-decoration: underline; }

.onboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  margin-top: 14px;
}
.onboard-card {
  background: var(--panel-elev);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: 18px 18px 16px;
  position: relative;
}
.onboard-num {
  position: absolute;
  top: 12px;
  right: 14px;
  font-size: 28px;
  font-weight: 700;
  color: var(--border);
  line-height: 1;
}
.onboard-card h3 {
  margin: 0 0 6px 0;
  font-size: 15px;
  font-weight: 600;
}
.onboard-card p {
  margin: 0 0 12px 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}
.onboard-btn {
  background: var(--text);
  color: var(--panel);
  border: 0;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  margin: 4px 4px 0 0;
  text-decoration: none;
  display: inline-block;
  font-family: inherit;
}
.onboard-btn.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.onboard-btn:hover { opacity: 0.85; }

.samples-toggle {
  margin-top: 14px;
}
.samples-toggle summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--muted);
  padding: 6px 0;
  list-style: none;
  user-select: none;
}
.samples-toggle summary::before {
  content: '▶ ';
  font-size: 9px;
  transition: transform 0.15s;
  display: inline-block;
}
.samples-toggle[open] summary::before {
  content: '▼ ';
}
.samples-toggle .samples {
  margin-top: 8px;
}

.setup-panel { padding: 24px 26px; }

.setup-group {
  margin-bottom: 22px;
  padding-bottom: 22px;
  border-bottom: 1px dashed var(--border-soft);
}
.setup-group:last-child { border-bottom: 0; margin-bottom: 0; padding-bottom: 0; }

.setup-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.setup-cta {
  text-align: center;
  padding-top: 14px;
}

.big-cta {
  width: 100%;
  font-size: 17px;
  padding: 18px 24px;
  background: linear-gradient(135deg, #2563eb, #1e40af);
  color: white;
  border-radius: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.3);
  transition: transform 0.1s, box-shadow 0.15s;
  margin-top: 0;
}
.big-cta:hover {
  background: linear-gradient(135deg, #1e40af, #1e3a8a);
  opacity: 1;
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.4);
  transform: translateY(-1px);
}
.big-cta:active { transform: translateY(1px); }
.big-cta.searching {
  background: linear-gradient(135deg, #dc2626, #991b1b);
  box-shadow: 0 4px 14px rgba(220, 38, 38, 0.3);
  animation: searchPulse 2s ease-in-out infinite;
}
.big-cta.searching:hover {
  background: linear-gradient(135deg, #991b1b, #7f1d1d);
}
@keyframes searchPulse {
  0%, 100% { box-shadow: 0 4px 14px rgba(220, 38, 38, 0.3); }
  50% { box-shadow: 0 6px 22px rgba(220, 38, 38, 0.55); }
}

.cta-sub {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.results-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.results-actions button { margin-top: 0; }

button.small { font-size: 12px; padding: 6px 12px; }

.region-btn {
  width: 100%;
  background: var(--panel-elev);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 9px 12px;
  margin-top: 4px;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
}
.region-btn:hover { background: var(--bg); opacity: 1; }

.region-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.region-chip {
  background: #dbeafe;
  color: #1e40af;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.region-chip.pref { background: #dcfce7; color: #166534; font-weight: 600; }
.region-chip .x { background: transparent; border: 0; color: inherit; cursor: pointer; padding: 0; margin: 0; font-size: 13px; line-height: 1; }

.region-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  align-items: center;
}
.region-toolbar input { flex: 1; }

.region-tree {
  max-height: 55vh;
  overflow-y: auto;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 8px;
  background: var(--panel-elev);
}
.region-pref {
  border-bottom: 1px solid var(--border-soft);
  padding: 4px 0;
}
.region-pref:last-child { border-bottom: 0; }
.region-pref-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  user-select: none;
}
.region-pref-head:hover { background: var(--bg); border-radius: 4px; }
.region-pref-head .toggle { font-size: 11px; color: var(--muted); width: 12px; }
.region-pref-head .count { font-size: 11px; color: var(--muted); font-weight: normal; margin-left: auto; }
.region-cities {
  display: none;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 0 8px 26px;
}
.region-pref[data-open="true"] .region-cities { display: flex; }
.region-pref[data-open="true"] .toggle::before { content: "▼"; }
.region-pref[data-open="false"] .toggle::before { content: "▶"; }
.region-city {
  font-size: 12px;
  background: var(--panel);
  border: 1px solid var(--border-soft);
  padding: 3px 10px;
  border-radius: 999px;
  cursor: pointer;
  user-select: none;
}
.region-city:hover { background: var(--bg); }
.region-city.selected { background: #dbeafe; color: #1e40af; border-color: #93c5fd; font-weight: 600; }
.region-pref-checkbox.selected-all { background: #16a34a; color: white; border-color: #16a34a; }

.action-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}
.action-row button { margin-top: 0; }

.discovery-progress {
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--panel-elev);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.discovery-progress::before {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  flex-shrink: 0;
}
.discovery-progress.done::before {
  content: "✓";
  border: 0;
  color: var(--good);
  width: auto; height: auto;
  font-size: 16px;
  animation: none;
}
.discovery-progress.error::before {
  content: "⚠";
  border: 0;
  color: var(--danger);
  width: auto; height: auto;
  font-size: 16px;
  animation: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

.chat-log {
  background: var(--panel-elev);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 14px;
  max-height: 50vh;
  min-height: 280px;
  overflow-y: auto;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-msg {
  display: flex;
  gap: 8px;
  font-size: 13px;
  line-height: 1.6;
}
.chat-msg .avatar {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  background: var(--border);
}
.chat-msg.user .avatar { background: var(--accent); color: white; }
.chat-msg.assistant .avatar { background: var(--text); color: var(--panel); }
.chat-msg .bubble {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  padding: 10px 12px;
  border-radius: 10px;
  flex: 1;
  white-space: pre-wrap;
}
.chat-msg.user .bubble { background: #eff6ff; border-color: #bfdbfe; }
.chat-msg.loading .bubble::after {
  content: '考え中…';
  color: var(--muted);
  font-style: italic;
}
.chat-input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.chat-input-row textarea {
  flex: 1;
}
.chat-input-row button {
  margin-top: 0;
  align-self: stretch;
  padding: 0 20px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-grid label {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  color: var(--muted);
  gap: 4px;
}
.form-grid label.full { grid-column: 1 / -1; }
.form-grid input, .form-grid select, .form-grid textarea {
  width: 100%;
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-elev);
  color: var(--text);
}

.followup-item, .profile-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--sidebar-border);
  gap: 8px;
  font-size: 12px;
}
.followup-item:last-child, .profile-item:last-child { border: 0; }
.followup-when {
  font-size: 11px;
  color: var(--sidebar-muted);
  margin-top: 2px;
}
.followup-when.overdue { color: #fca5a5; font-weight: 600; }
.profile-actions { display: flex; gap: 4px; }
.profile-actions button {
  background: transparent;
  border: 0;
  color: var(--sidebar-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 0 4px;
  margin: 0;
}
.profile-actions button:hover { color: var(--sidebar-fg); opacity: 1; }
.profile-item.active { color: #60a5fa; font-weight: 600; }

.ai-comment {
  font-size: 12px;
  color: var(--text);
  margin-bottom: 6px;
  padding: 6px 10px;
  background: var(--panel-elev);
  border-left: 2px solid var(--accent);
  border-radius: 6px;
  line-height: 1.5;
}
.ai-reason {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
}

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }

th, td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}

th {
  background: var(--panel-elev);
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

tbody tr { transition: background 0.1s; }
tbody tr:hover { background: var(--panel-elev); }
tr.saved-row { background: #fffaeb; }
tr.dnc-row { opacity: 0.4; }
tr.pending-row { opacity: 0.7; background: linear-gradient(90deg, var(--panel) 0%, #fef3c7 50%, var(--panel) 100%); background-size: 200% 100%; animation: pendingPulse 2s linear infinite; }
@keyframes pendingPulse { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.score {
  display: inline-block;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 12px;
  color: white;
  min-width: 42px;
  text-align: center;
}

.score.good { background: var(--good); }
.score.mid { background: var(--mid); }
.score.low { background: var(--low); }

.phone { font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.phone a { color: var(--accent); text-decoration: none; font-weight: 500; }
.phone a:hover { text-decoration: underline; }
.phone-empty { color: var(--muted); font-style: italic; font-size: 11px; }

.reasoning { font-size: 11px; color: var(--muted); max-width: 260px; }

.row-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.row-actions button {
  background: var(--panel);
  color: var(--muted);
  border: 1px solid var(--border-soft);
  padding: 4px 7px;
  font-size: 14px;
  margin: 0;
  border-radius: 6px;
  min-width: 30px;
  line-height: 1;
  font-weight: normal;
}
.row-actions button:hover { background: var(--panel-elev); color: var(--text); opacity: 1; }
.row-actions button.active { background: #fef9e7; color: #92400e; border-color: #fde68a; }
.row-actions button.dnc-on { background: #fef2f2; color: var(--danger); border-color: #fecaca; }

.status-select {
  font-size: 12px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  font-family: inherit;
}

.view-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border-soft);
  padding-bottom: 0;
}
.view-tab {
  background: transparent;
  color: var(--muted);
  border: 0;
  padding: 8px 14px;
  font-size: 13px;
  border-radius: 0;
  margin: 0;
  border-bottom: 2px solid transparent;
  font-weight: 500;
}
.view-tab:hover { background: transparent; color: var(--text); opacity: 1; }
.view-tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.muted { color: var(--muted); font-weight: normal; font-size: 13px; }

footer {
  margin: 48px 0 0 0;
  padding: 24px 0;
  border-top: 1px solid var(--border-soft);
  font-size: 12px;
  color: var(--muted);
}

footer a { color: var(--accent); }

/* ============ Modal ============ */
.modal[hidden] { display: none !important; }
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}

.modal-content {
  background: var(--panel);
  padding: 24px;
  border-radius: 14px;
  max-width: 500px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(28,25,23,0.18);
}

.modal-content.wide { max-width: 720px; }

.modal-content h3 { margin: 0 0 14px 0; font-size: 16px; font-weight: 600; }

.modal-content pre {
  background: var(--panel-elev);
  border: 1px solid var(--border-soft);
  padding: 14px;
  border-radius: 10px;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.7;
  max-height: 400px;
  overflow-y: auto;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 14px;
}

/* ============ Responsive ============ */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: 4px 0 16px rgba(0,0,0,0.2);
    width: min(280px, 85vw);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: block; }
  .sidebar-toggle { display: flex; align-items: center; justify-content: center; }
  .main-content { margin-left: 0; padding-top: 56px; }
  .container { padding: 0 14px; }
  header { padding: 14px 0; }
  header .lead { font-size: 13px; }
  .notice { padding: 12px 14px; font-size: 12px; margin: 14px auto; }
  .notice ul { padding-left: 16px; }
  .panel { padding: 14px 14px; margin: 10px 0; }
  .panel h2 { font-size: 15px; margin-bottom: 10px; }
  textarea, input[type="text"], select { font-size: 16px; }  /* iOS自動ズーム防止(16px) */
  button { padding: 12px 16px; font-size: 14px; }
  .sample-btn { padding: 6px 10px; font-size: 12px; }
  .filters { grid-template-columns: 1fr 1fr; gap: 8px; }
  .filters label { font-size: 11px; }
  #icp-display { grid-template-columns: 1fr; }
  .strategy-grid { grid-template-columns: 1fr; gap: 8px; }
  .strategy-card { padding: 8px 10px; font-size: 12px; }
  .strategy-summary { padding: 10px; font-size: 12px; }
  .classification-main { gap: 8px; }
  .category-name { font-size: 16px; }
}

/* スマホ縦 */
@media (max-width: 600px) {
  .container { padding: 0 10px; }
  header { padding: 12px 0; }
  header .lead { font-size: 12px; line-height: 1.5; }
  .panel { padding: 12px; margin: 8px 0; }
  .panel h2 { font-size: 14px; margin-bottom: 8px; }
  .notice { font-size: 11px; padding: 10px 12px; }
  .notice strong { display: block; margin-bottom: 4px; }
  .filters { grid-template-columns: 1fr; }
  .samples { gap: 4px; }
  .sample-btn { padding: 5px 9px; font-size: 11px; }
  .sample-label { width: 100%; margin-bottom: 4px; }

  /* テーブル → カード型レイアウトに変換 */
  #results-table thead { display: none; }
  #results-table, #results-table tbody, #results-table tr { display: block; width: 100%; }
  #results-table tr {
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 8px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  }
  #results-table tr.saved-row { background: #fffbeb; }
  #results-table tr.dnc-row { opacity: 0.45; }
  #results-table td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
    padding: 4px 0;
    border: 0;
    font-size: 13px;
  }
  #results-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    flex-shrink: 0;
    width: 80px;
  }
  #results-table td.no-label::before { display: none; }
  #results-table td.no-label {
    display: block;
    padding: 6px 0;
    border-top: 1px solid var(--border);
    margin-top: 4px;
  }
  .row-actions { flex-wrap: wrap; justify-content: flex-end; }
  .reasoning { max-width: none; text-align: left; flex: 1; }
  .ai-comment { margin-bottom: 6px; padding: 6px 8px; font-size: 12px; }
  .ai-reason { font-size: 11px; }

  .table-wrap { overflow: visible; }

  .modal { padding: 8px; align-items: flex-end; }
  .modal-content { max-width: 100%; padding: 16px; border-radius: 12px 12px 0 0; }
  .modal-content pre { font-size: 12px; max-height: 50vh; }

  .sidebar-toggle { top: 8px; left: 8px; width: 38px; height: 38px; font-size: 18px; }
}
