/* ============================================================
   Sentimind — Modal Components
   프롬프트 라이브러리, 법적 고지, 단축키 도움말, 위기 안전,
   히스토리 상세 모달, 설정 패널, 바텀시트
   ============================================================ */

/* --- Prompt Library Modal --- */
/* ===== Prompt Library Modal ===== */
.prompt-library-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 1100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 200ms ease;
}
.prompt-library-overlay[hidden] { display: none; }
.prompt-library {
  background: var(--color-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  animation: slideUp 250ms cubic-bezier(0.25,0.46,0.45,0.94);
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.prompt-library-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem 0.5rem;
}
.prompt-library-title {
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
  margin: 0;
}
.prompt-library-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
}
.prompt-library-tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.5rem 1.25rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.prompt-lib-tab {
  flex-shrink: 0;
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: 0.3rem 0.7rem;
  font-family: var(--font-body);
  font-size: 0.8rem;
  color: var(--color-text-light);
  cursor: pointer;
  transition: border-color 150ms ease, color 150ms ease;
}
.prompt-lib-tab:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}
.prompt-lib-tab.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}
.prompt-library-list {
  list-style: none;
  margin: 0;
  padding: 0.5rem 1.25rem 1.25rem;
  overflow-y: auto;
  flex: 1;
}
.prompt-library-item {
  padding: 0.75rem 0.85rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 150ms ease;
  margin-bottom: 0.35rem;
}
.prompt-library-item:hover {
  background: var(--color-background);
}
.prompt-library-item-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 0.2rem;
}
.prompt-library-item-text {
  display: block;
  font-size: 0.8rem;
  color: var(--color-text-light);
  line-height: 1.4;
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.6rem;
}
.filter-chips:empty { margin-top: 0; }
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: 0.5rem 0.85rem;
  font-family: var(--font-body);
  font-size: 0.75rem;
  color: var(--color-text-light);
  cursor: pointer;
  transition: all 150ms ease;
  user-select: none;
  min-height: 36px;
}
.filter-chip:hover {
  border-color: var(--color-primary);
}
.filter-chip[aria-pressed="true"] {
  background: rgba(194, 113, 79, 0.15);
  border-color: var(--color-primary);
  color: var(--color-text);
  font-weight: 500;
}
.filter-chip:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}
.filter-result-count {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-top: 0.5rem;
}
.filter-result-count[hidden] { display: none; }

/* Legal modal */
.legal-modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
  animation: fadeIn 200ms ease;
}
.legal-modal-overlay[hidden] { display: none; }
.legal-modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 600px; width: 100%;
  max-height: 80vh;
  display: flex; flex-direction: column;
  animation: scaleIn 300ms cubic-bezier(0.25,0.46,0.45,0.94) both;
}
.legal-modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-divider);
}
.legal-modal-title {
  font-family: var(--font-body);
  font-size: 1rem; font-weight: 600;
  color: var(--color-text);
}
.legal-modal-close {
  background: none; border: none; cursor: pointer;
  color: var(--color-text-muted); font-size: 1.3rem;
  padding: 4px 8px; border-radius: var(--radius-sm);
}
.legal-modal-close:hover { color: var(--color-text); background: var(--color-surface-warm); }
.legal-modal-body {
  padding: 1.25rem;
  overflow-y: auto;
  font-size: 0.85rem;
  line-height: 1.8;
  color: var(--color-text);
}
.legal-modal-body h3 {
  font-size: 0.9rem; font-weight: 600;
  margin: 1.2rem 0 0.4rem; color: var(--color-text);
}
.legal-modal-body h3:first-child { margin-top: 0; }
.legal-modal-body p { margin-bottom: 0.6rem; }
.legal-modal-body ul { margin: 0.3rem 0 0.6rem 1.2rem; }
.legal-modal-body li { margin-bottom: 0.2rem; }

/* --- Shortcut help button & modal --- */
/* Keyboard shortcut help button & modal */
.shortcut-help-btn {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 900;
  width: 44px;
  height: 44px;
  border: 1px solid var(--color-border);
  border-radius: 50%;
  background: var(--color-surface);
  box-shadow: var(--shadow-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: var(--color-text-light);
  transition: background 200ms, box-shadow 200ms, transform 200ms;
}
.shortcut-help-btn:hover {
  background: var(--color-surface-warm);
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}
.shortcut-help-btn:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}
@media (hover: none), (pointer: coarse) {
  .shortcut-help-btn { display: none; }
}

