/* App Tab Bar - Persistent bottom navigation for mobile */
/* Uses rgb(var(--card)), rgb(var(--foreground)), etc. with fallbacks */

.app-tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 0.5rem 0;
  padding-bottom: calc(0.5rem + env(safe-area-inset-bottom, 0px));
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.06);
}

/* Dark mode (blog pages use .dark, timer pages use [data-theme="style1"]) */
.dark .app-tab-bar,
[data-theme="style1"] .app-tab-bar {
  background: rgba(24, 24, 27, 0.9);
  border-top-color: rgba(255, 255, 255, 0.08);
}

.dark .app-tab-bar a,
.dark .app-tab-bar button,
[data-theme="style1"] .app-tab-bar a,
[data-theme="style1"] .app-tab-bar button {
  color: #a1a1aa;
}

.dark .app-tab-bar a:hover,
.dark .app-tab-bar a:active,
.dark .app-tab-bar button:hover,
.dark .app-tab-bar button:active,
[data-theme="style1"] .app-tab-bar a:hover,
[data-theme="style1"] .app-tab-bar a:active,
[data-theme="style1"] .app-tab-bar button:hover,
[data-theme="style1"] .app-tab-bar button:active {
  color: #fafafa;
}

.app-tab-bar a,
.app-tab-bar button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  min-width: 44px;
  min-height: 44px;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: rgb(var(--muted-foreground, 100 116 139));
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  transition: color 0.2s, opacity 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.app-tab-bar a:hover,
.app-tab-bar a:active,
.app-tab-bar button:hover,
.app-tab-bar button:active {
  color: rgb(var(--foreground, 10 10 10));
  opacity: 0.9;
}

.app-tab-bar .tab-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.app-tab-bar .tab-icon svg {
  width: 1.35rem;
  height: 1.35rem;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Spacer for pages with tab bar - prevent content from being hidden (footer must clear tab bar) */
.has-tab-bar main { padding-bottom: 7rem; }
.has-tab-bar .container { padding-bottom: calc(7rem + env(safe-area-inset-bottom, 0px)); }
/* Web footer: ensure visible above tab bar (not hidden behind it) */
.has-tab-bar .web-footer { margin-bottom: calc(7rem + env(safe-area-inset-bottom, 0px)); }

/* Prevent header overlapping timer box on mobile (Safari, iPhone 13 mini, etc.) */
@media (max-width: 768px) {
  .has-tab-bar .timer-container {
    margin-top: calc(4rem + env(safe-area-inset-top, 0px)) !important;
  }
  /* Browser-only: Safari iOS returns 0 for env(safe-area-inset-top) in portrait */
  html:not([data-capacitor]) .has-tab-bar .timer-container {
    margin-top: calc(4rem + max(env(safe-area-inset-top, 0px), 47px)) !important;
  }
}

/* Smartphone landscape: lift timer up - reduce margin below header */
@media (orientation: landscape) and (max-height: 500px) {
  html[data-capacitor="true"] .has-tab-bar .timer-container {
    margin-top: clamp(2rem, 3vw, 2.5rem) !important;
  }
  /* HTML/Safari only: reduce gap between header and timer to match Capacitor (Capacitor unchanged) */
  html:not([data-capacitor]) .has-tab-bar .timer-container {
    margin-top: calc(1.5rem + max(env(safe-area-inset-top, 0px), 47px)) !important;
  }
}

/* Keep sign-in visible when theme/menu are hidden on mobile */
.has-tab-bar .header-actions #timerist-auth-mount {
  flex-shrink: 0;
  min-width: fit-content;
}

/* Hide header moon + hamburger on mobile when tab bar provides them */
/* Exception: show-top-menu pages (u, my-workouts, profile) keep hamburger visible */
@media (max-width: 768px) {
  .has-tab-bar .blog-header-actions .blog-mode-btn,
  .has-tab-bar .blog-header-actions .blog-hamburger {
    display: none;
  }
  .show-top-menu.has-tab-bar .blog-header-actions .blog-hamburger {
    display: flex !important;
  }
  /* Also hide timer page header actions (different class names) */
  .has-tab-bar .header-actions .mode-toggle-btn,
  .has-tab-bar .header-actions .hamburger-menu {
    display: none;
  }
}

/* Mobile: reduce tab bar padding (portrait + landscape) - less white space below icons */
/* !important overrides tab-bar-inject.js base styles which load later in cascade */
@media (max-width: 768px) {
  .app-tab-bar {
    padding: 0.25rem 0 !important;
    padding-bottom: calc(0.125rem + env(safe-area-inset-bottom, 0px)) !important;
  }
  .app-tab-bar a,
  .app-tab-bar button {
    min-height: 40px !important;
    gap: 0.125rem !important;
    padding: 0.125rem 0.4rem !important;
    font-size: 0.7rem !important;
  }
  .app-tab-bar .tab-icon svg {
    width: 1.2rem !important;
    height: 1.2rem !important;
  }
}

/* Landscape: further reduce tab bar for short viewports */
@media (orientation: landscape) and (max-height: 500px) {
  .app-tab-bar {
    padding: 0.125rem 0 !important;
    padding-bottom: calc(0.125rem + env(safe-area-inset-bottom, 0px)) !important;
  }
  .app-tab-bar a,
  .app-tab-bar button {
    min-height: 32px !important;
    gap: 0.0625rem !important;
    padding: 0.0625rem 0.4rem !important;
    font-size: 0.65rem !important;
  }
  .app-tab-bar .tab-icon svg {
    width: 1.15rem !important;
    height: 1.15rem !important;
  }
  /* HTML/Safari only: thinner tab bar to match Capacitor (Capacitor unchanged) */
  html:not([data-capacitor]) .app-tab-bar {
    padding: 0 !important;
    padding-bottom: calc(0.0625rem + env(safe-area-inset-bottom, 0px)) !important;
  }
  html:not([data-capacitor]) .app-tab-bar a,
  html:not([data-capacitor]) .app-tab-bar button {
    min-height: 24px !important;
    gap: 0 !important;
    padding: 0.0625rem 0.3rem !important;
    font-size: 0.55rem !important;
  }
  html:not([data-capacitor]) .app-tab-bar .tab-icon svg {
    width: 0.9rem !important;
    height: 0.9rem !important;
  }
  /* Reduce bottom spacer so timer has more visible area */
  .has-tab-bar main { padding-bottom: 4rem !important; }
  .has-tab-bar .container { padding-bottom: calc(4rem + env(safe-area-inset-bottom, 0px)) !important; }
  .has-tab-bar .web-footer { margin-bottom: calc(4rem + env(safe-area-inset-bottom, 0px)) !important; }
  /* HTML only: smaller spacer for thinner tab bar */
  html:not([data-capacitor]) .has-tab-bar main { padding-bottom: 3rem !important; }
  html:not([data-capacitor]) .has-tab-bar .container { padding-bottom: calc(3rem + env(safe-area-inset-bottom, 0px)) !important; }
  html:not([data-capacitor]) .has-tab-bar .web-footer { margin-bottom: calc(3rem + env(safe-area-inset-bottom, 0px)) !important; }
}

/* Optional: hide tab bar on desktop (add app-tab-bar-mobile-only to nav) */
@media (min-width: 769px) {
  .app-tab-bar.app-tab-bar-mobile-only {
    display: none;
  }
}
