/* App shell: sidebar (desktop), top bar, bottom nav (mobile) — dark theme ~#121212 */
:root {
  --shell-bg: #121212;
  --shell-surface: #1a1a1a;
  --shell-border: #2a2a2a;
  --shell-text: #f5f5f5;
  --shell-muted: #9ca3af;
  --shell-accent: #7c3aed;
  --shell-accent2: #2563eb;
}

.photoai-app {
  margin: 0;
  min-height: 100vh;
  background: var(--shell-bg);
  color: var(--shell-text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.app-layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.shell-sidebar {
  --shell-sidebar-w: 232px;
  --shell-sidebar-w-collapsed: 56px;
  width: var(--shell-sidebar-w);
  flex-shrink: 0;
  background: var(--shell-bg);
  border-right: 1px solid var(--shell-border);
  padding: 0.65rem 0.6rem 0.85rem;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  align-self: flex-start;
  min-height: 100vh;
  z-index: 200;
  overflow: hidden;
  transition: width 0.22s ease, padding 0.22s ease;
}

.shell-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
  padding: 0 0.15rem;
  min-height: 2rem;
}

.shell-sidebar-collapse {
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--shell-muted);
  cursor: pointer;
  flex-shrink: 0;
}

.shell-sidebar-collapse:hover {
  color: var(--shell-text);
  background: rgba(255, 255, 255, 0.06);
}

.shell-sidebar-collapse-icon {
  width: 1.15rem;
  height: 1.15rem;
  display: block;
}

.shell-sidebar-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--shell-muted);
  cursor: pointer;
  flex-shrink: 0;
}

.shell-sidebar-close-icon {
  width: 1.15rem;
  height: 1.15rem;
  display: block;
}

.shell-sidebar-close:hover {
  color: var(--shell-text);
  background: rgba(255, 255, 255, 0.1);
}

.shell-nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  flex: 1;
}

.shell-nav-link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.35rem 0.4rem;
  border-radius: 10px;
  color: var(--shell-text);
  text-decoration: none;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  cursor: pointer;
  min-height: 3rem;
  box-sizing: border-box;
  flex-shrink: 0;
  transition: padding 0.22s ease, gap 0.22s ease;
}

.shell-nav-link:hover:not(:disabled):not(.active) {
  background: rgba(255, 255, 255, 0.04);
}

.shell-nav-link.active {
  background: rgba(255, 255, 255, 0.07);
}

.shell-nav-link--soon {
  cursor: not-allowed;
}

.shell-nav-link--soon .shell-nav-title {
  color: #d1d5db;
}

.shell-nav-label {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
  line-height: 1.2;
  overflow: hidden;
  max-width: 11rem;
  opacity: 1;
  transition: max-width 0.22s ease, opacity 0.18s ease, flex 0.22s ease;
}

