/* IQVIA QOL — Copyright (c) 2026 IQVIA Solutions Japan G.K. All rights reserved. */
/*
 * pmd-qol デザイントークンとコンポーネント。
 *
 * 配色は検証済みパレット（dataviz スキルの参照インスタンス）に合わせている。
 * 重要な制約:
 *   - 状態色 good(#0ca30c) と critical(#d03b3b) は CVD で ΔE 4.1 しかなく、
 *     赤緑色覚では区別できない。**必ずアイコン（形）とラベル（文字）を添える**
 *   - warning(#fab219) は明色面で 1.79:1 しかない。**文字色に使わない**
 *     （淡い塗り + 濃い文字でのみ使う）
 *   - ダークモードは自動反転ではなく、暗い面用に選び直した値
 */

/* ── トークン ─────────────────────────────────────────────────────── */

:root {
  color-scheme: light;

  /* 面 */
  --plane: #f9f9f7;
  --surface: #fcfcfb;
  --surface-raised: #ffffff;
  --surface-sunken: #f2f2ef;
  --surface-hover: rgb(11 11 11 / 4%);

  /* 文字 */
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-muted: #898781;
  --ink-on-accent: #ffffff;

  /* 線 */
  --line: #e1e0d9;
  --line-strong: #c3c2b7;
  --ring: rgb(42 120 214 / 40%);

  /* アクセント（sequential blue の 450 / 550） */
  --accent: #2a78d6;
  --accent-strong: #1c5cab;
  --accent-wash: #eaf2fd;
  --accent-track: #cde2fb;

  /* 状態（固定。テーマで変えない） */
  --good: #0ca30c;
  --good-wash: #e6f6e6;
  --good-ink: #006300;
  --critical: #d03b3b;
  --critical-wash: #fdecec;
  --critical-ink: #a52424;
  --warning: #fab219;
  --warning-wash: #fdf3dd;
  --warning-ink: #7a5300;
  --neutral-wash: #eeeeeb;

  /* かたち */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --shadow-1: 0 1px 2px rgb(11 11 11 / 5%), 0 1px 3px rgb(11 11 11 / 4%);
  --shadow-2: 0 4px 12px rgb(11 11 11 / 8%), 0 1px 3px rgb(11 11 11 / 5%);
  --shadow-3: 0 16px 48px rgb(11 11 11 / 18%), 0 2px 8px rgb(11 11 11 / 8%);

  /* 間隔（8px 基調） */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;

  --sidebar-w: 232px;
  --header-h: 56px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --plane: #0d0d0d;
    --surface: #1a1a19;
    --surface-raised: #222221;
    --surface-sunken: #131312;
    --surface-hover: rgb(255 255 255 / 6%);

    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --ink-muted: #898781;

    --line: #2c2c2a;
    --line-strong: #383835;
    --ring: rgb(57 135 229 / 50%);

    --accent: #3987e5;
    --accent-strong: #5598e7;
    --accent-wash: #16243a;
    --accent-track: #184f95;

    --good-wash: #102a10;
    --good-ink: #4cc44c;
    --critical-wash: #2e1414;
    --critical-ink: #f08b8b;
    --warning-wash: #2b2210;
    --warning-ink: #f5c95f;
    --neutral-wash: #262624;

    --shadow-1: 0 1px 2px rgb(0 0 0 / 40%);
    --shadow-2: 0 4px 12px rgb(0 0 0 / 45%);
    --shadow-3: 0 16px 48px rgb(0 0 0 / 60%);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --plane: #0d0d0d;
  --surface: #1a1a19;
  --surface-raised: #222221;
  --surface-sunken: #131312;
  --surface-hover: rgb(255 255 255 / 6%);

  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --ink-muted: #898781;

  --line: #2c2c2a;
  --line-strong: #383835;
  --ring: rgb(57 135 229 / 50%);

  --accent: #3987e5;
  --accent-strong: #5598e7;
  --accent-wash: #16243a;
  --accent-track: #184f95;

  --good-wash: #102a10;
  --good-ink: #4cc44c;
  --critical-wash: #2e1414;
  --critical-ink: #f08b8b;
  --warning-wash: #2b2210;
  --warning-ink: #f5c95f;
  --neutral-wash: #262624;

  --shadow-1: 0 1px 2px rgb(0 0 0 / 40%);
  --shadow-2: 0 4px 12px rgb(0 0 0 / 45%);
  --shadow-3: 0 16px 48px rgb(0 0 0 / 60%);
}

