/* v29: Mobile-first glass morphism, entrance animations, and visual polish.
   GPU-friendly: only use backdrop-filter on elements that truly need it,
   and keep animations on transform/opacity (compositor-only properties). */

/* ===== GLASS MORPHISM — selective, performant ===== */

/* Topbar glass: the one surface that genuinely needs live blur
   because it overlays scrolling content. */
.topbar {
  background: rgba(250, 251, 250, .82);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
}

/* Summary band: subtle frosted card */
.summary-band {
  background: linear-gradient(135deg, rgba(255, 255, 255, .92), rgba(250, 252, 251, .82));
  -webkit-backdrop-filter: saturate(160%) blur(18px);
  backdrop-filter: saturate(160%) blur(18px);
  border: 1px solid rgba(255, 255, 255, .6);
  box-shadow: 0 4px 24px rgba(0, 0, 0, .04), inset 0 1px 0 rgba(255, 255, 255, .9);
}

/* Quick menu: frosted popover */
.quick-menu {
  background: rgba(255, 255, 255, .85);
  -webkit-backdrop-filter: saturate(180%) blur(28px);
  backdrop-filter: saturate(180%) blur(28px);
  border: 1px solid rgba(255, 255, 255, .7);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .08);
}

/* Dialog: frosted overlay */
.app-dialog {
  background: rgba(255, 255, 255, .92);
  -webkit-backdrop-filter: saturate(180%) blur(36px);
  backdrop-filter: saturate(180%) blur(36px);
  border: 1px solid rgba(255, 255, 255, .75);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .1);
}

.app-dialog::backdrop {
  background: rgba(20, 28, 24, .28);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

/* Toast: glass dark */
.toast {
  background: rgba(28, 36, 32, .88);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid rgba(255, 255, 255, .08);
}

/* Username reminder: frosted card */
.username-reminder {
  background: rgba(255, 255, 255, .78);
  -webkit-backdrop-filter: saturate(160%) blur(24px);
  backdrop-filter: saturate(160%) blur(24px);
}

/* Chat form: gentle frost to separate from messages */
#aiView .chat-form {
  background: rgba(255, 255, 255, .88);
  -webkit-backdrop-filter: saturate(150%) blur(20px);
  backdrop-filter: saturate(150%) blur(20px);
}

/* ===== SEASONAL GLASS TINTS ===== */

/* 秋季 🍁 枫叶暖橘 */
:root[data-theme="autumn"] .summary-band,
:root[data-season="autumn"][data-theme="auto"] .summary-band {
  background: linear-gradient(135deg, rgba(253, 243, 234, .92), rgba(250, 238, 225, .82));
  border-color: rgba(196, 122, 58, .15);
}
:root[data-theme="autumn"] .topbar,
:root[data-season="autumn"][data-theme="auto"] .topbar {
  background: rgba(253, 249, 245, .85);
}

/* 夏季 🌊 清凉海蓝 */
:root[data-theme="summer"] .summary-band,
:root[data-season="summer"][data-theme="auto"] .summary-band {
  background: linear-gradient(135deg, rgba(237, 246, 252, .92), rgba(230, 242, 250, .82));
  border-color: rgba(46, 139, 170, .15);
}
:root[data-theme="summer"] .topbar,
:root[data-season="summer"][data-theme="auto"] .topbar {
  background: rgba(245, 250, 254, .85);
}

/* 冬季 ❄️ 冰晶靛蓝 */
:root[data-theme="winter"] .summary-band,
:root[data-season="winter"][data-theme="auto"] .summary-band {
  background: linear-gradient(135deg, rgba(238, 242, 249, .92), rgba(230, 236, 248, .82));
  border-color: rgba(88, 116, 168, .15);
}
:root[data-theme="winter"] .topbar,
:root[data-season="winter"][data-theme="auto"] .topbar {
  background: rgba(245, 247, 252, .85);
}

/* 春季 🌸 樱花嫩绿 */
:root[data-theme="spring"] .summary-band,
:root[data-season="spring"][data-theme="auto"] .summary-band {
  background: linear-gradient(135deg, rgba(238, 248, 240, .92), rgba(228, 245, 232, .82));
  border-color: rgba(74, 158, 110, .15);
}
:root[data-theme="spring"] .topbar,
:root[data-season="spring"][data-theme="auto"] .topbar {
  background: rgba(246, 251, 247, .85);
}

/* ===== ENTRANCE ANIMATIONS ===== */

/* Summary band slides up on load */
.summary-band {
  animation: slideUpFade 420ms cubic-bezier(.22, .8, .26, 1) both;
}

/* Calendar tool slides up with stagger */
.calendar-tool {
  animation: slideUpFade 460ms cubic-bezier(.22, .8, .26, 1) 80ms both;
}

