/* ═══════════════════════════════════════════════════════════════════════════
   Sidebar — 3D glass, collapsible, with FAB
   v2 — accessibility, performance, and polish pass

   ───────────────────────────────────────────────────────────────────────────
   HTML / JS contract required for full accessibility & the fixes to work:

     • <button class="sb-toggle" aria-label="Open menu" aria-expanded="false">
     • Each <a class="sb-link" data-title="…" aria-label="…">
     • Add / remove the body class "fab-open" when the FAB modal opens/closes.
     • Optional: <button class="fab" data-badge="3" aria-label="Compose">
       (remove data-badge or set it empty to hide the badge)
   ───────────────────────────────────────────────────────────────────────────
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  /* Fix #19: form controls and scrollbars pick up the right palette */
  color-scheme: dark;

  --sb-width: 260px;
  --sb-width-collapsed: 72px;
  --sb-bg-1: #0e1020;
  --sb-bg-2: #131730;
  --sb-bg-3: #1b1f42;
  --sb-accent: var(--primary, #4f46e5);
  --sb-accent-2: var(--primary-dark, #8c5cff);
  --sb-text: #e8ecf8;
  --sb-muted: #7f88a8;
  --sb-card: rgba(255, 255, 255, 0.04);
  --sb-card-hover: rgba(255, 255, 255, 0.08);
  --sb-border: rgba(255, 255, 255, 0.06);

  /* Fix #18: a single soft edge instead of a heavy black smear */
  --sb-shadow-1:
    0 0 0 1px rgba(255, 255, 255, 0.05),
    0 24px 48px -12px rgba(0, 0, 0, 0.7);

  --sb-shadow-item:
    0 4px 12px rgba(0, 0, 0, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);

  --sb-shadow-item-hover:
    0 8px 20px rgba(0, 0, 0, 0.35),
    0 0 0 1px rgba(255, 255, 255, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

/* ── Layout: body padding matches the sidebar width ──────────────────────── */
body.has-sidebar {
  margin: 0;
  padding-left: var(--sb-width);
  min-height: 100vh;
  transition: padding-left .28s cubic-bezier(.2, .7, .3, 1);
}
html.sb-collapsed body.has-sidebar { padding-left: var(--sb-width-collapsed); }

.app-main {
  max-width: 1200px;
  margin: 1.5rem auto;
  padding: 0 1.5rem 4rem;
}

/* ── Sidebar container ──────────────────────────────────────────────────── */
/* Note (Fix #5): we deliberately do NOT use `contain: layout` on .sidebar.
   It would make the sidebar a containing block for fixed-position descendants,
   breaking the collapse button docked to the viewport bottom (Fix #15).
   The width transition is instead kept smooth by giving the inner content
   its own layer where it matters. */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sb-width);
  z-index: 100;
  display: flex;
  flex-direction: column;
  color: var(--sb-text);
  background:
    radial-gradient(600px 400px at -20% -10%, rgba(140, 92, 255, 0.18), transparent 60%),
    radial-gradient(500px 500px at 120% 100%, rgba(79, 70, 229, 0.22), transparent 55%),
    linear-gradient(160deg, var(--sb-bg-1) 0%, var(--sb-bg-2) 45%, var(--sb-bg-3) 100%);
  box-shadow: var(--sb-shadow-1);
  overflow-y: auto;
  overflow-x: hidden;
  transition: width .28s cubic-bezier(.2, .7, .3, 1), transform .3s ease;

  /* Fix #17: Firefox scrollbar styling */
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.14) transparent;
}
html.sb-collapsed .sidebar { width: var(--sb-width-collapsed); }

