:root {
  --md-sys-color-background: #fffbff;
  --md-sys-color-surface: #fffbff;
  --md-sys-color-surface-container: #f3edf7;
  --md-sys-color-surface-container-low: #f7f2fa;
  --md-sys-color-surface-container-high: #ece6f0;
  --md-sys-color-on-surface: #1d1b20;
  --md-sys-color-on-surface-variant: #49454f;
  --md-sys-color-outline: #79747e;
  --md-sys-color-outline-variant: #cac4d0;
  --md-sys-color-primary: #006a6a;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-primary-container: #6ff7f6;
  --md-sys-color-on-primary-container: #002020;
  --md-sys-color-secondary: #625b71;
  --md-sys-color-error: #ba1a1a;
  --md-sys-color-error-container: #ffdad6;
  --md-elevation-1: 0 1px 2px rgba(0, 0, 0, 0.12), 0 1px 3px rgba(0, 0, 0, 0.08);
  --md-elevation-2: 0 2px 6px rgba(0, 0, 0, 0.13), 0 1px 2px rgba(0, 0, 0, 0.08);
  --md-elevation-3: 0 6px 14px rgba(0, 0, 0, 0.14), 0 2px 4px rgba(0, 0, 0, 0.08);
  --focus-ring: 0 0 0 3px rgba(0, 106, 106, 0.22);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--md-sys-color-background);
  color: var(--md-sys-color-on-surface);
  font-family:
    ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei",
    sans-serif;
}

button,
input {
  font: inherit;
}

button,
a,
input {
  -webkit-tap-highlight-color: transparent;
}

.shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 32px 0;
}

.topbar,
.gallery-hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

.gallery-hero {
  align-items: center;
  min-height: 180px;
  padding: 28px;
  border-radius: 8px;
  background: var(--md-sys-color-surface-container-low);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--md-sys-color-primary);
  font-size: 13px;
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.08;
  letter-spacing: 0;
}

.hero-copy {
  max-width: 520px;
  margin: 12px 0 0;
  color: var(--md-sys-color-on-surface-variant);
  line-height: 1.6;
}

.top-actions,
.stats,
.tool-row,
.upload-actions,
.preview-actions,
.lightbox-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.top-actions {
  justify-content: flex-end;
}

.stats span {
  min-width: 72px;
  padding: 8px 12px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 8px;
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface-variant);
  text-align: center;
  font-size: 13px;
  box-shadow: var(--md-elevation-1);
}

.gallery-stats {
  justify-content: flex-end;
}

.action,
.icon-button {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--md-sys-color-outline);
  background: transparent;
  color: var(--md-sys-color-primary);
  cursor: pointer;
  text-decoration: none;
  transition:
    background-color 140ms ease,
    border-color 140ms ease,
    box-shadow 140ms ease;
}

.action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  font-weight: 650;
}

.icon-button {
  width: 40px;
  display: grid;
  place-items: center;
  font-size: 20px;
}

.action:hover,
.icon-button:hover {
  background: rgba(0, 106, 106, 0.08);
}

.action:focus-visible,
.icon-button:focus-visible,
input:focus-visible,
.crumb:focus-visible,
.gallery-card:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.action:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.action.primary {
  border-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  box-shadow: var(--md-elevation-1);
}

.action.primary:hover {
  background: #005b5b;
}

.action.danger {
  border-color: var(--md-sys-color-error-container);
  color: var(--md-sys-color-error);
}

.admin-panel,
.list-panel,
.preview {
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 8px;
  background: var(--md-sys-color-surface);
  box-shadow: var(--md-elevation-1);
  overflow: hidden;
}

.admin-panel {
  padding: 16px;
  margin-bottom: 16px;
}

.admin-login,
.upload-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.manager-tools {
  display: grid;
  gap: 14px;
}

.upload-form {
  grid-template-columns: minmax(180px, 280px) minmax(220px, 1fr) auto;
}

.admin-login label,
.upload-form label,
.search {
  display: grid;
  gap: 6px;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 13px;
  font-weight: 650;
}