/* Sidebar cards stagger in */
.month-goal-card {
  animation: slideUpFade 440ms cubic-bezier(.22, .8, .26, 1) 140ms both;
}

.day-panel {
  animation: slideUpFade 440ms cubic-bezier(.22, .8, .26, 1) 200ms both;
}

/* Analysis sections fade in on view switch */
.analysis-section {
  animation: fadeInUp 380ms cubic-bezier(.22, .8, .26, 1) both;
}

.analysis-section:nth-child(2) { animation-delay: 60ms; }
.analysis-section:nth-child(3) { animation-delay: 120ms; }
.analysis-section:nth-child(4) { animation-delay: 180ms; }

/* Quarter cards stagger */
.quarter-card {
  animation: scaleIn 340ms cubic-bezier(.22, .8, .26, 1) both;
}

.quarter-card:nth-child(1) { animation-delay: 40ms; }
.quarter-card:nth-child(2) { animation-delay: 100ms; }
.quarter-card:nth-child(3) { animation-delay: 160ms; }
.quarter-card:nth-child(4) { animation-delay: 220ms; }

/* Bar chart bars grow up with stagger */
.bar-fill {
  animation: barGrow 500ms cubic-bezier(.22, .8, .26, 1) both;
  transform-origin: bottom center;
}

.bar-button:nth-child(1) .bar-fill { animation-delay: 50ms; }
.bar-button:nth-child(2) .bar-fill { animation-delay: 80ms; }
.bar-button:nth-child(3) .bar-fill { animation-delay: 110ms; }
.bar-button:nth-child(4) .bar-fill { animation-delay: 140ms; }
.bar-button:nth-child(5) .bar-fill { animation-delay: 170ms; }
.bar-button:nth-child(6) .bar-fill { animation-delay: 200ms; }
.bar-button:nth-child(7) .bar-fill { animation-delay: 230ms; }
.bar-button:nth-child(8) .bar-fill { animation-delay: 260ms; }
.bar-button:nth-child(9) .bar-fill { animation-delay: 290ms; }
.bar-button:nth-child(10) .bar-fill { animation-delay: 320ms; }
.bar-button:nth-child(11) .bar-fill { animation-delay: 350ms; }
.bar-button:nth-child(12) .bar-fill { animation-delay: 380ms; }

/* Trend overview slides in */
.trend-overview {
  animation: slideUpFade 400ms cubic-bezier(.22, .8, .26, 1) 60ms both;
}

/* AI panel fades in */
.ai-panel {
  animation: fadeInUp 420ms cubic-bezier(.22, .8, .26, 1) 200ms both;
}

/* Dialog enters with spring-like bounce */
.app-dialog[open] {
  animation: dialogSpring 300ms cubic-bezier(.22, .8, .26, 1) both;
}

.app-dialog::backdrop {
  animation: backdropFade 240ms ease both;
}

/* Quick menu spring entry */
.is-open .quick-menu {
  animation: menuSpring 280ms cubic-bezier(.16, 1, .3, 1.08) both;
}

/* Chat message entrance */
.chat-message {
  animation: chatMessageIn 300ms cubic-bezier(.22, .8, .26, 1) both;
}

/* Chat welcome screen */
.chat-welcome {
  animation: fadeInUp 500ms cubic-bezier(.22, .8, .26, 1) 100ms both;
}

.chat-suggestions button {
  animation: scaleIn 320ms cubic-bezier(.22, .8, .26, 1) both;
}

.chat-suggestions button:nth-child(1) { animation-delay: 200ms; }
.chat-suggestions button:nth-child(2) { animation-delay: 280ms; }
.chat-suggestions button:nth-child(3) { animation-delay: 360ms; }

/* Record rows slide in */
.record-row {
  animation: slideInLeft 280ms cubic-bezier(.22, .8, .26, 1) both;
}

.record-row:nth-child(1) { animation-delay: 30ms; }
.record-row:nth-child(2) { animation-delay: 70ms; }
.record-row:nth-child(3) { animation-delay: 110ms; }
.record-row:nth-child(4) { animation-delay: 150ms; }
.record-row:nth-child(5) { animation-delay: 190ms; }

/* Empty state gentle pulse */
.empty-state svg {
  animation: gentlePulse 2.4s ease-in-out infinite;
}

.empty-state {
  animation: fadeInUp 400ms cubic-bezier(.22, .8, .26, 1) both;
}

.empty-state svg {
  width: 28px;
  height: 28px;
  margin-bottom: 12px;
  color: var(--accent);
  opacity: .5;
}

/* ===== KEYFRAMES ===== */

