/* 企業業務向け洗練デザイン */
:root {
  --primary-color: #1469a8;
  --primary-hover: #0f5d96;
  --secondary-color: #64748b;
  --success-color: #10b981;
  --border-color: #e2e8f0;
  --bg-light: #f8fafc;
  --bg-white: #ffffff;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.10), 0 1px 2px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 8px 18px -10px rgba(15, 23, 42, 0.28), 0 4px 10px -6px rgba(15, 23, 42, 0.18);
  --shadow-lg: 0 18px 40px -18px rgba(15, 23, 42, 0.40), 0 10px 22px -12px rgba(15, 23, 42, 0.24);
}

* {
  box-sizing: border-box;
}

body { 
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  margin: 0;
  padding: 0;
  background: var(--bg-light);
  color: var(--text-primary);
  line-height: 1.6;
}

.container { 
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

header { 
  background: var(--surface-titlebar, var(--surface-header, var(--bg-white)));
  padding: 20px 24px;
  margin: -24px -24px 24px -24px;
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

header h1 {
  font-size: 24px;
  font-weight: 600;
  color: var(--titlebar-text, var(--text-primary));
  margin: 0;
}

.section { 
  background: var(--bg-white);
  border: 1px solid var(--border-color);
  padding: 24px;
  margin-bottom: 20px;
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
}

.section-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 16px 0;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--primary-color);
}

.input-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.label { 
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.input-group input,
.input-group select {
  width: 100%;
  padding: var(--control-padding-y, 8px) var(--control-padding-x, 10px);
  border: 1px solid var(--border-color);
  border-radius: var(--control-radius, 6px);
  font-size: var(--control-font-size, 14px);
  transition: all 0.2s;
  background: var(--bg-white);
}

.input-group input:focus,
.input-group select:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.input-group input::placeholder {
  color: #94a3b8;
}

.input-hint {
  display: block;
  font-size: 11px;
  color: #64748b;
  margin-top: 4px;
  line-height: 1.4;
}

.button-group {
  display: flex;
  gap: 12px;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border-color);
}

button { 
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--motion-fast, 0.2s);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

button:hover {
  transform: translateY(var(--button-hover-translate-y, -1px));
  box-shadow: var(--button-hover-shadow, var(--shadow-md));
}

button:active {
  transform: translateY(var(--button-active-translate-y, 0));
}

#btn-search {
  background: var(--primary-color);
  color: white;
  padding: 10px 32px;
}

#btn-search:hover {
  background: var(--primary-hover);
}

#btn-clear {
  background: var(--bg-white);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

#btn-clear:hover {
  background: var(--bg-light);
  border-color: var(--secondary-color);
}

.table-wrapper { 
  max-height: 600px;
  overflow: auto;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-white);
}

.table { 
  width: 100%;
  min-width: 1200px;
  border-collapse: separate;
  border-spacing: 0;
}

.table thead th {
  background: var(--table-header-bg, var(--bg-light));
  font-weight: 600;
  text-align: left;
  border-bottom: 2px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 5;
  white-space: nowrap;
}

/* ソート可能なヘッダー */
.table thead th.sortable {
  cursor: pointer;
  user-select: none;
  transition: background-color 0.2s;
}