.shell-nav-title {
  font-size: 0.875rem;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.shell-nav-sub {
  font-size: 0.68rem;
  font-weight: 400;
  color: #6b7280;
  line-height: 1.2;
}

.shell-nav-icon-wrap {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.shell-nav-icon-wrap svg {
  width: 1rem;
  height: 1rem;
}

.shell-nav-icon-wrap--templates {
  background: linear-gradient(135deg, #3b82f6 0%, #6366f1 100%);
  color: #fff;
}

.shell-nav-icon-wrap--text {
  background: linear-gradient(135deg, #64748b 0%, #475569 100%);
  color: #e2e8f0;
}

.shell-nav-icon-wrap--video {
  background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
  color: #fff;
}

.shell-nav-icon-wrap--gallery {
  background: linear-gradient(135deg, #0ea5e9 0%, #2563eb 100%);
  color: #fff;
}

.shell-nav-icon-wrap--tokens {
  background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
  color: #e0f2fe;
}

.shell-sidebar-legal {
  margin-top: auto;
  padding: 0.7rem 0.35rem 0.45rem;
  border-top: 1px solid var(--shell-border);
  overflow: hidden;
  transition: max-height 0.22s ease, opacity 0.18s ease, padding 0.22s ease, margin 0.22s ease;
}

.shell-sidebar-legal-title {
  margin: 0 0 0.35rem;
  font-size: 0.68rem;
  font-weight: 500;
  color: #6b7280;
  letter-spacing: 0.01em;
}

.shell-sidebar-legal a {
  display: block;
  padding: 0.18rem 0;
  font-size: 0.72rem;
  line-height: 1.35;
  color: #9ca3af;
  text-decoration: none;
  transition: color 0.15s ease;
}

.shell-sidebar-legal a:hover {
  color: #e5e7eb;
}

.shell-sidebar-legal-group {
  margin-top: 0.2rem;
}

.shell-sidebar-legal-subtitle {
  margin: 0.25rem 0 0.12rem;
  font-size: 0.68rem;
  font-weight: 500;
  color: #6b7280;
  letter-spacing: 0.01em;
}

.shell-sidebar-legal-mail {
  font-size: 0.7rem;
  word-break: break-all;
}

.shell-sidebar-footer {
  margin-top: 0;
  padding-top: 0.55rem;
}

.shell-user-footer {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 0.25rem;
  text-decoration: none;
  color: inherit;
  border-radius: 10px;
}

.shell-user-footer--guest:hover {
  background: rgba(255, 255, 255, 0.06);
}

.shell-user-avatar {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 9px;
  background: #262626;
  border: 1px solid #333;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--shell-text);
  flex-shrink: 0;
}

.shell-user-meta {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  overflow: hidden;
  max-width: 11rem;
  opacity: 1;
  transition: max-width 0.22s ease, opacity 0.18s ease, flex 0.22s ease;
}

.shell-user-name {
  font-size: 0.8rem;
  font-weight: 500;
  color: #f3f4f6;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: -0.01em;
}

.shell-user-balance {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  font-size: 0.72rem;
  color: #9ca3af;
}

.shell-balance-icon {
  color: #38bdf8;
  flex-shrink: 0;
}

.shell-user-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  margin-top: 0.35rem;
  padding: 0 0.25rem;
  flex-wrap: nowrap;
}

.shell-user-actions .shell-token-pill--sidebar {
  font-size: 0.78rem;
  padding: 0.3rem 0.55rem;
  flex-shrink: 0;
  line-height: 1;
}

.shell-token-pill--link {
  text-decoration: none;
  color: inherit;
}

.shell-token-pill--link:hover {
  opacity: 0.85;
}

.shell-logout-link {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  margin-top: 0;
  padding: 0.3rem 0.35rem;
  border: none;
  background: transparent;
  color: #6b7280;
  font-size: 0.72rem;
  text-align: left;
  cursor: pointer;
  border-radius: 8px;
  max-height: 1.75rem;
  opacity: 1;
  overflow: hidden;
  box-sizing: border-box;
  white-space: nowrap;
  transition: max-height 0.22s ease, opacity 0.18s ease, padding 0.22s ease, color 0.15s ease;
}

.shell-logout-link:hover {
  color: #d1d5db;
}

/* Desktop: свёрнутый сайдбар — только иконки */
@media (min-width: 992px) {
  body.shell-sidebar-collapsed .shell-sidebar,
  .shell-sidebar.is-collapsed {
    width: var(--shell-sidebar-w-collapsed);
    padding-left: 0.45rem;
    padding-right: 0.45rem;
  }

  body.shell-sidebar-collapsed .shell-sidebar-head,
  .shell-sidebar.is-collapsed .shell-sidebar-head {
    justify-content: center;
    padding: 0 0.15rem;
    margin-bottom: 0.85rem;
  }

  body.shell-sidebar-collapsed .shell-nav-link,
  .shell-sidebar.is-collapsed .shell-nav-link {
    justify-content: center;
    padding: 0.35rem;
    gap: 0;
  }

  body.shell-sidebar-collapsed .shell-nav-label,
  body.shell-sidebar-collapsed .shell-user-meta,
  .shell-sidebar.is-collapsed .shell-nav-label,
  .shell-sidebar.is-collapsed .shell-user-meta {
    max-width: 0;
    opacity: 0;
    flex: 0 0 0;
  }

  body.shell-sidebar-collapsed .shell-logout-link,
  .shell-sidebar.is-collapsed .shell-logout-link {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
    padding-top: 0;
    padding-bottom: 0;
    pointer-events: none;
  }

  body.shell-sidebar-collapsed .shell-user-actions,
  .shell-sidebar.is-collapsed .shell-user-actions {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
    padding: 0;
    overflow: hidden;
    pointer-events: none;
  }

  body.shell-sidebar-collapsed .shell-nav-link.shell-sidebar-tokens-link,
  .shell-sidebar.is-collapsed .shell-nav-link.shell-sidebar-tokens-link {
    max-height: 0;
    opacity: 0;
    margin: 0;
    padding-top: 0;
    padding-bottom: 0;
    overflow: hidden;
    pointer-events: none;
  }

  body.shell-sidebar-collapsed .shell-sidebar-legal,
  .shell-sidebar.is-collapsed .shell-sidebar-legal {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
    padding-top: 0;
    padding-bottom: 0;
    border-top-color: transparent;
    pointer-events: none;
  }

  body.shell-sidebar-collapsed .shell-user-footer,
  .shell-sidebar.is-collapsed .shell-user-footer {
    justify-content: center;
    padding: 0.35rem 0;
  }

  body.shell-sidebar-collapsed .shell-sidebar-footer,
  .shell-sidebar.is-collapsed .shell-sidebar-footer {
    padding-top: 0.55rem;
    border-top: 1px solid var(--shell-border);
  }
}

/* Main column */
.shell-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.shell-menu-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--shell-text);
  cursor: pointer;
  flex-shrink: 0;
}

.shell-menu-toggle:hover {
  background: rgba(255, 255, 255, 0.1);
}

.shell-menu-toggle-icon {
  width: 1.25rem;
  height: 1.25rem;
}

.shell-sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 199;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}

.shell-sidebar-backdrop.is-visible {
  display: block;
}

body.shell-nav-open {
  overflow: hidden;
}

.shell-lang-switch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.25rem;
  padding: 0.35rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: rgba(255, 255, 255, 0.85);
  text-decoration: none;
  background: rgba(255, 255, 255, 0.08);
  border: none;
  border-radius: 8px;
  transition: background 0.15s ease, color 0.15s ease;
}

