:root {
  --bg: #f5faf7;
  --bg-soft: #edf5f0;
  --bg-cool: #e3eee8;
  --surface: #ffffff;
  --surface-muted: rgba(255, 255, 255, 0.72);
  --surface-raised: rgba(255, 255, 255, 0.9);
  --text: #121d1a;
  --text-muted: #63746c;
  --line: rgba(111, 143, 131, 0.22);
  --line-strong: rgba(91, 122, 110, 0.34);
  --accent: #87ad9b;
  --accent-strong: #4f7668;
  --accent-soft: #dcebe4;
  --focus: #6da88c;
  --danger: #b85c5c;
  --danger-soft: #f7eaea;
  --button-bg: #13201d;
  --button-text: #ffffff;
  --overlay: rgba(12, 22, 19, 0.48);
  --shadow: 0 22px 56px rgba(36, 60, 51, 0.12);
  --shadow-hover: 0 28px 72px rgba(36, 60, 51, 0.18);
  --radius: 18px;
  --radius-sm: 12px;
  --radius-lg: 26px;
  --motion: 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
  --sidebar: 260px;
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

html[data-theme="dark"] {
  --bg: #0d1512;
  --bg-soft: #111d19;
  --bg-cool: #172721;
  --surface: #14201c;
  --surface-muted: rgba(19, 31, 27, 0.8);
  --surface-raised: rgba(24, 39, 34, 0.92);
  --text: #eef8f2;
  --text-muted: #9eb4aa;
  --line: rgba(155, 190, 174, 0.18);
  --line-strong: rgba(175, 212, 196, 0.3);
  --accent: #93c5ad;
  --accent-strong: #b8dec9;
  --accent-soft: rgba(113, 158, 137, 0.18);
  --focus: #9fd2ba;
  --danger: #ffadad;
  --danger-soft: rgba(184, 92, 92, 0.18);
  --button-bg: #d9f0e4;
  --button-text: #0d1512;
  --overlay: rgba(4, 9, 7, 0.72);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
  --shadow-hover: 0 30px 86px rgba(0, 0, 0, 0.48);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(145deg, var(--bg) 0%, var(--bg-soft) 100%);
  color: var(--text);
  transition:
    background-color var(--motion),
    color var(--motion);
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
a,
input,
select,
textarea {
  outline-color: var(--focus);
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  display: block;
  max-width: 100%;
}

button,
a,
input,
select,
textarea,
.work-card,
.admin-section,
.admin-work-row,
.admin-folder-row,
.folder-button,
.brand-mark,
.login-card,
.lightbox-panel {
  transition:
    background-color var(--motion),
    border-color var(--motion),
    color var(--motion),
    box-shadow var(--motion),
    transform var(--motion);
}

[hidden] {
  display: none !important;
}

.admin-page:not(.is-authenticated) #adminApp {
  display: none !important;
}

.admin-page.is-authenticated #loginView {
  display: none !important;
}

.app-shell,
.admin-shell {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  min-height: 100vh;
}

.folder-sidebar,
.admin-sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 26px;
  height: 100vh;
  padding: 28px 22px;
  border-right: 1px solid var(--line);
  background:
    linear-gradient(180deg, var(--surface-muted), var(--bg-soft));
  backdrop-filter: blur(18px);
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  width: fit-content;
}

.brand-link strong,
.brand-link small {
  display: block;
}

.brand-link strong {
  font-size: 16px;
  line-height: 1.1;
}

.brand-link small {
  margin-top: 3px;
  color: var(--text-muted);
  font-size: 12px;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: linear-gradient(145deg, var(--surface), var(--accent-soft));
  color: var(--accent-strong);
  font-weight: 750;
  box-shadow: 0 10px 28px rgba(79, 118, 104, 0.12);
}

.folder-nav,
.admin-nav {
  display: grid;
  gap: 6px;
}

.folder-button,
.admin-nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  text-align: left;
}

.folder-button:hover,
.folder-button.is-active,
.admin-nav a:hover {
  border-color: var(--line);
  background: var(--surface-raised);
  color: var(--text);
  transform: translateX(3px);
}

