/* ==========================================================================
   Reusable UI Components
   ========================================================================== */

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 14px 20px;
  font-size: 0.98rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  transition: background-color var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast), color var(--transition-fast);
  text-align: center;
  width: 100%;
}

.btn:active {
  transform: scale(0.97);
}

/* Modal footers use equal columns instead of the global full-width button rule. */
.modal-actions-equal {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  align-items: stretch;
}

.modal-actions-equal .btn {
  width: auto;
  min-width: 0;
  white-space: normal;
  line-height: 1.2;
}

.btn-primary {
  background-color: var(--accent-primary);
  color: var(--text-inverse);
  box-shadow: 0 4px 14px rgba(52, 122, 77, 0.22);
}

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

.btn-secondary {
  background-color: var(--accent-primary-subtle);
  color: var(--accent-primary);
}

.btn-secondary:hover {
  background-color: var(--bg-card-hover);
}

.btn-outline {
  background-color: transparent;
  border: 1.5px solid var(--border-subtle);
  color: var(--text-primary);
}

.btn-outline:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.btn-ghost {
  background: transparent;
  color: var(--accent-primary);
  padding: 8px 12px;
  font-size: 0.9rem;
}

.btn-sm {
  padding: 8px 14px;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--space-md);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
}

.card-interactive:active {
  transform: scale(0.985);
  box-shadow: var(--shadow-md);
}

/* Greeting / Hero Banner Card */
.hero-card {
  background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-card-subtle) 100%);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: var(--space-xl) var(--space-lg);
  text-align: center;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-md);
  margin-bottom: var(--space-lg);
}

.hero-art-wrap {
  width: 72px;
  height: 72px;
  margin: 0 auto var(--space-md) auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hero-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-xs);
}

.hero-desc {
  font-size: 0.92rem;
  color: var(--text-secondary);
  line-height: 1.45;
  margin-bottom: var(--space-lg);
}

/* Timeline Entry Item (Screen 3) */
.timeline-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 290px;
  overflow-y: auto;
  padding-right: 4px;
  margin-bottom: var(--space-md);
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* Elegant slim scrollbar */
.timeline-list::-webkit-scrollbar,
.history-entries-scroll::-webkit-scrollbar {
  width: 5px;
}

.timeline-list::-webkit-scrollbar-track,
.history-entries-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.timeline-list::-webkit-scrollbar-thumb,
.history-entries-scroll::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 10px;
}

.timeline-list::-webkit-scrollbar-thumb:hover,
.history-entries-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

.timeline-item {
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-fast), border-color var(--transition-fast);
}

/* Inline +1 Quick Increment Button on Pluses */
.today-plus-one-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--accent-primary);
  background: var(--accent-primary-subtle);
  border: 1.5px solid var(--accent-primary);
  cursor: pointer;
  transition: transform var(--transition-fast), background-color var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast);
  user-select: none;
  touch-action: manipulation;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  line-height: 1;
}

.today-plus-one-btn:hover {
  background-color: var(--accent-primary);
  color: var(--text-inverse, #ffffff);
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
  transform: scale(1.06);
}

.today-plus-one-btn:active {
  transform: scale(0.92);
}


.timeline-item:active {
  transform: scale(0.985);
}

.timeline-time {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  width: 44px;
  flex-shrink: 0;
}

.timeline-icon {
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
}

.timeline-text {
  flex: 1;
  font-size: 0.94rem;
  font-weight: 500;
  color: var(--text-primary);
  word-break: break-word;
}

.timeline-badge {
  font-size: 0.78rem;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  background: var(--accent-primary-subtle);
  color: var(--accent-primary);
  font-weight: 600;
  flex-shrink: 0;
}

/* Category Chips Grid / Flex (Screen 4) */
.chips-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: var(--space-md) 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-full);
  background: var(--bg-card-subtle);
  border: 1.5px solid var(--border-subtle);
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-primary);
  transition: all var(--transition-fast);
}

.chip:active, .chip.selected {
  background: var(--accent-primary-subtle);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  font-weight: 600;
  transform: scale(0.96);
}

/* Habit Modal Frequency & Weekday Selectors */
.habit-freq-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 6px 0 10px 0;
}

.habit-weekdays-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin: 6px 0 10px 0;
  width: 100%;
}

.weekday-circle {
  height: 38px;
  min-height: 38px;
  width: 100%;
  max-width: 44px;
  border-radius: var(--radius-full);
  background: var(--bg-card-subtle);
  border: 1.5px solid var(--border-subtle);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: all var(--transition-fast);
}

.weekday-circle:active, .weekday-circle.selected {
  background: var(--accent-primary-subtle);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  font-weight: 800;
  transform: scale(0.96);
}

/* Mood / Satisfaction Selector (Screen 4) */
.mood-selector-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin: var(--space-md) 0;
}

.mood-btn {
  flex: 1;
  padding: 10px 6px;
  border-radius: var(--radius-md);
  background: var(--bg-card-subtle);
  border: 1.5px solid var(--border-subtle);
  text-align: center;
  font-size: 1.1rem;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: all var(--transition-fast);
}

.mood-btn span.mood-label {
  font-size: 0.75rem;
  font-weight: 500;
}

.mood-btn.selected {
  background: var(--accent-primary-subtle);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  transform: scale(1.03);
}

/* Form Input with Clear Button */
.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  margin: var(--space-md) 0;
}

.text-input {
  width: 100%;
  padding: 14px 44px 14px 16px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border-subtle);
  background: var(--bg-card-subtle);
  color: var(--text-primary);
  font-size: 0.98rem;
  transition: border-color var(--transition-fast), background-color var(--transition-fast);
}

