/* ═══════════════════════════════════════════════════════════════
   ENERGYMAP — style.css
   Design tokens, base reset, layout, components, animations
   ═══════════════════════════════════════════════════════════════ */

/* ─── Design Tokens ─────────────────────────────────────────── */
:root {
  --bg: #0a0a0a;
  --accent: #4A9EFF;
  --text: #f0f0f0;
  --text-muted: #888;
  --nav-height: 64px;

  /* Energy-state background colors */
  --bg-down: #1a0a0a;
  --bg-neutral: #0a0a0a;
  --bg-up: #0a1a0a;

  /* Safe area insets — env() is the CSS standard for notch/home-indicator */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

/* ─── Reset & Base ───────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent; /* Remove tap flash on iOS */
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Prevent pull-to-refresh and over-scroll bounce on iOS */
body {
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
  /* Pad content away from status bar on notched iPhones */
  padding-top: var(--safe-top);
}

/* ─── Utility ────────────────────────────────────────────────── */
.hidden {
  display: none !important;
}


/* ═══════════════════════════════════════════════════════════════
   ONBOARDING OVERLAY
   ═══════════════════════════════════════════════════════════════ */
.onboarding {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding:
    calc(var(--safe-top) + 48px)
    calc(var(--safe-right) + 24px)
    calc(var(--safe-bottom) + 32px)
    calc(var(--safe-left) + 24px);
}

.onboarding-step {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  flex: 1;
}

.onboarding-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  flex: 1;
  justify-content: center;
  text-align: center;
  width: 100%;
}

/* Logo block */
.onboarding-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.onboarding-logo-icon {
  font-size: 72px;
  line-height: 1;
  filter: drop-shadow(0 0 24px var(--accent));
}

.onboarding-title {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text);
}

.onboarding-tagline {
  font-size: 16px;
  color: var(--text-muted);
}

/* Install instruction block */
.install-instruction {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  width: 100%;
}

.install-text {
  font-size: 17px;
  color: var(--text);
  text-align: center;
  max-width: 280px;
  line-height: 1.5;
}

.install-visual {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 16px;
  padding: 20px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 300px;
}

.install-step-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.install-icon {
  font-size: 24px;
  width: 32px;
  text-align: center;
}

.install-label {
  font-size: 15px;
  color: var(--text);
}

/* Animated arrow pointing down toward Safari share button */
.install-arrow-container {
  margin-top: 8px;
}

.install-arrow {
  font-size: 32px;
  color: var(--accent);
  animation: arrowBounce 1.4s ease-in-out infinite;
}

/* Notification step */
.notif-icon {
  font-size: 80px;
  line-height: 1;
  animation: notifPulse 2s ease-in-out infinite;
}

.onboarding-heading {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
}

.onboarding-subtext {
  font-size: 16px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.6;
}

.notif-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
}

/* Primary onboarding button */
.onboarding-btn {
  width: 100%;
  max-width: 320px;
  min-height: 56px;
  padding: 0 24px;
  border: none;
  border-radius: 16px;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: opacity 150ms ease, transform 100ms ease;
}

.onboarding-btn:active {
  opacity: 0.85;
  transform: scale(0.98);
}

/* Skip link */
.onboarding-skip {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 15px;
  cursor: pointer;
  font-family: inherit;
  min-height: 44px;
  padding: 8px 16px;
  transition: color 150ms ease;
}

.onboarding-skip:active {
  color: var(--text);
}


/* ═══════════════════════════════════════════════════════════════
   APP SHELL
   ═══════════════════════════════════════════════════════════════ */
.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  /* Account for safe area already applied to body */
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom));
  overflow: hidden;
}

/* Push fallback banner at very top of app */
.push-fallback {
  background: rgba(74, 158, 255, 0.15);
  border-bottom: 1px solid rgba(74, 158, 255, 0.3);
  color: var(--accent);
  font-size: 13px;
  text-align: center;
  padding: 10px 16px;
  padding-left: calc(16px + var(--safe-left));
  padding-right: calc(16px + var(--safe-right));
  flex-shrink: 0;
}


/* ═══════════════════════════════════════════════════════════════
   VIEW CONTAINER & TRANSITIONS
   ═══════════════════════════════════════════════════════════════ */
