/* ── D1 Drive — modern dark glass UI ───────────────────────────────────── */
:root {
  --bg: #070a12;
  --panel: rgba(148, 163, 184, .06);
  --panel-strong: rgba(15, 20, 34, .82);
  --border: rgba(148, 163, 184, .14);
  --text: #e8ecf4;
  --muted: #8b95a9;
  --accent1: #6d5cff;
  --accent2: #22d3ee;
  --grad: linear-gradient(135deg, var(--accent1), var(--accent2));
  --danger: #f43f5e;
  --ok: #34d399;
  --radius: 14px;
  --shadow: 0 10px 40px rgba(2, 6, 18, .55);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}
button { font: inherit; color: inherit; }

/* animated ambient background */
.bg-fx {
  position: fixed; inset: -20%;
  background:
    radial-gradient(42rem 42rem at 18% 12%, rgba(109, 92, 255, .16), transparent 60%),
    radial-gradient(38rem 38rem at 84% 22%, rgba(34, 211, 238, .11), transparent 60%),
    radial-gradient(46rem 46rem at 55% 105%, rgba(109, 92, 255, .10), transparent 60%);
  filter: blur(2px);
  animation: drift 26s ease-in-out infinite alternate;
  pointer-events: none;
}
@keyframes drift {
  from { transform: translate3d(-2%, -1%, 0) scale(1); }
  to   { transform: translate3d(2%, 2%, 0) scale(1.06); }
}

.glass {
  background: var(--panel-strong);
  backdrop-filter: blur(18px) saturate(1.25);
  -webkit-backdrop-filter: blur(18px) saturate(1.25);
  border: 1px solid var(--border);
}

/* ── Layout ── */
#app { display: flex; height: 100vh; }

.sidebar {
  width: 264px; min-width: 264px;
  display: flex; flex-direction: column; gap: 10px;
  padding: 18px 16px;
  z-index: 5;
}
.logo {
  display: flex; align-items: center; gap: 10px;
  font-size: 19px; font-weight: 700; letter-spacing: .2px;
  margin-bottom: 8px;
}
.side-spacer { flex: 1; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

/* storage ring */
.storage { display: flex; gap: 12px; align-items: center; }
.ring-bg { fill: none; stroke: rgba(148,163,184,.15); stroke-width: 9; }
.ring-fg {
  fill: none; stroke: url(#lg); stroke-width: 9; stroke-linecap: round;
  stroke-dasharray: 264; stroke-dashoffset: 264;
  transform: rotate(-90deg); transform-origin: 50% 50%;
  transition: stroke-dashoffset .9s cubic-bezier(.22,1,.36,1);
}
.ring-label { fill: var(--text); font-size: 17px; font-weight: 700; }
.storage-meta { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.storage-meta strong { font-size: 15px; }
.storage-meta span { color: var(--muted); font-size: 12px; }
.storage-meta small { color: var(--muted); opacity: .7; font-size: 10.5px; }

.dav-help { font-size: 12.5px; color: var(--muted); }
.dav-help summary { cursor: pointer; font-weight: 600; color: var(--text); }
.dav-help code {
  display: block; margin-top: 8px; padding: 6px 8px;
  background: rgba(2,6,18,.6); border-radius: 8px;
  font-size: 11.5px; color: var(--accent2); word-break: break-all;
}
.dav-help p { margin: 8px 0 0; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 14px 22px 10px;
}
.crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; min-width: 0; font-size: 16px; font-weight: 600; }
.crumbs a { color: var(--muted); text-decoration: none; padding: 4px 7px; border-radius: 8px; white-space: nowrap; }
.crumbs a:hover { color: var(--text); background: var(--panel); }
.crumbs .sep { color: var(--muted); opacity: .55; padding: 0 2px; user-select: none; }
.crumbs .here { color: var(--text); padding: 4px 7px; }

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

.search-wrap { position: relative; }
.search-wrap svg {
  position: absolute; left: 10px; top: 50%; translate: 0 -50%;
  width: 15px; height: 15px;
  stroke: var(--muted); stroke-width: 2; fill: none; stroke-linecap: round;
}
.search-wrap input {
  width: 220px; padding: 8px 12px 8px 32px;
  background: var(--panel); border: 1px solid var(--border);
  color: var(--text); border-radius: 10px; outline: none;
  transition: border-color .15s, box-shadow .15s, width .2s;
}
.search-wrap input:focus {
  border-color: var(--accent1);
  box-shadow: 0 0 0 3px rgba(109, 92, 255, .18);
  width: 260px;
}
.search-wrap input::placeholder { color: var(--muted); }

select {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 10px; outline: none; cursor: pointer;
}

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--border);
  cursor: pointer; transition: background .15s, transform .1s;
}
.icon-btn:hover { background: rgba(148,163,184,.13); }
.icon-btn:active { transform: scale(.94); }
.icon-btn svg { width: 18px; height: 18px; stroke: var(--text); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.tiny { width: 24px; height: 24px; border: none; background: transparent; font-size: 16px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: 11px;
  padding: 10px 14px; font-weight: 600; cursor: pointer;
  transition: filter .15s, background .15s, transform .08s;
}
.btn:active { transform: scale(.98); }
.btn svg { width: 17px; height: 17px; }
.btn.primary { background: var(--grad); color: white; box-shadow: 0 6px 22px rgba(109, 92, 255, .35); }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: var(--panel); border-color: var(--border); }
.btn.ghost:hover { background: rgba(148,163,184,.13); }
.btn.block { width: 100%; }
.btn.small { padding: 6px 11px; border-radius: 9px; font-size: 13px; }
.btn.danger { background: rgba(244,63,94,.14); border-color: rgba(244,63,94,.35); color: #ff8fa5; }
.btn.danger:hover { background: rgba(244,63,94,.24); }

/* bulk bar */
.bulkbar {
  position: sticky; top: 8px; z-index: 4;
  margin: 4px 22px 0; padding: 9px 14px;
  display: flex; align-items: center; justify-content: space-between;
  border-radius: 12px; animation: rise .18s ease-out;
}
@keyframes rise { from { opacity: 0; translate: 0 6px; } to { opacity: 1; translate: 0 0; } }
.bulk-actions { display: flex; gap: 8px; }

/* content area */
#content { flex: 1; overflow-y: auto; padding: 14px 22px 90px; outline: none; scrollbar-gutter: stable; }
#content::-webkit-scrollbar { width: 10px; }
#content::-webkit-scrollbar-thumb { background: rgba(148,163,184,.18); border-radius: 99px; border: 3px solid transparent; background-clip: content-box; }

.grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  animation: fadein .2s ease-out;
}
@keyframes fadein { from { opacity: 0 } to { opacity: 1 } }

