/* ========================================
   予実管理ダッシュボード専用スタイル
   ======================================== */

body {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.dashboard-header {
  background: var(--surface-titlebar, var(--surface-header, white));
  color: var(--titlebar-text, var(--text-primary));
  box-shadow: var(--shadow-sm);
  border-bottom: 1px solid var(--border-color);
  flex: 0 0 auto;
  position: sticky;
  top: 0;
  z-index: 1000;
}

.dashboard-title {
  color: var(--titlebar-text, var(--text-primary));
}

.dashboard-header .nav-link {
  background: var(--titlebar-link-bg, rgba(0, 0, 0, 0.04));
  color: var(--titlebar-text, var(--text-primary));
  border: 1px solid var(--titlebar-link-border, var(--border-color));
}

.dashboard-header .nav-link:hover {
  background: var(--titlebar-link-hover-bg, rgba(0, 0, 0, 0.08));
  color: var(--titlebar-text, white);
  border-color: var(--titlebar-link-border, var(--primary-color));
}

/* ========== 基本レイアウト ========== */
.dashboard-main {
  max-width: 1600px;
  margin: 0 auto;
  padding: 20px;
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ========== フィルタセクション ========== */
.filter-section {
  background: var(--surface-inset, white);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}

.filter-container {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  align-items: flex-end;
}

.filter-group {
  flex: 1;
  min-width: 200px;
}

.period-group {
  flex: 2;
  min-width: 360px;
}

.closing-month-group {
  flex: 0 0 240px;
  min-width: 240px;
  padding-left: 16px;
  border-left: 1px solid var(--border-color);
}

.filter-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: #333;
  margin-bottom: 8px;
  font-size: 14px;
}

.label-icon {
  font-size: 16px;
}

.filter-select,
.filter-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
  transition: border-color 0.2s;
  background: var(--surface-input, white);
}

.filter-select:focus,
.filter-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: var(--focus-ring);
}

.period-inputs {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.period-inputs .filter-input {
  width: auto;
  flex: 1 1 0;
  min-width: 0;
}

.period-inputs .period-separator {
  flex: 0 0 auto;
}

.period-separator {
  color: #666;
  font-weight: 500;
}

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

.header-filter-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0 0 0;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--titlebar-link-border, var(--border-color));
  background: var(--titlebar-link-bg, rgba(0, 0, 0, 0.04));
  color: var(--titlebar-text, var(--text-secondary));
  font-size: 12px;
  font-weight: 600;
}

/* ========== ボタン ========== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--primary-color);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background: #f5f5f5;
  color: #333;
}

.btn-secondary:hover {
  background: #e0e0e0;
}

.btn-icon {
  font-size: 16px;
}

/* ========== サマリーセクション ========== */
.summary-section {
  margin-bottom: 24px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
}

.summary-card {
  background: var(--surface-display, white);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s, box-shadow 0.2s;
}

.summary-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 2px solid #f0f0f0;
}

.card-icon {
  font-size: 24px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  color: #333;
  margin: 0;
}

.card-body {
  padding: 0;
}

.metric-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.metric {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
}

.metric-label {
  font-size: 13px;
  color: #666;
  font-weight: 500;
}

.metric-value {
  font-size: 18px;
  font-weight: 700;
  color: #333;
}

/* カード別の色分け */
.card-budget .card-header {
  border-bottom-color: var(--primary-color);
}

.card-budget .card-icon {
  color: var(--primary-color);
}

