/* App shell: left sidebar (logo + nav) + main area; mobile drawer + top bar */

.app-shell {
  min-height: 100dvh;
  min-height: 100vh;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  position: relative;
  z-index: 1;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 180;
  background: rgba(20, 18, 16, 0.45);
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.sidebar-backdrop:not([hidden]) {
  display: block;
}

.app-sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
  padding: var(--space-lg) var(--space-md);
  padding-top: calc(var(--space-lg) + env(safe-area-inset-top, 0px));
  padding-left: calc(var(--space-md) + env(safe-area-inset-left, 0px));
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  z-index: 200;
}

.app-sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-xs) 0;
}

.app-sidebar__logo {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-md);
  background: var(--bg-muted);
  border: 1px solid var(--border);
  object-fit: contain;
  padding: 4px;
  box-sizing: border-box;
  flex-shrink: 0;
}

.app-sidebar__brand-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.app-sidebar__title {
  font-family: var(--font-brand);
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.app-sidebar__subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.app-sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  flex: 1;
}

.app-sidebar__link {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0.65rem 0.85rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.9375rem;
  text-align: left;
  cursor: pointer;
  transition:
    background var(--transition),
    color var(--transition),
    transform var(--transition),
    box-shadow var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.app-sidebar__link:hover {
  background: var(--bg-muted);
  color: var(--text-primary);
  transform: translateX(3px);
}

.app-sidebar__link[aria-current="true"] {
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(63, 111, 94, 0.2);
  transform: translateX(0);
}

/* Light-only theme: no dark overrides. */

@media (prefers-reduced-motion: reduce) {
  .app-sidebar__link:hover {
    transform: none;
  }
}

.app-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.app-topbar {
  display: none;
  align-items: center;
  gap: var(--space-md);
  min-height: 52px;
  padding: var(--space-sm) var(--space-md);
  padding-top: calc(var(--space-sm) + env(safe-area-inset-top, 0px));
  padding-left: calc(var(--space-md) + env(safe-area-inset-left, 0px));
  padding-right: calc(var(--space-md) + env(safe-area-inset-right, 0px));
  background: var(--surface-glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 150;
}

.app-topbar__menu {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--bg-muted);
  color: var(--text-primary);
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.app-topbar__menu:hover {
  background: var(--bg-elevated);
}

.app-topbar__menu-bars {
  display: block;
  width: 20px;
  height: 14px;
  border-top: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  position: relative;
  box-sizing: border-box;
}

.app-topbar__menu-bars::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  height: 2px;
  background: currentColor;
}

.app-topbar__title {
  font-family: var(--font-brand);
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Light-only theme: no dark overrides. */

.app-main {
  flex: 1;
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-lg) var(--space-md) var(--space-2xl);
  padding-bottom: calc(var(--space-2xl) + env(safe-area-inset-bottom, 0px));
}

.view {
  display: none;
  animation: fadeIn 0.35s ease;
}

.view.is-active {
  display: block;
}

/* Log meal view: slightly richer entrance when switching from Overview */
.view#view-log.is-active {
  animation: viewEnterLog 0.48s var(--ease-out-soft, cubic-bezier(0.33, 1, 0.68, 1)) both;
}

@keyframes viewEnterLog {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

@media (prefers-reduced-motion: reduce) {
  .view {
    animation: none;
  }

  .view.is-active,
  .view#view-log.is-active {
    animation: fadeInReduced 0.22s ease;
  }

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

.grid-2 {
  display: grid;
  gap: var(--space-lg);
}

@media (min-width: 900px) {
  .grid-2 {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

/* —— Mobile: drawer sidebar + top bar —— */
@media (max-width: 899px) {
  .app-topbar {
    display: flex;
  }

  .sidebar-backdrop:not([hidden]) {
    display: block;
  }

  .app-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    max-width: min(300px, 88vw);
    transform: translateX(-105%);
    transition: transform 0.25s ease;
    box-shadow: var(--shadow-lg);
  }

  .app-sidebar.is-open {
    transform: translateX(0);
  }

  .app-main {
    padding-top: var(--space-md);
  }
}

@media (min-width: 900px) {
  .app-sidebar {
    position: relative;
    transform: none !important;
  }

  .sidebar-backdrop {
    display: none !important;
  }
}
