:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --danger: #dc2626;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 10px 28px rgba(16, 24, 40, 0.12);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container { width: min(1120px, 92vw); margin: 0 auto; }

main.container { flex: 1; }

.hidden { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
}

.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-sm);
}

.brand-name { font-weight: 800; font-size: 17px; letter-spacing: -0.02em; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, transform 0.08s, box-shadow 0.15s;
  user-select: none;
}

.btn:active { transform: translateY(1px); }

.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }

.btn.ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn.ghost:hover { background: #f3f4f6; }

.btn.danger { background: var(--surface); border-color: #fecaca; color: var(--danger); }
.btn.danger:hover { background: #fef2f2; }

.btn.small { padding: 6px 12px; font-size: 13px; border-radius: 8px; }

.btn.block { width: 100%; }

.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ---------- Hero / search ---------- */
.hero { margin: 36px 0 24px; }

.hero h1 { margin: 0 0 6px; font-size: 30px; font-weight: 800; letter-spacing: -0.03em; }

.hero .sub { margin: 0 0 18px; color: var(--muted); font-size: 15px; max-width: 640px; }

.searchbar {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 16px;
  color: var(--muted);
  box-shadow: var(--shadow-sm);
}

.searchbar:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15); }

.searchbar input {
  border: 0;
  outline: 0;
  flex: 1;
  font: inherit;
  font-size: 14.5px;
  color: var(--ink);
  background: transparent;
}

.count { color: var(--muted); font-size: 13px; margin: 12px 2px 0; }

/* ---------- File grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 18px;
  margin-bottom: 24px;
}

.file-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 10px;
  cursor: pointer;
  transition: transform 0.16s, box-shadow 0.16s, border-color 0.16s;
}

.file-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: #d6d9e0;
}

.file-top { display: flex; align-items: center; justify-content: space-between; }

.file-icon {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 12.5px;
  letter-spacing: 0.04em;
}

.file-icon.sm { width: 32px; height: 32px; border-radius: 8px; font-size: 9.5px; }

.file-icon.pdf  { background: #fee2e2; color: #dc2626; }
.file-icon.html { background: #e0e7ff; color: #4338ca; }
.file-icon.pptx { background: #fef3c7; color: #b45309; }

.file-name {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.file-meta { margin: 0; color: var(--muted); font-size: 12.5px; }

.file-actions { display: flex; gap: 8px; margin-top: auto; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  text-transform: capitalize;
}

.badge.pub  { background: #dcfce7; color: #15803d; }
.badge.priv { background: #fef9c3; color: #a16207; }

/* ---------- Empty state ---------- */
.empty {
  border: 2px dashed #d1d5db;
  border-radius: 16px;
  padding: 52px 24px;
  text-align: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.5);
}

.empty.slim { border: 0; padding: 40px 20px; background: transparent; }

.empty-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 12px;
  border-radius: 18px;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
}

.empty h3 { margin: 0 0 4px; color: var(--ink); }
.empty p { margin: 0; font-size: 14px; }

/* ---------- Admin layout ---------- */
.admin-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 20px;
  align-items: start;
  margin-bottom: 32px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.upload-card { padding: 20px; }
.upload-card h2, .table-head h2 { margin: 0 0 14px; font-size: 16px; font-weight: 700; }

.dropzone {
  border: 2px dashed #cbd0da;
  border-radius: 12px;
  padding: 26px 16px;
  text-align: center;
  cursor: pointer;
  color: var(--muted);
  transition: border-color 0.15s, background 0.15s;
}

.dropzone:hover, .dropzone.drag, .dropzone:focus-visible {
  border-color: var(--accent);
  background: #f7f7ff;
  outline: none;
}

.dropzone p { margin: 6px 0 0; font-size: 14px; color: var(--ink); }
.dropzone .hint { color: var(--muted); font-size: 12.5px; }

.dz-icon { color: var(--accent); }