.admin-login input,
.upload-form input[type="text"],
.upload-form input[type="password"],
.upload-form input[type="file"],
.search input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: 8px;
  padding: 8px 12px;
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
}

.search input::placeholder {
  color: color-mix(in srgb, var(--md-sys-color-on-surface-variant) 70%, transparent);
}

.check {
  display: inline-flex !important;
  align-items: center;
  gap: 8px !important;
  white-space: nowrap;
}

.drop-zone {
  display: grid;
  place-items: center;
  min-height: 82px;
  border: 1px dashed var(--md-sys-color-outline);
  border-radius: 8px;
  color: var(--md-sys-color-on-surface-variant);
  background: var(--md-sys-color-surface-container-low);
}

.drop-zone.dragging {
  border-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

.admin-status {
  min-height: 20px;
  margin: 12px 0 0;
  color: var(--md-sys-color-on-surface-variant);
}

.toolbar,
.gallery-toolbar {
  display: grid;
  gap: 16px;
  align-items: center;
  margin-bottom: 16px;
}

.toolbar {
  grid-template-columns: 1fr minmax(220px, 320px);
}

.gallery-toolbar {
  grid-template-columns: minmax(220px, 360px);
  justify-content: end;
}

.breadcrumbs {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.crumb {
  border: 0;
  background: transparent;
  color: var(--md-sys-color-primary);
  cursor: pointer;
  padding: 8px 10px;
  border-radius: 8px;
  font-weight: 650;
}

.crumb:hover {
  background: rgba(0, 106, 106, 0.08);
}

.separator {
  color: var(--md-sys-color-on-surface-variant);
}

.content {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  align-items: start;
}

.list-head,
.file-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 110px 150px;
  gap: 12px;
  align-items: center;
}

.list-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  color: var(--md-sys-color-on-surface-variant);
  font-size: 12px;
  font-weight: 700;
}

.file-list {
  min-height: 220px;
}

