/* ── CSS Variables ─────────────────────────────────────────── */
:root {
  --color-nav:           #1e2a3a;
  --color-nav-border:    #2d3f52;
  --color-primary:       #2e5fa0;
  --color-primary-hover: #244e86;
  --color-accent:        #0ea5e9;
  --color-bg:            #f3f4f6;
  --color-surface:       #ffffff;
  --color-border:        #e5e7eb;
  --color-text:          #111827;
  --color-text-muted:    #6b7280;
  --color-shadow:        rgba(46, 95, 160, .10);
  --radius:              6px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-nav:           #0d1117;
    --color-nav-border:    #1c2330;
    --color-primary:       #4d7ec0;
    --color-primary-hover: #3d6aab;
    --color-accent:        #60a5fa;
    --color-bg:            #18181b;
    --color-surface:       #27272a;
    --color-border:        #3f3f46;
    --color-text:          #f4f4f5;
    --color-text-muted:    #a1a1aa;
    --color-shadow:        rgba(0, 0, 0, .35);
  }
}

/* ── Reset & Base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  margin: 0;
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.6;
  font-size: 1rem;
}

h1, h2, h3 { margin-top: 0; line-height: 1.25; }
h1 { font-size: 1.5rem; margin-bottom: 1rem; }
h2 { font-size: 1.15rem; margin-bottom: .75rem; }
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--color-border); border-radius: 3px; padding: 1px 4px; font-size: .875em; }

/* ── Topbar / Navigation ────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .75rem 1.25rem;
  background: var(--color-nav);
  border-bottom: 1px solid var(--color-nav-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar .brand {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  text-decoration: none;
}

.topbar .brand img {
  height: 2.2rem;
  width: auto;
  display: block;
}

.topbar .brand:hover { text-decoration: none; opacity: .85; }

.nav-toggle {
  display: none;
  margin-left: auto;
  background: transparent;
  border: 1px solid rgba(255,255,255,.3);
  color: #fff;
  padding: .35rem .6rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}

.nav-toggle:hover { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.5); }

.hamburger-icon { display: block; }

.bar {
  transition: transform 0.25s cubic-bezier(.4,0,.2,1), opacity 0.2s ease;
  transform-box: fill-box;
  transform-origin: center;
}

.nav-toggle.open .bar-top { transform: translateY(7px) rotate(45deg); }
.nav-toggle.open .bar-mid { opacity: 0; transform: scaleX(0); }
.nav-toggle.open .bar-bot { transform: translateY(-7px) rotate(-45deg); }

.nav-links {
  display: flex;
  align-items: center;
  gap: .25rem;
  flex-wrap: wrap;
  margin-left: auto;
}

.nav-links a,
.nav-links button {
  color: rgba(255,255,255,.85);
  text-decoration: none;
  padding: .35rem .65rem;
  border-radius: var(--radius);
  font-size: .9rem;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background .15s, color .15s;
  white-space: nowrap;
}

.nav-links a:hover,
.nav-links button:hover {
  background: rgba(255,255,255,.12);
  color: #fff;
  text-decoration: none;
}

.nav-links a.active { background: rgba(255,255,255,.18); color: #fff; font-weight: 600; }

.nav-links .user-chip {
  color: rgba(255,255,255,.55);
  font-size: .85rem;
  padding: .35rem .5rem;
  border-left: 1px solid rgba(255,255,255,.15);
  margin-left: .25rem;
}

/* Mobile nav */
@media (max-width: 768px) {
  .nav-toggle { display: block; }

  .nav-links {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--color-nav);
    border-top: 1px solid var(--color-nav-border);
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: .5rem 0;
    margin-left: 0;
  }

  .nav-links.open { display: flex; }

  .nav-links a,
  .nav-links button {
    padding: .75rem 1.25rem;
    border-radius: 0;
    font-size: .95rem;
    text-align: left;
  }

  .nav-links .user-chip {
    border-left: none;
    border-top: 1px solid rgba(255,255,255,.1);
    padding: .6rem 1.25rem;
    margin-left: 0;
  }
}

/* ── Page loader (navigation) ───────────────────────────────── */
/* Full-viewport veil with a centred spinner, kept BELOW the sticky navbar
   (z-index:100) so the bar stays visible and the spinner reads as "below" it.
   Shown only while navigating to the next view; hidden by default. */
