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

:root {
  --primary: #0a4d8c;
  --primary-light: #1976d2;
  --primary-dark: #062f55;
  --accent: #ff6b35;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --bg: #f5f7fa;
  --bg-card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.08), 0 4px 10px rgba(0,0,0,0.04);
}

body {
  font-family: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 14px;
}

/* ===== Header ===== */
.header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  padding: 18px 32px;
  box-shadow: var(--shadow-lg);
}
.header-inner {
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}
.brand i {
  font-size: 32px;
  color: var(--accent);
}
.brand h1 {
  font-size: 22px;
  font-weight: 700;
  margin: 0;
}
.subtitle {
  font-size: 12px;
  opacity: 0.85;
  margin: 0;
}
.client-tag {
  text-align: right;
  font-size: 12px;
}
.badge {
  display: inline-block;
  background: var(--accent);
  color: white;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  margin-bottom: 4px;
}
.client-name {
  display: block;
  opacity: 0.9;
}

/* ===== Container ===== */
.container {
  max-width: 1600px;
  margin: 0 auto;
  padding: 24px 32px 60px;
}

/* ===== Steps ===== */
.steps {
  display: flex;
  align-items: center;
  background: var(--bg-card);
  padding: 18px 24px;
  border-radius: 12px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}
.step {
  display: flex;
  align-items: center;
  gap: 12px;
  opacity: 0.45;
  transition: opacity 0.3s;
}
.step.active { opacity: 1; }
.step.done { opacity: 1; }
.step.done .step-num { background: var(--success); }
.step-num {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--text-muted);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
}
.step.active .step-num { background: var(--primary); }
.step-label {
  font-weight: 500;
  font-size: 14px;
}
.step-line {
  flex: 1;
  height: 2px;
  background: var(--border);
  margin: 0 16px;
}

/* ===== Card ===== */
.card {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--border);
  gap: 16px;
}
.card-header h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 10px;
}
.card-header h2 i { color: var(--accent); }
.header-actions { display: flex; gap: 8px; }