.chosen {
  margin-top: 12px !important;
  display: inline-block;
  background: var(--accent-soft);
  color: #3730a3;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px !important;
  font-weight: 600;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.vis-group { border: 0; padding: 0; margin: 16px 0; }

.vis-group legend { font-size: 13px; font-weight: 700; padding: 0; margin-bottom: 8px; }

.radio {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.radio:hover { border-color: #c7cbd4; }

.radio:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }

.radio input { margin-top: 3px; accent-color: var(--accent); }

.radio span { display: flex; flex-direction: column; }
.radio strong { font-size: 14px; }
.radio small { color: var(--muted); font-size: 12.5px; }

/* ---------- Table ---------- */
.table-card { overflow: hidden; }

.table-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 0;
}

.table-head .count { margin: 0; }

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }

th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 700;
  padding: 14px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

td {
  padding: 13px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  vertical-align: middle;
  white-space: nowrap;
}

tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafafa; }

.cell-name { display: flex; align-items: center; gap: 10px; }

.cell-name .nm {
  font-weight: 600;
  max-width: 210px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.th-actions, .cell-actions { text-align: right; white-space: nowrap; }

.cell-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ---------- Footer ---------- */
footer {
  padding: 26px 0 34px;
  color: var(--muted);
  font-size: 13px;
}

footer p { margin: 0; }

/* ---------- Modals ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.55);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 20px;
}

.modal {
  background: var(--surface);
  border-radius: 16px;
  padding: 26px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-md);
}

.modal h2 { margin: 0 0 4px; font-size: 18px; }
.modal .sub { margin: 0 0 18px; color: var(--muted); font-size: 13.5px; }

.field { display: block; font-size: 13px; font-weight: 600; margin-bottom: 14px; }

.field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  font-size: 14.5px;
  font-weight: 400;
  margin-top: 6px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15); }

.form-error {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13.5px;
  margin-bottom: 14px;
}

.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }

/* ---------- Viewer ---------- */
.viewer {
  background: var(--surface);
  border-radius: 16px;
  overflow: hidden;
  width: min(1060px, 94vw);
  height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-md);
}

.viewer-bar {
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--line);
}

.viewer-title {
  flex: 1;
  font-weight: 600;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewer iframe { flex: 1; width: 100%; border: 0; background: #fff; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 10px);
  background: #111827;
  color: #fff;
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  z-index: 200;
  opacity: 0;
  transition: opacity 0.22s, transform 0.22s;
  max-width: 88vw;
  pointer-events: none;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #b91c1c; }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .admin-layout { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .hero h1 { font-size: 24px; }
  .topbar-inner { height: auto; padding: 10px 0; flex-wrap: wrap; }
  .cell-name .nm { max-width: 160px; }
}

/* ---------- Groups ---------- */
.left-stack { display: flex; flex-direction: column; gap: 20px; }

.groups-card { padding: 20px; }

.gtree-new { display: flex; gap: 8px; margin-bottom: 14px; }

.gtree-new input {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  font-size: 14px;
  outline: none;
  min-width: 0;
}

.gtree-new input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15); }

.gtree-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 6px;
  background: #fafafd;
}

.gtree-name { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }

.gtree-count {
  font-size: 11.5px;
  color: var(--muted);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 1px 8px;
}

.gtree-actions { margin-left: auto; display: flex; gap: 4px; flex-shrink: 0; }

.field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  font-size: 14.5px;
  font-weight: 400;
  margin-top: 6px;
  outline: none;
  background: var(--surface);
  cursor: pointer;
}

.field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15); }

.group-select {
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  background: var(--surface);
  cursor: pointer;
  max-width: 160px;
}

.group-select:focus { border-color: var(--accent); outline: none; }

/* Dashboard group sections */
#groupsArea { display: flex; flex-direction: column; gap: 26px; margin-bottom: 24px; }

.group-section {
  margin-left: calc(var(--depth, 0) * 22px);
  border-left: 3px solid #e0e7ff;
  padding-left: 18px;
}

.group-section .group-section { margin-top: 18px; }

.group-title {
  font-size: 17px;
  font-weight: 750;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
}

.group-chevron { color: var(--accent); font-size: 13px; }

.group-count {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 2px 9px;
}

.group-count:empty { display: none; }