.table thead th.sortable:hover {
  background: var(--table-header-hover-bg, #e5e7eb);
}

.table thead th.sorted {
  background: var(--table-header-sorted-bg, #dbeafe);
  color: var(--primary-color);
}

.table thead th .sort-icon {
  font-size: 11px;
  color: #9ca3af;
  margin-left: 4px;
}

.table thead th.sorted .sort-icon {
  color: var(--primary-color);
}

.table td { 
  padding: 12px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
}

.table tbody tr {
  transition: background-color 0.15s;
}

.table tbody tr:hover {
  background: var(--table-row-hover-bg, var(--bg-light));
  cursor: pointer;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.badge { 
  background: color-mix(in srgb, var(--primary-color) 14%, white);
  color: var(--primary-color);
  border: 1px solid color-mix(in srgb, var(--primary-color) 35%, white);
  border-radius: 4px;
  padding: 2px 8px;
  margin-left: 6px;
  font-size: 11px;
  font-weight: 500;
}

.sticky { 
  position: sticky;
  top: 0;
  background: var(--surface-titlebar, var(--surface-header, var(--bg-white)));
  z-index: 100;
  border-bottom: 1px solid var(--border-color);
  color: var(--titlebar-text, #fff);
}

/* モーダル */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0, 0, 0, 0.5);
  animation: fadeIn 0.2s;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background-color: var(--bg-white);
  margin: 5% auto;
  padding: 32px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  width: 90%;
  max-width: 600px;
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.3s;
}

@keyframes slideIn {
  from {
    transform: translateY(-50px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-content h2 {
  margin: 0 0 24px 0;
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 12px;
}

.modal-close {
  color: var(--text-secondary);
  float: right;
  font-size: 28px;
  font-weight: bold;
  line-height: 1;
  cursor: pointer;
  transition: color 0.2s;
}

.modal-close:hover,
.modal-close:focus {
  color: var(--text-primary);
}

/* UI改善用スタイル */

/* 拡張ヘッダー */
.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 16px;
}

.header-left {
  flex: 1;
}

.header-left h1 {
  color: var(--titlebar-text, #fff);
}

.header-right {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: flex-end;
}

.header-actions {
  display: flex;
  gap: 12px;
}

.header-actions .primary-button,
.header-actions .secondary-button {
  width: auto;
  min-width: 120px;
  padding: 10px 16px;
}

.header-subtitle {
  font-size: 14px;
  color: var(--titlebar-muted, rgba(255, 255, 255, 0.86));
  margin: 4px 0 0 0;
}

.status-info {
  display: flex;
  gap: 24px;
  text-align: right;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-item {
  font-size: 12px;
  color: var(--titlebar-muted, rgba(255, 255, 255, 0.86));
  display: block;
}

.case-info-bar {
  color: var(--titlebar-muted, rgba(255, 255, 255, 0.86));
}

.case-info-item strong {
  color: var(--titlebar-text, #fff);
}

/* パンくずリスト */
.breadcrumb {
  font-size: 12px;
  color: var(--titlebar-muted, var(--text-secondary));
  padding: 8px 0;
  border-top: 1px solid var(--titlebar-link-border, var(--border-color));
}

.breadcrumb-current {
  font-weight: 500;
  color: var(--titlebar-text, var(--text-primary));
}

.breadcrumb a {
  color: var(--titlebar-text, var(--text-primary));
}

.breadcrumb a:hover {
  color: var(--titlebar-text, var(--primary-color));
  text-decoration: underline;
}

/* メインコンテンツ */
.main-content {
  margin-top: 24px;
}

.section-header {
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
}

.section-header h2 {
  margin: 0 0 8px 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.section-header p {
  margin: 0;
  font-size: 14px;
  color: var(--text-secondary);
}

/* メニューカード */
.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 24px;
  margin-bottom: 32px;
}

.menu-card {
  background: var(--bg-white);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 24px;
  transition: all 0.3s ease;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 240px;
}

.menu-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
  border-color: var(--primary-color);
}

.menu-card:focus-within {
  border-color: var(--primary-color);
  box-shadow: var(--shadow-md);
}

.menu-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 28px;
  margin: 0 auto 6px auto;
  background: var(--bg-light);
  border: 1px solid var(--border-color);
}

.menu-card h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
  text-align: center;
}

.menu-card p {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin: 0;
  text-align: center;
}

.menu-actions {
  text-align: center;
  margin-top: auto;
}

/* 拡張ボタン */
.primary-button {
  background: var(--primary-color);
  color: white;
  padding: 12px 20px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--motion-fast, 0.2s);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  min-height: 44px;
  width: 100%;
  justify-content: center;
}

.primary-button:hover {
  background: var(--primary-hover);
  transform: translateY(var(--button-hover-translate-y, -1px));
  box-shadow: var(--button-hover-shadow, var(--shadow-md));
}

/* 情報カード */
.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
}

.info-card {
  background: var(--bg-light);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.info-card h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 12px 0;
}

.info-card ul {
  margin: 0;
  padding-left: 20px;
}

.info-card li {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 4px;
}

/* 固定フッター */
.sticky-footer {
  position: sticky;
  bottom: 0;
  background: var(--surface-header, var(--bg-white));
  border-top: 1px solid var(--border-color);
  padding: 16px 24px;
  margin: 32px -24px -24px -24px;
  z-index: 10;
}

.footer-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1400px;
  margin: 0 auto;
  gap: 12px;
}

.footer-left {
  font-size: 12px;
  color: var(--text-secondary);
}

.footer-right {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.footer-button {
  background: var(--bg-white);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: all var(--motion-fast, 0.2s);
  min-height: 36px;
}

.footer-button:hover {
  background: var(--bg-light);
  border-color: var(--secondary-color);
  color: var(--text-primary);
}

/* ヘルプコンテンツ */
.help-content,
.about-content {
  line-height: 1.6;
}

.help-content h3,
.about-content h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 20px 0 12px 0;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 4px;
}

.help-content ul,
.about-content ul {
  margin: 0;
  padding-left: 20px;
}

.help-content li,
.about-content li {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

/* 検索画面専用スタイル */

/* クイックアクションボタン */
.quick-actions {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
}

.secondary-button {
  background: var(--bg-white);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--motion-fast, 0.2s);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}

.secondary-button:hover {
  background: var(--bg-light);
  border-color: var(--secondary-color);
  color: var(--text-primary);
  transform: translateY(var(--button-hover-translate-y, -1px));
  box-shadow: var(--shadow-sm);
}

/* 検索グリッドレイアウト */
.search-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 24px;
  margin-bottom: 24px;
}