.sidebar::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.015) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.015) 1px, transparent 1px);
  background-size: 24px 24px;

  /* Fix #7: WebKit prefix so Safari doesn't hard-cut the pattern */
  -webkit-mask-image: linear-gradient(180deg, transparent, #000 20%, #000 80%, transparent);
          mask-image: linear-gradient(180deg, transparent, #000 20%, #000 80%, transparent);
}

/* ── Brand row ─────────────────────────────────────────────────────────── */
.sb-brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: 1rem 1rem .85rem;
  border-bottom: 1px solid var(--sb-border);
  position: relative;
  z-index: 1;
}
.sb-brand {
  display: flex;
  align-items: center;
  gap: .7rem;
  color: var(--sb-text);
  text-decoration: none;
  min-width: 0;
}
.sb-brand:hover { text-decoration: none; }
.sb-brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px; height: 38px;
  border-radius: 12px;
  font-weight: 900;
  letter-spacing: -.02em;
  color: #fff;
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--sb-accent), var(--sb-accent-2));
  box-shadow:
    0 8px 20px rgba(79, 70, 229, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    inset 0 -2px 0 rgba(0, 0, 0, 0.25);
  transform: perspective(200px) rotateX(2deg);
}
.sb-brand-name {
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sb-collapse-btn {
  background: transparent;
  border: 1px solid var(--sb-border);
  color: var(--sb-muted);
  width: 28px; height: 28px;
  border-radius: 8px;
  cursor: pointer;
  font-size: .7rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
  flex-shrink: 0;
}
.sb-collapse-btn:hover {
  background: var(--sb-card-hover);
  color: var(--sb-text);
  border-color: rgba(255, 255, 255, 0.12);
}
.sb-collapse-icon {
  display: inline-block;
  transition: transform .28s cubic-bezier(.2, .7, .3, 1);
}
html.sb-collapsed .sb-collapse-icon { transform: rotate(180deg); }

/* Fix #8: visible focus ring for keyboard users across all interactive chrome */
.sb-brand:focus-visible,
.sb-collapse-btn:focus-visible,
.sb-link:focus-visible,
.sb-user-name:focus-visible,
.sb-user-logout:focus-visible,
.sb-toggle:focus-visible,
.fab:focus-visible,
.fab-modal-close:focus-visible,
.fab-file-btn:focus-visible,
.fab-submit:focus-visible {
  outline: 2px solid var(--sb-accent-2);
  outline-offset: 2px;
}

/* ── Nav ────────────────────────────────────────────────────────────────── */
.sb-nav {
  flex: 1;
  padding: .75rem .75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .18rem;
  position: relative;
  z-index: 1;
}

.sb-section {
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--sb-muted);
  padding: 1rem .75rem .35rem;
  user-select: none;
  white-space: nowrap;
  transition: opacity .18s ease;
}

.sb-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .65rem .8rem;
  border-radius: 12px;
  color: var(--sb-text);
  text-decoration: none;
  font-size: .92rem;
  font-weight: 500;
  background: var(--sb-card);
  border: 1px solid transparent;
  box-shadow: var(--sb-shadow-item);

  /* Fix #1: was `overflow: hidden` — that clipped the active indicator bar
     which sits at left: -8px. Changed to `visible` so the bar can escape. */
  overflow: visible;

  transition:
    transform .18s cubic-bezier(.2, .7, .3, 1),
    box-shadow .18s ease,
    background .18s ease,
    border-color .18s ease,
    color .18s ease;
}
/* Fix #4: promote only when a transform is actually about to run */
.sb-link:hover,
.sb-link:focus-visible { will-change: transform; }

.sb-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px; height: 30px;
  border-radius: 10px;
  font-size: 1rem;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06),
              inset 0 -1px 0 rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
  transition: transform .18s ease, background .18s ease;
}

.sb-label {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity .2s ease, margin-left .28s ease;
}

.sb-link:hover {
  transform: translateY(-2px) translateX(2px);
  background: var(--sb-card-hover);
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: var(--sb-shadow-item-hover);
  text-decoration: none;
}
.sb-link:hover .sb-icon {
  transform: scale(1.06);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.04));
}

