#app-root {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  background-color: var(--bg-primary);
}

/* ================= TOP HEADER ================= */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  padding-top: var(--safe-top);
  background: var(--bg-glass);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 40;
  box-sizing: border-box;
}

.app-header-bar {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  width: 100%;
  box-sizing: border-box;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-title-box {
  display: flex;
  flex-direction: column;
}

.header-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.2px;
  line-height: 1.2;
}

.header-subtitle {
  font-size: 11px;
  color: var(--gold-light);
  font-weight: 500;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.avatar-badge {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-full);
  background: var(--gold-gradient);
  color: #000;
  font-size: 13px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(212, 175, 55, 0.3);
}

@keyframes spin-refresh {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.spin-active {
  animation: spin-refresh 0.75s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  color: var(--gold-primary) !important;
}

/* ================= SEARCH BAR ================= */
.search-container {
  position: fixed;
  top: calc(52px + var(--safe-top));
  left: 0;
  right: 0;
  width: 100%;
  padding: 0 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  z-index: 39;
  transition: max-height 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease, padding 0.3s ease;
  box-sizing: border-box;
}

.search-container.active {
  max-height: 64px;
  opacity: 1;
  padding: 8px 16px;
}

.search-container.active ~ .main-content {
  top: calc(52px + 54px + var(--safe-top));
}

.search-input-wrapper {
  display: flex;
  align-items: center;
  background: var(--bg-surface);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-full);
  padding: 6px 14px;
  gap: 8px;
}

.search-input-wrapper input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 14px;
  width: 100%;
}

.search-input-wrapper input::placeholder {
  color: var(--text-muted);
}

/* ================= MAIN SCROLL AREA ================= */
.main-content {
  position: fixed;
  top: calc(52px + var(--safe-top));
  bottom: calc(50px + var(--safe-bottom));
  left: 0;
  right: 0;
  width: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  box-sizing: border-box;
  z-index: 10;
  transition: top 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Pull to refresh spinner */
.ptr-indicator {
  height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gold-primary);
  font-size: 12px;
  font-weight: 600;
  transition: height 0.2s ease;
}

.ptr-indicator.visible {
  height: 48px;
}

/* ================= FLOATING ACTION BUTTON (COMPOSE) ================= */
.fab-compose {
  position: fixed;
  right: 20px;
  bottom: calc(66px + var(--safe-bottom));
  width: 54px;
  height: 54px;
  border-radius: var(--radius-full);
  background: var(--gold-gradient);
  color: #000000;
  box-shadow: 0 6px 20px rgba(212, 175, 55, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 45;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.fab-compose:active {
  transform: scale(0.92);
}

/* ================= BOTTOM TAB BAR ================= */
.app-tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  padding-bottom: var(--safe-bottom);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  background: var(--bg-glass);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  border-top: 1px solid var(--border-subtle);
  z-index: 50;
  box-sizing: border-box;
}

.app-tab-bar-inner {
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  width: 100%;
  box-sizing: border-box;
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  height: 100%;
  position: relative;
}

.tab-item.active {
  color: var(--gold-primary);
}

.tab-item svg {
  width: 22px;
  height: 22px;
}

.tab-badge {
  position: absolute;
  top: 6px;
  right: 28%;
}

/* ================= DRAWER & MODAL SHELLS ================= */
.drawer-backdrop, .modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.35s;
}

.drawer-backdrop.active, .modal-backdrop.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.drawer-content {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 84%;
  max-width: 320px;
  background: #0d0d12;
  border-right: 1px solid var(--border-card);
  box-shadow: 12px 0 40px rgba(0, 0, 0, 0.85);
  transform: translateX(-100%);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.drawer-backdrop.active .drawer-content {
  transform: translateX(0);
}

/* Fullscreen modal for Reader / Composer */
.fullscreen-modal {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  z-index: 120;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease, visibility 0.35s;
  overflow: hidden;
}

.fullscreen-modal.active {
  transform: translateY(0);
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
