/*
 * Responsive compatibility layer for the admin, editor and user portals.
 * This file intentionally changes layout only. Routes, requests, fields,
 * permissions and submission behaviour remain owned by the application bundle.
 */

:root {
  --app-mobile-header-height: 3rem;
  --app-mobile-nav-height: 3.5rem;
  --app-mobile-gutter: 0.75rem;
}

html {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  overflow-x: clip;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body,
#root {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 100%;
  overflow-x: hidden;
  overflow-x: clip;
}

#root,
main,
.main-layout,
.content-area,
.page-wrapper,
.page-content {
  min-width: 0;
}

img,
video,
canvas,
iframe,
svg {
  max-width: 100%;
}

img,
video {
  height: auto;
}

button,
a,
input,
select,
textarea,
label {
  touch-action: manipulation;
}

.rich-text-content,
.rich-text-editor,
.prose,
td,
th {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.overflow-x-auto {
  overscroll-behavior-inline: contain;
  -webkit-overflow-scrolling: touch;
}

@media (hover: none) {
  .card:hover,
  .btn-primary:hover {
    transform: none;
  }
}

/*
 * Phones and tablets use the dedicated mobile shell. 1024px and above keep the
 * desktop shell, with a compact sidebar until there is room for its labels.
 */
@media (max-width: 1023px) {
  .mobile-app-layout {
    width: 100%;
    min-width: 0;
    min-height: 100dvh;
    overflow-x: hidden;
  }

  .mobile-topbar {
    padding-top: env(safe-area-inset-top, 0px);
  }

  .mobile-topbar > div > div {
    min-width: 0;
  }

  .mobile-topbar > div > div:first-child > span:last-child {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-topbar button {
    width: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0 !important;
  }

  .mobile-content,
  .safe-area-top + main {
    width: 100%;
    min-width: 0;
    padding-top:
      calc(
        var(--app-mobile-header-height) +
        env(safe-area-inset-top, 0px)
      ) !important;
    padding-bottom:
      calc(
        var(--app-mobile-nav-height) +
        0.75rem +
        env(safe-area-inset-bottom, 0px)
      ) !important;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
  }

  .mobile-content-inner,
  .safe-area-top + main > div {
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }

  .mobile-page-content > [class~="w-full"][class~="px-4"],
  .mobile-page-content > [class~="w-full"][class~="px-6"],
  .mobile-page-content > [class~="w-full"][class~="px-8"] {
    padding-right: 0 !important;
    padding-left: 0 !important;
  }

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

  .mobile-bottom-nav > div {
    min-height: var(--app-mobile-nav-height);
  }

  .mobile-bottom-nav a,
  .mobile-bottom-nav button {
    min-width: 0;
    min-height: var(--app-mobile-nav-height);
  }

  .mobile-bottom-nav a > span,
  .mobile-bottom-nav button > span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .more-menu-content {
    max-height:
      calc(
        82dvh -
        env(safe-area-inset-top, 0px)
      ) !important;
  }

  .more-menu-content > div:last-child {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .more-menu-content a {
    min-width: 0;
    min-height: 5rem;
  }

  .mobile-page-content :where(
    input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
    select,
    textarea
  ),
  .modal-panel :where(
    input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
    select,
    textarea
  ),
  .modal-content :where(
    input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
    select,
    textarea
  ) {
    max-width: 100%;
    min-height: 44px;
    font-size: 16px;
  }

  .mobile-page-content :where(button, [role="button"]),
  .modal-panel :where(button, [role="button"]),
  .modal-content :where(button, [role="button"]) {
    min-height: 44px;
  }

  .mobile-page-content a[class*="inline-flex"],
  .modal-panel a[class*="inline-flex"],
  .modal-content a[class*="inline-flex"] {
    min-height: 44px;
  }

  .mobile-page-content :where(.min-w-0, .flex-1),
  .modal-panel :where(.min-w-0, .flex-1) {
    min-width: 0;
  }

  .mobile-page-content :where(
    .truncate,
    [class*="line-clamp-"]
  ) {
    max-width: 100%;
  }

  .mobile-page-content :where(.overflow-x-auto, .overflow-x-scroll) {
    max-width: 100%;
    overflow-x: auto !important;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
  }

  .mobile-page-content .overflow-hidden:has(> table) {
    max-width: 100%;
    overflow-x: auto !important;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
  }

  .mobile-page-content table {
    width: max-content;
    min-width: 100%;
    border-collapse: collapse;
  }

  .mobile-page-content table th,
  .mobile-page-content table td {
    white-space: nowrap;
  }

  .mobile-page-content pre,
  .mobile-page-content code {
    max-width: 100%;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
  }

  .mobile-page-content main .fixed.bottom-0,
  .mobile-page-content .fixed.bottom-0 {
    bottom:
      calc(
        var(--app-mobile-nav-height) +
        env(safe-area-inset-bottom, 0px)
      ) !important;
  }

  .mobile-page-content
    [class~="fixed"][class~="bottom-14"][class~="left-0"][class~="right-0"] {
    bottom:
      calc(
        var(--app-mobile-nav-height) +
        env(safe-area-inset-bottom, 0px)
      ) !important;
  }

  .mobile-page-content [aria-label="任务详情与要求"] {
    max-height: none !important;
    overflow-y: visible !important;
  }

  /*
   * All current React portals use these shared modal classes. Keep the shell
   * inside the visual viewport and let the panel itself scroll.
   */
  .modal-shell,
  .modal-overlay {
    align-items: center !important;
    padding:
      calc(0.5rem + env(safe-area-inset-top, 0px))
      0.5rem
      calc(0.5rem + env(safe-area-inset-bottom, 0px)) !important;
  }

  .modal-panel,
  .modal-content {
    width: 100% !important;
    max-width: calc(100vw - 1rem) !important;
    max-height:
      calc(
        100dvh -
        1rem -
        env(safe-area-inset-top, 0px) -
        env(safe-area-inset-bottom, 0px)
      ) !important;
    border-radius: 0.875rem !important;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .modal-panel.flex {
    overflow: hidden;
  }

  .modal-panel.flex > :where(div, section, form) {
    min-width: 0;
  }

  .modal-panel :where(img, video, iframe) {
    max-width: 100%;
  }

  .modal-panel iframe {
    min-height: min(55dvh, 32rem);
  }

  /*
   * Three legacy dialogs are still built with inline styles rather than the
   * shared modal classes. These selectors only constrain their presentation.
   */
  body > div[style*="position: fixed"][style*="z-index: 1000"],
  body > div[style*="position:fixed"][style*="z-index:1000"] {
    align-items: center !important;
    padding:
      calc(0.5rem + env(safe-area-inset-top, 0px))
      0.5rem
      calc(0.5rem + env(safe-area-inset-bottom, 0px)) !important;
    overflow-y: auto !important;
  }

  body > div[style*="position: fixed"][style*="z-index: 1000"] > div,
  body > div[style*="position:fixed"][style*="z-index:1000"] > div {
    width: 100% !important;
    max-width: calc(100vw - 1rem) !important;
    max-height:
      calc(
        100dvh -
        1rem -
        env(safe-area-inset-top, 0px) -
        env(safe-area-inset-bottom, 0px)
      ) !important;
    padding: 1rem !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
  }

  body > div[style*="position: fixed"][style*="z-index: 1000"]
    :where(
      input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
      select,
      textarea
    ),
  body > div[style*="position:fixed"][style*="z-index:1000"]
    :where(
      input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
      select,
      textarea
    ) {
    max-width: 100%;
    min-height: 44px;
    font-size: 16px !important;
  }

  body > div[style*="position: fixed"][style*="z-index: 1000"] button,
  body > div[style*="position:fixed"][style*="z-index:1000"] button {
    min-height: 44px;
  }

  body > div[style*="position: fixed"][style*="z-index: 1000"] table,
  body > div[style*="position:fixed"][style*="z-index:1000"] table {
    display: block;
    width: max-content !important;
    min-width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
  }

  body > div[class~="fixed"][class~="inset-0"][class~="z-50"] {
    padding:
      calc(0.5rem + env(safe-area-inset-top, 0px))
      0.5rem
      calc(0.5rem + env(safe-area-inset-bottom, 0px)) !important;
    overflow-y: auto !important;
  }

  body > div[class~="fixed"][class~="inset-0"][class~="z-50"] > div {
    max-width: calc(100vw - 1rem);
    max-height:
      calc(
        100dvh -
        1rem -
        env(safe-area-inset-top, 0px) -
        env(safe-area-inset-bottom, 0px)
      );
  }
}

@media (max-width: 767px) {
  :root {
    --app-mobile-gutter: 0.75rem;
  }

  .mobile-content-inner {
    padding: var(--app-mobile-gutter) !important;
  }

  .mobile-page-content :where(.p-12, .p-10, .p-8, .p-6),
  .modal-panel:where(.p-12, .p-10, .p-8, .p-6),
  .modal-content {
    padding: 1rem !important;
  }

  .mobile-page-content :where(.px-12, .px-10, .px-8, .px-6) {
    padding-right: 1rem !important;
    padding-left: 1rem !important;
  }

  .mobile-page-content :where(.py-12, .py-10, .py-8, .py-6) {
    padding-top: 1rem !important;
    padding-bottom: 1rem !important;
  }

  .mobile-page-content :where(.gap-8, .gap-6) {
    gap: 1rem !important;
  }

  .mobile-page-content :where(.mb-10, .mb-8) {
    margin-bottom: 1.25rem !important;
  }

  .mobile-page-content .text-4xl {
    font-size: clamp(1.75rem, 8vw, 2rem) !important;
    line-height: 1.15 !important;
  }

  .mobile-page-content .text-3xl {
    font-size: clamp(1.375rem, 7vw, 1.625rem) !important;
    line-height: 1.2 !important;
  }

  .mobile-page-content .text-2xl {
    font-size: clamp(1.2rem, 6vw, 1.5rem) !important;
    line-height: 1.25 !important;
  }

  .mobile-page-content :where(.rounded-\[2rem\], .rounded-3xl) {
    border-radius: 1rem !important;
  }

  .mobile-page-content .grid-cols-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .mobile-page-content [class~="grid-cols-[1fr_1fr_auto]"],
  .mobile-page-content [class~="grid-cols-[1fr_160px_130px_140px_110px]"],
  .mobile-page-content [class~="grid-cols-[1fr_160px]"] {
    grid-template-columns: minmax(0, 1fr) !important;
    align-items: stretch !important;
    gap: 0.75rem !important;
  }

  .mobile-page-content
    [class~="grid-cols-[1fr_160px_130px_140px_110px]"]:first-child {
    display: none !important;
  }

  .mobile-page-content
    [class~="grid-cols-[1fr_160px_130px_140px_110px]"]
    .text-right {
    text-align: left !important;
  }

  .mobile-page-content [style*="grid-template-columns: 1fr 1fr"],
  .mobile-page-content [style*="grid-template-columns:1fr 1fr"],
  .mobile-page-content [style*="grid-template-columns: 150px 1fr auto"],
  .mobile-page-content [style*="grid-template-columns:150px 1fr auto"] {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .mobile-page-content [style*="grid-template-columns: repeat(5"],
  .mobile-page-content [style*="grid-template-columns:repeat(5"] {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .mobile-page-content [style*="grid-template-columns: repeat(3"],
  .mobile-page-content [style*="grid-template-columns:repeat(3"],
  body > div[style*="position: fixed"][style*="z-index: 1000"]
    [style*="grid-template-columns: repeat(3"],
  body > div[style*="position:fixed"][style*="z-index:1000"]
    [style*="grid-template-columns:repeat(3"] {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .mobile-page-content
    .flex.items-center.justify-between:has(h1, h2, h3, h4) {
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  .mobile-page-content
    .flex.items-start.justify-between:has(h1, h2, h3, h4) {
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  .mobile-page-content :where(.w-\[calc\(100vw-2rem\)\], .max-w-\[95vw\]) {
    width: 100% !important;
    max-width: 100% !important;
  }

  .mobile-page-content :where(.h-\[240px\], .h-\[260px\]) {
    height: clamp(11rem, 55vw, 15rem) !important;
  }

  .mobile-page-content :where(.min-h-\[400px\], .min-h-\[320px\]) {
    min-height: min(60dvh, 22rem) !important;
  }

  .auth-layout {
    min-height: 100dvh;
    padding:
      max(0.75rem, env(safe-area-inset-top, 0px))
      0.75rem
      max(0.75rem, env(safe-area-inset-bottom, 0px)) !important;
  }

  .auth-container {
    width: 100%;
    max-width: 100%;
  }

  .auth-card {
    width: 100%;
    max-width: 100%;
    padding: 1.25rem !important;
  }
}

@media (max-width: 479px) {
  .mobile-page-content .grid-cols-3 {
    gap: 0.5rem !important;
  }

  .mobile-page-content .grid-cols-3 > * {
    min-width: 0;
  }

  .mobile-page-content .grid-cols-3 :where(.text-2xl, .text-3xl) {
    font-size: 1.125rem !important;
  }

  .mobile-page-content :where(.flex-row) {
    min-width: 0;
  }

  .modal-panel :where(.grid-cols-3, .grid-cols-4) {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

@media (max-width: 480px), (max-height: 600px) {
  [aria-label="素材预览"] .bg-gray-950 {
    height: min(42dvh, 220px) !important;
  }

  [aria-label="ZIP 素材文件预览"] .bg-gray-100 {
    height: min(42dvh, 220px) !important;
  }
}

@media (max-width: 359px) {
  :root {
    --app-mobile-gutter: 0.625rem;
  }

  .more-menu-content > div:last-child {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 0.625rem !important;
  }

  .mobile-bottom-nav a,
  .mobile-bottom-nav button {
    padding-right: 0.125rem;
    padding-left: 0.125rem;
  }

  .mobile-bottom-nav a > span,
  .mobile-bottom-nav button > span {
    font-size: 9px;
  }

  .mobile-page-content .grid-cols-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .mobile-page-content .grid-cols-2:has(
      input,
      select,
      textarea,
      button.w-full
    ) {
    grid-template-columns: minmax(0, 1fr) !important;
  }
}

/*
 * 1024–1279px is too narrow for a 256px sidebar plus lg multi-column pages.
 * Keep the existing compact icon sidebar until a 1280px desktop is available.
 */
/*
 * Desktop shell guardrails.
 *
 * The navigation rail is fixed, so the content column must consume the exact
 * remaining viewport width at every desktop size. Keep inner max-width
 * utilities intact: they are intentional reading-width constraints and must
 * not be allowed to limit the application shell itself.
 */
@media (min-width: 1024px) {
  html,
  body,
  #root,
  .main-layout {
    width: 100%;
    max-width: none;
  }

  #root,
  .main-layout {
    min-height: 100dvh;
  }

  .main-layout {
    --app-desktop-sidebar-width: 16rem;
  }

  .main-layout,
  .content-area,
  .top-bar,
  .page-wrapper,
  .page-content {
    min-width: 0;
  }

  .main-layout > aside {
    width: var(--app-desktop-sidebar-width);
    max-width: var(--app-desktop-sidebar-width);
    flex-shrink: 0;
  }

  .content-area {
    flex: 0 0 calc(100% - var(--app-desktop-sidebar-width));
    width: calc(100% - var(--app-desktop-sidebar-width));
    max-width: calc(100% - var(--app-desktop-sidebar-width));
    margin-left: var(--app-desktop-sidebar-width);
  }

  .top-bar,
  .page-wrapper,
  .page-content {
    width: 100%;
    max-width: none;
  }

  .page-content :where(.overflow-x-auto, .overflow-x-scroll),
  .page-content .overflow-hidden:has(> table) {
    max-width: 100%;
    overflow-x: auto !important;
    overscroll-behavior-inline: contain;
  }

  .page-content .overflow-hidden > table {
    min-width: max(100%, 60rem);
  }
}

@media (min-width: 1024px) and (max-width: 1279px) {
  .main-layout {
    --app-desktop-sidebar-width: 5rem;
  }

  .main-layout > aside {
    width: 5rem !important;
  }

  .content-area {
    margin-left: 5rem !important;
  }

  .main-layout > aside .lg\:block {
    display: none !important;
  }

  .main-layout > aside nav a,
  .main-layout > aside > div:first-child {
    justify-content: center !important;
  }

  .main-layout .page-wrapper .page-content {
    padding: 1.25rem !important;
  }

  .top-bar {
    padding-right: 1rem !important;
    padding-left: 1rem !important;
  }

  .page-content
    .flex.items-center.justify-between:has(h1, h2, h3) {
    flex-wrap: wrap;
    gap: 0.75rem;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .modal-shell,
  .modal-overlay {
    align-items: flex-start !important;
  }

  .modal-panel,
  .modal-content {
    max-height:
      calc(
        100dvh -
        0.75rem -
        env(safe-area-inset-top, 0px) -
        env(safe-area-inset-bottom, 0px)
      ) !important;
  }

  .more-menu-content {
    max-height: 88dvh !important;
  }
}

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

  .page-content > * {
    animation: none !important;
  }
}

/* Dedicated editor material album. The page renders every folder in editing
   order, while its card grid can expand fluidly from phones to wide desktops. */
.material-gallery-page {
  width: 100%;
  min-width: 0;
  padding: clamp(0.25rem, 1.25vw, 1.5rem);
  color: #111827;
}

.material-gallery-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.25rem;
  margin-bottom: 1rem;
  padding: clamp(1rem, 2vw, 1.5rem);
  border: 1px solid #dbeafe;
  border-radius: 1rem;
  background:
    radial-gradient(circle at 90% 10%, rgba(56, 189, 248, 0.16), transparent 34%),
    linear-gradient(135deg, #ffffff 0%, #f0f9ff 100%);
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.06);
}

.material-gallery-eyebrow,
.material-gallery-hero-actions,
.material-gallery-section-title-row,
.material-gallery-modal-meta,
.material-gallery-modal-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.material-gallery-eyebrow span {
  display: inline-flex;
  align-items: center;
  min-height: 1.75rem;
  padding: 0.25rem 0.625rem;
  border-radius: 999px;
  background: rgba(224, 242, 254, 0.85);
  color: #0369a1;
  font-size: 0.75rem;
  font-weight: 700;
}

.material-gallery-title {
  margin-top: 0.75rem;
  font-size: clamp(1.35rem, 2.3vw, 2rem);
  line-height: 1.2;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.material-gallery-subtitle {
  margin-top: 0.5rem;
  color: #64748b;
  font-size: 0.875rem;
  line-height: 1.6;
}

.material-gallery-primary-button,
.material-gallery-secondary-button {
  display: inline-flex;
  min-height: 2.75rem;
  align-items: center;
  justify-content: center;
  border-radius: 0.75rem;
  padding: 0.625rem 1rem;
  font-size: 0.8125rem;
  font-weight: 700;
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease;
}

.material-gallery-primary-button {
  border: 1px solid #111827;
  background: #111827;
  color: #fff;
}

.material-gallery-primary-button:hover {
  background: #030712;
}

.material-gallery-secondary-button {
  border: 1px solid #d1d5db;
  background: #fff;
  color: #374151;
}

.material-gallery-secondary-button:hover {
  border-color: #9ca3af;
  background: #f9fafb;
}

.material-gallery-layout {
  display: grid;
  grid-template-columns: 14rem minmax(0, 1fr);
  align-items: start;
  gap: 1rem;
  min-width: 0;
}

.material-gallery-folder-sidebar {
  position: sticky;
  top: 5rem;
  max-height: calc(100dvh - 6rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.75rem;
  border: 1px solid #e5e7eb;
  border-radius: 1rem;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.05);
}

.material-gallery-sidebar-title {
  padding: 0.375rem 0.5rem 0.625rem;
  color: #6b7280;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.material-gallery-folder-link {
  display: flex;
  width: 100%;
  min-width: 0;
  align-items: center;
  gap: 0.625rem;
  margin-top: 0.25rem;
  padding: 0.625rem;
  border-radius: 0.75rem;
  text-align: left;
  transition: background-color 160ms ease;
}

.material-gallery-folder-link:hover {
  background: #f0f9ff;
}

.material-gallery-folder-number {
  display: inline-flex;
  min-width: 1.75rem;
  height: 1.75rem;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  padding-inline: 0.4rem;
  border-radius: 0.5rem;
  background: #e0f2fe;
  color: #0369a1;
  font-size: 0.75rem;
  font-weight: 800;
}

.material-gallery-folder-name,
.material-gallery-folder-meta {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.material-gallery-folder-name {
  color: #1f2937;
  font-size: 0.8125rem;
  font-weight: 700;
}

.material-gallery-folder-meta {
  margin-top: 0.125rem;
  color: #64748b;
  font-size: 0.75rem;
}

.material-gallery-folder-chips {
  display: none;
}

.material-gallery-main,
.material-gallery-section {
  min-width: 0;
}

.material-gallery-section {
  scroll-margin-top: 5rem;
  margin-bottom: 1rem;
  padding: clamp(0.75rem, 1.4vw, 1.25rem);
  border: 1px solid #e5e7eb;
  border-radius: 1rem;
  background: #fff;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
}

.material-gallery-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.material-gallery-section-title {
  min-width: 0;
  font-size: 1rem;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.material-gallery-section-meta {
  margin-top: 0.375rem;
  color: #64748b;
  font-size: 0.75rem;
}

.material-gallery-selected-pill,
.material-gallery-card-selected,
.material-gallery-preview-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 800;
}

.material-gallery-selected-pill {
  min-height: 1.5rem;
  padding: 0.2rem 0.55rem;
  background: #dcfce7;
  color: #047857;
}

.material-gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 14rem), 1fr));
  gap: 0.875rem;
}

.material-gallery-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid #e5e7eb;
  border-radius: 0.875rem;
  background: #fff;
  box-shadow: 0 3px 12px rgba(15, 23, 42, 0.04);
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.material-gallery-card:hover {
  transform: translateY(-2px);
  border-color: #bae6fd;
  box-shadow: 0 10px 24px rgba(14, 165, 233, 0.1);
}

.material-gallery-card.is-selected {
  border-color: #34d399;
  box-shadow: 0 0 0 2px rgba(52, 211, 153, 0.16);
}

.material-gallery-media {
  position: relative;
  display: flex;
  width: 100%;
  aspect-ratio: 4 / 3;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background:
    linear-gradient(45deg, #f3f4f6 25%, transparent 25%),
    linear-gradient(-45deg, #f3f4f6 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f3f4f6 75%),
    linear-gradient(-45deg, transparent 75%, #f3f4f6 75%),
    #f8fafc;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}

.material-gallery-thumbnail {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: rgba(248, 250, 252, 0.94);
}

.material-gallery-media-fallback,
.material-gallery-media-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  color: #64748b;
  font-size: 0.75rem;
  font-weight: 700;
}

.material-gallery-media-fallback {
  position: absolute;
  inset: 0;
}

.material-gallery-text-placeholder {
  color: #047857;
}

.material-gallery-preview-badge,
.material-gallery-card-selected {
  position: absolute;
  z-index: 2;
  top: 0.625rem;
  min-height: 1.5rem;
  padding: 0.2rem 0.55rem;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.12);
}

.material-gallery-preview-badge {
  left: 0.625rem;
  background: rgba(17, 24, 39, 0.86);
  color: #fff;
}

.material-gallery-card-selected {
  right: 0.625rem;
  background: rgba(5, 150, 105, 0.94);
  color: #fff;
}

.material-gallery-card-body {
  padding: 0.75rem;
}

.material-gallery-name {
  min-height: 2.5rem;
  display: -webkit-box;
  overflow: hidden;
  color: #1f2937;
  font-size: 0.8125rem;
  font-weight: 700;
  line-height: 1.25rem;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.material-gallery-file-meta {
  margin-top: 0.35rem;
  color: #64748b;
  font-size: 0.75rem;
}

.material-gallery-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.375rem;
  margin-top: 0.75rem;
}

.material-gallery-action {
  display: inline-flex;
  min-width: 0;
  min-height: 2.75rem;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  border-radius: 0.6rem;
  padding: 0.45rem 0.35rem;
  font-size: 0.72rem;
  font-weight: 750;
  white-space: nowrap;
}

.material-gallery-action-preview {
  border: 1px solid #d1d5db;
  background: #fff;
  color: #374151;
}

.material-gallery-action-select {
  border: 1px solid #bae6fd;
  background: #f0f9ff;
  color: #0369a1;
}

.material-gallery-action-select.is-selected {
  border-color: #059669;
  background: #059669;
  color: #fff;
}

.material-gallery-action-download {
  border: 1px solid #111827;
  background: #111827;
  color: #fff;
}

.material-gallery-action:disabled {
  cursor: wait;
  opacity: 0.62;
}

.material-gallery-empty,
.material-gallery-loading {
  display: flex;
  min-height: 16rem;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  border: 1px dashed #d1d5db;
  border-radius: 1rem;
  background: #fff;
  color: #6b7280;
  text-align: center;
}

.material-gallery-preview-stage {
  position: relative;
  display: flex;
  height: clamp(15rem, 62dvh, 42rem);
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #030712;
  touch-action: pan-y;
}

.material-gallery-preview-image,
.material-gallery-preview-video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.material-gallery-preview-video {
  width: 100%;
  background: #000;
}

.material-gallery-text-preview {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: clamp(1rem, 2vw, 1.5rem);
  background: #fff;
  color: #1f2937;
  font-size: 0.875rem;
  line-height: 1.7;
  text-align: left;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  user-select: text;
}

.material-gallery-unsupported {
  max-width: 28rem;
  padding: 1.5rem;
  color: #d1d5db;
  font-size: 0.875rem;
  text-align: center;
}

.material-gallery-arrow {
  position: absolute;
  top: 50%;
  z-index: 3;
  display: inline-flex;
  width: 3rem;
  height: 3rem;
  align-items: center;
  justify-content: center;
  transform: translateY(-50%);
  border: 1px solid #d1d5db;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.96);
  color: #000;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
  font-size: 2.25rem;
  font-weight: 800;
  line-height: 1;
}

.material-gallery-arrow-left {
  left: 1rem;
}

.material-gallery-arrow-right {
  right: 1rem;
}

.material-gallery-modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid #e5e7eb;
  background: #fff;
}

.material-gallery-modal-meta {
  min-width: 0;
  color: #6b7280;
  font-size: 0.75rem;
}

.material-gallery-modal-actions {
  flex: 0 0 auto;
}

.material-gallery-modal-select,
.material-gallery-modal-download {
  display: inline-flex;
  min-width: 9rem;
  min-height: 2.75rem;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  border-radius: 0.75rem;
  padding: 0.625rem 1rem;
  font-size: 0.8125rem;
  font-weight: 800;
}

.material-gallery-modal-select {
  border: 1px solid #bae6fd;
  background: #f0f9ff;
  color: #0369a1;
}

.material-gallery-modal-select.is-selected {
  border-color: #059669;
  background: #059669;
  color: #fff;
}

.material-gallery-folder-link:focus-visible,
.material-gallery-folder-chip:focus-visible,
.material-gallery-primary-button:focus-visible,
.material-gallery-secondary-button:focus-visible,
.material-gallery-action:focus-visible,
.material-gallery-arrow:focus-visible,
.material-gallery-modal-select:focus-visible,
.material-gallery-modal-download:focus-visible {
  outline: 3px solid #0ea5e9;
  outline-offset: 2px;
}

.material-gallery-media:focus-visible {
  outline: 3px solid #0ea5e9;
  outline-offset: -3px;
}

.material-gallery-modal-download {
  border: 1px solid #111827;
  background: #111827;
  color: #fff;
}

@media (max-width: 1279px) {
  .material-gallery-layout {
    display: block;
  }

  .material-gallery-folder-sidebar {
    display: none;
  }

  .material-gallery-folder-chips {
    position: sticky;
    top: 3rem;
    z-index: 15;
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    padding: 0.625rem;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    border: 1px solid #e5e7eb;
    border-radius: 0.875rem;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.07);
    scrollbar-width: thin;
  }

  .material-gallery-folder-chip {
    flex: 0 0 auto;
    min-height: 2.75rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid #e5e7eb;
    border-radius: 999px;
    background: #fff;
    color: #475569;
    font-size: 0.75rem;
    font-weight: 700;
    white-space: nowrap;
  }

  .material-gallery-folder-chip.is-selected {
    border-color: #6ee7b7;
    background: #ecfdf5;
    color: #047857;
  }
}

@media (min-width: 1024px) and (max-width: 1279px) {
  .material-gallery-folder-chips {
    top: 4rem;
  }

  .material-gallery-section {
    scroll-margin-top: 8rem;
  }
}

@media (max-width: 1023px) {
  .material-gallery-folder-chips {
    top: calc(3rem + env(safe-area-inset-top, 0px));
  }

  .material-gallery-section {
    scroll-margin-top: calc(7rem + env(safe-area-inset-top, 0px));
  }
}

@media (max-width: 767px) {
  .material-gallery-page {
    padding: 0;
  }

  .material-gallery-hero {
    flex-direction: column;
    gap: 1rem;
    border-radius: 0.875rem;
  }

  .material-gallery-hero-actions,
  .material-gallery-primary-button,
  .material-gallery-secondary-button {
    width: 100%;
  }

  .material-gallery-hero-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .material-gallery-folder-chips {
    top: calc(3rem + env(safe-area-inset-top, 0px));
  }

  .material-gallery-section {
    scroll-margin-top: calc(7rem + env(safe-area-inset-top, 0px));
    padding: 0.75rem;
    border-radius: 0.875rem;
  }

  .material-gallery-section-header {
    align-items: stretch;
    flex-direction: column;
    gap: 0.75rem;
  }

  .material-gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 10.5rem), 1fr));
    gap: 0.625rem;
  }

  .material-gallery-card-body {
    padding: 0.625rem;
  }

  .material-gallery-actions {
    grid-template-columns: 1fr 1fr;
  }

  .material-gallery-action-preview {
    grid-column: 1 / -1;
  }

  .material-gallery-modal .modal-panel {
    border-radius: 0.875rem;
  }

  .material-gallery-preview-stage {
    height: clamp(14rem, 55dvh, 34rem);
  }

  .material-gallery-arrow {
    width: 2.75rem;
    height: 2.75rem;
    font-size: 2rem;
  }

  .material-gallery-arrow-left {
    left: 0.5rem;
  }

  .material-gallery-arrow-right {
    right: 0.5rem;
  }

  .material-gallery-modal-footer {
    align-items: stretch;
    flex-direction: column;
    padding: 0.875rem;
  }

  .material-gallery-modal-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .material-gallery-modal-select,
  .material-gallery-modal-download {
    min-width: 0;
    width: 100%;
  }
}

@media (max-width: 420px) {
  .material-gallery-grid {
    grid-template-columns: 1fr;
  }

  .material-gallery-hero-actions {
    grid-template-columns: 1fr;
  }
}
