/* hayt — Dark theme, mobile-first, iOS safe areas */

:root {
  --bg: #1a1a2e;
  --bg-card: #16213e;
  --bg-input: #0f3460;
  --text: #eaeaea;
  --text-muted: rgba(255,255,255,0.5);
  --accent: #F39C12;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

/* Focus indicators for keyboard navigation */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
:focus:not(:focus-visible) {
  outline: none;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

#nav {
  flex-shrink: 0;
}

#main {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

#app-version {
  text-align: center;
  color: var(--text-muted);
  font-size: 11px;
  padding: 8px 0 calc(8px + var(--safe-bottom));
  opacity: 0.5;
}

/* --- Top Nav --- */
.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-card);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.nav-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
.nav-logo:active { opacity: 0.7; }
.nav-logo-icon {
  border-radius: 6px;
}
.nav-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 1px;
}

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

.nav-btn {
  background: none;
  border: none;
  color: var(--text);
  padding: 8px;
  border-radius: 50%;
  cursor: pointer;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.nav-btn:active { opacity: 0.6; }

.sync-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: none;
}
.sync-dot.sync-active {
  display: block;
  background: var(--accent);
  animation: pulse 1s infinite;
}
.sync-dot.sync-error {
  display: block;
  background: #e74c3c;
}
.sync-dot.sync-pending {
  display: block;
  background: #F39C12;
}

.sync-time {
  font-size: 10px;
  color: var(--text-muted);
  align-self: center;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* --- Mood Prompt --- */
.mood-prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 60px - var(--safe-top) - var(--safe-bottom));
  padding: 24px 16px;
}

.prompt-title {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 32px;
  text-align: center;
}

.mood-grid {
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  gap: 8px;
}

.mood-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex: 1 1 0;
  min-width: 0;
  max-width: 100px;
  background: var(--bg-card);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 10px 6px;
  cursor: pointer;
  color: var(--text);
  transition: transform 0.15s, border-color 0.15s;
}
.mood-btn img {
  width: 100%;
  height: auto;
}
.mood-btn:active {
  transform: scale(0.93);
}
.mood-btn:hover {
  border-color: rgba(255,255,255,0.15);
}

.mood-label {
  font-size: 12px;
  font-weight: 500;
  opacity: 0.85;
  text-align: center;
  word-break: break-word;
}