/* Fix #12: glass highlight layer on top of the accent gradient */
.sb-link.active {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0) 40%),
    linear-gradient(135deg, rgba(79, 70, 229, 0.45), rgba(140, 92, 255, 0.30));
  border-color: rgba(140, 92, 255, 0.4);
  box-shadow:
    0 10px 26px rgba(79, 70, 229, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    inset 0 -1px 0 rgba(0, 0, 0, 0.35);
  color: #fff;
}
.sb-link.active::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 20%;
  bottom: 20%;
  width: 4px;
  border-radius: 4px;
  background: linear-gradient(180deg, var(--sb-accent), var(--sb-accent-2));

  /* Fix #13: brighter glow + subtle pulse for a premium feel */
  box-shadow:
    0 0 12px var(--sb-accent),
    0 0 24px var(--sb-accent-2);
  animation: sb-pulse 2.4s ease-in-out infinite;
}
@keyframes sb-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .65; }
}
.sb-link.active .sb-icon {
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0.06));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.sb-badge {
  margin-left: auto;
  background: linear-gradient(180deg, #ff5c8a, #d92e88);
  color: #fff;
  font-size: .7rem;
  font-weight: 800;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(217, 46, 136, 0.5),
              inset 0 1px 0 rgba(255, 255, 255, 0.35);
  flex-shrink: 0;
}

/* ── Select dropdowns ───────────────────────────────────────────────────── */
.sb-select-wrap {
  margin: .35rem .75rem 0;
  padding: .6rem .75rem;
  border-radius: 12px;
  background: var(--sb-card);
  box-shadow: var(--sb-shadow-item);
}
.sb-select-label {
  display: block;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--sb-muted);
  margin-bottom: .35rem;
}
.sb-select {
  width: 100%;
  padding: .4rem .55rem;
  border-radius: 8px;
  border: 1px solid var(--sb-border);
  background: rgba(0, 0, 0, 0.25);
  color: var(--sb-text);
  font-family: inherit;
  font-size: .85rem;
  cursor: pointer;
}
.sb-select:focus { outline: 2px solid var(--sb-accent); outline-offset: -1px; }