.shell-lang-switch:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
}

.shell-lang-switch-wrap {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
}

.shell-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--shell-bg);
  border-bottom: 1px solid var(--shell-border);
  position: sticky;
  top: 0;
  z-index: 50;
}

@media (min-width: 992px) {
  .shell-topbar {
    display: none;
  }

  /* Гостям — верхняя полоска с языком и «Войти» (как на десктопе) */
  .photoai-app.shell-guest .shell-topbar {
    display: flex;
    padding: 0.65rem 1.25rem;
  }

  .photoai-app.shell-guest .shell-menu-toggle {
    display: none !important;
  }

  .photoai-app.shell-guest .shell-brand-compact {
    font-size: 1.0625rem;
  }
}

.shell-brand-compact {
  font-weight: 700;
  font-size: 1rem;
}

.shell-token-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  background: #1e293b;
  border: 1px solid #334155;
  font-size: 0.85rem;
  font-weight: 600;
  color: #e2e8f0;
}

.shell-token-pill svg {
  width: 16px;
  height: 16px;
  color: #38bdf8;
  flex-shrink: 0;
}

.shell-token-pill--compact {
  font-size: 0.78rem;
}

.shell-page {
  flex: 1;
  padding: 1rem 1rem 2rem;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

@media (min-width: 992px) {
  .shell-page {
    padding: 1.5rem 1.5rem 2rem;
  }
}

/* Mobile bottom nav — отключена */
.shell-bottom-nav {
  display: none !important;
}

.shell-bottom-nav a,
.shell-bottom-nav button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.35rem;
  border: none;
  background: none;
  color: var(--shell-muted);
  font-size: 0.65rem;
  text-decoration: none;
  cursor: pointer;
  max-width: 72px;
}

.shell-bottom-nav a.active,
.shell-bottom-nav button.active {
  color: #a78bfa;
}

.shell-bottom-nav svg {
  width: 22px;
  height: 22px;
}

.shell-fab-wrap {
  position: relative;
  flex: 0 0 auto;
  width: 56px;
}

