:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --ink: #1c2434;
  --muted: #6b7688;
  --line: #e3e8f0;
  --brand: #3b6ef6;
  --brand-soft: #eaf0ff;
  --accent: #12b886;
  --danger: #e5484d;
  --shadow: 0 8px 30px rgba(28, 36, 52, 0.07);
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

/* ---------- Auth ---------- */
#auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, #eef2ff 0%, #f8fbff 55%, #f2fbf7 100%);
}
.auth-card {
  width: 100%; max-width: 420px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); padding: 36px 32px;
}
.auth-logo {
  width: 52px; height: 52px; border-radius: 15px;
  background: linear-gradient(135deg, var(--brand), #6d9bff);
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; color: #fff; margin-bottom: 18px;
}
.auth-card h1 { margin: 0 0 8px; font-size: 24px; }
.auth-card p.sub { margin: 0 0 26px; color: var(--muted); font-size: 14px; line-height: 1.6; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 7px; }
.field input {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink); outline: none;
}
.field input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 11px 18px; border: 1px solid transparent; border-radius: 10px;
  background: var(--brand); color: #fff; font-weight: 600; font-size: 14px;
}
.btn:hover { filter: brightness(1.05); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn.danger { background: var(--danger); }
.auth-msg { min-height: 20px; margin-top: 12px; font-size: 13px; color: var(--danger); }

/* ---------- App shell ---------- */
#app-screen { display: none; }
.topbar {
  background: var(--panel); border-bottom: 1px solid var(--line);
  padding: 14px 24px; display: flex; align-items: center; gap: 14px;
  position: sticky; top: 0; z-index: 20;
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.topbar .brand .mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--brand), #6d9bff);
  color: #fff; display: flex; align-items: center; justify-content: center; font-size: 17px;
}
.topbar .spacer { flex: 1; }
.topbar .quota { font-size: 13px; color: var(--muted); }

