:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #1b1f27;
  --muted: #667085;
  --accent: #2f5bea;
  --accent-text: #ffffff;
  --accent-soft: #e8eeff;
  --danger: #d92d20;
  --ok: #12855b;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 16px rgba(16, 24, 40, 0.06);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --surface: #1a1d24;
    --surface-2: #232731;
    --border: #2e3340;
    --text: #e8eaef;
    --muted: #9aa3b2;
    --accent: #6b8cff;
    --accent-text: #0b0f1a;
    --accent-soft: #232c4a;
    --danger: #ff6b5e;
    --ok: #3ccf91;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Buttons and fields */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap;
  color: var(--text); text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn svg { width: 16px; height: 16px; flex: none; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; }
.input {
  width: 100%; padding: 9px 11px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface);
}
.input:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea.input { min-height: 80px; resize: vertical; }
.error-text { color: var(--danger); font-size: 14px; min-height: 20px; }

/* Layout */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; font-size: 14px; }
.tabs { display: flex; gap: 4px; }
.tab { padding: 6px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); }
.tab.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.spacer { flex: 1; }
.main { max-width: 1200px; margin: 0 auto; padding: 20px; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 16px; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; font-size: 17px; font-weight: 600; flex: 1; min-width: 200px; }
.crumbs a { color: var(--text); text-decoration: none; padding: 2px 6px; border-radius: 6px; }
.crumbs a:hover { background: var(--surface-2); }
.crumbs .sep { color: var(--muted); }

/* File grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.tile {
  position: relative; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; cursor: pointer; user-select: none;
}
.tile:hover { box-shadow: var(--shadow); }
.tile.selected { outline: 2px solid var(--accent); border-color: var(--accent); }
.tile .thumb { aspect-ratio: 4 / 3; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; }
.tile .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .thumb svg { width: 44px; height: 44px; color: var(--muted); }
.tile.folder .thumb svg { color: var(--accent); }
.tile .meta { padding: 8px 10px; }
.tile .name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .sub { font-size: 12px; color: var(--muted); }
.tile .check {
  position: absolute; top: 8px; left: 8px; width: 22px; height: 22px; border-radius: 6px;
  background: rgba(255, 255, 255, 0.9); border: 1px solid var(--border); display: grid; place-items: center;
  opacity: 0; transition: opacity 0.1s;
}
.tile:hover .check, .tile.selected .check, .grid.selecting .check { opacity: 1; }
.tile.selected .check { background: var(--accent); border-color: var(--accent); color: #fff; }
.tile .check svg { width: 14px; height: 14px; }

.empty { text-align: center; padding: 60px 20px; color: var(--muted); border: 2px dashed var(--border); border-radius: var(--radius); }
.empty svg { width: 48px; height: 48px; }

/* Drag and drop overlay */
.drop-overlay {
  position: fixed; inset: 0; background: rgba(47, 91, 234, 0.12); border: 3px dashed var(--accent);
  display: grid; place-items: center; z-index: 50; pointer-events: none; font-size: 20px; font-weight: 600; color: var(--accent);
}

/* Upload panel */
.upload-panel {
  position: fixed; right: 20px; bottom: 20px; width: 360px; max-width: calc(100vw - 32px);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); z-index: 40; overflow: hidden;
}
.upload-panel header { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--border); font-weight: 600; }
.upload-panel .body { padding: 12px 14px; }
.upload-panel ul { list-style: none; margin: 8px 0 0; padding: 0; max-height: 160px; overflow: auto; font-size: 13px; }
.upload-panel li { color: var(--danger); padding: 2px 0; }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > div { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
.bar.done > div { background: var(--ok); }

/* Lightbox */
.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.92); z-index: 60; display: flex; flex-direction: column; color: #fff; }
.lightbox header { display: flex; align-items: center; gap: 8px; padding: 10px 14px; }
.lightbox header .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lightbox .btn { background: rgba(255, 255, 255, 0.1); border-color: transparent; color: #fff; }
.lightbox .stage { flex: 1; display: grid; place-items: center; min-height: 0; position: relative; }
.lightbox .stage img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lightbox .nav { position: absolute; top: 50%; transform: translateY(-50%); }
.lightbox .nav.prev { left: 12px; }
.lightbox .nav.next { right: 12px; }

/* Cards (file requests) */
.cards { display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.card h3 { margin: 0 0 4px; font-size: 16px; }
.card .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.badge.on { background: rgba(18, 133, 91, 0.12); color: var(--ok); }
.link-box { display: flex; gap: 8px; margin-top: 10px; }
.link-box .input { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: grid; place-items: center; z-index: 70; padding: 16px; }
.modal { background: var(--surface); border-radius: 14px; width: 460px; max-width: 100%; max-height: calc(100vh - 32px); overflow: auto; padding: 20px; box-shadow: var(--shadow); }
.modal h2 { margin: 0 0 16px; font-size: 18px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* Toasts */
.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast { background: var(--text); color: var(--bg); padding: 9px 14px; border-radius: 8px; box-shadow: var(--shadow); font-size: 14px; }
.toast.error { background: var(--danger); color: #fff; }

/* Login */
.center-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 380px; max-width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.login-card .brand { margin-bottom: 20px; justify-content: center; font-size: 20px; }
.login-card .btn { width: 100%; justify-content: center; padding: 10px; }

/* Public upload page */
.req-wrap { max-width: 640px; margin: 0 auto; padding: 40px 16px; }
.req-wrap h1 { margin: 0 0 6px; font-size: 26px; }
.req-message { white-space: pre-wrap; margin: 0 0 20px; color: var(--muted); }
.dropzone {
  border: 2px dashed var(--border); border-radius: 14px; background: var(--surface);
  padding: 44px 20px; text-align: center; cursor: pointer; transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone svg { width: 48px; height: 48px; color: var(--accent); }
.dropzone .big { font-size: 18px; font-weight: 600; margin: 8px 0 4px; }
.status-card { margin-top: 20px; }
.file-list { list-style: none; padding: 0; margin: 12px 0 0; max-height: 280px; overflow: auto; font-size: 14px; }
.file-list li { display: flex; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--border); }
.file-list li .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-list li.error { color: var(--danger); }
.file-list li.done .s { color: var(--ok); }
.footer-note { margin-top: 32px; text-align: center; font-size: 12px; color: var(--muted); }

@media (max-width: 600px) {
  .topbar { padding: 10px 16px; gap: 10px; flex-wrap: wrap; }
  .main { padding: 16px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
  .btn .label-hide-sm { display: none; }
}
