:root {
  --ink: #172033;
  --ink-soft: #3a4558;
  --muted: #6d7585;
  --paper: #f4f1eb;
  --paper-2: #ebe6dc;
  --surface: rgba(255, 252, 247, 0.88);
  --line: rgba(23, 32, 51, 0.1);
  --accent: #0f6b5c;
  --accent-2: #148576;
  --accent-soft: rgba(15, 107, 92, 0.12);
  --danger: #b42318;
  --danger-soft: rgba(180, 35, 24, 0.08);
  --shadow: 0 18px 50px rgba(23, 32, 51, 0.08);
  --radius: 18px;
  --radius-sm: 12px;
  --font: "DM Sans", "Segoe UI", sans-serif;
  --display: "Fraunces", Georgia, serif;
}

* { box-sizing: border-box; }

/* Pastikan atribut hidden menang melawan display:flex/grid di CSS author */
[hidden] { display: none !important; }

html, body { min-height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(15, 107, 92, 0.12), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(23, 32, 51, 0.08), transparent 50%),
    linear-gradient(180deg, #f7f4ee 0%, var(--paper) 45%, var(--paper-2) 100%);
  background-attachment: fixed;
}

button, input { font: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 14px 28px;
  backdrop-filter: blur(14px);
  background: rgba(244, 241, 235, 0.82);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background:
    linear-gradient(145deg, #1d8f7c, #0b4f44 70%),
    var(--accent);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.2);
}

.brand-name {
  margin: 0;
  font-family: var(--display);
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.brand-sub {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.main-nav {
  display: flex;
  gap: 6px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(255,255,255,0.55);
  border: 1px solid var(--line);
}

.nav-tab {
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  padding: 8px 18px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 500;
}

.nav-tab.active {
  background: var(--ink);
  color: #fff;
}

.user-area {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  font-size: 0.92rem;
}

.user-name { color: var(--ink-soft); }

main {
  width: 100%;
  margin: 0;
  padding: 0 0 40px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  cursor: pointer;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.92rem;
  transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.btn:hover { transform: translateY(-1px); }
.btn-sm { padding: 7px 12px; font-size: 0.82rem; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); }
.btn-secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.05); }
.btn-danger:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: rgba(23, 32, 51, 0.06); }
.btn-danger-ghost { background: transparent; color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.btn-link {
  background: none;
  border: 0;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
}

.gallery-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 0;
  min-height: calc(100vh - 78px);
  align-items: start;
}

body.rail-collapsed .gallery-shell {
  grid-template-columns: 1fr;
}

body.rail-collapsed .folder-rail {
  display: none;
}

.folder-rail,
.folders-page,
.account-page,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.folder-rail {
  margin: 12px 0 12px 12px;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: sticky;
  top: 78px;
  max-height: calc(100vh - 90px);
  overflow: auto;
  border-radius: var(--radius);
}

.rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 6px;
}

.rail-head h2 {
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.rail-meta {
  margin: auto 6px 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 0.78rem;
  color: var(--muted);
}

.folder-tree { display: flex; flex-direction: column; gap: 4px; }

.tree-node { display: flex; flex-direction: column; gap: 4px; }

.tree-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 0;
  background: transparent;
  border-radius: 12px;
  padding: 9px 10px 9px calc(10px + var(--depth, 0) * 14px);
  cursor: pointer;
  text-align: left;
  color: var(--ink-soft);
}

.tree-item:hover { background: rgba(23, 32, 51, 0.05); }
.tree-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.tree-icon,
.manage-icon,
.subfolder-icon {
  width: 18px;
  height: 14px;
  border-radius: 3px 3px 2px 2px;
  background: linear-gradient(180deg, #d8b56a 0 28%, #c79a3e 28%);
  box-shadow: 0 1px 0 rgba(0,0,0,0.08);
  flex: 0 0 auto;
}

.tree-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-count {
  font-size: 0.72rem;
  color: var(--muted);
  background: rgba(23, 32, 51, 0.06);
  border-radius: 999px;
  padding: 2px 7px;
}

.gallery-main {
  padding: 16px 18px 28px;
  min-height: 70vh;
  width: 100%;
}

.gallery-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 10px;
}

