/* ==========================================================================
   SEDORI COCKPIT — ベース（リセット / タイポグラフィ / レイアウトプリミティブ）
   色・余白・角丸はすべて tokens.css の変数経由。
   ========================================================================== */

/* ---------- リセット ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scrollbar-gutter: stable;
  scroll-padding-top: calc(var(--topbar-h) + var(--sp-4));
  background-color: var(--bg-0);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  font-weight: var(--fw-regular);
  line-height: var(--lh-body);
  color: var(--text-1);
  background-color: var(--bg-0);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-wrap: break-word;
}

/* 背景の演出（静止）: 隅のオーロラ ＋ 淡い格子。アニメーションさせない */
body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

body::before {
  background-image:
    radial-gradient(62vw 56vh at 0% 0%, var(--aurora-1), transparent 70%),
    radial-gradient(56vw 58vh at 100% 100%, var(--aurora-2), transparent 70%);
}

body::after {
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: var(--grid-size) var(--grid-size);
  -webkit-mask-image: linear-gradient(180deg, black 0%, rgba(0, 0, 0, 0.55) 60%, rgba(0, 0, 0, 0.2) 100%);
  mask-image: linear-gradient(180deg, black 0%, rgba(0, 0, 0, 0.55) 60%, rgba(0, 0, 0, 0.2) 100%);
}

h1,
h2,
h3,
h4,
h5,
h6,
p,
figure,
blockquote,
dl,
dd {
  margin: 0;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: var(--fw-semibold);
  line-height: var(--lh-snug);
  color: var(--text-1);
  letter-spacing: 0.01em;
}

h1 { font-size: var(--fs-3xl); }
h2 { font-size: var(--fs-2xl); }
h3 { font-size: var(--fs-xl); }
h4 { font-size: var(--fs-lg); }
h5,
h6 { font-size: var(--fs-md); }

ul,
ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

img,
svg,
video,
canvas {
  display: block;
  max-width: 100%;
}

svg {
  flex-shrink: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
  margin: 0;
}

button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:disabled {
  cursor: not-allowed;
}

table {
  border-collapse: collapse;
  border-spacing: 0;
  width: 100%;
}

th {
  text-align: left;
  font-weight: var(--fw-medium);
}

a {
  color: var(--accent-fg);
  text-decoration: none;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  border-radius: var(--r-xs);
  transition: color var(--dur-2) var(--ease-out);
}

a:hover {
  text-decoration: underline;
}

hr {
  border: 0;
  border-top: 1px solid var(--line-1);
  margin: 0;
}

small {
  font-size: var(--fs-sm);
}

strong,
b {
  font-weight: var(--fw-semibold);
}

code,
kbd,
samp,
pre {
  font-family: var(--font-mono);
  font-size: 0.92em;
}

code {
  padding: 0.1em 0.4em;
  border-radius: var(--r-xs);
  background: var(--neutral-soft);
  border: 1px solid var(--line-1);
  color: var(--text-1);
}

pre {
  margin: 0;
  padding: var(--sp-4);
  border-radius: var(--r-lg);
  background: var(--surface-sunken);
  border: 1px solid var(--line-1);
  overflow: auto;
  line-height: 1.55;
  color: var(--text-2);
}

pre code {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
}

::selection {
  background: var(--selection-bg);
}

[hidden] {
  display: none !important;
}

/* ---------- フォーカス ---------- */
:focus {
  outline: none;
}

:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

/* ---------- スクロールバー ---------- */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) transparent;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  background-clip: content-box;
  border: 2px solid transparent;
  border-radius: var(--r-pill);
}

::-webkit-scrollbar-thumb:hover {
  background-color: var(--scroll-thumb-hover);
}

/* ==========================================================================
   レイアウトプリミティブ
   ========================================================================== */

/* 縦積み。--gap で間隔を上書きできる */
.stack {
  display: flex;
  flex-direction: column;
  gap: var(--gap, var(--sp-4));
  min-width: 0;
}
.stack--xs { --gap: var(--sp-1); }
.stack--sm { --gap: var(--sp-2); }
.stack--md { --gap: var(--sp-4); }
.stack--lg { --gap: var(--sp-6); }
.stack--xl { --gap: var(--sp-8); }