.shell-fab {
  position: absolute;
  bottom: 0.85rem;
  left: 50%;
  transform: translateX(-50%);
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--shell-accent) 0%, var(--shell-accent2) 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(124, 58, 237, 0.45);
  cursor: pointer;
  text-decoration: none;
}

.shell-fab svg {
  width: 26px;
  height: 26px;
}

@media (min-width: 992px) {
  .shell-bottom-nav {
    display: none;
  }

  .shell-sidebar {
    display: flex;
  }
}

@media (max-width: 991.98px) {
  .shell-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    min-height: 0;
    height: 100%;
    align-self: auto;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.35);
  }

  .shell-sidebar.is-open {
    transform: translateX(0);
  }
}

/* Catalog cards on dark page */
.shell-page .preset-card {
  background: var(--shell-surface);
  border-color: var(--shell-border);
}

.shell-page .preset-card-title {
  color: var(--shell-text);
}

.shell-page .preset-card-desc {
  color: var(--shell-muted);
}

.shell-page .page-title {
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.shell-page .page-sub {
  color: var(--shell-muted);
  font-size: 0.875rem;
  margin-bottom: 1.25rem;
}

/* Pagination */
.shell-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 1.5rem;
}

.shell-pagination button {
  padding: 0.45rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--shell-border);
  background: var(--shell-surface);
  color: var(--shell-text);
  cursor: pointer;
  font-size: 0.85rem;
}

.shell-pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.shell-pagination .page-info {
  color: var(--shell-muted);
  font-size: 0.85rem;
}

/* Gallery grid */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.65rem;
}

@media (min-width: 576px) {
  .gallery-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 992px) {
  .gallery-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.gallery-cell {
  position: relative;
  aspect-ratio: 1;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--shell-border);
  background: var(--shell-surface);
  padding: 0;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.gallery-cell:hover {
  border-color: #555;
  transform: scale(1.02);
}

.gallery-cell:focus-visible {
  outline: 2px solid var(--shell-accent, #7c3aed);
  outline-offset: 2px;
}

.gallery-cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  user-select: none;
  pointer-events: none;
}

/* Preset cost badge */
.preset-token-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.7rem;
  font-weight: 600;
  color: #38bdf8;
  margin-top: 0.35rem;
}

/* Первый визит: подсказка про дневные токены */
.shell-token-notice {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 1rem;
  z-index: 110;
  width: calc(100% - 2rem);
  max-width: 440px;
  padding: 0;
  margin: 0;
  border: none;
  background: transparent;
  pointer-events: none;
}

.shell-token-notice-inner {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 1rem 1.15rem;
  border-radius: 16px;
  background: linear-gradient(145deg, #252530 0%, #1a1a22 100%);
  border: 1px solid var(--shell-border);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(124, 58, 237, 0.15);
  animation: shell-token-notice-in 0.35s ease-out;
}

@keyframes shell-token-notice-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.shell-token-notice-title {
  display: block;
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
  color: var(--shell-text);
}

.shell-token-notice-text {
  font-size: 0.875rem;
  line-height: 1.45;
  color: var(--shell-muted);
  margin: 0;
}

.shell-token-notice-text strong {
  color: #7dd3fc;
  font-weight: 600;
}

.shell-token-notice-btn {
  align-self: flex-end;
  border: none;
  border-radius: 12px;
  padding: 0.5rem 1.1rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, var(--shell-accent) 0%, var(--shell-accent2) 100%);
}

.shell-token-notice-btn:hover {
  filter: brightness(1.08);
}

@media (max-width: 991.98px) {
  .shell-token-notice {
    bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  }
}

.shell-user-card--guest {
  padding: 0.25rem 0;
}

.shell-login-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 0.55rem 1rem;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  color: #fff;
  background: linear-gradient(135deg, var(--shell-accent) 0%, var(--shell-accent2) 100%);
}

.shell-login-btn:hover {
  color: #fff;
  filter: brightness(1.06);
}

.shell-top-login {
  font-size: 0.875rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9) !important;
  white-space: nowrap;
}

.shell-top-login:hover {
  color: #fff !important;
}

.photoai-app.shell-guest .shell-topbar #shellTopToken {
  display: inline-flex;
  align-items: center;
}

.auth-required-banner {
  border-radius: 12px;
}