/* ── 土台 ─────────────────────────────────────────────────────────── */

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

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Kaku Gothic ProN",
    "Noto Sans JP", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
p,
ul,
ol,
figure {
  margin: 0;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

svg {
  flex: none;
}

.icon {
  width: 1em;
  height: 1em;
  fill: none;
  stroke: currentcolor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── ログイン ─────────────────────────────────────────────────────── */

.gate {
  display: grid;
  place-items: center;
  align-content: center;
  gap: var(--s5);
  min-height: 100vh;
  padding: var(--s5);
}

/* 著作権表示（ログイン前・ログイン後の両方） */
.app-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--s1) var(--s4);
  max-width: 1080px;
  margin: var(--s7) auto 0;
  padding-top: var(--s4);
  border-top: 1px solid var(--line);
  color: var(--ink-muted);
  font-size: 0.75rem;
  text-align: center;
}

.gate .app-footer {
  margin-top: 0;
  border-top: 0;
}

.gate-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
  padding: var(--s6);
  text-align: center;
}

.gate-card .brand {
  justify-content: center;
  margin-bottom: var(--s4);
}

.gate-card h1 {
  font-size: 1.15rem;
  letter-spacing: -0.01em;
}

/* 新規登録（自己登録）。ログインボタンの下に控えめに出す */
.gate-signup {
  margin-top: var(--s3);
}

.gate-card .gate-signup p {
  margin: var(--s2) 0 0;
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.gate-card p {
  color: var(--ink-2);
  margin: var(--s2) 0 var(--s5);
}

/* ── アプリシェル ─────────────────────────────────────────────────── */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: var(--s5);
  padding: var(--s4) var(--s3);
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s1) var(--s2);
  font-weight: 650;
  letter-spacing: -0.01em;
}

.brand .mark {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: linear-gradient(140deg, var(--accent), var(--accent-strong));
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 13px;
}

.brand .mark .icon {
  stroke-width: 2.25;
}

/* ログイン前のロゴ。文字は HTML にして、表示モード（明暗）の切り替えに追従させる */
.gate-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: var(--s5);
  font-size: 1.45rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.gate-logo b {
  color: var(--accent);
  font-weight: 700;
}

/* ロゴ画像（web/logo.svg）は背景込み。グラデーションの下地は使わない */
.brand img.mark {
  background: none;
  display: block;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-label {
  font-size: 0.7rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  padding: var(--s3) var(--s2) var(--s1);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s2) var(--s3);
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  color: var(--ink-2);
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background 0.12s, color 0.12s;
}

.nav-item .icon {
  width: 17px;
  height: 17px;
  color: var(--ink-muted);
}

.nav-item:hover {
  background: var(--surface-hover);
  color: var(--ink);
}

.nav-item[aria-current="page"] {
  background: var(--accent-wash);
  color: var(--accent-strong);
  font-weight: 600;
}

.nav-item[aria-current="page"] .icon {
  color: var(--accent);
}

.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  border-top: 1px solid var(--line);
  padding-top: var(--s3);
}

.sidebar-foot .guide-download {
  padding-inline: var(--s1);
  gap: var(--s1);
}

.who {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s2);
  min-width: 0;
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-wash);
  color: var(--accent-strong);
  display: grid;
  place-items: center;
  font-weight: 650;
  font-size: 0.8rem;
  flex: none;
}

.who-text {
  min-width: 0;
}

.who-text strong {
  display: block;
  font-size: 0.82rem;
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.who-text span {
  font-size: 0.72rem;
  color: var(--ink-muted);
}

.sidebar-actions {
  display: flex;
  gap: var(--s1);
}

/* ── 本文 ─────────────────────────────────────────────────────────── */

.main {
  min-width: 0;
  padding: var(--s6) var(--s6) var(--s7);
}

.view {
  max-width: 1080px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--s4);
}

.view-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s4);
  margin-bottom: var(--s1);
}

