/* ==========================================
   Tahap 4-2 専用の基本レイアウト設定（PC用）
   ========================================== */
.table-scroll-container {
  margin-top: 12px;
  margin-bottom: 12px;
  width: 100%;
}

.invest-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  table-layout: fixed; /* PCで列幅を完全に固定する */
}

.invest-table th,
.invest-table td {
  padding: 10px 8px;
  vertical-align: middle;
  box-sizing: border-box;
}

/* ------------------------------------------
   【PC用・横幅の統一設定】
   ------------------------------------------ */
.invest-table .col-price        { width: 170px; } 
.invest-table .col-month        { width: 110px; } 
.invest-table .col-span         { width: 110px; } 
.invest-table .col-reserve-calc { width: 170px; } 
.invest-table .col-action       { width: 50px;  } 
.invest-table .hidden-th        { display: none; }

.sub-asset-section {
  width: 100%;
  margin-top: 20px;
  padding-bottom: 16px;
  border-bottom: 1px dashed #E2E8F0;
}
.sub-asset-section.has-margin {
  margin-bottom: 30px;
}
.sub-asset-section:last-of-type {
  border-bottom: none;
}

.sub-asset-section h4 {
  font-size: 1rem;
  color: #334155;
  margin-bottom: 4px;
}

.field-desc-sub {
  font-size: 0.8rem;
  color: #64748B;
  margin-bottom: 8px;
}

.button-row-sub {
  margin-top: 8px;
  margin-bottom: 12px;
}

.btn-add-small {
  background-color: #64748B;
  color: #FFFFFF;
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.8rem;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: background-color 0.2s ease;
}

.btn-add-small:hover {
  background-color: #475569;
}

.input-group-half {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  max-width: 400px;
}

.form-grid-optimized {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 16px;
  width: 100%;
}

/* ------------------------------------------
   Setup Dasar用のインラインCSS分離クラス
   ------------------------------------------ */
.wrapper-date {
  width: 100%;
  height: 38px;
}
.wrapper-currency {
  position: relative;
  width: 100%;
  height: 38px;
  box-sizing: border-box;
}
.currency-prefix {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #94A3B8;
  font-size: 0.85rem;
  font-weight: bold;
  pointer-events: none;
}
.wrapper-currency input {
  width: 100%;
  height: 100%;
  padding: 6px 12px 6px 36px;
  font-size: 0.85rem;
  border-radius: 4px;
  border: 1px solid #CBD5E1;
  text-align: left;
  box-sizing: border-box;
  outline: none;
}

/* ==========================================================================
   Setup Dasar: カレンダー入力欄（#sim-start-date）の最適化設定
   ========================================================================== */
#sim-start-date {
  width: 100% !important;
  height: 100% !important;
  padding: 6px 12px !important;
  font-size: 0.85rem !important;
  border: 1px solid #CBD5E1 !important;
  border-radius: 4px !important;
  background-color: #FFFFFF !important;
  color: #0F172A !important;
  font-family: inherit !important;
  box-sizing: border-box !important;
  outline: none !important;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
#sim-start-date:focus {
  background-color: #FFFFFF !important;
  border-color: #3B82F6 !important;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15) !important;
}

/* ==========================================================================
   テーブル内パーツ用 スタイル設定
   ========================================================================== */
.invest-table td input {
  width: 100%;
  padding: 6px 8px;
  font-size: 0.85rem;
  height: 32px;
  border-radius: 6px;
  border: 1px solid #CBD5E1;
  background: #fff;
  box-sizing: border-box;
  outline: none;
}
.invest-table td.td-currency {
  position: relative;
}
.invest-table td.td-currency span {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: #94A3B8;
  font-size: 0.75rem;
  pointer-events: none;
}
.invest-table td.td-currency input {
  padding-left: 24px;
  padding-right: 24px;
}
.invest-table td.td-currency .btn-copy-fast {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: #94A3B8;
  cursor: pointer;
  font-size: 0.7rem;
}
.invest-table .font-center {
  text-align: center !important;
}
.invest-table .font-bold {
  font-weight: bold !important;
}
.invest-table .readonly-style {
  background: #E2E8F0 !important;
  color: #475569 !important;
  font-size: 0.8rem;
}
.invest-table .btn-delete-row {
  background: none;
  border: none;
  color: #EF4444;
  cursor: pointer;
  padding: 0;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* 【重要】最初の1行目のゴミ箱ボタンを自動で非表示にするルール */
#existing-asset-container tr:first-child .btn-delete-row,
#new-asset-container tr:first-child .btn-delete-row {
  display: none !important;
}

/* ==========================================================================
   📱 スマホ専用レスポンシブ（幅768px以下）: 安全なカード型変形
   ========================================================================== */
@media (max-width: 768px) {
  .form-grid-optimized {
    grid-template-columns: 1fr;
  }

  #sim-start-date {
    padding: 6px 8px !important;
    font-size: 0.85rem !important;
  }

  /* テーブルの構造を解除し、カードを並べるコンテナ化 */
  .invest-table {
    display: block;
    width: 100%;
  }
  .invest-table thead {
    display: none;
  }
  .invest-table tbody {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
  }

  /* 行をカードに変形 */
  .invest-table tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 16px;
    background: #F8FAFC;
    border: 1px solid #E2E8F0;
    border-radius: 8px;
    width: 100%;
    box-sizing: border-box;
    position: relative;
  }

  /* 各入力枠を縦並びにする */
  .invest-table td {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 0 !important;
    width: 100% !important;
  }

  /* アイテム名入力セルを横いっぱいに広げる */
  .invest-table td:first-child {
    grid-column: 1 / -1;
  }

  /* 擬似要素でスマホ専用の小見出しを強制挿入 */
  .invest-table td::before {
    font-size: 0.75rem;
    font-weight: bold;
    color: #64748B;
    margin-bottom: 4px;
  }

  /* 2-1 ラベル */
  #existing-asset-container td:nth-child(1)::before { content: "Nama Item Aset"; }
  #existing-asset-container td:nth-child(2)::before { content: "Harga"; }
  #existing-asset-container td:nth-child(3)::before { content: "Sisa Bulan"; }
  #existing-asset-container td:nth-child(4)::before { content: "Simpanan Cadangan"; }

  /* 2-2 ラベル */
  #new-asset-container td:nth-child(1)::before { content: "Komponen Aset Baru"; }
  #new-asset-container td:nth-child(2)::before { content: "Harga"; }
  #new-asset-container td:nth-child(3)::before { content: "Beli Bulan Ke-"; }
  #new-asset-container td:nth-child(4)::before { content: "Masa Pakai (Bln)"; }
  #new-asset-container td:nth-child(5)::before { content: "Simpanan Cadangan"; }

  /* ゴミ箱のセルをカードの右上に絶対配置 */
  .invest-table td.font-center:last-child {
    position: absolute;
    top: 12px;
    right: 12px;
    width: auto !important;
    height: auto;
  }
  .invest-table td.font-center:last-child::before {
    content: "" !important;
  }

  /* 1枚目カードからのゴミ箱非表示（スマホでも有効） */
  #existing-asset-container tr:first-child .btn-delete-row,
  #new-asset-container tr:first-child .btn-delete-row {
    display: none !important;
  }
}