.search-column h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 12px 0;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--primary-color);
}

/* 検索アクションボタン */
.search-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border-color);
}

/* 検索条件サマリー */
.search-summary {
  background: var(--surface-display, var(--bg-light));
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 16px;
  margin-top: 16px;
}

.search-summary h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 12px 0;
}

.summary-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-tag {
  background: var(--primary-color);
  color: white;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 12px;
  white-space: nowrap;
}

/* 結果情報 */
.result-info {
  margin-top: 8px;
}

#result-stats {
  font-size: 14px;
  color: var(--text-secondary);
  font-style: italic;
}

/* 結果アクションボタン */
.result-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
}

/* 検索結果なしメッセージ */
.no-results {
  text-align: center;
  padding: 48px 24px;
  background: var(--bg-light);
  border-radius: 12px;
  border: 2px dashed var(--border-color);
}

.no-results-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.no-results h3 {
  font-size: 18px;
  color: var(--text-primary);
  margin: 0 0 8px 0;
}

.no-results p {
  font-size: 14px;
  color: var(--text-secondary);
  margin: 0 0 20px 0;
}

/* ヒントカード */
.tips-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
}

.tip-card {
  background: var(--bg-light);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 20px;
}

.tip-card h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 12px 0;
}

.tip-card ul {
  margin: 0;
  padding-left: 20px;
}

.tip-card li {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 6px;
}

/* レスポンシブ対応の拡張 */
@media (max-width: 768px) {
  .search-grid {
    grid-template-columns: 1fr;
  }

  .tips-grid {
    grid-template-columns: 1fr;
  }

  .quick-actions {
    flex-direction: column;
  }

  .search-actions {
    flex-direction: column;
  }

  .result-actions {
    flex-direction: column;
  }

  .summary-tags {
    flex-direction: column;
  }

  .status-info {
    flex-direction: column;
    gap: 8px;
  }
}

/* 編集状態表示 */
.status-saved {
  color: var(--success-color);
  font-weight: 600;
}

.status-unsaved {
  color: #ef4444;
  font-weight: 600;
}

/* API接続状態表示 */
.api-connected {
  color: var(--success-color);
  font-weight: 600;
}

.api-disconnected {
  color: #ef4444;
  font-weight: 600;
}

.api-checking {
  color: var(--text-secondary);
  font-weight: 400;
}

/* フィールドステータス */
.field-status {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* 必須項目マーク */
.required {
  color: #ef4444;
  font-weight: 600;
  margin-left: 2px;
}

/* 明細フォームセクション */
.detail-form-section {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 2px solid var(--border-color);
}

.detail-form-section h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 8px 0;
}