.view-head h2 {
  font-size: 1.35rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.view-head p {
  color: var(--ink-2);
  margin-top: 2px;
}

/* ── カード ───────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  padding: var(--s4) var(--s5);
  border-bottom: 1px solid var(--line);
}

.card-head h3 {
  font-size: 0.92rem;
  font-weight: 650;
}

.card-head .sub {
  font-size: 0.8rem;
  color: var(--ink-muted);
  font-weight: 400;
}

.card-body {
  padding: var(--s5);
}

.card-body.tight {
  padding: 0;
}

/* ── ボタン ───────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  padding: 0 var(--s4);
  height: 36px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  background: none;
  cursor: pointer;
  font-weight: 550;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
}

.btn .icon {
  width: 16px;
  height: 16px;
}

.btn-primary {
  background: var(--accent);
  color: var(--ink-on-accent);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-strong);
}

.btn-secondary {
  border-color: var(--line-strong);
  color: var(--ink);
  background: var(--surface);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-hover);
}

.btn-ghost {
  color: var(--ink-2);
  padding: 0 var(--s2);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--ink);
}

.btn-sm {
  height: 28px;
  font-size: 0.82rem;
  padding: 0 var(--s3);
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: var(--r-sm);
  color: var(--ink-2);
}

.btn-icon:hover {
  background: var(--surface-hover);
  color: var(--ink);
}

.btn-icon .icon {
  width: 17px;
  height: 17px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ── ドロップゾーン ───────────────────────────────────────────────── */

.dropzone {
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface-sunken);
  padding: var(--s6) var(--s5);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  display: block;
  width: 100%;
}

.dropzone:hover,
.dropzone.is-over {
  border-color: var(--accent);
  background: var(--accent-wash);
}

.dropzone .icon {
  width: 30px;
  height: 30px;
  color: var(--accent);
  stroke-width: 1.5;
}

.dropzone strong {
  display: block;
  margin-top: var(--s3);
  font-weight: 600;
}

.dropzone span {
  display: block;
  color: var(--ink-muted);
  font-size: 0.83rem;
  margin-top: 2px;
}

.file-chip {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-sunken);
}

.file-chip .icon:first-child {
  width: 20px;
  height: 20px;
  color: var(--accent);
}

.file-chip .meta {
  min-width: 0;
  flex: 1;
}

.file-chip .meta strong {
  display: block;
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-chip .meta span {
  display: block;
  font-size: 0.8rem;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 6 表の割り当て。判別できなかったファイルは警告アイコン */
.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--s2);
}

.file-grid .file-chip:has(use[href="#i-alert"]) .icon:first-child {
  color: var(--warning-ink);
}

/* 形式チェックの結果。指摘のあるファイルは横幅いっぱいに広げて行番号付きで見せる */
.file-chip[data-state="error"] {
  border-color: var(--critical);
}

.file-chip[data-state="error"] .icon:first-child {
  color: var(--critical-ink);
}

.file-chip[data-state="warn"] .icon:first-child {
  color: var(--warning-ink);
}

.file-chip:has(.chip-issues) {
  grid-column: 1 / -1;
  flex-wrap: wrap;
}

.chip-issues,
.chip-note {
  flex-basis: 100%;
  margin: 0;
  font-size: 0.8rem;
  overflow-wrap: anywhere;
}

.chip-issues {
  padding-left: 1.2em;
}

.chip-note {
  color: var(--ink-muted);
}

.chip-issues .issue-error {
  color: var(--critical-ink);
}

.chip-issues .issue-warn {
  color: var(--warning-ink);
}

.error-lines {
  margin: var(--s2) 0 0;
  padding-left: 1.2em;
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

.progress-note {
  color: var(--ink-muted);
  font-size: 0.88rem;
}

.form-actions {
  display: flex;
  gap: var(--s3);
  margin-top: var(--s4);
  align-items: center;
}

/* ── 仕様の折りたたみ ─────────────────────────────────────────────── */

.spec {
  margin-top: var(--s4);
  border-top: 1px solid var(--line);
  padding-top: var(--s3);
}

.spec summary {
  cursor: pointer;
  color: var(--accent-strong);
  font-size: 0.85rem;
  font-weight: 550;
  list-style: none;
  display: flex;
  align-items: center;
  gap: var(--s2);
}

.spec summary::-webkit-details-marker {
  display: none;
}

.spec summary .icon {
  width: 14px;
  height: 14px;
  transition: transform 0.15s;
}

.spec[open] summary .icon {
  transform: rotate(90deg);
}

.spec .spec-body {
  padding-top: var(--s3);
  color: var(--ink-2);
  font-size: 0.85rem;
}

.spec dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--s2) var(--s4);
  margin: 0;
}

