:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #cbd5e1;
  --border-light: #e2e8f0;
  --text: #0f172a;
  --text-muted: #475569;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --navy: #0f172a;
  --teal: #0f766e;
  --green: #15803d;
  --green-bg: #dcfce7;
  --blue-bg: #dbeafe;
  --amber: #b45309;
  --amber-bg: #fef3c7;
  --red: #b91c1c;
  --red-bg: #fee2e2;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 14px;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-variant-numeric: tabular-nums;
}

/* Header */
.app-header {
  background: var(--navy);
  color: #ffffff;
  padding: 10px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 3px solid var(--primary);
}

.brand-area {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.brand-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.brand-sub {
  font-size: 12px;
  color: #cbd5e1;
}

.security-badge {
  background: #064e3b;
  color: #a7f3d0;
  border: 1px solid #10b981;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.free-badge {
  background: #1e3a8a;
  color: #dbeafe;
  border: 1px solid #60a5fa;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
}

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

/* Buttons */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn:hover {
  background: #f8fafc;
  border-color: #94a3b8;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

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

.btn-ghost-dark {
  background: #1e293b;
  border-color: #475569;
  color: #f8fafc;
}

.btn-ghost-dark:hover {
  background: #334155;
}

.btn-download {
  background: #0f766e;
  border-color: #14b8a6;
  color: #ffffff;
}

.btn-download:hover {
  background: #0d9488;
  border-color: #2dd4bf;
}

.btn-sm {
  padding: 5px 9px;
  font-size: 11.5px;
}

/* Workspace Layout */
.workspace {
  max-width: 1460px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  grid-template-columns: 390px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

@media (max-width: 1060px) {
  .workspace {
    grid-template-columns: 1fr;
  }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 14px;
}

.panel-title {
  margin: 0 0 10px 0;
  font-size: 14px;
  font-weight: 800;
  color: var(--navy);
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* Form Controls */
.field-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.field-grid-2,
.parse-options-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.field label {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-muted);
}

.field input,
.field select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 6px 8px;
  font-size: 13px;
  color: var(--text);
  background: #ffffff;
}

.field input:focus,
.field select:focus,
textarea:focus {
  outline: 2px solid #93c5fd;
  border-color: var(--primary);
}

textarea.data-input {
  min-height: 205px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
}

.sample-pills {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 4px;
}

.drop-zone {
  border: 1.5px dashed #94a3b8;
  background: var(--surface-alt);
  border-radius: 6px;
  padding: 8px 10px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
  cursor: pointer;
}

.drop-zone.drag-over {
  border-color: var(--primary);
  background: #eff6ff;
  color: var(--primary);
}

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

/* Alerts & Banners */
.banner {
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 12.5px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.banner-error {
  background: var(--red-bg);
  border: 1px solid #fca5a5;
  color: #7f1d1d;
  font-weight: 600;
}

.parse-info-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  margin-bottom: 10px;
  font-size: 11.5px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.parse-warn-bar {
  background: var(--amber-bg);
  border: 1px solid #f59e0b;
  color: #78350f;
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 600;
}

.hidden {
  display: none !important;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: var(--shadow);
}

.kpi-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.kpi-value {
  font-size: 20px;
  font-weight: 800;
  color: var(--navy);
  line-height: 1.2;
}

.kpi-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.ref-warning-note {
  color: var(--red);
  font-weight: 700;
  background: var(--red-bg);
  border: 1px solid #fca5a5;
  padding: 2px 6px;
  border-radius: 4px;
  display: inline-block;
  margin-top: 4px;
  font-size: 10.5px;
}

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 800;
}

.rank-A { background: var(--green-bg); color: var(--green); border: 1px solid #86efac; }
.rank-B { background: var(--blue-bg); color: var(--primary); border: 1px solid #93c5fd; }
.rank-C { background: var(--amber-bg); color: var(--amber); border: 1px solid #fcd34d; }
.rank-D { background: var(--red-bg); color: var(--red); border: 1px solid #fca5a5; }
.rank-NA { background: #e2e8f0; color: #475569; border: 1px solid #cbd5e1; }

/* Charts */
.chart-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.chart-box svg {
  display: block;
  width: 100%;
  height: auto;
}

/* Tables */
.stats-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}

@media (max-width: 820px) {
  .stats-split {
    grid-template-columns: 1fr;
  }
}

table.qc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

table.qc-table th,
table.qc-table td {
  border: 1px solid var(--border-light);
  padding: 6px 8px;
  text-align: left;
}

table.qc-table th {
  background: var(--surface-alt);
  color: var(--text-muted);
  font-weight: 700;
}

table.qc-table td.num,
table.qc-table th.num {
  text-align: right;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

.status-pill {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
}

.pill-ok { background: var(--green-bg); color: var(--green); }
.pill-ng { background: var(--red-bg); color: var(--red); }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}

.modal-card {
  background: #ffffff;
  border-radius: 10px;
  max-width: 680px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 20px;
  box-shadow: 0 20px 35px rgba(15, 23, 42, 0.25);
}

/* SEO Guide Section (Web only, no-print) */
.seo-guide {
  max-width: 1460px;
  margin: 8px auto 32px;
  padding: 0 16px;
}

.seo-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

@media (max-width: 900px) {
  .seo-grid {
    grid-template-columns: 1fr;
  }
}

.seo-guide h2 {
  font-size: 17px;
  color: var(--navy);
  margin: 0 0 10px 0;
}

.faq-list details {
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 8px;
  background: var(--surface-alt);
}

.faq-list summary {
  font-weight: 700;
  cursor: pointer;
  color: var(--navy);
}

.faq-list p {
  margin: 8px 0 2px;
  color: var(--text-muted);
  font-size: 13px;
}

/* Print-only Report Header */
.print-only {
  display: none;
}

.disclaimer-footer {
  font-size: 11.5px;
  color: var(--text-muted);
  background: var(--surface-alt);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 10px 12px;
}

@media print {
  @page {
    size: A4 portrait;
    margin: 10mm;
  }

  body,
  .rank-badge,
  .status-pill,
  .stamp-head,
  .qc-table th,
  .meta-print-table th,
  .ref-warning-note {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  body {
    background: #ffffff;
    font-size: 11px;
  }

  .no-print,
  .app-header,
  .sidebar-col,
  .parse-info-bar,
  .modal-backdrop,
  .seo-guide {
    display: none !important;
  }

  .workspace {
    display: block;
    max-width: none;
    padding: 0;
    margin: 0;
  }

  .print-only {
    display: block !important;
  }

  .print-page-break-before {
    break-before: page;
    page-break-before: always;
  }

  .report-header-box {
    border: 1.5px solid #0f172a;
    padding: 8px 12px;
    margin-bottom: 8px;
  }

  .report-title-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    border-bottom: 1px solid #0f172a;
    padding-bottom: 4px;
    margin-bottom: 6px;
  }

  .report-title-row h2 {
    margin: 0;
    font-size: 15px;
  }

  .stamp-grid {
    display: grid;
    grid-template-columns: repeat(3, 54px);
    border: 1px solid #0f172a;
    font-size: 9.5px;
    text-align: center;
  }

  .stamp-cell {
    border-left: 1px solid #0f172a;
  }

  .stamp-cell:first-child {
    border-left: none;
  }

  .stamp-head {
    background: #f1f5f9;
    border-bottom: 1px solid #0f172a;
    padding: 1px 0;
    font-weight: 700;
  }

  .stamp-body {
    height: 28px;
  }

  .meta-print-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 10.5px;
  }

  .meta-print-table th,
  .meta-print-table td {
    border: 1px solid #cbd5e1;
    padding: 3px 6px;
  }

  .meta-print-table th {
    background: #f8fafc;
    width: 14%;
  }

  .panel, .kpi-card, .chart-box {
    box-shadow: none;
    break-inside: avoid;
    page-break-inside: avoid;
    margin-bottom: 8px;
  }

  .kpi-grid {
    gap: 6px;
    margin-bottom: 8px;
  }
}
