:root {
  --fg: #1a1a1a;
  --muted: #6b6b6b;
  --bg: #fafafa;
  --card: #fff;
  --border: #e3e3e3;
  --accent: #2563eb;
  --danger: #b91c1c;
  --badge: #fee2e2;
  --badge-fg: #991b1b;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
}
main {
  max-width: 880px;
  margin: 0 auto;
  padding: 24px 16px 80px;
}
.shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 16px 80px;
  display: flex;
  gap: 28px;
  align-items: flex-start;
}
.shell main { padding: 0; margin: 0; flex: 1; min-width: 0; max-width: none; }
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 16px;
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}
.sidebar h2 { font-size: 0.95rem; margin: 0 0 4px; }
.sidebar .hint { color: var(--muted); font-size: 0.8em; margin: 0 0 12px; }
.sidebar-export { margin: 14px 0 0; padding-top: 12px; border-top: 1px solid var(--border); font-size: 0.85em; }
.sidebar-export a { color: var(--muted); text-decoration: none; }
.sidebar-export a:hover { color: var(--accent); text-decoration: underline; }
.tree, .tree ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.tree ul { padding-left: 14px; border-left: 1px dotted var(--border); margin-left: 6px; }
.tree li {
  padding: 3px 6px;
  border-radius: 4px;
  cursor: grab;
  position: relative;
}
.tree li:hover { background: #f5f5f7; }
.tree li.dragging { opacity: 0.4; }
.tree li.current > a { font-weight: 600; color: var(--fg); }
.tree li.inactive > a { color: var(--muted); text-decoration: line-through; }
.tree li.drop-target { background: #e0e7ff; outline: 2px dashed var(--accent); outline-offset: -2px; }
.tree li.drop-above, .tree li.drop-below { position: relative; }
.tree li.drop-above::before,
.tree li.drop-below::after {
  content: "";
  position: absolute;
  left: 0; right: 0;
  height: 3px;
  background: var(--accent);
  border-radius: 2px;
  pointer-events: none;
}
.tree li.drop-above::before { top: -2px; }
.tree li.drop-below::after  { bottom: -2px; }
.tree li a { display: inline-block; padding: 2px 0; }
.tree-root {
  padding: 8px 10px;
  border: 1px dashed var(--border);
  border-radius: 4px;
  color: var(--muted);
  font-size: 0.85em;
  margin-bottom: 10px;
  background: #fafafa;
}
.tree-root.drop-target { background: #e0e7ff; outline: 2px dashed var(--accent); outline-offset: -2px; color: var(--accent); }
@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; position: static; max-height: none; }
}
h1 { margin: 0 0 16px; font-size: 1.75rem; }
h2 { margin: 0 0 12px; font-size: 1.25rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: #f0f0f0; padding: 1px 6px; border-radius: 3px; font-size: 0.9em; }
.muted { color: var(--muted); }
.error { color: var(--danger); background: var(--badge); padding: 8px 12px; border-radius: 4px; }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 24px; background: var(--card); border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 600; color: var(--fg); display: inline-flex; align-items: center; gap: 10px; text-decoration: none; }
.topbar .brand .logo { height: 26px; width: auto; display: block; }
.topbar .brand .brand-text { font-size: 1.05rem; }
.auth-logo { display: flex; justify-content: center; align-items: center; gap: 12px; margin: 0 0 24px; color: var(--fg); }
.auth-logo .logo { height: 44px; width: auto; }
.auth-logo .brand-text { font-size: 1.25rem; font-weight: 600; }
.public-logo { display: flex; justify-content: center; align-items: center; gap: 14px; margin: 0 0 24px; color: var(--fg); }
.public-logo .logo { height: 48px; width: auto; }
.public-logo .brand-text { font-size: 1.35rem; font-weight: 600; }
.topbar nav { display: flex; gap: 14px; align-items: center; }
.topbar nav a { color: var(--fg); }
.topbar nav .account-link { color: var(--muted); text-decoration: none; }
.topbar nav .account-link:hover { color: var(--fg); text-decoration: underline; }
.card.narrow { max-width: 480px; }
.card.notfound { text-align: center; margin: 40px auto; }
.card.notfound h1 { margin: 0 0 12px; }
button, .btn {
  font: inherit; padding: 6px 12px; border: 1px solid var(--border);
  background: var(--card); color: var(--fg); border-radius: 4px; cursor: pointer;
}
button:hover, .btn:hover { background: #f0f0f0; }
button.danger { color: var(--danger); border-color: #fca5a5; }
button.danger:hover { background: #fee2e2; }
button.link { border: 0; padding: 0; background: transparent; color: var(--accent); cursor: pointer; }
.inline { display: inline; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 6px;
  padding: 20px; margin-bottom: 24px;
}
form label { display: block; margin-bottom: 12px; }
form input[type=text], form input[type=email], form input[type=password], form input[type=file] {
  display: block; width: 100%; padding: 8px 10px; margin-top: 4px;
  border: 1px solid var(--border); border-radius: 4px; font: inherit;
}
form button[type=submit] { background: var(--accent); color: #fff; border-color: var(--accent); padding: 8px 16px; }
form button[type=submit]:hover { background: #1e4fc7; }

.list { list-style: none; padding: 0; margin: 0; }
.list li {
  padding: 10px 0; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.list li:last-child { border-bottom: 0; }
.list li.inactive { opacity: 0.6; }

.badge {
  background: var(--badge); color: var(--badge-fg);
  padding: 1px 8px; border-radius: 999px; font-size: 0.75em;
}

.breadcrumbs { margin-bottom: 12px; color: var(--muted); font-size: 0.9em; }
.folder-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 8px; }
.folder-actions { display: flex; gap: 8px; flex-shrink: 0; }
.folder-public-title { margin: 0 0 12px; font-size: 0.9em; }

.title-disclosure {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 14px;
  background: var(--card);
  margin-bottom: 24px;
}
.title-disclosure summary {
  cursor: pointer;
  font-weight: 500;
  padding: 4px 0;
  list-style-position: inside;
}
.title-disclosure[open] summary { margin-bottom: 8px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.title-disclosure .title-form { margin-top: 8px; }
.title-disclosure .title-form input[type=text] { max-width: 480px; }

.qr img { display: block; margin: 12px 0; image-rendering: pixelated; }

.files { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.files th, .files td { padding: 8px 4px; border-bottom: 1px solid var(--border); text-align: left; font-size: 0.95em; }
.files tr.inactive td { opacity: 0.55; }
.files td:nth-child(4), .files td:nth-child(5) { white-space: nowrap; }

/* legacy users-table styles retained for /admin/settings footer-links table */
.users { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.users th, .users td { padding: 8px 4px; border-bottom: 1px solid var(--border); text-align: left; font-size: 0.95em; }
.users input[type=password] { display: inline-block; width: auto; margin: 0 4px 0 0; padding: 4px 8px; }
.users select { padding: 4px 8px; font: inherit; }

.badge.you         { background: #dbeafe; color: #1e40af; }
.badge.role-admin  { background: #fef3c7; color: #92400e; }
.badge.role-editor { background: #e0e7ff; color: #3730a3; }
.badge.pending     { background: #fef9c3; color: #854d0e; }
.badge.active      { background: #dcfce7; color: #166534; }
.badge.inactive    { background: #f1f5f9; color: #64748b; }

.user-list { list-style: none; padding: 0; margin: 0 0 16px; }
.user-row {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 16px;
  margin-bottom: 12px;
  background: var(--card);
}
.user-row.pending  { background: #fffbeb; }
.user-row.inactive { background: #f8fafc; }
.user-row.inactive .user-email { color: var(--muted); }
.user-summary {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
}
.user-meta { min-width: 0; }
.user-email {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-weight: 500; font-size: 1.02em;
}
.user-role select { padding: 4px 8px; font: inherit; }
.user-actions {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 12px;
}
.user-actions form { display: inline-flex; align-items: center; gap: 4px; margin: 0; }
.user-actions .password-form input[type=password] {
  display: inline-block; width: 180px; margin: 0;
  padding: 4px 8px; font: inherit;
}

.inline-check { display: inline-flex; align-items: center; gap: 4px; margin: 0 4px; font-size: 0.85em; color: var(--muted); }
.inline-check input[type=checkbox] { width: auto; margin: 0; }
.invite-link { display: flex; gap: 4px; margin-top: 10px; max-width: 100%; }
.invite-link input[type=text] {
  flex: 1; padding: 4px 8px; border: 1px solid var(--border); border-radius: 4px;
  font: 12px/1.4 ui-monospace, "SF Mono", Menlo, monospace; background: #fff;
  min-width: 0;
}
.invite-link button.copy { padding: 4px 10px; flex-shrink: 0; }
.muted.small { font-size: 0.85em; }

/* file upload — drop zone + selected-files preview */
.upload-form { margin-top: 12px; }
.upload-drop {
  display: block;
  border: 2px dashed var(--border);
  border-radius: 6px;
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  background: #fafafa;
  transition: background 0.1s, border-color 0.1s;
}
.upload-drop strong { display: block; margin-bottom: 4px; }
.upload-drop small { display: block; margin-top: 4px; }
.upload-drop:hover { background: #f5f5f7; border-color: #a3a3a3; }
.upload-drop.dragover { background: #e0e7ff; border-color: var(--accent); }
.upload-drop input[type=file] {
  /* keep accessible to assistive tech but hide visually */
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0,0,0,0);
  border: 0;
}
.upload-preview { list-style: none; padding: 0; margin: 12px 0 0; }
.upload-preview li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
  font-size: 0.9em;
  border-bottom: 1px solid var(--border);
}
.upload-preview li:last-child { border-bottom: 0; }
.upload-preview li > span:first-child { word-break: break-all; }

/* file-type icons */
.file-icon { width: 22px; height: 26px; flex-shrink: 0; vertical-align: middle; }
.file-icon-pdf   { color: #dc2626; }
.file-icon-docx  { color: #2563eb; }
.file-icon-xlsx  { color: #16a34a; }
.file-icon-zip   { color: #ca8a04; }
.file-icon-image { color: #7c3aed; }
.file-icon-doc   { color: #6b7280; }
.file-name { display: inline-flex; align-items: center; gap: 10px; vertical-align: middle; }
.downloads .name { display: inline-flex; align-items: center; gap: 12px; }
.flash { background: #dcfce7; color: #166534; padding: 8px 12px; border-radius: 4px; margin-bottom: 16px; }

/* auth pages */
body.auth main { max-width: 380px; margin-top: 80px; }
body.auth .card { margin: 0; }
.auth-aside { margin: 14px 0 0; font-size: 0.9em; }

/* public download page */
body.public { background: #fff; }
body.public main { max-width: 600px; padding-top: 32px; }
.downloads { list-style: none; padding: 0; margin: 24px 0; }
.downloads li { border-bottom: 1px solid var(--border); }
.downloads a {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 8px; color: var(--fg); text-decoration: none;
  min-height: 56px;
}
.downloads a:hover { background: #f5f7fb; text-decoration: none; }
.downloads .name { font-weight: 500; }
.downloads .size { color: var(--muted); font-size: 0.85em; margin-left: 12px; flex-shrink: 0; }

.footer {
  text-align: center; padding: 24px 16px; color: var(--muted); font-size: 0.85em;
  border-top: 1px solid var(--border); margin-top: 48px;
}
.footer a { color: var(--muted); }

.pw-modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 16px;
}
.pw-modal {
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: 22px 24px; width: 100%; max-width: 420px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.18);
}
.pw-modal-msg { margin: 0 0 6px; font-weight: 600; font-size: 1.02em; }
.pw-modal-sub { margin: 0 0 14px; font-size: 0.9em; }
.pw-modal input[type=password] {
  display: block; width: 100%; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 4px; font: inherit;
  margin-bottom: 14px;
}
.pw-modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

.branding-row { display: flex; gap: 24px; align-items: flex-start; flex-wrap: wrap; }
.branding-preview {
  flex-shrink: 0; padding: 14px 18px; border: 1px solid var(--border); border-radius: 6px;
  background: #fafafa; display: flex; align-items: center; justify-content: center;
  min-width: 140px; min-height: 80px;
}
.branding-preview img { max-width: 180px; max-height: 80px; display: block; }
.branding-preview.favicon { min-width: 80px; min-height: 80px; }
.branding-preview.favicon img { max-width: 48px; max-height: 48px; }
.branding-controls { flex: 1; min-width: 240px; }
.branding-controls form { margin: 0 0 8px; }
.branding-controls .small { font-size: 0.85em; }
