* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f0f0f;
  --bg-secondary: #1a1a1a;
  --bg-tertiary: #252525;
  --text: #ffffff;
  --text-muted: #888888;
  --border: #333333;
  --success: #22c55e;
  --danger: #ef4444;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* Views */
.view {
  display: none;
  min-height: 100vh;
}

.view.active {
  display: block;
}

/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 600;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border: none;
  background: var(--bg-tertiary);
  color: var(--text);
  font-size: 1.5rem;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:active {
  transform: scale(0.95);
}

.back-btn {
  font-size: 1.25rem;
}

.header-buttons {
  display: flex;
  gap: 8px;
}

.settings-btn {
  font-size: 1.25rem;
}

/* Search Bar */
.shares-btn {
  font-size: 1.3rem;
}

.history-btn {
  font-size: 1.3rem;
}

.search-bar {
  position: sticky;
  top: 73px; /* Below header */
  z-index: 99;
  padding: 8px 20px 12px;
  background: var(--bg);
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.search-bar.hidden {
  transform: translateY(-100%);
  opacity: 0;
  pointer-events: none;
}

.search-bar .habit-search {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 1rem;
}

.search-bar .habit-search::placeholder {
  color: var(--text-muted);
}

.search-bar .habit-search:focus {
  outline: none;
  border-color: #3b82f6;
}

/* Floating Action Button */
.fab {
  position: fixed;
  bottom: 100px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #3b82f6;
  color: white;
  border: none;
  font-size: 2rem;
  font-weight: 300;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99;
  transition: transform 0.15s, box-shadow 0.15s;
}

.fab:active {
  transform: scale(0.95);
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

/* Habit Grid */
.habit-grid {
  display: grid;
  gap: 16px;
  padding: 8px 20px 20px;
}

/* Grid view (default) */
.habit-grid.view-grid {
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}

/* Size variants for grid view */
.habit-grid.view-grid.size-small {
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 10px;
}

.habit-grid.view-grid.size-medium {
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
}

.habit-grid.view-grid.size-large {
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 20px;
}

/* List view */
.habit-grid.view-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Habit Card */
.habit-card {
  aspect-ratio: 1;
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.1s;
  position: relative;
  overflow: hidden;
}

.habit-card:active {
  transform: scale(0.95);
}

.habit-card.tapped {
  animation: tap-pulse 0.3s ease-out;
}

@keyframes tap-pulse {
  0% { transform: scale(1); }
  50% { transform: scale(0.9); }
  100% { transform: scale(1); }
}

.habit-icon {
  font-size: 3rem;
  line-height: 1;
}

/* Multi-emoji layouts (1-4 emojis) */
.multi-emoji {
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* 2 emojis: side-by-side */
.multi-emoji.emoji-count-2 {
  gap: 0.05em;
}
.multi-emoji.emoji-count-2 > span {
  font-size: 1em;
}

/* 3 emojis: triangle (1 top, 2 bottom) */
.multi-emoji.emoji-count-3 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto;
  gap: 0.15em;
}
.multi-emoji.emoji-count-3 > span {
  font-size: 1em;
  line-height: 1;
}
.multi-emoji.emoji-count-3 > span:first-child {
  grid-column: 1 / -1;
  justify-self: center;
}

/* 4 emojis: 2x2 grid */
.multi-emoji.emoji-count-4 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.15em;
}
.multi-emoji.emoji-count-4 > span {
  font-size: 1em;
  text-align: center;
  line-height: 1;
}

.habit-initial {
  font-size: 2.5rem;
  font-weight: 700;
  color: white;
  text-transform: uppercase;
}

.habit-name {
  font-size: 0.875rem;
  font-weight: 500;
  text-align: center;
  max-width: 90%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: rgba(255,255,255,0.9);
}

.habit-status {
  display: none;
}

.habit-card.done .habit-status {
  background: rgba(255,255,255,0.95);
  color: inherit;
}

.habit-card.done {
  box-shadow: inset 0 0 0 4px rgba(255,255,255,0.5);
}

/* Size variants for habit cards */
.habit-grid.size-small .habit-card .habit-icon {
  font-size: 1.75rem;
}

.habit-grid.size-small .habit-card .habit-initial {
  font-size: 1.5rem;
}

.habit-grid.size-small .habit-card .habit-status {
  top: 8px;
  right: 8px;
  width: 16px;
  height: 16px;
  font-size: 0.6rem;
}

.habit-grid.size-small .habit-card .habit-name {
  font-size: 0.65rem;
}

.habit-grid.size-large .habit-card .habit-icon {
  font-size: 3.75rem;
}

.habit-grid.size-large .habit-card .habit-initial {
  font-size: 3rem;
}

.habit-grid.size-large .habit-card .habit-status {
  top: 16px;
  right: 16px;
  width: 28px;
  height: 28px;
  font-size: 1rem;
}

/* List view card styling */
.habit-grid.view-list .habit-card {
  aspect-ratio: unset;
  flex-direction: row;
  justify-content: flex-start;
  padding: 12px 16px;
  border-radius: 12px;
  gap: 12px;
}

.habit-grid.view-list .habit-card .habit-icon {
  font-size: 1.5rem;
}

.habit-grid.view-list .habit-card .habit-initial {
  font-size: 1.25rem;
  min-width: 28px;
  text-align: center;
}

.habit-grid.view-list .habit-card .habit-name {
  flex: 1;
  text-align: left;
  font-size: 1rem;
}

.habit-grid.view-list .habit-card .habit-status {
  position: static;
  width: 22px;
  height: 22px;
  font-size: 0.75rem;
}

/* Stats Modal */
.stats-modal-content {
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.stats-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.stats-habit-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.stats-habit-icon {
  width: 52px;
  height: 52px;
  min-width: 52px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
}

.stats-habit-icon .habit-initial {
  font-size: 1.5rem;
  font-weight: 700;
  color: white;
  text-transform: uppercase;
}

.stats-habit-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.stats-habit-name {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stats-first-tracked {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.stats-cards-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--bg-tertiary);
  border-radius: 14px;
  padding: 14px 8px;
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 1.75rem;
  font-weight: 700;
}

.stat-label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.stats-summary-row {
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.stats-summary-row .summary-total {
  color: var(--text);
  font-weight: 600;
}

/* Calendar Heatmap */
.calendar-heatmap {
  background: var(--bg-tertiary);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 20px;
  overflow: hidden;
}

.calendar-grid {
  display: grid;
  grid-template-columns: auto repeat(7, 1fr);
  gap: 2px;
  width: 100%;
}

.calendar-day-labels {
  display: contents;
}

.calendar-day-label {
  font-size: 0.6rem;
  color: var(--text-muted);
  text-align: center;
  padding: 2px 0 6px;
}

.calendar-day-label:first-child {
  /* empty spacer for row-label column */
}

.calendar-month-label {
  grid-column: 1 / -1;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 8px 0 4px;
}

.calendar-month-label:first-of-type {
  padding-top: 0;
}

.calendar-row-label {
  font-size: 0.6rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  padding-right: 4px;
  min-width: 18px;
}

.calendar-day {
  aspect-ratio: 1;
  border-radius: 3px;
  background: var(--bg-secondary);
  min-width: 0;
}

.calendar-day.level-1 { opacity: 0.4; }
.calendar-day.level-2 { opacity: 0.6; }
.calendar-day.level-3 { opacity: 0.8; }
.calendar-day.level-4 { opacity: 1; }

.calendar-day.today {
  outline: 2px solid rgba(255, 255, 255, 0.5);
  outline-offset: -1px;
}

.calendar-day.future {
  visibility: hidden;
}

.calendar-day.before-creation {
  opacity: 0.15;
}

/* Buttons */
.secondary-btn {
  width: 100%;
  padding: 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1rem;
  border-radius: 12px;
  cursor: pointer;
  margin-bottom: 24px;
}

.secondary-btn:active {
  background: var(--bg-tertiary);
}

/* Recent Entries */
.recent-entries h3 {
  font-size: 1rem;
  margin-bottom: 12px;
  color: var(--text-muted);
}

#entries-list {
  list-style: none;
}

.entry-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-radius: 12px;
  margin-bottom: 8px;
}

.entry-date {
  font-weight: 500;
}

.entry-time {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.entry-delete {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 4px 8px;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.8);
  z-index: 1000;
  align-items: flex-end;
  justify-content: center;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--bg-secondary);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding-bottom: env(safe-area-inset-bottom, 20px);
}