/* ===== Forms ===== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}
.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.form-grid label span {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}
input[type="text"], input[type="search"], textarea {
  border: 1px solid var(--border);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: white;
  transition: border-color 0.2s, box-shadow 0.2s;
  width: 100%;
}
input[type="text"]:focus, input[type="search"]:focus, textarea:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.1);
}
.search-input {
  width: 320px;
}

/* ===== Tables ===== */
.process-table-wrap, .fmea-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 16px;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  background: #f1f5f9;
  padding: 10px;
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid var(--border);
  color: var(--text);
  white-space: nowrap;
}
.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover { background: #f8fafc; }
.data-table input {
  border: 1px solid transparent;
  padding: 6px 8px;
  font-size: 13px;
  background: transparent;
}
.data-table input:hover { border-color: var(--border); background: white; }
.data-table input:focus {
  border-color: var(--primary-light);
  background: white;
}

.fmea-table th {
  font-size: 11px;
  text-align: center;
  vertical-align: middle;
}
.fmea-table td {
  font-size: 12px;
  max-width: 200px;
}
.cause-header { background: #fef3c7 !important; color: #92400e !important; }
.rpn-header { background: #ddd6fe !important; color: #5b21b6 !important; }

.fmea-table .cell-cause {
  font-size: 11px;
  background: #fffbeb;
  color: #78350f;
  max-width: 130px;
}
.fmea-table .cell-score {
  text-align: center;
  font-weight: 700;
  background: #faf5ff;
  width: 40px;
}
.fmea-table .cell-rpn {
  text-align: center;
  font-weight: 800;
  font-size: 15px;
}
.rpn-low { background: #d1fae5; color: #065f46; }
.rpn-mid { background: #fef3c7; color: #92400e; }
.rpn-high { background: #fee2e2; color: #991b1b; }

.confidence-cell {
  font-size: 11px;
  text-align: center;
}
.confidence-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin: 4px 0;
}
.confidence-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--success), var(--primary-light));
  transition: width 0.6s;
}
.ref-tag {
  display: inline-block;
  background: #e0e7ff;
  color: #3730a3;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 9px;
  margin: 1px;
  font-family: monospace;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  transition: transform 0.1s, box-shadow 0.2s, background 0.2s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover { background: var(--primary-dark); box-shadow: var(--shadow-lg); }
.btn-secondary {
  background: white;
  color: var(--primary);
  border: 1px solid var(--primary);
}
.btn-secondary:hover { background: var(--primary); color: white; }
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-large { padding: 14px 28px; font-size: 15px; }
.btn-icon {
  padding: 6px 8px;
  background: transparent;
  color: var(--danger);
  border: none;
  cursor: pointer;
}
.btn-icon:hover { background: #fee2e2; border-radius: 4px; }

.form-actions {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
}

/* ===== Agent Flow ===== */
.agent-flow {
  margin: 20px 0;
}
.agent-node {
  background: #f8fafc;
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  transition: all 0.4s;
  position: relative;
}
.agent-node.running {
  border-color: var(--primary-light);
  background: #eff6ff;
  box-shadow: 0 0 0 4px rgba(25, 118, 210, 0.15);
  animation: pulse 1.5s infinite;
}
.agent-node.done {
  border-color: var(--success);
  background: #f0fdf4;
}
.agent-node.done::after {
  content: "✓";
  position: absolute;
  top: 8px;
  right: 12px;
  color: var(--success);
  font-weight: 700;
  font-size: 18px;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(25, 118, 210, 0.15); }
  50% { box-shadow: 0 0 0 8px rgba(25, 118, 210, 0.05); }
}
.agent-icon {
  font-size: 28px;
  margin-bottom: 6px;
}
.agent-name {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 4px;
}
.agent-status {
  font-size: 11px;
  color: var(--text-muted);
}
#agent-orch {
  max-width: 320px;
  margin: 0 auto 20px;
  background: linear-gradient(135deg, #1e3a8a, #1e40af);
  color: white;
  border-color: #1e3a8a;
}
#agent-orch .agent-status { color: rgba(255,255,255,0.85); }
.agent-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

/* ===== Agent Log ===== */
.agent-log {
  background: #0f172a;
  color: #e2e8f0;
  font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
  font-size: 12px;
  padding: 16px;
  border-radius: 8px;
  max-height: 280px;
  overflow-y: auto;
  margin-top: 20px;
  line-height: 1.6;
}
.agent-log .log-line {
  margin-bottom: 4px;
  opacity: 0;
  animation: fadeInLog 0.3s forwards;
}
.agent-log .log-time { color: #94a3b8; }
.agent-log .log-agent { color: #38bdf8; font-weight: 600; }
.agent-log .log-action { color: #f1f5f9; }
.agent-log .log-result { color: #4ade80; }
@keyframes fadeInLog {
  to { opacity: 1; }
}

/* ===== Summary Cards ===== */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.summary-card {
  background: linear-gradient(135deg, #f1f5f9, #fff);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  text-align: center;
}
.summary-card .label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 500;
}
.summary-card .value {
  font-size: 24px;
  font-weight: 800;
  color: var(--primary);
}
.summary-card .unit {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}
.summary-card.highlight .value { color: var(--accent); }
.summary-card.success .value { color: var(--success); }

/* ===== Past records ===== */
.stats-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 14px;
  background: #f8fafc;
  border-radius: 8px;
}
.stat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.stat-item strong { color: var(--primary); font-size: 16px; }
.past-records {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
  max-height: 480px;
  overflow-y: auto;
}
.past-record-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: #fafbfc;
  font-size: 12px;
}
.past-record-card .record-id {
  font-family: monospace;
  font-size: 10px;
  color: var(--accent);
  font-weight: 700;
}
.past-record-card .record-process {
  font-weight: 700;
  margin: 4px 0;
}
.past-record-card .record-failure {
  color: var(--danger);
  margin-bottom: 6px;
}
.past-record-card .record-meta {
  font-size: 10px;
  color: var(--text-muted);
  display: flex;
  gap: 8px;
}

/* ===== Footer ===== */
.footer {
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
  font-size: 12px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
}

/* ===== Utility ===== */
.hidden { display: none !important; }

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .form-grid { grid-template-columns: 1fr; }
  .agent-grid { grid-template-columns: repeat(2, 1fr); }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .header-inner { flex-direction: column; align-items: flex-start; gap: 12px; }
  .client-tag { text-align: left; }
}