/* ── User card ──────────────────────────────────────────────────────────── */
.sb-user {
  display: flex;
  align-items: center;
  gap: .65rem;
  margin: 1rem .75rem .25rem;
  padding: .7rem .8rem;
  border-radius: 14px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
  box-shadow: var(--sb-shadow-item);
  border: 1px solid var(--sb-border);
}
.sb-user-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  object-fit: cover;
  background: #2a3151;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.15);
  flex-shrink: 0;
}
.sb-user-info { flex: 1; min-width: 0; }
.sb-user-name {
  display: block;
  color: var(--sb-text);
  font-weight: 700;
  font-size: .88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-decoration: none;
}
.sb-user-name:hover { color: var(--sb-accent-2); text-decoration: none; }
.sb-user-meta { font-size: .72rem; color: var(--sb-muted); }
.sb-user-logout {
  font-size: 1.1rem;
  color: var(--sb-muted);
  text-decoration: none;
  padding: .25rem .35rem;
  border-radius: 8px;
  transition: color .15s, background .15s;
}
.sb-user-logout:hover { color: #ff5c8a; background: rgba(255, 92, 138, 0.1); text-decoration: none; }

.sb-foot {
  padding: .6rem 1rem 1rem;
  font-size: .7rem;
  color: var(--sb-muted);
  text-align: center;
  border-top: 1px solid var(--sb-border);
  white-space: nowrap;
  overflow: hidden;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Collapsed state (desktop only)
   ───────────────────────────────────────────────────────────────────────────
   Fix #21: all collapsed rules are grouped here, in this order:
     1. hidden content
     2. brand row
     3. collapse button (Fix #15)
     4. nav + links
     5. badges
     6. user card
     7. tooltip (Fix #16)
   ═══════════════════════════════════════════════════════════════════════════ */

/* 1. Hide content that doesn't fit */
html.sb-collapsed .sb-brand-name,
html.sb-collapsed .sb-section,
html.sb-collapsed .sb-label,
html.sb-collapsed .sb-select-wrap,
html.sb-collapsed .sb-user-info,
html.sb-collapsed .sb-user-logout,
html.sb-collapsed .sb-foot,
html.sb-collapsed .sb-brand { display: none; }

/* 2. Brand row */
html.sb-collapsed .sb-brand-row {
  justify-content: center;
  padding: .85rem .5rem;
}

/* 3. Collapse button — Fix #15: dock to the bottom of the viewport rail */
html.sb-collapsed .sb-collapse-btn {
  position: fixed;
  bottom: 16px;
  left: calc(var(--sb-width-collapsed) / 2);
  transform: translateX(-50%);
  background: var(--sb-bg-2);
  border-color: rgba(255, 255, 255, 0.12);
  z-index: 2;
}

/* 4. Nav + links */
html.sb-collapsed .sb-nav { padding-top: 1.25rem; }
html.sb-collapsed .sb-link {
  justify-content: center;
  padding: .6rem;
}
html.sb-collapsed .sb-link:hover { transform: translateY(-2px) scale(1.05); }
html.sb-collapsed .sb-link.active::before { display: none; }

/* 5. Badges */
html.sb-collapsed .sb-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  margin: 0;
  min-width: 16px;
  height: 16px;
  font-size: .6rem;
  padding: 0 4px;
}

/* 6. User card */
html.sb-collapsed .sb-user {
  justify-content: center;
  padding: .6rem .5rem;
  margin: .75rem .5rem .5rem;
}
html.sb-collapsed .sb-icon { width: 34px; height: 34px; font-size: 1.05rem; }

/* 7. Tooltip — Fix #16: glass treatment matching the rest of the chrome */
html.sb-collapsed .sb-link::after {
  content: attr(data-title);
  position: absolute;
  left: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%) scale(.94);
  background: linear-gradient(180deg, #1a1f3a, #131730);
  color: #fff;
  padding: .4rem .7rem;
  border-radius: 8px;
  font-size: .8rem;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  box-shadow:
    0 8px 24px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  -webkit-backdrop-filter: blur(8px);
          backdrop-filter: blur(8px);
  transition: opacity .15s ease, transform .15s ease;
  z-index: 10;
}
html.sb-collapsed .sb-link:hover::after,
html.sb-collapsed .sb-link:focus-visible::after {
  opacity: 1;
  transform: translateY(-50%) scale(1);
}

/* ═══════════════════════════════════════════════════════════════════════════
   Mobile toggle
   ═══════════════════════════════════════════════════════════════════════════ */
.sb-toggle {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  width: 44px; height: 44px;
  border-radius: 12px;
  border: 0;
  cursor: pointer;
  font-size: 1.3rem;
  color: #fff;
  background: linear-gradient(135deg, var(--sb-accent), var(--sb-accent-2));
  box-shadow: 0 8px 20px rgba(79, 70, 229, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.3);

  /* Fix #3: use opacity + visibility + pointer-events instead of `display`
     so the toggle can actually animate in and out. */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .18s ease, visibility .18s ease, transform .15s ease;
}
.sb-toggle:hover { transform: scale(1.05); }

.sb-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(4px);
          backdrop-filter: blur(4px);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease;
}
.sb-backdrop.open { opacity: 1; pointer-events: auto; }

/* ═══════════════════════════════════════════════════════════════════════════
   Floating action button
   ═══════════════════════════════════════════════════════════════════════════ */
.fab {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 150;
  width: 60px; height: 60px;
  border-radius: 50%;
  border: 0;
  cursor: pointer;
  color: #fff;
  font-size: 1.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--sb-accent), var(--sb-accent-2));
  box-shadow:
    0 12px 30px rgba(79, 70, 229, 0.5),
    0 4px 10px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    inset 0 -2px 0 rgba(0, 0, 0, 0.25);
  transition: transform .2s cubic-bezier(.2, .7, .3, 1), box-shadow .2s;
}
.fab:hover {
  transform: translateY(-3px) scale(1.05);
  box-shadow:
    0 16px 40px rgba(79, 70, 229, 0.6),
    0 8px 16px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    inset 0 -2px 0 rgba(0, 0, 0, 0.25);
}
/* Fix #14: tighter press, no floating gap */
.fab:active { transform: translateY(1px) scale(.94); }

.fab-icon {
  display: inline-block;
  line-height: 1;
  transition: transform .25s cubic-bezier(.2, .7, .3, 1);
}
/* Fix #2: the old selector `.fab-modal.open ~ .fab` required .fab to follow
   .fab-modal as a sibling — which it usually doesn't in the markup.
   Use a body class toggled by JS instead. */