.form-description {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0 0 16px 0;
}

/* アサインセクション */
.assign-section {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 2px solid var(--border-color);
}

.assign-section h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 8px 0;
}

.section-description {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0 0 16px 0;
}

/* 月次管理フォーム */
.monthly-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.monthly-input-form {
  background: var(--bg-light);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* 明細操作ボタン */
.detail-actions {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

#btn-copy-detail {
  min-width: 120px;
  white-space: nowrap;
  background: var(--primary-color);
  color: #ffffff;
  border: 1px solid var(--primary-color);
}

#btn-copy-detail:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  color: #ffffff;
}

/* フォームアクション */
.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border-color);
  flex-wrap: wrap;
}

/* 案件情報バー（ヘッダー内） */
.case-info-bar {
  display: flex;
  gap: 20px;
  padding: 12px 0;
  border-top: 1px solid var(--titlebar-link-border, var(--border-color));
  margin-top: 12px;
  flex-wrap: wrap;
}

.case-info-item {
  font-size: 13px;
  color: var(--titlebar-muted, rgba(255, 255, 255, 0.86));
}

.case-info-item strong {
  color: var(--titlebar-text, #fff);
  font-weight: 600;
  margin-left: 4px;
}

/* 明細情報バー（ヘッダー内） */
.detail-info-bar {
  display: flex;
  gap: 20px;
  padding: 12px 0;
  border-top: 1px solid var(--border-color);
  margin-top: 8px;
  flex-wrap: wrap;
  background-color: #f0f9ff;
  padding: 12px 16px;
  border-radius: 6px;
}

.detail-info-item {
  font-size: 13px;
  color: var(--text-secondary);
}

.detail-info-item strong {
  color: var(--primary-color);
  font-weight: 600;
  margin-left: 4px;
}

/* テーブル行の選択状態 */
.table tbody tr.selected-row {
  background-color: var(--table-row-selected-bg, #dbeafe);
  font-weight: 500;
}

.table tbody tr:hover {
  background-color: var(--table-row-hover-bg, #f1f5f9);
}

/* コンパクトフォームグリッド - 基本情報用 */
.compact-form-grid {
  display: grid;
  grid-template-columns: 1fr 2fr 2fr 1.5fr;
  gap: 16px;
  margin-bottom: 20px;
  grid-template-rows: auto auto;
}

/* 1行目: 案件番号、案件名、契約先、業種名 */
.compact-form-grid .input-group:nth-child(1) { grid-column: 1; }
.compact-form-grid .input-group:nth-child(2) { grid-column: 2; }
.compact-form-grid .input-group:nth-child(3) { grid-column: 3; }
.compact-form-grid .input-group:nth-child(4) { grid-column: 4; }

/* 2行目: 営業担当部門、担当営業名 */
.compact-form-grid .input-group:nth-child(5) { grid-column: 1 / 3; }
.compact-form-grid .input-group:nth-child(6) { grid-column: 3; }

/* 明細フォームグリッド - 美しく整然とした配置 */
.detail-form-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  margin-bottom: 16px;
  align-items: end;
}

/* 1行目: 明細番号、明細名、確度、区分、PM */
.detail-form-grid > .input-group:nth-child(1) { 
  grid-column: 1;
  max-width: 100px;
}
.detail-form-grid > .input-group:nth-child(2) { 
  grid-column: 2 / 4;
}
.detail-form-grid > .input-group:nth-child(3) { 
  grid-column: 4;
  max-width: 140px;
}
.detail-form-grid > .input-group:nth-child(3) #detail-probability {
  width: 100%;
  min-width: 140px;
}
.detail-form-grid > .input-group:nth-child(4) { 
  grid-column: 5;
  max-width: 100px;
}
.detail-form-grid > .input-group:nth-child(5) { 
  grid-column: 6;
}
.detail-form-grid > .input-group:nth-child(6) { 
  grid-column: 1 / 4;
}

/* 2行目: 受注日、開始日、終了日、会計PJ番号 */
.detail-form-grid > .input-group:nth-child(7),
.detail-form-grid > .input-group:nth-child(8),
.detail-form-grid > .input-group:nth-child(9) {
  grid-column: span 1;
}
.detail-form-grid > .input-group:nth-child(10) {
  grid-column: span 2;
}

/* 3行目: 案件スキル、契約タイプ */
.detail-form-grid > .input-group:nth-child(11) {
  grid-column: span 2;
}
.detail-form-grid > .input-group:nth-child(12) {
  grid-column: span 2;
}

/* 4行目: サマリーフィールド（予定売上、計画コスト、計画利益、利益率、経費） */
.detail-form-grid > .input-group:nth-child(13),
.detail-form-grid > .input-group:nth-child(14),
.detail-form-grid > .input-group:nth-child(15),
.detail-form-grid > .input-group:nth-child(16),
.detail-form-grid > .input-group:nth-child(17) {
  grid-column: span 1;
}

/* フィールド幅調整 */
.compact-field {
  grid-column: span 1;
}

.wide-field {
  grid-column: span 1;
}

/* 日付フィールド - 統一サイズ（美しく揃える） */
.date-field {
  width: 100%;
  min-width: 140px;
  max-width: 160px;
}

.date-field input {
  width: 100%;
}

/* 金額フィールド - 統一サイズ（金額がきちんと表示される） */
.currency-field {
  width: 100%;
  min-width: 140px;
  max-width: 180px;
}

 .currency-field.contingency-field {
   max-width: 240px;
 }

 .currency-field.contingency-field .label {
   white-space: nowrap;
 }

.currency-field input {
  width: 100%;
  text-align: right;
  font-weight: 500;
}

/* サマリーフィールドのスタイル */
.summary-field {
  background-color: var(--surface-inset, var(--bg-light));
  padding: 6px;
  border-radius: 6px;
}

.summary-field label {
  font-weight: 600;
  color: var(--primary-color);
}

/* 金額表示フィールド */
.currency-display {
  text-align: right;
  font-weight: 600;
  background-color: var(--surface-display, var(--bg-light));
  color: var(--text-primary);
}

/* 金額入力フィールド */
.currency-input {
  text-align: right;
  font-weight: 500;
}

.compact-field {
  grid-column: span 1;
}

.medium-field {
  grid-column: span 2;
}

.wide-field {
  grid-column: span 3;
}

.compact-input {
  max-width: 200px;
}

/* 金額入力フィールド（右寄せ） */
.currency-input {
  text-align: right;
}

/* 期間選択 */
.period-selector {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.period-selector .label {
  margin-bottom: 0;
}

/* 集計表示セクション */
.aggregation-section {
  margin-top: 24px;
  padding: 20px;
  background: var(--surface-display, var(--bg-light));
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.aggregation-section h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 16px 0;
}

/* アサイン一括登録モーダル */
.modal-large {
  max-width: 95vw;
  width: 95vw;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-description {
  color: var(--text-secondary);
  font-size: 14px;
  margin: 8px 0 20px 0;
}

.bulk-assign-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
  overflow: hidden;
}

.bulk-assign-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  background: var(--bg-light);
  border-radius: 6px;
  border: 1px solid var(--border-color);
}

.detail-info {
  display: flex;
  gap: 20px;
  font-size: 14px;
  color: var(--text-primary);
}

.detail-info strong {
  color: var(--text-secondary);
  font-weight: 600;
}

.bulk-assign-grid-wrapper {
  flex: 1;
  overflow: auto;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: white;
}

.bulk-assign-grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.bulk-assign-grid thead {
  position: sticky;
  top: 0;
  background: var(--bg-light);
  z-index: 10;
}

.bulk-assign-grid th {
  padding: 10px 8px;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border-color);
  white-space: nowrap;
  font-size: 12px;
}