@keyframes slideUpFade {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(.94);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes barGrow {
  from {
    transform: scaleY(0);
    opacity: 0;
  }
  to {
    transform: scaleY(1);
    opacity: 1;
  }
}

@keyframes dialogSpring {
  from {
    opacity: 0;
    transform: translateY(12px) scale(.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes backdropFade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes menuSpring {
  from {
    opacity: 0;
    transform: translateY(8px) scale(.92);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes chatMessageIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-12px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes gentlePulse {
  0%, 100% { transform: scale(1); opacity: .5; }
  50% { transform: scale(1.08); opacity: .7; }
}

/* ===== ENHANCED MOBILE CARDS — HEAVY GLASS ===== */

@media (max-width: 640px) {
  /* Glass cards on mobile — heavier blur, no dark borders */
  .calendar-tool,
  .month-goal-card,
  .day-panel {
    border: 1px solid rgba(255, 255, 255, .65);
    background: rgba(255, 255, 255, .82);
    -webkit-backdrop-filter: saturate(170%) blur(20px);
    backdrop-filter: saturate(170%) blur(20px);
    box-shadow: 0 4px 24px rgba(0, 0, 0, .04), inset 0 1px 0 rgba(255, 255, 255, .95);
  }

  /* Analysis chat glass */
  .analysis-chat {
    background: rgba(255, 255, 255, .85);
    -webkit-backdrop-filter: saturate(160%) blur(18px);
    backdrop-filter: saturate(160%) blur(18px);
    border: 1px solid rgba(255, 255, 255, .6);
  }

  /* Quarter cards glass */
  .quarter-card {
    background: rgba(255, 255, 255, .78);
    -webkit-backdrop-filter: saturate(150%) blur(14px);
    backdrop-filter: saturate(150%) blur(14px);
    border: 1px solid rgba(255, 255, 255, .6);
    box-shadow: 0 4px 20px rgba(0, 0, 0, .03), inset 0 1px 0 rgba(255, 255, 255, .9);
  }

  .quarter-card.is-current {
    background: rgba(255, 255, 255, .9);
    border-color: rgba(82, 117, 101, .2);
  }

  /* Table wrap glass */
  .table-wrap {
    background: rgba(255, 255, 255, .78);
    -webkit-backdrop-filter: saturate(150%) blur(14px);
    backdrop-filter: saturate(150%) blur(14px);
    border: 1px solid rgba(255, 255, 255, .6);
  }

  /* AI panel glass — heavy */
  .ai-panel {
    background: rgba(250, 251, 251, .82);
    -webkit-backdrop-filter: saturate(160%) blur(18px);
    backdrop-filter: saturate(160%) blur(18px);
    border: 1px solid rgba(255, 255, 255, .6);
    box-shadow: 0 4px 24px rgba(0, 0, 0, .04), inset 0 1px 0 rgba(255, 255, 255, .9);
  }

  /* Trend overview glass */
  .trend-overview {
    background: rgba(255, 255, 255, .72);
    -webkit-backdrop-filter: saturate(150%) blur(14px);
    backdrop-filter: saturate(150%) blur(14px);
    border: 1px solid rgba(255, 255, 255, .55);
  }

  /* Chat header glass — heavy */
  .chat-header {
    background: rgba(255, 255, 255, .82);
    -webkit-backdrop-filter: saturate(170%) blur(20px);
    backdrop-filter: saturate(170%) blur(20px);
  }

  /* Chat message bubbles: frosted glass assistant */
  .chat-message.is-assistant p {
    background: rgba(255, 255, 255, .88);
    -webkit-backdrop-filter: saturate(140%) blur(12px);
    backdrop-filter: saturate(140%) blur(12px);
    border: 1px solid rgba(255, 255, 255, .7);
    box-shadow: 0 2px 12px rgba(0, 0, 0, .03);
  }

  /* Smoother topbar on mobile */
  .topbar {
    background: rgba(250, 251, 250, .82);
    box-shadow: 0 1px 0 rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .02);
  }

  /* View tabs: subtle glass */
  .view-tabs {
    background: rgba(245, 247, 246, .7);
    -webkit-backdrop-filter: saturate(150%) blur(12px);
    backdrop-filter: saturate(150%) blur(12px);
  }

  .view-tab.is-active {
    background: rgba(255, 255, 255, .95);
    box-shadow: 0 2px 10px rgba(0, 0, 0, .06), inset 0 1px 0 rgba(255, 255, 255, .9);
  }

  /* Suggestion buttons glass */
  .chat-suggestions button {
    background: rgba(255, 255, 255, .82);
    -webkit-backdrop-filter: saturate(140%) blur(12px);
    backdrop-filter: saturate(140%) blur(12px);
    border: 1px solid rgba(255, 255, 255, .6);
  }

  /* Record dialog sticky actions glass */
  .record-dialog .dialog-actions {
    background: rgba(255, 255, 255, .88);
    -webkit-backdrop-filter: saturate(170%) blur(20px);
    backdrop-filter: saturate(170%) blur(20px);
  }

  /* Chat message visual hierarchy */
  .chat-message.is-user p {
    border-radius: 16px 16px 4px 16px;
    box-shadow: 0 4px 16px rgba(31, 90, 78, .14);
  }

  .chat-message.is-assistant p {
    border-radius: 16px 16px 16px 4px;
  }

  .chat-messages {
    padding: 16px 12px;
    gap: 12px;
  }

  /* Analysis section: card-like glass appearance */
  .analysis-section {
    padding: 24px 16px;
    margin: 0 -4px 12px;
    border-radius: 16px;
    border-bottom: none;
    background: rgba(255, 255, 255, .6);
    -webkit-backdrop-filter: saturate(140%) blur(12px);
    backdrop-filter: saturate(140%) blur(12px);
    border: 1px solid rgba(255, 255, 255, .55);
  }

  /* Quarter cards: 2-column on small screens */
  .quarter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .quarter-card {
    padding: 14px;
    border-radius: 14px;
  }

  .quarter-total {
    font-size: 18px;
  }

  /* Trend overview: glass */
  .trend-block {
    padding: 16px 18px;
    min-height: 100px;
  }

  .trend-block strong {
    font-size: 22px;
  }

  /* Monthly chart: responsive */
  .monthly-chart {
    height: 220px;
    gap: 5px;
    padding: 14px 4px 0;
  }

  .bar-value {
    font-size: 9px;
  }

  .bar-label {
    font-size: 10px;
    line-height: 24px;
  }

  /* Empty state: polished */
  .empty-state {
    padding: 32px 24px;
    border-radius: 16px;
    background: rgba(255, 255, 255, .5);
    -webkit-backdrop-filter: saturate(130%) blur(8px);
    backdrop-filter: saturate(130%) blur(8px);
  }

  /* Chat welcome: spacious */
  .chat-welcome {
    padding: 24px 20px;
  }

  /* Chat suggestions: rounded pill */
  .chat-suggestions button {
    border-radius: 20px;
    padding: 10px 16px;
  }

  /* Summary band: rounded card */
  .summary-band {
    border-radius: 16px;
    margin: 0 12px;
  }

  /* Calendar tool: rounded glass */
  .calendar-tool {
    border-radius: 16px;
  }

  /* Calendar day: today highlight */
  .calendar-day.is-today {
    box-shadow: 0 2px 10px rgba(82, 117, 101, .12), inset 0 0 0 1.5px var(--accent);
  }

  /* Month navigation: larger touch area */
  .month-navigation .icon-button {
    width: 44px;
    height: 44px;
  }
}

/* ===== ENHANCED MOBILE INTERACTIONS ===== */

@media (max-width: 640px) {
  /* Smoother touch feedback */
  .calendar-day:active {
    background: var(--accent-soft);
    transition: background-color 60ms ease;
  }

  /* Snappier day number press */
  .calendar-day .day-number {
    transition: transform 100ms cubic-bezier(.2, .7, .2, 1);
  }
  .calendar-day:active .day-number {
    transform: translateY(1.5px) scale(.95);
    transition-duration: 40ms;
  }

  /* Calendar grid: fade in on month switch */
  .calendar-grid {
    animation: fadeInUp 220ms cubic-bezier(.22, .8, .26, 1) both;
  }

  /* View tab switch animation */
  .view-tab.is-active {
    animation: tabActivate 200ms cubic-bezier(.22, .8, .26, 1) both;
  }

  /* Month goal progress bar: animate width */
  .month-goal-track > span {
    transition: width 600ms cubic-bezier(.22, .8, .26, 1);
  }

  /* Thinking dots: glass bubble */
  .chat-thinking-bubble {
    background: rgba(255, 255, 255, .72) !important;
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
  }
}

@keyframes tabActivate {
  from {
    opacity: .7;
    transform: scale(.96);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ===== RESPECT REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
  .summary-band,
  .calendar-tool,
  .calendar-grid,
  .month-goal-card,
  .day-panel,
  .analysis-section,
  .quarter-card,
  .bar-fill,
  .trend-overview,
  .ai-panel,
  .app-dialog[open],
  .app-dialog::backdrop,
  .is-open .quick-menu,
  .chat-message,
  .chat-welcome,
  .chat-suggestions button,
  .record-row,
  .empty-state,
  .empty-state svg,
  .view-tab.is-active {
    animation: none !important;
  }
}
