:root {
  --bg: #f6f8fc;
  --surface: #ffffff;
  --surface-2: #f1f3f9;
  --border: #dfe3ec;
  --text: #1b1f27;
  --muted: #5f6673;
  --accent: #2f6df6;
  --accent-soft: #e6efff;
  --danger: #d93b3b;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1219;
    --surface: #171b24;
    --surface-2: #1e232e;
    --border: #2a3040;
    --text: #e8eaf0;
    --muted: #98a0b0;
    --accent: #5b8dff;
    --accent-soft: #1c2740;
    --danger: #f2645a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

/* The UA sheet hides [hidden] with `display: none`, but ANY author-level
   `display` declaration outranks it — so `.modal-backdrop { display: grid }`
   left the preview overlay permanently on screen, swallowing every click.
   This rule must stay ahead of the component styles below. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ── Login ─────────────────────────────────────────────────────────────── */

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, var(--accent-soft), var(--bg));
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 36px 32px 32px;
  text-align: center;
}

.login-logo { color: var(--accent); margin-bottom: 10px; }
.login-card h1 { margin: 0 0 6px; font-size: 22px; font-weight: 650; }
.login-sub { margin: 0 0 22px; color: var(--muted); font-size: 14px; }

.login-card input {
  width: 100%;
  padding: 12px 14px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  margin-bottom: 12px;
}
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.login-card button {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
.login-card button:hover { filter: brightness(1.06); }

.login-error {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  margin-bottom: 14px;
}

/* ── Public share page ─────────────────────────────────────────────────── */

.share-card {
  width: 100%;
  max-width: 620px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 34px 30px 30px;
  text-align: center;
}

.share-icon { font-size: 46px; line-height: 1; margin-bottom: 12px; }

.share-name {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 620;
  word-break: break-word;
}

.share-meta { margin: 0 0 20px; color: var(--muted); font-size: 14px; }

.share-preview {
  margin: 0 0 22px;
  background: var(--surface-2);
  border-radius: 12px;
  padding: 12px;
  display: grid;
  place-items: center;
}
.share-preview img, .share-preview video { max-width: 100%; max-height: 52vh; border-radius: 8px; }
.share-preview audio { width: 100%; }

.share-btn {
  display: inline-flex; align-items: center; gap: 9px;
  padding: 12px 26px;
  background: var(--accent); color: #fff;
  border-radius: 10px; font-size: 15px; font-weight: 600;
  text-decoration: none;
}
.share-btn:hover { filter: brightness(1.06); }

.share-expiry { margin: 18px 0 0; font-size: 12.5px; color: var(--muted); }

/* ── Share dialog (inside the app) ─────────────────────────────────────── */

.share-box {
  background: var(--surface);
  border-radius: 14px;
  width: min(520px, 100%);
  padding: 22px;
}
.share-box h2 { margin: 0 0 4px; font-size: 17px; }
.share-box .share-sub {
  margin: 0 0 18px; font-size: 13.5px; color: var(--muted);
  word-break: break-word;
}
.share-row { display: flex; gap: 8px; margin-bottom: 14px; }
.share-row input {
  flex: 1; min-width: 0;
  padding: 10px 12px; font-size: 13px;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface-2); color: var(--text);
}
.share-expiry-row {
  display: flex; align-items: center; gap: 9px;
  margin-bottom: 18px; font-size: 13.5px; color: var(--muted);
}
.share-expiry-row select {
  padding: 7px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font-size: 13.5px;
}
.share-actions { display: flex; justify-content: space-between; gap: 8px; }

.share-list { margin-top: 6px; max-height: 260px; overflow-y: auto; }
.share-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13.5px;
}
.share-item:last-child { border-bottom: 0; }
.share-item .si-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share-item .si-meta { font-size: 12px; color: var(--muted); flex-shrink: 0; }

/* ── Text editor ───────────────────────────────────────────────────────── */

.editor-box {
  background: var(--surface);
  border-radius: 14px;
  width: min(980px, 100%);
  height: min(84vh, 800px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#editor-body {
  flex: 1;
  width: 100%;
  border: 0;
  outline: none;
  resize: none;
  padding: 16px 18px;
  background: var(--surface-2);
  color: var(--text);
  font: 13.5px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  tab-size: 2;
}
.editor-state { font-size: 12.5px; color: var(--muted); }
.editor-state.dirty { color: var(--accent); }
.editor-state.saved { color: #1a9d5a; }

/* ── Move-to picker ────────────────────────────────────────────────────── */

.move-list {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
}
.move-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px; border-radius: 8px;
  font-size: 14px; cursor: pointer;
}
.move-row:hover { background: var(--surface-2); }
.move-row .mr-icon { flex-shrink: 0; }
.move-row .mr-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.move-empty { padding: 22px; text-align: center; color: var(--muted); font-size: 13.5px; }

/* ── URL import ────────────────────────────────────────────────────────── */

#import-url {
  width: 100%;
  padding: 11px 13px;
  font: 13.5px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  resize: vertical;
}
#import-url:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.import-dest { margin: 10px 0 0; font-size: 12.5px; color: var(--muted); }