.spec dt {
  color: var(--ink-muted);
  white-space: nowrap;
}

.spec dd {
  margin: 0;
}

code {
  font-family: ui-monospace, "SFMono-Regular", "Cascadia Mono", Consolas, monospace;
  font-size: 0.86em;
  background: var(--surface-sunken);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
}

/* ── ステッパー（進捗）────────────────────────────────────────────── */

.stepper {
  display: flex;
  align-items: flex-start;
  gap: var(--s2);
}

.step {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  min-width: 0;
}

.step .bar {
  height: 4px;
  border-radius: 2px;
  background: var(--surface-sunken);
  overflow: hidden;
  position: relative;
}

.step[data-state="done"] .bar {
  background: var(--accent);
}

.step[data-state="active"] .bar {
  background: var(--accent-track);
}

.step[data-state="active"] .bar::after {
  content: "";
  position: absolute;
  inset: 0;
  width: 40%;
  border-radius: 2px;
  background: var(--accent);
  animation: slide 1.4s ease-in-out infinite;
}

.step[data-state="failed"] .bar {
  background: var(--critical);
}

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

.step .label {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-size: 0.82rem;
  color: var(--ink-muted);
}

.step[data-state="done"] .label,
.step[data-state="active"] .label {
  color: var(--ink);
  font-weight: 550;
}

.step[data-state="failed"] .label {
  color: var(--critical-ink);
  font-weight: 550;
}

.step .label .icon {
  width: 14px;
  height: 14px;
}

/* ── 状態バッジ ───────────────────────────────────────────────────── */

/*
 * 色だけに意味を持たせない。good と critical は CVD で ΔE 4.1 しか離れて
 * いないため、**アイコンの形とラベルの文字**が識別の主役。色は補助。
 */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px 2px 7px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  background: var(--neutral-wash);
  color: var(--ink-2);
}

.badge .icon {
  width: 13px;
  height: 13px;
  stroke-width: 2.25;
}

.badge[data-status="SUCCEEDED"] {
  background: var(--good-wash);
  color: var(--good-ink);
}

.badge[data-status="FAILED"] {
  background: var(--critical-wash);
  color: var(--critical-ink);
}

.badge[data-status="OVERDUE"] {
  background: var(--warning-wash);
  color: var(--warning-ink);
}

.badge[data-status="RUNNING"],
.badge[data-status="SUBMITTED"] {
  background: var(--accent-wash);
  color: var(--accent-strong);
}

.badge[data-status="RUNNING"] .icon,
.badge[data-status="SUBMITTED"] .icon {
  animation: spin 1.1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.badge-role {
  background: var(--accent-wash);
  color: var(--accent-strong);
}

/* ── アラート ─────────────────────────────────────────────────────── */

.alert {
  display: flex;
  gap: var(--s3);
  padding: var(--s4);
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface-sunken);
}

.alert .icon {
  width: 18px;
  height: 18px;
  margin-top: 1px;
}

.alert strong {
  display: block;
  font-weight: 600;
  margin-bottom: 2px;
}

.alert p {
  color: var(--ink-2);
  font-size: 0.88rem;
  white-space: pre-wrap;
}

.alert-error {
  border-color: color-mix(in srgb, var(--critical) 35%, var(--line));
  background: var(--critical-wash);
}

.alert-error .icon,
.alert-error strong {
  color: var(--critical-ink);
}

.alert-warn {
  border-color: color-mix(in srgb, var(--warning) 45%, var(--line));
  background: var(--warning-wash);
}

.alert-warn .icon,
.alert-warn strong {
  color: var(--warning-ink);
}

.alert ul {
  margin: var(--s2) 0 0;
  padding-left: 1.1rem;
  color: var(--ink-2);
  font-size: 0.85rem;
}

/* ── 結果サマリ ───────────────────────────────────────────────────── */

.result {
  display: flex;
  align-items: center;
  gap: var(--s5);
  flex-wrap: wrap;
}

.result .figures {
  display: flex;
  gap: var(--s6);
}

.figure strong {
  display: block;
  font-size: 1.6rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.figure span {
  font-size: 0.78rem;
  color: var(--ink-muted);
}

.result .btn {
  margin-left: auto;
}

/* ── 統計タイル ───────────────────────────────────────────────────── */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--s3);
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--s4);
  box-shadow: var(--shadow-1);
}