.bulk-assign-grid td {
  padding: 8px;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}

.bulk-assign-grid tbody tr:hover {
  background: var(--bg-light);
}

/* 固定列（メンバー種別、メンバー名） */
.bulk-assign-grid th:nth-child(1),
.bulk-assign-grid th:nth-child(2),
.bulk-assign-grid td:nth-child(1),
.bulk-assign-grid td:nth-child(2) {
  position: sticky;
  background: white;
  z-index: 5;
}

.bulk-assign-grid th:nth-child(1),
.bulk-assign-grid td:nth-child(1) {
  left: 0;
  min-width: 100px;
}

.bulk-assign-grid th:nth-child(2),
.bulk-assign-grid td:nth-child(2) {
  left: 100px;
  min-width: 150px;
}

.bulk-assign-grid thead th:nth-child(1),
.bulk-assign-grid thead th:nth-child(2) {
  background: var(--bg-light);
}

.bulk-assign-grid tbody tr:hover td:nth-child(1),
.bulk-assign-grid tbody tr:hover td:nth-child(2) {
  background: var(--bg-light);
}

/* グリッド内の入力フィールド */
.bulk-grid-input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 13px;
  transition: all 0.2s;
}

.bulk-grid-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.bulk-grid-input.error {
  border-color: #ef4444;
  background-color: #fef2f2;
}

