/* ==========================================================================
   YOSAN — Modern Minimal Theme (案1)
   v1.4: 「堅苦しい」office 風から、明るく親しみやすい SaaS 風へ刷新。
   既存クラス名はすべて維持 (app.js 側の変更不要)。
   ========================================================================== */
:root {
  /* === カラーパレット === */
  --bg: #f6f8fb;             /* ページ背景 (ほのかなブルーグレー) */
  --panel: #ffffff;          /* パネル背景 */
  --surface-2: #fafbfd;      /* テーブルヘッダ等の控えめな面 */
  --border: #e6eaf0;         /* メイン罫線 */
  --border-soft: #f1f5f9;    /* 行罫線などより薄い線 */
  --text: #1f2937;
  --muted: #6b7785;
  --muted-strong: #475569;

  --primary: #2563eb;
  --primary-strong: #1e40af;
  --primary-tint: #eff5ff;
  --primary-tint-strong: #dbeafe;

  --success: #10b981;
  --success-tint: #d1fae5;
  --success-strong: #047857;
  --warning: #f59e0b;
  --warning-tint: #fef3c7;
  --warning-strong: #b45309;
  --danger: #f97066;          /* 旧 #b91c1c より柔らかいコーラル */
  --danger-tint: #fee2e2;
  --danger-strong: #b91c1c;
  --info-tint: #eff6ff;

  /* === シャドウ (オフィス風強調 → 控えめでフラット) === */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-md: 0 4px 14px rgba(15, 23, 42, .06);
  --shadow-lg: 0 12px 28px rgba(15, 23, 42, .10);

  /* === radius === */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-pill: 999px;

  /* === transition === */
  --t-fast: .12s ease;
}

* { box-sizing: border-box; }

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

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

/* ==========================================================================
   Buttons
   ========================================================================== */