.tile {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 9px;
  padding: 18px 12px 13px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); cursor: pointer; user-select: none;
  transition: transform .14s ease, border-color .14s, box-shadow .14s, background .14s;
}
.tile:hover { transform: translateY(-3px); border-color: rgba(139,124,255,.45); box-shadow: var(--shadow); background: rgba(148,163,184,.09); }
.tile.selected { border-color: var(--accent1); background: rgba(109,92,255,.12); box-shadow: 0 0 0 3px rgba(109,92,255,.16); }
.tile .name {
  max-width: 100%; text-align: center; font-weight: 600; font-size: 13px;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  word-break: break-word;
}
.tile .meta { font-size: 11px; color: var(--muted); }

/* icon tiles */
.ftile {
  width: 58px; height: 58px; border-radius: 15px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; flex: none;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.28), 0 6px 16px rgba(2,6,18,.35);
}
.ftile svg { width: 27px; height: 27px; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.g-folder { background: linear-gradient(135deg, #6d5cff, #9f7cff); }
.g-image  { background: linear-gradient(135deg, #0ea5e9, #22d3ee); }
.g-video  { background: linear-gradient(135deg, #e11d48, #fb7185); }
.g-audio  { background: linear-gradient(135deg, #d97706, #fbbf24); }
.g-pdf    { background: linear-gradient(135deg, #dc2626, #f87171); }
.g-code   { background: linear-gradient(135deg, #059669, #34d399); }
.g-archive{ background: linear-gradient(135deg, #a16207, #d97706); }
.g-doc    { background: linear-gradient(135deg, #2563eb, #60a5fa); }
.g-sheet  { background: linear-gradient(135deg, #047857, #10b981); }
.g-slide  { background: linear-gradient(135deg, #c026d3, #e879f9); }
.g-file   { background: linear-gradient(135deg, #475569, #64748b); }

/* list view */
.list { width: 100%; border-collapse: collapse; }
.list th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); font-weight: 600; padding: 8px 12px;
  border-bottom: 1px solid var(--border); position: sticky; top: 0;
  background: rgba(7,10,18,.85); backdrop-filter: blur(8px);
}
.list td { padding: 9px 12px; border-bottom: 1px solid rgba(148,163,184,.07); }
.list tr.row { cursor: pointer; transition: background .12s; }
.list tr.row:hover { background: rgba(148,163,184,.07); }
.list tr.row.selected { background: rgba(109,92,255,.12); }
.list .cell-name { display: flex; align-items: center; gap: 11px; font-weight: 600; min-width: 0; }
.list .cell-name .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .ftile { width: 34px; height: 34px; border-radius: 10px; }
.list .ftile svg { width: 17px; height: 17px; }
.list td.meta, .list th:nth-child(3), .list th:nth-child(4) { color: var(--muted); font-size: 12.5px; }

/* checkbox */
.pick {
  position: absolute; top: 9px; right: 9px; z-index: 2;
  width: 21px; height: 21px; border-radius: 7px;
  border: 1.5px solid rgba(148,163,184,.5); background: rgba(7,10,18,.55);
  cursor: pointer; opacity: 0; transition: opacity .12s, background .12s;
  display: flex; align-items: center; justify-content: center;
}
.tile:hover .pick, tr.row:hover .pick-cell .pick, .pick.checked { opacity: 1; }
.pick.checked { background: var(--grad); border-color: transparent; }
.pick svg { width: 12px; height: 12px; stroke: white; stroke-width: 3; fill: none; stroke-linecap: round; stroke-linejoin: round; opacity: 0; }
.pick.checked svg { opacity: 1; }
.pick-cell { width: 30px; }
tr .pick { position: static; }

/* kebab menu button on tiles */
.kebab {
  position: absolute; top: 7px; left: 7px; z-index: 2;
  width: 26px; height: 26px; border-radius: 8px; border: none;
  background: rgba(7,10,18,.55); color: var(--text);
  opacity: 0; cursor: pointer; font-size: 15px; line-height: 1;
  transition: opacity .12s, background .12s;
}
.tile:hover .kebab, tr.row:hover .kebab { opacity: 1; }
.kebab:hover { background: rgba(148,163,184,.25); }

/* empty state */
.empty {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 70px 0 40px; color: var(--muted);
  animation: fadein .3s ease-out;
}
.empty p { margin: 14px 0 0; font-size: 17px; font-weight: 700; color: var(--text); }
.empty small { font-size: 12.5px; }

/* skeleton loading */
.skeleton-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); }
.skeleton-tile {
  height: 132px; border-radius: var(--radius);
  background: linear-gradient(100deg, rgba(148,163,184,.07) 40%, rgba(148,163,184,.16) 50%, rgba(148,163,184,.07) 60%);
  background-size: 200% 100%; animation: shimmer 1.1s infinite linear;
}
@keyframes shimmer { to { background-position-x: -200%; } }

/* drag overlay */
#drop-overlay {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: rgba(4, 6, 14, .62); backdrop-filter: blur(6px);
}
.drop-box {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 44px 64px; border-radius: 22px;
  border: 2px dashed rgba(139,124,255,.65);
  color: var(--text); font-size: 19px; font-weight: 700;
  animation: pulse 1.4s ease-in-out infinite;
}
.drop-box svg { width: 46px; height: 46px; stroke: url(#lg); stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
@keyframes pulse { 50% { transform: scale(1.03); } }

/* context menu */
.ctxmenu {
  position: fixed; z-index: 70; min-width: 190px;
  border-radius: 13px; padding: 6px; box-shadow: var(--shadow);
  animation: rise .12s ease-out;
}
.ctxmenu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 11px; border: none; border-radius: 9px;
  background: none; cursor: pointer; text-align: left; font-weight: 500;
}
.ctxmenu button:hover { background: rgba(148,163,184,.12); }
.ctxmenu button.destructive { color: #ff8fa5; }
.ctxmenu hr { border: none; border-top: 1px solid var(--border); margin: 5px 4px; }
.ctxmenu svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* modals */
.modal-back {
  position: fixed; inset: 0; z-index: 80;
  display: flex; align-items: center; justify-content: center;
  background: rgba(4,6,14,.6); backdrop-filter: blur(7px);
  animation: fadein .15s ease-out;
}
.modal {
  width: min(480px, calc(100vw - 40px)); max-height: min(560px, calc(100vh - 80px));
  display: flex; flex-direction: column;
  border-radius: 18px; padding: 20px; box-shadow: var(--shadow);
  animation: pop .18s cubic-bezier(.2,1.4,.4,1);
}
@keyframes pop { from { transform: scale(.93); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal h3 { margin: 0 0 14px; font-size: 17px; }
.modal .body { overflow-y: auto; min-height: 0; }
.modal input[type="text"], .modal input[type="search"] {
  width: 100%; padding: 10px 12px; border-radius: 11px;
  border: 1px solid var(--border); background: rgba(2,6,18,.5);
  color: var(--text); outline: none; font: inherit;
}
.modal input:focus { border-color: var(--accent1); box-shadow: 0 0 0 3px rgba(109,92,255,.18); }
.modal .actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 18px; }
.modal p.msg { color: var(--muted); margin: 0 0 4px; line-height: 1.55; }

/* folder picker */
.folder-pick { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.folder-pick label {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: 10px; cursor: pointer;
  border: 1px solid transparent; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.folder-pick label:hover { background: rgba(148,163,184,.09); }
.folder-pick input { accent-color: var(--accent1); }
.folder-pick label.sel { border-color: var(--accent1); background: rgba(109,92,255,.12); }
.folder-pick svg { width: 17px; height: 17px; flex: none; stroke: var(--accent2); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* preview modal */
.preview-body { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.preview-body img { max-width: 100%; max-height: 56vh; border-radius: 12px; box-shadow: var(--shadow); }
.preview-body video, .preview-body audio { width: 100%; border-radius: 12px; }
.preview-body pre {
  width: 100%; max-height: 52vh; overflow: auto; margin: 0;
  padding: 13px; border-radius: 12px; background: rgba(2,6,18,.6);
  border: 1px solid var(--border); font-size: 12.5px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word;
}
.preview-name { font-size: 13px; color: var(--muted); word-break: break-all; text-align: center; }

/* toasts */
#toasts {
  position: fixed; right: 18px; bottom: 18px; z-index: 90;
  display: flex; flex-direction: column; gap: 9px; max-width: 340px;
}
.toast {
  padding: 11px 15px; border-radius: 12px; font-weight: 500;
  background: var(--panel-strong); border: 1px solid var(--border);
  backdrop-filter: blur(16px); box-shadow: var(--shadow);
  animation: slidein .22s cubic-bezier(.2,1.2,.4,1);
}
.toast.err { border-color: rgba(244,63,94,.5); color: #ffb3c0; }
.toast.ok { border-color: rgba(52,211,153,.45); color: #a7f3d0; }
.toast.out { opacity: 0; translate: 12px 0; transition: all .25s; }
@keyframes slidein { from { opacity: 0; translate: 18px 0; } to { opacity: 1; translate: 0 0; } }

/* upload tray */
#upload-tray {
  position: fixed; right: 18px; bottom: 18px; z-index: 85;
  width: 320px; max-height: 300px; display: flex; flex-direction: column;
  border-radius: 15px; box-shadow: var(--shadow); overflow: hidden;
  animation: rise .2s ease-out;
}
#toasts:not(:empty) + #upload-tray { bottom: 150px; }
#upload-tray header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; font-weight: 700; border-bottom: 1px solid var(--border);
}
#upload-list { overflow-y: auto; padding: 8px 12px 12px; display: flex; flex-direction: column; gap: 10px; }
.up-item { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; }
.up-item .row1 { display: flex; justify-content: space-between; gap: 8px; }
.up-item .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-item .st { color: var(--muted); flex: none; }
.up-item.err .st { color: #ff8fa5; }
.up-bar { height: 5px; border-radius: 99px; background: rgba(148,163,184,.16); overflow: hidden; }
.up-bar i { display: block; height: 100%; width: 0%; background: var(--grad); border-radius: 99px; transition: width .2s; }
.up-item.done .up-bar i { background: var(--ok); }
.up-item.err .up-bar i { background: var(--danger); }

@media (max-width: 860px) {
  #app { flex-direction: column; height: 100dvh; }
  .sidebar {
    width: 100%; min-width: 0; flex-direction: row; flex-wrap: wrap; align-items: center;
    padding: 10px 14px; gap: 8px;
  }
  .logo { margin: 0; font-size: 17px; }
  .btn.block { width: auto; }
  .side-spacer { display: none; }
  .storage { padding: 8px 10px; gap: 8px; }
  .storage svg { display: none; }
  .dav-help { display: none; }
  .topbar { flex-wrap: wrap; padding: 10px 14px 6px; }
  .search-wrap input { width: 150px; }
  .bulkbar { margin: 4px 14px 0; }
  #content { padding: 10px 14px 120px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); }
}
