/**
 * =====================================================
 * 家臣データシミュレーター ローカルスタイル
 * =====================================================
 * 
 * 共有CSSデザイントークンを使用
 * デザイン基準: tsukumo-filter
 */

/* =====================================================
   アプリケーションコンテナ
   ===================================================== */

.app-container {
  display: flex;
  flex-direction: column;
  max-width: 100%;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  background: var(--c-bg-card);
  margin-top: 1rem;
  border: 1px solid var(--c-border);
}

/* =====================================================
   グリッド行レイアウト
   ===================================================== */

.grid-row {
  display: grid;
  grid-template-columns: 140px repeat(11, 85px);
  border-bottom: 1px solid var(--c-border);
}

@media (max-width: 640px) {
  .grid-row {
    grid-template-columns: 110px repeat(11, 70px);
  }
}

/* =====================================================
   セル共通スタイル
   ===================================================== */

.cell {
  padding: 0.5rem 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 1px solid var(--c-border);
  font-size: 0.875rem;
  color: var(--c-text);
}

/* 右端のセルの縦罫線を削除 */
.cell:last-child {
  border-right: none;
}

/* 固定ラベル列 */
.sticky-label {
  position: sticky;
  left: 0;
  z-index: 10;
  background-color: var(--c-bg-alt);
  font-weight: 400;
  color: var(--c-text-sub);
  justify-content: flex-start;
  padding-left: 1rem;
  box-shadow: 2px 0 5px rgba(0, 0, 0, 0.05);
  border-right: 1px solid var(--c-border-strong);
}

/* =====================================================
   ヘッダー領域
   ===================================================== */

.header-container {
  background: var(--c-bg-alt);
  color: var(--c-text-sub);
  overflow: hidden;
  flex-shrink: 0;
  border-bottom: 1px solid var(--c-border-strong);
}

.header-row .cell {
  border-right: 1px solid var(--c-border);
  font-size: 0.875rem;
  font-weight: 400;
  color: var(--c-text-sub);
}

.header-row .cell:last-child {
  border-right: none;
}

.header-row .sticky-label {
  background: var(--c-bg-alt);
  color: var(--c-text-sub);
  z-index: 20;
}

/* 属性ヘッダーの特別色 */
.header-cell.attr {
  background: rgba(41, 128, 185, 0.05);
  color: #2980b9;
}

/* ヘッダーハイライト */
.header-highlight {
  background-color: #dbeafe !important;
  color: #1e40af !important;
}

/* =====================================================
   スクロールボディ
   ===================================================== */

.scroll-body {
  flex: 1;
  overflow: auto;
  background: var(--c-bg-card);
  max-height: 70vh;
}

@media (max-width: 640px) {
  .scroll-body {
    max-height: 100vh;
  }
}

/* =====================================================
   セクションラベル
   ===================================================== */

.section-label {
  position: sticky;
  left: 0;
  background: var(--c-bg);
  padding: 0.5rem 1rem;
  font-weight: 600;
  color: var(--c-primary);
  border-left: 4px solid var(--c-primary);
  margin-top: 0.5rem;
  margin-bottom: 0.25rem;
  z-index: 5;
  width: fit-content;
  font-size: 0.875rem;
}

/* =====================================================
   入力フィールド
   ===================================================== */

input[type="number"] {
  width: 100%;
  height: 100%;
  padding: 0.375rem;
  border: none;
  border-right: 1px solid var(--c-border);
  border-radius: 0;
  text-align: right;
  font-size: 0.875rem;
  font-family: "Inter", sans-serif;
  background: transparent;
  color: var(--c-text);
  transition: all var(--transition-fast);
}

input[type="number"].calc-base {
  border-right: 1px solid var(--c-border);
}

input[type="number"]:focus {
  outline: none;
  background: #fff;
  box-shadow: inset 0 0 0 2px var(--c-primary);
  z-index: 2;
  position: relative;
}

input[type="number"]:hover {
  background-color: #f8fafc;
}

/* 最後の列のinputの右ボーダーを消す */
.grid-row input[type="number"]:last-child {
  border-right: none;
}

/* 列ハイライト */
.col-highlight {
  background-color: #eff6ff !important;
  color: inherit !important;
}

/* =====================================================
   フッター領域（結果表示）
   ===================================================== */

.footer-container {
  background: var(--c-bg-alt);
  color: var(--c-text);
  border-top: 1px solid var(--c-border-strong);
  overflow: hidden;
  flex-shrink: 0;
  padding-bottom: 0.5rem;
}

.footer-row .sticky-label {
  background: var(--c-bg-alt);
  color: var(--c-text);
  border-right: 1px solid var(--c-border-strong);
}

