/* =====================================================================
 * Phase 10: 共通デザインシステム (Linear / Vercel / Notion 風)
 * 全画面 (index / trend / backmargin) から読み込む共通 CSS。
 * 既存の <style> ブロックとは「後勝ち」で併存し、既存の特殊コンポーネント
 * (aliases モーダル、backmargin 契約カード、matrix-sheet 等) には干渉しない。
 * ===================================================================== */

/* --- Design tokens ------------------------------------------------- */
:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --border: #e4e4e7;
  --border-2: #d4d4d8;
  --text: #09090b;
  --muted: #71717a;
  --hint: #a1a1aa;
  --accent: #18181b;
  --accent-hover: #27272a;
  --accent-fg: #fafafa;
  --success: #16a34a;
  --success-bg: #f0fdf4;
  --info: #3b82f6;
  --info-bg: #eff6ff;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --amber: #d97706;
  --amber-bg: #fffbeb;

  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;

  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-modal: 0 24px 48px -12px rgba(0, 0, 0, 0.25);

  --maxw: 1400px;

  /* --- Legacy aliases (Phase 10 以前の inline CSS との互換) --------
   * 既存の index.html / trend.html / backmargin.html の inline <style>
   * は旧命名 (--text-muted, --text-subtle, --accent-soft 等) を参照している。
   * 新 UI のトークンへエイリアスすることで、既存コンポーネント (modal,
   * matrix-sheet, alias-list 等) が新カラーシステムに自動追従する。
   * --------------------------------------------------------------- */
  --text-muted: var(--muted);
  --text-subtle: var(--hint);
  --border-strong: var(--border-2);
  --surface-2-alt: var(--surface-2);
  --accent-soft: #f4f4f5;
  --green: var(--success);
  --green-soft: var(--success-bg);
  --red: var(--danger);
  --red-soft: var(--danger-bg);
  --amber-soft: var(--amber-bg);
  --shadow-sm: var(--shadow-card);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Hiragino Sans",
               "Yu Gothic UI", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

a { color: inherit; text-decoration: none; }
a:hover { color: var(--text); }

/* --- Header ------------------------------------------------------- */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
  min-height: 48px;
}
.app-header-left { display: flex; align-items: center; }
.app-header-right { display: flex; align-items: center; gap: 10px; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}
.brand-logo {
  width: 26px; height: 26px;
  background: var(--accent);
  border-radius: 6px;
  display: grid;
  place-items: center;
  color: var(--accent-fg);
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
  transition: transform 0.15s ease;
}
.brand:active .brand-logo { transform: scale(0.92); }
.brand-name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.brand-edition {
  color: var(--muted);
  font-size: 12px;
  margin-left: 8px;
  font-weight: 400;
}

.main-nav {
  display: flex;
  gap: 2px;
  margin-left: 24px;
}
.main-nav a {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--muted);
  transition: background 0.1s ease, color 0.1s ease;
  white-space: nowrap;
}
.main-nav a:hover { background: var(--surface-2); color: var(--text); }
.main-nav a.active {
  background: var(--surface-2);
  color: var(--text);
  font-weight: 500;
}

/* --- Status pill -------------------------------------------------- */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  background: var(--success-bg);
  border-radius: 9999px;
  font-size: 12px;
  color: var(--success);
  white-space: nowrap;
  line-height: 1.4;
}
.status-pill::before {
  content: "";
  width: 6px; height: 6px;
  background: var(--success);
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.status-pill.loading { background: var(--surface-2); color: var(--muted); }
.status-pill.loading::before { background: var(--hint); animation: pill-pulse 1.2s ease-in-out infinite; }
.status-pill.err { background: var(--danger-bg); color: var(--danger); }
.status-pill.err::before { background: var(--danger); }
@keyframes pill-pulse { 0%,100% { opacity: 0.4; } 50% { opacity: 1; } }

/* --- Main layout -------------------------------------------------- */
.app-main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 24px;
}
.app-main--wide {
  max-width: 1600px;
}

