@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700&display=swap');

:root {
  /* Tells the browser which palette its NATIVE widgets (scrollbars, date
     pickers, <select> popups) should use — without it dark mode still
     gets bright white OS scrollbars on every scrollable pane. */
  color-scheme: light;
  --background: 40 33% 98%;
  --foreground: 220 25% 14%;
  --card: 0 0% 100%;
  --card-foreground: 220 25% 14%;
  --popover: 0 0% 100%;
  --popover-foreground: 220 25% 14%;
  --primary: 210 65% 45%;
  --primary-foreground: 0 0% 100%;
  --secondary: 40 40% 94%;
  --secondary-foreground: 220 25% 14%;
  --muted: 40 20% 95%;
  --muted-foreground: 220 10% 46%;
  --accent: 28 80% 56%;
  --accent-foreground: 0 0% 100%;
  --destructive: 0 72% 51%;
  --destructive-foreground: 0 0% 100%;
  --border: 220 13% 90%;
  --input: 220 13% 90%;
  --ring: 210 65% 45%;
  --radius: 0.75rem;
  --sidebar-bg: 0 0% 100%;
  --sidebar-fg: 220 20% 30%;
  --sidebar-primary: 210 65% 45%;
  --sidebar-accent-bg: 220 15% 95%;
  --sidebar-border: 220 13% 90%;
  --chart-1: 210 65% 45%;
  --chart-2: 28 80% 56%;
}

/* Dark palette: every neutral is stepped from one base, #121416
   (hsl 210 10% 8%) - page background - so surfaces, borders and the
   sidebar stay the same cool grey family rather than drifting blue. */
.dark {
  color-scheme: dark;
  --background: 210 10% 8%;
  --foreground: 210 15% 92%;
  --card: 210 9% 11%;
  --card-foreground: 210 15% 92%;
  --popover: 210 9% 11%;
  --popover-foreground: 210 15% 92%;
  --primary: 210 65% 58%;
  --primary-foreground: 0 0% 100%;
  --secondary: 210 8% 16%;
  --secondary-foreground: 210 15% 92%;
  --muted: 210 8% 15%;
  --muted-foreground: 220 8% 64%;
  --accent: 28 80% 56%;
  --accent-foreground: 0 0% 100%;
  --destructive: 0 62% 50%;
  --destructive-foreground: 0 0% 100%;
  --border: 210 7% 19%;
  --input: 210 7% 19%;
  --ring: 210 65% 58%;
  --sidebar-bg: 210 10% 6%;
  --sidebar-fg: 210 12% 85%;
  --sidebar-primary: 210 65% 58%;
  --sidebar-accent-bg: 210 8% 14%;
  --sidebar-border: 210 7% 14%;
}

.dark label,
.dark .form-group label,
.dark th,
.dark .card-title,
.dark .feature-title,
.dark .step-title,
.dark .testimonial-author,
.dark h1,
.dark h2,
.dark h3 {
  color: hsl(var(--foreground));
}

.dark .input,
.dark .select {
  color: hsl(var(--foreground));
  background: hsl(var(--card));
  border-color: hsl(var(--input));
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Thin, theme-tinted scrollbars app-wide (sidebar, tables, modals,
   history rail…). The chat pane refines this further in chat.html. */
* { scrollbar-width: thin; scrollbar-color: hsl(var(--muted-foreground) / .35) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background-color: hsl(var(--muted-foreground) / .35); border-radius: 999px;
  border: 2px solid transparent; background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background-color: hsl(var(--muted-foreground) / .6); }
.dark * { scrollbar-color: hsl(var(--muted-foreground) / .5) transparent; }
.dark *::-webkit-scrollbar-thumb { background-color: hsl(var(--muted-foreground) / .5); }
.dark *::-webkit-scrollbar-thumb:hover { background-color: hsl(var(--muted-foreground) / .8); }

body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: 'DM Sans', system-ui, sans-serif; font-weight: 700; letter-spacing: -0.01em; }

a { color: inherit; text-decoration: none; }

/* ─── Utility ─── */
.container { max-width: 1152px; margin: 0 auto; padding: 0 1.5rem; }
.text-center { text-align: center; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-end { justify-content: flex-end; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.gap-6 { gap: 1.5rem; }
.gap-8 { gap: 2rem; }
.flex-wrap { flex-wrap: wrap; }
.shrink-0 { flex-shrink: 0; }
/* Icons next to text in a flex row keep their size: icon() SVGs have fixed width/height,
   but flex items shrink by default, so a long title (e.g. Related Documents) squeezed them. */
.flex > svg, .inline-flex > svg { flex-shrink: 0; }
/* Long titles in compact lists: two lines, then "…" (full title in the title attribute). */
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-width: 0; }
.min-w-0 { min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none; }
.grid { display: grid; }
.space-y-2 > * + * { margin-top: 0.5rem; }
.space-y-3 > * + * { margin-top: 0.75rem; }
.space-y-4 > * + * { margin-top: 1rem; }
.space-y-5 > * + * { margin-top: 1.25rem; }
.space-y-6 > * + * { margin-top: 1.5rem; }
.space-y-8 > * + * { margin-top: 2rem; }

@media (min-width: 640px) {
  .sm-grid-2 { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 768px) {
  .md-flex { display: flex; }
  .md-grid-2 { grid-template-columns: repeat(2, 1fr); }
  .md-grid-3 { grid-template-columns: repeat(3, 1fr); }
  .md-hidden { display: none; }
  .md-show { display: flex; }
}
@media (min-width: 1024px) {
  .lg-grid-2 { grid-template-columns: repeat(2, 1fr); }
  .lg-grid-3 { grid-template-columns: repeat(3, 1fr); }
  .lg-grid-4 { grid-template-columns: repeat(4, 1fr); }
}

/* ─── Components ─── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.5rem 1rem; border-radius: var(--radius); font-size: 0.875rem;
  font-weight: 500; border: none; cursor: pointer; transition: all 0.15s;
  font-family: inherit; gap: 0.5rem; white-space: nowrap;
}
.btn-primary { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.btn-primary:hover { opacity: 0.9; }
.btn-outline { background: transparent; border: 1px solid hsl(var(--border)); color: hsl(var(--foreground)); }
.btn-outline:hover { background: hsl(var(--muted)); }
/* .btn-destructive is the same red button (Modal.confirm({danger}), "Replace", "Discard changes"). */
.btn-danger, .btn-destructive { background: hsl(var(--destructive)); color: hsl(var(--destructive-foreground)); border: 1px solid hsl(var(--destructive)); }
.btn-danger:hover, .btn-destructive:hover { background: hsl(0 65% 42%); }
/* Frosted-glass secondary button (landing hero): translucent fill that
   blurs whatever sits behind it, a hairline light border, and a faint top
   highlight. Readable over the ribbons in both themes. */
.btn-glass {
  background: hsl(0 0% 100% / .45);
  border: 1px solid hsl(0 0% 100% / .7);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
          backdrop-filter: blur(14px) saturate(1.4);
  box-shadow: inset 0 1px 0 hsl(0 0% 100% / .6), 0 4px 18px hsl(220 30% 20% / .08);
}
.btn-glass:hover { background: hsl(0 0% 100% / .62); }
.dark .btn-glass {
  background: hsl(0 0% 100% / .07);
  border-color: hsl(0 0% 100% / .16);
  box-shadow: inset 0 1px 0 hsl(0 0% 100% / .1), 0 4px 18px hsl(0 0% 0% / .3);
}
.dark .btn-glass:hover { background: hsl(0 0% 100% / .12); }
.btn-ghost { background: transparent; color: hsl(var(--foreground)); }
.btn-ghost:hover { background: hsl(var(--muted)); }
.btn-sm { padding: 0.25rem 0.75rem; font-size: 0.75rem; }
.btn-lg { padding: 0.75rem 2rem; font-size: 1rem; height: 3rem; }
.btn-icon { padding: 0.5rem; width: 2.25rem; height: 2.25rem; }
.btn-secondary { background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground)); }

.card {
  background: hsl(var(--card)); border: 1px solid hsl(var(--border));
  border-radius: var(--radius); overflow: hidden;
}
.card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.08); }
.card-content { padding: 1.25rem; }
.card-header { padding: 1.25rem 1.25rem 0.5rem; }
.card-title { font-family: 'DM Sans', sans-serif; font-size: 1.125rem; font-weight: 600; }

.badge {
  display: inline-flex; align-items: center; padding: 0.125rem 0.5rem;
  border-radius: 9999px; font-size: 0.75rem; font-weight: 500;
}
.badge-primary { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.badge-secondary { background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground)); }
.badge-outline { background: transparent; border: 1px solid hsl(var(--border)); color: hsl(var(--foreground)); }
.status-public { background: hsl(142 70% 94%); color: hsl(142 70% 25%); border: 1px solid hsl(142 60% 80%); }
.status-private { background: hsl(0 80% 96%); color: hsl(0 70% 38%); border: 1px solid hsl(0 70% 85%); }
.status-restricted { background: hsl(38 95% 94%); color: hsl(28 80% 35%); border: 1px solid hsl(38 85% 80%); }
.status-crossorg { background: hsl(265 80% 96%); color: hsl(265 60% 40%); border: 1px solid hsl(265 70% 85%); }
.status-global { background: hsl(200 80% 94%); color: hsl(205 75% 32%); border: 1px solid hsl(200 70% 80%); }
/* Dark mode: the pastel pills above are light-mode colours — on a dark
   card they'd sit as bright blocks with dark text. Same hues, but as a
   translucent tint with a light text tone instead. */