.layout { display: flex; align-items: stretch; min-height: calc(100vh - 63px); }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 240px; flex: none; background: var(--panel);
  border-right: 1px solid var(--line); padding: 18px 12px;
  position: sticky; top: 63px; height: calc(100vh - 63px); overflow-y: auto;
}
.side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 8px 12px; font-size: 13px; font-weight: 700; color: var(--muted);
}
.side-add {
  width: 28px; height: 28px; border: 1px dashed #b9c6e6; border-radius: 8px;
  background: #fff; color: var(--brand); font-size: 18px; line-height: 1;
}
.side-add:hover { background: var(--brand-soft); border-color: var(--brand); }
.side-list { display: flex; flex-direction: column; gap: 3px; }
.folder-item {
  display: flex; align-items: center; gap: 8px; padding: 9px 10px;
  border-radius: 9px; cursor: pointer; font-size: 14px; color: var(--ink);
  border: 1px solid transparent; transition: .12s; user-select: none;
}
.folder-item:hover { background: #f5f7fc; }
.folder-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.folder-item.drop-target { background: #dce9ff; border: 1px dashed var(--brand); }
.folder-item .ficon { font-size: 16px; width: 20px; text-align: center; }
.folder-item .fname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-item .fcount { font-size: 11px; color: var(--muted); background: #eef1f6; border-radius: 10px; padding: 1px 7px; }
.folder-item.child { padding-left: 20px; font-size: 13px; }
.folder-node { display: block; }
.folder-toggle {
  flex: 0 0 auto; width: 18px; height: 18px; padding: 0; border: 0; border-radius: 4px;
  background: transparent; color: var(--muted); font-size: 11px; line-height: 1;
  cursor: pointer; text-align: center;
}
.folder-toggle:hover { background: #e3e8f0; color: var(--ink); }
.folder-toggle.placeholder { cursor: default; }
.folder-children {
  display: flex; flex-direction: column; gap: 3px;
  margin: 2px 0 6px 19px; padding-left: 10px; border-left: 1px dashed #cbd5e6;
}
.folder-children .folder-item .mini { visibility: hidden; }
.folder-children .folder-item:hover .mini { visibility: visible; }
.folder-item .mini {
  width: 20px; height: 20px; border: 0; background: transparent; color: var(--muted);
  font-size: 12px; border-radius: 5px; padding: 0; line-height: 1; visibility: hidden;
}
.folder-item:hover .mini { visibility: visible; }
.folder-item .mini:hover { background: #e3e8f0; color: var(--ink); }
.side-tip { margin-top: 18px; padding: 0 10px; font-size: 11px; color: #a3adbd; line-height: 1.5; }

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; padding: 26px 28px 70px; max-width: 1280px; }
.stats-grid { display: grid; gap: 16px; margin-bottom: 22px; grid-template-columns: repeat(4, 1fr); }
.stat {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.stat .k { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.stat .v { font-size: 25px; font-weight: 700; letter-spacing: -.5px; }
.stat .v small { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 3px; }

.charts { display: grid; grid-template-columns: 1.1fr 1fr; gap: 16px; margin-bottom: 22px; }
.chart-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
}
.chart-card h3 { margin: 0 0 16px; font-size: 15px; }
.chart-body { display: flex; align-items: center; gap: 22px; min-height: 170px; }
.legend { flex: 1; display: grid; gap: 10px; }
.legend .row { display: flex; align-items: center; gap: 9px; font-size: 13px; }
.legend .dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend .name { flex: 1; color: var(--muted); }
.legend .num { font-weight: 600; }

.uploader {
  background: var(--panel); border: 1px dashed #b9c6e6; border-radius: var(--radius);
  padding: 26px; text-align: center; transition: .18s; box-shadow: var(--shadow); margin-bottom: 22px;
}
.uploader.drag { background: var(--brand-soft); border-color: var(--brand); }
.uploader h3 { margin: 0 0 6px; font-size: 16px; }
.uploader p { margin: 0 0 16px; color: var(--muted); font-size: 13px; }
.upload-row { display: flex; gap: 12px; justify-content: center; align-items: center; flex-wrap: wrap; }
.upload-row select {
  padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink); max-width: 260px;
}
.upload-hint { margin: 12px 0 0 !important; font-size: 12px !important; color: var(--brand) !important; font-weight: 600; }
.progress-wrap { margin-top: 18px; display: grid; gap: 8px; text-align: left; }
.upload-progress { text-align: left; }
.upload-progress .progress-text { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.upload-progress .progress-bar { height: 8px; }
.upload-progress .progress-bar > i { transition: width .15s linear; }
.progress-item { font-size: 12px; color: var(--muted); }
.progress-bar { height: 5px; background: var(--line); border-radius: 6px; overflow: hidden; margin-top: 4px; }
.progress-bar > i { display: block; height: 100%; background: var(--brand); width: 0; transition: width .2s; }

.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.current-crumb {
  font-size: 14px; font-weight: 700; color: var(--ink);
  padding: 8px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 9px;
}
.toolbar input[type=text] {
  flex: 1; min-width: 180px; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 10px; outline: none; background: #fff;
}
.toolbar input[type=text]:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.toolbar select { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
#batch-toggle.active { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 600; }

.file-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.file-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; cursor: grab;
}
.file-card:active { cursor: grabbing; }
.file-card.dragging { opacity: .45; }
.file-card.drop-hover { outline: 2px dashed var(--brand); }
.file-card.selected { outline: 2px solid var(--brand); border-color: var(--brand); }
.file-check {
  position: absolute; top: 8px; left: 8px; z-index: 3;
  width: 20px; height: 20px; cursor: pointer; accent-color: var(--brand);
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.25));
}
.file-grid:not(.batch-mode) .file-check { display: none; }
.file-card .thumb { position: relative; }

/* ---------- Batch action bar ---------- */
.batch-bar {
  display: none; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--brand-soft); border: 1px solid #cddaff; border-radius: 12px;
  padding: 10px 14px; margin-bottom: 16px; position: sticky; top: 70px; z-index: 15;
  box-shadow: var(--shadow);
}
.batch-bar.show { display: flex; }
.batch-bar .spacer { flex: 1; }
.batch-check { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--brand); white-space: nowrap; cursor: pointer; }
.batch-check input { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }
.batch-count { font-size: 13px; font-weight: 700; color: var(--ink); white-space: nowrap; }
.batch-bar select {
  padding: 8px 10px; border: 1px solid #b9c6e6; border-radius: 9px;
  background: #fff; color: var(--ink); max-width: 220px; font-size: 13px;
}
.batch-bar button { padding: 8px 13px; font-size: 13px; }
.thumb {
  height: 132px; background: #f0f3f9; display: flex; align-items: center; justify-content: center;
  font-size: 40px; color: #aab4c6; overflow: hidden; cursor: pointer;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.file-info { padding: 12px; flex: 1; }
.file-name { font-size: 13px; font-weight: 600; word-break: break-all; line-height: 1.4; }
.file-meta { font-size: 11px; color: var(--muted); margin-top: 6px; }
.file-actions { display: flex; gap: 6px; padding: 0 12px 12px; }
.file-actions button {
  flex: 1; padding: 7px 0; font-size: 12px; border: 1px solid var(--line);
  background: #fff; border-radius: 8px; color: var(--ink);
}
.file-actions button.del { color: var(--danger); }
.empty { grid-column: 1 / -1; text-align: center; padding: 60px 20px; color: var(--muted); font-size: 14px; }

/* ---------- Modal ---------- */
.overlay {
  display: none; position: fixed; inset: 0; z-index: 60;
  background: rgba(16, 22, 34, .62); align-items: center; justify-content: center; padding: 24px;
}
.overlay.show { display: flex; }
.modal {
  background: #fff; border-radius: 16px; padding: 24px; width: 100%; max-width: 460px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal.wide { max-width: 920px; }
.modal h3 { margin: 0 0 12px; font-size: 17px; }
.modal p { color: var(--muted); font-size: 14px; line-height: 1.6; }
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.preview-box { min-height: 320px; max-height: 70vh; display: flex; align-items: center; justify-content: center; background: #f2f4f9; border-radius: 10px; overflow: hidden; }
.preview-box img, .preview-box iframe { max-width: 100%; max-height: 70vh; }
.preview-box iframe { width: 100%; height: 70vh; border: 0; }
.preview-loading, .preview-error { color: var(--muted); font-size: 14px; padding: 40px; text-align: center; }
/* Plain-text preview: scrollable, monospace, light background */
.preview-box.text-mode { display: block; background: #fbfcfe; padding: 0; overflow: auto; align-items: initial; justify-content: initial; }
.preview-box .txt-preview {
  margin: 0; padding: 22px 24px; font-family: "SFMono-Regular", Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 13.5px; line-height: 1.7; color: #2a3446; white-space: pre-wrap;
  word-wrap: break-word; word-break: break-word; tab-size: 4; user-select: text;
}
/* Image stage: prev/next navigation + counter. Keep preview image modest for speed. */
.preview-stage { position: relative; }
.preview-box { touch-action: pan-y pinch-zoom; }
.preview-box img { user-select: none; -webkit-user-select: none; }
.preview-box img { max-height: 56vh; object-fit: contain; }
.preview-nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 2;
  width: 42px; height: 42px; border: 0; border-radius: 50%;
  background: rgba(255,255,255,.92); color: #2a3446; box-shadow: 0 3px 12px rgba(0,0,0,.22);
  font-size: 30px; line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center;
  padding: 0 0 4px 0; transition: background .15s, transform .15s;
}
.preview-nav:hover:not(:disabled) { background: #fff; transform: translateY(-50%) scale(1.06); }
.preview-nav:disabled { opacity: .3; cursor: default; }
.preview-nav.prev { left: 12px; }
.preview-nav.next { right: 12px; }
.preview-nav.hidden { display: none; }
.preview-counter {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); z-index: 2;
  background: rgba(28,36,52,.72); color: #fff; font-size: 12px; line-height: 1;
  padding: 6px 12px; border-radius: 20px; pointer-events: none;
}
.preview-counter.hidden { display: none; }

.toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%) translateY(20px);
  background: #1c2434; color: #fff; padding: 11px 20px; border-radius: 10px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: .25s; z-index: 80;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- View switcher ---------- */
.view-switch {
  display: flex; gap: 6px; padding: 0 4px 14px; margin-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.view-btn {
  flex: 1; padding: 9px 6px; border: 1px solid transparent; border-radius: 9px;
  background: transparent; color: var(--muted); font-size: 12px; font-weight: 600; white-space: nowrap;
}
.view-btn:hover { background: #f5f7fc; }
.view-btn.active { background: var(--brand-soft); color: var(--brand); border-color: #d6e2ff; }

/* ---------- Notes: gate / unlock ---------- */
.notes-gate {
  min-height: 62vh; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.gate-card {
  width: 100%; max-width: 440px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 20px; box-shadow: var(--shadow); padding: 38px 34px; text-align: center;
}
.gate-icon {
  width: 60px; height: 60px; border-radius: 17px; margin: 0 auto 18px;
  background: linear-gradient(135deg, #f59e0b, #e5484d);
  display: flex; align-items: center; justify-content: center; font-size: 28px; color: #fff;
}
.gate-card h2 { margin: 0 0 10px; font-size: 22px; }
.gate-card p.sub, #gate-desc { color: var(--muted); font-size: 13px; line-height: 1.7; margin: 0 0 26px; text-align: left; }
.gate-card .field { text-align: left; }
.gate-foot { margin-top: 16px; font-size: 12px; color: #a3adbd; line-height: 1.6; }
.gate-foot a { color: var(--danger); cursor: pointer; text-decoration: underline; }

/* ---------- Notes: home / list ---------- */
.notes-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.notes-head h2 { margin: 0 0 6px; font-size: 22px; }
.notes-head p { margin: 0; color: var(--muted); font-size: 13px; }
.notes-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.notes-toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.notes-toolbar input[type=text] {
  flex: 1; min-width: 180px; padding: 11px 14px; border: 1px solid var(--line);
  border-radius: 10px; outline: none; background: #fff;
}
.notes-toolbar input[type=text]:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.auto-lock-hint { font-size: 12px; color: var(--muted); white-space: nowrap; }
.notes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.note-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 13px;
  padding: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; min-height: 150px;
  border-left: 4px solid var(--accent);
}
.note-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.note-card h3 { margin: 0; font-size: 15px; word-break: break-all; line-height: 1.4; }
.note-card .note-date { font-size: 11px; color: var(--muted); white-space: nowrap; }
.note-card .note-body {
  margin: 12px 0; font-size: 13px; color: #48536a; line-height: 1.6; white-space: pre-wrap;
  word-break: break-all; flex: 1; max-height: 130px; overflow: hidden;
}
.note-card .note-body.hidden-content { color: #b2bbc9; letter-spacing: 2px; font-family: monospace; }
.note-card-actions { display: flex; gap: 6px; }
.note-card-actions button {
  flex: 1; padding: 7px 0; font-size: 12px; border: 1px solid var(--line);
  background: #fff; border-radius: 8px; color: var(--ink);
}
.note-card-actions button:hover { background: #f5f7fc; }
.note-card-actions button.del { color: var(--danger); }
.note-empty { grid-column: 1 / -1; text-align: center; padding: 70px 20px; color: var(--muted); font-size: 14px; }
.note-textarea {
  width: 100%; min-height: 200px; padding: 12px 14px; border: 1px solid var(--line);
  border-radius: 10px; outline: none; background: #fff; color: var(--ink);
  font-family: inherit; font-size: 14px; line-height: 1.6; resize: vertical;
}
.note-textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }

/* ---------- Notes: view all ---------- */
.note-view-modal { max-height: 88vh; display: flex; flex-direction: column; }
.note-view-modal > p { margin: 0 0 14px; color: var(--muted); font-size: 12px; }
.note-view-list {
  flex: 1; min-height: 100px; max-height: 58vh; overflow-y: auto;
  display: grid; gap: 10px; padding: 2px 4px 2px 0;
}
.note-view-item {
  border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: 10px; padding: 14px 16px; background: #fafbfe;
}
.note-view-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.note-view-head h4 { margin: 0; font-size: 15px; word-break: break-all; }
.note-view-meta { font-size: 11px; color: var(--muted); }
.note-view-content {
  margin-top: 10px; font-size: 13px; line-height: 1.7; color: #3d4658;
  white-space: pre-wrap; word-break: break-all; user-select: text;
}
.note-view-index { color: var(--brand); font-weight: 700; margin-right: 6px; }

/* ---------- Security log ---------- */
.seclog-list { max-height: 56vh; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; background: #fafbfc; }
.seclog-loading { padding: 30px; text-align: center; color: var(--muted); font-size: 14px; }
.seclog-row {
  display: flex; align-items: flex-start; gap: 12px; padding: 11px 14px;
  border-bottom: 1px solid var(--line); font-size: 13px;
}
.seclog-row:last-child { border-bottom: 0; }
.seclog-badge {
  flex: 0 0 auto; min-width: 74px; text-align: center; padding: 3px 7px; border-radius: 6px;
  font-size: 12px; font-weight: 600; color: #fff; background: #8b95a7;
}
.seclog-badge.ok { background: #12b886; }
.seclog-badge.warn { background: #f59e0b; }
.seclog-badge.bad { background: #e03131; }
.seclog-body { flex: 1; min-width: 0; }
.seclog-detail { color: var(--ink); line-height: 1.5; }
.seclog-meta { color: var(--muted); font-size: 12px; margin-top: 3px; word-break: break-all; }
.seclog-empty { padding: 30px; text-align: center; color: var(--muted); }

/* ---------- Responsive ---------- */
/* Top-bar action buttons wrap icon + label so labels can hide on small screens. */
.top-actions { display: flex; align-items: center; gap: 8px; }
.top-btn { gap: 6px; }
.tb-ico { font-size: 15px; line-height: 1; }

@media (max-width: 980px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .charts { grid-template-columns: 1fr; }
}

/* Tablet */
@media (max-width: 820px) {
  .topbar { padding: 12px 16px; gap: 10px; }
  .topbar .quota { display: none; }
}

/* Phone */
@media (max-width: 640px) {
  html { -webkit-text-size-adjust: 100%; }
  body { font-size: 14px; }

  /* Top bar: icon-only actions, brand kept compact */
  .topbar { padding: 10px 12px; gap: 8px; }
  .topbar .brand { font-size: 15px; gap: 7px; }
  .topbar .brand .mark { width: 30px; height: 30px; font-size: 15px; border-radius: 8px; }
  .top-actions { gap: 6px; }
  .top-btn { padding: 8px 10px; min-width: 38px; justify-content: center; }
  .tb-text { display: none; }
  .tb-ico { font-size: 17px; }

  /* Layout: visual data first, then category directory, then files */
  .layout {
    flex-direction: column; align-items: stretch;
    padding: 12px 12px 64px;
  }
  /* Promote the stats/charts and file sections into the column flex container
     so they can be reordered without changing desktop markup. */
  .main, #files-view { display: contents; }
  #notes-view { order: 8; }

  .stats-grid { order: 1; gap: 10px; margin: 0 0 12px; }
  .sidebar {
    order: 3; width: 100%; height: auto; position: static; overflow: visible;
    background: var(--panel); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 12px; margin: 0 0 12px;
  }
  .charts { order: 2; gap: 12px; margin: 0 0 12px; }
  .view-switch { margin-bottom: 10px; padding-bottom: 10px; }
  .view-btn { font-size: 12px; padding: 10px 6px; }
  .side-head { padding-bottom: 8px; }
  .side-list { flex-direction: column; flex-wrap: nowrap; gap: 4px; }
  .folder-node { width: 100%; }
  .folder-item { padding: 8px 10px; font-size: 13px; border: 1px solid var(--line); }
  .folder-item.child { padding-left: 8px; font-size: 12px; }
  .folder-children { margin: 3px 0 5px 20px; padding-left: 8px; }
  .folder-item .fcount { display: none; }
  .side-tip { display: none; }
  .notes-head-actions { width: 100%; }

  .stat { padding: 14px; }
  .stat .k { font-size: 11px; }
  .stat .v { font-size: 21px; }
  .chart-card { padding: 16px; }
  .chart-body { flex-direction: column; gap: 14px; min-height: 0; }
  #donut svg { width: 130px; height: 130px; }
  .legend { width: 100%; }

  .uploader { order: 4; padding: 20px 16px; margin: 0 0 12px; }
  .uploader h3 { font-size: 15px; }
  .uploader p { font-size: 12px; line-height: 1.5; }
  .upload-row { flex-direction: column; }
  .upload-row select { width: 100%; max-width: none; }

  .toolbar { order: 5; gap: 8px; margin: 0 0 12px; }
  .toolbar input[type=text] { flex: 1 1 100%; min-width: 0; width: 100%; }
  .toolbar select { flex: 1; min-width: 0; }

  .batch-bar { order: 6; gap: 8px; top: 56px; padding: 10px; }
  .batch-scope { flex: 1 1 100%; font-size: 12px; color: var(--muted); }
  .batch-bar .spacer { display: none; }
  .batch-check, .batch-count { flex: 1 1 auto; }
  .batch-bar select { flex: 1 1 100%; max-width: none; }
  .batch-bar button { flex: 1 1 45%; }

  .file-grid { order: 7; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .thumb { height: 112px; font-size: 34px; }
  .file-info { padding: 10px; }
  .file-actions { padding: 0 10px 10px; }

  .notes-grid { grid-template-columns: 1fr; }
  .notes-toolbar { flex-wrap: wrap; }
  .notes-toolbar input[type=text] { flex: 1 1 100%; min-width: 0; }
  .notes-head h2 { font-size: 20px; }
  .note-view-item { padding: 12px; }
  .note-view-list { max-height: 52vh; }
  .gate-card { padding: 30px 22px; }
  .gate-card h2 { font-size: 20px; }

  /* Modals: fill screen comfortably, scroll if tall */
  .overlay { padding: 10px; }
  .modal { padding: 18px 16px; border-radius: 14px; max-height: 92vh; overflow-y: auto; }
  .modal.wide { max-width: 100%; }
  .modal h3 { font-size: 16px; }
  .modal .actions { flex-wrap: wrap; }
  .modal .actions .btn { flex: 1 1 auto; }
  .preview-box { min-height: 220px; }
  .preview-box img, .preview-box iframe { max-height: 52vh; }
  .preview-box iframe { height: 52vh; }
  .preview-nav { width: 36px; height: 36px; font-size: 26px; }
  .preview-nav.prev { left: 6px; }
  .preview-nav.next { right: 6px; }

  .seclog-row { gap: 8px; padding: 10px; }
  .seclog-badge { min-width: 60px; font-size: 11px; }

  .auth-card { padding: 28px 22px; }
  .auth-card h1 { font-size: 22px; }
  .toast { left: 16px; right: 16px; text-align: center; }
}

/* Very narrow phones */
@media (max-width: 360px) {
  .topbar .brand-text { display: none; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .file-grid { grid-template-columns: 1fr 1fr; }
}