.folder-button.is-active {
  box-shadow: 0 12px 34px rgba(79, 118, 104, 0.14);
}

.folder-count {
  min-width: 28px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--text-muted);
  font-size: 12px;
  line-height: 22px;
  text-align: center;
}

.sidebar-admin-link {
  margin-top: auto;
  color: var(--accent-strong);
  font-size: 14px;
}

.gallery-main,
.admin-main {
  min-width: 0;
  padding: 32px clamp(22px, 4vw, 58px) 64px;
}

.gallery-header,
.admin-header,
.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}

.gallery-header {
  position: sticky;
  z-index: 8;
  top: 0;
  margin: -32px calc(clamp(22px, 4vw, 58px) * -1) 24px;
  padding: 30px clamp(22px, 4vw, 58px) 22px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(18px);
}

.header-actions,
.admin-header-actions {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 12px;
}

.theme-toggle {
  position: relative;
  display: inline-grid;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background:
    radial-gradient(circle at 35% 30%, var(--accent-soft), transparent 60%),
    var(--surface-raised);
  color: var(--accent-strong);
  box-shadow: 0 14px 36px rgba(79, 118, 104, 0.14);
  cursor: pointer;
  overflow: hidden;
}

.theme-toggle:hover {
  transform: translateY(-2px) rotate(-6deg);
  border-color: var(--accent);
  box-shadow: var(--shadow-hover);
}

.theme-toggle:active {
  transform: translateY(0) scale(0.96);
}

.theme-toggle:focus-visible {
  border-color: var(--accent);
  box-shadow:
    var(--shadow),
    0 0 0 4px color-mix(in srgb, var(--accent) 30%, transparent);
}

.page-theme-toggle {
  position: fixed;
  z-index: 30;
  top: 22px;
  right: 22px;
}

.theme-icon {
  position: absolute;
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  transition:
    opacity var(--motion),
    transform var(--motion);
}

.theme-icon-sun {
  opacity: 0;
  transform: translateY(10px) rotate(90deg) scale(0.7);
}

.theme-icon-moon {
  opacity: 1;
  transform: translateY(0) rotate(0) scale(1);
}

html[data-theme="dark"] .theme-icon-sun {
  opacity: 1;
  transform: translateY(0) rotate(0) scale(1);
}

html[data-theme="dark"] .theme-icon-moon {
  opacity: 0;
  transform: translateY(-10px) rotate(-90deg) scale(0.7);
}

.section-label {
  margin: 0 0 8px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(34px, 5vw, 66px);
  font-weight: 760;
  line-height: 0.98;
  letter-spacing: 0;
}

.admin-main h1 {
  font-size: clamp(32px, 4vw, 52px);
}

h2 {
  margin-bottom: 0;
  font-size: 28px;
  line-height: 1.1;
}

h3 {
  margin-bottom: 7px;
  font-size: 17px;
  line-height: 1.25;
}

.gallery-tools,
.upload-form,
.folder-create-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 12px;
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-raised);
  color: var(--text);
  font-size: 14px;
  line-height: 1.4;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.field input,
.field select {
  padding: 0 12px;
}

.field textarea {
  min-height: 94px;
  padding: 10px 12px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow:
    0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.compact-field {
  width: min(245px, 32vw);
}

.gallery-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 10px 0 18px;
  color: var(--text-muted);
  font-size: 14px;
}

.gallery-meta span:first-child {
  color: var(--text);
  font-weight: 700;
}

.gallery-grid {
  --gallery-gap: clamp(12px, 1.1vw, 18px);
  display: block;
  column-width: clamp(230px, 18vw, 330px);
  column-gap: var(--gallery-gap);
}

.work-card {
  display: block;
  width: 100%;
  margin: 0 0 var(--gallery-gap);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-raised);
  box-shadow: var(--shadow);
  break-inside: avoid;
  cursor: pointer;
  overflow: hidden;
  page-break-inside: avoid;
  -webkit-column-break-inside: avoid;
}