.dark .status-public     { background: hsl(142 60% 45% / .16); color: hsl(142 55% 68%); border-color: hsl(142 50% 40% / .5); }
.dark .status-private    { background: hsl(0 70% 55% / .16);   color: hsl(0 80% 74%);   border-color: hsl(0 60% 45% / .5); }
.dark .status-restricted { background: hsl(38 90% 50% / .16);  color: hsl(38 90% 68%);  border-color: hsl(38 80% 45% / .5); }
.dark .status-crossorg   { background: hsl(265 70% 60% / .18); color: hsl(265 80% 78%); border-color: hsl(265 60% 50% / .5); }
.dark .status-global     { background: hsl(200 80% 50% / .16); color: hsl(200 80% 70%); border-color: hsl(200 70% 45% / .5); }
.org-chip { display:inline-flex; align-items:center; gap:0.3rem; padding:0.15rem 0.5rem; border-radius:0.375rem; background:hsl(var(--muted)); color:hsl(var(--foreground)); font-size:0.7rem; font-weight:600; border:1px solid hsl(var(--border)); }
.org-chip-dot { width:0.5rem; height:0.5rem; border-radius:9999px; }
.org-switcher { display:flex; align-items:center; gap:0.5rem; max-width:100%; min-width:0; padding:0.4rem 0.65rem; border:1px solid hsl(var(--border)); border-radius:0.5rem; background:hsl(var(--background)); }
.org-switcher select {
  appearance: none; -webkit-appearance: none;
  border: 1px solid transparent; background: transparent;
  font-family: inherit; font-size: 0.8rem; font-weight: 600; outline: none; cursor: pointer;
  color: hsl(var(--foreground)); color-scheme: light dark; min-width: 0;
  padding: 0.2rem 1.4rem 0.2rem 0.4rem; border-radius: 0.375rem;
  max-width: 260px; text-overflow: ellipsis;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 0.15rem center; background-size: 1rem;
  transition: background-color .15s, border-color .15s;
}
.org-switcher select:hover   { background-color: hsl(var(--muted) / .6); }
.org-switcher select:focus-visible { border-color: hsl(var(--primary) / .5); box-shadow: 0 0 0 3px hsl(var(--primary) / .15); }
.dark .org-switcher select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}
.org-switcher select option { background: hsl(var(--card)); color: hsl(var(--foreground)); }
.checkbox-row { display:flex; align-items:center; gap:0.5rem; padding:0.5rem 0.75rem; border:1px solid hsl(var(--border)); border-radius:0.5rem; cursor:pointer; }
.checkbox-row:hover { background:hsl(var(--muted)/0.4); }

.input {
  width: 100%; height: 2.5rem; padding: 0 0.75rem; border-radius: var(--radius);
  border: 1px solid hsl(var(--input)); background: hsl(var(--background));
  font-size: 0.875rem; font-family: inherit; color: hsl(var(--foreground));
  outline: none; transition: border-color 0.15s;
}
.input:focus { border-color: hsl(var(--ring)); box-shadow: 0 0 0 2px hsl(var(--ring) / 0.2); }
/* Multiline fields share .input's look but not its single-line box: a
   fixed 2.5rem height and zero vertical padding squash a textarea to one
   line with the text pinned to the top edge. Resizable vertically only,
   and never below its starting height. */
textarea.input {
  height: auto; min-height: 6.5rem; padding: 0.65rem 0.75rem;
  line-height: 1.5; resize: vertical; display: block;
}
.input-counter { display: block; text-align: right; font-size: 0.72rem; color: hsl(var(--muted-foreground)); margin-top: 0.3rem; }
.input-counter.over { color: hsl(var(--destructive)); }
.input-lg { height: 3.5rem; font-size: 1rem; }

.select {
  height: 2.5rem; padding: 0 0.75rem; border-radius: var(--radius);
  border: 1px solid hsl(var(--input)); background: hsl(var(--background));
  font-size: 0.875rem; font-family: inherit; color: hsl(var(--foreground));
  cursor: pointer; outline: none; appearance: auto;
}

label { font-size: 0.875rem; font-weight: 500; color: hsl(var(--foreground)); }

/* ─── Navbar ─── */
.navbar {
  position: sticky; top: 0; z-index: 50;
  border-bottom: 1px solid hsl(var(--border));
  background: hsl(var(--background) / 0.8); backdrop-filter: blur(12px);
}
.navbar-inner {
  max-width: 1152px; margin: 0 auto; padding: 0 1.5rem;
  display: flex; align-items: center; justify-content: space-between; height: 4rem;
}
.logo { display: flex; align-items: center; gap: 0.5rem; }
.logo svg { width: 1.75rem; height: 1.75rem; color: hsl(var(--primary)); }
.logo img.brand-mark { display: block; }
.logo img.brand-mark-secondary,
.sidebar-header img.brand-mark-secondary {
  display: block; width: auto; max-width: 120px; object-fit: contain;
  /* Pulled in tighter than the container's normal gap (and no divider) so
     the two logos read as "together" rather than two unrelated marks that
     just happen to share a header. */
  margin-right: -0.2rem;
}
.sidebar.collapsed .sidebar-header img.brand-mark-secondary { display: none; }
.logo span { font-size: 1.25rem; font-weight: 700; font-family: 'DM Sans', sans-serif; }
/* Landing-page section links (index.html). Inline on desktop; on phones they
   collapse into a panel under the bar, toggled by the hamburger. */
.nav-links { display: flex; align-items: center; gap: 2rem; }
.nav-toggle { display: none; }
.nav-toggle-icon { display: inline-flex; }
.nav-toggle-icon[hidden] { display: none; }
@media (max-width: 767px) {
  .navbar-inner { padding: 0 1rem; }
  /* The school mark can be up to 120px wide — with the hamburger and Sign
     In button there's no room for it on a phone-width bar. */
  .navbar .logo img.brand-mark-secondary { display: none; }
  .nav-toggle { display: inline-flex; }
  .nav-links {
    display: none; position: absolute; top: 100%; left: 0; right: 0;
    flex-direction: column; align-items: stretch; gap: 0;
    background: hsl(var(--background)); border-bottom: 1px solid hsl(var(--border));
    box-shadow: 0 12px 24px -8px rgba(0,0,0,.12);
  }
  .nav-links.open { display: flex; }
  .nav-links a {
    padding: .9rem 1.25rem; font-size: .95rem; color: hsl(var(--foreground));
    border-top: 1px solid hsl(var(--border));
  }
  .nav-links a:hover { background: hsl(var(--muted) / .5); }
}
/* Anchor links (#features, #how-it-works) land below the sticky bar. Scoped
   to pages that have the public navbar so app pages' scroll behaviour is
   untouched. */