.modal-content.small {
  max-height: 50vh;
}

.modal-content header {
  position: sticky;
  top: 0;
  background: var(--bg-secondary);
}

.modal-content h2 {
  font-size: 1.125rem;
}

.text-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 8px;
}

.text-btn.primary {
  color: #3b82f6;
  font-weight: 600;
}

/* Form */
.form-group {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.form-group input[type="text"],
.form-group input[type="date"] {
  width: 100%;
  padding: 12px;
  background: var(--bg-tertiary);
  border: none;
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
}

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

/* Toggle Buttons */
.display-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.toggle-btn {
  flex: 1;
  padding: 10px;
  background: var(--bg-tertiary);
  border: none;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 0.875rem;
  cursor: pointer;
}

.toggle-btn.active {
  background: #3b82f6;
  color: white;
}

/* Emoji Picker */
.emoji-picker-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.emoji-search {
  width: 100%;
  padding: 12px;
  background: var(--bg-tertiary);
  border: none;
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
}

.emoji-search::placeholder {
  color: var(--text-muted);
}

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

.emoji-direct-field {
  width: 100%;
  padding: 12px;
  background: var(--bg-tertiary);
  border: 2px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1.5rem;
  text-align: center;
}

.emoji-direct-field:focus {
  border-color: #3b82f6;
  outline: none;
}

.emoji-direct-field.invalid {
  border-color: #ef4444;
}

.emoji-direct-field::placeholder {
  font-size: 1rem;
  color: var(--text-muted);
}

.emoji-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
}

/* Emoji chips for multi-emoji input */
.emoji-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 0;
}

.emoji-chips:empty {
  display: none;
}

.emoji-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1.25rem;
}