.stat .k {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.78rem;
  color: var(--ink-muted);
  margin-bottom: var(--s1);
}

.stat .k .icon {
  width: 13px;
  height: 13px;
}

/* 大きな単独の数値は比例数字（tabular は列にだけ使う） */
.stat .v {
  font-size: 1.75rem;
  font-weight: 650;
  letter-spacing: -0.025em;
  line-height: 1.15;
}

.stat[data-tone="good"] .v {
  color: var(--good-ink);
}

.stat[data-tone="critical"] .v {
  color: var(--critical-ink);
}

/* ── 表 ───────────────────────────────────────────────────────────── */

.scroll {
  overflow-x: auto;
  overscroll-behavior-x: contain;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

th,
td {
  text-align: left;
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--surface);
  color: var(--ink-muted);
  font-size: 0.75rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
  z-index: 1;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover {
  background: var(--surface-hover);
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.actions-cell {
  text-align: right;
  white-space: nowrap;
}

.actions-cell .btn + .btn {
  margin-left: var(--s1);
}

.owner {
  display: flex;
  align-items: center;
  gap: var(--s2);
  min-width: 0;
}

.owner .avatar {
  width: 24px;
  height: 24px;
  font-size: 0.7rem;
}

.owner span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filename {
  display: flex;
  align-items: center;
  gap: var(--s2);
  max-width: 26ch;
}

/* 長いファイル名で表が横に伸びないようにする */
.filename span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filename .icon {
  width: 15px;
  height: 15px;
  color: var(--ink-muted);
}

/* ── ページ送り ───────────────────────────────────────────────────── */

.pager {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}

.pager .status {
  font-size: 0.82rem;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

.pager .spacer {
  flex: 1;
}

.pager select {
  height: 28px;
  font-size: 0.82rem;
  background-position: calc(100% - 15px) 12px, calc(100% - 10px) 12px;
}

.pager label {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  font-size: 0.82rem;
  color: var(--ink-muted);
}

/* ── 空状態・読み込み中 ───────────────────────────────────────────── */

.empty {
  padding: var(--s7) var(--s5);
  text-align: center;
  color: var(--ink-2);
}

.empty .icon {
  width: 34px;
  height: 34px;
  color: var(--ink-muted);
  stroke-width: 1.25;
}

.empty strong {
  display: block;
  margin-top: var(--s3);
  color: var(--ink);
  font-weight: 600;
}

.empty p {
  margin-top: 2px;
  font-size: 0.86rem;
}

.skeleton-row {
  height: 14px;
  margin: var(--s4);
  border-radius: 4px;
  background: linear-gradient(
    90deg,
    var(--surface-sunken) 25%,
    var(--surface-hover) 37%,
    var(--surface-sunken) 63%
  );
  background-size: 300% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}

@keyframes shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: -100% 0;
  }
}

/* ── フィルタ ─────────────────────────────────────────────────────── */

.toolbar {
  display: flex;
  align-items: center;
  gap: var(--s3);
  flex-wrap: wrap;
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--s1);
}

.field span {
  font-size: 0.75rem;
  color: var(--ink-muted);
  font-weight: 550;
}

select {
  height: 32px;
  padding: 0 var(--s5) 0 var(--s3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  cursor: pointer;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, currentcolor 50%),
    linear-gradient(135deg, currentcolor 50%, transparent 50%);
  background-position: calc(100% - 15px) 14px, calc(100% - 10px) 14px;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  max-width: 280px;
}

/* ── 利用者の招待（admin）──────────────────────────────────────── */
.invite-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--s3);
  padding: var(--s4) var(--s5) 0;
}

.invite-form .field {
  flex: 1 1 220px;
  max-width: 360px;
}

.invite-form input {
  height: 32px;
  padding: 0 var(--s3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink);
}

.invite-note {
  margin: var(--s2) var(--s5) var(--s4);
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.owner-text {
  display: grid;
  min-width: 0;
  line-height: 1.35;
}

.owner-sub {
  font-size: 0.75rem;
  color: var(--ink-muted);
}

.invite-form input[type="text"] {
  height: 32px;
  padding: 0 var(--s3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink);
}

#profile-dialog {
  width: min(440px, calc(100vw - 32px));
}