html:has(> body > .navbar) { scroll-padding-top: 4.5rem; scroll-behavior: smooth; }
html[data-reduce-motion="true"] { scroll-behavior: auto; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

/* ─── AI "working" indicator ───
   Wrap icon('aiMark') in .ai-thinking while the model is busy — the mark
   breathes (scale + fade) with a slow quarter-turn, the way an assistant's
   logo idles while it thinks. The glyph is 4-fold symmetric, so the turn
   lands back on itself and loops seamlessly. */
.ai-thinking { display: inline-flex; line-height: 0; transform-origin: 50% 50%; animation: ai-thinking 1.6s ease-in-out infinite; }
@keyframes ai-thinking {
  0%   { transform: scale(1)    rotate(0deg);  opacity: 1;   }
  50%  { transform: scale(0.82) rotate(45deg); opacity: 0.55; }
  100% { transform: scale(1)    rotate(90deg); opacity: 1;   }
}
@media (prefers-reduced-motion: reduce) {
  .ai-thinking { animation: ai-thinking-still 1.6s ease-in-out infinite; }
  @keyframes ai-thinking-still { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }
}

/* ─── Sidebar Layout ─── */
.app-layout { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.app-layout > .flex-1 { display: flex; flex-direction: column; min-width: 0; min-height: 0; flex: 1; }
.app-header { flex-shrink: 0; }
.sidebar {
  width: 260px; background: hsl(var(--sidebar-bg)); color: hsl(var(--sidebar-fg));
  display: flex; flex-direction: column; flex-shrink: 0;
  border-right: 1px solid hsl(var(--sidebar-border));
  overflow: hidden;
}
/* No transition: the sidebar opens and closes instantly (and a collapsed
   sidebar doesn't visibly shrink on every page load). */
.sidebar.collapsed { width: 56px; }
.sidebar.collapsed .sidebar-header span { display: none; }
.sidebar.collapsed .sidebar-group-label { opacity: 0; height: 0; padding: 0; margin: 0; overflow: hidden; }
.sidebar.collapsed .sidebar-link span { display: none; }
.sidebar.collapsed .sidebar-link { justify-content: center; padding: 0.625rem 0; }
.sidebar.collapsed .sidebar-link svg { width: 1.25rem; height: 1.25rem; }
.sidebar.collapsed .sidebar-header { justify-content: center; padding: 1rem 0; }
.sidebar-header { padding: 1rem 1.25rem; display: flex; align-items: center; gap: 0.5rem; }
.sidebar-header svg { color: hsl(var(--sidebar-primary)); }
.sidebar-header span { font-size: 1.125rem; font-weight: 700; font-family: 'DM Sans', sans-serif; white-space: nowrap; }
.sidebar-group-label {
  padding: 0.75rem 1.25rem 0.25rem; font-size: 0.7rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em; color: hsl(var(--sidebar-fg) / 0.5);
  transition: opacity 0.2s, height 0.2s, padding 0.2s;
}
.sidebar-link {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 1.25rem; font-size: 0.875rem; color: hsl(var(--sidebar-fg));
  transition: background 0.15s; border-radius: 0; white-space: nowrap;
}
.sidebar-link:hover { background: hsl(var(--sidebar-accent-bg)); }
.sidebar-link.active { background: hsl(var(--sidebar-accent-bg)); color: hsl(var(--sidebar-primary)); font-weight: 500; }
.sidebar-link svg { width: 1rem; height: 1rem; flex-shrink: 0; }
.sidebar-nav { flex: 1; overflow-y: auto; }
/* Footer has no horizontal padding of its own: the profile button carries
   the same 1.25rem inset as .sidebar-link, so its hover fills the sidebar
   edge to edge exactly like the nav links do. */
.sidebar-footer { padding: 0.5rem 0; border-top: 1px solid hsl(var(--sidebar-border)); }
.app-header {
  display: flex; align-items: center; height: 3.5rem;
  border-bottom: 1px solid hsl(var(--border)); padding: 0 1.5rem;
  background: hsl(var(--background));
}
/* Admins' storage banner (layout.js showStorageBanner) */
.storage-banner { display: flex; align-items: flex-start; gap: .6rem; padding: .65rem 1.5rem; font-size: .85rem; line-height: 1.45; border-bottom: 1px solid; }
.storage-banner > svg { flex-shrink: 0; margin-top: .1rem; }
.storage-banner > span { flex: 1; }
.storage-warning { background: hsl(38 92% 50% / .12); border-color: hsl(38 92% 50% / .35); color: hsl(var(--foreground)); }
.storage-warning > svg { color: hsl(38 92% 42%); }
.storage-full { background: hsl(var(--destructive) / .1); border-color: hsl(var(--destructive) / .35); color: hsl(var(--foreground)); }
.storage-full > svg, .storage-full strong { color: hsl(var(--destructive)); }
.storage-banner-x { border: 0; background: none; padding: .15rem; border-radius: .3rem; cursor: pointer; color: hsl(var(--muted-foreground)); display: inline-flex; }
.storage-banner-x:hover { background: hsl(var(--foreground) / .08); color: hsl(var(--foreground)); }
@media (max-width: 640px) { .storage-banner { padding: .6rem .9rem; } }

.app-header .avatar {
  margin-left: auto; width: 2rem; height: 2rem; border-radius: 9999px;
  background: hsl(var(--primary)); color: hsl(var(--primary-foreground));
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 600;
}
.app-main { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; padding: 1.5rem; min-height: 0; -webkit-overflow-scrolling: touch; }
@media (max-width: 767px) { .app-main { padding: 1rem; } }
/* Wide screens: stop page content stretching edge-to-edge on large monitors.
   Every page puts its content in a single wrapper directly under .app-main,
   so cap and center that wrapper (pages that already size themselves with a
   .wrap-* helper are left alone). Two steps so ultrawides don't get a tiny
   island of content in a sea of margin. */
@media (min-width: 1600px) {
  .app-main { padding: 2rem 2.5rem; }
  .app-main > :not(.wrap-narrow):not(.wrap-md):not(.wrap-lg):not(.wrap-xl) { max-width: 1480px; width: 100%; margin-left: auto; margin-right: auto; }
}
@media (min-width: 2200px) {
  .app-main > :not(.wrap-narrow):not(.wrap-md):not(.wrap-lg):not(.wrap-xl) { max-width: 1760px; }
}

/* ─── Hero ─── */
.hero { position: relative; padding: 6rem 1.5rem; overflow: hidden; isolation: isolate; }
.hero h1 { font-size: 2.5rem; line-height: 1.15; font-weight: 700; }
@media (min-width: 768px) { .hero h1 { font-size: 3.75rem; } }
.hero .highlight { color: hsl(var(--primary)); position: relative; display: inline-block; }

/* ── Ambient background: flowing gradient ribbons ──
   A looping ribbon (purple -> blue -> mint -> amber) and a warm strand
   (amber -> red) sweep across the hero, each with a blurred copy beneath
   for glow and a small light "sheen" travelling along the main one. Film
   grain over the top, and a soft scrim behind the copy so the headline
   always reads. Dark: vivid on the page background. Light: a pastel
   lavender -> pink -> peach wash with the ribbons slightly softened. All
   decorative, behind the content (z-index -1 in the hero's own context). */
.hero-ambient {
  position: absolute; inset: 0; z-index: -1; pointer-events: none; overflow: hidden;
  --hero-scrim: var(--background);
  background: hsl(var(--background));
}
.dark .hero-ambient { --hero-scrim: var(--background); background: hsl(var(--background)); }
/* Fade the whole layer out over the last stretch so the ribbons and the
   pastel wash melt into the next section instead of stopping at a line. */
.hero-ambient {
  -webkit-mask-image: linear-gradient(to bottom, #000 68%, transparent 100%);
          mask-image: linear-gradient(to bottom, #000 68%, transparent 100%);
}
.hero-ribbons {
  position: absolute; inset: 0; width: 100%; height: 100%;
  animation: hero-ribbon-drift 26s ease-in-out infinite alternate; transform-origin: 50% 60%;
}
.hero-ribbons .rb-core  { opacity: .78; }
.hero-ribbons .rb-glow  { opacity: .35; }
.dark .hero-ribbons .rb-core { opacity: 1; }
.dark .hero-ribbons .rb-glow { opacity: .6; }
.hero-ribbons .rb-sheen {
  fill: none; stroke: #fff; stroke-width: 7; stroke-linecap: round; opacity: .55;
  stroke-dasharray: 55 945; animation: hero-sheen 8s linear infinite;
}
@keyframes hero-sheen { from { stroke-dashoffset: 1000; } to { stroke-dashoffset: 0; } }
@keyframes hero-ribbon-drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(-1.5%, 1%, 0) scale(1.04); }
}
/* Scrim: fades the ribbons out behind the centre column of text. */
.hero-ambient::after {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(ellipse 42% 46% at 50% 44%, hsl(var(--hero-scrim) / .88) 0%, hsl(var(--hero-scrim) / .55) 45%, transparent 78%);
}
/* Film grain, like the references - fine noise, not a pattern. */
.hero-ambient::before {
  content: ''; position: absolute; inset: 0; z-index: 1; opacity: .12; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 1 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.dark .hero-ambient::before { opacity: .09; mix-blend-mode: overlay; }

/* ── Entrance: pill, headline, copy, buttons, stats rise in one after another ── */
.hero .wrap-lg > * { animation: hero-rise .7s cubic-bezier(.2,.7,.2,1) both; }
.hero .wrap-lg > :nth-child(1) { animation-delay: .05s; }
.hero .wrap-lg > :nth-child(2) { animation-delay: .15s; }
.hero .wrap-lg > :nth-child(3) { animation-delay: .27s; }
.hero .wrap-lg > :nth-child(4) { animation-delay: .38s; }
.hero .wrap-lg > :nth-child(5) { animation-delay: .55s; }
@keyframes hero-rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .hero .wrap-lg > *, .hero-ribbons, .hero-ribbons .rb-sheen { animation: none; }
  .hero-ribbons .rb-sheen { display: none; }
}
@media (max-width: 767px) {
  .hero-ambient::after { background: radial-gradient(ellipse 70% 42% at 50% 42%, hsl(var(--hero-scrim) / .9) 0%, hsl(var(--hero-scrim) / .6) 50%, transparent 85%); }
}
.hero p.sub { font-size: 1.125rem; color: hsl(var(--muted-foreground)); max-width: 640px; margin: 0 auto; }
.pill {
  display: inline-flex; align-items: center; gap: 0.5rem;
  border: 1px solid hsl(var(--border)); background: hsl(var(--card));
  border-radius: 9999px; padding: 0.375rem 1rem; font-size: 0.875rem;
  color: hsl(var(--muted-foreground)); margin-bottom: 1.5rem;
}
.pill svg { color: hsl(var(--primary)); width: 1rem; height: 1rem; }
.stats-row {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 2rem;
  margin-top: 3rem; font-size: 0.875rem; color: hsl(var(--muted-foreground));
}
.stats-row div { display: flex; align-items: center; gap: 0.5rem; }
.stats-row svg { width: 1rem; height: 1rem; }
@media (max-width: 767px) {
  .hero { padding: 3.5rem 1.25rem 3rem; }
  .hero h1 { font-size: 2rem; }
  .hero p.sub { font-size: 1rem; }
  /* Stack the two CTAs full-width instead of wrapping unevenly. */
  .hero .btn-lg { width: 100%; max-width: 22rem; }
  .stats-row { gap: 1rem 1.5rem; margin-top: 2rem; }
}

/* ─── Sections ─── */
.section { padding: 5rem 1.5rem; }
.section-muted { background: hsl(var(--muted) / 0.5); }
.section-title { font-size: 1.875rem; font-weight: 700; margin-bottom: 1rem; }
@media (min-width: 768px) { .section-title { font-size: 2.25rem; } }
.section-desc { color: hsl(var(--muted-foreground)); max-width: 560px; margin: 0 auto 3.5rem; }
@media (max-width: 767px) {
  .section { padding: 3.5rem 1.25rem; }
  .section-desc { margin-bottom: 2.25rem; }
}

.feature-icon {
  display: inline-flex; padding: 0.75rem; border-radius: 0.75rem;
  background: hsl(var(--primary) / 0.1); margin-bottom: 1rem;
}
.feature-icon svg { width: 1.5rem; height: 1.5rem; color: hsl(var(--primary)); }
.feature-title { font-family: 'DM Sans', sans-serif; font-size: 1.125rem; font-weight: 600; margin-bottom: 0.5rem; }
.feature-desc { font-size: 0.875rem; color: hsl(var(--muted-foreground)); line-height: 1.65; }

.step-icon {
  width: 4rem; height: 4rem; border-radius: 1rem; margin: 0 auto 1rem;
  background: hsl(var(--primary)); color: hsl(var(--primary-foreground));
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 20px hsl(var(--primary) / 0.3);
}
.step-icon svg { width: 1.75rem; height: 1.75rem; }
.step-label { font-size: 0.875rem; font-weight: 500; color: hsl(var(--primary)); margin-bottom: 0.5rem; }
.step-title { font-family: 'DM Sans', sans-serif; font-size: 1.25rem; font-weight: 600; margin-bottom: 0.5rem; }

/* How It Works: hovering (or focusing/tapping) a step icon pops the matching
   clip from the SmartKMS explainer up above it. Clips: static/videos/how-*.mp4 */
.step { position: relative; }
.step-icon { cursor: pointer; transition: transform .2s ease; }
.step-icon:hover, .step-icon:focus-visible { transform: translateY(-2px); }
.step-icon:focus-visible { outline: 2px solid hsl(var(--primary)); outline-offset: 3px; }
.step-clip {
  position: absolute; left: 50%; bottom: calc(100% - 0.5rem); z-index: 20;
  width: min(28rem, 90vw); padding: 0.375rem; border-radius: var(--radius);
  background: hsl(var(--card)); border: 1px solid hsl(var(--border));
  box-shadow: 0 18px 40px rgb(0 0 0 / 0.18);
  opacity: 0; visibility: hidden; pointer-events: none;
  transform: translate(-50%, 0.5rem) scale(0.96); transform-origin: 50% 100%;
  transition: opacity .2s ease, transform .2s ease, visibility 0s linear .2s;
}
.step-clip video { display: block; width: 100%; aspect-ratio: 720 / 476; border-radius: calc(var(--radius) - 0.25rem); background: #f4f1ec; }
.step-clip figcaption { font-size: 0.75rem; color: hsl(var(--muted-foreground)); padding: 0.375rem 0.25rem 0.125rem; }
.step.show-clip .step-clip {
  opacity: 1; visibility: visible; transform: translate(-50%, 0) scale(1);
  transition: opacity .2s ease, transform .2s ease, visibility 0s;
}
@media (prefers-reduced-motion: reduce) {
  .step-icon, .step-clip { transition: none; }
  .step-icon:hover, .step-icon:focus-visible { transform: none; }
}

.testimonial-quote { font-size: 0.875rem; font-style: italic; line-height: 1.65; margin-bottom: 1rem; }
.testimonial-author { font-family: 'DM Sans', sans-serif; font-size: 0.875rem; font-weight: 600; }
.testimonial-role { font-size: 0.75rem; color: hsl(var(--muted-foreground)); }

/* ─── Footer ─── */
.footer {
  border-top: 1px solid hsl(var(--border)); background: hsl(var(--card));
  padding: 3rem 1.5rem;
}
.footer-inner {
  max-width: 1152px; margin: 0 auto;
  display: flex; flex-direction: column; align-items: center; gap: 1.5rem;
}
@media (min-width: 768px) { .footer-inner { flex-direction: row; justify-content: space-between; } }
.footer-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 1rem 1.5rem; }
@media (max-width: 767px) { .footer { padding: 2.25rem 1.25rem; } .footer-copy { text-align: center; } }
.footer-links a { font-size: 0.875rem; color: hsl(var(--muted-foreground)); }
.footer-links a:hover { color: hsl(var(--foreground)); }
.footer-copy { font-size: 0.75rem; color: hsl(var(--muted-foreground)); }

/* ─── Login ─── */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: hsl(var(--background)); padding: 1rem;
  position: relative; overflow: hidden; isolation: isolate;
}
.login-stack { position: relative; z-index: 1; }

/* Colour for the login screen, deliberately a different figure from the
   landing ribbon: two fans of three strands (teal/blue, purple/pink,
   amber/red) - one rising from the bottom-left corner, one falling from
   the top-right - kept to the screen edges so the card stays clear. They draw
   themselves in on load; the card rises in just after. */
.login-ambient { position: absolute; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.login-strands { position: absolute; inset: 0; width: 100%; height: 100%; }
.login-strands path { stroke-dasharray: 1000; stroke-dashoffset: 1000; animation: ls-draw 1.6s cubic-bezier(.3,.6,.2,1) .1s forwards; }
.login-strands path:nth-child(3), .login-strands path:nth-child(4) { animation-delay: .22s; }
.login-strands path:nth-child(5), .login-strands path:nth-child(6) { animation-delay: .34s; }
@keyframes ls-draw { to { stroke-dashoffset: 0; } }
.login-strands .ls-core { opacity: .55; }
.login-strands .ls-glow { opacity: .3; }
.dark .login-strands .ls-core { opacity: .9; }
.dark .login-strands .ls-glow { opacity: .5; }
.login-ambient::before {        /* film grain, as on the landing hero */
  content: ''; position: absolute; inset: 0; z-index: 1; opacity: .1; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 1 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.dark .login-ambient::before { opacity: .08; mix-blend-mode: overlay; }
.login-stack { animation: login-rise .7s cubic-bezier(.2,.7,.2,1) .15s both; }
@keyframes login-rise { from { opacity: 0; transform: translateY(18px) scale(.985); } to { opacity: 1; transform: none; } }

/* Landing -> login: a cross-document View Transition (both pages opt in
   with @view-transition in their <head>). The old page eases up and fades,
   the new one fades in, and the logo - named "brand" on both pages -
   glides from the navbar to its place above the card. Browsers without
   View Transitions just get the entrance animations above. */
.navbar .logo, .login-header .logo { view-transition-name: brand; }
::view-transition-old(root) { animation: vt-out .35s cubic-bezier(.4,0,.2,1) both; }
::view-transition-new(root) { animation: vt-in .45s cubic-bezier(.2,.7,.2,1) .05s both; }
::view-transition-group(brand) { animation-duration: .5s; animation-timing-function: cubic-bezier(.2,.7,.2,1); }
@keyframes vt-out { to { opacity: 0; transform: translateY(-16px) scale(.99); } }
@keyframes vt-in  { from { opacity: 0; transform: translateY(16px); } }

@media (prefers-reduced-motion: reduce) {
  .login-strands path { animation: none; stroke-dashoffset: 0; }
  .login-stack { animation: none; }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}
.login-card { width: 100%; max-width: 28rem; }
.login-card .card-header { text-align: center; }
.login-card .card-title { font-size: 1.25rem; }
.login-card .card-desc { font-size: 0.875rem; color: hsl(var(--muted-foreground)); margin-top: 0.25rem; }
.password-toggle {
  position: absolute; right: 0.75rem; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; color: hsl(var(--muted-foreground)); padding: 0;
}
.password-toggle:hover { color: hsl(var(--foreground)); }
.remember-row { display: flex; align-items: center; justify-content: space-between; font-size: 0.875rem; }
/* Third-party sign-in above the e-mail form (login.html) */
.sso-block { margin-bottom: 1.25rem; }
.sso-btn { gap: 0.6rem; height: 2.75rem; font-weight: 500; }
.sso-btn:not(.hidden) ~ .sso-btn:not(.hidden) { margin-top: 0.6rem; }
.sso-divider { display: flex; align-items: center; gap: 0.75rem; margin-top: 1.1rem; font-size: 0.75rem; color: hsl(var(--muted-foreground)); }
.sso-divider::before, .sso-divider::after { content: ""; flex: 1; height: 1px; background: hsl(var(--border)); }
.link-btn { background: none; border: none; color: hsl(var(--primary)); cursor: pointer; font-size: inherit; font-family: inherit; }
.link-btn:hover { text-decoration: underline; }

/* ─── Upload Zone ─── */
.upload-zone {
  border: 2px dashed hsl(var(--primary) / 0.3); background: hsl(var(--primary) / 0.05);
  border-radius: var(--radius); padding: 2.5rem; text-align: center;
}
.upload-icon { 
  display: inline-flex; padding: 1rem; border-radius: 1rem;
  background: hsl(var(--primary) / 0.1); margin-bottom: 1rem;
}
.upload-icon svg { width: 2rem; height: 2rem; color: hsl(var(--primary)); }

/* ─── Filters ─── */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; }
.search-wrap { position: relative; flex: 1; min-width: 200px; max-width: 24rem; }
.search-wrap svg { position: absolute; left: 0.75rem; top: 50%; transform: translateY(-50%); width: 1rem; height: 1rem; color: hsl(var(--muted-foreground)); }
.search-wrap .input { padding-left: 2.25rem; }
.view-btns { margin-left: auto; display: flex; gap: 0.25rem; }

/* ─── Stat Card ─── */
.stat-value { font-size: 1.5rem; font-weight: 700; font-family: 'DM Sans', sans-serif; margin-top: 0.25rem; }
.stat-label { font-size: 0.875rem; color: hsl(var(--muted-foreground)); }
.stat-change { font-size: 0.75rem; color: hsl(var(--muted-foreground)); margin-top: 0.25rem; }
.stat-icon { padding: 0.75rem; border-radius: 0.75rem; background: hsl(var(--primary) / 0.1); }
.stat-icon svg { width: 1.25rem; height: 1.25rem; color: hsl(var(--primary)); }

/* ─── Doc Card ─── */
.doc-icon { padding: 0.5rem; border-radius: 0.5rem; background: hsl(var(--primary) / 0.1); flex-shrink: 0; }
.doc-icon svg { width: 1.25rem; height: 1.25rem; color: hsl(var(--primary)); }
.doc-title { font-size: 0.875rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-summary { font-size: 0.75rem; color: hsl(var(--muted-foreground)); line-height: 1.5; margin-top: 0.25rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.doc-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.375rem; margin-top: 0.5rem; }
.doc-date { font-size: 0.75rem; color: hsl(var(--muted-foreground)); margin-left: auto; }

/* ─── Chat ─── */
.chat-container { display: flex; flex-direction: column; height: calc(100vh - 8rem); max-width: 48rem; margin: 0 auto; }
.chat-messages { flex: 1; overflow-y: auto; padding-right: 0.5rem; }
.chat-msg { display: flex; gap: 0.75rem; margin-bottom: 1rem; }
.chat-msg.user { justify-content: flex-end; }
.chat-avatar {
  width: 2rem; height: 2rem; border-radius: 9999px; flex-shrink: 0; margin-top: 0.25rem;
  display: flex; align-items: center; justify-content: center;
}
.chat-avatar.bot { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.chat-avatar.human { background: hsl(var(--muted)); color: hsl(var(--muted-foreground)); }
.chat-avatar svg { width: 1rem; height: 1rem; }
.chat-bubble {
  max-width: 80%; padding: 1rem; border-radius: var(--radius);
  font-size: 0.875rem; line-height: 1.65; white-space: pre-line;
}
.chat-bubble.bot { background: hsl(var(--card)); border: 1px solid hsl(var(--border)); }
.chat-bubble.user { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.chat-sources { display: flex; flex-wrap: wrap; gap: 0.375rem; margin-top: 0.75rem; }
.chat-input-wrap { position: relative; margin-top: 0.5rem; }
.chat-input-wrap .input { padding-right: 3rem; height: 3rem; border-radius: 0.75rem; }
.chat-input-wrap .btn { position: absolute; right: 0.375rem; top: 50%; transform: translateY(-50%); width: 2.25rem; height: 2.25rem; }
.chat-chips { display: flex; flex-wrap: wrap; gap: 0.5rem; padding: 0.75rem 0; }

/* ─── Analytics canvas ─── */
.chart-container { width: 100%; height: 280px; position: relative; }
.chart-container canvas { width: 100% !important; height: 100% !important; }

/* ─── Pricing ─── */
.pricing-card { border-width: 2px; cursor: pointer; transition: all 0.2s; position: relative; }
.pricing-card.selected { border-color: hsl(var(--primary)); box-shadow: 0 8px 24px rgba(0,0,0,0.1); transform: scale(1.02); }
.pricing-card.popular { border-color: hsl(var(--primary) / 0.4); box-shadow: 0 4px 12px rgba(0,0,0,0.08); }
.pricing-card .popular-badge {
  position: absolute; top: -0.75rem; left: 50%; transform: translateX(-50%);
  background: hsl(var(--primary)); color: hsl(var(--primary-foreground));
  padding: 0.125rem 0.75rem; border-radius: 9999px; font-size: 0.75rem; font-weight: 500;
}
.price { font-size: 2.5rem; font-weight: 700; }
.price-period { font-size: 0.875rem; color: hsl(var(--muted-foreground)); }
.plan-features li { display: flex; align-items: flex-start; gap: 0.5rem; font-size: 0.875rem; padding: 0.25rem 0; }
.plan-features svg { width: 1rem; height: 1rem; color: hsl(var(--primary)); flex-shrink: 0; margin-top: 0.125rem; }

/* ─── Settings ─── */
.settings-page { max-width: 56rem; margin: 0 auto; }
/* minmax(0,…): an auto-sized column grows to an input's intrinsic width and pushed
   Settings' Full Name/Email past the card on 320-375px phones. */
.form-grid { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 640px) { .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.form-group { display: flex; flex-direction: column; gap: 0.25rem; }
.theme-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem; }
@media (min-width: 640px) { .theme-grid { grid-template-columns: repeat(6, 1fr); } }
.theme-btn {
  display: flex; flex-direction: column; align-items: center; gap: 0.5rem;
  border: 2px solid hsl(var(--border)); border-radius: 0.75rem; padding: 0.75rem;
  background: none; cursor: pointer; position: relative; transition: all 0.15s;
  color: hsl(var(--foreground));
}
.theme-btn:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.theme-btn.active { border-color: hsl(var(--primary)); background: hsl(var(--primary) / 0.05); }
.theme-swatch { width: 1.5rem; height: 1.5rem; border-radius: 9999px; box-shadow: inset 0 1px 3px rgba(0,0,0,0.15); }
.theme-check {
  position: absolute; top: -0.375rem; right: -0.375rem;
  width: 1.25rem; height: 1.25rem; border-radius: 9999px;
  background: hsl(var(--primary)); color: hsl(var(--primary-foreground));
  display: flex; align-items: center; justify-content: center;
}
.theme-check svg { width: 0.75rem; height: 0.75rem; }

/* ─── Table ─── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
th { text-align: left; padding: 0.75rem; font-weight: 500; color: hsl(var(--muted-foreground)); border-bottom: 1px solid hsl(var(--border)); }
td { padding: 0.75rem; border-bottom: 1px solid hsl(var(--border)); }

/* ─── Folder ─── */
.folder-card { cursor: pointer; transition: all 0.15s; }
.folder-card:hover { border-color: hsl(var(--primary) / 0.3); }
.folder-card.drag-over { border-color: hsl(var(--primary)); background: hsl(var(--primary) / 0.05); }
.drop-zone { min-height: 120px; border: 2px dashed hsl(var(--muted)); border-radius: var(--radius); padding: 0.5rem; }

/* ─── Dialog / Modal ─── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: hsl(var(--card)); border-radius: var(--radius); max-width: 42rem;
  width: 100%; max-height: 90vh; overflow-y: auto; padding: 1.5rem;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
.modal-title { font-family: 'DM Sans', sans-serif; font-size: 1.125rem; font-weight: 600; display: flex; align-items: center; gap: 0.5rem; }
.modal-close { background: none; border: none; cursor: pointer; color: hsl(var(--muted-foreground)); font-size: 1.25rem; }

/* Large modal variant — used for the document preview modal (chat citations,
   AI search results), which needs far more room than a confirm/prompt dialog. */
.modal-lg {
  max-width: 62rem; width: 95%; height: 85vh; max-height: 85vh;
  display: flex; flex-direction: column; padding: 1.25rem 1.25rem 1rem;
}
.modal-lg .modal-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
/* Scrolling variant (like the Terms modal): as tall as its content, up to 80%
   of the screen; past that only the body scrolls, title and buttons stay put. */
.modal-scroll { max-width: 46rem; max-height: 80vh; overflow: hidden; display: flex; flex-direction: column; }
.modal-scroll .modal-header, .modal-scroll .modal-footer { flex-shrink: 0; }
.modal-scroll .modal-body { overflow-y: auto; min-height: 0; overscroll-behavior: contain; }
/* Maximized preview: fill the viewport (toggled by DocPreview.toggleMaximize). */
.modal.modal-maximized {
  max-width: 100vw; width: 100vw; height: 100vh; max-height: 100vh;
  border-radius: 0; box-shadow: none;
}
.modal-overlay:has(.modal-maximized) { padding: 0; }
.dp-meta { display: flex; flex-wrap: wrap; gap: .5rem .9rem; align-items: center; margin-bottom: .85rem; color: hsl(var(--muted-foreground)); font-size: .78rem; flex-shrink: 0; }
.dp-maximize-btn {
  margin-left: auto; width: 1.8rem; height: 1.8rem; display: flex; align-items: center; justify-content: center;
  border-radius: 999px; border: 1px solid hsl(var(--border)); background: transparent; cursor: pointer;
  color: hsl(var(--foreground));
}
.dp-maximize-btn:hover { background: hsl(var(--muted)); }
.dp-pane {
  flex: 1; min-height: 0; background: hsl(var(--muted) / .25);
  display: flex; align-items: center; justify-content: center; overflow: auto;
  border-radius: .6rem;
}
.dp-pane.dp-pad { padding: 1.5rem; }
.dp-pane iframe {
  width: 100%; height: 100%; max-height: 100%; border: none; border-radius: .5rem;
  background: hsl(var(--card)); box-shadow: 0 2px 20px rgba(0,0,0,.12);
}
#dpOfficeHost { width: 100%; height: 100%; }
/* pdf.js pages on phones (pdfView.js) */
.pdfv {
  align-self: stretch; width: 100%; height: 100%; overflow: auto; -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column; gap: .5rem; padding: .5rem;
}
.pdfv-page { width: 100%; flex-shrink: 0; background: #fff; border-radius: .25rem; box-shadow: 0 1px 4px rgba(0,0,0,.15); overflow: hidden; }
.pdfv-page canvas { display: block; width: 100%; height: auto; }
.dp-pane:has(> .pdfv), .dv-preview:has(> .pdfv) { padding: 0; }
.modal-title > svg { flex-shrink: 0; }
/* "Ad blocker may be stopping the editor" notice over an ONLYOFFICE pane (showOfficeBlockedNotice in app.js) */
:has(> .office-blocked) { position: relative; }
.office-blocked {
  position: absolute; inset: 0; z-index: 5; padding: 1rem;
  display: flex; align-items: center; justify-content: center;
  background: hsl(var(--background) / .75);
}
.office-blocked-card {
  max-width: 24rem; display: flex; flex-direction: column; align-items: center; gap: .6rem;
  padding: 1.5rem; text-align: center; border-radius: var(--radius);
  background: hsl(var(--card)); border: 1px solid hsl(var(--border)); box-shadow: 0 8px 30px rgba(0,0,0,.15);
}
.office-blocked-title { font-weight: 600; }
.office-blocked-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: .5rem; margin-top: .4rem; }
/* Right-click menu (showContextMenu in app.js), same look as the ⋮ menus */
.context-menu {
  position: fixed; z-index: 150; min-width: 180px; padding: .3rem;
  display: flex; flex-direction: column;
  background: hsl(var(--card)); border: 1px solid hsl(var(--border)); border-radius: .6rem;
  box-shadow: 0 8px 24px rgba(0,0,0,.28);
}
.context-menu-item {
  display: flex; align-items: center; gap: .55rem; width: 100%; padding: .45rem .6rem;
  border: none; border-radius: .4rem; background: none; cursor: pointer;
  font: inherit; font-size: .82rem; text-align: left; color: hsl(var(--foreground));
}
.context-menu-item:hover, .context-menu-item:focus-visible { background: hsl(var(--muted)); outline: none; }
.context-menu-item.danger { color: hsl(var(--destructive)); }
.context-menu-item:disabled { opacity: .55; cursor: default; background: none; }
.context-menu-item svg { width: 14px; height: 14px; flex-shrink: 0; }
/* Multi-select (Documents, Trash): the bar of bulk actions */
.selection-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .75rem;
  padding: .5rem .75rem; margin-bottom: .75rem; border-radius: var(--radius);
  background: hsl(var(--primary) / .08); border: 1px solid hsl(var(--primary) / .25);
}
.selection-bar .selection-count { font-size: .875rem; font-weight: 600; margin-right: auto; }
/* Resizable table columns (makeColumnsResizable in app.js) */
.col-resizer { position: absolute; top: 0; right: -3px; width: 7px; height: 100%; cursor: col-resize; user-select: none; z-index: 1; }
.col-resizer:hover, .col-resizing .col-resizer { background: hsl(var(--primary) / .35); }
.col-resizing, .col-resizing * { cursor: col-resize !important; user-select: none !important; }
/* Flat file picker (hidden <input type=file> + button + chosen name) */
.file-pick { display: flex; align-items: center; gap: .6rem; padding: .5rem .6rem; border: 1px dashed hsl(var(--border)); border-radius: var(--radius); background: hsl(var(--muted) / .3); }
.file-pick input[type=file] { display: none; }
.file-pick-name { font-size: .82rem; color: hsl(var(--muted-foreground)); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-pick-name.has-file { color: hsl(var(--foreground)); font-weight: 500; }
/* CSV preview (documents pane + DocPreview modal) */
.csv-preview { width: 100%; height: 100%; overflow: auto; background: hsl(var(--card)); }
.csv-table { border-collapse: collapse; font-size: .8rem; min-width: 100%; }
.csv-table th, .csv-table td { padding: .4rem .7rem; border: 1px solid hsl(var(--border)); text-align: left; white-space: nowrap; max-width: 28rem; overflow: hidden; text-overflow: ellipsis; }
.csv-table th { position: sticky; top: 0; background: hsl(var(--muted)); font-weight: 600; z-index: 1; }
.csv-table tbody tr:nth-child(even) { background: hsl(var(--muted) / .35); }
.csv-truncated { font-size: .75rem; color: hsl(var(--muted-foreground)); padding: .6rem .8rem; }
.dp-pane .dp-icon { width: 110px; height: 110px; border-radius: 1.2rem; }
.dp-pane .dp-icon svg { width: 46px; height: 46px; }
.dp-fallback { display: flex; flex-direction: column; align-items: center; gap: .7rem; text-align: center; }
.dp-view-only { display: inline-flex; align-items: center; gap: .4rem; }
.dp-view-only svg { width: 14px; height: 14px; }

/* ─── Zoomable/pannable image viewer (imageZoom.js) ───
   Used in place of a plain <img> for approved-image previews so the image
   shows at its true proportions (never stretched to fill the pane) with
   zoom in/out, drag-to-pan, mouse-wheel, and double-click-to-1:1. */
/* The zoom box must fill its pane (not size itself to the image) so that
   "fit" means fit-to-pane and anything larger scrolls INSIDE the box. Both
   panes that host it (.dp-pane, .dv-preview) are flex containers that
   centre their content; a centred flex child taller than its parent
   overflows equally above and below, and the part above can never be
   scrolled to — which showed up as tall images being "stuck" centred with
   their top and bottom cut off. So: stretch the box in those panes, and
   centre the image inside the viewport with auto margins instead of
   align/justify (auto margins collapse to 0 on overflow, so the image
   starts at the top-left and scrolls normally). */
.dp-zoom { position: relative; width: 100%; height: 100%; min-height: 0; align-self: stretch; flex: 1 1 auto; border-radius: .5rem; overflow: hidden; background: hsl(var(--card)); box-shadow: 0 2px 20px rgba(0,0,0,.12); }
.dp-pane:has(> .dp-zoom), .dv-preview:has(> .dp-zoom) { align-items: stretch; justify-content: stretch; }
.dp-zoom-viewport { width: 100%; height: 100%; overflow: auto; display: flex; cursor: grab; }
.dp-zoom-viewport.dragging { cursor: grabbing; }
.dp-zoom-img { max-width: none; margin: auto; flex-shrink: 0; user-select: none; -webkit-user-drag: none; display: block; }
.dp-zoom-controls {
  position: absolute; bottom: .75rem; right: .75rem; display: flex; align-items: center; gap: .15rem;
  background: hsl(var(--card) / .92); backdrop-filter: blur(6px); border: 1px solid hsl(var(--border));
  border-radius: 999px; padding: .3rem .4rem; box-shadow: 0 2px 10px rgba(0,0,0,.15);
}
.dp-zoom-btn {
  width: 1.7rem; height: 1.7rem; display: flex; align-items: center; justify-content: center;
  border-radius: 999px; border: none; background: transparent; cursor: pointer;
  font-size: 1rem; line-height: 1; color: hsl(var(--foreground));
}
.dp-zoom-btn:hover { background: hsl(var(--muted)); }
.dp-zoom-reset { width: auto; padding: 0 .55rem; font-size: .72rem; font-weight: 500; }
.dp-zoom-level { font-size: .72rem; color: hsl(var(--muted-foreground)); min-width: 2.6rem; text-align: center; }

.dp-censored { position: relative; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.dp-censored-img { width: 100%; height: 100%; object-fit: cover; filter: blur(28px) saturate(60%); transform: scale(1.05); pointer-events: none; }
.dp-censored-overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: .6rem; text-align: center; padding: 1.5rem;
  /* Solid, near-opaque scrim (not the old translucent one) — guarantees
     text contrast regardless of how light/dark the blurred image behind
     it is, instead of relying on --muted-foreground grey text that read
     poorly over dark images. */
  background: hsl(var(--card) / .94); backdrop-filter: blur(8px); border-radius: .5rem;
}
.dp-censored-overlay svg { color: hsl(var(--destructive)); width: 28px; height: 28px; }
.dp-censored-overlay p { max-width: 30ch; color: hsl(var(--foreground)); font-weight: 500; }
.dp-censored--revealed .dp-censored-img { filter: none; object-fit: contain; transform: none; }
.dp-censored--revealed .dp-censored-overlay { display: none; }
.dp-text { white-space: pre-wrap; font-size: .82rem; line-height: 1.6; padding: 1.25rem; height: 100%; overflow-y: auto; width: 100%; }
@media (max-width: 720px) {
  /* Phones: the preview takes the whole screen. At 90vh with a 7-line title
     an iPhone left the PDF ~200px tall. dvh = the area the toolbars leave. */
  .modal-overlay:has(.modal-lg) { padding: 0; }
  .modal-lg { width: 100%; max-width: 100%; height: 100vh; height: 100dvh; max-height: 100dvh; border-radius: 0; padding: .75rem .75rem .6rem; }
  .modal-lg .modal-title { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 1rem; }
  .modal-lg .modal-header { margin-bottom: .5rem; }
  .modal-lg .dp-meta { margin-bottom: .5rem; }
  .modal-lg .dp-maximize-btn { display: none; } /* already full screen */
  .modal-lg .modal-footer { margin-top: .6rem; padding-top: .6rem; }
}

.ai-summary-card {
  background: hsl(var(--primary) / 0.05); border: 1px solid hsl(var(--primary) / 0.2);
  border-radius: var(--radius); padding: 1rem; margin-top: 1rem;
}
.ai-summary-title { font-family: 'DM Sans', sans-serif; font-size: 1rem; font-weight: 600; display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
.ai-folder-suggest-row { display: flex; align-items: center; gap: 0.625rem; }
.ai-folder-suggest-row .gd-icon { color: hsl(var(--primary)); flex-shrink: 0; }
.ai-folder-suggest-main { flex: 1; min-width: 0; }
.ai-folder-suggest-main > div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-folder-suggest-row .btn { flex-shrink: 0; }
.ai-folder-suggest-alts { margin-top: 0.5rem; }
.ai-folder-suggest-alts .link-btn { padding: 0; font-size: inherit; }

/* ─── Trend ─── */
.trend { display: flex; align-items: center; gap: 0.25rem; font-size: 0.75rem; color: hsl(var(--primary)); margin-top: 0.5rem; }
.trend svg { width: 0.75rem; height: 0.75rem; }

/* ─── Knowledge Gap ─── */
.gap-item { display: flex; align-items: flex-start; gap: 0.75rem; padding: 0.75rem; border-radius: 0.5rem; background: hsl(var(--accent) / 0.1); }
.gap-num { font-size: 0.875rem; font-weight: 500; color: hsl(var(--accent)); margin-top: 0.125rem; }

/* ─── Contributor ─── */
.contributor { display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem; border-radius: 0.5rem; }
.contributor:hover { background: hsl(var(--muted) / 0.5); }
.contributor-avatar {
  width: 2rem; height: 2rem; border-radius: 9999px;
  background: hsl(var(--primary)); color: hsl(var(--primary-foreground));
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 500;
}

/* ─── Mobile sidebar toggle ─── */
@media (max-width: 767px) {
  .sidebar { position: fixed; left: -260px; top: 0; bottom: 0; z-index: 60; width: 260px; }
  .sidebar.open { left: 0; }
  .sidebar.collapsed { width: 260px; left: -260px; }
  .sidebar.collapsed.open { left: 0; }
  .sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 55; display: none; }
  .sidebar-overlay.open { display: block; }
}

/* ─── Modular utility classes (added for inline-style cleanup) ─── */

/* Page title block */
.page-header { display: flex; flex-direction: column; gap: 0.25rem; }
.page-title { font-size: 1.875rem; font-weight: 700; line-height: 1.2; }
.page-subtitle { color: hsl(var(--muted-foreground)); font-size: 0.95rem; }

/* Section headings smaller than page title */
.heading-sm { font-family: 'DM Sans', sans-serif; font-size: 1.125rem; font-weight: 600; }
.heading-xs { font-family: 'DM Sans', sans-serif; font-size: 0.875rem; font-weight: 600; }
.heading-xs--muted { color: hsl(var(--muted-foreground)); }

/* Width wrappers (centered) */
.wrap-narrow { max-width: 28rem; width: 100%; margin: 0 auto; }
.wrap-md     { max-width: 48rem; margin: 0 auto; }
.wrap-lg     { max-width: 56rem; margin: 0 auto; }
.wrap-xl     { max-width: 64rem; margin: 0 auto; }

/* Muted text helpers (size-aware) */
.text-muted    { color: hsl(var(--muted-foreground)); }
.text-sm       { font-size: 0.875rem; }
.text-xs       { font-size: 0.75rem; }
.text-2xs      { font-size: 0.7rem; }
.text-muted-sm { font-size: 0.875rem; color: hsl(var(--muted-foreground)); }
.text-muted-xs { font-size: 0.75rem;  color: hsl(var(--muted-foreground)); }
.text-uppercase{ text-transform: uppercase; }
.text-italic   { font-style: italic; }
.font-medium   { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold     { font-weight: 700; }
.font-display  { font-family: 'DM Sans', sans-serif; }

/* Margin / padding helpers */
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mt-5 { margin-top: 1.25rem; }
.mt-6 { margin-top: 1.5rem; }
.mt-8 { margin-top: 2rem; }
.mt-10 { margin-top: 2.5rem; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.mb-14 { margin-bottom: 3.5rem; }
.ml-auto { margin-left: auto; }
.ml-2 { margin-left: 0.5rem; }
.block { display: block; }
.mx-auto { margin-left: auto; margin-right: auto; }

/* Padded card-content variants */
.card-content-lg { padding: 1.5rem; }
.card-content-md { padding: 1.25rem; }
.card-content-sm { padding: 1rem; }

/* Clickable rows & hover surface */
.clickable { cursor: pointer; }
.row-hover { padding: 0.75rem; border-radius: 0.5rem; transition: background 0.15s; }
.row-hover:hover { background: hsl(var(--muted) / 0.5); }

/* Bordered inner panel (used in modal access section, user rows) */
.panel       { padding: 1rem; border: 1px solid hsl(var(--border)); border-radius: 0.5rem; }
.panel-row   { display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 0.75rem; border: 1px solid hsl(var(--border)); border-radius: 0.5rem; background: hsl(var(--muted) / 0.3); }
.panel-row__email { font-size: 0.8125rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Compact icon-only buttons in tables */
.btn-icon-xs { padding: 0.25rem; height: auto; width: auto; }
.text-destructive { color: hsl(var(--destructive)); }

/* Compact select variants */
.select-auto { width: auto; }
.select-sm   { height: 1.875rem; font-size: 0.75rem; padding: 0 0.5rem; }

/* Empty state inside a grid */
.empty-state {
  grid-column: 1 / -1; text-align: center;
  color: hsl(var(--muted-foreground)); padding: 2rem 0; font-size: 0.875rem;
}
.empty-state--lg { padding: 3rem 0; }

/* Folder card inner */
.folder-cover {
  padding: 0.75rem; border-radius: 0.5rem;
  background: hsl(var(--primary) / 0.1); display: inline-flex;
}
.folder-cover svg { color: hsl(var(--primary)); }

/* Upload zone copy */
.upload-zone__title { font-size: 1.125rem; font-weight: 600; font-family: 'DM Sans', sans-serif; }
.upload-zone__hint  { font-size: 0.75rem;  color: hsl(var(--muted-foreground)); margin-top: 0.25rem; }
.upload-zone__hint--sm { font-size: 0.875rem; color: hsl(var(--muted-foreground)); margin: 0.25rem 0; }

/* Modal header row */
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.modal-body { color: hsl(var(--foreground)); }
.modal-footer { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid hsl(var(--border)); }

/* Sidebar group label spacing override */
.sidebar-group-label--spaced { margin-top: 0.5rem; }

/* Trend pill (already had .trend) — alias for descending */
.trend--down { color: hsl(var(--destructive)); }

/* Pricing page tweaks */
.pricing-card__head { padding-top: 2rem; padding-bottom: 0.5rem; }
.pricing-card__cta  { width: 100%; margin-top: 1rem; }

/* Cross-org checkbox grid */
.access-org-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.4rem;
}

/* Search page input */
.search-bar-lg { position: relative; }
.search-bar-lg .search-icon {
  position: absolute; left: 1rem; top: 50%; transform: translateY(-50%);
  display: flex; align-items: center; color: hsl(var(--muted-foreground));
  pointer-events: none; line-height: 0;
}
.loading-state .search-thinking img { width: 28px; height: 28px; display: block; }
/* Brand glyph on suggestion chips, in the theme colour rather than the
   chip's text colour. */
.chip-mark { display: inline-flex; line-height: 0; color: hsl(var(--primary)); }
/* Suggested-prompt chips: AI Search (#chips) and Q&A (#chipsRow). One line each,
   "…" if a chip is wider than the space. Phones/tablets: one swipeable row instead of
   a wall of wrapped chips; the faded right edge shows there is more to swipe. */
.chip-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
#chips .btn, #chipsRow .chip-btn { max-width: 100%; min-width: 0; justify-content: flex-start; flex-shrink: 0; }
/* The icon keeps its size however long the question is (it used to shrink to make room). */
#chips .btn svg, #chips .chip-mark, #chipsRow .chip-btn svg { flex-shrink: 0; }
@media (max-width: 900px) {
  #chips, #chipsRow {
    flex-wrap: nowrap; overflow-x: auto; scroll-snap-type: x proximity; overscroll-behavior-x: contain;
    scrollbar-width: none; padding-right: 2rem;
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 2.5rem), transparent);
            mask-image: linear-gradient(to right, #000 calc(100% - 2.5rem), transparent);
  }
  #chips::-webkit-scrollbar, #chipsRow::-webkit-scrollbar { display: none; }
  #chips .btn, #chipsRow .chip-btn { max-width: min(78vw, 20rem); scroll-snap-align: start; }
}
.search-bar-lg .input {
  padding-left: 3rem; padding-right: 6rem; border-radius: 0.75rem;
}
.search-bar-lg .btn-submit {
  position: absolute; right: 0.5rem; top: 50%; transform: translateY(-50%);
}

/* Full-width button helper */
.btn-block { width: 100%; }

/* Login layout helpers */
.login-stack { width: 100%; max-width: 28rem; }
.login-header { text-align: center; margin-bottom: 1.5rem; }
.input-with-toggle { position: relative; }

/* Stat icon size variant */
.stat-icon--sm { padding: 0.625rem; }

/* Org chip dot inline-helper (color still inline as data-driven) */

/* Chat input wrap — fixed-position send button */
.chat-input-wrap .send-btn {
  position: absolute; right: 0.375rem; top: 50%; transform: translateY(-50%);
  width: 2.25rem; height: 2.25rem;
}

/* Source badge on chat (translucent bg) */
.chat-source-badge { gap: 0.25rem; background: hsl(var(--background) / 0.5); }

/* Settings: user-status active badge (re-skinned outline) */
.badge-status-active { color: hsl(var(--primary)); border-color: hsl(var(--primary)); }

/* Doc card extra-compact padding */
.card-content--compact { padding: 1rem; }

/* Center the logo for the login page */
.justify-center { justify-content: center; }

/* ── SmartKMS runtime additions ─────────────────────────────────────── */

/* Loading / empty / error states */
.loading-state, .empty-state, .error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .75rem;
  padding: 3rem 1rem;
  text-align: center;
  color: hsl(var(--muted-foreground));
}
.error-state { color: hsl(var(--destructive)); }

.spinner {
  width: 32px; height: 32px;
  border: 3px solid hsl(var(--muted));
  border-top-color: hsl(var(--primary));
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Typing dots */
.typing-dots span {
  animation: blink 1.2s infinite;
  font-size: 1.4rem;
  line-height: 1;
}
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100%{opacity:0} 40%{opacity:1} }

/* Card hover */
.card-hover { transition: box-shadow .15s, transform .15s; cursor: pointer; }
.card-hover:hover { box-shadow: 0 4px 16px rgba(0,0,0,.1); transform: translateY(-1px); }

/* Sidebar profile: a button that opens the account menu (Help, Log out)
   in a popover ABOVE itself. The menu is position:fixed and placed by
   toggleSidebarUserMenu() so it escapes the sidebar's overflow:hidden —
   needed for the 56px collapsed rail, where an in-flow menu would be
   clipped. Long names/roles truncate rather than wrap. */
.sidebar-user-wrap { position: relative; }
.sidebar-user {
  display: flex; align-items: center; gap: .6rem; width: 100%;
  padding: .5rem 1.25rem; min-width: 0;
  background: none; border: 0; color: inherit; font: inherit; text-align: left;
  cursor: pointer; transition: background .15s;
}
.sidebar-user:hover, .sidebar-user.is-open { background: hsl(var(--sidebar-accent-bg)); }
.sidebar-user:focus-visible { outline: 2px solid hsl(var(--ring)); outline-offset: -2px; }
.sidebar-user-avatar {
  width: 32px; height: 32px; border-radius: 50%; overflow: hidden;
  background: hsl(var(--primary)); color: hsl(var(--primary-foreground));
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 700; flex-shrink: 0;
}
.sidebar-user-info  { min-width: 0; flex: 1; }
.sidebar-user-name,
.sidebar-user-role  { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-name  { font-size: .8rem; font-weight: 600; line-height: 1.2; }
.sidebar-user-role  { font-size: .7rem; color: hsl(var(--muted-foreground)); }
.sidebar-user-caret { width: 14px; height: 14px; flex-shrink: 0; color: hsl(var(--muted-foreground)); transition: transform .15s; }
.sidebar-user.is-open .sidebar-user-caret { transform: rotate(180deg); }
.sidebar.collapsed .sidebar-user { justify-content: center; padding: .5rem 0; }
.sidebar.collapsed .sidebar-user-info,
.sidebar.collapsed .sidebar-user-caret { display: none; }

.sidebar-user-menu {
  position: fixed; z-index: 70; min-width: 220px;
  background: hsl(var(--card)); color: hsl(var(--foreground));
  border: 1px solid hsl(var(--border)); border-radius: .6rem;
  box-shadow: 0 10px 28px rgba(0,0,0,.18); padding: .3rem;
  display: flex; flex-direction: column;
  animation: msg-enter-up .14s ease-out backwards;
}
.sidebar-user-menu[hidden] { display: none; }
@keyframes msg-enter-up { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.sidebar-menu-item {
  display: flex; align-items: center; gap: .55rem; width: 100%;
  padding: .5rem .6rem; border: 0; background: none; text-align: left;
  font: inherit; font-size: .82rem; border-radius: .4rem; cursor: pointer;
  color: hsl(var(--foreground)); text-decoration: none;
}
.sidebar-menu-item:hover { background: hsl(var(--muted)); }
.sidebar-menu-item svg { width: 15px; height: 15px; flex-shrink: 0; }
.sidebar-menu-item span { flex: 1; }
.sidebar-menu-caret { color: hsl(var(--muted-foreground)); transition: transform .15s; }
.sidebar-menu-item.is-open .sidebar-menu-caret { transform: rotate(180deg); }
.sidebar-menu-sub { display: flex; flex-direction: column; }
.sidebar-menu-sub[hidden] { display: none; }
.sidebar-menu-item--sub { padding-left: 2.15rem; font-size: .8rem; }
.sidebar-menu-sep { height: 1px; background: hsl(var(--border)); margin: .3rem .25rem; }
.sidebar-menu-item--danger { color: hsl(var(--destructive)); }
.sidebar-menu-item--danger:hover { background: hsl(var(--destructive) / .08); }

/* Error banner */
.error-banner {
  padding: .65rem .9rem;
  background: hsl(var(--destructive) / .1);
  border: 1px solid hsl(var(--destructive) / .3);
  border-radius: .375rem;
  color: hsl(var(--destructive));
  font-size: .875rem;
}

/* link helper */
a.link { color: hsl(var(--primary)); text-decoration: underline; }

/* ── Display preferences (Settings → Display) ─────────────────────────────
   Applied as data-attributes on <html> by applyDisplayPrefs() in layout.js,
   restored on every page load the same way the sidebar-collapsed state is. */
[data-density="compact"] .card-content { padding: 0.85rem; }
[data-density="compact"] .card-header  { padding: 0.85rem 0.85rem 0.35rem; }
[data-density="compact"] th            { padding: 0.45rem 0.6rem; }
[data-density="compact"] td            { padding: 0.45rem 0.6rem; }
[data-density="compact"] .sidebar-link { padding: 0.4rem 0.75rem; }

[data-reduce-motion="true"] *,
[data-reduce-motion="true"] *::before,
[data-reduce-motion="true"] *::after {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
  scroll-behavior: auto !important;
}

/* ── Admin management tables (Users / Settings pages) ─────────────────────
   Shared by users.html and settings.html: small icon action buttons, the
   active/inactive + role badges, and the modal form spacing. */
.act-btn {
  width: 32px; height: 32px; border-radius: .4rem; border: 1px solid hsl(var(--border));
  background: transparent; display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all .12s; color: hsl(var(--muted-foreground));
}
.act-btn:hover { background: hsl(var(--muted)); color: hsl(var(--foreground)); }
.act-btn:disabled { opacity: .45; cursor: default; }
.act-btn.act-danger:hover { background: hsl(0 72% 96%); color: hsl(0 65% 42%); border-color: hsl(0 60% 85%); }
.dark .act-btn.act-danger:hover { background: hsl(0 70% 55% / .16); color: hsl(0 80% 74%); border-color: hsl(0 60% 45% / .5); }
.act-btn svg { width: 15px; height: 15px; }
.badge-active   { background: hsl(142 60% 94%); color: hsl(142 55% 28%); border: 1px solid hsl(142 50% 82%); }
.dark .badge-active { background: hsl(142 60% 45% / .16); color: hsl(142 55% 68%); border-color: hsl(142 50% 40% / .5); }
.badge-inactive { background: hsl(var(--muted)); color: hsl(var(--muted-foreground)); }
.badge-admin    { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.badge-staff    { background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground)); }
.section-head-row { display: flex; align-items: center; justify-content: space-between; gap: .5rem; flex-wrap: wrap; }
.modal-form .form-group { margin-bottom: .9rem; }
.modal-form label { font-size: .82rem; font-weight: 600; display: block; margin-bottom: .3rem; }
.field-hint { font-size: .72rem; color: hsl(var(--muted-foreground)); margin-top: .3rem; }

/* ─── Organization color picker (Settings → Add / Edit Organization) ─── */
.org-swatches { display: flex; flex-wrap: wrap; gap: .55rem; }
.org-swatch {
  position: relative; width: 2rem; height: 2rem; border-radius: 9999px; padding: 0; margin: 0;
  border: none; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  color: #fff; box-shadow: inset 0 0 0 1px rgb(0 0 0 / .12); transition: transform .12s, box-shadow .12s;
}
.org-swatch:hover { transform: scale(1.08); }
.org-swatch:focus-visible, .org-swatch-custom:focus-within { outline: 2px solid hsl(var(--ring)); outline-offset: 2px; }
.org-swatch svg { width: .9rem; height: .9rem; opacity: 0; filter: drop-shadow(0 1px 1px rgb(0 0 0 / .35)); pointer-events: none; }
.org-swatch.selected { box-shadow: 0 0 0 2px hsl(var(--card)), 0 0 0 4px hsl(var(--foreground) / .7); }
.org-swatch.selected svg { opacity: 1; }
/* Custom: a colour wheel until a colour outside the presets is chosen, then that colour. */
.org-swatch-custom { background: conic-gradient(#e5484d, #f5a623, #f8e71c, #46a758, #00a2c7, #3e63dd, #8e4ec6, #e5484d); }
.modal-form label.org-swatch-custom { display: inline-flex; margin: 0; }
.org-swatch-custom input[type="color"] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.org-color-row { display: flex; align-items: center; gap: .75rem; margin-top: .85rem; flex-wrap: wrap; }
.org-hex { position: relative; width: 7.5rem; flex-shrink: 0; }
.org-hex > span { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: hsl(var(--muted-foreground)); font-size: .875rem; pointer-events: none; }
.org-hex .input { padding-left: 1.6rem; font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; text-transform: uppercase; letter-spacing: .03em; }
.org-preview {
  flex: 1; min-width: 12rem; display: flex; align-items: center; gap: .55rem; height: 2.5rem; padding: 0 .85rem;
  border: 1px dashed hsl(var(--border)); border-radius: var(--radius); font-size: .875rem; overflow: hidden;
}
.org-preview-dot { width: .625rem; height: .625rem; border-radius: 9999px; flex-shrink: 0; }
.org-preview-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.org-preview-name.is-empty { color: hsl(var(--muted-foreground)); }
.org-preview-code { margin-left: auto; font-size: .72rem; font-weight: 600; padding: .1rem .5rem; border: 1px solid hsl(var(--border)); border-radius: 9999px; color: hsl(var(--muted-foreground)); }
.org-preview-code[hidden] { display: none; }

/* ─── Sharing: access choice + per-person download switch (documents.html) ─── */
.share-choices { display: grid; gap: .5rem; }
.share-choice, .share-download {
  display: flex; align-items: flex-start; gap: .65rem; padding: .7rem .85rem; cursor: pointer;
  border: 1px solid hsl(var(--border)); border-radius: calc(var(--radius) - .25rem); font-size: .875rem;
}
.share-choice:has(input:checked) { border-color: hsl(var(--primary)); background: hsl(var(--primary) / .06); }
.share-choice input, .share-download input { margin-top: .2rem; accent-color: hsl(var(--primary)); }
.share-choice > span:last-child, .share-download > span:last-child { display: flex; flex-direction: column; gap: .1rem; }
.share-choice-icon { color: hsl(var(--muted-foreground)); line-height: 0; margin-top: .15rem; }
.share-download { margin-top: .75rem; border-style: dashed; }
.share-dl-toggle {
  display: inline-flex; align-items: center; justify-content: center; gap: .2rem; flex-shrink: 0;
  height: 1.875rem; padding: 0 .45rem; border: 1px solid hsl(var(--border)); border-radius: .5rem; cursor: pointer;
  color: hsl(var(--muted-foreground));
}
.share-dl-toggle input { margin: 0; accent-color: hsl(var(--primary)); }
.share-dl-toggle:has(input:checked) { color: hsl(var(--primary)); }
.share-dl-toggle:has(input:not(:checked)) svg { opacity: .45; }
.ai-folder-suggest .ai-summary-title { position: relative; padding-right: 1.75rem; }
.ai-folder-suggest-close {
  position: absolute; right: -.25rem; top: 50%; transform: translateY(-50%);
  width: 1.6rem; height: 1.6rem; display: inline-flex; align-items: center; justify-content: center;
  border: none; background: none; border-radius: .4rem; cursor: pointer; color: hsl(var(--muted-foreground));
}
.ai-folder-suggest-close:hover { background: hsl(var(--muted)); color: hsl(var(--foreground)); }

/* Cross-org sharing: a ticked organization shows its access + download controls. */
.org-share-row { border-radius: .5rem; }
.org-share-row.is-on { border: 1px solid hsl(var(--primary) / .35); background: hsl(var(--primary) / .04); }
.org-share-row.is-on > .checkbox-row { border: none; }
.org-share-controls { display: flex; align-items: center; gap: .4rem; padding: 0 .75rem .6rem 2.1rem; }

/* Share dialog: e-mail suggestions */
.share-email { position: relative; }
.share-suggest {
  position: absolute; left: 0; right: 0; top: calc(100% + .3rem); z-index: 5; max-height: 16rem; overflow-y: auto;
  background: hsl(var(--popover)); border: 1px solid hsl(var(--border)); border-radius: calc(var(--radius) - .25rem);
  box-shadow: 0 10px 30px -10px rgb(0 0 0 / .25); padding: .25rem;
}
.share-suggest-item {
  display: flex; align-items: center; gap: .6rem; width: 100%; padding: .45rem .55rem; border: none; background: none;
  border-radius: .45rem; cursor: pointer; text-align: left; font: inherit; color: hsl(var(--foreground));
}
.share-suggest-item:hover, .share-suggest-item.is-active { background: hsl(var(--muted)); }
.share-suggest-avatar {
  width: 1.75rem; height: 1.75rem; border-radius: 9999px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
  background: hsl(var(--primary) / .12); color: hsl(var(--primary)); font-size: .75rem; font-weight: 600;
}
.share-suggest-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.share-suggest-email { font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share-suggest-item mark { background: none; color: inherit; font-weight: 700; }
.share-suggest-recent { display: inline-flex; align-items: center; gap: .2rem; font-size: .68rem; color: hsl(var(--muted-foreground)); flex-shrink: 0; }
.field-hint.is-error { color: hsl(var(--destructive)); }

/* Profile picture (Settings → Profile, sidebar) */
.sidebar-user-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.profile-head { display: flex; align-items: center; gap: 1rem; }
.profile-avatar {
  position: relative; width: 4.5rem; height: 4.5rem; border-radius: 9999px; flex-shrink: 0; cursor: pointer;
  background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); overflow: hidden;
  display: flex; align-items: center; justify-content: center; font-size: 1.35rem; font-weight: 700;
  box-shadow: 0 0 0 3px hsl(var(--card)), 0 0 0 4px hsl(var(--border));
}
.profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
.profile-avatar-edit {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgb(0 0 0 / .45); color: #fff; opacity: 0; transition: opacity .15s;
}
.profile-avatar:hover .profile-avatar-edit, .profile-avatar:focus-within .profile-avatar-edit { opacity: 1; }
.profile-avatar-actions { display: flex; align-items: center; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; font-size: .8rem; }
.profile-avatar-actions .link-btn { font-size: .8rem; padding: 0; }

/* A person's picture or initials next to their name (Reapprovals, …) */
.person-chip { display: inline-flex; align-items: center; gap: .45rem; min-width: 0; }
.person-avatar {
  width: 1.35rem; height: 1.35rem; border-radius: 9999px; flex-shrink: 0; object-fit: cover;
  background: hsl(var(--primary)); color: hsl(var(--primary-foreground));
  display: inline-flex; align-items: center; justify-content: center; font-size: .6rem; font-weight: 700;
}