.page-loader {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  opacity: 0;
  visibility: hidden;
  transition: opacity .15s ease, visibility .15s ease;
}

body.is-navigating .page-loader {
  opacity: .9;
  visibility: visible;
  /* Delay the reveal so instant (cached) navigations never flash a spinner. */
  transition-delay: .12s;
}

.page-loader .spinner {
  width: 2.5rem;
  height: 2.5rem;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: page-spin .7s linear infinite;
}

@keyframes page-spin { to { transform: rotate(360deg); } }

@keyframes page-fade-in { from { opacity: 0; } to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .page-loader .spinner { animation-duration: 1.5s; }
  main { animation: none; }
}

/* ── Main Content ───────────────────────────────────────────── */
main {
  padding: 1.5rem 1.25rem;
  max-width: 1100px;
  margin: 0 auto;
  /* Gently reveal the content area on each view so a finished page eases in
     instead of snapping. Defined in render-blocking CSS, so it only runs once
     the stylesheet is applied — never on truly unstyled markup. */
  animation: page-fade-in .2s ease both;
}

@media (max-width: 480px) {
  main { padding: 1rem .75rem; }
}

/* ── Tables ─────────────────────────────────────────────────── */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  margin-bottom: 1rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  min-width: 480px;
}

thead th {
  background: var(--color-bg);
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--color-text-muted);
  white-space: nowrap;
}

