:root {
  --bg: #f3efe7;
  --wash-top: #f8f3eb;
  --paper: #fffaf1;
  --ink: #1b1915;
  --muted: #736c61;
  --line: #d9cfbf;
  --accent: #1d6b57;
  --accent-soft: #d7efe7;
  --danger: #b7392f;
  --shadow: 0 18px 40px rgba(58, 42, 16, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: linear-gradient(180deg, var(--wash-top) 0%, var(--bg) 100%);
  background-color: var(--bg);
}

body {
  margin: 0;
  min-height: 100dvh;
  overflow-x: hidden;
  /* `max(safe-area-inset, N)` guarantees a minimum gutter even when
     iOS reports 0 (desktop browsers, non-PWA mobile Safari without a
     notch). Previously these were bare `env(...)` calls → 0 on desktop
     → hero "PRIVATE DROP / NAS Drop" headline touched the top of the
     window when the viewport was short. */
  padding-top: max(env(safe-area-inset-top), 20px);
  padding-right: max(env(safe-area-inset-right), 0px);
  padding-bottom: max(env(safe-area-inset-bottom), 20px);
  padding-left: max(env(safe-area-inset-left), 0px);
  background: inherit;
  background-color: var(--bg);
  color: var(--ink);
  font-family: "Avenir Next", "PingFang SC", "Hiragino Sans GB", sans-serif;
}

.shell {
  width: min(1180px, calc(100vw - clamp(24px, 4vw, 56px)));
  margin: 0 auto;
  padding: clamp(24px, 4vw, 48px) 0 56px;
}

body[data-auth="false"] .shell {
  max-width: 760px;
  /* Subtract the *effective* padding (the max() value the body actually
     applied) so the centred shell still fills the visible area without
     overflowing into the safe-area gutter. */
  min-height: calc(
    100dvh
    - max(env(safe-area-inset-top), 20px)
    - max(env(safe-area-inset-bottom), 20px)
  );
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  /* A bit of breathing room above + below the hero/login card on top of
     whatever the body already contributes, so on a short viewport (split
     screen, small browser window) the headline still has a clear top
     margin instead of bleeding into the body padding. */
  padding-top: 24px;
  padding-bottom: 24px;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
  margin-bottom: 20px;
}

body[data-auth="false"] .hero {
  max-width: 640px;
  margin-bottom: 28px;
  align-items: center;
}

.eyebrow {
  margin: 0 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 12px;
  color: var(--muted);
}

h1 {
  margin: 0;
  font-size: clamp(36px, 8vw, 72px);
  line-height: 0.95;
}

.subhead {
  margin: 14px 0 0;
  color: var(--muted);
  max-width: 620px;
  font-size: 18px;
  line-height: 1.55;
}

.card,
.item {
  background: color-mix(in srgb, var(--paper) 92%, white 8%);
  border: 1px solid color-mix(in srgb, var(--line) 80%, white 20%);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.card {
  padding: clamp(20px, 2.4vw, 28px);
}

#loginCard {
  width: min(100%, 420px);
  text-align: left;
}

#loginCard h2 {
  margin: 0 0 18px;
  font-size: clamp(24px, 3.5vw, 40px);
  line-height: 1;
}