.file-row {
  width: 100%;
  min-height: 58px;
  padding: 10px 16px;
  border: 0;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.file-row:last-child {
  border-bottom: 0;
}

.file-row:hover,
.file-row:focus-visible,
.file-row.active {
  background: var(--md-sys-color-surface-container-low);
  outline: none;
}

.name-cell {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.file-icon {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-secondary);
  font-weight: 800;
  font-size: 13px;
}

.folder .file-icon {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

.file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 650;
}

.meta,
.muted,
.empty,
.loading {
  color: var(--md-sys-color-on-surface-variant);
}

.meta {
  font-size: 13px;
}

.preview {
  position: sticky;
  top: 18px;
}

.preview-box {
  min-height: 420px;
  padding: 16px;
}

.preview-title {
  margin: 0 0 14px;
  font-size: 18px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.preview-actions {
  margin-bottom: 14px;
}

.preview-media {
  width: 100%;
  max-height: 520px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 8px;
  background: var(--md-sys-color-surface-container-low);
}

img.preview-media {
  height: auto;
  object-fit: contain;
}

pre.preview-text {
  max-height: 520px;
  overflow: auto;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 8px;
  background: #1d1b20;
  color: #f7f2fa;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  align-items: stretch;
}

.gallery-card {
  min-width: 0;
  padding: 0;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 8px;
  overflow: hidden;
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  cursor: pointer;
  text-align: left;
  box-shadow: var(--md-elevation-1);
  transition:
    box-shadow 140ms ease,
    transform 140ms ease,
    border-color 140ms ease;
}

.gallery-card:hover {
  border-color: var(--md-sys-color-primary);
  box-shadow: var(--md-elevation-2);
  transform: translateY(-1px);
}

.gallery-card img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: var(--md-sys-color-surface-container);
}

.gallery-card span {
  display: block;
  min-height: 44px;
  padding: 12px;
  overflow: hidden;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 14px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty {
  display: grid;
  gap: 6px;
  justify-items: center;
  padding: 52px 16px;
  text-align: center;
}

.error {
  color: var(--md-sys-color-error);
}

.lightbox {
  width: min(1040px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  box-shadow: var(--md-elevation-3);
}

.lightbox::backdrop {
  background: rgba(29, 27, 32, 0.6);
}

.lightbox-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.lightbox-head strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lightbox img {
  display: block;
  width: 100%;
  max-height: calc(100vh - 180px);
  object-fit: contain;
  background: var(--md-sys-color-surface-container-low);
}

.lightbox-actions {
  justify-content: center;
  padding: 14px 16px 16px;
}

@media (max-width: 900px) {
  .topbar,
  .gallery-hero,
  .toolbar,
  .admin-login,
  .upload-form {
    grid-template-columns: 1fr;
  }

  .topbar,
  .gallery-hero {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions,
  .stats,
  .gallery-stats {
    justify-content: flex-start;
  }

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

  .preview {
    position: static;
  }

  .gallery-toolbar {
    justify-content: stretch;
  }
}

@media (max-width: 640px) {
  .shell {
    width: min(100vw - 20px, 1180px);
    padding: 18px 0;
  }

  .gallery-hero {
    min-height: 0;
    padding: 20px;
  }

  .top-actions {
    width: 100%;
  }

  .stats {
    width: 100%;
  }

  .stats span {
    flex: 1;
  }

  .list-head {
    display: none;
  }

  .file-row {
    grid-template-columns: 1fr;
    gap: 6px;
    min-height: 70px;
  }

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

  .lightbox-actions .action {
    flex: 1 1 120px;
  }
}

/* PicImpact-inspired gallery */
.impact-page {
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(0, 106, 106, 0.08), transparent 340px),
    var(--md-sys-color-background);
}

.impact-shell {
  width: min(1320px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 36px;
}

.impact-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  min-height: min(72vh, 720px);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 8px;
  overflow: hidden;
  background: var(--md-sys-color-surface);
  box-shadow: var(--md-elevation-2);
}

.impact-preview {
  position: relative;
  min-height: 460px;
  background: #111318;
  overflow: hidden;
}

.impact-preview img {
  width: 100%;
  height: 100%;
  min-height: 460px;
  display: block;
  object-fit: cover;
}

.impact-preview-shade {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.72), rgba(0, 0, 0, 0.18) 54%, transparent),
    linear-gradient(0deg, rgba(0, 0, 0, 0.48), transparent 52%);
}

.impact-preview-copy {
  position: absolute;
  left: clamp(20px, 5vw, 60px);
  right: clamp(20px, 5vw, 60px);
  bottom: clamp(24px, 6vw, 70px);
  color: #ffffff;
}

.impact-preview-copy h1 {
  max-width: 720px;
  font-size: clamp(42px, 8vw, 92px);
  line-height: 0.95;
}

.impact-preview-copy p:not(.impact-kicker) {
  max-width: 680px;
  margin: 16px 0 0;
  color: rgba(255, 255, 255, 0.86);
  font-size: clamp(16px, 2vw, 20px);
}

.impact-kicker {
  margin: 0 0 10px;
  color: var(--md-sys-color-primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.impact-preview-copy .impact-kicker {
  color: #7df4f0;
}

.impact-panel {
  display: grid;
  grid-template-rows: auto auto auto auto minmax(0, 1fr);
  gap: 18px;
  padding: 22px;
  border-left: 1px solid var(--md-sys-color-outline-variant);
  background: color-mix(in srgb, var(--md-sys-color-surface) 92%, white);
}

.impact-nav,
.impact-controls,
.impact-lightbox-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.impact-link,
.impact-button,
.impact-icon-button {
  min-height: 40px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 8px;
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  cursor: pointer;
  text-decoration: none;
}

.impact-link,
.impact-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  font-weight: 700;
}

.impact-button.primary {
  border-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

.impact-link:hover,
.impact-button:hover,
.impact-icon-button:hover,
.impact-thumb:hover,
.impact-card:hover {
  border-color: var(--md-sys-color-primary);
}

.impact-link:focus-visible,
.impact-button:focus-visible,
.impact-icon-button:focus-visible,
.impact-thumb:focus-visible,
.impact-card:focus-visible,
.impact-search input:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.impact-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.impact-stats span {
  min-height: 72px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 8px;
  background: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-on-surface-variant);
}

.impact-stats strong {
  color: var(--md-sys-color-on-surface);
  font-size: 28px;
}

.impact-search {
  display: grid;
  gap: 8px;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 13px;
  font-weight: 800;
}

.impact-search input {
  min-height: 44px;
  width: 100%;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
}

.impact-rail {
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-content: start;
  overflow: auto;
  padding-right: 2px;
}

.impact-thumb {
  padding: 0;
  border: 2px solid transparent;
  border-radius: 8px;
  overflow: hidden;
  background: var(--md-sys-color-surface-container-low);
  cursor: pointer;
}

.impact-thumb.active {
  border-color: var(--md-sys-color-primary);
}

.impact-thumb img {
  width: 100%;
  aspect-ratio: 1;
  display: block;
  object-fit: cover;
}

.impact-section {
  padding: 32px 0 0;
}

.impact-section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.impact-section-head h2 {
  margin: 0;
  font-size: clamp(26px, 4vw, 42px);
}

.impact-meta {
  margin: 0;
  color: var(--md-sys-color-on-surface-variant);
  font-weight: 700;
}

.impact-grid {
  columns: 4 220px;
  column-gap: 16px;
}

.impact-loading,
.impact-empty {
  padding: 44px 16px;
  color: var(--md-sys-color-on-surface-variant);
  text-align: center;
}

.impact-card {
  width: 100%;
  display: inline-grid;
  margin: 0 0 16px;
  padding: 0;
  break-inside: avoid;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 8px;
  overflow: hidden;
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  cursor: pointer;
  text-align: left;
  box-shadow: var(--md-elevation-1);
  transition:
    border-color 140ms ease,
    box-shadow 140ms ease,
    transform 140ms ease;
}

.impact-card:nth-child(3n + 1) img {
  aspect-ratio: 4 / 5;
}

.impact-card:nth-child(3n + 2) img {
  aspect-ratio: 1 / 1;
}

.impact-card:nth-child(3n) img {
  aspect-ratio: 4 / 3;
}

.impact-card:hover {
  box-shadow: var(--md-elevation-2);
  transform: translateY(-2px);
}

.impact-card img {
  width: 100%;
  display: block;
  object-fit: cover;
  background: var(--md-sys-color-surface-container-low);
}

.impact-card-info {
  display: grid;
  gap: 4px;
  padding: 12px;
}

.impact-card-info strong,
.impact-card-info small {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.impact-card-info small {
  color: var(--md-sys-color-on-surface-variant);
}

.impact-lightbox {
  width: min(1180px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  padding: 0;
  border: 0;
  border-radius: 8px;
  overflow: hidden;
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  box-shadow: var(--md-elevation-3);
}

.impact-lightbox::backdrop {
  background: rgba(17, 19, 24, 0.74);
}

.impact-lightbox-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.impact-lightbox-toolbar strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.impact-icon-button {
  width: 40px;
  display: grid;
  place-items: center;
  font-size: 24px;
}

.impact-lightbox img {
  width: 100%;
  max-height: calc(100vh - 172px);
  display: block;
  object-fit: contain;
  background: #111318;
}

.impact-lightbox-actions {
  justify-content: center;
  padding: 14px;
}

@media (max-width: 980px) {
  .impact-hero {
    grid-template-columns: 1fr;
  }

  .impact-panel {
    border-left: 0;
    border-top: 1px solid var(--md-sys-color-outline-variant);
  }

  .impact-rail {
    grid-template-columns: repeat(4, minmax(84px, 1fr));
  }
}

@media (max-width: 640px) {
  .impact-shell {
    width: min(100vw - 20px, 1320px);
    padding-top: 12px;
  }

  .impact-preview,
  .impact-preview img {
    min-height: 360px;
  }

  .impact-panel {
    padding: 16px;
  }

  .impact-stats,
  .impact-rail {
    grid-template-columns: 1fr 1fr;
  }

  .impact-section-head {
    align-items: start;
    flex-direction: column;
  }

  .impact-grid {
    columns: 1;
  }

  .impact-lightbox-actions .impact-button {
    flex: 1 1 100px;
  }
}
