/* Layout: App Shell, Desktop Rail, Mobile Bottom Navigation, Safe Areas (UX-28) */

.shell {
  position: relative;
  width: 100%;
  min-height: 100dvh;
  margin: 0 auto;
  box-sizing: border-box;
}

.main-content {
  min-width: 0;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 0 0 calc(72px + max(var(--s-4), env(safe-area-inset-bottom)));
  display: flex;
  flex-direction: column;
  gap: 0;
  box-sizing: border-box;
}

/* App Header (Sticky, 48px, --surface-1) */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  height: 58px;
  padding: 0 var(--s-4);
  background: var(--bg);
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  position: sticky;
  top: 0;
  z-index: 50;
  box-sizing: border-box;
}

.header-date {
  font-size: var(--t-body);
  font-weight: 600;
  color: var(--text);
  font-family: var(--font-num);
  letter-spacing: -0.01em;
}

.header-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--tap);
  min-height: var(--tap);
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease),
              background-color var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease);
}

.header-icon-btn:hover,
.header-icon-btn:focus-visible {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--line);
}

.header-icon {
  width: 20px;
  height: 20px;
}

/* Desktop Rail Navigation (Hidden by default on mobile) */
.desktop-rail {
  display: none;
}

/* Mobile Bottom Navigation (Sticky, 56px + safe-area) */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 90;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  min-height: 64px;
  height: calc(64px + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface-nav);
  border-top: 1px solid var(--line);
  box-sizing: border-box;
}

.bottom-nav .nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 56px;
  min-width: var(--tap);
  background: transparent;
  border: 0;
  color: var(--text-muted);
  cursor: pointer;
  font-size: var(--t-label);
  font-weight: 600;
  text-decoration: none;
  padding: var(--s-1) 0;
  box-sizing: border-box;
  transition: color var(--dur-fast) var(--ease),
              background-color var(--dur-fast) var(--ease);
}

.bottom-nav .nav-item:hover,
.bottom-nav .nav-item:focus-visible {
  color: var(--text);
  background: var(--surface-2);
}

.bottom-nav .nav-item.active {
  color: var(--accent);
  font-weight: 600;
}

.bottom-nav .nav-item.active .nav-icon {
  stroke: var(--accent);
}

.nav-icon {
  width: 22px;
  height: 22px;
}

/* View Containers */
.app-view {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.app-view[hidden] {
  display: none !important;
}

/* View Header */
.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-4) var(--s-3);
  border-bottom: 1px solid var(--line);
}

.view-header-title h2 {
  margin: var(--s-1) 0 0;
  font-size: var(--t-h1);
  font-weight: 600;
}

/* Desktop Viewport Layout (≥1024px) */
@media (min-width: 1024px) {
  .shell {
    display: flex;
    max-width: var(--max);
    min-height: 100dvh;
  }

  .desktop-rail {
    display: flex;
    flex-direction: column;
    width: var(--rail-width);
    min-width: var(--rail-width);
    height: 100dvh;
    position: sticky;
    top: 0;
    padding: 20px 0;
    background: var(--surface-nav);
    border-right: 1px solid var(--line);
    box-sizing: border-box;
    z-index: 60;
  }

  .rail-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin-bottom: 14px;
  }

  .brand-copy {
    display: none;
  }

  .brand-name {
    display: block;
    font-size: var(--t-small);
    font-weight: 600;
    color: var(--text);
  }

  .brand-subtitle {
    display: block;
    font-size: var(--t-label);
    color: var(--text-muted);
  }

  .rail-nav {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--s-2);
    flex: 1;
  }

  .rail-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--s-1);
    min-height: 56px;
    padding: var(--s-2) var(--s-1);
    border-radius: var(--r-md);
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-muted);
    font-size: 9px;
    font-weight: 500;
    cursor: pointer;
    text-align: center;
    width: 56px;
    box-sizing: border-box;
    transition: color var(--dur-base) var(--ease),
                background-color var(--dur-base) var(--ease),
                border-color var(--dur-base) var(--ease);
  }

  .rail-nav-item:hover,
  .rail-nav-item:focus-visible {
    color: var(--text);
    background: var(--surface-2);
    border-color: var(--line);
  }

  .rail-nav-item.active {
    color: var(--accent-strong);
    background: var(--accent-wash);
    border-color: transparent;
    font-weight: 600;
  }

  .rail-nav-item.active .nav-icon {
    stroke: var(--accent-strong);
  }

  .rail-footer {
    margin-top: auto;
    border-top: 1px solid var(--line);
    padding-top: var(--s-3);
    display: flex;
    justify-content: center;
  }

  .main-content {
    flex: 1;
    max-width: none;
    padding: 0;
  }

  .app-header {
    position: static;
    min-height: 82px;
    height: 82px;
    padding: 0 var(--s-6);
  }

  .header-date {
    font-family: var(--font-display);
    font-size: var(--t-h1);
  }

  .app-view {
    padding: 22px 32px 32px;
  }

  .app-view > .view-header {
    margin: -22px -32px 0;
    padding: 20px 32px;
  }

  .bottom-nav {
    display: none;
  }
}
