/* ============================================================
   請求UI スタイル v2
   - 画像 84×84px に拡大
   - 文字色を濃く、コントラスト改善
   - 全体的にはっきり見えるように
   ============================================================ */

* {
  box-sizing: border-box;
}

body {
  font-family: Meiryo, system-ui, sans-serif;
  background: #eef2f5;
  padding: 0;
  margin: 0;
  color: #1a1a1a;     /* ← #333 から濃くした */
}

/* ===== 全体レイアウト ===== */
.invoice-app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ============================================================
   左パネル
   ============================================================ */
.left-panel {
  width: 340px;
  min-width: 340px;
  background: #fff;
  border-right: 2px solid #b0bec5;
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.left-panel-header {
  padding: 14px 16px;
  border-bottom: 2px solid #1565c0;
  background: #1976d2;          /* 濃い青で目立たせる */
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.left-panel-header h2 {
  margin: 0;
  font-size: 17px;
  font-weight: bold;
  color: #fff;                  /* 白文字 */
}

.btn-refresh {
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 4px;
  padding: 5px 11px;
  cursor: pointer;
  font-size: 14px;
  color: #fff;
  transition: background 0.15s;
}
.btn-refresh:hover {
  background: rgba(255,255,255,0.4);
}

.left-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  background: #fafafa;
}

.left-panel-footer {
  padding: 10px 16px;
  border-top: 2px solid #b0bec5;
  background: #eceff1;
  font-size: 13px;
  color: #263238;               /* 濃い色 */
  font-weight: bold;
}

/* ===== 客先グループ ===== */
.customer-group {
  margin-bottom: 20px;
}

.customer-group-header {
  font-size: 14px;
  font-weight: bold;
  color: #fff;
  padding: 6px 12px;
  border-radius: 4px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-shadow: 0 1px 1px rgba(0,0,0,0.2);
}

/* 客先カラー（より濃く） */
.customer-group[data-customer="E2"]       .customer-group-header { background: #0d47a1; }
.customer-group[data-customer="カーワーク"] .customer-group-header { background: #1b5e20; }
.customer-group[data-customer="細田"]     .customer-group-header { background: #e65100; }
.customer-group[data-customer="ベスト"]   .customer-group-header { background: #6a1b9a; }
.customer-group[data-customer="その他"]   .customer-group-header { background: #424242; }

.group-count {
  background: rgba(255,255,255,0.3);
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
}

.group-empty {
  font-size: 12px;
  color: #757575;
  padding: 8px 6px;
  font-style: italic;
}

/* ===== カード ===== */
.invoice-card {
  background: #fff;
  border: 1px solid #b0bec5;
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.invoice-card:hover {
  border-color: #1976d2;
  box-shadow: 0 3px 8px rgba(25, 118, 210, 0.25);
  transform: translateY(-1px);
}
.invoice-card.selected {
  border: 2px solid #1565c0;
  background: #e3f2fd;
  box-shadow: 0 3px 10px rgba(25, 118, 210, 0.35);
}

.card-job-no {
  font-weight: bold;
  font-size: 15px;
  color: #0d47a1;
  margin-bottom: 4px;
}

.card-project {
  font-size: 13px;
  color: #1a1a1a;               /* 濃く */
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: #455a64;               /* 濃く */
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid #cfd8dc;
}

.card-status {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: bold;
}
.card-status.pending  { background: #ffe0b2; color: #bf360c; }
.card-status.finalized { background: #c8e6c9; color: #1b5e20; }

.card-image-flag {
  font-size: 12px;
  color: #455a64;
  font-weight: bold;
}

/* ===== ロード中・空 ===== */
.loading,
.error-msg,
.empty-msg {
  text-align: center;
  padding: 24px 16px;
  color: #546e7a;
  font-size: 14px;
}
.error-msg { color: #c62828; font-weight: bold; }

/* ============================================================
   右メイン
   ============================================================ */
.main-panel {
  flex: 1;
  overflow-y: auto;
  background: #eef2f5;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 40px;
  text-align: center;
  color: #546e7a;
}
.empty-state .empty-icon {
  font-size: 64px;
  margin-bottom: 16px;
  opacity: 0.5;
}
.empty-state h2 {
  font-size: 22px;
  font-weight: normal;
  margin: 0 0 8px;
  color: #37474f;
}
.empty-state p {
  font-size: 14px;
  margin: 0;
  max-width: 460px;
  line-height: 1.6;
}

/* ============================================================
   編集エリア
   ============================================================ */

/* ===== ヘッダー情報 ===== */
.invoice-header {
  background: #fff;
  border-bottom: 3px solid #0d47a1;
  padding: 18px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.invoice-header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}
.job-no-display {
  font-size: 32px;
  font-weight: bold;
  color: #0d47a1;
  letter-spacing: 1px;
}
.invoice-header-right {
  flex: 1;
  text-align: right;
}
.header-row {
  font-size: 14px;
  margin-bottom: 4px;
}
.header-row label {
  color: #546e7a;
  margin-right: 8px;
}
.header-row span {
  color: #1a1a1a;
  font-weight: bold;
}

/* ===== 客先バッジ ===== */
.customer-badge {
  display: inline-block;
  padding: 5px 14px;
  border-radius: 14px;
  color: #fff;
  font-size: 13px;
  font-weight: bold;
  text-shadow: 0 1px 1px rgba(0,0,0,0.2);
}
.customer-badge.badge-e2    { background: #0d47a1; }
.customer-badge.badge-kw    { background: #1b5e20; }
.customer-badge.badge-hd    { background: #e65100; }
.customer-badge.badge-bs    { background: #6a1b9a; }
.customer-badge.badge-other { background: #424242; }

/* ===== 単価集計パネル ===== */
.price-panel-placeholder {
  background: #fff8e1;
  border: 2px solid #ffc107;
  border-radius: 6px;
  margin: 16px 24px;
  padding: 14px 18px;
}
.price-panel-title {
  font-size: 14px;
  color: #5d4037;
  font-weight: bold;
  margin-bottom: 10px;
}
.price-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.price-chip {
  background: #fff;
  border: 2px solid #ff9800;
  border-radius: 4px;
  padding: 6px 12px;
  font-size: 14px;
  color: #4e342e;
  font-weight: bold;
}
.price-chip b {
  color: #bf360c;
  font-size: 16px;
  margin-right: 4px;
}
.no-data {
  color: #757575;
  font-size: 13px;
  font-style: italic;
}

/* ===== 明細テーブル ===== */
.invoice-table-wrapper {
  margin: 0 24px;
  background: #fff;
  border: 1px solid #90a4ae;
  border-radius: 4px;
  overflow: auto;
  /* スクロール領域を固定するため最大高さを設ける */
  max-height: calc(100vh - 380px);
  position: relative;
}
.invoice-table {
  width: 100%;
  border-collapse: separate;  /* sticky を機能させるため */
  border-spacing: 0;
  font-size: 13px;
  color: #1a1a1a;
}

/* ===== 固定ヘッダー（縦スクロールで残る） ===== */
.invoice-table thead th {
  background: #37474f;
  color: #fff;
  padding: 8px 10px;
  font-weight: bold;
  text-align: center;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 3;
  border: 1px solid #263238;
  /* 影で行から浮いて見せる */
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

.invoice-table td {
  padding: 6px 10px;
  border-bottom: 1px solid #cfd8dc;
  border-right: 1px solid #eceff1;
  white-space: nowrap;
  color: #1a1a1a;
  background: #fff; /* sticky列の重なり防止 */
}
.invoice-table tbody tr:nth-child(even) td {
  background: #fafafa;
}
.invoice-table tbody tr:hover td {
  background: #fff9c4;
}

/* ===== No列を横スクロールでも固定 ===== */
.invoice-table .part-no-th,
.invoice-table .part-no-cell {
  width: 44px;
  min-width: 44px;
  text-align: center;
  background: #cfd8dc !important;  /* 行の背景に上書き */
  font-weight: bold;
  color: #263238;
  position: sticky;
  left: 0;
  z-index: 2;  /* 通常セルより上、ヘッダーより下 */
  /* 右側に区切り線を強調 */
  border-right: 2px solid #90a4ae !important;
}
/* ヘッダー行の No列 はヘッダー(z=3)とNo列(z=2)の交差点 */
.invoice-table thead .part-no-th {
  z-index: 4;  /* 最前面 */
  background: #263238 !important;
  border-right: 2px solid #1a1a1a !important;
}

/* ===== 画像セル（拡大版 84×84） ===== */
.invoice-table .preview-cell {
  width: 92px;
  text-align: center;
  padding: 4px;
}
.invoice-table tbody tr:nth-child(even) .preview-cell {
  background: #fafafa;
}
.invoice-table .preview-img {
  max-width: 84px;
  max-height: 84px;
  border: 1px solid #90a4ae;
  border-radius: 3px;
  display: block;
  margin: 0 auto;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.invoice-table .preview-fallback {
  font-size: 12px;
  color: #90a4ae;
}

.invoice-table .align-right  { text-align: right; }
.invoice-table .align-left   { text-align: left; }
.invoice-table .align-center { text-align: center; }

/* 編集可能セル */
.invoice-table .cell-editable {
  background: #fff8e1 !important;
  font-weight: bold;
  color: #bf360c;
}

/* ===== 合計エリア ===== */
.invoice-total-area {
  margin: 16px 24px 0;
  background: #263238;        /* ダークでメリハリ */
  border-radius: 6px;
  padding: 16px 20px;
  font-size: 15px;
  text-align: right;
  color: #fff;
}
.invoice-total-area .total-amount {
  font-size: 28px;
  font-weight: bold;
  color: #ffeb3b;             /* 黄色で目立つ */
  margin: 0 4px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.invoice-total-area .total-weight {
  font-size: 20px;
  font-weight: bold;
  color: #81d4fa;             /* 水色 */
  margin: 0 4px;
}
.invoice-total-area .total-count {
  font-weight: bold;
  color: #fff;
}

/* ===== アクションボタン ===== */
.invoice-action-area {
  margin: 16px 24px 24px;
  padding: 16px;
  text-align: center;
  background: #fff;
  border: 1px solid #b0bec5;
  border-radius: 6px;
}
.invoice-action-area .btn {
  font-size: 16px;
  padding: 12px 28px;
  margin: 0 8px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
  transition: all 0.15s;
}
.invoice-action-area .btn-disabled {
  background: #cfd8dc;
  color: #607d8b;
  cursor: not-allowed;
}

/* ============================================================
   Phase 3-3: 単価一括変更パネル
   ============================================================ */
.price-edit-panel {
  background: #fff8e1;
  border: 2px solid #ffc107;
  border-radius: 6px;
  margin: 16px 24px;
  padding: 14px 18px;
}
.price-edit-panel .price-panel-title {
  font-size: 16px;
  color: #4e342e;
  font-weight: bold;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.price-edit-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid #ffb300;
  border-radius: 4px;
  overflow: hidden;
}
.price-edit-table th {
  background: #ff9800;
  color: #fff;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: bold;
  text-align: center;
  border: 1px solid #f57c00;
}
.price-edit-table td {
  padding: 8px 12px;
  border-bottom: 1px solid #ffe082;
  font-size: 14px;
  vertical-align: middle;
}
.price-edit-table tbody tr:last-child td {
  border-bottom: none;
}
.price-edit-table tbody tr:hover {
  background: #fffde7;
}

.price-edit-table .price-current {
  font-weight: bold;
  color: #bf360c;
  text-align: right;
  font-size: 16px;
  width: 25%;
}
.price-edit-table .price-count {
  text-align: center;
  color: #455a64;
  font-weight: bold;
  width: 15%;
}
.price-edit-table .price-input-cell {
  width: 30%;
  text-align: center;
}
.price-new-input {
  width: 100px;
  padding: 6px 10px;
  font-size: 15px;
  font-weight: bold;
  border: 2px solid #ff9800;
  border-radius: 4px;
  text-align: right;
  color: #1a1a1a;
}
/* 例テキスト（プレースホルダー）を薄く */
.price-new-input::placeholder {
  color: #bdbdbd;
  font-weight: normal;
  font-style: italic;
  opacity: 1;  /* Firefoxのデフォルト透明度を打ち消す */
}
/* ブラウザ別フォールバック */
.price-new-input::-webkit-input-placeholder { color: #bdbdbd; font-weight: normal; font-style: italic; }
.price-new-input::-moz-placeholder         { color: #bdbdbd; font-weight: normal; font-style: italic; opacity: 1; }
.price-new-input:-ms-input-placeholder     { color: #bdbdbd; font-weight: normal; font-style: italic; }

.price-new-input:focus {
  outline: none;
  border-color: #d84315;
  background: #fff3e0;
}
.yen-mark {
  margin-left: 4px;
  color: #5d4037;
  font-weight: bold;
}

.btn-bulk-change {
  background: #d84315;
  color: #fff;
  font-size: 14px;
  font-weight: bold;
  padding: 8px 18px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  text-shadow: 0 1px 1px rgba(0,0,0,0.2);
  transition: background 0.15s;
}
.btn-bulk-change:hover {
  background: #bf360c;
}
.btn-bulk-change:active {
  background: #a13310;
}

.price-edit-hint {
  margin-top: 10px;
  font-size: 12px;
  color: #6d4c41;
  font-style: italic;
}

/* ============================================================
   トースト通知
   ============================================================ */
.invoice-toast {
  position: fixed;
  bottom: 30px;
  right: 30px;
  background: #2e7d32;
  color: #fff;
  padding: 14px 22px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: bold;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  white-space: pre-line;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  z-index: 9999;
  max-width: 400px;
}
.invoice-toast.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ============================================================
   フィルター（月セレクタ + 検索ボックス）
   ============================================================ */
.left-panel-filter {
  padding: 10px 12px;
  background: #eceff1;
  border-bottom: 1px solid #b0bec5;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.filter-month {
  width: 100%;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: bold;
  border: 1px solid #90a4ae;
  border-radius: 4px;
  background: #fff;
  color: #1a1a1a;
  cursor: pointer;
}
.filter-month:focus {
  outline: none;
  border-color: #1976d2;
  box-shadow: 0 0 0 2px rgba(25,118,210,0.2);
}

.filter-search {
  width: 100%;
  padding: 6px 10px;
  font-size: 13px;
  border: 1px solid #90a4ae;
  border-radius: 4px;
  background: #fff;
  color: #1a1a1a;
}
.filter-search:focus {
  outline: none;
  border-color: #1976d2;
  box-shadow: 0 0 0 2px rgba(25,118,210,0.2);
}

/* ============================================================
   カード削除ボタン
   ============================================================ */
.invoice-card {
  position: relative;  /* 絶対配置の削除ボタン用 */
}

.card-delete-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid #ef9a9a;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
  color: #c62828;
  z-index: 1;
}
.invoice-card:hover .card-delete-btn {
  opacity: 1;
}
.card-delete-btn:hover {
  background: #c62828;
  color: #fff;
  border-color: #b71c1c;
}
.card-delete-btn:disabled {
  cursor: wait;
  opacity: 1;
  background: #fff;
}

/* タッチデバイスでは常時表示（hover非対応） */
@media (hover: none) {
  .card-delete-btn { opacity: 0.8; }
}

/* ============================================================
   Phase 3-4: 保存ボタン関連
   ============================================================ */
.invoice-action-area {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.invoice-action-area .btn-save {
  background: #2e7d32;
  color: #fff;
  text-shadow: 0 1px 1px rgba(0,0,0,0.2);
  transition: background 0.15s, transform 0.05s;
}
.invoice-action-area .btn-save:hover:not(:disabled) {
  background: #1b5e20;
}
.invoice-action-area .btn-save:active:not(:disabled) {
  transform: scale(0.97);
}
.invoice-action-area .btn-save:disabled {
  background: #9e9e9e;
  color: #eee;
  cursor: wait;
}

.save-status {
  font-size: 13px;
  font-weight: bold;
  margin-left: 12px;
  padding: 4px 10px;
  border-radius: 4px;
}
.save-status.status-dirty {
  color: #c62828;
  background: #ffebee;
  border: 1px solid #ef9a9a;
  animation: pulse-dirty 1.6s infinite;
}
.save-status.status-saved {
  color: #2e7d32;
  background: #e8f5e9;
  border: 1px solid #a5d6a7;
}

@keyframes pulse-dirty {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.6; }
}

/* ============================================================
   Phase 3-5: 本出力ボタン
   ============================================================ */
.invoice-action-area .btn-finalize {
  background: #d84315;
  color: #fff;
  text-shadow: 0 1px 1px rgba(0,0,0,0.2);
  transition: background 0.15s, transform 0.05s;
}
.invoice-action-area .btn-finalize:hover:not(:disabled) {
  background: #bf360c;
}
.invoice-action-area .btn-finalize:active:not(:disabled) {
  transform: scale(0.97);
}
.invoice-action-area .btn-finalize:disabled {
  background: #9e9e9e;
  color: #eee;
  cursor: wait;
}

/* ============================================================
   Phase B: 請求タイプセレクター
   ============================================================ */
.invoice-type-selector {
  padding: 10px 12px;
  background: #cfd8dc;
  border-bottom: 1px solid #90a4ae;
  display: flex;
  align-items: center;
  gap: 8px;
}
.invoice-type-selector label {
  font-size: 13px;
  font-weight: bold;
  color: #263238;
}
.filter-type {
  flex: 1;
  padding: 5px 10px;
  font-size: 14px;
  font-weight: bold;
  border: 2px solid #455a64;
  border-radius: 4px;
  background: #fff;
  color: #1a1a1a;
  cursor: pointer;
}
.filter-type:focus {
  outline: none;
  border-color: #1976d2;
  box-shadow: 0 0 0 2px rgba(25,118,210,0.2);
}

/* ============================================================
   Phase C 用 プレースホルダー（鋼材カード選択時）
   ============================================================ */
.phase-placeholder {
  padding: 40px;
  background: #fff;
  border-radius: 8px;
  margin: 20px;
  border: 2px dashed #90a4ae;
}
.phase-placeholder h2 {
  margin: 0 0 16px;
  color: #c2185b;
  font-size: 24px;
}
.phase-placeholder p {
  margin: 8px 0;
  font-size: 15px;
  color: #1a1a1a;
}
.phase-placeholder hr {
  margin: 16px 0;
  border: none;
  border-top: 1px solid #b0bec5;
}

/* ============================================================
   Phase C: 鋼材テーブル
   ============================================================ */
.steel-table {
  font-size: 13px;
}

/* 単価セルの編集input */
.steel-table .price-cell-input {
  width: 80px;
  padding: 4px 6px;
  font-size: 14px;
  font-weight: bold;
  border: 1px solid #ff9800;
  border-radius: 3px;
  text-align: right;
  color: #bf360c;
  background: #fff;
}
.steel-table .price-cell-input:focus {
  outline: none;
  border-color: #d84315;
  background: #fff3e0;
  box-shadow: 0 0 0 2px rgba(216,67,21,0.2);
}

.steel-table .amount-cell {
  font-weight: bold;
  color: #1a1a1a;
}

/* 鋼材は画像列がないのでheader画像が無い分横に余裕がある */
.steel-table th:first-child,
.steel-table td:first-child {
  width: 44px;
}

/* ============================================================
   小計行（鋼材タブ、pricemaster小計再現）
   ============================================================ */
.steel-table tr.subtotal-row {
  background: #eceff1 !important;
}
.steel-table tr.subtotal-row td {
  font-weight: bold;
  color: #263238;
  border-top:    2px solid #607d8b !important;
  border-bottom: 2px solid #607d8b !important;
}
.steel-table tr.subtotal-row td.align-left {
  text-align: center !important;
  font-style: italic;
  color: #455a64;
}

/* ============================================================
   カード日付クリック編集
   ============================================================ */
.card-date {
  cursor: pointer;
  padding: 1px 4px;
  border-radius: 3px;
  transition: background 0.15s;
  display: inline-block;
}
.card-date:hover {
  background: #fff59d;
  text-decoration: underline dotted;
  color: #5d4037;
}
.card-date::after {
  content: '✏️';
  margin-left: 3px;
  opacity: 0;
  font-size: 10px;
  transition: opacity 0.15s;
}
.card-date:hover::after {
  opacity: 0.7;
}