.footer-row .cell {
  border-right: 1px solid var(--c-border);
}

.footer-row .cell:last-child {
  border-right: none;
}

/* フッター内のspan要素を垂直中央揃えに */
.footer-row span {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  padding: 0.5rem;
  font-weight: 400;
  font-family: "Inter", monospace;
  font-size: 1rem;
}

/* 結果行の色分け */
.sub-result {
  background: #fff5f5;
}
.sub-result .sticky-label {
  background: #fff5f5;
  color: var(--c-error);
}
.sub-result span {
  color: var(--c-error);
}

.main-result {
  background: #fff;
}
.main-result .sticky-label {
  background: #fff;
}

/* 合計プログレスバー */
.main-result .total-cell {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  border-right: 1px solid var(--c-border);
}

.main-result .total-cell:last-child {
  border-right: none;
}

.main-result .total-cell .progress-bar {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: linear-gradient(to right, #dc2626 0%, #ef4444 100%);
  opacity: 0.5;
  z-index: 0;
  transition: width 0.3s ease-out;
}

.main-result .total-cell span {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  padding: 0.5rem;
  font-weight: 500;
  font-family: "Inter", monospace;
  font-size: 1rem;
  color: var(--c-text);
}

.bond-result {
  background: #f0fdf4;
}
.bond-result .sticky-label {
  background: #f0fdf4;
  color: var(--c-success);
}
.bond-result span {
  color: var(--c-success);
}

/* =====================================================
   小計行
   ===================================================== */

.section-total {
  background-color: #f0fdf4;
  border-top: 1px solid var(--c-success-light);
  font-weight: 400;
  color: #15803d;
}

.section-total .sticky-label {
  background-color: #f0fdf4;
  color: #15803d;
}

.section-total .cell {
  border-right: 1px solid rgba(0, 0, 0, 0.05);
}

.section-total span {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  width: 100%;
  padding-right: 0.5rem;
  font-family: "Inter", monospace;
}

/* =====================================================
   目標行
   ===================================================== */

.target-row {
  background-color: #fffbeb;
}

.target-row .sticky-label {
  background-color: #fffbeb;
  color: #92400e;
}

.target-row .cell {
  border-right: 1px solid rgba(0, 0, 0, 0.05);
}

.target-row input {
  background-color: rgba(255, 251, 235, 0.5);
  font-weight: 400;
  color: #92400e;
  border-right: 1px solid rgba(0, 0, 0, 0.1);
}

/* =====================================================
   メッセージボックス
   ===================================================== */

.message-box {
  display: none;
  animation: slideIn 0.3s ease;
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  padding: 1rem 1.5rem;
  border-radius: 0.375rem;
  box-shadow: 0 4px 6px rgb(0 0 0 / 0.1);
  z-index: 1000;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translate(-50%, -10px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

.message-box.show {
  display: block;
}

/* =====================================================
   ボタン共通スタイル (tsukumo-filter準拠)
   ===================================================== */

.custom-btn {
  color: #fff;
  font-weight: 600;
  font-size: 0.875rem;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  transition: all 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

.custom-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
}

.custom-btn:active {
  transform: translateY(0);
}

/* リセットボタン（赤色） - kijin-filter準拠 */
.reset-button-alt {
  background-color: #ef4444;
  color: #fff;
}
.reset-button-alt:hover {
  background-color: #dc2626;
}
.reset-button-alt:focus {
  box-shadow: 0 0 0 2px #fca5a5;
}

/* =====================================================
   プリセット管理セクション
   ===================================================== */

#presetManagementSectionKashin {
  margin-top: 0;
  border: 1px solid var(--c-border);
  box-shadow: var(--shadow-sm);
}

#presetListContainerKashin > div {
  padding: 0.75rem !important;
  border: 1px solid var(--c-border) !important;
  background-color: #fff !important;
  margin-bottom: 0.5rem;
  border-radius: 0.375rem;
}

#presetListContainerKashin > div:hover {
  background-color: #f8fafc !important;
}

/* =====================================================
   レスポンシブ調整
   ===================================================== */

@media (max-width: 640px) {
  .cell {
    padding: 0.375rem 0.25rem;
    font-size: 0.75rem;
  }

  .sticky-label {
    font-size: 0.75rem;
    padding-left: 0.5rem;
  }

  input[type="number"] {
    font-size: 0.75rem;
    padding: 0.25rem;
  }

  .footer-row span {
    font-size: 0.875rem;
  }

  .section-label {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
  }

  .custom-btn {
    min-height: 44px;
  }
}

/* スピンボタン非表示 */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}
