/* ============================================================
   Sentimind — Dashboard Components
   히스토리, 대시보드 요약, 바 차트, 트렌드
   ============================================================ */

/* --- History --- */
/* History */
.diary-history {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--color-divider);
  animation: fadeInUp 500ms 200ms cubic-bezier(0.25,0.46,0.45,0.94) both;
}
.section-title {
  font-family: var(--font-diary);
  font-size: var(--text-lg);
  color: var(--color-text);
  font-weight: var(--weight-semibold);
  margin-bottom: 1.25rem;
  text-wrap: balance;
}
/* ===== Select Mode ===== */
.history-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}
.history-title-row .section-title { margin-bottom: 0; }
.btn-select-mode {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.75rem;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  cursor: pointer;
  font-family: var(--font-body);
  transition: color 200ms, border-color 200ms;
}
.btn-select-mode:hover { color: var(--color-primary); border-color: var(--color-primary); }
.btn-select-mode.active { color: var(--color-primary); border-color: var(--color-primary); font-weight: 600; }
.select-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: 0.75rem;
}
.select-toolbar[hidden] { display: none; }
.select-all-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--color-text-muted);
  cursor: pointer;
  flex: 1;
}
.select-all-label input[type="checkbox"] { accent-color: var(--color-primary); }
.btn-select-delete {
  background: #e74c3c;
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.9rem;
  font-size: 0.8rem;
  cursor: pointer;
  font-family: var(--font-body);
  transition: opacity 200ms;
}
.btn-select-delete:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-select-cancel {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  cursor: pointer;
  font-family: var(--font-body);
}
.history-item .select-check {
  display: none;
  margin-left: 0.5rem;
  margin-right: -0.5rem;
  accent-color: var(--color-primary);
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  cursor: pointer;
}
.select-mode .history-item .select-check { display: block; }
.select-mode .history-item .btn-bookmark { display: none; }
.history-item.selected { border-color: var(--color-primary); background: rgba(196, 139, 108, 0.05); }

