/* Form Outreach — shared dashboard UI */
:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --sidebar: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-active: #1e293b;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #166534;
  --primary-hover: #14532d;
  --accent: #2563eb;
  --warn: #d97706;
  --danger: #dc2626;
  --purple: #7c3aed;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 4px 16px rgba(15, 23, 42, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

/* —— Layout —— */
.app-layout {
  display: grid;
  grid-template-columns: 252px 1fr;
  min-height: 100vh;
}

.app-sidebar {
  background: var(--sidebar);
  color: #e2e8f0;
  padding: 24px 0;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-sidebar .brand {
  padding: 0 22px 28px;
  font-weight: 800;
  font-size: 1.125rem;
  color: #fff;
  letter-spacing: -0.02em;
}

.app-sidebar .brand small {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--sidebar-text);
  margin-top: 4px;
}

.app-nav { flex: 1; }

.app-nav .nav-group-title {
  padding: 14px 22px 6px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748b;
}

.app-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 22px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: background 0.15s, color 0.15s;
}

.app-nav a:hover {
  background: var(--sidebar-active);
  color: #f8fafc;
}

.app-nav a.active {
  background: var(--sidebar-active);
  color: #fff;
  border-left-color: #22c55e;
}

.app-nav .nav-icon {
  width: 20px;
  text-align: center;
  opacity: 0.9;
}

.app-main {
  padding: 28px 32px 48px;
  max-width: 1280px;
  width: 100%;
}

/* —— Page header —— */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 28px;
}

.page-header h1 {
  margin: 0 0 6px;
  font-size: 1.625rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.page-header .sub {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  max-width: 52ch;
  line-height: 1.6;
}

.header-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* —— Buttons —— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, transform 0.1s;
}

.btn:active { transform: scale(0.98); }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }

.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: #1d4ed8; }