.emoji-chip-remove {
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1;
  padding: 2px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.emoji-chip-remove:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

/* Emoji input field (replacing emoji-direct-field) */
.emoji-input-field {
  width: 100%;
  padding: 12px;
  background: var(--bg-tertiary);
  border: 2px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1.25rem;
  text-align: center;
}

.emoji-input-field:focus {
  border-color: #3b82f6;
  outline: none;
}

.emoji-input-field::placeholder {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.emoji-input-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.emoji-count {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.emoji-count.at-limit {
  color: var(--danger);
}

.emoji-browse-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 8px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.emoji-browse-toggle:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.emoji-browse-arrow {
  font-size: 0.7rem;
  transition: transform 0.2s;
}

.emoji-browse-toggle.expanded .emoji-browse-arrow {
  transform: rotate(90deg);
}

.emoji-browse-panel {
  display: none;
  flex-direction: column;
  gap: 8px;
}

.emoji-browse-panel.open {
  display: flex;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  max-height: 200px;
  overflow-y: auto;
  padding: 4px;
}

.emoji-option {
  aspect-ratio: 1;
  font-size: 1.5rem;
  background: var(--bg-tertiary);
  border: 2px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s, background 0.1s;
}

.emoji-option:hover {
  background: var(--border);
}

.emoji-option:active {
  transform: scale(0.9);
}

.emoji-option.selected {
  border-color: #3b82f6;
  background: rgba(59,130,246,0.2);
}

.emoji-grid::-webkit-scrollbar {
  width: 6px;
}

.emoji-grid::-webkit-scrollbar-track {
  background: var(--bg-tertiary);
  border-radius: 3px;
}

.emoji-grid::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.emoji-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-muted);
  padding: 20px;
  font-size: 0.875rem;
}

/* Initial Picker */
.initial-picker input {
  text-align: center;
  font-size: 1.5rem;
  font-weight: 700;
  text-transform: uppercase;
}

/* Color Picker */
.color-picker {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 200px;
  overflow-y: auto;
}

.color-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
}

