/* ============================================
   Base Styles & Reset
   Food Cost Control Hub Mini App
   ============================================ */

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-normal);
  line-height: var(--line-height-normal);
  color: var(--color-text);
  background-color: var(--color-bg);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

/* === Typography === */
h1, h2, h3, h4, h5, h6 {
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-tight);
  color: var(--color-text);
}

h1 { font-size: var(--font-size-3xl); }
h2 { font-size: var(--font-size-2xl); }
h3 { font-size: var(--font-size-xl); }
h4 { font-size: var(--font-size-lg); }
h5 { font-size: var(--font-size-base); }
h6 { font-size: var(--font-size-sm); }

p {
  margin-bottom: var(--space-3);
}

a {
  color: var(--color-link);
  text-decoration: none;
  transition: opacity var(--duration-fast) var(--ease-default);
}

a:active {
  opacity: 0.7;
}

small {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

strong, b {
  font-weight: var(--font-weight-semibold);
}

/* === Lists === */
ul, ol {
  list-style: none;
}

/* === Images === */
img, svg {
  display: block;
  max-width: 100%;
  height: auto;
}

/* === Forms === */
button,
input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  color: inherit;
  background: none;
  border: none;
  outline: none;
}

button {
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

input::placeholder,
textarea::placeholder {
  color: var(--color-text-secondary);
}

/* === Utility Classes === */

/* Display */
.hidden { display: none !important; }
.block { display: block; }
.inline-block { display: inline-block; }
.flex { display: flex; }
.inline-flex { display: inline-flex; }
.grid { display: grid; }

/* Flexbox */
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-start { align-items: flex-start; }
.items-center { align-items: center; }
.items-end { align-items: flex-end; }
.justify-start { justify-content: flex-start; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-xs { gap: var(--space-1); }
.gap-sm { gap: var(--space-2); }
.gap-md { gap: var(--space-3); }
.gap-lg { gap: var(--space-4); }
.flex-1 { flex: 1; }
.flex-shrink-0 { flex-shrink: 0; }
.align-center { align-items: center; }

/* Text */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }
.text-xs { font-size: var(--font-size-xs); }
.text-sm { font-size: var(--font-size-sm); }
.text-base { font-size: var(--font-size-base); }
.text-lg { font-size: var(--font-size-lg); }
.text-xl { font-size: var(--font-size-xl); }
.text-2xl { font-size: var(--font-size-2xl); }
.font-medium { font-weight: var(--font-weight-medium); }
.font-semibold { font-weight: var(--font-weight-semibold); }
.font-bold { font-weight: var(--font-weight-bold); }
.text-secondary { color: var(--color-text-secondary); }
.text-hint { color: var(--color-text-secondary); }
.text-accent { color: var(--color-accent); }
.text-success { color: var(--color-success); }
.text-warning { color: var(--color-warning); }
.text-error { color: var(--color-error); }
.text-md { font-size: var(--font-size-base); }
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Spacing */
.m-0 { margin: 0; }
.m-auto { margin: auto; }
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-xs { margin-top: var(--space-1); }
.mt-sm { margin-top: var(--space-2); }
.mt-md { margin-top: var(--space-3); }
.mt-lg { margin-top: var(--space-4); }
.mb-1 { margin-bottom: var(--space-1); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-xs { margin-bottom: var(--space-1); }
.mb-sm { margin-bottom: var(--space-2); }
.mb-md { margin-bottom: var(--space-3); }
.mb-lg { margin-bottom: var(--space-4); }
.ml-xs { margin-left: var(--space-1); }
.ml-sm { margin-left: var(--space-2); }
.ml-md { margin-left: var(--space-3); }
.ml-lg { margin-left: var(--space-4); }
.mr-xs { margin-right: var(--space-1); }
.mr-sm { margin-right: var(--space-2); }
.mr-md { margin-right: var(--space-3); }
.mr-lg { margin-right: var(--space-4); }
.p-0 { padding: 0; }
.p-2 { padding: var(--space-2); }
.p-3 { padding: var(--space-3); }
.p-4 { padding: var(--space-4); }
.p-md { padding: var(--space-3); }
.p-lg { padding: var(--space-4); }
.px-2 { padding-left: var(--space-2); padding-right: var(--space-2); }
.px-3 { padding-left: var(--space-3); padding-right: var(--space-3); }
.px-4 { padding-left: var(--space-4); padding-right: var(--space-4); }
.py-2 { padding-top: var(--space-2); padding-bottom: var(--space-2); }
.py-3 { padding-top: var(--space-3); padding-bottom: var(--space-3); }
.py-4 { padding-top: var(--space-4); padding-bottom: var(--space-4); }

/* Width & Height */
.w-full { width: 100%; }
.h-full { height: 100%; }
.min-h-screen { min-height: 100vh; min-height: 100dvh; }

/* Border Radius */
.rounded { border-radius: var(--radius-md); }
.rounded-sm { border-radius: var(--radius-sm); }
.rounded-lg { border-radius: var(--radius-lg); }
.rounded-xl { border-radius: var(--radius-xl); }
.rounded-full { border-radius: var(--radius-full); }

/* Overflow */
.overflow-hidden { overflow: hidden; }
.overflow-auto { overflow: auto; }
.overflow-y-auto { overflow-y: auto; }

/* Position */
.relative { position: relative; }
.absolute { position: absolute; }
.fixed { position: fixed; }
.sticky { position: sticky; }
.inset-0 { top: 0; right: 0; bottom: 0; left: 0; }

/* Transitions */
.transition {
  transition-property: all;
  transition-duration: var(--duration-normal);
  transition-timing-function: var(--ease-default);
}
.transition-fast { transition-duration: var(--duration-fast); }
.transition-slow { transition-duration: var(--duration-slow); }

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@keyframes slideDown {
  from { transform: translateY(0); }
  to { transform: translateY(100%); }
}

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

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

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

.animate-fadeIn { animation: fadeIn var(--duration-normal) var(--ease-out); }
.animate-scaleIn { animation: scaleIn var(--duration-normal) var(--ease-out); }
.animate-spin { animation: spin 1s linear infinite; }
.animate-pulse { animation: pulse 2s var(--ease-default) infinite; }

/* === Enhanced Micro-Animations === */
@keyframes slideInUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes slideInDown {
  from {
    transform: translateY(-20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

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

@keyframes slideInRight {
  from {
    transform: translateX(20px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

@keyframes popIn {
  0% {
    transform: scale(0.8);
    opacity: 0;
  }
  70% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes wiggle {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-3deg); }
  75% { transform: rotate(3deg); }
}

@keyframes glow {
  0%, 100% { box-shadow: 0 0 5px var(--color-accent); }
  50% { box-shadow: 0 0 20px var(--color-accent); }
}

@keyframes ripple {
  0% {
    transform: scale(0);
    opacity: 0.5;
  }
  100% {
    transform: scale(4);
    opacity: 0;
  }
}

.animate-slideInUp { animation: slideInUp var(--duration-normal) var(--ease-out); }
.animate-slideInDown { animation: slideInDown var(--duration-normal) var(--ease-out); }
.animate-slideInLeft { animation: slideInLeft var(--duration-normal) var(--ease-out); }
.animate-slideInRight { animation: slideInRight var(--duration-normal) var(--ease-out); }
.animate-bounce { animation: bounce 0.5s var(--ease-bounce); }
.animate-shake { animation: shake 0.3s var(--ease-default); }
.animate-popIn { animation: popIn var(--duration-normal) var(--ease-bounce); }
.animate-wiggle { animation: wiggle 0.3s var(--ease-default); }

/* Staggered animations for lists */
.stagger-list > *:nth-child(1) { animation-delay: 0ms; }
.stagger-list > *:nth-child(2) { animation-delay: 30ms; }
.stagger-list > *:nth-child(3) { animation-delay: 60ms; }
.stagger-list > *:nth-child(4) { animation-delay: 90ms; }
.stagger-list > *:nth-child(5) { animation-delay: 120ms; }
.stagger-list > *:nth-child(6) { animation-delay: 150ms; }
.stagger-list > *:nth-child(7) { animation-delay: 180ms; }
.stagger-list > *:nth-child(8) { animation-delay: 210ms; }
.stagger-list > *:nth-child(9) { animation-delay: 240ms; }
.stagger-list > *:nth-child(10) { animation-delay: 270ms; }

.stagger-list > * {
  animation: slideInUp var(--duration-normal) var(--ease-out) backwards;
}

/* Hover lift effect */
.hover-lift {
  transition: transform var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out);
}

.hover-lift:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.hover-lift:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

/* Press effect */
.press-effect {
  transition: transform var(--duration-fast) var(--ease-out);
}

.press-effect:active {
  transform: scale(0.97);
}

/* Ripple button effect */
.ripple-effect {
  position: relative;
  overflow: hidden;
}

.ripple-effect::after {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  background: radial-gradient(circle, rgba(255,255,255,0.3) 0%, transparent 70%);
  border-radius: inherit;
  pointer-events: none;
}

.ripple-effect:active::after {
  animation: ripple 0.4s var(--ease-out);
}

/* === App Layout === */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: var(--max-width);
  margin: 0 auto;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-bg-secondary);
}

.app-content {
  flex: 1;
  padding: var(--space-4);
  padding-bottom: calc(var(--nav-height) + var(--space-4) + var(--safe-area-bottom));
  overflow-y: auto;
}

.app-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: var(--z-fixed);
  background: var(--color-bg);
  border-top: 1px solid var(--color-bg-secondary);
  padding-bottom: var(--safe-area-bottom);
}

/* === Screen Containers === */
.screen {
  display: none;
}

.screen.active {
  display: block;
  animation: fadeIn var(--duration-fast) var(--ease-out);
}

/* === Scrollbar === */
::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--color-text-secondary);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-text);
}