body.fab-open .fab-icon { transform: rotate(45deg); }

/* Fix #20: optional notification badge on the FAB.
   In PHP: <button class="fab" data-badge="<?= $unread ?: '' ?>"> */
.fab[data-badge]:not([data-badge=""])::after {
  content: attr(data-badge);
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ff5c8a, #d92e88);
  color: #fff;
  font-size: .7rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 4px 10px rgba(217, 46, 136, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

/* ── FAB modal ──────────────────────────────────────────────────────────── */
.fab-modal {
  position: fixed;
  inset: 0;
  z-index: 250;
  background: rgba(0, 0, 0, 0.65);
  -webkit-backdrop-filter: blur(6px);
          backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
.fab-modal.open { opacity: 1; pointer-events: auto; }

.fab-modal-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  width: 100%;
  max-width: 560px;
  box-shadow: 0 40px 80px rgba(0, 0, 0, 0.6);
  padding: 1.25rem;
  transform: translateY(20px) scale(.97);
  transition: transform .25s cubic-bezier(.2, .7, .3, 1);
}
.fab-modal.open .fab-modal-card { transform: translateY(0) scale(1); }

.fab-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .85rem;
}
.fab-modal-head h3 { margin: 0; font-size: 1.15rem; }
.fab-modal-close {
  background: transparent;
  border: 0;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--muted);
  padding: .3rem .5rem;
  border-radius: 8px;
  transition: background .15s, color .15s;
}
.fab-modal-close:hover { background: rgba(127, 127, 127, 0.1); color: var(--text); }

#fab-content {
  width: 100%;
  min-height: 110px;
  padding: .75rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: .95rem;
  resize: vertical;
  box-sizing: border-box;
}
#fab-content:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

.fab-file-row {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
  margin-top: .75rem;
}
.fab-file-btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .45rem .8rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  font-size: .85rem;
  transition: background .15s, border-color .15s;
}
.fab-file-btn:hover { background: rgba(127, 127, 127, 0.08); border-color: var(--primary); }

.fab-visibility { margin-left: auto; }
.fab-visibility select {
  padding: .45rem .6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: .85rem;
  cursor: pointer;
}

.fab-submit {
  padding: .55rem 1.2rem;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  font-weight: 700;
  font-size: .9rem;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(79, 70, 229, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  transition: transform .15s, box-shadow .15s;
}
.fab-submit:hover { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(79, 70, 229, 0.5); }

.fab-file-preview {
  margin-top: .6rem;
  font-size: .85rem;
  color: var(--muted);
  min-height: 18px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Keyboard shortcut hint
   ═══════════════════════════════════════════════════════════════════════════ */
.kbd-hint {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translate(-50%, 20px);
  z-index: 300;
  background: rgba(14, 16, 32, 0.95);
  color: #e8ecf8;
  padding: 1rem 1.15rem;
  border-radius: 14px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.55),
              inset 0 1px 0 rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.08);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: 90vw;
}
.kbd-hint.show {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}
.kbd-hint-head {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: #7f88a8;
  font-weight: 700;
  margin-bottom: .6rem;
}
.kbd-hint-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: .35rem .9rem;
}
.kbd-hint-list > div {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .85rem;
}
.kbd-hint-foot {
  margin-top: .7rem;
  padding-top: .6rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: .75rem;
  color: #7f88a8;
}
.kbd-hint kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.3);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .78rem;
  color: #e8ecf8;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Scrollbar (WebKit)
   ═══════════════════════════════════════════════════════════════════════════ */
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.12); border-radius: 999px; }
.sidebar::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.22); }

/* ═══════════════════════════════════════════════════════════════════════════
   RTL
   ═══════════════════════════════════════════════════════════════════════════ */
