:root {
  --color-bg: #FBFAF7;
  --color-surface: #FFFFFF;
  --color-elevated: #FBFAF7;
  --color-border: #DEDCD6;
  --color-border-strong: #C0BEB5;
  --color-text: #0B1433;
  --color-muted: #596378;
  --color-primary: #0B1F4D;
  --color-primary-hover: #0B1433;
  --color-danger: #DE3C37;
  --color-success: #169F65;
  --color-warning: #B08505;
  --reader-paper: #FFFFFF;
  --reader-ink: #0B1433;
  --reader-highlight: #FFEEC3;
  --reader-highlight-strong: #FECD5C;
  --radius-8: 8px;
  --radius-12: 12px;
  --radius-16: 16px;
  --radius-22: 22px;
  --radius-28: 28px;
  --shadow-soft: 0 10px 24px -10px rgba(11, 20, 51, 0.18);
  --shadow-medium: 0 24px 48px -24px rgba(11, 20, 51, 0.28);
  --shadow-overlay: 0 44px 88px -44px rgba(11, 20, 51, 0.45);
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --font-12: 12px;
  --font-14: 14px;
  --font-16: 16px;
  --font-18: 18px;
  --font-20: 20px;
  --font-24: 24px;
  --font-32: 32px;
  --font-sans: "IBM Plex Sans", "Inter", "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-serif: "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  /* Already loaded for the reader; the landing uses the same editorial voice. */
  --font-display: "Source Serif 4", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --line-height: 1.6;
  --z-sidebar: 100;
  --z-topbar: 200;
  --z-dropdown: 1050;
  /* Keep modals above any app overlays/backdrops (Bootstrap defaults are ~1050+). */
  --z-modal: 2000;
  --bg: var(--color-bg);
  --surface: var(--color-surface);
  --surface-2: var(--color-elevated);
  --paper: var(--reader-paper);
  --bg-muted: #EEEDE8;
  --bg-page: var(--bg);
  --bg-surface: var(--surface);
  --bg-elevated: var(--surface-2);
  --bg-paper: var(--paper);
  --text-main: var(--color-text);
  --text-muted: var(--color-muted);
  --text-on-primary: #FFFFFF;
  --text: var(--color-text);
  --muted: var(--color-muted);
  --border-soft: var(--color-border);
  --border-strong: var(--color-border-strong);
  --border: var(--color-border);
  --primary: var(--color-primary);
  --primary-hover: var(--color-primary-hover);
  --primary-ink: var(--color-primary-hover);
  --accent: #0B1F4D;
  --accent-soft: #F3F7FF;
  --accent-line: #C7DBFF;
  --danger: var(--color-danger);
  --success: var(--color-success);
  --warning: var(--color-warning);
  --radius-sm: var(--radius-8);
  --radius-md: var(--radius-12);
  --radius-lg: var(--radius-16);
  --radius-xl: var(--radius-22);
  --radius-2xl: var(--radius-28);
  --shadow-sm: var(--shadow-soft);
  --shadow-md: var(--shadow-medium);
  --shadow-subtle: 0 6px 18px rgba(11, 20, 51, 0.08);
  --paper-shadow: 0 20px 40px rgba(11, 20, 51, 0.12);
  --sp-1: var(--space-1);
  --sp-2: var(--space-2);
  --sp-3: var(--space-3);
  --sp-4: var(--space-4);
  --sp-5: var(--space-5);
  --sp-6: var(--space-6);
}

* {
  box-sizing: border-box;
}

body.app-body {
  /* Flat: a page that shades from one grey to another reads as a surface,
     and everything on it has to fight for separation. */
  background: #FBFAF7;
  color: var(--text-main);
  font-family: var(--font-sans);
  min-height: 100vh;
  line-height: var(--line-height);
  overflow: hidden;
}

body.app-body[data-app-page="standalone"] {
  overflow: auto;
}