/* --- Metrics (KPI cards) ----------------------------------------- */
.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
@media (max-width: 960px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
  .metrics { grid-template-columns: 1fr; }
}
.metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-height: 96px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.metric-label {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 6px;
}
.metric-value {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.metric-value.loading {
  color: var(--hint);
  font-weight: 400;
}
.metric-sub {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--hint);
  font-variant-numeric: tabular-nums;
}
.metric-sub.up { color: var(--success); }
.metric-sub.down { color: var(--danger); }

/* --- Split metric (1 枚のカード内に 2 値) ----------------------- */
.metric-split {
  display: grid;
  grid-template-columns: 1fr 1px 1fr;
  gap: 12px;
  align-items: stretch;
  flex: 1;
  min-height: 0;
}
.metric-split-cell {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-width: 0;
}
.metric-split-divider {
  background: var(--border);
  width: 1px;
  align-self: stretch;
}
.metric-split .metric-label {
  font-size: 11px;
  margin: 0 0 4px;
}
.metric-split .metric-value {
  font-size: 19px;
  margin: 0;
}
.metric-split .metric-sub {
  font-size: 11px;
  margin: 2px 0 0;
}
@media (max-width: 380px) {
  .metric-split { grid-template-columns: 1fr; }
  .metric-split-divider {
    width: auto; height: 1px;
  }
}

/* --- BM progress card (バックマージン進捗) ---------------------- */
.metric-bm .metric-value.bm-actual { color: var(--success); }
.metric-bm .bm-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
}
.metric-bm .bm-row .bm-row-v { color: var(--text); font-weight: 600; }

/* --- yc-card: 前年単価ベース比較 (検索結果に連動する横長 KPI) -----
 * yc-bar は display: contents で内部の 1 枚のワイドカードを metrics
 * グリッドに直接配置 (グリッド後半 2 スロットを span 2 で占有)。
 * 検索前 / 比較不能時は .show が外れ、カードが半透明プレースホルダ。
 * JS (bar.classList.add/remove('show')) のロジックは既存のまま維持。
 * --------------------------------------------------------------- */
/* .yc-bar.show も display: contents に上書き (既存 inline CSS の
   .yc-bar.show { display: block } は特異度 (0,2,0) で勝ってしまうので、
   こちらも同等特異度 + 宣言順で後勝ち) */
.yc-bar,
.yc-bar.show { display: contents; }
.yc-bar:not(.show) .yc-card {
  opacity: 0.45;
  filter: saturate(0);
}
.yc-card {
  grid-column: span 2;
  min-height: 0;
}
@media (max-width: 560px) {
  .yc-card { grid-column: auto; }
}
.yc-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.yc-card .yc-head .metric-label { margin: 0; }
.yc-extra-sub {
  margin: 0;
  font-size: 11px;
  color: var(--hint);
  font-variant-numeric: tabular-nums;
}
.yc-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.yc-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.yc-cell-k {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.03em;
}
/* ※ 注意: #yc-diff は JS が className を 'yc-v ${cls}' で置換するため、
   .yc-cell-v クラスが剥がれる。値スタイルは両セレクタで共有する。 */
.yc-cell-v,
.yc-cell .yc-v {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.yc-cell-val-line {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
}
.yc-card .yc-pct {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
}
.yc-cell .yc-v.up, .yc-card .yc-pct.up { color: var(--success); }
.yc-cell .yc-v.down, .yc-card .yc-pct.down { color: var(--danger); }
.yc-cell .yc-v.same, .yc-card .yc-pct.same { color: var(--muted); }

/* --- Cards -------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.card-title {
  font-size: 13px;
  font-weight: 600;
  margin: 0;
  color: var(--text);
}
.card-sub {
  font-size: 12px;
  color: var(--muted);
  margin-left: 10px;
  font-variant-numeric: tabular-nums;
}

/* --- Buttons ------------------------------------------------------ */
.btn {
  font-family: inherit;
  font-size: 13px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text);
  transition: background 0.1s ease, border-color 0.1s ease, color 0.1s ease;
  white-space: nowrap;
  line-height: 1.4;
  height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { border-color: var(--border-2); background: var(--surface-2); }
.btn:disabled {
  opacity: 0.5; cursor: not-allowed;
  background: var(--surface-2);
}
.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}
.btn-primary:hover {
  background: var(--accent-hover);
  color: var(--accent-fg);
  border-color: var(--accent-hover);
}
.btn-primary:disabled {
  background: var(--surface-2);
  color: var(--muted);
  border-color: var(--border);
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); border-color: transparent; }
.btn-danger {
  color: var(--danger);
}
.btn-danger:hover { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }
.btn-xs {
  height: 26px;
  padding: 3px 9px;
  font-size: 12px;
}