.view-container {
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* Each view fills the container */
.view {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  /* Hide scrollbars while keeping scroll functionality */
  scrollbar-width: none;
  -ms-overflow-style: none;
  /* Start invisible — will animate in */
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
  /* Content padding: left/right safe areas + 24px gutter */
  padding-left: calc(24px + var(--safe-left));
  padding-right: calc(24px + var(--safe-right));
  padding-bottom: 32px;
}

.view::-webkit-scrollbar {
  display: none;
}

/* Active view */
.view.active {
  opacity: 1;
  pointer-events: auto;
}

/* View header (Today/History/Insights) */
.view-header {
  padding-top: 20px;
  padding-bottom: 16px;
}

.view-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.3px;
}


/* ═══════════════════════════════════════════════════════════════
   LOG VIEW
   ═══════════════════════════════════════════════════════════════ */
#view-log {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 32px;
  padding-top: 20px;
  /* Background transitions with energy state */
  background: var(--bg-neutral);
  transition: background 400ms ease;
}

#view-log.state-down {
  background: var(--bg-down);
}

#view-log.state-neutral {
  background: var(--bg-neutral);
}

#view-log.state-up {
  background: var(--bg-up);
}

/* Current time */
.log-time {
  font-size: 22px;
  font-weight: 300;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

/* ── Emoji Selector ── */
.emoji-selector {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 24px;
}

.emoji-btn {
  min-width: 80px;
  min-height: 80px;
  font-size: 44px;
  background: none;
  border: 3px solid transparent;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.4;
  transition: opacity 250ms ease, box-shadow 250ms ease, border-color 250ms ease;
  position: relative;
  /* Ensure touch target meets 44px minimum */
  -webkit-user-select: none;
  user-select: none;
}

/* Selected state — glowing ring in accent color */
.emoji-btn.selected {
  opacity: 1;
  border-color: var(--accent);
  box-shadow:
    0 0 0 2px rgba(74, 158, 255, 0.3),
    0 0 20px rgba(74, 158, 255, 0.25);
}

/* Tap pulse animation — pure CSS keyframe */
.emoji-btn.pulse {
  animation: emojiPulse 200ms ease forwards;
}


/* ── Note Input ── */
.note-container {
  width: 100%;
  max-width: 400px;
}

.log-note {
  width: 100%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  padding: 14px 16px;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  resize: none;
  outline: none;
  transition: border-color 200ms ease;
  caret-color: var(--accent);
}

.log-note::placeholder {
  color: var(--text-muted);
  opacity: 0.7;
}

.log-note:focus {
  border-color: rgba(74, 158, 255, 0.5);
}

/* ── Log It Button ── */
.btn-log-it {
  min-height: 56px;
  padding: 0 48px;
  border: none;
  border-radius: 16px;
  background: var(--accent);
  color: #fff;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: opacity 150ms ease, transform 100ms ease;
  letter-spacing: 0.2px;
}

.btn-log-it:active {
  opacity: 0.85;
  transform: scale(0.97);
}

/* ── Save Confirmation Flash ── */
.log-flash {
  position: absolute;
  inset: 0;
  background: var(--accent);
  opacity: 0;
  pointer-events: none;
  border-radius: 0;
}

/* Triggered by app.js adding .flash-active class */
.log-flash.flash-active {
  animation: screenFlash 400ms ease forwards;
}

/* Bouncing emoji when saved */
.emoji-btn.save-bounce {
  animation: emojiBounce 400ms ease;
}


/* ═══════════════════════════════════════════════════════════════
   TODAY VIEW
   ═══════════════════════════════════════════════════════════════ */
#view-today {
  padding-top: 0;
}

.chart-container {
  width: 100%;
  height: 260px;
  position: relative;
  margin-top: 8px;
}

#today-chart {
  width: 100% !important;
  height: 100% !important;
}


/* ═══════════════════════════════════════════════════════════════
   HISTORY VIEW
   ═══════════════════════════════════════════════════════════════ */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* Each date group */
.history-date-group {
  margin-bottom: 24px;
}

.history-date-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 0 0 8px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 4px;
}

/* Individual log entry — swipe-to-delete container */
.history-entry-wrapper {
  position: relative;
  overflow: hidden;
  border-radius: 12px;
  margin-bottom: 4px;
}

