/* ============================================
   請求比較表 UI スタイル
   配置先: /demo-2/invoice-data/css/style.css
   作成: 2026-05-07 (v2: summary準拠 全面刷新)
============================================ */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  font-family: 'Yu Gothic', 'Meiryo', 'Hiragino Sans', sans-serif;
  background: #f5f6f8;
  color: #222;
  font-size: 13px;
  height: 100vh;
  overflow: hidden;
}

/* ===== ヘッダー ===== */
.app-header {
  background: linear-gradient(180deg, #2c3e50 0%, #34495e 100%);
  color: #fff;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 2px solid #1a252f;
  flex-shrink: 0;
}

.app-header .back-link {
  color: #ecf0f1;
  text-decoration: none;
  font-size: 18px;
  padding: 4px 10px;
  border: 1px solid #4a5d70;
  border-radius: 4px;
  transition: background 0.15s;
}

.app-header .back-link:hover {
  background: rgba(255, 255, 255, 0.1);
}

.app-header h1 {
  font-size: 18px;
  font-weight: 700;
}

.app-header .subtitle {
  font-size: 12px;
  color: #bdc3c7;
  margin-left: 8px;
}

/* ===== ツールバー ===== */
.toolbar {
  background: #fff;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid #d6d9dc;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.toolbar button {
  padding: 6px 14px;
  font-size: 13px;
  border: 1px solid #c4c8cc;
  background: #fff;
  color: #333;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.toolbar button:hover:not(:disabled) {
  background: #f0f2f5;
  border-color: #999;
}

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

.toolbar button.btn-primary  { background: #3498db; color: #fff; border-color: #2980b9; }
.toolbar button.btn-primary:hover:not(:disabled)  { background: #2980b9; }
.toolbar button.btn-success  { background: #27ae60; color: #fff; border-color: #229954; }
.toolbar button.btn-success:hover:not(:disabled)  { background: #229954; }
.toolbar button.btn-danger   { background: #e74c3c; color: #fff; border-color: #c0392b; }
.toolbar button.btn-danger:hover:not(:disabled)   { background: #c0392b; }
.toolbar button.btn-warn     { background: #f39c12; color: #fff; border-color: #d68910; }
.toolbar button.btn-warn:hover:not(:disabled)     { background: #d68910; }

.toolbar .spacer { flex: 1; }

.toolbar .info {
  font-size: 12px;
  color: #666;
  padding: 0 8px;
}

.toolbar .info strong {
  color: #2c3e50;
  font-size: 14px;
}

.toolbar .save-status {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 3px;
  background: #ecf0f1;
  color: #555;
  min-width: 100px;
  text-align: center;
}

.toolbar .save-status.saving { background: #fff4d4; color: #b8870a; }
.toolbar .save-status.saved  { background: #d4edda; color: #155724; }
.toolbar .save-status.error  { background: #f8d7da; color: #721c24; }

/* ===== 凡例 ===== */
.legend {
  background: #fdf6e3;
  border-bottom: 1px solid #f0e0a8;
  padding: 6px 16px;
  font-size: 11px;
  color: #6b5b00;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  flex-shrink: 0;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-cell {
  display: inline-flex;
  flex-direction: column;
  border: 1px solid #999;
  background: #fff;
  padding: 2px 6px;
  text-align: right;
  min-width: 64px;
  line-height: 1.1;
}

.legend-amount-top { color: #c0392b; font-weight: 700; font-size: 12px; }
.legend-amount-bot { color: #888; font-size: 10px; text-decoration: line-through; }

/* ===== レイアウト ===== */
.app-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ===== テーブルコンテナ ===== */
.table-container {
  flex: 1;
  overflow: auto;
  background: #fff;
  position: relative;
}

table.invoice-table {
  border-collapse: separate;
  border-spacing: 0;
  width: max-content;
  min-width: 100%;
}

/* ===== 3行ヘッダー ===== */
table.invoice-table thead {
  position: sticky;
  top: 0;
  z-index: 10;
}

/* 2026-06-01: 落ち着いた統一配色ヘッダー
   ・グループ帯(1行目)= ミュートカラー + 白文字
   ・業者名(2行目)   = 同系色の薄トーン
   ・金額/重量(3行目)・基本情報列 = 薄グレーのニュートラル
   ・業者ごとのバラバラな個別色(赤/紫/緑など)は廃止して統一 */
table.invoice-table thead th {
  background: #eef2f7;       /* ニュートラルな薄スレートグレー */
  color: #1f2d3d;
  font-weight: 700;
  font-size: 15px;          /* 2026-05-08: ヘッダーも大きく(セル17pxより少し小さく) */
  padding: 7px 5px;
  border: 1px solid #c2ccd9;
  text-align: center;
  white-space: nowrap;
  user-select: none;
}

table.invoice-table thead .col-check {
  width: 36px;
  min-width: 36px;
  background: #dfe6ef;       /* チェック列(Excelの行番号列風) */
}

/* ===== グループ帯(1行目): 落ち着いた3色 + 白文字 ===== */
table.invoice-table thead th.grp-steel     { background: #5b6b8c; color: #fff; border-color: #4a5876; }
table.invoice-table thead th.grp-yamashita { background: #4e8a7c; color: #fff; border-color: #3f7367; }
table.invoice-table thead th.grp-laser     { background: #b5894e; color: #fff; border-color: #9a7340; }

/* ===== 業者名(2行目): グループ色の薄トーンで統一(個別色は廃止) ===== */
table.invoice-table thead tr.hdr-vendor th.grp-steel     { background: #d8deea; color: #2c3a52; }
table.invoice-table thead tr.hdr-vendor th.grp-yamashita { background: #d3e7e1; color: #234a42; }
table.invoice-table thead tr.hdr-vendor th.grp-laser     { background: #ecdcc3; color: #5c4318; }

/* ===== ボディ ===== */
table.invoice-table tbody td {
  border: 1px solid #d6d9dc;
  padding: 0;
  background: #fff;
  vertical-align: middle;
  min-height: 36px;       /* 17px文字に対応する余裕高さ */
  font-size: 17px;        /* セル本体の文字サイズ(2026-05-08: 大きく) */
  line-height: 1.4;
}

table.invoice-table tbody tr:nth-child(even) td { background: #fafbfc; }
table.invoice-table tbody tr:hover td { background: #fff8e7; }
table.invoice-table tbody tr.selected td { background: #e3f2fd; }
table.invoice-table tbody tr.selected:hover td { background: #d0e7f7; }

table.invoice-table td.cell-check {
  text-align: center;
  width: 36px;
}

table.invoice-table td.cell-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

table.invoice-table td .cell-input {
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  padding: 6px 8px;        /* 文字大きくなった分パディングも増やす */
  font: inherit;           /* 親td(17px)を継承 */
  font-size: 17px;
  color: inherit;
  outline: none;
  line-height: 1.4;
}

table.invoice-table td .cell-input:focus {
  background: #fffbe5;
  box-shadow: inset 0 0 0 2px #f1c40f;
}

table.invoice-table td.cell-numeric .cell-input {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;     /* 数値は折り返さない */
}

table.invoice-table td.cell-text .cell-input {
  text-align: left;
}

/* ===== セル内折り返し(文字列列のみ) ===== */
/* 文字列列はtextareaにして自動折り返し */
table.invoice-table td.cell-text {
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}

table.invoice-table td .cell-textarea {
  width: 100%;
  min-height: 36px;
  border: none;
  background: transparent;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 17px;
  color: inherit;
  outline: none;
  line-height: 1.4;
  resize: none;        /* 手動リサイズ無効 */
  overflow: hidden;    /* スクロールバーを隠す。高さはJSで自動調整 */
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  box-sizing: border-box;
  vertical-align: middle;
  display: block;
}

table.invoice-table td .cell-textarea:focus {
  background: #fffbe5;
  box-shadow: inset 0 0 0 2px #f1c40f;
}

/* 数値列は折り返しなし */
table.invoice-table td.cell-numeric {
  text-align: right;
  white-space: nowrap;
}

/* ===== 再計算採用セルの2段表示 ===== */
table.invoice-table td.cell-recalc-used {
  background: #fff5f5 !important;
  padding: 0;
  position: relative;
}

table.invoice-table tbody tr:nth-child(even) td.cell-recalc-used {
  background: #fff0f0 !important;
}

.amount-stack {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 36px;
}

.amount-stack .amount-top {
  flex: 1;
  border-bottom: 1px dashed #f5b7b1;
}

.amount-stack .amount-top .cell-amount-input {
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  padding: 2px 6px;
  font: inherit;
  outline: none;
  text-align: right;
  color: #c0392b;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.amount-stack .amount-top .cell-amount-input:focus {
  background: #fff5e8;
  box-shadow: inset 0 0 0 2px #f1c40f;
}

.amount-stack .amount-bot {
  padding: 1px 6px;
  font-size: 10px;
  color: #888;
  text-align: right;
  text-decoration: line-through;
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
}

/* ===== グループ小計行 ===== */
table.invoice-table tbody tr.subtotal-row td {
  background: #d6eaf8 !important;
  font-weight: 700;
  color: #1a5490;
  border-top: 2px solid #5dade2;
  border-bottom: 2px solid #5dade2;
  height: 32px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

table.invoice-table tbody tr.subtotal-row td.subtotal-label {
  background: #aed6f1 !important;
  color: #1a5490;
  text-align: left;
  padding: 4px 10px;
  font-size: 13px;
}

table.invoice-table tbody tr.subtotal-row td.subtotal-empty {
  background: #d6eaf8 !important;
}

/* ===== 総合計行(全グループの最後) ===== */
table.invoice-table tbody tr.grandtotal-row td {
  background: #34495e !important;
  color: #fff !important;
  font-weight: 700;
  border-top: 3px double #fff;
  border-bottom: 2px solid #2c3e50;
  height: 36px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
}

table.invoice-table tbody tr.grandtotal-row td.subtotal-label {
  background: #2c3e50 !important;
  color: #fff !important;
  text-align: left;
  padding: 4px 10px;
}

/* グループ表示中はカーソルを少しだけ識別しやすく */
table.invoice-table tbody.is-grouped tr[data-id] td.col-project {
  border-left: 3px solid #aed6f1;
}

/* ON状態のボタン */
.toolbar button#groupToggleBtn.is-active {
  background: #2980b9;
  color: #fff;
  border-color: #1f618d;
}

/* ===== カラム幅 =====
   2026-05-08: 文字サイズ17pxに合わせて少し広めに調整 */
.col-billing-month { min-width: 90px;  max-width: 100px; }
.col-estimate      { min-width: 100px; max-width: 130px; }
.col-work-month    { min-width: 80px;  max-width: 100px; }
.col-jobno         { min-width: 110px; max-width: 130px; }
.col-customer      { min-width: 110px; max-width: 150px; }
.col-project       { min-width: 200px; max-width: 280px; }
.col-item          { min-width: 180px; max-width: 240px; }
.col-seisaku       { min-width: 100px; max-width: 130px; }
.col-set           { min-width: 100px; max-width: 130px; }

.col-steel-amount    { min-width: 110px; max-width: 130px; }
.col-steel-weight    { min-width: 90px;  max-width: 110px; }
.col-yamashita       { min-width: 110px; max-width: 130px; }

.col-laser-sl-amount, .col-laser-ki-amount, .col-laser-ya-amount,
.col-laser-y-amount,  .col-laser-di-amount, .col-laser-ko-amount,
.col-laser-be-amount, .col-laser-ku-amount, .col-laser-kmf-amount,
.col-laser-fr-amount, .col-laser-self-amount {
  min-width: 110px; max-width: 130px;
}
.col-laser-sl-weight, .col-laser-ki-weight, .col-laser-ya-weight,
.col-laser-y-weight,  .col-laser-di-weight, .col-laser-ko-weight,
.col-laser-be-weight, .col-laser-ku-weight, .col-laser-kmf-weight,
.col-laser-fr-weight, .col-laser-self-weight {
  min-width: 90px; max-width: 110px;
}

.col-ship-method     { min-width: 110px; max-width: 130px; }
.col-other           { min-width: 100px; max-width: 120px; }
.col-grand-total     { min-width: 120px; max-width: 140px; }
/* ===== 合計金額列だけ太字 ===== */
table.invoice-table tbody td.col-grand-total .cell-input {
  font-weight: 700;
}
.col-grand-weight    { min-width: 100px; max-width: 120px; }
.col-ship-date       { min-width: 110px; max-width: 130px; }
.col-plan-date       { min-width: 100px; max-width: 120px; }
.col-designer        { min-width: 100px; max-width: 120px; }
.col-memo            { min-width: 180px; max-width: 280px; }
.col-delivery-dest   { min-width: 120px; max-width: 160px; }

/* ===== 空テーブル時のメッセージ ===== */
.empty-message {
  padding: 40px 16px;
  text-align: center;
  color: #888;
  font-size: 14px;
}

.empty-message strong {
  display: block;
  font-size: 16px;
  color: #555;
  margin-bottom: 8px;
}

/* ===== トースト通知 ===== */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 10px 16px;
  background: #2c3e50;
  color: #fff;
  border-radius: 4px;
  font-size: 13px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  z-index: 1000;
  animation: toast-in 0.2s ease-out;
}

.toast.success { background: #27ae60; }
.toast.error   { background: #e74c3c; }
.toast.warning { background: #f39c12; }

@keyframes toast-in {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

/* ===== ロード中 ===== */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #555;
  z-index: 100;
}

.loading-overlay::before {
  content: '';
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid #ddd;
  border-top-color: #3498db;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 8px;
}

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

/* ===== 確認ダイアログ ===== */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.confirm-dialog {
  background: #fff;
  padding: 20px 24px;
  border-radius: 6px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  min-width: 320px;
  max-width: 420px;
}

.confirm-dialog h3 {
  font-size: 15px;
  margin-bottom: 12px;
}

.confirm-dialog p {
  color: #555;
  font-size: 13px;
  margin-bottom: 16px;
  line-height: 1.5;
}

.confirm-dialog .actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.confirm-dialog button {
  padding: 6px 16px;
  font-size: 13px;
  border-radius: 4px;
  border: 1px solid #c4c8cc;
  background: #fff;
  cursor: pointer;
  font-family: inherit;
}

.confirm-dialog button.btn-danger {
  background: #e74c3c;
  color: #fff;
  border-color: #c0392b;
}

.confirm-dialog button:hover {
  filter: brightness(0.95);
}