th, td {
  padding: .6rem .85rem;
  border-bottom: 1px solid var(--color-border);
  text-align: left;
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--color-bg); }

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  font-size: .75rem;
  font-weight: 600;
  padding: .15rem .5rem;
  border-radius: 999px;
  line-height: 1.4;
}
.badge-green  { background: #dcfce7; color: #166534; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-indigo { background: #dbeafe; color: #1e40af; }
.badge-gray   { background: var(--color-border); color: var(--color-text-muted); }

@media (prefers-color-scheme: dark) {
  .badge-green  { background: #14532d; color: #86efac; }
  .badge-red    { background: #450a0a; color: #fca5a5; }
  .badge-indigo { background: #1e2a3a; color: #93c5fd; }
  .badge-gray   { background: #374151; color: #9ca3af; }
}

/* ── Buttons ─────────────────────────────────────────────────── */
.btn, button[type=submit] {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  background: var(--color-primary);
  color: #fff;
  border: none;
  padding: .5rem 1.1rem;
  border-radius: var(--radius);
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, opacity .15s;
  min-height: 44px;
  white-space: nowrap;
}

.btn:hover, button[type=submit]:hover {
  background: var(--color-primary-hover);
  text-decoration: none;
  color: #fff;
}

.btn-secondary {
  background: transparent;
  color: var(--color-primary);
  border: 1px solid var(--color-primary);
}

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

.btn-danger {
  background: #dc2626;
}

.btn-danger:hover {
  background: #b91c1c;
}

.btn-sm,
button[type=submit].btn-sm {
  padding: .3rem .7rem;
  font-size: .8rem;
  min-height: 36px;
}

/* ── Forms ───────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 1rem;
}

.form-group label,
form > label {
  display: block;
  font-size: .875rem;
  font-weight: 500;
  color: var(--color-text);
  margin-bottom: .35rem;
}

input[type=text],
input[type=email],
input[type=password],
input[type=search],
select,
textarea {
  display: block;
  width: 100%;
  max-width: 400px;
  padding: .5rem .75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: .95rem;
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
  min-height: 44px;
}

input[type=text]:focus,
input[type=email]:focus,
input[type=password]:focus,
input[type=search]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(46, 95, 160, .15);
}

input[type=checkbox] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--color-primary);
  cursor: pointer;
}

fieldset {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin: .5rem 0 1rem;
  padding: .75rem 1rem 1rem;
  background: var(--color-surface);
}

fieldset legend {
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--color-text-muted);
  padding: 0 .35rem;
}

fieldset label {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .3rem 0;
  font-size: .9rem;
  cursor: pointer;
}

.form-hint {
  font-size: .8rem;
  color: var(--color-text-muted);
  margin-top: .3rem;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-top: 1.25rem;
  flex-wrap: wrap;
}

/* ── Flash / Alert Messages ─────────────────────────────────── */
.flash {
  padding: .75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: .9rem;
  border: 1px solid transparent;
}

.flash.error   { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.flash.success { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.flash.info    { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }

@media (prefers-color-scheme: dark) {
  .flash.error   { background: #450a0a; color: #fca5a5; border-color: #7f1d1d; }
  .flash.success { background: #14532d; color: #86efac; border-color: #166534; }
  .flash.info    { background: #1e2a3a; color: #93c5fd; border-color: #2d3f52; }
}

/* ── Card ────────────────────────────────────────────────────── */
.card {
  background: var(--color-surface);
  padding: 2rem;
  border-radius: 10px;
  box-shadow: 0 4px 18px var(--color-shadow);
  border: 1px solid var(--color-border);
}

/* ── Login / Centered ───────────────────────────────────────── */
.centered {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.login-card {
  background: var(--color-surface);
  padding: 2rem 2.25rem;
  border-radius: 12px;
  box-shadow: 0 6px 24px var(--color-shadow);
  border: 1px solid var(--color-border);
  width: 100%;
  max-width: 360px;
}

.login-card h1 {
  margin-bottom: .25rem;
  font-size: 1.6rem;
  color: var(--color-primary);
  letter-spacing: -.01em;
}

.login-card .subtitle {
  color: var(--color-text-muted);
  font-size: .875rem;
  margin-bottom: 1.5rem;
}

.login-card .login-logo {
  display: block;
  margin-bottom: 1rem;
}

.login-card .login-logo img {
  height: 2.8rem;
  width: auto;
  display: block;
}

.login-card input[type=text],
.login-card input[type=email],
.login-card input[type=password] {
  max-width: 100%;
}

.login-card .btn,
.login-card button[type=submit] {
  width: 100%;
  justify-content: center;
  margin-top: .25rem;
}

/* ── Pagination ─────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-top: 1rem;
  font-size: .875rem;
  color: var(--color-text-muted);
}

/* ── Page header row ────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.page-header h1 { margin-bottom: 0; }

/* ── Info / Definition grid ─────────────────────────────────── */
.data-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: .4rem 1rem;
  font-size: .9rem;
  margin-bottom: 1rem;
}

.data-grid dt { color: var(--color-text-muted); font-weight: 500; }
.data-grid dd { margin: 0; color: var(--color-text); }

/* ── Section panels ─────────────────────────────────────────── */
.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}

.panel h2 { margin-bottom: .85rem; }

/* ── Actions row ────────────────────────────────────────────── */
.actions {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
}

/* ── Error pages ────────────────────────────────────────────── */
.error-page {
  text-align: center;
  padding: 3rem 1rem;
}

.error-page .error-code {
  font-size: 5rem;
  font-weight: 800;
  color: var(--color-primary);
  line-height: 1;
  opacity: .25;
  margin-bottom: .5rem;
}

.error-page h1 {
  font-size: 1.4rem;
  margin-bottom: .5rem;
}

.error-page p { color: var(--color-text-muted); margin-bottom: 1.5rem; }

/* ── Utility ────────────────────────────────────────────────── */
.row { display: flex; align-items: center; gap: .5rem; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.text-muted { color: var(--color-text-muted); font-size: .875rem; }

/* Permission rows whose code is not yet enforced anywhere — dimmed but still assignable. */
.perm-inactive { opacity: .55; }

/* ══════════════════════════════════════════════════════════════
   FILE MANAGER
   ══════════════════════════════════════════════════════════════ */

/* ── Breadcrumb ──────────────────────────────────────────────── */
.breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .15rem;
  font-size: .875rem;
  margin-bottom: 1rem;
  color: var(--color-text-muted);
}

.breadcrumb a { color: var(--color-primary); }
.breadcrumb a:hover { text-decoration: underline; }

.breadcrumb-sep {
  color: var(--color-border);
  user-select: none;
  padding: 0 .1rem;
}

.breadcrumb-current { color: var(--color-text); font-weight: 500; }

/* ── File toolbar ────────────────────────────────────────────── */
.file-toolbar {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  padding: .65rem .85rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.file-toolbar form { display: contents; }

/* ── Quota bar ───────────────────────────────────────────────── */
.quota-bar-wrap {
  margin-bottom: 1rem;
}

.quota-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: .8rem;
  color: var(--color-text-muted);
  margin-bottom: .3rem;
}

.quota-bar {
  height: 6px;
  background: var(--color-border);
  border-radius: 999px;
  overflow: hidden;
}

.quota-bar-fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: 999px;
  transition: width .4s ease;
}

.quota-bar-fill.warning { background: #f59e0b; }
.quota-bar-fill.danger  { background: #dc2626; }

/* ── File list (card-based grid for larger screens) ─────────── */
.file-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-top: 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}

.file-item {
  display: grid;
  grid-template-columns: 2rem 1fr auto auto;
  align-items: center;
  gap: .5rem .75rem;
  padding: .55rem .9rem;
  border-bottom: 1px solid var(--color-border);
  transition: background .1s;
}

.file-item:last-child { border-bottom: none; }
.file-item:hover { background: var(--color-bg); }

.file-item-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.file-item-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: .9rem;
}

.file-item-name a {
  color: var(--color-text);
  font-weight: 500;
}

.file-item-name a:hover { color: var(--color-primary); text-decoration: none; }

.file-item-meta {
  font-size: .78rem;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.file-item-actions {
  display: flex;
  align-items: center;
  gap: .35rem;
  opacity: 0;
  transition: opacity .15s;
}

.file-item:hover .file-item-actions,
.file-item:focus-within .file-item-actions { opacity: 1; }

@media (max-width: 600px) {
  .file-item { grid-template-columns: 2rem 1fr auto; }
  .file-item-meta { display: none; }
  .file-item-actions { opacity: 1; }
}

/* Per-resource permission popover. Renders in the browser top layer, so it is never clipped by
   .file-list's overflow:hidden. Positioned just below its trigger button by app.js (position:fixed
   + viewport-relative left/top), which works across browsers regardless of CSS anchor support. */
.perm-popover {
  position: fixed;
  margin: 0;
  width: 220px;
  padding: .6rem;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .18);
}

/* ── File icons (emoji / unicode as CSS content) ─────────────── */
.icon-folder::before  { content: "📁"; }
.icon-img::before     { content: "🖼️"; }
.icon-pdf::before     { content: "📄"; }
.icon-text::before    { content: "📝"; }
.icon-archive::before { content: "🗜️"; }
.icon-file::before    { content: "📎"; }

/* ── Drop zone ───────────────────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius);
  padding: 2rem 1rem;
  text-align: center;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: border-color .2s, background .2s;
  margin-bottom: 1rem;
  font-size: .9rem;
}

.drop-zone.drag-over {
  border-color: var(--color-primary);
  background: color-mix(in srgb, var(--color-primary) 6%, transparent);
  color: var(--color-primary);
}

.drop-zone input[type=file] {
  display: none;
}

.drop-zone-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
  cursor: pointer;
}

.drop-zone-icon { font-size: 2.5rem; }

/* ── Upload progress ─────────────────────────────────────────── */
.upload-progress-list {
  list-style: none;
  padding: 0;
  margin: .5rem 0 0;
  display: flex;
  flex-direction: column;
  gap: .4rem;
}

.upload-progress-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  font-size: .82rem;
}

.upload-progress-bar-wrap {
  flex: 1;
  height: 5px;
  background: var(--color-border);
  border-radius: 999px;
  overflow: hidden;
}

.upload-progress-bar {
  height: 100%;
  background: var(--color-primary);
  border-radius: 999px;
  width: 0;
  transition: width .2s linear;
}
.upload-progress-bar.error { background: #dc2626; }

.upload-error {
  font-size: .82rem;
  color: #dc2626;
}

/* ── File preview overlay ────────────────────────────────────── */
.preview-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.85);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.preview-overlay.open { display: flex; }

.preview-overlay iframe {
  width: 90vw;
  height: 90vh;
  border: none;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 8px 40px rgba(0,0,0,.5);
}

/* Images preview as a real <img>: centred by the flex overlay, transparent
   background (no white page), scaled to fit while keeping aspect ratio. */
.preview-overlay .preview-img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius);
  box-shadow: 0 8px 40px rgba(0,0,0,.5);
}

/* Inline preview for a single-file view (public folder / share link) */
.file-preview-frame {
  width: 100%;
  height: 70vh;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: #fff;
  margin-bottom: 1rem;
}

/* Inline image preview for a single-file view: centred, no white frame. */
.file-preview-img {
  display: block;
  max-width: 100%;
  max-height: 70vh;
  margin: 0 auto 1rem;
  border-radius: var(--radius);
}

.preview-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: rgba(255,255,255,.15);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: .4rem .8rem;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}

.preview-close:hover { background: rgba(255,255,255,.25); }

/* ── Inline rename input ─────────────────────────────────────── */
.rename-input {
  font-size: .9rem;
  padding: .2rem .4rem;
  border: 1px solid var(--color-primary);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  width: 100%;
  max-width: 300px;
}

/* ── Admin banner ────────────────────────────────────────────── */
.admin-banner {
  background: color-mix(in srgb, var(--color-accent) 12%, transparent);
  border: 1px solid var(--color-accent);
  border-radius: var(--radius);
  padding: .55rem 1rem;
  font-size: .875rem;
  color: var(--color-text);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}

/* ── Share badge ─────────────────────────────────────────────── */
.share-info {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  font-size: .875rem;
}

.share-info .share-token {
  font-family: monospace;
  font-size: .8rem;
  background: var(--color-bg);
  padding: .2rem .5rem;
  border-radius: 4px;
  border: 1px solid var(--color-border);
  word-break: break-all;
  cursor: pointer;
}

/* ── Public share page ───────────────────────────────────────── */
.share-header {
  background: var(--color-nav);
  color: #fff;
  padding: .75rem 1.25rem;
  display: flex;
  align-items: center;
  gap: .75rem;
}

.share-header .brand { font-weight: 700; font-size: 1.1rem; color: #fff; text-decoration: none; display: inline-flex; align-items: center; }
.share-header .brand img { height: 1.8rem; width: auto; display: block; }
.share-header .share-owner { font-size: .85rem; color: rgba(255,255,255,.6); margin-left: auto; }

/* ── Storage overview table ──────────────────────────────────── */
.storage-bar {
  display: inline-block;
  height: 8px;
  min-width: 60px;
  max-width: 120px;
  width: 80px;
  background: var(--color-border);
  border-radius: 999px;
  overflow: hidden;
  vertical-align: middle;
}

.storage-bar-fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: 999px;
}

.storage-bar-fill.warning { background: #f59e0b; }
.storage-bar-fill.danger  { background: #dc2626; }

/* ── Markdown editor / viewer ─────────────────────────────── */
/* The editor is a fixed-height column that fills the viewport (height set in app.js, with an
   80vh fallback): the head stays put and only the panes below it scroll. */
.md-editor-page {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 80vh;
}
.md-editor-page > #mdForm {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

/* Header + collab bar + toolbar: the non-scrolling head of the editor. */
.md-sticky-head {
  flex: none;
  background: var(--color-bg);
  padding-bottom: .6rem;
  margin-bottom: .75rem;
  border-bottom: 1px solid var(--color-border);
}
.md-sticky-head .md-toolbar { margin-bottom: 0; }

.md-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .35rem;
  margin-bottom: .75rem;
}

.md-toolbar-sep {
  width: 1px;
  align-self: stretch;
  background: var(--color-border);
  margin: 0 .25rem;
}

.md-toolbar-tabs {
  display: none;
  margin-left: auto;
  gap: .35rem;
}

.md-editor {
  display: flex;
  gap: 1rem;
  flex: 1 1 auto;
  min-height: 0;
}

.md-editor > .md-source-wrap,
.md-editor > .md-live {
  flex: 1 1 50%;
  min-width: 0;
  min-height: 0;
}

/* Wraps the textarea so the remote-cursor overlay can be absolutely positioned over it. */
.md-source-wrap {
  position: relative;
  display: flex;
}

.md-source {
  flex: 1 1 auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .9rem;
  line-height: 1.5;
  padding: .75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  resize: none;
  width: 100%;
  height: 100%;
}

.md-live {
  overflow: auto;
  height: 100%;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  background: var(--color-surface);
}

/* Rendered markdown typography (shared by editor preview and read-only view) */
.md-preview { line-height: 1.65; }
.md-preview > :first-child { margin-top: 0; }
.md-preview h1, .md-preview h2, .md-preview h3,
.md-preview h4, .md-preview h5, .md-preview h6 {
  margin: 1.4em 0 .6em;
  line-height: 1.25;
}
.md-preview h1 { font-size: 1.7rem; border-bottom: 1px solid var(--color-border); padding-bottom: .3em; }
.md-preview h2 { font-size: 1.4rem; border-bottom: 1px solid var(--color-border); padding-bottom: .25em; }
.md-preview h3 { font-size: 1.2rem; }
.md-preview p, .md-preview ul, .md-preview ol, .md-preview blockquote, .md-preview table {
  margin: 0 0 1em;
}
.md-preview ul, .md-preview ol { padding-left: 1.5rem; }
.md-preview li { margin: .2em 0; }
.md-preview a { color: var(--color-primary); }
.md-preview code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .88em;
  background: var(--color-bg);
  padding: .15em .35em;
  border-radius: 4px;
}
.md-preview pre {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: .85rem 1rem;
  overflow: auto;
  margin: 0 0 1em;
}
.md-preview pre code { background: none; padding: 0; font-size: .85rem; }
.md-preview blockquote {
  border-left: 3px solid var(--color-border);
  padding: .1em 0 .1em 1rem;
  color: var(--color-text-muted);
}
.md-preview img { max-width: 100%; height: auto; }
/* GFM task lists: drop the bullet for items that start with a checkbox */
.md-preview li:has(> input[type=checkbox]) { list-style: none; margin-left: -1.25rem; }
.md-preview input[type=checkbox] { margin-right: .5rem; vertical-align: middle; }
.md-preview input.md-task { cursor: pointer; }

/* ── README panel (GitHub-style, below file listings) ───────── */
.readme-panel { margin-top: 1.25rem; padding: 0; overflow: hidden; }
.readme-panel-header {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .6rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
}
.readme-panel .readme-panel-title { font-size: .9rem; font-weight: 600; margin: 0; }
.readme-panel .md-preview { padding: 1.25rem 1.5rem; }
@media (max-width: 600px) {
  .readme-panel-header { padding: .6rem .9rem; }
  .readme-panel .md-preview { padding: 1rem .9rem; }
}

/* ── Collaborative editor ─────────────────────────────────── */
.collab { display: none; }

.collab-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: .6rem;
}
.collab-status {
  font-size: .85rem;
  color: var(--color-text-muted);
}
.collab-presence {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
}
.collab-peer {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .8rem;
  padding: .15rem .5rem;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-surface);
}
.collab-peer-dot {
  width: .6rem;
  height: .6rem;
  border-radius: 50%;
  display: inline-block;
}

.collab-editor-wrap {
  position: relative;
}
.collab-source {
  display: block;
  width: 100%;
  margin: 0;
  min-height: 60vh;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .9rem;
  line-height: 1.5;
  padding: .75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  resize: vertical;
  box-sizing: border-box;
}
/* Overlay layer for remote carets — sits exactly over the textarea, never intercepts input. */
.collab-cursors {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
  border-radius: var(--radius);
}
.collab-caret {
  position: absolute;
  width: 2px;
}
.collab-caret-label {
  position: absolute;
  top: -1.1rem;
  left: 0;
  font-size: .68rem;
  line-height: 1;
  color: #fff;
  padding: .1rem .3rem;
  border-radius: 3px;
  white-space: nowrap;
}
/* Hidden text mirror used only to measure caret coordinates. */
.collab-mirror {
  position: absolute;
  top: 0;
  left: 0;
  visibility: hidden;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow: hidden;
  box-sizing: border-box;
  pointer-events: none;
}
/* Wide tables scroll horizontally inside their own container (server wraps each <table>),
   so they never overflow the preview panel on narrow screens. */
.md-table-wrap {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 0 1em;
}
.md-preview table {
  width: max-content;
  max-width: none;
  margin: 0;
  border-collapse: collapse;
}
.md-preview th, .md-preview td {
  border: 1px solid var(--color-border);
  padding: .4rem .65rem;
  text-align: left;
}
.md-preview th { background: var(--color-bg); }
.md-preview hr { border: none; border-top: 1px solid var(--color-border); margin: 1.5em 0; }

/* Side-by-side images: a row of <img>/<figure> laid out horizontally. The same markup renders in
   the PDF via inline-block (flexbox is unsupported there); widths come from each image's width attr. */
.md-preview .md-row {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: flex-start;
  margin: 0 0 1em;
}
.md-preview .md-row img { margin: 0; }

/* Page-break marker, shown only in the editor's live preview (PageBreakMode.EDITOR). The marker is
   removed entirely in the read-only view and becomes a real page break in the exported PDF. */
.md-preview .page-break-marker {
  height: 0;
  margin: 1.4em 0;
  border-top: 2px dashed var(--color-border);
  position: relative;
}
.md-preview .page-break-marker::after {
  content: "Page break";
  position: absolute;
  top: -0.7em;
  left: 50%;
  transform: translateX(-50%);
  padding: 0 .5rem;
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-size: .7rem;
  letter-spacing: .04em;
  text-transform: uppercase;
}

/* Print-to-PDF dialog */
.print-dialog {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 0;
  max-width: 30rem;
  width: calc(100% - 2rem);
  color: var(--color-text);
  background: var(--color-surface);
}
.print-dialog::backdrop { background: rgba(0, 0, 0, .4); }
.print-form { padding: 1.25rem; display: flex; flex-direction: column; gap: .85rem; }
.print-title { margin: 0; font-size: 1.15rem; }
.print-hint { margin: -.4rem 0 .2rem; font-size: .8rem; color: var(--color-text-muted); }
.print-form .form-row { display: flex; gap: .85rem; }
.print-form .form-row > label { flex: 1 1 0; }
.print-form label {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  font-size: .85rem;
  color: var(--color-text-muted);
}
.print-form select,
.print-form input[type="number"] {
  width: 100%;
  padding: .4rem .5rem;
  border: 1px solid var(--color-border);
  border-radius: 5px;
  background: var(--color-bg);
  color: var(--color-text);
}
.print-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .25rem; }

/* Print view: a standalone page (no app chrome) tuned for the browser's print/PDF output.
   Force the light palette regardless of the OS colour scheme — printed paper is white, so dark-mode
   light text would be invisible. Redefining the variables here cascades to all .md-preview styles. */
.print-page {
  --color-bg: #f3f4f6;
  --color-surface: #ffffff;
  --color-border: #e5e7eb;
  --color-text: #111827;
  --color-text-muted: #6b7280;
  --color-primary: #2e5fa0;
  --color-accent: #0ea5e9;
  max-width: 60rem;
  margin: 0 auto;
  padding: 1.5rem;
  color: var(--color-text);
  background: var(--color-surface);
}
.print-toolbar {
  display: flex;
  gap: .5rem;
  justify-content: flex-end;
  margin-bottom: 1rem;
}
.print-document { line-height: 1.55; }
.print-page.theme-serif .print-document { font-family: Georgia, "Times New Roman", serif; }
.print-page.theme-compact .print-document { line-height: 1.35; }
.print-document h1, .print-document h2, .print-document h3, .print-document h4 {
  break-after: avoid;
  page-break-after: avoid;
}
.print-document img { max-width: 100%; height: auto; }
.print-document .md-row,
.print-document figure,
.print-document img,
.print-document table,
.print-document pre,
.print-document blockquote {
  break-inside: avoid;
  page-break-inside: avoid;
}

@media print {
  /* Page margins come from the @page rule; hide the on-screen controls and app surface. */
  body.print-page { margin: 0; padding: 0; max-width: none; background: #fff; }
  .print-toolbar { display: none !important; }
  .print-document a { color: inherit; text-decoration: none; }
}

@media (max-width: 768px) {
  .print-form .form-row { flex-direction: column; gap: .85rem; }
}

@media (max-width: 768px) {
  .md-toolbar-tabs { display: flex; }
  .md-editor { flex-direction: column; min-height: 0; }
  .md-editor > .md-source-wrap,
  .md-editor > .md-live { min-height: 0; }
  /* On mobile only one pane is shown at a time, toggled by the Edit/Preview tabs. */
  .md-editor.show-preview > .md-source-wrap { display: none; }
  .md-editor:not(.show-preview) > .md-live { display: none; }
}
