:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --line: #e3e8ee;
  --line-2: #eef2f6;
  --text: #1f2733;
  --muted: #6b7684;
  --faint: #9aa5b1;
  --accent: #1a73e8;
  --accent-soft: #e8f0fe;
  --accent-hover: #1765cc;
  --danger: #d93636;
  --shadow: 0 1px 2px rgba(16,24,40,0.04), 0 8px 24px -18px rgba(16,24,40,0.25);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.9rem; }
.error { color: var(--danger); font-size: 0.86rem; min-height: 1.1em; margin: 0; }

.brand { display: flex; align-items: center; gap: 0.55rem; font-weight: 600; letter-spacing: -0.01em; }
.brand-mark { font-size: 1.15rem; }

button { cursor: pointer; font: inherit; border: none; border-radius: 8px; }
.btn-primary { background: var(--accent); color: #fff; font-weight: 600; padding: 0.5rem 0.95rem; transition: background .15s; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: var(--surface); border: 1px solid var(--line); color: var(--text); font-weight: 500; padding: 0.5rem 0.8rem; transition: background .15s, border-color .15s; }
.btn-ghost:hover { background: var(--line-2); border-color: var(--faint); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 1.6rem; display: flex; flex-direction: column; gap: 0.8rem; box-shadow: var(--shadow);
}
.login-card .brand { font-size: 1.1rem; }
input[type="text"], input[type="password"] {
  width: 100%; padding: 0.7rem 0.85rem; background: #fff; border: 1px solid var(--line);
  border-radius: 9px; color: var(--text); font-size: 0.98rem; outline: none;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-card button { padding: 0.7rem; background: var(--accent); color: #fff; font-weight: 600; }
.login-card button:hover { background: var(--accent-hover); }

/* App shell */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.7rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.top-actions { display: flex; align-items: center; gap: 0.7rem; }
.search input {
  width: 240px; max-width: 42vw; padding: 0.5rem 0.85rem; border: 1px solid var(--line);
  border-radius: 999px; background: var(--bg); font-size: 0.92rem; outline: none;
}
.search input:focus { border-color: var(--accent); background: #fff; }

.toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: 0.8rem 1.25rem; border-bottom: 1px solid var(--line); background: var(--surface);
  position: sticky; top: 53px; z-index: 9;
}
.crumbs { display: flex; align-items: center; gap: 0.3rem; font-size: 0.95rem; flex-wrap: wrap; min-width: 0; }
.crumbs a { color: var(--muted); text-decoration: none; padding: 0.15rem 0.4rem; border-radius: 6px; cursor: pointer; }
.crumbs a:hover { background: var(--line-2); color: var(--text); }
.crumbs .sep { color: var(--faint); }
.crumbs .current { color: var(--text); font-weight: 600; padding: 0.15rem 0.4rem; }
.tools { display: flex; gap: 0.5rem; }

.surface { position: relative; max-width: 1200px; margin: 0 auto; padding: 1.25rem; min-height: calc(100vh - 120px); }

/* Uploads progress */
.uploads { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1rem; }
.up-row { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 0.6rem 0.85rem; }
.up-top { display: flex; justify-content: space-between; gap: 1rem; font-size: 0.86rem; }
.up-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 6px; border-radius: 4px; background: var(--line-2); margin-top: 0.4rem; overflow: hidden; }
.bar > span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.up-row.done .bar > span { background: #1e8e3e; }
.up-row.err .up-top { color: var(--danger); }

/* Grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 0.9rem; }
.grid.list { grid-template-columns: 1fr; gap: 0.4rem; }

.card {
  position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  overflow: hidden; cursor: pointer; transition: border-color .15s, box-shadow .15s, transform .1s;
  display: flex; flex-direction: column;
}
.card:hover { border-color: #c7d2e0; box-shadow: var(--shadow); }
.thumb {
  height: 112px; display: grid; place-items: center; background: var(--bg); border-bottom: 1px solid var(--line-2);
  overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .ficon { font-size: 2.3rem; }
.ext-badge { font-size: 0.7rem; font-weight: 700; letter-spacing: .04em; color: var(--accent); margin-top: 0.2rem; }
.folder-thumb { background: linear-gradient(180deg,#eef4ff,#e4edfd); }
.card-body { padding: 0.6rem 0.7rem; display: flex; align-items: center; gap: 0.5rem; }
.card-ico { flex: none; font-size: 1.05rem; }
.card-name { font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-sub { font-size: 0.74rem; color: var(--faint); }
.menu-btn {
  position: absolute; top: 6px; right: 6px; width: 28px; height: 28px; border-radius: 7px;
  background: rgba(255,255,255,0.9); border: 1px solid var(--line); color: var(--muted);
  display: none; align-items: center; justify-content: center; font-size: 0.95rem; backdrop-filter: blur(4px);
}
.card:hover .menu-btn { display: flex; }
.menu-btn:hover { color: var(--text); border-color: var(--faint); }

/* List variant */
.grid.list .card { flex-direction: row; align-items: center; border-radius: 10px; }
.grid.list .thumb { width: 52px; height: 52px; flex: none; border: none; border-radius: 8px; margin: 0.35rem; }
.grid.list .thumb .ficon { font-size: 1.4rem; }
.grid.list .ext-badge { display: none; }
.grid.list .card-body { flex: 1; }
.grid.list .menu-btn { position: static; display: flex; margin-right: 0.6rem; opacity: 0.6; }

/* Context menu */
.ctx {
  position: fixed; z-index: 40; background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 10px 30px -8px rgba(16,24,40,0.3); padding: 0.35rem; min-width: 160px;
}
.ctx button {
  display: flex; width: 100%; gap: 0.6rem; align-items: center; background: none; color: var(--text);
  padding: 0.5rem 0.7rem; border-radius: 7px; font-size: 0.9rem; text-align: left;
}
.ctx button:hover { background: var(--line-2); }
.ctx button.danger { color: var(--danger); }

.empty { padding: 3rem 1rem; text-align: center; }

/* Drag overlay */
.drop-overlay {
  position: absolute; inset: 0.5rem; border: 2px dashed var(--accent); border-radius: 16px;
  background: rgba(232,240,254,0.85); display: none; place-items: center; z-index: 20; pointer-events: none;
}
.surface.dragging .drop-overlay { display: grid; }
.drop-msg { font-size: 1.2rem; font-weight: 600; color: var(--accent); }

/* Lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 60; background: rgba(15,20,28,0.92);
  display: grid; place-items: center; padding: 2rem;
}
.lightbox img { max-width: 92vw; max-height: 82vh; border-radius: 8px; box-shadow: 0 20px 60px rgba(0,0,0,0.5); }
.lb-close { position: fixed; top: 1rem; right: 1.2rem; background: rgba(255,255,255,0.12); color: #fff; width: 40px; height: 40px; border-radius: 50%; font-size: 1.1rem; }
.lb-name { position: fixed; bottom: 1.2rem; left: 0; right: 0; text-align: center; color: #e6edf3; font-size: 0.9rem; }

.toast {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%);
  background: #1f2733; color: #fff; padding: 0.65rem 1rem; border-radius: 10px; font-size: 0.9rem;
  box-shadow: 0 10px 30px -10px rgba(0,0,0,0.5); z-index: 80;
}