.chip.primary-chip { background: var(--accent); color: #fff; border-color: transparent; font-weight: 600; }
.chip.primary-chip:hover { filter: brightness(1.06); }

.import-list { margin-top: 16px; max-height: 240px; overflow-y: auto; }

.import-row { padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.import-row:last-child { border-bottom: 0; }
.import-head { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.import-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.import-badge {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); flex-shrink: 0;
}
.import-badge.running { background: var(--accent-soft); color: var(--accent); }
.import-badge.done    { background: color-mix(in srgb, #1a9d5a 16%, transparent); color: #1a9d5a; }
.import-badge.failed  { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.import-bar { height: 4px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.import-fill { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.import-row.done .import-fill { background: #1a9d5a; }
.import-row.failed .import-fill { background: var(--danger); }
.import-note { font-size: 11.5px; color: var(--muted); margin-top: 4px; word-break: break-word; }

/* ── Shell ─────────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 650; font-size: 17px; color: var(--accent);
  flex-shrink: 0;
}
.brand span { color: var(--text); }

.search-wrap { flex: 1; max-width: 640px; }
#search {
  width: 100%;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
}
#search:focus { outline: 2px solid var(--accent); outline-offset: 1px; background: var(--surface); }

.topbar-actions { display: flex; gap: 6px; margin-left: auto; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px;
  border: 0; border-radius: 8px;
  background: transparent; color: var(--muted);
  cursor: pointer; text-decoration: none; font-size: 15px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.layout { display: flex; align-items: flex-start; }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  padding: 18px 14px;
  position: sticky;
  top: 55px;
}

.primary-btn, .ghost-btn {
  display: flex; align-items: center; gap: 9px;
  width: 100%; padding: 11px 14px; margin-bottom: 9px;
  border-radius: 10px; font-size: 14px; font-weight: 550;
  cursor: pointer; border: 1px solid transparent;
}
.primary-btn { background: var(--accent); color: #fff; box-shadow: var(--shadow); }
.primary-btn:hover { filter: brightness(1.06); }
.ghost-btn { background: var(--surface); color: var(--text); border-color: var(--border); }
.ghost-btn:hover { background: var(--surface-2); }
.primary-btn:disabled, .ghost-btn:disabled { opacity: .5; cursor: not-allowed; }

.storage { margin-top: 22px; padding: 0 4px; }
.storage-label { font-size: 12px; color: var(--muted); margin-bottom: 7px; }
.storage-bar { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.storage-fill { height: 100%; width: 0; background: var(--accent); transition: width .4s; }
.storage-text { font-size: 12px; color: var(--muted); margin-top: 7px; }

.ro-badge {
  margin-top: 18px; padding: 10px 12px;
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  color: var(--danger); border-radius: 9px; font-size: 12.5px; line-height: 1.45;
}

.content { flex: 1; padding: 18px 22px 60px; min-width: 0; position: relative; }

/* ── Breadcrumbs ───────────────────────────────────────────────────────── */

.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 3px; margin-bottom: 14px; font-size: 14px; }
.crumbs button {
  border: 0; background: transparent; color: var(--muted);
  padding: 5px 8px; border-radius: 7px; cursor: pointer; font-size: 14px;
}
.crumbs button:hover { background: var(--surface-2); color: var(--text); }
.crumbs button.current { color: var(--text); font-weight: 600; }
.crumbs .sep { color: var(--muted); opacity: .5; }

/* ── Toolbars ──────────────────────────────────────────────────────────── */

.toolbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 9px 12px; margin-bottom: 12px;
  background: var(--accent-soft); border-radius: 10px; font-size: 14px;
}
#sel-count { font-weight: 600; margin-right: 4px; }

.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 6px 12px; border-radius: 999px; font-size: 13px; cursor: pointer;
  text-decoration: none; display: inline-block;
}
.chip:hover { background: var(--surface-2); }
.chip.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }

.sortbar { display: flex; gap: 4px; margin-bottom: 10px; }
.sort-btn {
  border: 0; background: transparent; color: var(--muted);
  font-size: 13px; padding: 5px 10px; border-radius: 7px; cursor: pointer;
}
.sort-btn:hover { background: var(--surface-2); }
.sort-btn.active { color: var(--accent); font-weight: 600; background: var(--accent-soft); }

/* ── Listing ───────────────────────────────────────────────────────────── */

.listing.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 12px;
}

.listing.list { display: flex; flex-direction: column; gap: 2px; }

.item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); cursor: pointer;
  transition: border-color .12s, background .12s;
  position: relative; overflow: hidden;
}
.item:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.item.selected { border-color: var(--accent); background: var(--accent-soft); }

.listing.grid .item { padding: 16px 12px 12px; text-align: center; }
.listing.grid .item .icon { font-size: 34px; line-height: 1; margin-bottom: 10px; }
.listing.grid .item .name {
  font-size: 13.5px; word-break: break-word; margin-bottom: 4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.listing.grid .item .meta { font-size: 11.5px; color: var(--muted); }

.listing.list .item {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 13px; border-radius: 9px;
}
.listing.list .item .icon { font-size: 20px; flex-shrink: 0; }
.listing.list .item .name { flex: 1; font-size: 14px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.listing.list .item .meta { font-size: 12.5px; color: var(--muted); flex-shrink: 0; }

/* Dragging must not start a text selection instead. */
.item { user-select: none; -webkit-user-select: none; }

/* The tile's children would otherwise become drag event targets, so entering
   the icon or the filename fires dragleave on the tile and the drop highlight
   flickers. Let every pointer event land on the tile itself. */
.item > * { pointer-events: none; }

/* Drop target highlight — applies to folder tiles and breadcrumbs alike. */
.item.drop-target,
.crumbs button.drop-target {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: var(--accent-soft);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}
.listing.grid .item.drop-target { transform: scale(1.03); }
.item { transition: transform .12s, border-color .12s, background .12s; }

/* The tile being carried. */
.item.dragging { opacity: .45; }

/* Folders advertise themselves as targets while a drag is in progress. */
body.dragging-active .item.is-folder {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  border-style: dashed;
}

.paste-bar { background: var(--surface-2); }

.empty, .loading { text-align: center; color: var(--muted); padding: 56px 20px; font-size: 14px; }

.drop-hint {
  position: absolute; inset: 12px;
  border: 2px dashed var(--accent); border-radius: 14px;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  display: grid; place-items: center;
  font-size: 16px; font-weight: 600; color: var(--accent);
  pointer-events: none; z-index: 5;
}

/* ── Uploads ───────────────────────────────────────────────────────────── */

.uploads {
  position: fixed; right: 20px; bottom: 20px; width: 330px; z-index: 40;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); overflow: hidden;
}
.uploads-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; background: var(--surface-2);
  font-size: 14px; font-weight: 600; border-bottom: 1px solid var(--border);
}
#uploads-list { max-height: 260px; overflow-y: auto; }

.up-row { padding: 9px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
.up-row:last-child { border-bottom: 0; }
.up-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 5px; }
.up-bar { height: 4px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.up-fill { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.up-row.done .up-fill { background: #1a9d5a; }
.up-row.failed .up-fill { background: var(--danger); }
.up-status { font-size: 11.5px; color: var(--muted); margin-top: 4px; display: block; }

/* ── Preview ───────────────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, .72);
  display: grid; place-items: center; padding: 24px;
}
.preview-box {
  background: var(--surface); border-radius: 14px;
  width: min(1100px, 100%); max-height: 90vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.preview-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 14px; font-weight: 600;
}
#preview-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.preview-body { padding: 14px; overflow: auto; display: grid; place-items: center; background: var(--surface-2); }
.preview-body img, .preview-body video { max-width: 100%; max-height: 74vh; border-radius: 8px; }
.preview-body audio { width: 100%; }
.preview-body pre {
  width: 100%; margin: 0; padding: 14px; text-align: left;
  background: var(--surface); border-radius: 8px; overflow: auto;
  font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; max-height: 72vh;
}
.preview-body iframe { width: 100%; height: 74vh; border: 0; border-radius: 8px; background: #fff; }
.preview-note { color: var(--muted); padding: 40px 20px; text-align: center; }

/* ── Toast ─────────────────────────────────────────────────────────────── */

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: #1b1f27; color: #fff; padding: 11px 18px;
  border-radius: 10px; font-size: 14px; z-index: 60; box-shadow: var(--shadow);
  max-width: 90vw;
}
.toast.error { background: var(--danger); }

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; position: static; display: flex; flex-wrap: wrap; gap: 9px; padding: 12px 16px; }
  .primary-btn, .ghost-btn { width: auto; margin: 0; }
  .storage { width: 100%; margin-top: 10px; }
  .content { padding: 14px 16px 50px; }
  .search-wrap { order: 3; flex-basis: 100%; max-width: none; }
  .topbar { flex-wrap: wrap; }
  .uploads { right: 10px; left: 10px; width: auto; }
}
