/* ==========================================================================
   PODEUM LAYOUT & SHELL ARCHITECTURE — RESPONSIVE WEB & MOBILE
   ========================================================================== */

#app-root {
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: var(--bg-canvas);
  position: relative;
}

/* Top Sticky Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  width: 100%;
  min-height: var(--header-height);
  height: auto;
  background: #ffffff;
  border-bottom: 1px solid var(--border-subtle);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
}

.header-container {
  width: 100%;
  max-width: var(--max-content-width);
  margin: 0 auto;
  padding: 0.65rem 1rem;
  min-height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.desktop-only {
  display: none !important;
}

.mobile-only {
  display: block;
}

@media (min-width: 860px) {
  .desktop-only {
    display: flex !important;
  }

  .mode-pill.desktop-only {
    display: inline-flex !important;
  }

  .mobile-only {
    display: none !important;
  }
}

/* Global search */
.header-search {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
  max-width: 520px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 0.25rem 0.35rem 0.25rem 0.85rem;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.header-search:focus-within {
  border-color: var(--primary-600);
  box-shadow: 0 0 0 3px var(--primary-focus-ring);
  background: #ffffff;
}

.header-search-icon {
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.header-search-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text-primary);
  outline: none;
  padding: 0.45rem 0;
}

.header-search-input::placeholder {
  color: var(--text-tertiary);
}

.header-search-submit {
  flex-shrink: 0;
  border-radius: var(--radius-full) !important;
}

.mobile-search-row {
  width: 100%;
  max-width: var(--max-content-width);
  margin: 0 auto;
  padding: 0 1rem 0.75rem 1rem;
}

.mobile-search-row .header-search {
  max-width: none;
  width: 100%;
}

.user-avatar-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-primary);
}

@media (max-width: 480px) {
  .user-avatar-label {
    display: none;
  }
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  cursor: pointer;
  flex-shrink: 0;
}

.header-logo-icon {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-weight: 900;
  font-size: 1.2rem;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.2);
}

.header-brand-text {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: #0f172a;
}

.header-brand-badge {
  font-size: 0.65rem;
  background: var(--primary-50);
  color: var(--primary-700);
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-full);
  font-weight: 700;
  border: 1px solid var(--primary-100);
  display: none;
}

@media (min-width: 640px) {
  .header-brand-badge {
    display: inline-block;
  }
}

/* Desktop Navigation Menu (>= 860px) */
.desktop-nav-links {
  display: none;
  align-items: center;
  gap: 0.2rem;
  flex-shrink: 0;
}

@media (min-width: 860px) {
  .desktop-nav-links {
    display: flex;
  }
}