.bulk-grid-input:disabled {
  background-color: #f8fafc;
  cursor: not-allowed;
}

.bulk-grid-select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 13px;
  background: white;
  cursor: pointer;
}

.bulk-grid-effort {
  width: 60px;
  text-align: center;
}

.bulk-grid-price {
  width: 100px;
  text-align: right;
}

.bulk-grid-total {
  font-weight: 600;
  color: var(--primary-color);
  text-align: center;
}

.bulk-row-delete {
  background: none;
  border: none;
  color: #ef4444;
  cursor: pointer;
  font-size: 18px;
  padding: 4px 8px;
  transition: all 0.2s;
}

.bulk-row-delete:hover {
  background: #fee2e2;
  border-radius: 4px;
}

.bulk-assign-footer {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
}

/* エラーメッセージ */
.bulk-error-message {
  padding: 12px 16px;
  background-color: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 6px;
  color: #991b1b;
  font-size: 13px;
  line-height: 1.6;
}

.bulk-error-message ul {
  margin: 8px 0 0 0;
  padding-left: 20px;
}

.bulk-error-message li {
  margin: 4px 0;
}

/* 成功メッセージ */
.bulk-success-message {
  padding: 12px 16px;
  background-color: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 6px;
  color: #166534;
  font-size: 13px;
}

/* ローディングオーバーレイ */
.bulk-loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  border-radius: 8px;
}

.bulk-loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid #e5e7eb;
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.bulk-loading-text {
  margin-top: 16px;
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* ツールチップ */
.bulk-tooltip {
  position: relative;
  display: inline-block;
  cursor: help;
  margin-left: 4px;
  color: var(--text-secondary);
}

.bulk-tooltip:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 12px;
  background: #1f2937;
  color: white;
  font-size: 12px;
  border-radius: 4px;
  white-space: nowrap;
  z-index: 1000;
  margin-bottom: 8px;
}

.bulk-tooltip:hover::before {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #1f2937;
  margin-bottom: 2px;
}

/* 月次管理グリッド */
.monthly-management {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* 月次管理コントロール */
.monthly-controls {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: 6px;
}

.monthly-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 13px;
}

.monthly-status .status-icon {
  font-size: 16px;
}

.monthly-status.status-changed {
  background: #fef3c7;
  border-color: #fbbf24;
}

.monthly-status.status-changed .status-icon {
  color: #f59e0b;
}

.monthly-status.status-calculating {
  background: #dbeafe;
  border-color: #60a5fa;
}

.monthly-status.status-calculating .status-icon {
  color: #3b82f6;
  animation: spin 1s linear infinite;
}

.monthly-status.status-updated {
  background: #d1fae5;
  border-color: #34d399;
}

.monthly-status.status-updated .status-icon {
  color: #10b981;
}

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

.monthly-grid-wrapper {
  overflow: auto;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: white;
  max-height: 600px;
}

.monthly-grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.monthly-grid thead {
  position: sticky;
  top: 0;
  background: var(--bg-light);
  z-index: 10;
}