/* Note field on mood prompt */
.note-section {
  width: 100%;
  max-width: 400px;
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.note-section.hidden { display: none; }
.note-input {
  resize: vertical;
  min-height: 60px;
  font-family: inherit;
}
.note-save-btn {
  align-self: flex-end;
  flex: none;
  width: auto;
  padding: 10px 32px;
}

/* Post-save success + actions */
.mood-saved-msg {
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  color: #2ECC71;
  margin-top: 24px;
  margin-bottom: 16px;
}
.mood-post-actions {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 400px;
}
.mood-post-actions .note-section {
  margin-top: 0;
}

.mood-grid-small {
  gap: 6px;
}
.mood-btn-small {
  max-width: 72px;
  padding: 8px 4px;
}
.mood-btn-small .mood-label {
  font-size: 10px;
}

/* --- Mood Banner --- */
.mood-banner {
  background: linear-gradient(135deg, rgba(243,156,18,0.18) 0%, rgba(243,156,18,0.06) 100%);
  border: 1px solid rgba(243,156,18,0.25);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 16px;
  text-align: center;
}
.mood-banner-text {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.5;
  color: #f5e6cc;
}

/* --- Calendar View --- */
.calendar-view {
  padding: 16px;
  padding-bottom: 80px; /* room for FAB */
}

.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.cal-nav-btn {
  background: none;
  border: none;
  color: var(--text);
  padding: 8px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
}
.cal-nav-btn:active { opacity: 0.5; }

.cal-month-title {
  font-size: 18px;
  font-weight: 600;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.cal-header {
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 4px 0;
}

.cal-cell {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: var(--bg-card);
  border: none;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  position: relative;
  gap: 1px;
  padding: 2px;
}
.cal-cell:active { opacity: 0.6; }

.cal-empty {
  background: transparent;
  cursor: default;
}

.cal-today {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.cal-has-mood {
  background: var(--mood-bg, var(--bg-card));
}

.cal-day-num {
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
}

.cal-face {
  display: flex;
  line-height: 0;
}

.cal-count {
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 8px;
  background: rgba(255,255,255,0.2);
  border-radius: 50%;
  width: 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cal-note {
  position: absolute;
  top: 2px;
  left: 4px;
  color: rgba(255,255,255,0.7);
  line-height: 0;
}

/* Trend chart */
.trend-section {
  margin-top: 24px;
}

.trend-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.trend-chart {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 12px 8px;
}

.trend-chart svg {
  display: block;
}

/* FAB */
.fab {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  cursor: pointer;
  z-index: 10;
}
.fab:active { transform: scale(0.9); }

/* --- Day Detail --- */
.day-detail {
  padding: 16px;
}

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

.back-btn {
  background: none;
  border: none;
  color: var(--text);
  padding: 8px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
}
.back-btn:active { opacity: 0.5; }

.day-title {
  font-size: 18px;
  font-weight: 600;
}

.day-entries {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 24px;
}

.day-entry {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 12px 16px;
  border-left: 4px solid;
}

.entry-face {
  flex-shrink: 0;
  line-height: 0;
}

.entry-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.entry-label {
  font-size: 15px;
  font-weight: 600;
}

.entry-time {
  font-size: 13px;
  color: var(--text-muted);
}
.entry-note {
  display: flex;
  align-items: flex-start;
  gap: 5px;
  font-size: 13px;
  color: rgba(255,255,255,0.7);
  font-style: italic;
  line-height: 1.4;
  margin-top: 4px;
  background: rgba(255,255,255,0.05);
  border-radius: 8px;
  padding: 6px 8px;
}
.entry-note-icon {
  flex-shrink: 0;
  margin-top: 2px;
  opacity: 0.6;
}

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

.entry-edit, .entry-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 10px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  min-width: 40px;
  min-height: 40px;
  align-items: center;
  justify-content: center;
}
.entry-edit:active, .entry-delete:active { opacity: 0.5; }
.entry-edit:hover { color: var(--text); }
.entry-delete:hover { color: #e74c3c; }
.entry-delete.confirm {
  background: #e74c3c;
  color: #fff;
  border-radius: var(--radius);
  min-width: auto;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  position: relative;
  overflow: hidden;
}
.entry-delete.confirm::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  width: 100%;
  background: rgba(255,255,255,0.5);
  animation: delete-countdown 3s linear forwards;
}
@keyframes delete-countdown {
  from { width: 100%; }
  to { width: 0%; }
}

.day-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 32px 0;
  font-size: 15px;
}

.edit-picker-inline {
  padding: 8px 0;
}

.day-actions {
  text-align: center;
  margin-bottom: 16px;
}

.mood-picker.hidden {
  display: none;
}

.picker-title {
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
}

/* --- Settings --- */
.settings-view {
  padding: 16px;
  max-width: 500px;
  margin: 0 auto;
}

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

.settings-title {
  font-size: 20px;
  font-weight: 700;
}

.settings-section {
  margin-bottom: 28px;
}

.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 4px;
  margin-top: 12px;
}

.field-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 15px;
  outline: none;
}
.field-password-wrap {
  position: relative;
}
.field-password-wrap .field-input {
  padding-right: 44px;
}
.field-toggle-vis {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
}
.field-toggle-vis:active { opacity: 0.5; }
.field-input:focus {
  border-color: var(--accent);
}
.field-input::placeholder {
  color: rgba(255,255,255,0.25);
}

.settings-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.btn-primary, .btn-secondary {
  flex: 1;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  border: none;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:active { opacity: 0.8; }
.btn-secondary {
  background: rgba(255,255,255,0.08);
  color: var(--text);
}
.btn-secondary:active { opacity: 0.6; }

.settings-info {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 8px;
}

.settings-version {
  font-size: 12px;
  opacity: 0.4;
}

.settings-attribution {
  font-size: 11px;
  opacity: 0.4;
}
.settings-attribution a {
  color: inherit;
}

/* Settings danger banner */
.settings-danger {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: rgba(231,76,60,0.12);
  border: 1px solid rgba(231,76,60,0.3);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 20px;
  font-size: 13px;
  line-height: 1.5;
  color: #f5a5a0;
}
.settings-danger svg {
  flex-shrink: 0;
  margin-top: 1px;
  stroke: #e74c3c;
}

/* Settings tabs */
.settings-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: rgba(255,255,255,0.04);
  border-radius: 10px;
  padding: 3px;
}

.settings-tab-btn {
  flex: 1;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.settings-tab-btn.active {
  background: var(--bg-input);
  color: var(--text);
}
.settings-tab-btn:active { opacity: 0.7; }

.settings-tab.hidden {
  display: none;
}

/* --- Toast --- */
#toast-container {
  position: fixed;
  top: calc(60px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: auto;
  white-space: nowrap;
}

.toast-visible {
  opacity: 1;
  transform: translateY(0);
}

.toast-success {
  background: #2ECC71;
  color: #fff;
}
.toast-error {
  background: #e74c3c;
  color: #fff;
}
.toast-info {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.1);
}

/* --- Update Overlay --- */
.update-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px;
}

.update-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 32px 24px;
  max-width: 340px;
  width: 100%;
  text-align: center;
}

.update-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 12px;
}

.update-desc {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 24px;
}

.update-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.update-btn:active { opacity: 0.8; }