.toolbar-right {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  font-size: 0.82rem;
  color: var(--muted);
}

.crumb {
  border: 0;
  background: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  font-weight: 500;
}

.crumb.current { color: var(--muted); cursor: default; }
.crumb-sep { opacity: 0.45; }

.gallery-title {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.6rem, 2.4vw, 2.2rem);
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.gallery-count {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.upload-progress {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--line);
}

.upload-progress-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.88rem;
  color: var(--ink-soft);
  margin-bottom: 8px;
}

.upload-track {
  height: 8px;
  border-radius: 999px;
  background: rgba(23, 32, 51, 0.08);
  overflow: hidden;
}

.upload-bar {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #27a992);
  transition: width 0.15s ease;
}

.upload-bar.is-error {
  background: var(--danger);
}

.subfolder-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}

.subfolder-card {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.subfolder-card:hover {
  transform: translateY(-2px);
  border-color: rgba(15, 107, 92, 0.35);
}

.subfolder-name {
  font-weight: 600;
  font-size: 0.92rem;
}

.gallery-masonry {
  column-count: 2;
  column-gap: 14px;
  width: 100%;
}

@media (min-width: 700px) {
  .gallery-masonry { column-count: 3; }
}
@media (min-width: 1000px) {
  .gallery-masonry { column-count: 4; }
}
@media (min-width: 1300px) {
  .gallery-masonry { column-count: 5; }
}
@media (min-width: 1600px) {
  .gallery-masonry { column-count: 6; }
}

.selection-footer {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%) translateY(12px);
  z-index: 40;
  width: min(720px, calc(100% - 24px));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.selection-footer:not([hidden]) {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.selection-footer-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 12px 16px;
  border-radius: 18px;
  background: rgba(23, 32, 51, 0.94);
  color: #f4f1eb;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 18px 40px rgba(23, 32, 51, 0.28);
  backdrop-filter: blur(10px);
}

.select-all {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: rgba(244, 241, 235, 0.9);
  cursor: pointer;
}

.selected-count {
  font-size: 0.9rem;
  font-weight: 600;
  color: #9ee0d4;
  margin-right: auto;
}

.selection-footer-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.selection-footer .btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.18);
}

.selection-footer .btn-ghost {
  color: rgba(244, 241, 235, 0.85);
}

body.has-selection-footer {
  padding-bottom: 88px;
}

body.has-selection-footer .pagination {
  margin-bottom: 72px;
}

.gallery-card {
  position: relative;
  break-inside: avoid;
  margin: 0 0 14px;
  border-radius: 16px;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 10px 28px rgba(23, 32, 51, 0.05);
  animation: rise 0.45s ease both;
  animation-delay: calc(var(--i, 0) * 40ms);
}