.profile-fields {
  display: grid;
  gap: var(--s3);
  padding: var(--s4) var(--s5);
}

.profile-fields input {
  height: 34px;
  padding: 0 var(--s3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink);
}

.profile-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--s2);
  padding: 0 var(--s5) var(--s4);
}

.btn-danger {
  color: var(--critical-ink);
}

.account-actions {
  white-space: nowrap;
  text-align: right;
}

/* ── 処理ログ（admin）──────────────────────────────────────────── */
.log-time {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.log-source {
  color: var(--ink-muted);
  font-size: 0.8rem;
}

.log-detail {
  font-size: 0.85rem;
}

tr[data-level="error"] td {
  color: var(--critical-ink);
}

/* ── プレビュー（ダイアログ）──────────────────────────────────────── */

dialog {
  border: 0;
  padding: 0;
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-3);
  width: min(1180px, 94vw);
  max-width: none;
  max-height: 88vh;
  overflow: hidden;
}

dialog::backdrop {
  background: rgb(11 11 11 / 45%);
  backdrop-filter: blur(2px);
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s4);
  padding: var(--s4) var(--s5);
  border-bottom: 1px solid var(--line);
}

.dialog-head h3 {
  font-size: 0.98rem;
  font-weight: 650;
  display: flex;
  align-items: center;
  gap: var(--s2);
}

.dialog-head .meta {
  color: var(--ink-muted);
  font-size: 0.8rem;
  margin-top: 3px;
  display: flex;
  gap: var(--s3);
  flex-wrap: wrap;
}

.dialog-body {
  overflow: auto;
  max-height: calc(88vh - 64px);
}

.preview-table {
  font-size: 0.8rem;
  white-space: nowrap;
  border-collapse: separate;
  border-spacing: 0;
}

.preview-table th,
.preview-table td {
  border-bottom: 1px solid var(--line);
  padding: var(--s2) var(--s3);
}

.preview-table thead th {
  background: var(--surface-sunken);
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.75rem;
}

/* 行番号列は固定して、横スクロールしても位置を見失わない */
.preview-table .rownum {
  position: sticky;
  left: 0;
  background: var(--surface-sunken);
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
  z-index: 2;
  border-right: 1px solid var(--line);
}

.preview-table thead .rownum {
  z-index: 3;
}

/* モデルが付け足した列は、入力の列と見分けられるようにする */
.preview-table .added {
  background: var(--accent-wash);
}

.preview-table thead .added {
  background: color-mix(in srgb, var(--accent-wash) 70%, var(--surface-sunken));
  color: var(--accent-strong);
}

/* ── トースト ─────────────────────────────────────────────────────── */

.toasts {
  position: fixed;
  right: var(--s5);
  bottom: var(--s5);
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  max-width: min(400px, calc(100vw - 48px));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface-raised);
  box-shadow: var(--shadow-2);
  animation: rise 0.18s ease-out;
}

.toast .icon {
  width: 17px;
  height: 17px;
  margin-top: 2px;
}

.toast[data-tone="error"] {
  border-color: color-mix(in srgb, var(--critical) 40%, var(--line));
}

.toast[data-tone="error"] .icon {
  color: var(--critical);
}

.toast[data-tone="success"] .icon {
  color: var(--good);
}

.toast p {
  font-size: 0.86rem;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* ── 画面幅への追従 ───────────────────────────────────────────────── */

@media (width <= 860px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    flex-direction: row;
    align-items: center;
    gap: var(--s3);
    overflow-x: auto;
    padding: var(--s2) var(--s3);
  }

  .brand span:not(.mark) {
    display: none;
  }

  .nav {
    flex-direction: row;
    gap: var(--s1);
  }

  .nav-label {
    display: none;
  }

  /* 管理者メニューも横に並べる（縦に積むと上のバーが高くなる） */
  .nav-admin:not([hidden]) {
    display: flex;
    gap: var(--s1);
  }

  .nav-item {
    padding: var(--s2);
    white-space: nowrap;
  }

  .sidebar-foot {
    margin: 0 0 0 auto;
    border: 0;
    padding: 0;
    flex-direction: row;
    align-items: center;
  }

  .who-text {
    display: none;
  }

  .main {
    padding: var(--s4) var(--s4) var(--s6);
  }

  .result .btn {
    margin-left: 0;
    width: 100%;
  }
}
