.preview-nav.prev {
  left: 16px;
}

.preview-nav.next {
  right: 16px;
}

.preview-info {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  padding: 18px;
  border-left: 1px solid var(--line);
  overflow: auto;
}

.preview-close {
  align-self: flex-end;
}

.preview-close-floating {
  position: absolute;
  top: 0;
  right: 0;
  transform: translate(50%, -50%);
  z-index: 12;
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 999px;
  color: #fff;
  border-color: rgba(248, 113, 113, 0.58);
  background: rgba(239, 68, 68, 0.92);
  backdrop-filter: none;
}

.preview-close-floating .icon {
  width: 14px;
  height: 14px;
}

.preview-close-floating:hover {
  color: #fff;
  border-color: rgba(220, 38, 38, 0.9);
  background: rgba(185, 28, 28, 0.98);
}

.preview-close-on-image {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  min-width: 36px;
  padding: 0;
  box-sizing: border-box;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: #fff;
  border-color: rgba(255, 255, 255, 0.3);
  background: rgba(15, 23, 42, 0.74);
  backdrop-filter: none;
  transform: none;
  z-index: 14;
}

.preview-close-on-image .icon {
  width: 14px;
  height: 14px;
}

.preview-close-on-image:hover,
.preview-close-on-image:focus-visible {
  color: #fff;
  border-color: rgba(220, 38, 38, 0.92);
  background: rgba(220, 38, 38, 0.92);
}