.card-actual .card-header {
  border-bottom-color: var(--success-color, #10b981);
}

.card-actual .card-icon {
  color: var(--success-color, #10b981);
}

.card-variance .card-header {
  border-bottom-color: var(--warning-color, #f59e0b);
}

.card-variance .card-icon {
  color: var(--warning-color, #f59e0b);
}

.card-achievement .card-header {
  border-bottom-color: var(--primary-color);
}

.card-achievement .card-icon {
  color: var(--primary-color);
}

/* ========== グラフセクション ========== */
.charts-section {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(600px, 1fr));
  gap: 32px;
  margin-bottom: 32px;
}

.chart-container {
  background: var(--surface-card, white);
  border-radius: 12px;
  padding: 24px;
  padding-bottom: 32px;
  box-shadow: var(--shadow-sm);
  min-height: 480px;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 2px solid #f0f0f0;
}

.chart-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 600;
  color: #333;
  margin: 0;
}

.chart-controls {
  display: flex;
  gap: 8px;
}

.chart-btn {
  padding: 6px 14px;
  border: 1px solid #ddd;
  background: white;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.chart-btn:hover {
  background: #f5f5f5;
}

.chart-btn.active {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.chart-body {
  position: relative;
  height: 400px;
  margin-top: 8px;
}

.chart-body canvas {
  max-height: 100%;
  display: block;
}

/* ========== テーブルセクション ========== */
.table-section {
  margin-bottom: 24px;
}

.table-container {
  background: var(--surface-display, white);
  border-radius: 12px;
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

.table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 2px solid #f0f0f0;
}

.table-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 600;
  color: #333;
  margin: 0;
}

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

.table-wrapper {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid #e0e0e0;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table thead {
  background: color-mix(in srgb, var(--primary-color) 8%, #f8f9fa);
  position: sticky;
  top: 0;
  z-index: 60;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.06);
}

.data-table th {
  padding: 12px 8px;
  text-align: center;
  font-weight: 600;
  color: #333;
  border: 1px solid #e0e0e0;
  background: color-mix(in srgb, var(--primary-color) 8%, #f8f9fa);
  white-space: nowrap;
}

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

.data-table tbody tr:hover {
  background-color: #f5f5f5;
}

.data-table tbody tr:nth-child(even) {
  background-color: #fafafa;
}

.data-table td {
  padding: 10px 8px;
  text-align: right;
  border: 1px solid #e0f0f0;
}

.data-table td:first-child,
.data-table td:nth-child(2) {
  text-align: center;
  font-weight: 500;
}

.data-table tfoot {
  background: #f0f0f0;
  font-weight: 700;
}

.data-table tfoot td {
  padding: 12px 8px;
  border-top: 2px solid #333;
}

/* 値の色分け */
.value-positive {
  color: var(--success-color, #10b981);
  font-weight: 600;
}

.value-negative {
  color: var(--danger-color, #ef4444);
  font-weight: 600;
}

.value-neutral {
  color: #666;
}

/* 状態バッジ */
.status-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
}

.status-confirmed {
  background: #e8f5e9;
  color: #2e7d32;
}

.status-planned {
  background: #fff3e0;
  color: #e65100;
}

/* 実績と見通しの境界線 */
.data-table tbody tr.boundary-row td {
  border-top: 3px solid var(--warning-color, #f59e0b) !important;
  position: relative;
}

.data-table tbody tr.boundary-row td:first-child::before {
  content: '▼ 以降は見通し（計画値）';
  position: absolute;
  left: 50%;
  top: -15px;
  transform: translateX(-50%);
  background: var(--warning-color, #f59e0b);
  color: white;
  padding: 3px 16px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  z-index: 5;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* 見通し行の背景色 */
.data-table tbody tr.planned-row {
  background-color: #fff8e1 !important;
}

.data-table tbody tr.planned-row:hover {
  background-color: #ffecb3 !important;
}

/* 四半期行のスタイル */
.data-table tbody tr.quarter-row {
  background-color: #e3f2fd !important;
  font-weight: bold;
  border-top: 2px solid var(--primary-color);
  border-bottom: 2px solid var(--primary-color);
}

.data-table tbody tr.quarter-row:hover {
  background-color: #bbdefb !important;
}

.data-table tbody tr.quarter-row td {
  padding: 12px 8px;
}

/* ========== 確度別分布セクション ========== */
.probability-section {
  margin-bottom: 24px;
}

.probability-container {
  background: var(--surface-display, white);
  border-radius: 12px;
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

.probability-header {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 2px solid #f0f0f0;
}

.probability-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 600;
  color: #333;
  margin: 0 0 8px 0;
}

.probability-note {
  font-size: 13px;
  color: #666;
  margin: 0;
  font-style: italic;
}

.probability-body {
  position: relative;
  height: 300px;
}

/* ========== レスポンシブ対応 ========== */
@media (max-width: 1200px) {
  .charts-section {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .filter-container {
    flex-direction: column;
  }
  
  .filter-group {
    width: 100%;
  }
  
  .filter-actions {
    width: 100%;
    flex-direction: column;
  }
  
  .filter-actions .btn {
    width: 100%;
    justify-content: center;
  }
  
  .summary-grid {
    grid-template-columns: 1fr;
  }
  
  .table-wrapper {
    font-size: 11px;
  }
  
  .data-table th,
  .data-table td {
    padding: 8px 4px;
  }
}

/* ========== ダークモード対応 ========== */
@media (prefers-color-scheme: dark) {
  .filter-section,
  .summary-card,
  .chart-container,
  .table-container,
  .probability-container {
    background: #1e1e1e;
    color: #e0e0e0;
  }
  
  .filter-select,
  .filter-input {
    background: #2a2a2a;
    border-color: #444;
    color: #e0e0e0;
  }
  
  .data-table thead {
    background: #2a2a2a;
  }
  
  .data-table tbody tr:nth-child(even) {
    background-color: #252525;
  }
  
  .data-table tbody tr:hover {
    background-color: #2a2a2a;
  }
  
  .data-table th,
  .data-table td {
    border-color: #444;
    color: #e0e0e0;
  }
  
  .data-table tfoot {
    background: #2a2a2a;
  }
}

/* ========== アニメーション ========== */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.summary-card,
.chart-container,
.table-container {
  animation: fadeIn 0.3s ease-out;
}

/* ========== ローディング状態 ========== */
.loading {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 40px;
  color: #666;
  font-size: 16px;
}

.loading::before {
  content: "⏳";
  margin-right: 8px;
  animation: spin 1s linear infinite;
}

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