.shortcut-modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
  animation: fadeIn 200ms ease;
}
.shortcut-modal-overlay[hidden] { display: none; }
.shortcut-modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 420px; width: 100%;
  animation: scaleIn 300ms cubic-bezier(0.25,0.46,0.45,0.94) both;
}
.shortcut-modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-divider);
}
.shortcut-modal-title {
  font-family: var(--font-body);
  font-size: 1rem; font-weight: 600;
  color: var(--color-text);
}
.shortcut-modal-close {
  background: none; border: none; cursor: pointer;
  color: var(--color-text-muted); font-size: 1.3rem;
  padding: 4px 8px; border-radius: var(--radius-sm);
}
.shortcut-modal-close:hover { color: var(--color-text); background: var(--color-surface-warm); }
.shortcut-modal-body {
  padding: 1rem 1.25rem;
}
.shortcut-list {
  list-style: none;
  display: flex; flex-direction: column;
  gap: 0.6rem;
}
.shortcut-list li {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 0.85rem;
  color: var(--color-text);
}
.shortcut-list .shortcut-keys {
  display: flex; gap: 4px; align-items: center;
  flex-shrink: 0;
  margin-left: 1rem;
}
.shortcut-list kbd {
  font-size: 0.7rem;
  padding: 2px 7px;
}
.shortcut-list .shortcut-sep {
  font-size: 0.65rem;
  color: var(--color-text-muted);
}
.shortcut-modal-footer {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--color-divider);
  font-size: 0.7rem;
  color: var(--color-text-muted);
  text-align: center;
}

/* --- History detail modal + Settings panel --- */
/* History detail modal */
.history-detail-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 1rem;
  animation: overlayFadeIn 200ms ease;
}
@keyframes overlayFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.history-detail-overlay[hidden] { display: none; }
.history-detail-content {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  padding: 2rem;
  box-shadow: var(--shadow-lg);
  max-width: 520px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
  animation: modalSlideIn 300ms cubic-bezier(0.25,0.46,0.45,0.94) both;
}
@keyframes modalSlideIn {
  from { opacity: 0; transform: translateY(24px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.history-detail-close {
  position: absolute; top: 1rem; right: 1rem;
  background: var(--color-surface-warm); border: none; cursor: pointer;
  color: var(--color-text-muted); font-size: 1.25rem;
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  transition: background 200ms, color 200ms;
  line-height: 1;
}
.history-detail-close:hover { background: var(--color-border); color: var(--color-text); }
.history-detail-date {
  font-size: 0.8rem; color: var(--color-text-muted);
  margin-bottom: 1rem;
  letter-spacing: 0.01em;
}
.history-detail-emotion {
  display: flex; align-items: center; gap: 0.75rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--color-divider);
}
.history-detail-emoji { font-size: 2.5rem; }
.history-detail-emotion-text {
  font-size: 1.2rem; font-weight: 600;
  color: var(--color-text);
}
.history-detail-section {
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--color-divider);
}
.history-detail-section:last-of-type { border-bottom: none; padding-bottom: 0; }
.history-detail-section h4 {
  font-size: 0.72rem; color: var(--color-text-muted);
  margin-bottom: 0.5rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.history-detail-text {
  font-family: var(--font-diary);
  font-size: 1.05rem; color: var(--color-text);
  line-height: 1.8;
}
.history-detail-message,
.history-detail-advice {
  font-size: 0.92rem; color: var(--color-text-light);
  line-height: 1.7;
}
.btn-detail-delete {
  display: block; width: 100%;
  margin-top: 1.25rem; padding: 0.65rem;
  background: none; border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  border-radius: var(--radius-md);
  cursor: pointer; font-size: 0.82rem;
  font-family: var(--font-body);
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.btn-detail-delete:hover {
  background: var(--color-error-bg);
  border-color: var(--color-error);
  color: var(--color-error);
}

/* Settings */
.settings-panel {
  margin-top: 2rem;
  border-top: 1px solid var(--color-divider);
  padding-top: 1rem;
}
.settings-panel summary {
  display: flex; align-items: center; gap: 0.5rem;
  color: var(--color-text-light);
  font-size: 0.85rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.settings-panel summary::-webkit-details-marker { display: none; }
.settings-panel summary svg { width: 16px; height: 16px; }
.settings-content {
  padding-top: 1rem;
  overflow: hidden;
}
.form-group {
  display: flex; gap: 0.5rem; align-items: center;
  margin-bottom: 0.5rem;
}
.form-group label {
  font-size: 0.85rem; color: var(--color-text-light); white-space: nowrap;
}
.form-group input {
  flex: 1;
  font-family: var(--font-body);
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  outline: none;
  background: var(--color-surface);
  color: var(--color-text);
}
.form-group input:focus { border-color: var(--color-primary); }
.btn-save-key {
  background: var(--color-secondary);
  color: #fff;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 200ms;
}
.btn-save-key:hover { background: var(--color-primary-hover); }
.settings-hint {
  font-size: clamp(0.7rem, 0.65rem + 0.25vw, 0.75rem);
  color: var(--color-text-muted);
}
.settings-status {
  font-size: 0.8rem;
  margin-top: 0.5rem;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
}
.settings-status.success { background: #e8f5e9; color: #2e7d32; }
.settings-status.error { background: #fce4ec; color: #c62828; }
.settings-status[hidden] { display: none; }


/* --- Crisis Safety Modal --- */
/* ===== Crisis Safety Modal ===== */
.crisis-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fadeIn 200ms ease;
}
.crisis-modal-overlay[hidden] { display: none; }
.crisis-modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 420px;
  width: 100%;
  padding: 2rem 1.5rem;
  text-align: center;
  animation: fadeInUp 300ms ease;
}
.crisis-modal-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
}
.crisis-modal-title {
  font-family: var(--font-body);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--color-text);
  margin: 0 0 0.5rem;
}
.crisis-modal-text {
  font-size: 0.9rem;
  color: var(--color-text-light);
  line-height: 1.6;
  margin: 0 0 1.25rem;
}
.crisis-contacts {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.crisis-contact-btn {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--color-text);
  transition: background 150ms ease, border-color 150ms ease;
}
.crisis-contact-btn:hover {
  background: var(--color-background);
  border-color: var(--color-primary);
}
.crisis-contact-btn--primary {
  border-color: #e74c3c;
  background: #fef0ef;
}
[data-theme="dark"] .crisis-contact-btn--primary {
  background: rgba(231,76,60,0.1);
}
.crisis-contact-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
}
.crisis-contact-info {
  display: flex;
  flex-direction: column;
  text-align: left;
}
.crisis-contact-info strong {
  font-size: 0.9rem;
  font-weight: 600;
}
.crisis-contact-info span {
  font-size: 0.75rem;
  color: var(--color-text-muted);
}
.crisis-modal-disclaimer {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin: 0 0 1rem;
}
.crisis-modal-close {
  display: inline-block;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 0.6rem 2rem;
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 150ms ease;
}
.crisis-modal-close:hover { opacity: 0.85; }

/* --- Bottom Sheet / Modal --- */
/* ===== Bottom Sheet / Modal ===== */
.bottom-sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 25, 23, 0.4);
  z-index: 2000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 300ms ease, visibility 300ms ease;
}
.bottom-sheet-overlay[data-open="true"] {
  opacity: 1;
  visibility: visible;
}
.bottom-sheet-overlay[hidden] { display: none; }