/* 横並び（折り返しあり）。ボタン群・バッジ群に */
.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--gap, var(--sp-2));
  min-width: 0;
}
.cluster--xs { --gap: var(--sp-1); }
.cluster--sm { --gap: var(--sp-1-5); }
.cluster--md { --gap: var(--sp-3); }
.cluster--lg { --gap: var(--sp-4); }
.cluster--nowrap { flex-wrap: nowrap; }
.cluster--end { justify-content: flex-end; }
.cluster--center { justify-content: center; }
.cluster--between { justify-content: space-between; }
.cluster--top { align-items: flex-start; }
.cluster--baseline { align-items: baseline; }

/* 左右に振り分け */
.split {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap, var(--sp-4));
  min-width: 0;
}
.split--top { align-items: flex-start; }
.split--wrap { flex-wrap: wrap; }

/* 自動で段組みするグリッド。--min で1列の最小幅を指定 */
.grid {
  display: grid;
  gap: var(--gap, var(--sp-4));
  grid-template-columns: repeat(auto-fit, minmax(min(var(--min, 240px), 100%), 1fr));
  min-width: 0;
}
.grid > * { min-width: 0; }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid--6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.grid--kpi { --min: 208px; }
.grid--tight { --gap: var(--sp-3); }
.grid--loose { --gap: var(--sp-6); }

/* 12分割グリッド。.col-N で幅を指定 */
.cols {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: var(--gap, var(--sp-4));
  min-width: 0;
}
.cols > * { min-width: 0; grid-column: span 12; }
.cols > .col-2 { grid-column: span 2; }
.cols > .col-3 { grid-column: span 3; }
.cols > .col-4 { grid-column: span 4; }
.cols > .col-5 { grid-column: span 5; }
.cols > .col-6 { grid-column: span 6; }
.cols > .col-7 { grid-column: span 7; }
.cols > .col-8 { grid-column: span 8; }
.cols > .col-9 { grid-column: span 9; }
.cols > .col-12 { grid-column: span 12; }

/* 本体 ＋ 右の補助パネル（計算フォームと結果など） */
.with-aside {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--aside-w, 380px);
  gap: var(--gap, var(--sp-4));
  align-items: start;
  min-width: 0;
}
.with-aside > * { min-width: 0; }
.with-aside--left { grid-template-columns: var(--aside-w, 320px) minmax(0, 1fr); }
.with-aside__sticky {
  position: sticky;
  top: calc(var(--topbar-h) + var(--sp-4));
}

@media (max-width: 1180px) {
  .grid--6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols > .col-2,
  .cols > .col-3 { grid-column: span 6; }
  .cols > .col-4,
  .cols > .col-5,
  .cols > .col-6,
  .cols > .col-7,
  .cols > .col-8,
  .cols > .col-9 { grid-column: span 12; }
  .with-aside,
  .with-aside--left { grid-template-columns: minmax(0, 1fr); }
  .with-aside__sticky { position: static; }
}

@media (max-width: 760px) {
  .grid--6,
  .grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid--2 { grid-template-columns: minmax(0, 1fr); }
}

/* 画面の器。各画面は root の直下にこれを1つ置く */
.page {
  width: 100%;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: var(--page-pad-y) var(--page-pad-x) var(--sp-12);
  display: flex;
  flex-direction: column;
  gap: var(--sp-6);
  min-width: 0;
}
.page--narrow { max-width: 960px; }
.page--medium { max-width: 1240px; }

/* 画面の見出し帯（説明文と主要ボタン） */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-4) var(--sp-6);
  flex-wrap: wrap;
  min-width: 0;
}
.page-header__text {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  min-width: 0;
  flex: 1 1 320px;
}
.page-header__eyebrow {
  font-family: var(--font-num);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-hud);
  color: var(--accent-fg);
  text-transform: uppercase;
}
.page-header__title {
  font-size: var(--fs-3xl);
  font-weight: var(--fw-bold);
  line-height: 1.3;
  letter-spacing: 0.01em;
}
.page-header__desc {
  color: var(--text-2);
  max-width: 68ch;
}
.page-header__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
}