.desktop-nav-link {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.5rem 0.7rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.desktop-nav-link:hover {
  color: var(--text-primary);
  background: var(--bg-subtle);
}

.desktop-nav-link.active {
  color: var(--primary-700);
  background: var(--primary-50);
  font-weight: 700;
}

.desktop-nav-link.sell-btn {
  color: var(--success-700);
  background: var(--success-50);
  border: 1px solid var(--success-border);
}

.desktop-nav-link.sell-btn:hover {
  background: var(--success-100);
}

.nav-more {
  position: relative;
}

.nav-more-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.35rem;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.nav-more-menu[hidden] {
  display: none !important;
}

.nav-more-item {
  text-align: left;
  background: transparent;
  border: none;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}

.nav-more-item:hover,
.nav-more-item.active {
  background: var(--primary-50);
  color: var(--primary-700);
}

/* Header Right Actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-shrink: 0;
}

.mode-pill {
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  border: 1px solid var(--border-subtle);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.mode-pill.live {
  background: var(--success-50);
  border-color: var(--success-border);
  color: var(--success-700);
}

.mode-pill.mock {
  background: var(--warning-50);
  border-color: var(--warning-border);
  color: var(--warning-700);
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: all var(--transition-fast);
}

.icon-btn:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
  border-color: var(--border-medium);
}

.icon-btn .unread-dot {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 7px;
  height: 7px;
  background: var(--primary-600);
  border-radius: 50%;
  border: 1.5px solid #ffffff;
}

/* User Avatar Dropdown CTA */
.user-avatar-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  padding: 0.25rem 0.65rem 0.25rem 0.35rem;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.user-avatar-btn:hover {
  border-color: var(--border-medium);
  background: var(--bg-subtle);
}

.user-avatar-circle {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: #ffffff;
  font-weight: 700;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Main Viewport Router Container — centered column for all pages */
.app-viewport {
  flex: 1;
  width: 100%;
  max-width: var(--max-content-width);
  margin: 0 auto;
  padding: 1.5rem 1rem calc(var(--bottom-nav-height) + 2rem) 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

@media (min-width: 768px) {
  .app-viewport {
    padding: 2.25rem 1.5rem 4rem 1.5rem;
  }
}

@media (min-width: 860px) {
  .app-viewport {
    padding-bottom: 3rem;
  }
}

.tab-view {
  display: none;
  width: 100%;
  max-width: 100%;
  margin-inline: auto;
  transform-origin: center center;
  animation: pageZoomIn 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

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

/* Keep every page section centered in the content column */
.tab-view > section {
  width: 100%;
  margin-left: auto;
  margin-right: auto;
}

/* Narrow journey pages (auth, sell, orders, chat, profile) stay centered */
.page-shell {
  width: 100%;
  max-width: 100%;
  margin-left: auto;
  margin-right: auto;
}

.page-shell-narrow {
  width: 100%;
  max-width: 820px;
  margin-left: auto;
  margin-right: auto;
}

.page-shell-form {
  width: 100%;
  max-width: 540px;
  margin-left: auto;
  margin-right: auto;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  width: 100%;
  margin-bottom: 1.25rem;
  text-align: left;
}

@media (max-width: 639px) {
  .page-header {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .page-header > div {
    width: 100%;
    text-align: center;
  }
}

@keyframes pageZoomIn {
  from {
    opacity: 0;
    transform: scale(0.985) translateY(6px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

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

/* Bottom Navigation Bar (Mobile only < 860px) — centered with content column */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--max-content-width);
  height: var(--bottom-nav-height);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 50;
  padding: 0 0.5rem;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.03);
}

/* Full-bleed bar background behind centered nav on wide phones / tablets */
.bottom-nav::before {
  content: '';
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--bottom-nav-height);
  background: rgba(255, 255, 255, 0.95);
  border-top: 1px solid var(--border-subtle);
  z-index: -1;
  pointer-events: none;
}

@media (min-width: 860px) {
  .bottom-nav {
    display: none !important;
  }
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.45rem 0.35rem;
  min-height: 48px;
  min-width: 56px;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  flex: 1;
}

.nav-item:active {
  transform: scale(0.92);
}

.nav-item svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
}

.nav-item span {
  font-size: 0.68rem;
  font-weight: 600;
  color: inherit;
}

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

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

.nav-item.sell-action {
  color: var(--success-600);
}

/* Modal Dialog & Bottom Sheet Architecture */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 100;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  animation: fadeIn 0.2s ease-out;
}

@media (min-width: 768px) {
  .drawer-backdrop {
    align-items: center;
    padding: 1.5rem;
  }
}

.drawer-backdrop.open {
  display: flex;
}

.drawer-sheet {
  width: 100%;
  max-height: 90vh;
  background: #ffffff;
  border-top: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 1.25rem 1.5rem 2.5rem 1.5rem;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl);
  overflow-y: auto;
  animation: slideUp 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (min-width: 768px) {
  .drawer-sheet {
    max-width: 680px;
    max-height: 85vh;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-subtle);
    padding: 1.75rem 2rem 2rem 2rem;
    animation: zoomModal 0.24s cubic-bezier(0.16, 1, 0.3, 1);
  }

  .drawer-handle {
    display: none;
  }
}

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

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

.drawer-handle {
  width: 40px;
  height: 5px;
  background: var(--border-medium);
  border-radius: var(--radius-full);
  margin: 0 auto 1.25rem auto;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
}

.drawer-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
}

.drawer-close {
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 1.1rem;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.drawer-close:hover {
  background: var(--bg-muted);
  color: var(--text-primary);
}

/* Toast Notifications — centered on small screens, right-aligned on desktop */
#toast-container {
  position: fixed;
  top: calc(var(--header-height) + var(--header-mobile-search) + 12px);
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  width: calc(100% - 2rem);
  max-width: 420px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.65rem;
  pointer-events: none;
}

@media (min-width: 860px) {
  #toast-container {
    top: calc(var(--header-height) + 16px);
    left: auto;
    right: 1.5rem;
    transform: none;
    width: calc(100% - 3rem);
  }
}

.toast {
  background: #ffffff;
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1.15rem;
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toastIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast-success { border-left: 4px solid var(--success-600); }
.toast-error { border-left: 4px solid var(--danger-600); }
.toast-warning { border-left: 4px solid var(--warning-600); }
.toast-info { border-left: 4px solid var(--primary-600); }

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

/* Phase 10 — skip link, safe areas, reduced motion, drawer lock */
.skip-link {
  position: absolute;
  left: 0.75rem;
  top: -3rem;
  z-index: 200;
  padding: 0.55rem 0.9rem;
  background: var(--primary-700, #0369a1);
  color: #fff;
  border-radius: var(--radius-md, 8px);
  font-weight: 700;
  font-size: 0.85rem;
  text-decoration: none;
}

.skip-link:focus {
  top: 0.75rem;
  outline: 2px solid var(--primary-300);
  outline-offset: 2px;
}

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

body.drawer-open {
  overflow: hidden;
}

.bottom-nav {
  height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.bottom-nav::before {
  height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
}

.app-viewport {
  padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px) + 1rem);
}

.icon-btn {
  min-width: 44px;
  min-height: 44px;
}

.nav-item {
  min-width: 44px;
  min-height: 48px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