.monthly-grid th {
  padding: 12px 10px;
  text-align: center;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border-color);
  border-right: 1px solid var(--border-color);
  white-space: nowrap;
  font-size: 12px;
}

.monthly-grid th:first-child {
  position: sticky;
  left: 0;
  background: var(--bg-light);
  z-index: 11;
  text-align: left;
  min-width: 140px;
}

.monthly-grid td {
  padding: 10px;
  border-bottom: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
  text-align: right;
  vertical-align: middle;
}

.monthly-grid td:first-child {
  position: sticky;
  left: 0;
  background: white;
  z-index: 5;
  text-align: left;
  font-weight: 600;
  color: var(--text-primary);
}

.monthly-grid tbody tr:hover td {
  background: var(--bg-light);
}

.monthly-grid tbody tr:hover td:first-child {
  background: var(--bg-light);
}

/* 行タイトルのスタイル */
.monthly-grid .row-title-sales {
  color: var(--primary-color);
}

.monthly-grid .row-title-cost {
  color: #dc2626;
}

.monthly-grid .row-title-separator {
  border-top: 2px solid var(--border-color);
  background: #f8fafc;
}

.monthly-grid .row-title-posted {
  color: #059669;
}

.monthly-grid .row-title-wip {
  color: #7c3aed;
}

.monthly-grid .row-title-cumulative {
  color: #ea580c;
  font-size: 12px;
}

/* 仕掛率セレクトボックス */
.monthly-wip-select {
  width: 80px;
  padding: 6px 8px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 13px;
  text-align: center;
  background: white;
  cursor: pointer;
  transition: all 0.2s;
}

.monthly-wip-select:hover {
  border-color: var(--primary-color);
  background: #f0f9ff;
}

.monthly-wip-select:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

/* 旧仕掛率入力フィールド（互換性のため残す） */
.monthly-wip-input {
  width: 70px;
  padding: 6px 8px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 13px;
  text-align: center;
  transition: all 0.2s;
}

.monthly-wip-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

/* 合計列のスタイル */
.monthly-grid .total-column {
  background: #f0f9ff;
  font-weight: 600;
  color: var(--primary-color);
}

/* 読み取り専用セル */
.monthly-grid .readonly-cell {
  background: #f8fafc;
  color: var(--text-secondary);
}

/* 計算値のスタイル */
.monthly-grid .calculated-value {
  font-weight: 500;
}

.monthly-grid .positive-value {
  color: #059669;
}

.monthly-grid .negative-value {
  color: #dc2626;
}

/* 情報テキスト */
.monthly-info {
  padding: 12px 16px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
}

.info-text {
  margin: 0;
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.6;
}

.info-text strong {
  color: var(--primary-color);
}

/* 月次グリッドのアニメーション */
.monthly-grid tbody tr {
  transition: background-color 0.2s ease;
}

.monthly-wip-input {
  transition: all 0.2s ease;
}

.monthly-wip-input:hover {
  border-color: var(--primary-color);
  background: #f0f9ff;
}

/* 月次グリッドのツールチップ */
.monthly-grid th[title] {
  cursor: help;
  position: relative;
}

/* 数値のフォーマット */
.monthly-grid .currency-value {
  font-variant-numeric: tabular-nums;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
}

/* エラー状態 */
.monthly-grid .error-cell {
  background: #fef2f2;
  border: 1px solid #fecaca;
}

/* ローディング状態 */
.monthly-grid-loading {
  position: relative;
}

.monthly-grid-loading::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 空データ表示 */
.monthly-grid .empty-data {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
  font-size: 14px;
}

/* 月次グリッドのレスポンシブ対応 */
@media (max-width: 1200px) {
  .monthly-grid {
    font-size: 12px;
  }
  
  .monthly-grid th,
  .monthly-grid td {
    padding: 8px 6px;
  }
  
  .monthly-wip-select {
    width: 70px;
    padding: 4px 6px;
    font-size: 12px;
  }
  
  .monthly-wip-input {
    width: 60px;
    padding: 4px 6px;
    font-size: 12px;
  }
}