.text-input:focus {
  border-color: var(--accent-primary);
  background: var(--bg-card);
}

/* Quantity controls use explicit side buttons instead of the browser's
   vertical number spinner, which is difficult to operate on a phone. */
.quantity-control {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 42px;
  align-items: stretch;
  gap: 4px;
}

.quantity-step-btn {
  min-width: 42px;
  min-height: 44px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-card-subtle);
  color: var(--accent-primary);
  font-size: 1.35rem;
  font-weight: 700;
  cursor: pointer;
}

.quantity-step-btn:active {
  background: var(--accent-primary-subtle);
}

.quantity-input {
  min-width: 0;
  padding-left: 10px;
  padding-right: 10px;
  text-align: center;
  appearance: textfield;
  -moz-appearance: textfield;
}

.quantity-input::-webkit-outer-spin-button,
.quantity-input::-webkit-inner-spin-button {
  margin: 0;
  appearance: none;
}

.input-clear-btn {
  position: absolute;
  right: 12px;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-full);
  background: var(--text-muted);
  color: var(--text-inverse);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  opacity: 0.6;
}

.input-clear-btn:active {
  opacity: 1;
}

/* Rating Scale 1..10 (Screen 7) */
.scale-rating-wrap {
  margin: var(--space-lg) 0;
}

.scale-numbers {
  display: flex;
  justify-content: space-between;
  gap: 4px;
  margin-bottom: 8px;
}

.scale-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 0.88rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.scale-btn.active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: var(--text-inverse);
  transform: scale(1.15);
  box-shadow: var(--shadow-glow);
}

.scale-smileys {
  display: flex;
  justify-content: space-between;
  padding: 0 4px;
  font-size: 1.05rem;
  color: var(--text-muted);
}

/* Section Header */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: var(--space-lg);
  margin-bottom: var(--space-sm);
}

.section-title {
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--text-primary);
}

.section-count {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-primary);
}

/* Habit / Rhythm Item (Screen 6) */
.habit-item {
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 8px;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform var(--transition-fast), border-color var(--transition-fast);
}

.card > .habit-item:last-child {
  margin-bottom: 0;
}

.habit-item:active {
  transform: scale(0.985);
}

.habit-checkbox {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-full);
  border: 2px solid var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-inverse);
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

.habit-checkbox.checked {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
}

.habit-checkbox.not-today {
  border-color: var(--accent-sky, #4a90e2);
  background: var(--accent-sky-bg, rgba(74, 144, 226, 0.08));
  color: var(--accent-sky, #4a90e2);
  opacity: 0.9;
}

.habit-checkbox.checked svg {
  display: block;
}

.habit-checkbox svg {
  display: none;
  width: 14px;
  height: 14px;
  stroke-width: 3;
}

.habit-text {
  flex: 1;
  font-size: 0.94rem;
  font-weight: 500;
  color: var(--text-primary);
}

/* Progress Bar Component (Screen 11) */
.analytics-row {
  margin-bottom: 12px;
}

.analytics-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
  font-size: 0.9rem;
}

.analytics-name {
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.analytics-score {
  font-weight: 700;
  color: var(--accent-primary);
  font-size: 0.85rem;
}

.analytics-score.negative {
  color: var(--accent-rose);
}

.progress-track {
  width: 100%;
  height: 7px;
  background: var(--bg-card-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--accent-primary);
  transition: width 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.progress-fill.rose {
  background: var(--accent-rose);
}

/* AI Note / Observation Card */
.ai-card {
  background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-card-subtle) 100%);
  border: 1px solid var(--accent-primary-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-md) var(--space-lg);
  margin: var(--space-md) 0;
  box-shadow: var(--shadow-sm);
  position: relative;
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 12px;
}

.ai-card-icon {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent-primary-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  margin-top: 2px;
}

.ai-card-body {
  flex: 1;
  min-width: 0;
}

.ai-card-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent-primary);
  margin-bottom: 5px;
}

.ai-card-text {
  font-size: 0.92rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* Beauty row items (1 column, full-width rows) */
.beauty-row-card {
  transition: transform var(--transition-fast), border-color var(--transition-fast), background var(--transition-fast), box-shadow var(--transition-fast);
}

.beauty-row-card:hover {
  background: var(--bg-card-hover) !important;
  border-color: var(--accent-primary) !important;
  transform: translateY(-1px);
}

.beauty-row-card:active {
  transform: scale(0.99);
  background: var(--accent-primary-subtle) !important;
}

/* Form Inputs & Textareas */
.input-field {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--radius-md, 12px);
  background: var(--bg-card);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.95rem;
  box-sizing: border-box;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input-field:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-primary-subtle);
}

.input-field::placeholder {
  color: var(--text-muted);
}

/* WYSIWYG Story Editor */
.story-wysiwyg-editor:empty:before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  pointer-events: none;
  display: block;
}

.story-wysiwyg-editor b,
.story-wysiwyg-editor strong {
  font-weight: 800;
  color: var(--text-primary);
}

.story-wysiwyg-editor i,
.story-wysiwyg-editor em {
  font-style: italic;
}

.story-wysiwyg-editor blockquote {
  border-left: 3px solid var(--accent-primary);
  margin: 6px 0;
  padding-left: 10px;
  color: var(--text-secondary);
  font-style: italic;
}

.story-wysiwyg-editor ul {
  padding-left: 20px;
  margin: 6px 0;
}

.story-wysiwyg-editor li {
  margin-bottom: 2px;
}