body.app-body[data-app-page="standalone"] .app-content,
body.app-body[data-app-page="standalone"] .page-layout,
body.app-body[data-app-page="standalone"] .page-main {
  height: auto;
  min-height: auto;
  overflow: visible;
}

a {
  color: inherit;
}

:focus-visible {
  outline: 2px solid rgba(11, 31, 77, 0.45);
  outline-offset: 2px;
}

.hidden,
.is-hidden {
  display: none !important;
}

/* Le rappel d'essai vit dans components/page_basics.css, chargé partout : il
 * était redéclaré ici et dans pages/admin.css, si bien qu'un changement de
 * position se faisait à trois endroits (23 septembre). */

.btn {
  border-radius: var(--radius-md);
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #FFFFFF;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.16);
}

.btn-primary:hover,
.btn-primary:focus {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-secondary,
.btn-outline-secondary {
  color: var(--text-main);
  background: #FFFFFF;
  border-color: var(--border-soft);
}

.btn-outline-secondary:hover,
.btn-outline-secondary:focus,
.btn-secondary:hover,
.btn-secondary:focus {
  background: rgba(11, 20, 51, 0.06);
  color: var(--primary);
  border-color: rgba(11, 20, 51, 0.16);
  transform: translateY(-1px);
}

.btn-light {
  background: #F7F6F2;
  border-color: var(--border-soft);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-main);
}

.btn-icon {
  width: 42px;
  height: 42px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
}

.form-control,
.form-select,
.input-group .form-control {
  border-radius: var(--radius-md);
  border-color: var(--border-soft);
  padding: 0.65rem 0.85rem;
  height: 44px;
  font-size: var(--font-14);
  background: #FFFFFF;
}

.form-control:focus,
.form-select:focus {
  box-shadow: 0 0 0 0.2rem rgba(11, 20, 51, 0.12);
  border-color: var(--primary);
}

.form-control::placeholder {
  color: rgba(89, 99, 120, 0.7);
}

.card,
.app-card {
  background: var(--bg-surface);
  border: 1px solid rgba(192, 190, 181, 0.9);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  transition: box-shadow 0.25s ease, transform 0.25s ease;
}

.card:hover,
.app-card:hover {
  box-shadow: var(--shadow-medium);
  transform: translateY(-2px);
}

.table {
  border-color: var(--border-soft);
}

.table thead th {
  border-bottom: 1px solid var(--border-soft);
  color: var(--text-muted);
  font-weight: 600;
  font-size: var(--font-12);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.table tbody tr:hover {
  background: rgba(11, 20, 51, 0.03);
}

.table tbody tr {
  transition: background 0.2s ease;
}

.sidebar-brand img {
  width: 36px;
  height: 36px;
}

.sidebar-link .icon {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.65);
}

.sidebar-link:hover .icon,
.sidebar-link:focus .icon {
  background: rgba(11, 31, 77, 0.20);
  color: #0B1F4D;
}

.sidebar-link.active .icon {
  background: rgba(11, 31, 77, 0.25);
  color: #224AA9;
}

.global-search {
  position: relative;
}

.global-search .input-group {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  max-width: 980px;
  width: min(980px, 100%);
}

.global-search .search-field {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
}

.global-search .form-control {
  height: 52px;
  border-radius: 999px;
  border: 1px solid rgba(192, 190, 181, 0.9);
  padding-left: 3rem;
  padding-right: 3.6rem;
  background: #FFFFFF;
  font-size: var(--font-16);
  width: 100%;
  box-shadow: 0 10px 22px rgba(11, 20, 51, 0.08);
}

/* The magnifier at the start of the field is the submit button, on every page
   the topbar appears on: quiet until there is something to search for, then
   in the navy of an action. */