.app-grid {
  display: grid;
  grid-template-columns: minmax(320px, 440px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card-head h2 {
  margin: 0;
  font-size: 24px;
}

.card-head p {
  margin: 6px 0 0;
  color: var(--muted);
}

.dropzone {
  display: block;
  border: 2px dashed color-mix(in srgb, var(--accent) 45%, white 55%);
  border-radius: 24px;
  background:
    linear-gradient(135deg, rgba(29, 107, 87, 0.08), rgba(29, 107, 87, 0.02)),
    var(--paper);
  min-height: 240px;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.dropzone.dragover {
  transform: scale(1.01);
  border-color: var(--accent);
  background:
    linear-gradient(135deg, rgba(29, 107, 87, 0.16), rgba(29, 107, 87, 0.05)),
    var(--paper);
}

.drop-inner {
  display: grid;
  place-items: center;
  min-height: 240px;
  text-align: center;
  padding: 24px;
  gap: 8px;
}

.drop-inner strong {
  font-size: 22px;
}

.drop-inner span,
.drop-inner small,
.muted {
  color: var(--muted);
}

textarea,
input[type="password"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: white;
  color: var(--ink);
  padding: 14px 16px;
  font: inherit;
}

textarea {
  resize: vertical;
  min-height: 132px;
}

button,
.download-btn {
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  padding: 12px 18px;
  cursor: pointer;
  font: inherit;
  text-decoration: none;
  text-align: center;
}

button.ghost {
  background: white;
  color: var(--ink);
  border: 1px solid var(--line);
}

.tab-bar {
  display: flex;
  gap: 8px;
}

.tab-btn {
  min-height: 40px;
  padding: 0 18px;
  border-radius: 999px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  border: 1px solid var(--line);
  background: white;
  color: var(--muted);
}

.tab-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.star-btn {
  min-height: 48px;
  padding: 0 16px;
  white-space: nowrap;
}

.star-btn.starred {
  background: #fdf4e3;
  color: #b8860b;
  border-color: #e0c97f;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.items {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 120px;
}

.item {
  padding: 16px;
}

.item-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.item-info {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.item-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.item-remark {
  padding: 8px 12px;
  border-radius: 12px;
  background: #f7f2ea;
  color: #5d574e;
  font-size: 14px;
  line-height: 1.5;
}

.item-remark-edit {
  display: flex;
  gap: 8px;
  align-items: center;
}

.remark-input {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
}

.remark-btn {
  min-height: 48px;
  padding: 0 16px;
  white-space: nowrap;
}

.remark-save-btn,
.remark-cancel-btn {
  min-height: 40px;
  padding: 0 14px;
  white-space: nowrap;
  font-size: 14px;
}

.item-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.item-title {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.item-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.badge,
.item-meta {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
}

.item-meta {
  margin: 0;
  background: #f1ebdf;
  color: #5d574e;
}

.item-preview {
  margin: 0;
  padding: 10px 12px;
  border-radius: 14px;
  background: #f7f2ea;
  color: #534c42;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 180px;
  overflow: auto;
  font-family: "SF Mono", "JetBrains Mono", monospace;
  font-size: 12px;
}

.share-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 16px;
  background: #f7f2ea;
}

.share-input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: white;
  color: #5d574e;
}

.share-copy-btn,
.share-open-btn {
  min-height: 44px;
  padding: 0 16px;
  white-space: nowrap;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.preview-media-btn {
  min-height: 48px;
  padding: 0 16px;
  white-space: nowrap;
}

.download-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 112px;
  min-height: 48px;
  padding: 0 18px;
  white-space: nowrap;
  flex-shrink: 0;
}

.copy-btn {
  min-height: 48px;
  padding: 0 16px;
  white-space: nowrap;
}

.copy-image-btn {
  min-height: 48px;
  padding: 0 16px;
  white-space: nowrap;
}

.share-btn {
  min-height: 48px;
  padding: 0 16px;
  white-space: nowrap;
}

.upload-feedback {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.status {
  min-height: 24px;
  color: var(--muted);
  text-align: center;
  line-height: 1.45;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.progress {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: #e7dccb;
  overflow: hidden;
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #2a7a65 0%, #51af95 100%);
  transition: width 120ms linear;
}

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

.hidden {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(27, 25, 21, 0.52);
  backdrop-filter: blur(8px);
}

.modal-dialog {
  position: relative;
  width: min(720px, calc(100vw - 32px));
  max-height: min(82vh, 900px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border-radius: 28px;
  background: color-mix(in srgb, var(--paper) 94%, white 6%);
  border: 1px solid color-mix(in srgb, var(--line) 82%, white 18%);
  box-shadow: 0 32px 80px rgba(28, 23, 14, 0.22);
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.modal-title {
  width: 100%;
  font-size: 18px;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-close {
  min-height: 46px;
  width: min(100%, 320px);
  padding: 0 18px;
}

.modal-body {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 auto;
  min-height: 0;
  min-height: 240px;
  overflow: auto;
}

.modal-actions {
  display: flex;
  justify-content: center;
}

.preview-image {
  display: block;
  max-width: 100%;
  max-height: min(68vh, 760px);
  border-radius: 18px;
  box-shadow: 0 18px 42px rgba(34, 25, 12, 0.14);
  background: white;
}

.preview-video {
  display: block;
  width: 100%;
  max-width: min(100%, 960px);
  height: auto;
  max-height: min(68vh, 760px);
  border-radius: 18px;
  box-shadow: 0 18px 42px rgba(34, 25, 12, 0.14);
  background: #090909;
}

@media (max-width: 900px) {
  .shell {
    width: min(100%, calc(100vw - 36px));
    padding-top: max(26px, calc(env(safe-area-inset-top) + 10px));
    padding-bottom: max(44px, calc(env(safe-area-inset-bottom) + 16px));
  }

  .app-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .hero {
    flex-direction: column;
    align-items: stretch;
    gap: 18px;
    margin-bottom: 24px;
  }

  body[data-auth="false"] .shell {
    padding-top: max(28px, calc(env(safe-area-inset-top) + 12px));
    padding-bottom: max(28px, calc(env(safe-area-inset-bottom) + 12px));
  }

  body[data-auth="false"] .subhead {
    max-width: 30ch;
    font-size: 17px;
  }

  .toolbar,
  .item {
    flex-direction: column;
    align-items: stretch;
  }

  .item-actions {
    width: 100%;
    flex-direction: column;
  }

  .item-remark-edit {
    flex-direction: column;
  }

  .download-btn,
  .copy-btn,
  .preview-media-btn,
  .copy-image-btn,
  .share-btn,
  .star-btn,
  .remark-btn,
  .share-copy-btn,
  .share-open-btn,
  button {
    width: 100%;
  }

  .share-row {
    flex-direction: column;
    align-items: stretch;
  }

  .modal {
    padding: 16px;
  }

  .modal-dialog {
    width: calc(100vw - 28px - env(safe-area-inset-left) - env(safe-area-inset-right));
    max-width: 100%;
    max-height: calc(100dvh - 28px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    padding: 14px;
    border-radius: 22px;
  }

  .modal-head {
    align-items: center;
  }

  .modal-title {
    font-size: 16px;
    text-align: center;
  }

  .modal-body {
    min-height: 0;
    max-height: min(56dvh, 420px);
  }

  .modal-actions {
    padding-top: 2px;
  }

  .modal-close {
    width: 100%;
  }

  .preview-image,
  .preview-video {
    width: 100%;
    max-width: 100%;
    max-height: min(48dvh, 360px);
    object-fit: contain;
  }
}

@media (max-width: 640px) {
  .shell {
    width: min(100%, calc(100vw - 24px));
    max-width: 100%;
    padding-top: max(28px, calc(env(safe-area-inset-top) + 12px));
    padding-bottom: max(48px, calc(env(safe-area-inset-bottom) + 18px));
  }

  body[data-auth="false"] .shell {
    max-width: 420px;
    justify-content: center;
    padding-top: max(24px, calc(env(safe-area-inset-top) + 12px));
    padding-bottom: max(24px, calc(env(safe-area-inset-bottom) + 12px));
  }

  body[data-auth="true"] .hero {
    width: 100%;
    max-width: 352px;
    margin-left: auto;
    margin-right: auto;
  }

  .hero,
  #loginCard {
    width: 100%;
    max-width: 352px;
    margin-left: auto;
    margin-right: auto;
  }

  .app-grid {
    width: 100%;
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
  }

  h1 {
    font-size: clamp(30px, 14vw, 48px);
    line-height: 0.98;
  }

  .hero {
    gap: 14px;
    margin-bottom: 18px;
  }

  body[data-auth="false"] .hero {
    margin-bottom: 16px;
  }

  body[data-auth="false"] #loginCard {
    margin-bottom: 0;
  }

  .subhead {
    max-width: 18ch;
    font-size: 15px;
    line-height: 1.6;
  }

  .card {
    padding: 16px;
    border-radius: 22px;
  }

  #loginCard h2,
  .card-head h2 {
    font-size: 22px;
  }

  .dropzone,
  .drop-inner {
    min-height: 190px;
  }

  .drop-inner strong {
    font-size: 20px;
  }

  textarea,
  input[type="password"] {
    padding: 13px 14px;
  }

  .toolbar {
    gap: 10px;
  }

  .item {
    padding: 14px;
    border-radius: 20px;
  }
}

/* ==========================================================================
   Folder tree UI — added 2026-08-06 for Baidu-Pan-style navigation
   ========================================================================== */

/* Breadcrumb (currently-open path). Rows are anchors; the last one is
   the current dir and non-clickable. */
.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--wash-top);
  font-size: 13px;
  min-height: 34px;
}
.breadcrumb a,
.breadcrumb .crumb-current {
  padding: 3px 8px;
  border-radius: 7px;
  color: var(--muted);
  text-decoration: none;
  cursor: pointer;
}
.breadcrumb a:hover {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  color: var(--accent);
}
.breadcrumb .crumb-current {
  color: var(--ink);
  font-weight: 600;
  cursor: default;
}
.breadcrumb .crumb-sep {
  color: var(--line);
  padding: 0 2px;
  user-select: none;
}
.breadcrumb.at-root a:first-child { color: var(--ink); font-weight: 600; }

/* Upload target hint inside dropzone — tells you which folder the next
   upload goes into, since it's not always the visible one. */
.upload-target {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}
.upload-target b { color: var(--accent); font-weight: 600; }

/* Item type icon slot (📁 for folder, 📄 for file, 📝 for text). Kept
   inline in the title row so it flows with the filename. */
.item-icon {
  display: inline-block;
  font-size: 18px;
  line-height: 1;
  margin-right: 4px;
  transform: translateY(1px);
}

/* Folder item: whole row is a click-to-enter surface (double-click
   desktop, single-tap mobile). Hover cursor hints at it. */
.item.item-folder {
  cursor: pointer;
}
.item.item-folder:hover {
  background: color-mix(in srgb, var(--accent) 5%, var(--paper));
}
.item.item-folder .item-preview,
.item.item-folder .item-remark,
.item.item-folder .share-btn,
.item.item-folder .copy-btn,
.item.item-folder .copy-image-btn,
.item.item-folder .preview-media-btn,
.item.item-folder .download-btn,
.item.item-folder .item-size {
  display: none !important;
}

/* Custom context menu — anchored via inline top/left set by JS. */
.ctx-menu {
  position: fixed;
  z-index: 1000;
  min-width: 180px;
  padding: 4px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(58, 42, 16, 0.18);
  font-size: 14px;
}
.ctx-menu.hidden { display: none; }
.ctx-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border: 0;
  background: transparent;
  border-radius: 8px;
  text-align: left;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
}
.ctx-menu button:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.ctx-menu button.danger { color: #b91c1c; }
.ctx-menu button.danger:hover { background: color-mix(in srgb, #ef4444 12%, transparent); color: #b91c1c; }
.ctx-menu .ctx-sep {
  height: 1px;
  margin: 4px 6px;
  background: var(--line);
}
.ctx-menu button[disabled] { opacity: 0.4; cursor: not-allowed; }

/* Hide desktop-only affordances on narrow screens (matches phone/tablet).
   Users on mobile can still open, download, star — just no folder mgmt. */
@media (max-width: 720px) {
  .desktop-only { display: none !important; }
}

/* ---- Phase 3: multi-select, clipboard, drag-drop states ---- */

/* Row is currently in the selection. Same visual weight as hover on a
   folder — noticeable but not screaming. */
.item.is-selected {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: color-mix(in srgb, var(--accent) 8%, var(--paper));
}
/* Multi-selected: prevent text-selection while shift-clicking. */
.items { user-select: none; -webkit-user-select: none; }

/* Row was cut into the clipboard — dimmed until paste (like Finder). */
.item.is-cut {
  opacity: 0.55;
  filter: grayscale(0.35);
}

/* Drop-target highlight — used by folder rows and breadcrumb links
   while a compatible drag is hovering over them. */
.item.drop-target {
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
  background: color-mix(in srgb, var(--accent) 14%, var(--paper));
}
.breadcrumb a.drop-target {
  background: color-mix(in srgb, var(--accent) 20%, transparent);
  color: var(--accent);
  outline: 1px dashed var(--accent);
}

/* Selection count chip on the toolbar — appears only when >= 1 selected. */
.sel-count {
  display: none;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  font-size: 12px;
  font-weight: 600;
  margin-left: 8px;
}
.sel-count.on { display: inline-block; }

/* Dropzone highlight when receiving a folder drop (files-with-directories) */
.dropzone.folder-drop {
  outline: 3px dashed var(--accent);
  outline-offset: -6px;
  background: color-mix(in srgb, var(--accent) 8%, var(--wash-top));
}