.work-card:hover {
  transform: translateY(-7px) scale(1.01);
  border-color: var(--accent);
  box-shadow: var(--shadow-hover);
}

.work-card:focus-visible {
  border-color: var(--accent);
  box-shadow:
    var(--shadow-hover),
    0 0 0 4px color-mix(in srgb, var(--accent) 28%, transparent);
}

.work-media {
  position: relative;
  min-height: 210px;
  background: linear-gradient(145deg, var(--bg-cool), var(--accent-soft));
  overflow: hidden;
}

.work-media img {
  width: 100%;
  height: auto;
  transition:
    transform 420ms cubic-bezier(0.2, 0.8, 0.2, 1),
    filter var(--motion);
}

.work-card:hover .work-media img {
  transform: scale(1.035);
  filter: saturate(1.08);
}

.document-preview {
  display: grid;
  min-height: 320px;
  place-items: center;
  background:
    linear-gradient(#ffffff, #ffffff) padding-box,
    repeating-linear-gradient(
      135deg,
      var(--line) 0 8px,
      var(--bg-cool) 8px 16px
    ) border-box;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 750;
}

.work-card-body {
  padding: 16px;
}

.work-card p {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.45;
}

.work-folder {
  margin-bottom: 10px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 750;
}

.empty-state {
  max-width: 420px;
  margin: 80px auto;
  padding: 34px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-muted);
  text-align: center;
}

.empty-state p {
  color: var(--text-muted);
}

.button-link,
.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0 14px;
  font-size: 14px;
  font-weight: 750;
  cursor: pointer;
}

.button-link,
.primary-button {
  background: var(--button-bg);
  color: var(--button-text);
  box-shadow: 0 14px 32px rgba(18, 29, 26, 0.14);
}

.secondary-button {
  border-color: var(--line-strong);
  background: var(--surface-raised);
  color: var(--text);
}

.ghost-button {
  border-color: var(--line);
  background: transparent;
  color: var(--text-muted);
}

.danger-button {
  border-color: color-mix(in srgb, var(--danger) 42%, transparent);
  background: var(--danger-soft);
  color: var(--danger);
}

.icon-button {
  width: 38px;
  min-height: 38px;
  padding: 0;
  border-color: var(--line);
  background: var(--surface-raised);
  color: var(--text-muted);
}

.button-link:hover,
.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover,
.danger-button:hover,
.icon-button:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.lightbox {
  position: fixed;
  z-index: 40;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--overlay);
  backdrop-filter: blur(12px);
}

.lightbox[hidden] {
  display: none;
}

.lightbox-panel {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(280px, 0.75fr);
  width: min(1120px, 100%);
  max-height: min(820px, 92vh);
  border-radius: var(--radius);
  background: var(--surface-raised);
  box-shadow: 0 32px 80px rgba(10, 17, 22, 0.24);
  overflow: hidden;
}

.lightbox-close {
  position: absolute;
  z-index: 2;
  top: 14px;
  right: 14px;
}

.lightbox-media {
  display: grid;
  min-height: 420px;
  place-items: center;
  background: linear-gradient(145deg, var(--bg-soft), var(--bg-cool));
  overflow: auto;
}

.lightbox-media img,
.lightbox-media iframe {
  width: 100%;
  height: 100%;
  max-height: 820px;
  object-fit: contain;
  border: 0;
}

.lightbox-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  padding: 34px;
}

.lightbox-copy h2 {
  font-size: clamp(28px, 4vw, 44px);
}

.lightbox-copy p:not(.section-label) {
  color: var(--text-muted);
  line-height: 1.55;
}

.login-view {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(145deg, var(--bg), var(--bg-soft));
}

.login-card {
  display: grid;
  width: min(420px, 100%);
  gap: 18px;
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface-raised);
  box-shadow: var(--shadow);
  animation: panelIn 420ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.centered-brand {
  margin-bottom: 8px;
}

.login-card h1 {
  font-size: 34px;
}

.admin-sidebar {
  background:
    linear-gradient(180deg, var(--surface-muted), var(--bg-soft));
}