[dir="rtl"] body.has-sidebar { padding-left: 0; padding-right: var(--sb-width); }
[dir="rtl"] html.sb-collapsed body.has-sidebar { padding-right: var(--sb-width-collapsed); }
[dir="rtl"] .sidebar { inset: 0 0 0 auto; }
[dir="rtl"] .sb-toggle { left: auto; right: 12px; }
[dir="rtl"] .sb-link.active::before { left: auto; right: -8px; }
[dir="rtl"] .sb-link:hover { transform: translateY(-2px) translateX(-2px); }
[dir="rtl"] .fab { right: auto; left: 28px; }
[dir="rtl"] .fab[data-badge]:not([data-badge=""])::after { right: auto; left: -4px; }
[dir="rtl"] html.sb-collapsed .sb-link::after { left: auto; right: calc(100% + 12px); }
[dir="rtl"] html.sb-collapsed .sb-collapse-btn {
  left: auto;
  right: calc(var(--sb-width-collapsed) / 2);
  transform: translateX(50%);
}

/* ═══════════════════════════════════════════════════════════════════════════
   Mobile
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  body.has-sidebar,
  html.sb-collapsed body.has-sidebar { padding-left: 0; padding-right: 0; }

  .sidebar {
    transform: translateX(-100%);
    width: 280px !important;
  }
  .sidebar.open { transform: translateX(0); }

  /* Show the mobile toggle (overrides the base hidden state) */
  .sb-toggle {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  /* The collapse button is desktop-only */
  .sb-collapse-btn { display: none; }

  .app-main { padding: 3.5rem 1rem 5rem; }

  /* Force expand on mobile regardless of cookie state */
  html.sb-collapsed .sb-brand-name,
  html.sb-collapsed .sb-section,
  html.sb-collapsed .sb-label,
  html.sb-collapsed .sb-select-wrap,
  html.sb-collapsed .sb-user-info,
  html.sb-collapsed .sb-user-logout,
  html.sb-collapsed .sb-foot { display: revert; }
  html.sb-collapsed .sb-link { justify-content: flex-start; padding: .65rem .8rem; }
  html.sb-collapsed .sb-link::after { display: none; }
  html.sb-collapsed .sb-badge { position: static; margin-left: auto; }

  [dir="rtl"] .sidebar { transform: translateX(100%); }
  [dir="rtl"] .sidebar.open { transform: translateX(0); }

  .fab { bottom: 20px; right: 20px; width: 54px; height: 54px; font-size: 1.6rem; }
  [dir="rtl"] .fab { left: 20px; right: auto; }

  .kbd-hint { display: none; }

  /* Fix #6: backdrop-filter is one of the most expensive properties on
     mobile GPUs — swap it for a solid darker scrim. */
  .fab-modal {
    -webkit-backdrop-filter: none;
            backdrop-filter: none;
    background: rgba(0, 0, 0, 0.85);
  }
  .sb-backdrop {
    -webkit-backdrop-filter: none;
            backdrop-filter: none;
    background: rgba(0, 0, 0, 0.7);
  }
}

/* Fix #9: honour the user's motion preference */
@media (prefers-reduced-motion: reduce) {
  .sidebar,
  body.has-sidebar,
  .sb-link,
  .sb-link.active::before,
  .sb-icon,
  .sb-collapse-icon,
  .sb-toggle,
  .fab,
  .fab-icon,
  .fab-modal,
  .fab-modal-card,
  .kbd-hint,
  .sb-backdrop {
    transition: none !important;
    animation: none !important;
  }
}

/* Fix #6 (continued): honour reduced transparency where supported */
@media (prefers-reduced-transparency: reduce) {
  .fab-modal,
  .sb-backdrop,
  html.sb-collapsed .sb-link::after {
    -webkit-backdrop-filter: none;
            backdrop-filter: none;
  }
}

/* Kill old top-nav on pages that still have it */
body.has-sidebar .navbar,
body.has-sidebar .nav-links,
body.has-sidebar .nav-toggle,
body.has-sidebar .lang-switcher,
body.has-sidebar .theme-switcher { display: none !important; }

/* Fix #24: don't waste ink printing the chrome */
@media print {
  .sidebar,
  .sb-toggle,
  .sb-backdrop,
  .fab,
  .fab-modal,
  .kbd-hint { display: none !important; }

  body.has-sidebar,
  html.sb-collapsed body.has-sidebar {
    padding-left: 0 !important;
    padding-right: 0 !important;
  }
}