.btn-warn { background: var(--warn); color: #fff; }
.btn-warn:hover { background: #b45309; }

.btn-danger { background: var(--danger); color: #fff; }

.btn-secondary {
  background: var(--surface);
  color: #334155;
  border: 1px solid var(--line);
}

.btn-secondary:hover { background: #f8fafc; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

/* —— Stats —— */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow);
}

.stat-card .label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 8px;
}

.stat-card .value {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.stat-card.accent-green { border-top: 3px solid #22c55e; }
.stat-card.accent-blue { border-top: 3px solid #3b82f6; }
.stat-card.accent-amber { border-top: 3px solid #f59e0b; }
.stat-card.accent-purple { border-top: 3px solid #a855f7; }

/* —— Sections —— */
.section {
  margin-bottom: 36px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.section-head h2 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
}

.section-head .hint {
  font-size: 13px;
  color: var(--muted);
}

/* —— Toolbar —— */
.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.toolbar input[type="search"],
.toolbar input[type="text"] {
  flex: 1;
  min-width: 200px;
  max-width: 360px;
  padding: 9px 12px 9px 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.242 1.1a5 5 0 1 1 0-10 5 5 0 0 1 0 10z'/%3E%3C/svg%3E") 12px center no-repeat;
}

/* —— Cards & panels —— */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-flush { overflow: hidden; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 20px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.panel-head {
  padding: 14px 18px;
  font-weight: 700;
  font-size: 15px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}

.panel-body { padding: 18px; }

.panel.accent-warn { border-color: #fcd34d; }
.panel.accent-warn .panel-head { background: #fffbeb; color: #92400e; }

.panel.accent-create { border-color: #93c5fd; }
.panel.accent-create .panel-head { background: #eff6ff; color: #1e40af; }

.panel.green { border-color: #86efac; }
.panel.green .panel-head { background: #ecfdf5; color: var(--primary); }

.panel.blue { border-color: #93c5fd; }
.panel.blue .panel-head { background: #eff6ff; color: #1d4ed8; }

.panel.purple { border-color: #c4b5fd; }
.panel.purple .panel-head { background: #f5f3ff; color: #6d28d9; }

/* —— Run cards (submissions) —— */
.runs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 18px;
}

.run-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s;
}

.run-card:hover { box-shadow: 0 8px 24px rgba(15, 23, 42, 0.1); }

.run-card-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  background: #fafafa;
}

.run-card-head strong {
  font-size: 15px;
  line-height: 1.35;
}

.run-shots {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px;
  background: #f8fafc;
}

.run-shots img {
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  cursor: zoom-in;
  aspect-ratio: 4/3;
  object-fit: cover;
  background: #e2e8f0;
}

.run-shots figcaption {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
  text-align: center;
}

.run-meta {
  padding: 12px 16px 16px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.65;
}

.run-meta .track-stat {
  color: var(--primary);
  font-weight: 600;
  margin-top: 6px;
}

.run-meta .message-preview {
  margin-top: 10px;
  padding: 10px;
  background: #f1f5f9;
  border-radius: var(--radius-sm);
  color: #334155;
  white-space: pre-wrap;
  font-size: 12px;
  max-height: 100px;
  overflow: hidden;
}

/* —— Tables —— */
.table-wrap {
  overflow: auto;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

table.data-table th,
table.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

table.data-table th {
  background: #f8fafc;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

table.data-table tbody tr:hover td { background: #fafafa; }

table.data-table tbody tr:last-child td { border-bottom: none; }

table.data-table .cell-company strong {
  display: block;
  color: var(--text);
  font-size: 14px;
}

table.data-table .cell-muted {
  font-size: 12px;
  color: var(--muted);
}

table.data-table a {
  word-break: break-all;
  font-size: 13px;
}

/* —— Badges —— */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.badge-default { background: #f1f5f9; color: #64748b; }

.badge-success,
.badge.submitted,
.badge.filled,
.badge.form_found {
  background: #dcfce7;
  color: #166534;
}

.badge-fail,
.badge.failed {
  background: #fee2e2;
  color: #b91c1c;
}

.badge-pending,
.badge.pending {
  background: #fef3c7;
  color: #92400e;
}

.badge.zero { background: #f1f5f9; color: #94a3b8; }

/* —— Forms —— */
.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #475569;
  margin-bottom: 6px;
}

/* ラジオ・チェックボックス行は横並び（width:100% の input ルールで崩れないように） */
.field .radios,
.field .radio-options {
  display: flex !important;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

.field .radios > label,
.field .radio-options > label,
.field > label.radio-option,
label.radio-option,
.checkbox-row {
  display: inline-flex !important;
  align-items: flex-start;
  gap: 8px;
  width: auto !important;
  font-size: 13px;
  font-weight: 400;
  color: #334155;
  margin: 0 !important;
  padding: 0;
  cursor: pointer;
  line-height: 1.55;
}

.field .radios > label > span,
.field .radio-options > label > span,
label.radio-option > span {
  flex: 1;
  min-width: 0;
}

.field input[type="text"],
.field input[type="search"],
.field input[type="number"],
.field input[type="email"],
.field input[type="url"],
.field input[type="date"],
.field select,
.field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--surface);
  font-family: inherit;
}

.field input[type="radio"],
.field input[type="checkbox"],
input[type="radio"],
input[type="checkbox"] {
  width: 16px !important;
  height: 16px !important;
  min-width: 16px;
  max-width: 16px;
  flex-shrink: 0;
  margin: 2px 0 0;
  padding: 0;
  border: 1px solid var(--line-strong, #d1d5db);
  box-shadow: none;
  accent-color: var(--primary);
  display: inline-block;
  vertical-align: middle;
}

.field input[type="radio"]:focus,
.field input[type="checkbox"]:focus {
  box-shadow: none;
  outline: 2px solid rgba(22, 101, 52, 0.35);
  outline-offset: 2px;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: #86efac;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15);
}

.field small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.field textarea { min-height: 140px; resize: vertical; line-height: 1.6; }

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }

.preview-box,
.preview {
  background: #f1f5f9;
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 13px;
  line-height: 1.6;
  word-break: break-all;
}

.preview { white-space: pre-wrap; min-height: 100px; color: #334155; }

/* —— Alerts —— */
.alert {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.55;
  margin-bottom: 16px;
}

.alert-warn {
  background: #fffbeb;
  border: 1px solid #fcd34d;
  color: #92400e;
}

.alert-info {
  background: #eff6ff;
  border: 1px solid #93c5fd;
  color: #1e40af;
}

/* —— Empty & loading —— */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
  font-size: 14px;
}

.empty-state .icon { font-size: 2rem; margin-bottom: 8px; opacity: 0.5; }

.loading-bar {
  height: 3px;
  background: #e2e8f0;
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 20px;
  display: none;
}

.loading-bar.active { display: block; }

.loading-bar::after {
  content: "";
  display: block;
  height: 100%;
  width: 40%;
  background: var(--primary);
  border-radius: 99px;
  animation: load-slide 1s ease-in-out infinite;
}

@keyframes load-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}

/* —— Toast & modal —— */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--primary);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  display: none;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.modal-img {
  max-width: min(92vw, 1200px);
  max-height: 90vh;
  display: block;
  border-radius: var(--radius-sm);
}

dialog.modal {
  border: none;
  border-radius: var(--radius);
  padding: 8px;
  background: #0f172a;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.4);
}

dialog.modal::backdrop { background: rgba(15, 23, 42, 0.75); }

.result-box {
  margin-top: 14px;
  padding: 14px;
  background: #ecfdf5;
  border: 1px solid #86efac;
  border-radius: var(--radius-sm);
  font-size: 13px;
  display: none;
}

.result-box code { word-break: break-all; font-size: 12px; }

.radios { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }

.radios label,
.radio-options label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  font-weight: 400;
  cursor: pointer;
  line-height: 1.5;
}

.radio-options { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }

.template-list {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 18px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.template-list select {
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  min-width: 220px;
  font-size: 14px;
}

.test-panel {
  background: var(--surface);
  border: 1px solid #fcd34d;
  border-radius: var(--radius);
  padding: 18px;
  margin-top: 24px;
  box-shadow: var(--shadow);
}

.test-panel h2 { margin: 0 0 12px; font-size: 16px; color: #92400e; }

.test-result {
  margin-top: 12px;
  padding: 14px;
  background: #f8fafc;
  border-radius: var(--radius-sm);
  font-size: 13px;
  display: none;
}

.test-result.ok { border-left: 4px solid #16a34a; }
.test-result.err { border-left: 4px solid #dc2626; }

.test-result img {
  max-width: 100%;
  margin-top: 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}

.radios-inline {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: wrap;
  gap: 16px 20px;
}

.radios-inline > label {
  display: inline-flex !important;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

/* —— Tabs —— */
.tab-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 4px;
  background: #e2e8f0;
  border-radius: var(--radius-sm);
  width: fit-content;
  max-width: 100%;
}

.tab-btn {
  border: none;
  background: transparent;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.tab-btn:hover { color: var(--text); }

.tab-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.1);
}

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

.stat-card.clickable {
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.stat-card.clickable:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.1);
}

.stat-card.clickable.active-tab {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* —— Responsive —— */
@media (max-width: 960px) {
  .app-layout { grid-template-columns: 1fr; }
  .app-sidebar {
    position: relative;
    height: auto;
    padding: 16px 0;
  }
  .app-nav { display: flex; flex-wrap: wrap; gap: 4px; padding: 0 12px; }
  .app-nav a {
    border-left: none;
    border-radius: var(--radius-sm);
    padding: 8px 14px;
  }
  .app-main { padding: 20px 16px 40px; }
  .grid-2, .row-2, .row-3 { grid-template-columns: 1fr; }
  .runs-grid { grid-template-columns: 1fr; }
}
