:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --border: #e3e6ea;
  --text: #1f2329;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-d: #1d4ed8;
  --danger: #dc2626;
  --sel: #e8f0fe;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); }
.spacer { flex: 1; }

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 700; font-size: 16px; }
.search {
  width: 280px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.select {
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}
.badge {
  background: #111827;
  color: #fff;
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 11px;
  letter-spacing: .5px;
}

/* Buttons */
.btn {
  border: 1px solid var(--border);
  background: #fff;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
.btn:hover { background: #f0f2f5; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-d); }
.btn.danger { color: var(--danger); border-color: #f3c7c7; }
.btn.danger:hover { background: #fdeaea; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 5px 9px; font-size: 12px; }
.icon-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 16px;
  color: var(--muted);
  padding: 2px 6px;
  border-radius: 6px;
}
.icon-btn:hover { background: #eef0f3; color: var(--text); }

/* Layout */
.layout { display: flex; height: calc(100vh - 53px); }
.sidebar {
  width: 240px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 8px;
}
.side-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: .5px;
  padding: 6px 8px;
}
.folder-tree { list-style: none; margin: 0; padding: 0; }
.folder-tree li { list-style: none; }
.tree-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
}
.tree-row:hover { background: #f0f2f5; }
.tree-row.active { background: var(--sel); color: var(--accent-d); font-weight: 600; }
.tree-row .del {
  margin-left: auto;
  visibility: hidden;
  color: var(--muted);
}
.tree-row:hover .del { visibility: visible; }
.tree-children { padding-left: 14px; }

.main { flex: 1; overflow-y: auto; padding: 16px 20px; }
.main-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 10px;
}
.main-head h2 { margin: 0; font-size: 18px; }
#adminTools { display: flex; gap: 8px; }

.selection-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--sel);
  border: 1px solid #cfe0fb;
  padding: 8px 12px;
  border-radius: 8px;
  margin-bottom: 10px;
}
.selection-bar .hint { color: var(--muted); margin-left: auto; font-size: 12px; }

/* Notes table */
table.notes { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.notes th, .notes td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.notes th { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); background: #fbfbfc; }
.notes tbody tr { cursor: pointer; }
.notes tbody tr:hover { background: #f7f9fc; }
.notes tbody tr.selected { background: var(--sel); }
.col-sel { width: 34px; }
.col-num { width: 150px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.col-subj { width: 120px; }
.col-actions { width: 90px; text-align: right; }
.num-pill { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: #eef2ff; color: #3730a3; padding: 2px 7px; border-radius: 6px; }
.subj-tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; }
.subj-0 { background: #e0f2fe; color: #075985; }
.subj-1 { background: #dcfce7; color: #166534; }
.subj-2 { background: #fae8ff; color: #86198f; }
.subj-3 { background: #fef3c7; color: #92400e; }
.title-link { color: var(--accent-d); text-decoration: none; font-weight: 600; }
.title-link:hover { text-decoration: underline; }
.empty { color: var(--muted); padding: 30px; text-align: center; }

/* Modals */
.modal {
  position: fixed; inset: 0;
  background: rgba(17, 24, 39, .45);
  display: flex; align-items: center; justify-content: center;
  z-index: 50; padding: 20px;
}
.modal-box {
  background: #fff; border-radius: 12px; width: 460px; max-width: 100%;
  padding: 18px; box-shadow: 0 20px 50px rgba(0,0,0,.25);
  max-height: 90vh; display: flex; flex-direction: column;
}
.modal-box.small { width: 360px; }
.modal-box.large { width: 860px; }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; gap: 10px; }
.modal-head h3 { margin: 0; }
.modal-head-actions { display: flex; gap: 6px; align-items: center; }
.modal-foot { margin-top: 14px; display: flex; justify-content: flex-end; gap: 8px; }
.field { display: block; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.field input, .field select {
  display: block; width: 100%; margin-top: 4px;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; color: var(--text);
}
.title-input { font-size: 18px; font-weight: 700; border: none; padding: 0; width: 100%; }
.title-input:disabled, .num-input:disabled { background: transparent; color: var(--text); }
.meta-row { display: flex; gap: 14px; align-items: center; margin-top: 6px; }
.num-input { border: 1px solid var(--border); border-radius: 6px; padding: 2px 6px; width: 200px; font-family: ui-monospace, monospace; }

/* Document content */
.doc-content { overflow-y: auto; padding: 14px 4px; line-height: 1.6; }
.doc-content img { max-width: 100%; }
.doc-content table { border-collapse: collapse; }
.doc-content td, .doc-content th { border: 1px solid #ccc; padding: 4px 8px; }
#vEditor { height: 50vh; }
.ql-container { font-size: 14px; }

.review-note {
  background: #fef9e7;
  border: 1px solid #f7e3a1;
  color: #8a6d1b;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12.5px;
  margin: 0 0 12px;
}
.pending-row { background: #fffdf5; }

/* Toast */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #111827; color: #fff; padding: 10px 16px; border-radius: 8px;
  z-index: 100; font-size: 13px;
}
.toast.error { background: var(--danger); }