/* 区画（見出し＋内容） */
.section {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  min-width: 0;
}
.section__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3) var(--sp-4);
  flex-wrap: wrap;
  min-height: var(--hit-min);
}
.section__title {
  display: flex;
  align-items: center;
  gap: var(--sp-2-5);
  font-size: var(--fs-xl);
  font-weight: var(--fw-semibold);
}
.section__title::before {
  content: "";
  width: 3px;
  height: 1.05em;
  border-radius: var(--r-pill);
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-2) 100%);
  box-shadow: var(--glow-dot);
  flex-shrink: 0;
}
.section__desc {
  color: var(--text-2);
  font-size: var(--fs-md);
}
.section__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
}

/* 絞り込み・操作の帯 */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2) var(--sp-3);
  min-width: 0;
}
.toolbar__spacer { flex: 1 1 auto; }

/* ==========================================================================
   ユーティリティ
   ========================================================================== */
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.clamp-2,
.clamp-3 {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.clamp-2 { -webkit-line-clamp: 2; line-clamp: 2; }
.clamp-3 { -webkit-line-clamp: 3; line-clamp: 3; }
.nowrap { white-space: nowrap; }
.break { overflow-wrap: anywhere; word-break: break-word; }

/* 数値: 等幅数字・右寄せは .num--right か表の td.num で */
.num {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  letter-spacing: 0;
  white-space: nowrap;
}
.num--right { text-align: right; }
.mono { font-family: var(--font-mono); }

.text-1 { color: var(--text-1); }
.text-2,
.subtle { color: var(--text-2); }
.text-3,
.muted { color: var(--text-3); }
.text-accent { color: var(--accent-fg); }
.text-violet { color: var(--violet-fg); }
.text-pos,
.text-success { color: var(--success-fg); }
.text-neg,
.text-danger { color: var(--danger-fg); }
.text-warn { color: var(--warn-fg); }
.text-info { color: var(--info-fg); }

.fs-xs { font-size: var(--fs-xs); }
.fs-sm { font-size: var(--fs-sm); }
.fs-md { font-size: var(--fs-md); }
.fs-lg { font-size: var(--fs-lg); }
.fs-xl { font-size: var(--fs-xl); }
.fs-2xl { font-size: var(--fs-2xl); }
.fw-regular { font-weight: var(--fw-regular); }
.fw-medium { font-weight: var(--fw-medium); }
.fw-semibold { font-weight: var(--fw-semibold); }
.fw-bold { font-weight: var(--fw-bold); }

.ta-left { text-align: left; }
.ta-center { text-align: center; }
.ta-right { text-align: right; }

.grow { flex: 1 1 auto; min-width: 0; }
.shrink-0 { flex-shrink: 0; }
.w-full { width: 100%; }
.min-w-0 { min-width: 0; }
.scroll-x { overflow-x: auto; }
.scroll-y { overflow-y: auto; }
.relative { position: relative; }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: var(--sp-1); }
.mt-2 { margin-top: var(--sp-2); }
.mt-3 { margin-top: var(--sp-3); }
.mt-4 { margin-top: var(--sp-4); }
.mt-6 { margin-top: var(--sp-6); }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: var(--sp-2); }
.mb-4 { margin-bottom: var(--sp-4); }
.ml-auto { margin-left: auto; }

/* HUD風の極小ラベル（欧文・英数字の短い見出し用） */
.hud-label {
  font-family: var(--font-num);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-hud);
  text-transform: uppercase;
  color: var(--text-3);
  white-space: nowrap;
}
.hud-label--accent { color: var(--accent-fg); }

.divider {
  height: 1px;
  background: var(--line-1);
  border: 0;
  margin: 0;
  flex-shrink: 0;
}
.divider--v {
  width: 1px;
  height: auto;
  align-self: stretch;
}

/* 画面切替: フェード＋4pxスライド */
@keyframes view-enter {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.view-enter {
  animation: view-enter var(--dur-4) var(--ease-out) both;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

/* 動きを減らす設定では演出を止める */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* 印刷（古物台帳などの帳票用の最低限） */
@media print {
  body {
    background: none;
  }
  body::before,
  body::after {
    display: none;
  }
}