.global-search .search-submit {
  position: absolute;
  left: 0.45rem;
  top: 50%;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: none;
  color: #959FB2;
  font-size: 0.85rem;
  transform: translateY(-50%);
  cursor: pointer;
  transition: color 140ms ease-out, background-color 140ms ease-out;
}
.global-search.has-value .search-submit { color: #0B1F4D; }
.global-search .search-submit:hover,
.global-search .search-submit:focus-visible {
  background: rgba(11, 31, 77, 0.08);
  color: #0B1F4D;
  outline: none;
}
@media (prefers-reduced-motion: reduce) {
  .global-search .search-submit { transition: none; }
}

.global-search .search-shortcut {
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.75rem;
  color: var(--text-muted);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 0.15rem 0.4rem;
  background: var(--bg-surface);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.global-search.has-value .search-shortcut {
  opacity: 0;
  transform: translateY(-50%) scale(0.9);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.action-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-main);
  border: 1px solid rgba(192, 190, 181, 0.9);
  background: #FFFFFF;
  transition: background 0.2s ease, color 0.2s ease, border 0.2s ease, transform 0.2s ease;
  box-shadow: var(--shadow-subtle);
}

.action-icon:hover {
  background: #EEEDE8;
  color: var(--primary);
  transform: translateY(-1px);
}

.page-header {
  display: none;
}

.page-layout {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  width: 100%;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
}

.page-title {
  font-size: var(--font-24);
  font-weight: 700;
  margin: 0;
}

.page-actions .btn {
  border-radius: var(--radius-md);
}

.card,
.shadow-card {
  border-radius: var(--radius-lg);
  border: 1px solid rgba(192, 190, 181, 0.9);
  box-shadow: var(--shadow-subtle);
  background: var(--bg-surface);
}

.card-header,
.card-body,
.card-footer {
  background: transparent;
}

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

.table-modern th,
.table-modern td {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border-soft);
}

.table-modern tbody tr:hover {
  background: rgba(11, 20, 51, 0.04);
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: rgba(11, 20, 51, 0.08);
  color: var(--primary);
  font-weight: 600;
  font-size: 0.85rem;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: rgba(11, 20, 51, 0.06);
  color: #0B1433;
  font-size: 0.8rem;
  font-weight: 600;
  margin-right: var(--sp-2);
  margin-bottom: var(--sp-1);
}

.paper-pane {
  background: var(--bg-paper);
  border-radius: var(--radius-lg);
  box-shadow: var(--paper-shadow);
  padding: var(--sp-6);
  border: 1px solid rgba(192, 190, 181, 0.82);
  max-width: 920px;
  margin: 0 auto;
  color: var(--reader-ink);
  line-height: 1.8;
  font-family: var(--font-serif);
  transition: box-shadow 0.25s ease, transform 0.25s ease;
}

.paper-pane:hover {
  box-shadow: var(--shadow-overlay);
  transform: translateY(-2px);
}

.paper-pane h1,
.paper-pane h2,
.paper-pane h3,
.paper-pane h4 {
  font-family: var(--font-serif);
  color: var(--reader-ink);
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
}

.reader-toolbar {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-subtle);
}

.reader-toolbar .btn {
  border-radius: var(--radius-md);
}

.occurrence-panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: var(--sp-4);
  box-shadow: var(--shadow-subtle);
}

.occurrence-item {
  padding: var(--sp-3);
  border-radius: var(--radius-md);
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.occurrence-item:hover {
  background: #EEEDE8;
  box-shadow: var(--shadow-subtle);
  cursor: pointer;
}

.tree-panel {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  box-shadow: var(--shadow-subtle);
}

.tree-panel__header {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}

.tree-panel__body {
  padding: var(--sp-3);
}

.filter-card {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  padding: var(--sp-4);
  box-shadow: var(--shadow-subtle);
}

.filter-card__header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-3);
}

.filter-card__reset {
  margin-left: auto;
  border: none;
  background: none;
  color: var(--text-muted);
}

.document-preview-panel {
  position: sticky;
  top: 1rem;
}

