/* assets/css/layout.css - Adaptive Mobile-First Layout */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  font-family: var(--font-main);
  background-color: var(--bg-page);
  color: var(--text-primary);
  scroll-behavior: smooth;
}

body {
  min-height: 100dvh;
  margin: 0;
  background-color: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.45;
  font-size: var(--fs-body);
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* App Shell Structure */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  width: 100%;
  position: relative;
}

/* Top App Bar (48px mobile, 52px desktop) */
.top-appbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--h-appbar);
  padding-top: env(safe-area-inset-top, 0px);
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-inline: var(--sp-4);
  gap: var(--sp-3);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.top-appbar-left, .top-appbar-right {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.brand-badge {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  text-decoration: none;
  color: var(--text-primary);
}

.brand-logo-icon {
  width: 28px;
  height: 28px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: var(--r-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-weight: 700;
  font-size: 14px;
}

.brand-title {
  font-size: var(--fs-title);
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: var(--fs-caption);
  color: var(--text-secondary);
  font-weight: 400;
  display: none;
}

/* Portal Mode Switcher in Header */
.portal-switcher {
  display: flex;
  align-items: center;
  background: var(--bg-sunken);
  border: 1px solid var(--border-line);
  border-radius: var(--r-full);
  padding: 2px;
  gap: 2px;
}

.portal-tab-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: var(--fs-caption);
  font-weight: 500;
  padding: 4px 10px;
  border-radius: var(--r-full);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--tr-fast);
  white-space: nowrap;
}

.portal-tab-btn.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

/* Main Content Wrapper */
.main-layout {
  display: flex;
  flex: 1;
  width: 100%;
}

.sidebar-nav {
  display: none; /* Hidden on mobile */
}

.content-body {
  flex: 1;
  width: 100%;
  max-width: 1280px;
  margin-inline: auto;
  padding: var(--sp-3) var(--sp-4);
  padding-bottom: calc(var(--h-bottomnav) + var(--sp-6) + env(safe-area-inset-bottom, 0px));
}

/* Bottom Navigation Bar (Phones only, < 600px) */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  height: calc(var(--h-bottomnav) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-line);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: center;
  justify-items: center;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.04);
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding-top: 4px;
  transition: color var(--tr-fast);
  text-decoration: none;
}

.bottom-nav-item svg {
  width: 22px;
  height: 22px;
  margin-bottom: 2px;
}

.bottom-nav-item span {
  font-size: 11px;
  font-weight: 500;
  line-height: 1;
}

.bottom-nav-item.active {
  color: var(--primary);
}

.bottom-nav-item.active svg {
  stroke: var(--primary);
}

/* Network Status & PWA Install Banner */
.network-status-bar {
  background: var(--warning-subtle, #fef3c7);
  color: var(--warning, #b45309);
  border-bottom: 1px solid var(--border-line);
  font-size: 12px;
  font-weight: 600;
  padding: 6px var(--sp-4);
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  position: sticky;
  top: var(--h-appbar);
  z-index: 49;
}

.network-status-bar.online {
  background: var(--success-subtle, #dcfce7);
  color: var(--success, #15803d);
}

.pwa-install-banner {
  background: linear-gradient(135deg, rgba(13, 148, 136, 0.08), rgba(249, 115, 22, 0.08));
  border: 1px solid var(--primary-border, rgba(13, 148, 136, 0.2));
  border-radius: var(--r-md);
  margin: var(--sp-3) var(--sp-4) var(--sp-2);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  animation: toast-in 0.3s ease-out;
}

.pwa-install-banner-text {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text-primary);
}

.pwa-install-banner-icon {
  width: 36px;
  height: 36px;
  background: var(--primary);
  color: #fff;
  border-radius: var(--r-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.pwa-install-banner-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Tablet Rail Navigation (600px to 839px) */
@media (min-width: 600px) {
  .brand-sub {
    display: inline-block;
  }

  .bottom-nav {
    display: none !important;
  }

  .content-body {
    padding-bottom: var(--sp-6);
  }

  .sidebar-nav {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 60px;
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border-line);
    padding-top: var(--sp-4);
    gap: var(--sp-2);
    position: sticky;
    top: var(--h-appbar);
    height: calc(100dvh - var(--h-appbar));
  }

  .nav-rail-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: var(--r-md);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--tr-fast);
    text-decoration: none;
  }

  .nav-rail-item:hover {
    background-color: var(--bg-sunken);
    color: var(--text-primary);
  }

  .nav-rail-item.active {
    background-color: var(--primary-subtle);
    color: var(--primary);
  }
}

/* Desktop Sidebar (≥ 840px) */
@media (min-width: 840px) {
  .content-body {
    padding: var(--sp-4) var(--sp-6);
    padding-bottom: var(--sp-8);
  }

  .sidebar-nav {
    width: 220px;
    align-items: stretch;
    padding: var(--sp-4) var(--sp-3);
  }

  .nav-rail-item {
    flex-direction: row;
    justify-content: flex-start;
    width: 100%;
    height: 40px;
    padding-inline: var(--sp-3);
    gap: var(--sp-3);
    border-radius: var(--r-sm);
  }

  .nav-rail-item span {
    font-size: var(--fs-small);
    font-weight: 500;
    display: block;
  }
}

@media (max-width: 839px) {
  .nav-rail-item span {
    display: none;
  }
}

/* Mobile & Desktop Utility Classes */
@media (max-width: 600px) {
  .hide-mobile {
    display: none !important;
  }
}

@media (min-width: 601px) {
  .show-mobile-only {
    display: none !important;
  }
}