.prompt-box {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 750;
  line-height: 1.65;
  white-space: pre-wrap;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(18px);
  opacity: 0;
  pointer-events: none;
  z-index: 20070;
  width: max-content;
  max-width: min(480px, calc(100vw - 32px));
  padding: 12px 18px;
  border-radius: var(--radius);
  color: var(--panel);
  background: var(--toast);
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 850;
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.preview-toast {
  position: fixed;
  top: 18px;
  left: 50%;
  bottom: auto;
  z-index: 9999;
  width: max-content;
  max-width: min(480px, calc(100% - 36px));
  transform: translateX(-50%) translateY(-14px);
}

.preview-toast.show {
  transform: translateX(-50%) translateY(0);
}

.auth-toast {
  position: fixed;
  top: 18px;
  left: 50%;
  bottom: auto;
  z-index: 10000;
  width: max-content;
  max-width: min(460px, calc(100vw - 40px));
  transform: translateX(-50%) translateY(-14px);
}

.auth-toast.show {
  transform: translateX(-50%) translateY(0);
}

.admin-toast {
  position: fixed;
  z-index: 10001;
}

@media (max-width: 1080px) {
  .sidebar {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 12px;
    padding: 10px 14px;
  }

  .header-health {
    grid-column: 1 / -1;
    justify-self: stretch;
    justify-content: center;
  }

  .nav-list {
    justify-content: flex-start;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .nav-list::-webkit-scrollbar {
    display: none;
  }

  .topbar {
    width: calc(100% - 28px);
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .page {
    width: calc(100% - 28px);
    padding: 18px 0 190px;
  }

  .home-hero {
    grid-template-columns: 1fr;
    grid-template-areas:
      "copy"
      "composer"
      "stats";
    padding: 20px;
  }

  .home-hero-copy h1 {
    max-width: 12em;
    font-size: 36px;
  }

  .create-grid-floating {
    padding-bottom: 176px;
  }

  .create-prompt-dock {
    width: min(860px, calc(100vw - 28px));
    bottom: 14px;
  }

  .hero-grid,
  .create-grid,
  .settings-grid,
  .admin-editor-grid {
    grid-template-columns: 1fr;
  }

  .my-history-section {
    grid-template-columns: 1fr;
  }

  .history-result-card {
    grid-template-columns: 1fr;
  }

  .history-result-images {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .composer-panel {
    position: static;
  }

  .preview-shell {
    grid-template-columns: 1fr;
  }

  .preview-info {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .admin-row {
    grid-template-columns: 72px minmax(0, 1fr);
  }

  .admin-row img {
    width: 72px;
  }

  .admin-row-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }
}

@media (max-width: 640px) {
  .sidebar {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .brand {
    min-width: 0;
  }

  .brand-mark {
    width: 62px;
    height: 62px;
  }

  .nav-list {
    margin: 0 -2px;
    padding-bottom: 2px;
  }

  .nav-item {
    min-height: 38px;
    padding: 0 10px;
    gap: 6px;
    font-size: 12px;
  }

  .header-health {
    overflow-x: auto;
    justify-content: flex-start;
  }

  .topbar {
    grid-template-columns: 1fr;
    width: calc(100% - 24px);
  }

  .topbar-actions {
    justify-content: space-between;
  }

  .avatar-text {
    display: none;
  }

  .page {
    width: calc(100% - 24px);
    padding-bottom: max(142px, calc(118px + env(safe-area-inset-bottom)));
  }

  .home-hero {
    padding: 14px;
    gap: 12px;
  }

  .home-hero-copy h1 {
    max-width: none;
    font-size: 28px;
  }

  .home-hero-copy p {
    font-size: 14px;
  }

  .home-quick-panel,
  .home-composer {
    padding: 12px;
  }

  .home-prompt {
    min-height: 112px;
  }

  .prompt-tip-grid,
  .home-stats,
  .composer-footer {
    grid-template-columns: 1fr;
  }

  .composer-footer {
    align-items: stretch;
  }

  .composer-footer .toolbar-row {
    width: 100%;
  }

  .create-grid-floating {
    padding-bottom: max(148px, calc(124px + env(safe-area-inset-bottom)));
  }

  .create-prompt-dock {
    width: calc(100vw - 20px);
    bottom: 10px;
  }

.create-prompt-dock.mobile-collapsed {
    width: clamp(118px, 31vw, 128px);
  }

  .create-prompt-panel {
    padding: 10px;
  }

  .prompt-input-box {
    min-height: 88px;
    gap: 8px;
    padding: 8px 10px 10px;
    border-radius: 28px;
  }

  .prompt-input-floating {
    min-height: 36px;
    max-height: 112px;
    padding: 6px 10px 2px;
    font-size: 13px;
    line-height: 1.45;
  }

  .prompt-input-hint {
    top: 14px;
    left: 20px;
    right: 22px;
    font-size: 13px;
    line-height: 1.45;
  }

.mobile-collapsed .prompt-compact {
    min-height: 76px;
    padding: 10px 14px;
  }

  .create-prompt-actions {
    position: relative;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 6px;
    padding-right: 44px;
  }

  .create-prompt-actions .toolbar-row {
    justify-content: flex-start;
  }

  .create-submit-button {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 42px;
    height: 42px;
    min-width: 42px;
    flex-basis: 42px;
  }

  .dock-control-strip {
    gap: 4px;
  }

  .dock-reference-stack {
    width: var(--dock-control-width);
    max-width: var(--dock-control-width);
    gap: 4px;
  }

  .dock-reference-stack.upload-only {
    width: var(--dock-control-width);
    max-width: var(--dock-control-width);
  }

  .dock-upload-button {
    width: var(--dock-control-width);
    min-width: var(--dock-control-width);
    min-height: 34px;
    padding: 0 10px;
    gap: 5px;
    font-size: 12px;
  }

  .dock-upload-button .icon {
    width: 14px;
    height: 14px;
  }

  .dock-reference-stack .dock-upload-button {
    width: var(--dock-control-width);
    min-width: var(--dock-control-width);
  }

  .count-stepper {
    min-height: 34px;
    gap: 3px;
    padding: 2px 2px 2px 6px;
    font-size: 11px;
  }

  .count-stepper button {
    width: 17px;
  }

  .dock-ratio-row {
    max-width: 178px;
  }

  .dock-reference-row {
    width: 100%;
    max-width: 104px;
  }

  .ratio-select-pill {
    min-height: 34px;
    padding: 0 18px 0 8px;
    font-size: 11px;
    gap: 5px;
  }

  .ratio-select-pill select {
    max-width: 54px;
  }

  .theme-toggle {
    padding: 0 8px;
  }

  .theme-toggle span {
    display: none;
  }

  .hero-banner,
  .hero-banner img {
    min-height: 292px;
  }

  .hero-copy {
    inset: auto 12px 12px 12px;
    padding: 12px;
  }

  .hero-copy h1 {
    font-size: 24px;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .category-grid,
  .gallery-grid,
  .works-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .inspiration-grid {
    column-width: 188px;
    column-gap: 14px;
  }

  .inspiration-grid .example-card {
    margin-bottom: 14px;
  }

  .preview-dialog {
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }

  .admin-dialog {
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }

  .login-dialog {
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    padding: 0;
    border: 0;
    overflow: visible;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .login-dialog .admin-editor {
    min-height: 0;
    height: auto;
    max-height: calc(100vh - 24px);
    overflow: auto;
    padding: 12px;
    width: min(420px, calc(100vw - 24px));
    border-radius: 24px;
    background: var(--panel);
    box-shadow: var(--shadow);
  }

  .preview-shell {
    min-height: 100vh;
  }

  .admin-editor {
    min-height: 100vh;
    padding: 14px;
  }

  .auth-code-row {
    grid-template-columns: 1fr;
  }

  .auth-code-row .button {
    width: 100%;
    min-width: 0;
  }

  .category-admin-grid {
    grid-template-columns: 1fr;
  }
}

.pagination-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 20px;
  margin: 16px 0;
  border-radius: var(--radius);
  background: var(--panel-strong);
}

.pagination-btn {
  min-height: 36px;
  padding: 0 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.pagination-btn:hover:not(:disabled) {
  background: var(--panel-soft);
  border-color: var(--ink-soft);
}

.pagination-btn:active:not(:disabled) {
  transform: scale(0.98);
}

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

.pagination-info {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  min-width: 120px;
  text-align: center;
}

@media (max-width: 640px) {
  .pagination-controls {
    gap: 12px;
    padding: 14px;
    margin: 12px 0;
  }

  .pagination-btn {
    min-height: 32px;
    padding: 0 12px;
    font-size: 12px;
  }

  .pagination-info {
    min-width: 100px;
    font-size: 12px;
  }
}