.history-entry {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(255,255,255,0.04);
  border-radius: 12px;
  min-height: 52px;
  /* Translate for swipe reveal */
  transform: translateX(0);
  transition: transform 250ms ease;
  position: relative;
  z-index: 1;
  will-change: transform;
}

.history-entry.swiped {
  transform: translateX(-80px);
}

.history-time {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 52px;
}

.history-emoji {
  font-size: 28px;
  line-height: 1;
  flex-shrink: 0;
}

.history-note {
  font-size: 15px;
  color: var(--text);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Delete button revealed on swipe */
.history-delete-btn {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 80px;
  background: #c0392b;
  color: #fff;
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0 12px 12px 0;
  z-index: 0;
}

.history-delete-btn:active {
  background: #a93226;
}


/* ═══════════════════════════════════════════════════════════════
   INSIGHTS VIEW
   ═══════════════════════════════════════════════════════════════ */
#view-insights {
  padding-top: 0;
}

.insight-card {
  background: rgba(255,255,255,0.04);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}

.insight-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  align-self: stretch;
  text-align: left;
}

.insight-big-emoji {
  font-size: 72px;
  line-height: 1;
  filter: drop-shadow(0 0 16px rgba(255,255,255,0.1));
}

.insight-breakdown {
  display: flex;
  gap: 28px;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.insight-breakdown-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.insight-breakdown-emoji {
  font-size: 22px;
}

.insight-breakdown-count {
  font-size: 16px;
  color: var(--text-muted);
}

/* 7-day row */
.insight-7day-row {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.insight-day-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
}

.insight-day-emoji {
  font-size: 24px;
  line-height: 1;
}

.insight-day-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}


/* ═══════════════════════════════════════════════════════════════
   EMPTY STATES
   ═══════════════════════════════════════════════════════════════ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 48px 24px;
  text-align: center;
  min-height: 200px;
}

.empty-emoji {
  font-size: 48px;
  opacity: 0.5;
}

.empty-msg {
  font-size: 16px;
  color: var(--text-muted);
  max-width: 260px;
  line-height: 1.5;
}


/* ═══════════════════════════════════════════════════════════════
   BOTTOM NAVIGATION
   ═══════════════════════════════════════════════════════════════ */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  background: rgba(10, 10, 10, 0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: flex-start;
  padding-top: 0;
  /* Pad buttons away from home indicator */
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  z-index: 100;
}

.nav-btn {
  flex: 1;
  min-height: 56px;
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  font-family: inherit;
  color: var(--text-muted);
  transition: color 200ms ease;
  padding: 8px 4px;
}

.nav-btn.active {
  color: var(--accent);
}

.nav-btn:active {
  opacity: 0.7;
}

.nav-icon {
  font-size: 22px;
  line-height: 1;
}

.nav-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}


/* ═══════════════════════════════════════════════════════════════
   CSS KEYFRAME ANIMATIONS — Non-Negotiable Pure CSS
   ═══════════════════════════════════════════════════════════════ */

/* Emoji tap pulse: scale 1 → 1.3 → 1 over 200ms */
@keyframes emojiPulse {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.3); }
  100% { transform: scale(1); }
}

/* Save confirmation bounce on selected emoji */
@keyframes emojiBounce {
  0%   { transform: scale(1) translateY(0); }
  25%  { transform: scale(1.2) translateY(-8px); }
  50%  { transform: scale(0.95) translateY(0); }
  75%  { transform: scale(1.05) translateY(-3px); }
  100% { transform: scale(1) translateY(0); }
}

/* Screen flash on save */
@keyframes screenFlash {
  0%   { opacity: 0.18; }
  40%  { opacity: 0.22; }
  100% { opacity: 0; }
}

/* Arrow bounce for install instruction */
@keyframes arrowBounce {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(10px); }
}

/* Bell pulse for notification step */
@keyframes notifPulse {
  0%, 100% { transform: scale(1); }
  10%       { transform: scale(1.12) rotate(-8deg); }
  20%       { transform: scale(1.12) rotate(8deg); }
  30%       { transform: scale(1.12) rotate(-6deg); }
  40%       { transform: scale(1.12) rotate(6deg); }
  50%       { transform: scale(1) rotate(0); }
}