button, .btn-link {
  font: inherit; padding: 7px 14px; border-radius: var(--r-md);
  border: 1px solid var(--border); background: #fff; color: var(--text);
  cursor: pointer; transition: background var(--t-fast), border-color var(--t-fast),
                                box-shadow var(--t-fast), transform var(--t-fast);
  font-weight: 500;
}
button:hover, .btn-link:hover {
  background: #f3f6fb; border-color: #d6dbe4; text-decoration: none;
}
button:active { transform: translateY(1px); }
button.primary {
  background: var(--primary); color: #fff; border-color: var(--primary);
  box-shadow: 0 1px 0 rgba(255,255,255,.15) inset, var(--shadow-sm);
}
button.primary:hover { background: var(--primary-strong); border-color: var(--primary-strong); }
button.danger { background: var(--danger-strong); color: #fff; border-color: var(--danger-strong); }
button.danger:hover { background: #991b1b; border-color: #991b1b; }
button:disabled { opacity: .5; cursor: not-allowed; }
button:disabled:hover { background: #fff; border-color: var(--border); transform: none; }

a.btn-link {
  display: inline-block; text-decoration: none;
}

/* ==========================================================================
   SCR-03 明細編集 — 表 横の操作ボタン列 (v1.4 2026-04-28)
   ========================================================================== */
/* 表とボタンを並べる外殻。狭画面では下に折返す */
.sheet-with-actions {
  display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap;
}
.sheet-with-actions > .sheet-pane { flex: 1 1 0; min-width: 0; }
.sheet-with-actions > .actions-pane {
  flex: 0 0 auto; width: 200px;
  position: sticky; top: 12px;
  display: flex; flex-direction: column; gap: 6px;
}
/* セクション間の小見出し (薄いラベル) */
.sheet-with-actions > .actions-pane .actions-label {
  font-size: 10.5px; color: var(--muted, #6b7785);
  text-transform: uppercase; letter-spacing: .04em;
  margin: 6px 0 -2px 2px;
}
.sheet-with-actions > .actions-pane .actions-label:first-child { margin-top: 0; }
/* 各ボタンを 100% 幅 + 中央寄せ */
.sheet-with-actions > .actions-pane button,
.sheet-with-actions > .actions-pane a.btn-link {
  width: 100%; text-align: center; box-sizing: border-box;
}
/* 提出ボタンは目立つように下にスペース */
.sheet-with-actions > .actions-pane .submit-row { margin-top: 6px; }
/* 狭画面 (< 1100px) では横並びを解除 (sticky も無効化) */
@media (max-width: 1100px) {
  .sheet-with-actions > .actions-pane {
    width: 100%; position: static; flex-direction: row; flex-wrap: wrap;
  }
  .sheet-with-actions > .actions-pane button,
  .sheet-with-actions > .actions-pane a.btn-link { width: auto; }
  .sheet-with-actions > .actions-pane .actions-label {
    width: 100%; margin: 4px 0 -2px 0;
  }
}

/* ==========================================================================
   Form controls
   ========================================================================== */
input, select, textarea {
  font: inherit; padding: 6px 10px; border-radius: var(--r-md);
  border: 1px solid var(--border); background: #fff; color: var(--text);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
input:hover, select:hover, textarea:hover { border-color: #d6dbe4; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-tint);
}
input[type=checkbox], input[type=radio] { padding: 0; }
textarea { font-family: inherit; }

/* ==========================================================================
   App Layout
   ========================================================================== */
.app {
  display: grid; grid-template-columns: 240px 1fr;
  grid-template-rows: auto 1fr; min-height: 100vh;
  grid-template-areas: "header header" "nav main";
}

/* ヘッダ: ダークネイビー → 白に変更 (sidebar と一体化) */
.app > header {
  grid-area: header; background: #ffffff; color: var(--text);
  padding: 12px 24px; display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.app > header h1 { font-size: 15px; margin: 0; font-weight: 600; letter-spacing: -.005em; }
.app > header .who { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.app > header .who button { margin-left: 4px; padding: 5px 12px; }

/* サイドバー: 白基調 + アイテムごと角丸 */
nav.side {
  grid-area: nav; background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 14px 12px; overflow-y: auto;
}
nav.side ul { list-style: none; padding: 0; margin: 0; }
nav.side li { margin: 0; }
nav.side a {
  display: block; padding: 8px 12px; color: var(--muted-strong); font-size: 13px;
  border-radius: var(--r-md); margin: 1px 0;
  transition: background var(--t-fast), color var(--t-fast);
}
nav.side a:hover { background: #f1f5f9; color: var(--text); text-decoration: none; }
nav.side a.active {
  background: var(--primary-tint); color: var(--primary); font-weight: 600;
}
nav.side .section {
  padding: 14px 12px 4px; font-size: 10px; color: var(--muted);
  letter-spacing: .12em; text-transform: uppercase; font-weight: 700;
}

main { grid-area: main; padding: 20px 24px; overflow: auto; }

/* ==========================================================================
   Panels & Headings
   ========================================================================== */
.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow-sm);
}
h1 { font-size: 22px; margin: 0 0 12px; font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: 18px; margin: 0 0 12px; font-weight: 600; letter-spacing: -.005em; }
h3 { font-size: 15px; margin: 0 0 10px; font-weight: 600; }
h4 { font-size: 14px; margin: 0 0 8px; font-weight: 600; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > * { margin: 0; }

/* ==========================================================================
   Tables (一般)
   ========================================================================== */
table {
  border-collapse: separate; border-spacing: 0;
  width: 100%; background: #fff; font-size: 13px;
}
table th, table td {
  border: none;
  border-bottom: 1px solid var(--border-soft);
  padding: 10px 12px; text-align: left; vertical-align: top;
}
table th {
  background: var(--surface-2); font-weight: 600; color: var(--muted-strong);
  font-size: 12px; letter-spacing: .02em;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 1;
}
table td.num, table th.num { text-align: right; font-variant-numeric: tabular-nums; }
table tbody tr { transition: background var(--t-fast); }
table tbody tr:hover { background: var(--primary-tint); }
tr.dim { color: var(--muted); }

/* ==========================================================================
   Badges (角丸 pill + ソフトカラー)
   ========================================================================== */
.badge {
  display: inline-block; padding: 2px 10px; border-radius: var(--r-pill);
  font-size: 11px; background: #e5e7eb; color: #374151; font-weight: 500;
  letter-spacing: .02em;
}
.badge.draft     { background: #f1f5f9; color: #475569; }
.badge.submitted { background: var(--info-tint); color: var(--primary-strong); }
.badge.returned  { background: var(--danger-tint); color: var(--danger-strong); }
.badge.approved  { background: var(--success-tint); color: var(--success-strong); }
.badge.fixed     { background: #ede9fe; color: #6d28d9; }
.badge.withdrawn { background: #f5f5f4; color: #57534e; }
.badge.entry_open        { background: var(--info-tint); color: var(--primary-strong); }
.badge.submission_closed { background: var(--warning-tint); color: var(--warning-strong); }
.badge.approval_locked   { background: #fde68a; color: #78350f; }
.badge.fixed_locked      { background: var(--danger-tint); color: var(--danger-strong); }

/* ==========================================================================
   Status messages
   ========================================================================== */
.error   { background: var(--danger-tint); color: var(--danger-strong);
           padding: 10px 14px; border-radius: var(--r-md);
           border: 1px solid #fecaca; }
.warning { background: var(--warning-tint); color: var(--warning-strong);
           padding: 10px 14px; border-radius: var(--r-md);
           border: 1px solid #fde68a; }
.success { background: var(--success-tint); color: var(--success-strong);
           padding: 10px 14px; border-radius: var(--r-md);
           border: 1px solid #a7f3d0; }
.muted   { color: var(--muted); font-size: 12px; }

/* ==========================================================================
   Sheet (SCR-03 編集表) — Excel ライクな見た目を維持しつつソフトに
   ========================================================================== */
.sheet {
  overflow: auto; max-height: 70vh;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: #fff;
}
.sheet table { font-size: 12.5px; table-layout: fixed; }
.sheet table th, .sheet table td {
  border: 1px solid var(--border-soft);
  padding: 5px 8px;
}
.sheet table th {
  background: var(--surface-2); font-weight: 600; color: var(--muted-strong);
  border-bottom: 1px solid var(--border);
  /* v1.4 (2026-04-28 第19版): スクロールしても列名 (thead) が固定表示されるよう sticky */
  position: sticky; top: 0; z-index: 2;
}
/* tfoot (合計行) も下端に固定して、スクロールでも合計が見える */
.sheet table tfoot td {
  position: sticky; bottom: 0; z-index: 2;
  background: #f6f6f8;
  border-top: 1px solid var(--border);
}
.sheet table tbody tr:hover { background: transparent; }
.sheet input, .sheet select {
  width: 100%; padding: 4px 6px; border: 1px solid transparent;
  background: transparent; box-sizing: border-box; border-radius: 4px;
}
.sheet input:hover, .sheet select:hover { border-color: var(--border); background: #fff; }
.sheet input:focus, .sheet select:focus {
  outline: none; border-color: var(--primary); background: #fff;
  box-shadow: 0 0 0 2px var(--primary-tint);
}
.sheet tr.changed { background: #fff7ed; }
.sheet tr.changed td { background: inherit; }
/* v1.4 (2026-04-28 第24版): 編集されたセル単位のハイライト
   行全体は薄オレンジ (.changed) のまま、編集セルだけ さらに濃いオレンジ + 左の細枠 */
.sheet td.cell-changed {
  background: #ffe4b5 !important;
  box-shadow: inset 3px 0 0 #f59e0b;
}

/* SCR-03 列リサイズ */
.sheet th { position: relative; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet th .col-resizer {
  position: absolute; right: 0; top: 0; bottom: 0; width: 6px;
  cursor: col-resize; user-select: none;
}
.sheet th .col-resizer:hover { background: rgba(37, 99, 235, .25); }
.sheet th.col-resizing .col-resizer { background: rgba(37, 99, 235, .5); }
.sheet td { overflow: hidden; }

/* ==========================================================================
   Data table (一覧画面用 自動幅)
   ========================================================================== */
table.data-table {
  table-layout: auto;
  border-collapse: separate;
  border-spacing: 0;
  width: max-content;
  min-width: 100%;
}
table.data-table th, table.data-table td {
  white-space: nowrap; vertical-align: middle;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-soft);
  border-left: none; border-right: none; border-top: none;
}
table.data-table td.wrap, table.data-table th.wrap { white-space: normal; }
table.data-table td.num, table.data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data-table tbody tr:hover { background: var(--primary-tint); }

/* リサイズハンドル */
table.resizable-table th { position: relative; }
table.resizable-table th .col-resizer {
  position: absolute; right: 0; top: 0; bottom: 0; width: 6px;
  cursor: col-resize; user-select: none; background: transparent;
}
table.resizable-table th .col-resizer:hover { background: rgba(37, 99, 235, .25); }
table.resizable-table th.col-resizing .col-resizer { background: rgba(37, 99, 235, .5); }

/* スクロールコンテナ */
.table-scroll {
  overflow: auto; max-height: 75vh;
  border: 1px solid var(--border); border-radius: var(--r-md); background: #fff;
}

.panel > table,
.panel table.resizable-table {
  border-collapse: separate; border-spacing: 0;
}
.panel table.resizable-table th { position: relative; }

/* dialog 内テーブル */
dialog table.resizable-table {
  table-layout: auto; border-collapse: separate; border-spacing: 0;
  width: max-content; min-width: 100%;
}
dialog table.resizable-table th,
dialog table.resizable-table td {
  white-space: nowrap; vertical-align: middle;
}
dialog table.resizable-table td.num,
dialog table.resizable-table th.num { text-align: right; }
dialog table.resizable-table th { position: relative; }

/* ==========================================================================
   Forms / Misc layout helpers
   ========================================================================== */
.grid-form { display: grid; grid-template-columns: max-content 1fr; gap: 10px 14px; align-items: center; }
.flex-grow { flex: 1; }

/* ==========================================================================
   Login box (フローティングカード)
   ========================================================================== */
.login-box {
  max-width: 380px; margin: 80px auto; background: #fff;
  padding: 36px 32px; border-radius: var(--r-lg);
  border: 1px solid var(--border); box-shadow: var(--shadow-lg);
}
.login-box h2 { text-align: center; margin-bottom: 18px; }
.login-box label { display: block; margin: 12px 0 4px; font-weight: 600; color: var(--muted-strong); font-size: 12px; }
.login-box input { width: 100%; padding: 8px 12px; }
.login-box button { width: 100%; margin-top: 18px; padding: 10px; font-weight: 600; }

/* ==========================================================================
   Key-Value display
   ========================================================================== */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { font-weight: 600; color: var(--muted); }
.kv dd { margin: 0; }

/* ==========================================================================
   Dialog
   ========================================================================== */
dialog {
  border: 1px solid var(--border); border-radius: var(--r-lg); padding: 24px;
  min-width: 400px; max-width: 80vw; box-shadow: var(--shadow-lg);
  background: #fff;
}
dialog::backdrop { background: rgba(15, 23, 42, .45); backdrop-filter: blur(2px); }

/* ==========================================================================
   Tabs
   ========================================================================== */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tabs a {
  padding: 8px 16px; border: 1px solid transparent; border-bottom: none;
  color: var(--muted); cursor: pointer; border-radius: var(--r-md) var(--r-md) 0 0;
  font-weight: 500;
}
.tabs a:hover { background: #f1f5f9; color: var(--text); text-decoration: none; }
.tabs a.active {
  border-color: var(--border); background: var(--panel); color: var(--primary);
  font-weight: 600; position: relative; top: 1px;
}

/* ==========================================================================
   Toast (もし app.js で .toast クラスを使っている場合)
   ========================================================================== */
.toast {
  border-radius: var(--r-md); box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}

/* ==========================================================================
   スクロールバー (Webkit) — slim でモダンに
   ========================================================================== */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: #cbd5e1; border-radius: 5px; border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
::-webkit-scrollbar-track { background: transparent; }