.admin-nav {
  align-content: start;
}

.admin-nav a {
  justify-content: flex-start;
}

.admin-sidebar .ghost-button {
  margin-top: auto;
}

.admin-main {
  display: grid;
  gap: 24px;
  background: var(--bg);
}

.admin-section {
  display: grid;
  gap: 18px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-raised);
  box-shadow: 0 16px 42px rgba(36, 60, 51, 0.08);
  animation: panelIn 360ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.admin-section:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow);
}

.upload-form {
  grid-template-columns: minmax(220px, 1.2fr) minmax(160px, 0.8fr) minmax(160px, 0.7fr) auto;
  align-items: end;
}

.wide-field {
  grid-column: 1 / -2;
}

.inline-field {
  min-width: 220px;
}

.folder-create-form {
  grid-template-columns: minmax(240px, 360px) auto;
  align-items: end;
}

.works-list,
.folders-list {
  display: grid;
  gap: 10px;
}

.admin-work-row,
.admin-folder-row {
  display: grid;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface-raised) 82%, var(--accent-soft));
}

.admin-work-row:hover,
.admin-folder-row:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 16px 44px rgba(36, 60, 51, 0.1);
}

.admin-work-row {
  grid-template-columns: 90px minmax(180px, 1fr) minmax(160px, 0.7fr) auto;
}

.admin-folder-row {
  grid-template-columns: minmax(200px, 1fr) auto auto;
}

.admin-thumb {
  width: 90px;
  height: 70px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-cool);
  object-fit: cover;
}

.admin-thumb.document {
  display: grid;
  place-items: center;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 800;
}

.work-edit-fields {
  display: grid;
  grid-template-columns: minmax(150px, 0.9fr) minmax(180px, 1.1fr);
  gap: 10px;
}

.row-actions,
.folder-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.folder-name-edit {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) auto;
  gap: 10px;
}

.folder-stat {
  color: var(--text-muted);
  font-size: 13px;
  white-space: nowrap;
}

.form-message {
  min-height: 20px;
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
}

.form-message.is-error {
  color: var(--danger);
}

.form-message.is-success {
  color: var(--accent-strong);
}

.sticky-message {
  position: sticky;
  z-index: 9;
  top: 0;
  padding: 8px 0;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(12px);
}

@keyframes panelIn {
  from {
    opacity: 0;
    transform: translateY(14px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1100px) {
  .gallery-header,
  .admin-header,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .gallery-tools {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .header-actions,
  .admin-header-actions {
    align-items: end;
    justify-content: space-between;
  }

  .compact-field {
    width: auto;
  }

  .upload-form,
  .admin-work-row,
  .work-edit-fields {
    grid-template-columns: 1fr;
  }

  .wide-field {
    grid-column: auto;
  }

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

@media (max-width: 780px) {
  .app-shell,
  .admin-shell {
    display: block;
  }

  .folder-sidebar,
  .admin-sidebar {
    position: static;
    height: auto;
    padding: 18px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .folder-nav {
    display: flex;
    overflow-x: auto;
    padding-bottom: 6px;
  }

  .folder-button {
    flex: 0 0 auto;
    min-width: 152px;
  }

  .sidebar-admin-link {
    margin-top: 0;
  }

  .gallery-main,
  .admin-main {
    padding: 22px 18px 48px;
  }

  .gallery-header {
    position: static;
    margin: -22px -18px 20px;
    padding: 24px 18px 20px;
  }

  .gallery-tools,
  .folder-create-form {
    grid-template-columns: 1fr;
  }

  .header-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .header-actions .theme-toggle {
    align-self: flex-end;
  }

  .page-theme-toggle {
    top: 14px;
    right: 14px;
  }

  .lightbox-panel {
    grid-template-columns: 1fr;
    max-height: 94vh;
    overflow: auto;
  }

  .lightbox-media {
    min-height: 300px;
  }

  .admin-folder-row,
  .folder-name-edit {
    grid-template-columns: 1fr;
  }
}

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