.bottom-sheet {
  background: var(--color-surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 300ms cubic-bezier(0.22, 1, 0.36, 1);
  box-shadow: 0 -8px 30px rgba(28,25,23,0.15);
}
.bottom-sheet-overlay[data-open="true"] .bottom-sheet {
  transform: translateY(0);
}

.bottom-sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--color-border);
  border-radius: 2px;
  margin: 0.75rem auto 0;
}

.bottom-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--color-divider);
}
.bottom-sheet-title {
  font-family: var(--font-diary);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
  margin: 0;
}
.bottom-sheet-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
}
.bottom-sheet-close:hover { color: var(--color-text); }
.bottom-sheet-close:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}
.bottom-sheet-body {
  padding: 1.25rem;
  overflow-y: auto;
}

/* 데스크탑: 중앙 모달 형태 */
@media (min-width: 768px) {
  .bottom-sheet-overlay {
    align-items: center;
    padding: 2rem;
  }
  .bottom-sheet {
    max-width: 480px;
    max-height: 70vh;
    border-radius: var(--radius-xl);
    transform: translateY(20px) scale(0.97);
  }
  .bottom-sheet-overlay[data-open="true"] .bottom-sheet {
    transform: translateY(0) scale(1);
  }
  .bottom-sheet-handle { display: none; }
}

/* 다크모드 */
[data-theme="dark"] .bottom-sheet-overlay {
  background: rgba(0, 0, 0, 0.6);
}
[data-theme="dark"] .bottom-sheet {
  background: var(--color-surface);
  box-shadow: 0 -8px 30px rgba(0,0,0,0.4);
}

/* reduced-motion */
@media (prefers-reduced-motion: reduce) {
  .bottom-sheet-overlay,
  .bottom-sheet {
    transition: none;
  }
}
