:root {
  --bg: #0f1420;
  --bg2: #161d2e;
  --bg3: #1e2740;
  --border: #2a3554;
  --text: #e8ecf6;
  --muted: #8b96b5;
  --accent: #4f8cff;
  --accent2: #3b6fe0;
  --danger: #e5484d;
  --ok: #30a46c;
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

.hidden { display: none !important; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg3); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 14px; font-size: 14px; cursor: pointer;
  text-decoration: none; user-select: none;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #26314f; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent2); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { padding: 4px 10px; font-size: 13px; border-radius: 7px; }
.btn.icon { padding: 8px 10px; }
.btn.wide { width: 100%; justify-content: center; }
.btn:disabled { opacity: .55; cursor: default; }

input, select {
  background: var(--bg2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 12px; font-size: 14px; outline: none;
  width: 100%;
}
input:focus, select:focus { border-color: var(--accent); }

/* ---------- auth ---------- */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 20% -10%, #1b2a4d 0%, var(--bg) 55%);
}
.auth-card {
  width: 380px; max-width: calc(100vw - 32px);
  background: var(--bg2); border: 1px solid var(--border); border-radius: 16px;
  padding: 32px 28px; display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.logo { font-size: 24px; font-weight: 700; text-align: center; }
.auth-sub { color: var(--muted); text-align: center; margin-bottom: 12px; font-size: 14px; }
.setup-note { color: var(--muted); font-size: 13px; }
.auth-error {
  background: rgba(229,72,77,.12); border: 1px solid rgba(229,72,77,.4);
  color: #ff8a8e; border-radius: 8px; padding: 8px 12px; font-size: 13px;
}

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px; background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; font-size: 17px; white-space: nowrap; }
.search-box { flex: 1; display: flex; align-items: center; gap: 8px; max-width: 520px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.user-chip { color: var(--muted); font-size: 13px; white-space: nowrap; }

/* ---------- stats & filters ---------- */
.stats-bar { padding: 12px 20px 0; color: var(--muted); font-size: 13px; }
.filters { display: flex; gap: 8px; padding: 10px 20px; flex-wrap: wrap; }
.chip {
  background: var(--bg2); border: 1px solid var(--border); color: var(--muted);
  padding: 6px 12px; border-radius: 999px; font-size: 13px; cursor: pointer;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.small { padding: 3px 10px; font-size: 12px; }

/* ---------- dropzone ---------- */
.dropzone {
  margin: 4px 20px 8px; padding: 18px; text-align: center;
  border: 2px dashed var(--border); border-radius: var(--radius);
  color: var(--muted); font-size: 14px; transition: all .15s;
}
.dropzone.dragover { border-color: var(--accent); background: rgba(79,140,255,.08); color: var(--text); }

/* ---------- upload queue ---------- */
.upload-queue { padding: 0 20px; display: flex; flex-direction: column; gap: 8px; }
.up-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 12px; font-size: 13px;
}
.up-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-bar { width: 160px; height: 6px; background: var(--bg3); border-radius: 4px; overflow: hidden; }
.up-fill { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.up-status { width: 70px; text-align: right; color: var(--muted); }
.up-item.done .up-status { color: var(--ok); }
.up-item.error .up-status { color: var(--danger); width: auto; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- file grid ---------- */
.file-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px; padding: 12px 20px 28px;
}
.file-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column; transition: transform .12s, border-color .12s;
}
.file-card:hover { transform: translateY(-2px); border-color: #3c4b76; }
.thumb {
  position: relative; height: 118px; background: var(--bg3);
  display: flex; align-items: center; justify-content: center; font-size: 40px;
  overflow: hidden; cursor: pointer;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.f-name { padding: 8px 10px 2px; font-size: 13px; font-weight: 600; word-break: break-word; line-height: 1.3; }
.f-meta { padding: 0 10px 8px; color: var(--muted); font-size: 12px; }
.f-actions { display: flex; gap: 6px; padding: 0 10px 10px; flex-wrap: wrap; }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; font-size: 15px; }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 0 0 30px; color: var(--muted); }

/* ---------- modals ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(5,8,16,.72);
  display: flex; align-items: center; justify-content: center; z-index: 50;
  padding: 24px;
}
.modal-box {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 14px;
  width: 460px; max-width: 100%; max-height: 92vh; display: flex; flex-direction: column;
  box-shadow: 0 24px 80px rgba(0,0,0,.5);
}
.preview-box { width: min(1100px, 96vw); height: 88vh; }
.confirm-box { width: 380px; padding: 20px; }
.modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.modal-title { flex: 1; font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-head-actions { display: flex; gap: 8px; align-items: center; }
.modal-body { padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-body label { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 5px; }

.hint {
  background: var(--bg3); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; font-size: 13px; color: var(--muted); line-height: 1.55;
}
.hint b { color: var(--text); }
.hint ol { margin: 6px 0 0 18px; }
.cfg-status { font-size: 13px; min-height: 16px; }
.cfg-status.ok { color: var(--ok); }
.cfg-status.err { color: var(--danger); }

.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 0 20px 20px; }

.users-add { display: flex; gap: 8px; flex-wrap: wrap; }
.users-add input, .users-add select { width: auto; flex: 1; min-width: 120px; }
.user-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 4px;
  border-bottom: 1px solid var(--border); font-size: 14px;
}
.user-row .role { color: var(--muted); font-size: 12px; }
.user-row .spacer { flex: 1; }

/* ---------- preview ---------- */
.preview-body {
  flex: 1; overflow: auto; display: flex; flex-direction: column;
  align-items: center; justify-content: center; background: var(--bg);
  position: relative;
}
.preview-body video, .preview-body audio { width: 100%; height: auto; max-height: 100%; outline: none; }
.preview-body video { max-height: calc(88vh - 60px); }
.preview-body img { max-width: 100%; max-height: 100%; object-fit: contain; }
.preview-body .pdf-frame { width: 100%; height: 100%; border: 0; }
.pv-note { color: var(--muted); font-size: 12px; padding: 8px; }

.epub-reader { width: 100%; height: 100%; }
.epub-nav { position: absolute; right: 12px; top: 12px; display: flex; gap: 6px; z-index: 5; }

.docx-view {
  background: #fff; color: #222; width: min(860px, 94%); margin: 16px auto;
  padding: 40px 48px; border-radius: 8px; font-size: 15px; line-height: 1.6;
  overflow-wrap: break-word; min-height: 200px;
}
.docx-view.loading { background: var(--bg2); color: var(--muted); }
.docx-view img { max-width: 100%; }
.docx-view table { border-collapse: collapse; }
.docx-view table td, .docx-view table th { border: 1px solid #ccc; padding: 4px 8px; }

.sheet-tabs { display: flex; gap: 6px; padding: 10px 14px 0; flex-wrap: wrap; width: 100%; background: var(--bg2); }
.sheet-holder { width: 100%; min-height: 300px; padding: 14px; overflow: auto; }
.sheet-holder table { border-collapse: collapse; background: #fff; color: #111; font-size: 13px; }
.sheet-holder td { border: 1px solid #d0d7e2; padding: 4px 10px; min-width: 70px; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pptx-view { width: 100%; height: 100%; overflow: auto; background: #101010; }

.text-pre {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 10px;
  padding: 16px; width: min(920px, 94%); margin: 16px auto; overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px;
  white-space: pre-wrap; word-break: break-word;
}

.fallback { text-align: center; color: var(--muted); display: flex; flex-direction: column; gap: 14px; align-items: center; }
.fb-icon { font-size: 52px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg3); border: 1px solid var(--border); color: var(--text);
  padding: 10px 18px; border-radius: 10px; font-size: 14px; z-index: 100;
  box-shadow: 0 10px 40px rgba(0,0,0,.5); max-width: 80vw;
}
.toast.error { border-color: rgba(229,72,77,.55); color: #ff8a8e; }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; }
  .search-box { order: 3; max-width: none; width: 100%; }
  .file-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}