.color-row.custom-row {
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.color-option {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border: 3px solid transparent;
  border-radius: 50%;
  cursor: pointer;
}

.color-option.selected {
  border-color: white;
}

.color-label-display {
  flex: 1;
  font-size: 0.875rem;
  color: var(--text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.color-label-display[data-color] {
  cursor: default;
}

.color-label-edit {
  background: none;
  border: none;
  font-size: 0.75rem;
  cursor: pointer;
  padding: 4px;
  opacity: 0.5;
  transition: opacity 0.15s;
}

.color-label-edit:hover {
  opacity: 1;
}

.color-usage {
  font-size: 0.75rem;
  color: var(--text-muted);
  min-width: 30px;
  text-align: right;
}

.color-label-input {
  flex: 1;
  padding: 4px 8px;
  background: var(--bg-tertiary);
  border: 1px solid #3b82f6;
  border-radius: 4px;
  color: var(--text);
  font-size: 0.875rem;
  min-width: 0;
}

.color-label-input:focus {
  outline: none;
}

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

/* Custom Color Picker */
.custom-color-picker {
  position: relative;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.custom-color-picker input[type="color"] {
  position: absolute;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  border: none;
  padding: 0;
}

.custom-color-icon {
  font-size: 1.25rem;
  font-weight: 300;
  color: var(--text-muted);
  pointer-events: none;
}

.custom-color-picker.selected .custom-color-icon {
  color: white;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

/* Add Custom Color Button */
.add-custom-color-btn {
  background: #3b82f6;
  border: none;
  color: white;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.15s;
}

.add-custom-color-btn:hover {
  background: #2563eb;
}

.add-custom-color-btn:active {
  transform: scale(0.95);
}

/* Preview */
.preview-section {
  padding: 16px 20px;
}

.duplicate-warning {
  display: none;
  background: rgba(234, 179, 8, 0.15);
  border: 1px solid #eab308;
  color: #eab308;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.875rem;
  text-align: center;
  margin-bottom: 12px;
}

.habit-card.preview {
  width: 100px;
  height: 100px;
  margin: 12px auto 0;
  pointer-events: none;
}

/* Danger Zone */
.danger-zone {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.muted-btn {
  padding: 14px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 1rem;
  border-radius: 12px;
  cursor: pointer;
}

.danger-btn {
  padding: 14px;
  background: none;
  border: 1px solid var(--danger);
  color: var(--danger);
  font-size: 1rem;
  border-radius: 12px;
  cursor: pointer;
}

/* Context Menu */
.context-menu {
  display: none;
  position: fixed;
  background: var(--bg-secondary);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  z-index: 1001;
  min-width: 160px;
}

.context-menu.active {
  display: block;
}

.context-menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 12px 20px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
}

.context-menu-header span {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.context-menu-close {
  width: 28px;
  height: 28px;
  border: none;
  background: var(--bg-secondary);
  color: var(--text-muted);
  font-size: 1.25rem;
  line-height: 1;
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
  margin-left: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.context-menu-close:active {
  background: var(--border);
  color: var(--text);
}

/* Menu action buttons - use direct child selector to exclude close button in header */
.context-menu > button {
  display: block;
  width: 100%;
  padding: 14px 20px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 1rem;
  text-align: left;
  cursor: pointer;
}

.context-menu > button:last-child {
  border-bottom: none;
}

.context-menu > button:active {
  background: var(--bg-tertiary);
}

/* Color Group Header */
.color-group-header {
  grid-column: 1 / -1;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  padding: 8px 0 4px 12px;
  border-left: 3px solid;
  margin-top: 8px;
  text-transform: capitalize;
  display: flex;
  align-items: center;
  cursor: grab;
  user-select: none;
  transition: opacity 0.15s, border-top 0.15s;
}

.color-group-header:first-child {
  margin-top: 0;
}

.color-group-header .drag-handle {
  margin-right: 8px;
  opacity: 0.4;
  cursor: grab;
  font-size: 0.75rem;
  letter-spacing: -2px;
}

.color-group-header:hover .drag-handle {
  opacity: 0.7;
}

.color-group-header.dragging {
  opacity: 0.5;
  cursor: grabbing;
}

.color-group-header.dragging .drag-handle {
  cursor: grabbing;
}

.color-group-header.drag-over {
  border-top: 2px solid #3b82f6;
  padding-top: 6px;
}

.color-group-header .group-label {
  flex: 1;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state p {
  font-size: 1.125rem;
  margin-bottom: 8px;
}

.empty-state small {
  font-size: 0.875rem;
}

/* Settings Modal */
.settings-options {
  display: flex;
  gap: 8px;
}

.settings-options button {
  flex: 1;
  padding: 10px;
  background: var(--bg-tertiary);
  border: none;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.settings-options button.active {
  background: #3b82f6;
  color: white;
}

.settings-options button:active {
  transform: scale(0.98);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.toggle-row label {
  margin-bottom: 0;
}

.toggle-checkbox {
  width: 50px;
  height: 28px;
  appearance: none;
  background: var(--bg-tertiary);
  border-radius: 14px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-checkbox::before {
  content: '';
  position: absolute;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: white;
  top: 2px;
  left: 2px;
  transition: transform 0.2s;
}

.toggle-checkbox:checked {
  background: #3b82f6;
}

.toggle-checkbox:checked::before {
  transform: translateX(22px);
}

/* Sub-option styling (indented child option) */
.toggle-row.sub-option {
  margin-top: 12px;
  padding-left: 16px;
}

.toggle-row.sub-option label {
  font-size: 0.8rem;
}

/* Settings hint text */
.settings-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

/* Color order list in settings */
.color-order-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 200px;
  overflow-y: auto;
}

.color-order-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border-radius: 8px;
  cursor: grab;
  touch-action: none;
}

.color-order-item:active {
  cursor: grabbing;
}

.color-order-item.dragging {
  opacity: 0.5;
  background: var(--bg-secondary);
}

.color-order-item.drag-over {
  border-top: 2px solid var(--success);
}

.color-order-swatch {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  flex-shrink: 0;
}

.color-order-label {
  flex: 1;
  font-size: 0.85rem;
}

.color-order-handle {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.color-order-empty {
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 12px;
  text-align: center;
}

/* Enhanced color order item for settings */
.color-order-swatch {
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.color-order-swatch input[type="color"] {
  position: absolute;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  border: none;
  padding: 0;
}

.color-order-edit-btn {
  background: none;
  border: none;
  font-size: 0.75rem;
  cursor: pointer;
  padding: 4px;
  opacity: 0.5;
  transition: opacity 0.15s;
}

.color-order-edit-btn:hover {
  opacity: 1;
}

.color-order-delete-btn {
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  padding: 4px;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}

.color-order-item:hover .color-order-delete-btn {
  opacity: 0.6;
}

.color-order-delete-btn:hover {
  opacity: 1 !important;
  color: var(--danger);
}

.color-order-label-input {
  flex: 1;
  padding: 4px 8px;
  background: var(--bg-secondary);
  border: 1px solid #3b82f6;
  border-radius: 4px;
  color: var(--text);
  font-size: 0.85rem;
  min-width: 0;
}

.color-order-label-input:focus {
  outline: none;
}

/* Add Color Button */
.add-color-btn {
  width: 100%;
  padding: 10px;
  margin-top: 8px;
  background: transparent;
  border: 2px dashed var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.add-color-btn:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

/* Color Replacement Modal */
.color-replace-message {
  padding: 16px 20px;
  font-size: 0.9rem;
  color: var(--text-muted);
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.color-replace-options {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 250px;
  overflow-y: auto;
}

.color-replace-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-tertiary);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.color-replace-option:hover {
  background: var(--border);
}

.color-replace-option input[type="radio"] {
  accent-color: #3b82f6;
}

.color-replace-option-swatch {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  flex-shrink: 0;
}

.color-replace-option-label {
  flex: 1;
  font-size: 0.9rem;
  color: var(--text);
}

/* Export section in settings */
.export-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.export-btn {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-tertiary);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.export-btn:hover {
  background: var(--bg-secondary);
  border-color: var(--text-muted);
}

.export-btn:active {
  background: var(--border);
}

/* Account section in settings */
.account-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

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

.current-username {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.logout-btn {
  padding: 8px 16px;
  background: var(--bg-tertiary);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
}

.logout-btn:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

/* Keyboard shortcuts in settings */
.keyboard-shortcuts {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.keyboard-shortcuts summary {
  cursor: pointer;
  padding: 4px 0;
  list-style: none;
}

.keyboard-shortcuts summary::-webkit-details-marker {
  display: none;
}

.keyboard-shortcuts summary::before {
  content: '▸ ';
}

.keyboard-shortcuts[open] summary::before {
  content: '▾ ';
}

.shortcuts-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 12px;
  margin-top: 10px;
  padding-left: 4px;
}

.shortcuts-grid kbd {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  font-family: inherit;
  font-size: 0.75rem;
  min-width: 28px;
  text-align: center;
}

.shortcuts-grid span {
  color: var(--text-muted);
}

/* Responsive */
@media (min-width: 768px) {
  .habit-grid.view-grid {
    padding: 24px;
  }

  .habit-grid.view-grid.size-small {
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 12px;
  }

  .habit-grid.view-grid.size-medium {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 20px;
  }

  .habit-grid.view-grid.size-large {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 24px;
  }

  .modal-content {
    border-radius: 20px;
    margin: auto;
    max-height: 80vh;
  }

  .calendar-heatmap {
    max-width: 600px;
  }

  .calendar-grid {
    gap: 3px;
  }

  .calendar-day {
    border-radius: 4px;
  }
}

/* Page Indicator (Paginated View) */
.page-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px 20px 24px;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(transparent, var(--bg) 30%);
  pointer-events: none;
}

.page-indicator .page-label {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  text-transform: capitalize;
}

.page-indicator .page-dots {
  display: flex;
  gap: 10px;
  pointer-events: auto;
  padding: 8px 16px;
}

.page-indicator .page-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  opacity: 0.4;
  transition: opacity 0.2s, transform 0.2s;
  cursor: pointer;
  /* Larger touch target */
  position: relative;
  flex-shrink: 0;
}

.page-indicator .page-dot::before {
  content: '';
  position: absolute;
  top: -10px;
  left: -10px;
  right: -10px;
  bottom: -10px;
}

.page-indicator .page-dot.active {
  opacity: 1;
  transform: scale(1.2);
}

.page-indicator .page-dot:hover {
  opacity: 0.8;
}

/* Stat Snippet */
.stat-snippet {
  font-size: 0.8rem;
  font-style: italic;
  color: var(--text-muted);
  opacity: 0.7;
  text-align: center;
  padding: 6px 16px;
  line-height: 1.4;
}

.stat-snippet:empty {
  display: none;
}

/* History Modal */
.history-modal-content {
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.history-tabs {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.history-tab {
  flex: 1;
  padding: 10px 16px;
  background: var(--bg-tertiary);
  border: none;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.history-tab.active {
  background: #3b82f6;
  color: white;
}

.history-tab:active {
  transform: scale(0.98);
}

.history-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: relative;
}

.history-nav-btn {
  width: 36px;
  height: 36px;
  background: var(--bg-tertiary);
  border: none;
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.history-nav-btn:active {
  transform: scale(0.95);
  background: var(--border);
}

.history-sort-btn {
  width: 36px;
  height: 36px;
  background: var(--bg-tertiary);
  border: none;
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  position: absolute;
  right: 16px;
}

.history-sort-btn.active {
  background: #3b82f6;
  color: white;
}

.history-sort-btn.hidden {
  display: none;
}

.history-sort-btn:active {
  transform: scale(0.95);
}

.history-period-label {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.history-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

/* History Day View */
.history-day {
  margin-bottom: 24px;
}

.history-day:last-child {
  margin-bottom: 0;
}

.history-day-header {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.history-day-header.today {
  color: #3b82f6;
}

.history-habit-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.history-habit-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  cursor: pointer;
  transition: transform 0.1s;
}

.history-habit-icon:active {
  transform: scale(0.95);
}

.history-habit-icon .habit-initial {
  font-size: 1rem;
  font-weight: 700;
  color: white;
  text-transform: uppercase;
}

/* History Aggregate View (Week/Month) */
.history-period-section {
  margin-bottom: 24px;
}

.history-period-section:last-child {
  margin-bottom: 0;
}

.history-period-header {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

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

.history-summary-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: transform 0.1s;
}

.history-summary-card:active {
  transform: scale(0.95);
}

.history-summary-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

.history-summary-icon .habit-initial {
  font-size: 1rem;
  font-weight: 700;
  color: white;
  text-transform: uppercase;
}

.history-summary-count {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
}

/* History Empty State */
.history-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.history-empty p {
  font-size: 1rem;
  margin-bottom: 4px;
}

.history-empty small {
  font-size: 0.875rem;
}

/* History day with no entries */
.history-day-empty {
  color: var(--text-muted);
  font-size: 0.875rem;
  font-style: italic;
  padding: 8px 0;
}

/* Browse Ideas Link */
.browse-ideas-link {
  display: inline-block;
  margin-top: 8px;
  font-size: 0.875rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s;
}

.browse-ideas-link:hover {
  color: var(--text);
}

/* Ideas Panel */
.ideas-panel {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-secondary);
  z-index: 10;
  display: flex;
  flex-direction: column;
}

.ideas-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

.ideas-header span {
  font-size: 1.125rem;
  font-weight: 600;
}

.ideas-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.ideas-category {
  margin-bottom: 20px;
}

.ideas-category:last-child {
  margin-bottom: 0;
}

.ideas-category-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  margin-bottom: 8px;
  cursor: pointer;
  user-select: none;
}

.ideas-category-header:hover {
  opacity: 0.8;
}

.ideas-category-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.ideas-category-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}

.ideas-category-toggle {
  font-size: 0.75rem;
  color: var(--text-muted);
  transition: transform 0.2s;
}

.ideas-category.collapsed .ideas-category-toggle {
  transform: rotate(-90deg);
}

.ideas-category-items {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ideas-category.collapsed .ideas-category-items {
  display: none;
}

.idea-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-tertiary);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.idea-item:hover {
  background: var(--border);
}

.idea-item:active {
  transform: scale(0.98);
}

.idea-item.dimmed {
  opacity: 0.4;
}

.idea-item-emoji {
  font-size: 1.25rem;
  width: 28px;
  text-align: center;
}

.idea-item-name {
  font-size: 0.9rem;
  color: var(--text);
  flex: 1;
}

.idea-item-exists {
  font-size: 0.7rem;
  color: var(--text-muted);
  background: var(--bg-secondary);
  padding: 2px 6px;
  border-radius: 4px;
}

/* Empty State with Browse Ideas */
.empty-state-ideas {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state-ideas p {
  font-size: 1.25rem;
  margin-bottom: 16px;
  color: var(--text);
}

.empty-state-ideas .browse-ideas-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.empty-state-ideas .browse-ideas-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--text-muted);
}

.empty-state-ideas .browse-ideas-btn:active {
  transform: scale(0.98);
}

.empty-state-ideas .empty-hint {
  display: block;
  margin-top: 12px;
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* ============================================
   SHARING STYLES
   ============================================ */

/* Shares button badge */
.shares-btn {
  position: relative;
}

.shares-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  background: var(--danger);
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Share Modal */
.share-habit-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
}

.share-preview-card {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

.share-preview-card .habit-initial {
  font-size: 1.25rem;
  font-weight: 700;
  color: white;
}

.share-preview-name {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text);
}

.share-select {
  width: 100%;
  padding: 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
}

.share-select:focus {
  outline: none;
  border-color: #3b82f6;
}

.share-type-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.share-type-option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  background: var(--bg-tertiary);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
}

.share-type-option:hover {
  background: var(--border);
}

.share-type-option input[type="radio"] {
  margin-top: 2px;
  accent-color: #3b82f6;
}

.share-type-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.share-type-name {
  font-weight: 500;
  color: var(--text);
}

.share-type-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Existing shares section */
.existing-shares {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.existing-shares label {
  display: block;
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.existing-shares-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.existing-share-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border-radius: 8px;
}

.existing-share-user {
  flex: 1;
  font-size: 0.9rem;
  color: var(--text);
}

.existing-share-type {
  font-size: 0.9rem;
}

.existing-share-status {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: capitalize;
}

.existing-share-status.pending {
  background: rgba(234, 179, 8, 0.2);
  color: #eab308;
}

.existing-share-status.accepted {
  background: rgba(34, 197, 94, 0.2);
  color: #22c55e;
}

.existing-share-status.declined {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
}

.existing-share-revoke {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.existing-share-revoke:hover {
  color: var(--danger);
}

/* Shares Inbox Modal */
.shares-inbox-tabs {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.shares-tab {
  flex: 1;
  padding: 10px 16px;
  background: var(--bg-tertiary);
  border: none;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.shares-tab.active {
  background: #3b82f6;
  color: white;
}

.shares-tab:active {
  transform: scale(0.98);
}

.shares-inbox-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.shares-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.shares-empty p {
  font-size: 1rem;
  margin-bottom: 4px;
  color: var(--text);
}

.shares-empty small {
  font-size: 0.875rem;
}

/* Share invite card (pending) */
.share-invite-card {
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
}

.share-invite-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.share-invite-habit {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.share-invite-habit .habit-initial {
  font-size: 1.25rem;
  font-weight: 700;
  color: white;
}

.share-invite-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.share-invite-name {
  font-weight: 600;
  color: var(--text);
}

.share-invite-from {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.share-invite-type {
  margin-bottom: 12px;
}

.share-type-badge {
  display: inline-block;
  padding: 4px 10px;
  background: var(--bg-tertiary);
  border-radius: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.share-invite-actions {
  display: flex;
  gap: 8px;
}

.share-decline-btn,
.share-accept-btn {
  flex: 1;
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.share-decline-btn {
  background: var(--bg-tertiary);
  color: var(--text-muted);
}

.share-decline-btn:hover {
  background: var(--border);
}

.share-accept-btn {
  background: #3b82f6;
  color: white;
}

.share-accept-btn:hover {
  background: #2563eb;
}

/* Shared habit cards (accepted) */
.shared-by-section {
  margin-bottom: 24px;
}

.shared-by-header {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.shared-habit-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-secondary);
  border-radius: 12px;
  margin-bottom: 8px;
}

.shared-habit-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
  position: relative;
}

.shared-habit-icon .habit-initial {
  font-size: 1rem;
  font-weight: 700;
  color: white;
}

.shared-habit-check {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 16px;
  height: 16px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 50%;
  font-size: 0.6rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  color: inherit;
}

.shared-habit-card.done {
  opacity: 0.7;
}

.shared-habit-card.done .shared-habit-icon {
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.4);
}

.shared-habit-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.shared-habit-name {
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.shared-habit-type {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.shared-habit-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.shared-habit-actions button {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--bg-tertiary);
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.shared-habit-actions button:hover {
  background: var(--border);
}

.shared-habit-log {
  background: #3b82f6 !important;
  color: white;
  font-weight: 700;
}

.shared-habit-log:hover {
  background: #2563eb !important;
}

.shared-habit-remove {
  color: var(--text-muted);
}

.shared-habit-remove:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1) !important;
}

/* Shared habit dot indicators - LARGER AND CLEARER */
.habit-share-dot {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.95;
  font-size: 0.7rem;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

/* Joint received (someone shared with me) - filled person icon style */
.habit-share-dot.joint-received {
  width: 22px;
  height: 22px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 6px;
  color: inherit;
  font-size: 0.8rem;
  text-shadow: none;
}

.habit-share-dot.joint-received::before {
  content: '🤝';
  font-size: 0.75rem;
}

/* I shared as joint - outline with joint icon */
.habit-share-dot.shared-joint {
  width: 22px;
  height: 22px;
  background: rgba(0, 0, 0, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 6px;
}

.habit-share-dot.shared-joint::before {
  content: '🤝';
  font-size: 0.65rem;
}

/* I shared as view - eye icon style */
.habit-share-dot.shared-view {
  width: 22px;
  height: 22px;
  background: rgba(0, 0, 0, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.7);
  border-radius: 6px;
}

.habit-share-dot.shared-view::before {
  content: '👁';
  font-size: 0.65rem;
}

/* I shared as both joint and view - combined icon */
.habit-share-dot.shared-both {
  width: 26px;
  height: 22px;
  background: rgba(0, 0, 0, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 6px;
  gap: 1px;
}

.habit-share-dot.shared-both::before {
  content: '🤝👁';
  font-size: 0.55rem;
  letter-spacing: -2px;
}

/* Size adjustments - small */
.habit-grid.size-small .habit-share-dot {
  top: 4px;
  left: 4px;
  width: 16px;
  height: 16px;
  border-radius: 4px;
}

.habit-grid.size-small .habit-share-dot::before {
  font-size: 0.5rem;
}

.habit-grid.size-small .habit-share-dot.shared-both {
  width: 18px;
}

.habit-grid.size-small .habit-share-dot.shared-both::before {
  font-size: 0.4rem;
}

/* Size adjustments - large */
.habit-grid.size-large .habit-share-dot {
  top: 12px;
  left: 12px;
  width: 26px;
  height: 26px;
  border-radius: 8px;
}

.habit-grid.size-large .habit-share-dot::before {
  font-size: 0.85rem;
}

.habit-grid.size-large .habit-share-dot.shared-both {
  width: 32px;
}

.habit-grid.size-large .habit-share-dot.shared-both::before {
  font-size: 0.7rem;
}

/* List view positioning */
.habit-grid.view-list .habit-share-dot {
  position: static;
  margin-right: 8px;
  flex-shrink: 0;
  width: 20px;
  height: 20px;
}

.habit-grid.view-list .habit-share-dot.shared-both {
  width: 24px;
}

/* Outgoing shares section (Sharing tab) */
.outgoing-habit-section {
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
}

.outgoing-habit-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.outgoing-habit-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.outgoing-habit-icon .habit-initial {
  font-size: 1rem;
  font-weight: 700;
  color: white;
}

.outgoing-habit-name {
  font-weight: 600;
  color: var(--text);
  font-size: 1rem;
}

.outgoing-shares-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.outgoing-share-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg-tertiary);
  border-radius: 8px;
}

.outgoing-share-user {
  flex: 1;
  font-size: 0.9rem;
  color: var(--text);
}

.outgoing-share-type {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.outgoing-share-status {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: capitalize;
}

.outgoing-share-status.pending {
  background: rgba(234, 179, 8, 0.2);
  color: #eab308;
}

.outgoing-share-status.accepted {
  background: rgba(34, 197, 94, 0.2);
  color: #22c55e;
}

.outgoing-share-status.declined {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
}

.outgoing-share-revoke {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  transition: color 0.15s;
}

.outgoing-share-revoke:hover {
  color: var(--danger);
}

/* ============================================
   LOADING INDICATOR
   ============================================ */

.loading-indicator {
  display: none;
  padding: 20px;
  gap: 16px;
}

.loading-indicator.active {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
}

/* Match size settings */
.loading-indicator.size-small {
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 10px;
}

.loading-indicator.size-medium {
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
}

.loading-indicator.size-large {
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 20px;
}

.loading-skeleton {
  aspect-ratio: 1;
  border-radius: 20px;
  background: var(--bg-tertiary);
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}

@keyframes skeleton-pulse {
  0%, 100% {
    opacity: 0.4;
  }
  50% {
    opacity: 0.7;
  }
}

/* Responsive */
@media (min-width: 768px) {
  .loading-indicator.size-small {
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 12px;
  }

  .loading-indicator.size-medium {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 20px;
  }

  .loading-indicator.size-large {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 24px;
  }
}

/* Habit Reorder Mode */
.reorder-btn {
  font-size: 1.1rem;
  letter-spacing: -2px;
}

.reorder-btn.active {
  background: var(--success);
  color: var(--bg);
}

.habit-grid.reorder-mode .habit-card {
  cursor: grab;
  transition: transform 0.15s ease, opacity 0.15s ease, box-shadow 0.15s ease;
  touch-action: none; /* Prevent scroll interference on mobile */
}

.habit-grid.reorder-mode .habit-card:active {
  cursor: grabbing;
}

.habit-grid.reorder-mode .habit-card.dragging {
  opacity: 0.5;
  transform: scale(0.95);
  cursor: grabbing;
}

.habit-grid.reorder-mode .habit-card.drag-over {
  box-shadow: 0 0 0 3px var(--success), 0 0 20px rgba(34, 197, 94, 0.4);
  transform: scale(1.02);
}

/* Disable hover effects and interactions in reorder mode */
.habit-grid.reorder-mode .habit-card:hover {
  transform: none;
}

.habit-grid.reorder-mode .habit-card.drag-over:hover {
  transform: scale(1.02);
}

/* ============================================
   BATCH SHARE STYLES
   ============================================ */

.batch-share-link-container {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.batch-share-link {
  width: 100%;
  padding: 12px;
  background: var(--bg-tertiary);
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.batch-share-link:hover {
  background: var(--border);
  border-color: var(--text-muted);
  color: var(--text);
}

.batch-filter-row {
  margin-bottom: 12px;
}

.batch-color-filter {
  width: 100%;
  padding: 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
}

.batch-color-filter:focus {
  outline: none;
  border-color: #3b82f6;
}

.batch-habit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 10px;
  max-height: 300px;
  overflow-y: auto;
  padding: 4px;
}

.batch-habit-item {
  aspect-ratio: 1;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  cursor: pointer;
  position: relative;
  transition: transform 0.1s, opacity 0.1s;
  border: 3px solid transparent;
}

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

.batch-habit-item.selected {
  border-color: white;
  box-shadow: 0 0 0 2px #3b82f6;
}

.batch-habit-item .batch-check {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  color: #3b82f6;
  font-weight: 700;
}

.batch-habit-item.selected .batch-check {
  display: flex;
}

.batch-habit-item .habit-initial {
  font-size: 1rem;
  font-weight: 700;
  color: white;
}

.batch-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-muted);
  padding: 30px 20px;
  font-size: 0.9rem;
}

/* ============================================
   SHARE CUSTOMIZE STYLES
   ============================================ */

.customize-preview-section {
  padding: 20px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: center;
}

.customize-preview {
  width: 80px;
  height: 80px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.customize-preview .habit-icon {
  font-size: 2rem;
}

.customize-preview .habit-initial {
  font-size: 1.5rem;
  font-weight: 700;
  color: white;
}

.customize-preview .habit-name {
  font-size: 0.7rem;
  max-width: 90%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.customize-emoji-picker {
  display: flex;
  gap: 8px;
  align-items: center;
}

.customize-emoji-picker .emoji-direct-field {
  flex: 1;
}

.customize-clear-btn {
  width: 40px;
  height: 40px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.customize-clear-btn:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.customize-color-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.customize-color-option {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform 0.1s;
}

.customize-color-option:hover {
  transform: scale(1.1);
}

.customize-color-option.selected {
  border-color: white;
  box-shadow: 0 0 0 2px #3b82f6;
}

.customize-color-option.original {
  position: relative;
}

.customize-color-option.original::after {
  content: '✓';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.8rem;
  color: white;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

/* Edit customization button in received shares */
.shared-habit-edit {
  color: var(--text-muted);
}

.shared-habit-edit:hover {
  color: var(--text);
}

/* ============================================
   MANAGE HABITS STYLES
   ============================================ */

/* Manage section in settings */
.manage-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* Sticky bottom action toolbar */
.manage-actions {
  position: sticky;
  bottom: 0;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  z-index: 10;
}

.manage-action-btn {
  flex: 1 1 calc(50% - 4px);
  padding: 12px 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.manage-action-btn:hover {
  background: var(--border);
}

.manage-action-btn:active {
  transform: scale(0.98);
}

.manage-action-btn.danger {
  border-color: var(--danger);
  color: var(--danger);
}

.manage-action-btn.danger:hover {
  background: rgba(239, 68, 68, 0.15);
}

/* Select All link */
.manage-select-all-btn {
  float: right;
  font-size: 0.875rem;
  color: #3b82f6;
  text-decoration: none;
  cursor: pointer;
}

.manage-select-all-btn:hover {
  text-decoration: underline;
}

/* Archived item indicator */
.batch-habit-item.archived-item {
  opacity: 0.5;
}

.batch-habit-item .archived-badge {
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.55rem;
  background: rgba(0, 0, 0, 0.5);
  color: rgba(255, 255, 255, 0.8);
  padding: 1px 4px;
  border-radius: 3px;
  white-space: nowrap;
}

/* Batch color picker grid */
.batch-color-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 4px;
}

.batch-color-option {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform 0.1s;
}

.batch-color-option:hover {
  transform: scale(1.1);
}

.batch-color-option.selected {
  border-color: white;
  box-shadow: 0 0 0 2px #3b82f6;
}

/* Custom label indicator */
.shared-habit-customized {
  font-size: 0.65rem;
  color: #3b82f6;
  margin-left: 4px;
}

/* Emoji2 picker section */
.emoji2-section {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.emoji2-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.emoji2-header label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.emoji2-optional {
  font-size: 0.75rem;
  color: var(--text-muted);
  opacity: 0.7;
}

.emoji2-clear-btn {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 2px 8px;
}