#main-app {
  background: transparent;
  /* Same reason as .page-main above: this sits between it and the reader. */
  min-width: 0;
}

#landing {
  background: var(--bg-paper);
  border: 1px dashed var(--border-soft);
  border-radius: var(--radius-lg);
  padding: var(--sp-6);
  color: var(--text-main);
  box-shadow: var(--shadow-subtle);
}

#app-loader {
  background: rgba(247, 246, 242, 0.85);
  backdrop-filter: blur(3px);
}

.modal-content {
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow-soft);
  animation: modal-rise 0.25s ease;
}

.tab-pane.active {
  animation: panel-reveal 0.35s ease;
}

.fade-in-up {
  animation: panel-reveal 0.35s ease;
}

.modal-body {
  max-height: 70vh;
  min-height: 180px;
  overflow: auto;
}

/* `background-color`, not `background`.
 *
 * Bootstrap draws the × as a background-image on .btn-close. The shorthand
 * here reset it to none, so every modal in the application had a close button
 * that was a blank white circle: it was in the right place, the right size,
 * and completely invisible - which is what the review meant by close buttons
 * not being where the eye looks for them. The only ways out of a dialog were
 * Escape, the scrim, or a footer button where there happened to be one. */
.modal-header .btn-close,
.modal-header .close {
  box-sizing: border-box;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background-color: #FFFFFF;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  box-shadow: 0 6px 16px rgba(11, 20, 51, 0.12);
}

.modal-header {
  position: relative;
  padding-right: 3.5rem;
}

/* Centred on the header, whatever its height: a fixed offset from the top put
   the button across the rule of any header shorter than the upload dialog's. */
.modal-header .btn-close,
.modal-header .close {
  position: absolute;
  top: 50%;
  right: 0.85rem;
  margin: 0;
  transform: translateY(-50%);
}

.modal-header .close span {
  font-size: 1.2rem;
  line-height: 1;
  color: var(--text-main);
}

.modal-backdrop { z-index: calc(var(--z-modal) - 10) !important; }
.modal { z-index: var(--z-modal) !important; }

.loader,
.loading-spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid rgba(11, 20, 51, 0.14);
  border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

.skeleton {
  border-radius: var(--radius-md);
  background: linear-gradient(90deg, #DEDCD6 0%, #F7F6F2 50%, #DEDCD6 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease infinite;
}

.skeleton.skeleton-text {
  height: 12px;
  width: 100%;
  margin-bottom: 0.5rem;
}

.dropdown-menu {
  border-radius: var(--radius-md);
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow-soft);
}

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

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@keyframes panel-reveal {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes modal-rise {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.form-control,
.form-select {
  border-radius: var(--radius-md);
  border: 1px solid var(--border-soft);
  background: var(--bg-surface);
}

.form-control:focus,
.form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 0.2rem rgba(11, 20, 51, 0.12);
}

.badge-soft {
  background: rgba(11, 20, 51, 0.12);
  color: var(--primary);
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
}

.list-group-item {
  border-color: var(--border-soft);
}

.highlight-swatch {
  width: 32px;
  height: 24px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
}

kbd {
  font-family: var(--font-sans);
  font-size: 0.7rem;
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
  border: 1px solid var(--border-soft);
  background: #FFFFFF;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* Legacy spacing helpers (Bootstrap 4 compatibility for existing templates) */
.mr-1 { margin-right: 0.25rem !important; }
.mr-2 { margin-right: 0.5rem !important; }
.mr-3 { margin-right: 1rem !important; }
.ml-1 { margin-left: 0.25rem !important; }
.ml-2 { margin-left: 0.5rem !important; }
.ml-3 { margin-left: 1rem !important; }
.ml-auto { margin-left: auto !important; }
.mr-auto { margin-right: auto !important; }

@media (max-width: 991.98px) {

  .global-search .search-shortcut {
    display: none;
  }
}