@media (max-width: 768px) {
  .monthly-grid-wrapper {
    max-height: 400px;
  }
  
  .monthly-grid {
    font-size: 11px;
  }
  
  .monthly-grid th,
  .monthly-grid td {
    padding: 6px 4px;
  }
  
  .monthly-wip-select {
    width: 60px;
    padding: 3px 4px;
    font-size: 11px;
  }
  
  .monthly-wip-input {
    width: 50px;
    padding: 3px 4px;
    font-size: 11px;
  }
  
  .monthly-info {
    padding: 10px 12px;
  }
  
  .info-text {
    font-size: 12px;
  }
}

/* レスポンシブ対応 */
@media (max-width: 1400px) {
  .modal-large {
    max-width: 98vw;
    width: 98vw;
  }
  
  .bulk-assign-grid {
    font-size: 12px;
  }
  
  .bulk-grid-input,
  .bulk-grid-select {
    padding: 5px 6px;
    font-size: 12px;
  }
}

@media (max-width: 1024px) {
  .detail-form-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  
  .bulk-assign-header {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }
  
  .detail-info {
    flex-direction: column;
    gap: 8px;
  }
}

@media (max-width: 768px) {
  .modal-large {
    max-width: 100vw;
    width: 100vw;
    max-height: 100vh;
    border-radius: 0;
  }
  
  .bulk-assign-grid th,
  .bulk-assign-grid td {
    padding: 6px 4px;
  }
  
  .bulk-grid-input,
  .bulk-grid-select {
    padding: 4px;
    font-size: 11px;
  }
}

.aggregation-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.aggregation-grid-main {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.aggregation-grid-breakdown {
  grid-template-columns: 120px repeat(4, minmax(180px, 1fr));
  align-items: stretch;
  margin-top: 12px;
}

.aggregation-breakdown-label {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 10px 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  border-left: 3px solid var(--primary-color);
}

.aggregation-item {
  background: var(--bg-white);
  padding: 16px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
}

.aggregation-grid-breakdown .aggregation-item {
  padding: 14px;
}

.aggregation-item.highlight {
  background: #f0f9ff;
  border-color: var(--primary-color);
}

.aggregation-item label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 10px;
  font-weight: 500;
  line-height: 1.35;
}

.aggregation-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  text-align: right;
  line-height: 1.25;
}

.aggregation-grid-breakdown .aggregation-value {
  font-size: 18px;
}

.aggregation-item.highlight .aggregation-value {
  color: var(--primary-color);
}

@media (max-width: 768px) {
  .aggregation-grid-breakdown {
    grid-template-columns: 1fr;
    margin-top: 16px;
  }

  .aggregation-breakdown-label {
    padding: 8px 12px;
    border-left: none;
    border-bottom: 2px solid var(--primary-color);
  }
}

/* セクションヘッダーとアクションボタンの横並び */
.section-header-with-action {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
  gap: 16px;
}

.section-header-with-action h3 {
  margin: 0 0 8px 0;
}

.section-header-with-action .section-description {
  margin: 0;
}

/* レスポンシブ対応 */
@media (max-width: 1200px) {
  .wide-field {
    grid-column: span 2;
  }
}

@media (max-width: 768px) {
  .compact-form-grid {
    grid-template-columns: 1fr;
  }
  
  .compact-field,
  .medium-field,
  .wide-field {
    grid-column: span 1;
  }
  
  .compact-input {
    max-width: 100%;
  }
  
  .case-info-bar {
    flex-direction: column;
    gap: 8px;
  }
  
  .section-header-with-action {
    flex-direction: column;
  }

  .container {
    padding: 16px;
  }

  header {
    margin: -16px -16px 16px -16px;
    padding: 16px;
  }

  .header-content {
    flex-direction: column;
    align-items: flex-start;
  }

  .header-right {
    align-items: flex-start;
    width: 100%;
  }

  .status-info {
    justify-content: flex-start;
    gap: 12px;
  }

  .menu-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .sticky-footer {
    margin: 24px -16px -16px -16px;
    padding: 12px 16px;
  }

  .footer-content {
    flex-direction: column;
    align-items: flex-start;
  }

  .footer-right {
    width: 100%;
    justify-content: flex-start;
  }
}