/* --- Inputs / selects -------------------------------------------- */
.input, .select,
input[type="text"].input, input[type="number"].input, select.input {
  font-family: inherit;
  font-size: 13px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  color: var(--text);
  height: 32px;
  line-height: 1.4;
  min-width: 0;
}
.input:focus, .select:focus,
input[type="text"].input:focus, input[type="number"].input:focus, select.input:focus {
  outline: 2px solid var(--info);
  outline-offset: -1px;
  border-color: var(--info);
}
.input::placeholder { color: var(--hint); }

/* --- Segmented control ------------------------------------------- */
.seg {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 0;
  height: 32px;
}
.seg > button,
.seg > label {
  background: transparent;
  border: 0;
  padding: 0 12px;
  font-size: 12px;
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  transition: color 0.1s ease;
}
.seg > button:hover,
.seg > label:hover { color: var(--text); }
.seg > button.on,
.seg > label input:checked + span,
.seg > button[aria-selected="true"],
.seg > button.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}
.seg > label { position: relative; }
.seg > label input { position: absolute; opacity: 0; pointer-events: none; }
.seg > label span {
  padding: 0 12px;
  height: 28px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
  transition: all 0.1s ease;
}

/* --- Search bar / toolbar ---------------------------------------- */
.toolbar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.toolbar .divider {
  width: 1px;
  height: 22px;
  background: var(--border);
}
.toolbar .spacer { flex: 1 1 auto; }