.history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-height: 60vh;
  overflow-y: auto;
  padding-right: 4px;
}
.history-list::-webkit-scrollbar { width: 4px; }
.history-list::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 2px; }
.history-list::-webkit-scrollbar-track { background: transparent; }
.history-item {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  position: relative;
  display: flex;
  align-items: stretch;
  border: 1px solid var(--color-border);
  animation: fadeInUp 300ms cubic-bezier(0.25,0.46,0.45,0.94) both;
  transition: box-shadow 200ms ease, border-color 200ms ease, transform 200ms ease;
}
.history-item:hover {
  box-shadow: var(--shadow-md);
  border-color: transparent;
  transform: translateY(-1px);
}
.history-item-inner {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  padding: 1rem 1.25rem;
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
  color: inherit;
  text-align: left;
  border-radius: var(--radius-lg);
}
.history-item-inner:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}
.history-emoji {
  width: 48px; height: 48px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
}
.history-content { flex: 1; min-width: 0; }
.history-meta {
  display: flex; align-items: center; gap: 0.5rem;
  margin-top: 0.35rem;
}
.history-emotion {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-primary);
  background: rgba(196, 139, 108, 0.1);
  padding: 0.1rem 0.5rem;
  border-radius: var(--radius-sm);
}
.history-date {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}
.history-text {
  font-family: var(--font-diary);
  font-size: var(--text-sm);
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  white-space: normal;
  line-height: var(--leading-base);
}
.btn-delete {
  background: none; border: none;
  color: var(--color-text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity 200ms;
  padding: 8px 12px;
  min-width: 44px; min-height: 44px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.history-item:hover .btn-delete { opacity: 1; }
.btn-delete:hover { color: #c0392b; }
.btn-delete:focus-visible { opacity: 1; outline: 2px solid var(--color-primary); outline-offset: 2px; }
.btn-bookmark {
  background: none; border: none; cursor: pointer;
  font-size: 1.4rem; color: var(--color-text-muted);
  padding: 0.75rem; flex-shrink: 0; transition: color 200ms, transform 200ms;
  align-self: center;
  opacity: 0.7;
}
.history-item:hover .btn-bookmark { opacity: 1; }
.btn-bookmark.active { color: #e74c3c; opacity: 1; font-size: 1.5rem; }
.btn-bookmark:hover { transform: scale(1.15); opacity: 1; }
@media (hover: none) { .btn-delete { opacity: 0.6; } }
.history-item.deleting {
  animation: slideOut 300ms ease forwards;
}
@keyframes slideOut {
  to { transform: translateX(100%); opacity: 0; max-height: 0; margin: 0; padding: 0; overflow: hidden; }
}
.history-item:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

/* 더 보기 버튼 */
.history-load-more {
  list-style: none;
  text-align: center;
  padding: 0.75rem 0;
}
.btn-load-more {
  display: inline-block;
  padding: 0.6rem 1.5rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-primary);
  font-family: var(--font-ui);
  font-size: clamp(0.8rem, 0.75rem + 0.25vw, 0.9rem);
  cursor: pointer;
  transition: background 200ms ease, box-shadow 200ms ease;
}
.btn-load-more:hover {
  background: var(--color-bg);
  box-shadow: var(--shadow-sm);
}
.btn-load-more:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.empty-state {
  text-align: center;
  color: var(--color-text-muted);
  font-size: clamp(0.85rem, 0.8rem + 0.25vw, 0.9rem);
  padding: 3rem 1rem;
  background: var(--color-surface);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-lg);
}

/* History Search & Filter */
.history-filter {
  margin-bottom: 1rem;
}
.search-input {
  width: 100%;
  font-family: var(--font-body);
  font-size: 0.88rem;
  padding: 0.7rem 1rem 0.7rem 2.5rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  outline: none;
  background: var(--color-surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23B8A99A' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") no-repeat 0.85rem center;
  color: var(--color-text);
  transition: border-color 200ms ease, box-shadow 200ms ease;
}
.search-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(196, 139, 108, 0.1);
}
.search-input::placeholder {
  color: var(--color-text-muted);
}

/* --- Stats period filter + keyboard shortcut --- */
/* Stats period filter */
.period-filter {
  display: flex; gap: 4px; margin-bottom: 1.25rem;
  background: var(--color-surface-warm); border-radius: var(--radius-md); padding: 3px;
}
.period-chip {
  font-family: var(--font-body); font-size: 0.78rem;
  padding: 0.4rem 1rem; border-radius: var(--radius-sm);
  border: none;
  background: transparent; color: var(--color-text-muted);
  cursor: pointer; transition: color 200ms ease, background 200ms ease, box-shadow 200ms ease;
  font-weight: 500;
}
.period-chip:hover { color: var(--color-text-light); }
.period-chip.active {
  background: var(--color-surface); color: var(--color-text);
  box-shadow: var(--shadow-sm);
}

/* Keyboard shortcut hint */
.shortcut-hint {
  font-size: 0.65rem; color: var(--color-text-muted);
  margin-top: 0.3rem; text-align: right;
}
@media (hover: none), (pointer: coarse) {
  .shortcut-hint { display: none; }
}
kbd {
  display: inline-block; padding: 1px 5px;
  font-family: var(--font-body); font-size: 0.6rem;
  background: var(--color-surface-warm); border: 1px solid var(--color-border);
  border-radius: 3px; color: var(--color-text-light);
}

/* Edit entry */
.btn-edit-detail {
  background: none; border: 1px solid var(--color-border); cursor: pointer;
  color: var(--color-text-light); font-size: 0.75rem; padding: 4px 10px;
  border-radius: var(--radius-sm); font-family: var(--font-body);
  transition: all 200ms ease;
}
.btn-edit-detail:hover { background: var(--color-surface-warm); color: var(--color-text); }
.edit-textarea {
  width: 100%; min-height: 80px; padding: 0.6rem;
  border: 1px solid var(--color-primary); border-radius: var(--radius-sm);
  font-family: var(--font-diary); font-size: 0.9rem; line-height: 1.6;
  color: var(--color-text); background: var(--color-surface);
  resize: vertical; outline: none;
}
.edit-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.btn-edit-save {
  background: var(--color-primary); color: #fff; border: none;
  padding: 6px 14px; border-radius: var(--radius-sm); font-family: var(--font-body);
  font-size: 0.8rem; cursor: pointer;
}
.btn-edit-save:hover { background: var(--color-primary-hover); }
.btn-edit-save:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-edit-cancel {
  background: none; color: var(--color-text-light); border: 1px solid var(--color-border);
  padding: 6px 14px; border-radius: var(--radius-sm); font-family: var(--font-body);
  font-size: 0.8rem; cursor: pointer;
}
.btn-edit-cancel:hover { background: var(--color-surface-warm); }
.edit-char-count { font-size: 0.7rem; color: var(--color-text-muted); margin-top: 0.3rem; }

/* --- Dashboard + Summary cards + Bar chart + Trend chart --- */
/* Dashboard */
.dashboard {
  animation: fadeInUp 400ms cubic-bezier(0.25,0.46,0.45,0.94) both;
}
.dashboard-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
.summary-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1rem;
  text-align: center;
  border: 1px solid var(--color-border);
  transition: border-color 200ms ease;
}
.summary-card:hover {
  border-color: var(--color-primary);
}
.summary-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--color-primary);
  display: block;
}
.summary-label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: 0.3rem;
}
.dashboard-section {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1rem;
  border: 1px solid var(--color-border);
}
.dashboard-section-title {
  font-size: var(--text-sm);
  color: var(--color-text);
  margin-bottom: 1rem;
  font-weight: var(--weight-semibold);
}
/* AI 리포트 버튼 및 카드 */
.report-btn-group {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.btn-report {
  flex: 1;
  padding: 0.65rem 1rem;
  border: 1px solid var(--color-primary);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-primary);
  font-size: var(--text-sm);
  font-family: var(--font-body);
  font-weight: var(--weight-semibold);
  cursor: pointer;
  transition: background 0.2s, color 0.2s, transform 0.1s;
}
.btn-report:hover { background: var(--color-primary); color: #fff; }
.btn-report:active { transform: scale(0.97); }
.btn-report:disabled { opacity: 0.5; cursor: not-allowed; }
.report-card {
  background: var(--gradient-response);
  border-radius: 16px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.report-card-section {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.report-card-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-text-light);
  letter-spacing: 0.01em;
}
.report-card-text {
  font-size: var(--text-sm);
  color: var(--color-text);
  line-height: var(--leading-base);
}
/* CSS Bar chart */
.bar-chart {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.bar-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.bar-label {
  min-width: 5em;
  font-size: 0.8rem;
  color: var(--color-text);
  text-align: right;
  flex-shrink: 0;
}
.bar-track {
  flex: 1;
  height: 22px;
  background: var(--color-surface-warm);
  border-radius: 6px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: 6px;
  transition: width 600ms cubic-bezier(0.25,0.46,0.45,0.94);
  min-width: 2px;
}
.bar-fill[data-emotion="기쁨"], .bar-fill[data-emotion="감사"], .bar-fill[data-emotion="설렘"] { background: #F4A261; }
.bar-fill[data-emotion="슬픔"], .bar-fill[data-emotion="외로움"], .bar-fill[data-emotion="그리움"] { background: #7EB8DA; }
.bar-fill[data-emotion="분노"], .bar-fill[data-emotion="짜증"], .bar-fill[data-emotion="억울함"] { background: #E76F51; }
.bar-fill[data-emotion="불안"], .bar-fill[data-emotion="걱정"], .bar-fill[data-emotion="두려움"] { background: #9C89B8; }
.bar-fill[data-emotion="평온"], .bar-fill[data-emotion="편안함"], .bar-fill[data-emotion="안도"] { background: #A8DAAB; }
.bar-fill[data-emotion="사랑"], .bar-fill[data-emotion="애정"] { background: #F2A0A0; }
.bar-fill[data-emotion="피곤"], .bar-fill[data-emotion="지침"], .bar-fill[data-emotion="무기력"] { background: #B0A89A; }
.bar-count {
  min-width: 2em;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  text-align: left;
}
/* Situation bar alternate color */
.bar-fill.situation {
  background: rgba(85, 160, 180, 0.6);
}
/* Recent entries in dashboard */
.recent-entry {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--color-divider);
}
.recent-entry:last-child { border-bottom: none; }
.recent-emoji { font-size: 1.2rem; flex-shrink: 0; }
.recent-info { flex: 1; min-width: 0; }
.recent-text {
  font-family: var(--font-diary);
  font-size: 0.85rem;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.recent-meta {
  font-size: 0.7rem;
  color: var(--color-text-muted);
}
.dashboard-empty {
  text-align: center;
  color: var(--color-text-muted);
  padding: 2rem 0;
  font-size: 0.9rem;
}
@media (max-width: 480px) {
  .dashboard-section {
    padding: 1rem;
    margin-bottom: 0.75rem;
  }
  .dashboard-section-title {
    font-size: var(--text-xs);
    margin-bottom: 0.75rem;
  }
  .diary-history {
    margin-top: 1.5rem;
    padding-top: 1rem;
  }
}
.dashboard-progress-nudge {
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--color-surface-warm, var(--color-surface));
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}
.dashboard-progress-text {
  font-size: 0.82rem;
  color: var(--color-text-secondary);
  margin-bottom: 0.5rem;
  text-align: center;
}
.dashboard-progress-bar {
  height: 6px;
  background: var(--color-border);
  border-radius: 99px;
  overflow: hidden;
}
.dashboard-progress-fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: 99px;
  transition: width 0.4s ease;
}
/* Trend Chart */
.trend-chart {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1rem;
  border: 1px solid var(--color-border);
}
.trend-chart-title {
  font-size: 0.88rem;
  color: var(--color-text);
  margin-bottom: 1rem;
  font-weight: 600;
}
.trend-chart svg {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}
.trend-chart-empty {
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.85rem;
  padding: 1.5rem 0;
}
.trend-chart-legend {
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.75rem;
  margin-top: 0.5rem;
  line-height: 1.5;
}
.trend-chart-legend strong {
  color: var(--color-text-light);
  font-weight: 600;
}
.trend-tooltip {
  position: fixed;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.65rem;
  font-size: 0.75rem;
  color: var(--color-text);
  box-shadow: var(--shadow-md);
  pointer-events: none;
  white-space: nowrap;
  z-index: 9999;
  display: none;
}


/* --- Export button group --- */
/* Export button wrapper */
.export-btn-group {
  display: flex;
  gap: 0.4rem;
}
.export-btn {
  font-size: 0.78rem;
  min-width: 3rem;
  justify-content: center;
  box-shadow: 0 1px 2px rgba(35, 26, 17, 0.08);
}
.export-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(35, 26, 17, 0.10);
}
.export-btn:active {
  transform: translateY(1px) scale(0.98);
  box-shadow: inset 0 1px 2px rgba(35, 26, 17, 0.18);
}
.export-btn:disabled {
  cursor: wait;
  opacity: 0.7;
  transform: none;
  box-shadow: none;
}
@media (max-width: 480px) {
  .setting-row {
    flex-wrap: wrap;
    gap: 0.4rem;
  }
  .export-btn-group {
    width: 100%;
  }
  .export-btn-group .export-btn {
    flex: 1;
    min-width: 0;
    text-align: center;
  }
}

/* --- Stats Sub-Tabs --- */
/* ===== Stats Sub-Tabs ===== */
@keyframes tabFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.stats-sub-nav {
  display: flex;
  gap: 2px;
  background: var(--color-surface-warm);
  border-radius: var(--radius-md);
  padding: 3px;
  margin-bottom: 1.25rem;
}

.stats-sub-tab {
  flex: 1;
  background: none;
  border: none;
  padding: 0.55rem 0.75rem;
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 200ms ease;
}

.stats-sub-tab:hover {
  color: var(--color-text-light);
}

.stats-sub-tab.active,
.stats-sub-tab[aria-selected="true"] {
  color: var(--color-text);
  font-weight: var(--weight-semibold);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
}

.stats-sub-tab:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: -2px;
}

.stats-tab-panel[hidden] { display: none; }

.stats-tab-panel {
  animation: tabFadeIn 250ms ease-out both;
}

/* 모바일에서 서브 탭 스크롤 가능 */
@media (max-width: 480px) {
  .stats-sub-nav {
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .stats-sub-nav::-webkit-scrollbar { display: none; }
  .stats-sub-tab {
    white-space: nowrap;
    flex: none;
    min-width: 4.5rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .stats-tab-panel { animation: none; }
}