.gallery-card.is-selected {
  border-color: rgba(15, 107, 92, 0.55);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.gallery-check-wrap {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(23, 32, 51, 0.12);
}

.gallery-check {
  width: 16px;
  height: 16px;
  margin: 0;
  cursor: pointer;
  accent-color: var(--accent);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.gallery-thumb {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: #ddd6c8;
  cursor: zoom-in;
  overflow: hidden;
}

.gallery-thumb img {
  width: 100%;
  height: auto;
  display: block;
  transition: transform 0.35s ease;
}

.gallery-card:hover .gallery-thumb img {
  transform: scale(1.03);
}

.thumb-fallback {
  min-height: 220px;
  display: grid;
  place-items: center;
  padding: 16px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.gallery-card-meta {
  padding: 10px 12px 12px;
}

.gallery-card-name {
  display: block;
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 8px;
  color: var(--ink-soft);
}

.gallery-card-actions {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
}

.gallery-card-actions a,
.gallery-card-actions button {
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
}

.gallery-card-actions .danger { color: var(--danger); }

.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.page-btn {
  min-width: 38px;
  height: 38px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-soft);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.88rem;
}

.page-btn:hover:not(:disabled) {
  border-color: rgba(15, 107, 92, 0.4);
  color: var(--accent);
}

.page-btn.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

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

.page-ellipsis {
  color: var(--muted);
  padding: 0 2px;
}

.page-meta {
  margin-left: auto;
  font-size: 0.84rem;
  color: var(--muted);
}

.empty-state {
  padding: 48px 20px;
  text-align: center;
  color: var(--ink-soft);
}

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

.empty { color: var(--muted); font-size: 0.9rem; }
.loading { padding: 24px 0; }

.folders-page,
.account-page {
  margin: 16px;
  padding: 28px;
  border-radius: var(--radius);
}

.account-card {
  max-width: 520px;
  padding: 22px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #fff;
}

.account-card h2 {
  margin: 0 0 8px;
  font-size: 1.05rem;
}

.account-status {
  margin: 0 0 16px;
  color: var(--ink-soft);
}

.account-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.page-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 22px;
}

.page-header h1 {
  margin: 0 0 6px;
  font-family: var(--display);
  font-size: 1.8rem;
}

.page-header p { margin: 0; }

.manage-tree { display: flex; flex-direction: column; gap: 10px; }

.manage-node {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  overflow: hidden;
}

.manage-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 14px 16px 14px calc(16px + var(--depth, 0) * 18px);
}

.manage-info {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.manage-name {
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  font-weight: 600;
  color: var(--ink);
  text-align: left;
}

.manage-name:hover { color: var(--accent); }
.manage-info .muted { margin: 2px 0 0; font-size: 0.8rem; }

.manage-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: flex-end;
}

.manage-children {
  border-top: 1px solid var(--line);
  background: rgba(244, 241, 235, 0.55);
}

.danger-zone {
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.modal {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: calc(100% - 32px);
}

.modal::backdrop { background: rgba(23, 32, 51, 0.45); }

.modal-card {
  width: min(420px, 100%);
  margin: auto;
  background: #fffdf9;
  border-radius: 20px;
  padding: 24px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-card h3 {
  margin: 0;
  font-family: var(--display);
}

.modal-card label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--muted);
}

.modal-card input {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 12px;
  color: var(--ink);
  background: #fff;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.lightbox {
  position: relative;
  border: 0;
  padding: 0;
  width: min(920px, calc(100% - 24px));
  max-height: calc(100vh - 24px);
  background: transparent;
}

.lightbox::backdrop { background: rgba(10, 14, 22, 0.82); }

.lightbox img {
  width: 100%;
  max-height: calc(100vh - 110px);
  object-fit: contain;
  border-radius: 16px;
  background: #111;
  display: block;
}

.lightbox-close {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 999px;
  background: #fff;
  cursor: pointer;
  font-size: 1.4rem;
  line-height: 1;
}

.lightbox-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  color: #f4f1eb;
  font-size: 0.9rem;
}

.lightbox-meta a { color: #9ee0d4; }

/* Auth pages */
.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 32px;
  box-shadow: var(--shadow);
}

.auth-card h1 {
  margin: 0 0 18px;
  font-family: var(--display);
  font-size: 1.7rem;
}

.auth-card form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.86rem;
  color: var(--muted);
}

.auth-card input {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 12px;
  background: #fff;
  color: var(--ink);
}

.btn-block { width: 100%; }
.status { font-size: 0.86rem; color: var(--muted); min-height: 1.2em; }

@media (max-width: 900px) {
  .topbar {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "brand user"
      "nav nav";
  }
  .brand { grid-area: brand; }
  .user-area { grid-area: user; }
  .main-nav { grid-area: nav; justify-self: start; }

  .gallery-shell { grid-template-columns: 1fr; }
  .folder-rail {
    position: static;
    max-height: none;
    margin: 12px 12px 0;
  }

  .gallery-toolbar { flex-direction: column; }
  .manage-row { flex-direction: column; align-items: flex-start; }
}