.period-badge {
  font-size: 11px;
  color: var(--muted);
  background: var(--surface-2);
  padding: 4px 10px;
  border-radius: 4px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* --- Tables ------------------------------------------------------- */
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data-table th, table.data-table td {
  padding: 9px 14px;
  text-align: left;
  vertical-align: top;
}
table.data-table thead th {
  background: #fafafa;
  font-weight: 500;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}
table.data-table tbody tr { border-top: 1px solid var(--border); }
table.data-table tbody tr:first-child { border-top: 0; }
table.data-table tbody tr:hover { background: #fafafa; }
table.data-table tbody tr.selected { background: #f4f4f5; }
table.data-table tbody tr.selected td:first-child {
  box-shadow: inset 2px 0 0 var(--accent);
}
table.data-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
table.data-table .num.bold { font-weight: 600; }
table.data-table .code {
  font-family: "SF Mono", "Menlo", Consolas, monospace;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
table.data-table .mute {
  color: var(--muted);
  font-size: 12px;
}

/* --- Result layout (検索結果 + サイドバー) ----------------------- */
.results-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 16px;
}
@media (max-width: 960px) {
  .results-layout { grid-template-columns: minmax(0, 1fr); }
}
.sidebar-card {
  padding: 16px;
  display: flex;
  flex-direction: column;
}

/* Phase 13-4: 左カードを card 高に充填、flex chain を末端まで伝播 */
.results-layout > .card:not(.sidebar-card) {
  display: flex;
  flex-direction: column;
}
.results-layout > .card:not(.sidebar-card) > .card-body.flush {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.results-layout > .card:not(.sidebar-card) > .card-body.flush > .table-wrap {
  flex: 1;
  min-height: 0;
  max-height: none;
  display: flex;
  flex-direction: column;
}
.results-layout > .card:not(.sidebar-card) > .card-body.flush > .table-wrap > #result-table-container {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
#result-table-container > .state {
  margin: auto;
}

/* Phase 13-5: 左右カードを viewport 下端まで伸ばす（body flex 化、index.html 専用） */
body.page-fit {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
body.page-fit .app-main {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
body.page-fit .metrics,
body.page-fit .toolbar {
  flex-shrink: 0;
}
body.page-fit .results-layout {
  flex: 1;
  min-height: 0;
}
body.page-fit .app-footer {
  flex-shrink: 0;
  margin: 16px auto 16px;
}
@media (max-height: 600px) {
  body.page-fit {
    height: auto;
    overflow: auto;
    display: block;
  }
  body.page-fit .app-main {
    overflow: visible;
    display: block;
  }
  body.page-fit .app-footer {
    margin: 32px auto 24px;
  }
}

/* Phase 13-6: 右カード（.sidebar-card）の内部スクロール */
body.page-fit .sidebar-card > .sidebar-title {
  flex-shrink: 0;
}
body.page-fit .sidebar-card > .cls-list {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
}
body.page-fit .sidebar-card > .cls-total {
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 12px;
  font-weight: 600;
  margin: 0 0 10px;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.cat-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.cat-row:last-of-type { border-bottom: 0; }
.cat-row .label { color: var(--muted); display: flex; align-items: center; gap: 8px; }
.cat-row .value { font-variant-numeric: tabular-nums; font-weight: 500; color: var(--text); }
.cat-row .value.muted { color: var(--hint); font-weight: 400; }
.cat-row .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--hint);
  flex-shrink: 0;
}
.cat-row[data-name="原料"]   .dot { background: #6366f1; }
.cat-row[data-name="資材"]   .dot { background: #0891b2; }
.cat-row[data-name="中間品"] .dot { background: #10b981; }
.cat-row[data-name="その他"] .dot { background: #a1a1aa; }
.cat-total {
  display: flex;
  justify-content: space-between;
  padding: 10px 0 0;
  margin-top: 8px;
  border-top: 1px solid var(--border-2);
  font-weight: 600;
  gap: 12px;
}
.cat-total .label { color: var(--text); }
.cat-total .value { font-variant-numeric: tabular-nums; font-size: 14px; }

/* --- Footer ------------------------------------------------------- */
.app-footer {
  max-width: var(--maxw);
  margin: 32px auto 24px;
  padding: 0 24px;
  text-align: center;
  font-size: 12px;
  color: var(--hint);
}
.app-footer a { color: var(--muted); }
.app-footer a:hover { text-decoration: underline; }

/* --- States / utilities ------------------------------------------ */
.state {
  padding: 48px 20px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}
.state-icon { font-size: 18px; margin-right: 6px; opacity: 0.7; }
.state.err { color: var(--danger); }
.hidden { display: none !important; }

/* skeleton shimmer (既存 index.html が使用) */
.skeleton {
  display: inline-block;
  height: 1em;
  width: 100%;
  background: linear-gradient(90deg, var(--surface-2) 0%, #eaeaec 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.2s ease-in-out infinite;
  border-radius: 4px;
}
@keyframes skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* --- Back link (trend/backmargin の戻る) ------------------------- */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
}
.back-link:hover { background: var(--surface-2); color: var(--text); }

/* --- Tier table (Phase 12: 段階料率) ----------------------------- */
table.tier-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}
table.tier-table th, table.tier-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
table.tier-table thead th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
table.tier-table th.num, table.tier-table td.num { text-align: right; }
table.tier-table input[type="number"] {
  width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 12.5px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
table.tier-table input[type="number"]:focus {
  outline: 2px solid var(--info);
  outline-offset: -1px;
  border-color: var(--info);
}
table.tier-table .tier-row-del {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  font-size: 14px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  line-height: 1;
}
table.tier-table .tier-row-del:hover {
  background: var(--danger-bg);
  color: var(--danger);
}

/* --- Progress section (Phase 12: 段階契約の進捗カード) ----------- */
.tier-progress {
  margin-top: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.tier-progress .tp-cum {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  margin-bottom: 8px;
}
.tier-progress .tp-cum-amt {
  font-size: 22px; font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.tier-progress .tp-cum-label { font-size: 12px; color: var(--muted); }
.tier-progress .tp-bar {
  width: 100%; height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  margin: 4px 0 8px;
}
.tier-progress .tp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--info));
  transition: width 0.4s ease;
}
.tier-progress .tp-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 8px 0;
  font-size: 12.5px;
}
@media (max-width: 720px) {
  .tier-progress .tp-meta { grid-template-columns: 1fr; }
}
.tier-progress .tp-cell {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}
.tier-progress .tp-cell-k { color: var(--muted); font-size: 11px; }
.tier-progress .tp-cell-v { font-variant-numeric: tabular-nums; font-weight: 600; }

.tier-progress .tp-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  font-size: 12.5px;
}
.tier-progress .tp-list li {
  padding: 5px 10px;
  border-bottom: 1px dashed var(--border);
  display: flex; justify-content: space-between;
  font-variant-numeric: tabular-nums;
}
.tier-progress .tp-list li:last-child { border-bottom: 0; }
.tier-progress .tp-list li.current {
  background: var(--info-bg);
  font-weight: 700;
  border-radius: var(--radius-sm);
  border-bottom: 0;
}

/* =====================================================================
 * Phase 14-1: AI 価格交渉候補 — UI ベース (POP オーバーライドは Step 14-1.3-B で yoko-mode.css へ)
 * ===================================================================== */

/* --- AI dropdown (header 内) ---------------------------------------- */
.ai-dropdown { position: relative; display: inline-flex; }
.ai-dropdown-trigger { white-space: nowrap; }
.ai-dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 4px;
  display: none;
  z-index: 55;          /* header (50) より上、modal (60+) より下 */
}
.ai-dropdown.open .ai-dropdown-menu { display: block; }
.ai-dropdown-item {
  display: block;
  width: 100%;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}
.ai-dropdown-item:hover { background: var(--surface-2); }

/* --- PN modal (大型) ------------------------------------------------ */
.modal.pn-modal {
  width: min(1200px, 90vw);
  max-width: none;
  min-width: min(800px, 100%);
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.modal.pn-modal .modal-header { flex-shrink: 0; }
.pn-modal-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.pn-toolbar { margin-bottom: 0; flex-shrink: 0; }
.pn-toolbar-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.pn-custom-dates { display: inline-flex; gap: 6px; align-items: center; }

/* --- Loading 段階表示 ----------------------------------------------- */
.pn-loading {
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.pn-loading-step {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  font-size: 13px;
  color: var(--muted);
}
.pn-loading-step .pn-step-icon { display: inline-block; min-width: 18px; }
.pn-loading-step .pn-step-icon::before { content: '○'; opacity: 0.5; }
.pn-loading-step.active .pn-step-icon::before { content: '⏳'; opacity: 1; }
.pn-loading-step.done .pn-step-icon::before { content: '✓'; opacity: 1; color: var(--success); }
.pn-loading-step.active { color: var(--text); font-weight: 600; }
.pn-loading-step.done { color: var(--success); }

/* --- Warning / summary / error bars -------------------------------- */
.pn-warn-bar {
  padding: 10px 14px;
  background: var(--amber-bg);
  border: 1px solid var(--amber);
  border-radius: var(--radius);
  font-size: 12.5px;
  color: var(--amber);
}
.pn-summary-bar {
  padding: 8px 12px;
  font-size: 12px;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}
.pn-error {
  padding: 10px 14px;
  background: var(--danger-bg);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--danger);
}

/* --- Initial placeholder ------------------------------------------- */
.pn-initial {
  padding: 32px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.pn-initial p { margin: 6px 0; }
.pn-initial-note { font-size: 11.5px; color: var(--hint); margin-top: 14px; }

/* --- Results table ------------------------------------------------- */
.pn-results-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}
table.pn-results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.pn-results-table thead th {
  background: var(--surface-2);
  text-align: left;
  padding: 9px 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.pn-results-table thead th.num { text-align: right; }
table.pn-results-table thead th.sortable { cursor: pointer; }
table.pn-results-table thead th.sortable:hover { background: var(--border); }
table.pn-results-table thead th.sorted { color: var(--accent); }
table.pn-results-table .sort-icon { margin-left: 4px; opacity: 0.5; font-size: 10px; }
table.pn-results-table thead th.sorted .sort-icon { opacity: 1; }
table.pn-results-table tbody tr.pn-row {
  cursor: pointer;
  border-top: 1px solid var(--border);
  transition: background 0.1s ease;
}
table.pn-results-table tbody tr.pn-row:hover { background: var(--surface-2); }
table.pn-results-table tbody tr.pn-row.expanded { background: var(--surface-2); }
table.pn-results-table tbody td { padding: 9px 10px; vertical-align: top; }
table.pn-results-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.pn-col-toggle   { width: 30px; color: var(--muted); }
.pn-col-code     { width: 100px; white-space: nowrap; }
.pn-col-name     { min-width: 200px; word-break: break-word; }
.pn-col-supplier { width: 200px; word-break: break-word; }
.pn-col-rec      { width: 80px; }
.pn-col-yoy      { width: 90px; }
.pn-col-amount   { width: 120px; white-space: nowrap; }
.pn-rec-stars { color: var(--accent); font-size: 14px; letter-spacing: 1px; }
.pn-yoy-up   { color: var(--danger); font-weight: 600; }
.pn-yoy-down { color: var(--success); }
.pn-yoy-flat { color: var(--muted); }

/* --- Detail row (accordion) ---------------------------------------- */
.pn-detail-row { background: var(--surface-2); }
.pn-detail-row td { padding: 14px 18px; }
.pn-detail { font-size: 13px; line-height: 1.7; color: var(--text); }
.pn-detail-summary { margin: 0 0 8px; font-size: 13px; color: var(--text); }
.pn-detail-analysis { margin: 0 0 10px; }
.pn-detail-approach {
  padding: 8px 12px;
  background: var(--surface);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
}

/* --- Account management modal (Phase 18c Sprint 2) ----------------- */
.modal.account-modal { max-width: 1100px; }

/* --- Edit account checkbox (Phase 18c Sprint 3) -------------------- */
.edit-account-perm input[type="checkbox"] { cursor: pointer; }
.edit-account-perm input[type="checkbox"]:disabled { cursor: not-allowed; opacity: 0.5; }
.edit-account-perm input[type="checkbox"]:disabled + span { opacity: 0.6; }

/* --- User menu (Phase 18c Sprint 1) -------------------------------- */
.user-menu { position: relative; display: inline-flex; align-items: center; margin-left: 12px; }
.user-menu-trigger { background: none; border: none; color: inherit; font-size: 14px; cursor: pointer; padding: 4px 8px; border-radius: 4px; font-family: inherit; }
.user-menu-trigger:hover { background-color: rgba(0, 0, 0, 0.05); }
.user-menu-dropdown { position: absolute; top: 100%; right: 0; margin-top: 8px; background: white; border: 1px solid #e5e7eb; border-radius: 8px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); z-index: 101; min-width: 200px; display: none; }
.user-menu-dropdown.open { display: block; }
.user-menu-info { padding: 12px 16px; font-size: 13px; border-bottom: 1px solid #e5e7eb; }
.user-menu-info > div:first-child { font-weight: 600; color: #1f2937; }
.user-menu-info > div:last-child { font-size: 12px; color: #6b7280; margin-top: 2px; }
.user-menu-divider { margin: 0; border: none; border-top: 1px solid #e5e7eb; }
.user-menu-item { display: block; width: 100%; padding: 10px 16px; background: none; border: none; color: #374151; font-size: 13px; text-align: left; cursor: pointer; font-family: inherit; }
.user-menu-item:hover { background-color: #f9fafb; }
.user-menu-item:last-child { color: #ef4444; }

/* --- Print: neutralize hover etc ---------------------------------- */
@media print {
  .app-header, .toolbar, .app-footer, .main-nav, .status-pill { display: none !important; }
  .app-main { padding: 0; max-width: none; }
  .card { border: 1px solid #ccc; box-shadow: none; }
}
