/* =====================================================
   1. Custom styles (formerly custom.css)
   ===================================================== */

/* Add Taguette font */
@font-face {
  font-family: BadScript;
  font-display: swap;
  src: url(../webfonts/BadScript.ttf);
}

/* Add body font */
@font-face {
  font-family: Montserrat;
  font-display: fallback;
  src: url(../webfonts/Montserrat-Light.ttf);
}

/* Change link colors */
.container-body a:not(.btn) {
  color: var(--ui-link-color);
}

/* Disabled links */
#document-contents a:not([href]):not(.highlight) {
  color: var(--ui-muted);
}

/* Change body font */
body {
  font-family: var(--font-sans) !important;
  font-size: var(--font-size-base) !important;
  line-height: var(--line-height-normal);
}

/* Some space before content */
.container-body {
  padding-top: 1em;
}

/* Border for the tab container */
.tab-content {
  border-style: solid;
  border-width: 1px;
  border-color: var(--ui-surface) var(--ui-border) var(--ui-border) var(--ui-border);
  background: var(--ui-surface);
  padding: 0.4em;
}

/* Left pane scrolls on overflow — but must NOT set a fixed 100vh height
   that traps the page. Use max-height + overflow-y:auto for internal scroll. */
div.sticky-top {
  overflow-x: hidden;
  overflow-y: auto;
  max-height: calc(100vh - 96px); /* room for navbar (~56px) + toolbar (~40px) */
}

/* Footer */
.footer {
  font-size: 0.82em;
  text-align: center;
}

/* Navigation */

.navbar.navbar-expand-lg.navbar-dark.bg-primary {
  background-color: var(--ui-nav-bg) !important;
}

.navbar-dark .navbar-nav .nav-link {
  color: rgba(255, 255, 255, 0.8) !important;
  transition: color var(--transition-fast), opacity var(--transition-fast);
}

.navbar-dark .navbar-nav .nav-link.disabled {
  color: rgba(255, 255, 255, 0.4) !important;
}

.navbar-dark .navbar-nav .nav-link.active {
  color: #fff !important;
  font-weight: var(--font-weight-semibold) !important;
}

.navbar-dark .navbar-nav .nav-link.disabled:hover, .navbar-dark .navbar-nav .nav-link.disabled:focus {
  color: rgba(255, 255, 255, 0.4) !important;
}

.navbar-dark .navbar-nav .nav-link:hover, .navbar-dark .navbar-nav .nav-link:focus {
  color: #fff !important;
}

.navbar-dark .navbar-nav .dropdown-item.active {
  color: #fff !important;
  background-color: var(--color-primary) !important;
}

/* Make icon lighter */
.navbar-dark .navbar-nav .nav-link .fas {
  opacity: 0.8;
}

/* Fix margins in RTL */
html[dir="rtl"] .navbar-nav.t-ms-auto {
  margin-right: auto !important;
}

html:not([dir="rtl"]) .navbar-nav.t-ms-auto {
  margin-left: auto !important;
}

html[dir="rtl"] .navbar-nav.t-me-auto {
  margin-left: auto !important;
}

html:not([dir="rtl"]) .navbar-nav.t-me-auto {
  margin-right: auto !important;
}

/* Tab navs for project*/

.nav-link {
  padding: 0.5rem 0.5rem !important;
}

/* Document version tabs */
.document-version-tabs__tab {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.document-version-tabs__tab.disabled {
  pointer-events: none;
  opacity: 0.6;
}

.document-version-tabs__badge {
  font-size: 0.7rem;
}

/* ── Document version panel: unified sizing ── */
section[id^="document-version-panel-"] {
  min-height: 70vh;
  height: calc(100vh - 200px);
  overflow-y: auto;
  box-sizing: border-box;
}

/* Scrollable panels: same sizing, explicit scroll padding */
.document-panel__content--scroll {
  padding-right: 0.5rem;
}

/* PDF panel needs full viewport height for iframe */
#document-version-panel-pdf {
  height: calc(100vh - 160px);
}

/* Markdown panel: let the editor fill the container */
#document-version-panel-markdown {
  display: flex;
  flex-direction: column;
}

#document-version-panel-markdown .document-editor-container {
  flex: 1 1 0%;
  min-height: 0;
}

/* AllMD panel: allow scrolling for the expanded Maestro content */
#document-version-panel-allmd {
  overflow-y: auto;
  padding: 0;
}

/* ── Async loading skeleton ── */
.document-panel__skeleton {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1.5rem;
}

.document-panel__skeleton-line {
  height: 1rem;
  border-radius: 4px;
  background: linear-gradient(
    90deg,
    var(--tg-border, #dee2e6) 25%,
    var(--tg-bg-alt, #f1f3f5) 50%,
    var(--tg-border, #dee2e6) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
}

.document-panel__skeleton-line:nth-child(1) { width: 85%; }
.document-panel__skeleton-line:nth-child(2) { width: 70%; }
.document-panel__skeleton-line:nth-child(3) { width: 90%; }
.document-panel__skeleton-line:nth-child(4) { width: 60%; }
.document-panel__skeleton-line:nth-child(5) { width: 75%; }

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

/* ── Editor containers (moved from inline styles) ── */
.document-editor-container {
  border: 1px solid var(--tg-border, #dee2e6);
  border-radius: 4px;
  overflow: hidden;
}

/* ── Suggestions & Metadata panels padding ── */
#document-version-panel-suggestions,
#document-version-panel-metadata {
  padding: 1.5rem;
}

.document-version-text {
  font-size: 0.98rem;
  line-height: 1.5;
}

.document-version-pre {
  white-space: pre-wrap;
  font-family: "Courier New", Courier, monospace;
  font-size: 0.92rem;
  margin: 0;
}

.dashboard-card .display-4 {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.document-alignment .card-header {
  font-weight: 600;
}

/* Colors for button primary */

.btn.btn-primary {
  background-color: var(--color-primary) !important;
}

.btn.btn-outline-primary {
  color: var(--color-primary);
  background-color: transparent;
  background-image: none;
  border-color: var(--color-primary);
}

.btn.btn-outline-primary:hover {
  color: #fff !important;
  background-color: var(--color-primary) !important;
  border-color: var(--color-primary) !important;
}

.btn.btn-outline-primary:focus, .btn-outline-primary.focus {
  box-shadow: none !important;
}

.btn.btn-outline-primary:not(:disabled):not(.disabled).active:focus, .btn-outline-primary:not(:disabled):not(.disabled):active:focus, .show > .btn-outline-primary.dropdown-toggle:focus {
  box-shadow: none !important;
}

.btn.btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, .show > .btn-outline-secondary.dropdown-toggle:focus {
  box-shadow: none !important;
}

.btn.btn-outline-primary:not(:disabled):not(.disabled).active:focus, .btn-outline-primary:not(:disabled):not(.disabled):active:focus, .show > .btn-outline-primary.dropdown-toggle:focus {
  color: #fff !important;
  background-color: var(--color-primary) !important;
  border-color: var(--color-primary) !important;
}

.btn.btn-outline-primary.disabled, .btn-outline-primary:disabled {
  color: var(--color-primary) !important;
  background-color: transparent !important;
}

.btn.btn-outline-primary:not(:disabled):not(.disabled):active, .btn-outline-primary:not(:disabled):not(.disabled).active,
.show > .btn-outline-primary.dropdown-toggle {
  color: #fff !important;
  background-color: var(--color-primary) !important;
  border-color: var(--color-primary) !important;
}

.btn.btn-outline-primary:not(:disabled):not(.disabled):active:focus, .btn-outline-primary:not(:disabled):not(.disabled).active:focus,
.show > .btn-outline-primary.dropdown-toggle:focus {
  box-shadow: none !important;
}

.dropdown-item:focus, .dropdown-item:hover {
  color: #fff !important;
  background-color: var(--color-primary) !important;
  border-color: var(--color-primary) !important;
}

/* Colors for button info */
.btn.btn-info {
  background-color: #1d87a9 !important;
}

/* Colors for badges */
.badge-secondary {
  color: #fff !important;
}

.badge-info {
  color: #fff !important;
}

.badge-dark {
  color: #fff !important;
}

.badge-warning {
  color: #fff !important;
}

.badge-danger {
  color: #fff !important;
}

.badge-secondary {
  color: #fff !important;
  background-color: var(--color-primary) !important;
}

.badge-primary {
  color: #fff !important;
  background-color: var(--color-primary) !important;
}

.badge-primary[href]:hover, .badge-primary[href]:focus {
  color: #fff !important;
  text-decoration: none !important;
  background-color: var(--color-primary-dark) !important;
}

.badge-dark[href]:focus, .badge-dark[href]:hover {
  color: #abacaf !important;
  text-decoration: none !important;
}

/* Don't show the resize control on textareas */
textarea.form-control {
  resize: none;
}

/* Wrap long tag names and long doc names */
.tag-name {
  word-break: break-all;
}

.tag-color-swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: var(--tag-color);
  display: inline-block;
  margin-right: 0.5rem;
  flex: 0 0 auto;
}

a.document-link-a {
  word-break: break-all;
}

/* Work-around to make a whole element clickable while it contains links */
.overlay-outer {
  position: relative;
}

.overlay-bottom {
  position: absolute;
  left: 0; top: 0; bottom: 0; right: 0;
}

.overlay-top {
  position: relative;
  pointer-events: none;
  z-index: 1;
}

.overlay-top a {
  pointer-events: all;
}

li.document-link-current {
  background-color: var(--ui-active-bg) !important;
}

li.document-link-current a.document-link-a {
  font-weight: bold;
  color: var(--ui-accent-strong) !important;
}

.document-view {
  position: relative;
  text-align: initial; /* Reset alignment so RTL works */
}

li.tag-current {
  background-color: var(--ui-active-bg) !important;
}

.backlight {
  color: #bbb;
}

#export-button {
  position: absolute;
  top: .1em;
  right: .5em;
}

#export-button .dropdown-toggle {
  padding: 0.125rem 0.25rem;
}

a.dropdown-item:hover {
  color: white !important;
  text-decoration: none;
}

#document-view .highlight {
  background-color: #ff0;
  color: black;
  cursor: pointer;
  position: relative;
  display: inline-block;
  padding: 2px 0;
  border-top: 3px solid transparent;
  transition: box-shadow 0.15s ease-in-out, outline-color 0.15s ease-in-out, opacity 0.15s ease-in-out;
}

#document-view .highlight[data-color] {
  background-color: var(--hl-color);
  background-image: none;
}

#document-view .highlight-text {
  display: inline;
}

#document-view .highlight-color-strip {
  display: flex;
  height: 4px;
  width: 100%;
  margin-top: 2px;
  overflow: hidden;
  border-radius: 0 0 2px 2px;
  pointer-events: none;
}

#document-view .highlight-color-strip-segment {
  flex: 1 1 0;
}

/* Keep the bar stable when a highlight is split across text nodes */
#document-view .highlight[data-tag-colors] {
  position: relative;
  display: inline-block;
}
#document-view .highlight:hover {
  opacity: 0.8;
  outline: 1px solid rgba(0, 0, 0, 0.25);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18), 0 0 0 1px rgba(0, 0, 0, 0.12);
}

#document-view .highlight.dragging {
  opacity: 0.5;
  outline: 2px solid rgba(0, 0, 0, 0.5);
}

#document-view .highlight.selected {
  outline: 2px solid #0066cc;
  box-shadow: inset 0 0 3px rgba(0, 102, 204, 0.3);
}

#document-view .highlight[data-comment]::after {
  content: attr(data-comment);
  position: absolute;
  bottom: -20px;
  left: 0;
  background: #f8f9fa;
  border: 1px solid #dee2e6;
  border-radius: 3px;
  padding: 2px 4px;
  font-size: 0.8em;
  white-space: nowrap;
  display: none;
  z-index: 1000;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

#document-view .highlight[data-comment]:hover::after {
  display: block;
}

#document-view .highlight-edit-btn {
  position: relative;
  z-index: 20;
  width: 1.6em;
  height: 1.6em;
  padding: 0;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.2);
  background: #fff;
  color: #343a40;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
  opacity: 0;
  pointer-events: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 0.2em;
  transform: scale(0.9);
  transition: opacity 0.15s ease-in-out, transform 0.15s ease-in-out;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

#document-view .highlight:hover .highlight-edit-btn,
#document-view .highlight:focus-within .highlight-edit-btn,
#document-view .highlight-hover .highlight-edit-btn {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
}

#document-view .highlight-edit-btn:hover,
#document-view .highlight-edit-btn:focus {
  background: #f8f9fa;
  color: #212529;
}

/* Styles for segment-based rendering with nested highlights */
#document-view .hl-layer {
  display: inline;
  position: relative;
  /* Prevent layout shift with nested highlights */
  vertical-align: baseline;
  line-height: inherit;
}

/* Nested highlight support - show all highlight IDs in segment */
#document-view .highlight[data-highlights] {
  /* Properly mix colors for overlapping highlights */
  transition: opacity 0.15s ease-in-out;
}

/* Hover state for nested highlights */
#document-view .highlight-hover,
#document-view .highlight:hover {
  opacity: 0.85;
  outline: 1px solid rgba(0, 0, 0, 0.3);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.16), 0 0 0 1px rgba(0, 0, 0, 0.1);
  z-index: 10;
}

/* Parent highlight border overlay */
.parent-hl-border {
  box-sizing: border-box;
  background: transparent;
}

/* Selected state for multi-highlight segments */
#document-view .highlight[data-highlights*=","] {
  /* Slightly darker for visibility when multiple highlights overlap */
  filter: saturate(1.1);
}

#hlinfo {
  display: none;
  position: absolute;
  background-color: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(0, 0, 0, 0.18);
  border-radius: 0.5rem;
  box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.12);
  padding: 0.75rem;
  z-index: 1080;
  min-width: 14rem;
}

#hlinfo em {
  text-decoration: underline;
  font-style: normal;
}

#hlinfo .hlinfo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

#hlinfo-summary {
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  line-height: 1.25;
  color: #5b6472;
}

body.highlight-debug-mode #document-view .hl-layer[data-highlight-debug]::after {
  content: attr(data-highlight-debug);
  position: absolute;
  right: 0;
  top: -1.4rem;
  padding: 0.1rem 0.35rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--color-primary) 30%, transparent);
  background: rgba(255, 255, 255, 0.96);
  color: var(--color-primary);
  font-size: 0.68rem;
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

body.highlight-debug-mode #document-view .highlight[data-highlights] {
  outline: 1px dashed rgba(18, 83, 104, 0.35);
  outline-offset: 1px;
}

.list-group-item-primary a {
  color: #404041;
}

.list-group .sublist {
  padding-left: 0;
  margin-top: 5px;
  margin-right: -20px;
  margin-left: 5px;
  margin-bottom: -12px;
  border-top: 1px solid #dee2e6;
  display: flex;
  flex-direction: column;
}

.list-group .sublist li {
  padding: 12px 20px;
}

.dropdown-item.active {
  background-color: #e7f2ff !important;
}

.expand-marker {
  width: 7px;
}

.highlight-entry {
  border: 1px solid rgba(0,0,0,.125);
  margin: 1rem 0;
  padding: 1rem 0.6rem 1rem 0.6rem;
}

/* Spinner animation */
#spinner {
  border: 3vh solid #dcdcdc;
  border-top: 3vh solid var(--color-primary);
  border-radius: 50%;
  width: 30vh;
  height: 30vh;
  animation: spinneranim 2s linear infinite;
}

@keyframes spinneranim {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

#spinner-modal .modal-dialog {
  display: table;
  position: relative;
  margin: 0 auto;
  top: calc(50% - 15vh);
}

#spinner-modal .modal-dialog .modal-content{
  background-color: transparent;
  border: none;
  width: 30vh;
}

/* --------------------SCROLLBAR FOR MODALS--------------------------*/

.modal-body {
  max-height: calc(100vh - 210px);
  overflow-y: auto;
}

/* --------------------DRAG AND DROP STYLES--------------------------*/

/* Tags list items - enable drag and drop */
#tags-list li[draggable="true"] {
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
}

#tags-list li[draggable="true"]:active {
  cursor: grabbing;
}

/* Dragging state - visual feedback */
#tags-list li.tag-dragging {
  opacity: 0.5;
  background-color: #e7f2ff !important;
  border-left: 4px solid var(--color-primary);
}

/* Drop target state - visual feedback */
#tags-list li.tag-drop-target {
  background-color: #d4e6f1 !important;
  border-top: 2px solid var(--color-primary);
}

/* Drop to root area styling */
#tag-drop-root {
  background-color: #f8f9fa !important;
  border: 2px dashed #ccc !important;
  transition: all 0.2s ease-in-out;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#tag-drop-root.tag-drop-target {
  background-color: #d4e6f1 !important;
  border-color: var(--color-primary) !important;
  border-style: solid !important;
}

/* Parent tag selector in modal */
#tag-add-parent {
  font-size: 0.95em;
}

#tag-add-parent option {
  padding-left: 0.5rem;
}

/* --------------------RESPONSIVE DISPLAY HEADINGS--------------------------*/
@media (max-width: 575.98px) {
  .display-1 {
  font-size: 3rem;
  font-weight: 300;
  line-height: 1.0;
  }
  .display-2 {
    font-size: 2.75rem;
    font-weight: 300;
    line-height: 1.0;
  }
  .display-3 {
    font-size: 2.25rem;
    font-weight: 300;
    line-height: 1.0;
  }
  .display-4 {
    font-size: 1.75rem;
    font-weight: 300;
    line-height: 1.0;
  }
}

/* Document Source Banner styles using CSS content to avoid plain text offset shifts */
.document-source-banner {
  margin-bottom: 20px;
  padding: 12px;
  border-radius: 6px;
  border-left: 5px solid #17a2b8;
  font-size: 0.95em;
  font-family: sans-serif;
  background-color: #f7f9fa;
  color: #333;
  font-weight: bold;
}
.document-source-banner[data-source="pdf"]::before {
  content: "ℹ️ Source d'importation : Contenu obtenu via extraction directe depuis le pdf";
}
.document-source-banner[data-source="md"]::before {
  content: "ℹ️ Source d'importation : Contenu obtenu via la version ALL/ALLMD";
}
.document-source-banner[data-source="md"] {
  border-left-color: #28a745;
  background-color: #f4faf6;
}
.document-source-banner[data-source="txt"]::before {
  content: "ℹ️ Source d'importation : Contenu obtenu via la version ALL/ALLNBLM/Source";
}
.document-source-banner[data-source="txt"] {
  border-left-color: #ffc107;
  background-color: #fffbeb;
}

/* Marker image block styling in native HTML */
.marker-image-placeholder {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  transition: border-color 0.15s ease-in-out;
}
.marker-image-placeholder:hover {
  border-color: #6366f1 !important;
}

/* Pulsing styling for active scrolled highlight */
.highlight-active {
  outline: 3px solid #ff4081 !important;
  outline-offset: 2px;
  border-radius: 2px;
  animation: pulse-active-highlight 2s ease-in-out;
}

@keyframes pulse-active-highlight {
  0% { outline-color: rgba(255, 64, 129, 1); box-shadow: 0 0 12px rgba(255, 64, 129, 0.9); }
  50% { outline-color: rgba(255, 64, 129, 0.4); box-shadow: 0 0 6px rgba(255, 64, 129, 0.4); }
  100% { outline-color: rgba(255, 64, 129, 0); box-shadow: 0 0 0 rgba(255, 64, 129, 0); }
}

/* Custom Alert/Toast Status Modifiers */
.custom-toast--success {
  border-left: 4px solid #2ecc71 !important;
}
.custom-toast--error {
  border-left: 4px solid #e74c3c !important;
}
.custom-toast--warning {
  border-left: 4px solid #f1c40f !important;
}
.custom-toast--info {
  border-left: 4px solid #3498db !important;
}

/* Skeleton Shimmer Animation */
.skeleton-loader {
  background: #f6f7f8;
  background-image: linear-gradient(
    90deg,
    #f6f7f8 0%,
    #edeef1 20%,
    #f6f7f8 40%,
    #f6f7f8 100%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s infinite linear;
  display: inline-block;
  height: 1rem;
  width: 100%;
  border-radius: var(--radius-sm, 2px);
}

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


/* =====================================================
   2. Tagma UI Core tokens & components
   ===================================================== */

[x-cloak] {
  display: none !important;
}

:root {
  /* Common variables (Transitions, Border radius, Spacing) */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

  --transition-fast: 100ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-serif: BadScript, Georgia, Cambria, "Times New Roman", Times, serif;
  --font-mono: 'JetBrains Mono', SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.25rem;
  --font-size-2xl: 1.5rem;
  --font-size-3xl: 1.875rem;
  --font-size-4xl: 2.25rem;

  --font-weight-light: 300;
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;

  --line-height-tight: 1.2;
  --line-height-snug: 1.35;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.625;

  /* LIGHT THEME VARIABLES */
  --ui-bg: #f8fafc;
  --ui-surface: #ffffff;
  --ui-surface-hover: #f1f5f9;
  --ui-sidebar-bg: #ffffff;
  --ui-border: #e2e8f0;
  --ui-border-hover: #cbd5e1;
  --ui-text: #0f172a;
  --ui-muted: #64748b;
  --ui-accent: #125368;
  --ui-accent-strong: #0d3b4a;
  --ui-tag-border: #cbd5e1;
  --ui-loading: #125368;
  
  --ui-hl-default: oklch(0.92 0.14 90);
  --ui-hl-alt: oklch(0.88 0.12 55);
  --ui-hl-overlap: color-mix(in oklch, var(--ui-hl-default) 62%, var(--ui-hl-alt) 38%);

  --color-primary: #125368;
  --color-primary-light: #1d87a9;
  --color-primary-dark: #0d3b4a;
  --color-secondary: #3498DB;

  /* Component specific light overrides */
  --ui-nav-bg: #125368;
  --ui-header-bg: #f8fafc;
  --ui-table-striped: #f8fafc;
  --ui-table-hover: #f1f5f9;
  --ui-input-bg: #ffffff;
  --ui-input-focus-bg: #ffffff;
  --ui-input-focus-text: #0f172a;
  --ui-active-bg: color-mix(in oklch, var(--ui-accent) 8%, #ffffff);
  --ui-link-color: var(--color-primary);

  /* Legacy tagmaqda mappings */
  --bg-color: var(--ui-bg);
  --surface-color: var(--ui-surface);
  --primary-color: var(--color-primary);
  --text-color: var(--ui-text);
  --text-muted: var(--ui-muted);
}

[data-theme="dark"] {
  /* DARK THEME VARIABLES */
  --ui-bg: #0f1117;
  --ui-surface: #1a1d27;
  --ui-surface-hover: #252836;
  --ui-sidebar-bg: #0c0d12;
  --ui-border: #2e303f;
  --ui-border-hover: #3e4156;
  --ui-text: #f1f5f9;
  --ui-muted: #94a3b8;
  --ui-accent: #4f98a3;
  --ui-accent-strong: #5db0bd;
  --ui-tag-border: #3e4156;
  --ui-loading: #4f98a3;
  
  --ui-hl-default: oklch(0.45 0.14 90);
  --ui-hl-alt: oklch(0.40 0.12 55);
  --ui-hl-overlap: color-mix(in oklch, var(--ui-hl-default) 62%, var(--ui-hl-alt) 38%);

  --color-primary: #4f98a3;
  --color-primary-light: #5db0bd;
  --color-primary-dark: #2c6872;
  --color-secondary: #5db0bd;

  /* Component specific dark overrides */
  --ui-nav-bg: #1a1d27;
  --ui-header-bg: #252836;
  --ui-table-striped: #202330;
  --ui-table-hover: #292d3e;
  --ui-input-bg: #202330;
  --ui-input-focus-bg: #252836;
  --ui-input-focus-text: #ffffff;
  --ui-active-bg: color-mix(in oklch, var(--ui-accent) 20%, #1a1d27);
  --ui-link-color: var(--color-primary);

  /* Legacy tagmaqda mappings */
  --bg-color: var(--ui-bg);
  --surface-color: var(--ui-surface);
  --primary-color: var(--color-primary);
  --text-color: var(--ui-text);
  --text-muted: var(--ui-muted);
}

body {
  background: var(--ui-bg);
  color: var(--ui-text);
}

.container-body {
  position: relative;
}

.app-shell__nav {
  box-shadow: 0 0.75rem 1.75rem rgba(18, 83, 104, 0.12);
}

.app-shell__brand {
  letter-spacing: 0.08em;
}

.app-shell__body {
  padding-top: 1rem;
}

.app-shell__footer {
  color: var(--ui-muted);
}

.project-sidebar,
.document-panel,
.tag-tree__item,
.modal-content {
  border-color: var(--ui-border);
}

.tag-tree {
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: 0.75rem;
  overflow: hidden;
}

.tag-tree__item {
  background: transparent;
  transition: background-color 120ms ease, border-color 120ms ease;
}

.tag-tree__row {
  min-width: 0;
  gap: 0.75rem;
}

.tag-tree__children {
  margin-top: 0.25rem;
}

.tag-tree__item:hover {
  background: color-mix(in oklch, var(--ui-accent) 7%, white);
}

.tag-tree__toggle {
  min-width: 2rem;
  color: var(--ui-accent-strong);
  text-decoration: none;
}

.tag-tree__toggle-spacer {
  display: inline-block;
  width: 2rem;
}

/* Tag tree indentation based on depth */
.tag-tree__item {
  --tag-depth: 0;
  padding-left: calc(var(--tag-depth, 0) * 1.5rem);
}

.tag-tree__item[style*="--tag-depth"] {
  padding-left: calc(var(--tag-depth) * 1.5rem);
}

/* Drag and drop visual feedback */
.tag-tree__item.tag-dragging {
  opacity: 0.6;
  background: color-mix(in oklch, var(--ui-accent) 15%, white);
  border: 2px dashed var(--ui-accent);
}

.tag-tree__item.tag-drop-target {
  background: color-mix(in oklch, var(--ui-accent) 25%, white);
  border: 2px solid var(--ui-accent-strong);
  box-shadow: inset 0 2px 0 0 var(--ui-accent-strong);
}

.tag-tree__link {
  color: var(--ui-text);
  text-decoration: none;
}

.tag-tree__link:hover,
.tag-tree__link:focus {
  color: var(--ui-accent-strong);
  text-decoration: underline;
}

.tag-current {
  background: color-mix(in oklch, var(--ui-accent) 10%, white);
}

.tag-color-swatch {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px color-mix(in oklch, var(--ui-text) 18%, white);
}

.document-panel {
  min-height: 60vh;
}

.document-panel__toolbar {
  gap: 1rem;
}

.document-panel__content {
  min-height: 40vh;
}

.document-empty-state {
  font-style: oblique;
  text-align: center;
  color: var(--ui-muted);
}

.document-version-tabs__tab[aria-selected="true"] {
  background: var(--ui-accent-strong) !important;
  border-color: var(--ui-accent-strong) !important;
  color: white !important;
}

.document-panel[data-state="loading"] {
  opacity: 0.88;
}

body[data-state="loading"]::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: transparent;
  animation: none;
}

@keyframes ui-loading-sweep {
  from {
    transform: translateX(-35%);
  }
  to {
    transform: translateX(35%);
  }
}

.highlight,
.highlight-entry a.badge,
.badge.badge-dark,
.badge.badge-light {
  border-radius: 999px;
}

.highlight {
  background: var(--ui-hl-default);
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  position: relative;
  transition: box-shadow 120ms ease, transform 120ms ease, background-color 120ms ease;
}

.highlight--interactive:hover,
.highlight--interactive.highlight-hover {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--hl-border, var(--ui-accent)) 72%, black 28%);
  border-radius: 0.35em;
  z-index: 2;
}

/* Parent highlight visual distinction: subtle outline to show containment */
.highlight--parent {
  /* No additional border - parent status shown through continuous background/border on hover */
  /* The fact that child highlights are visually inside shows the parent-child relationship */
}

.highlight--parent:hover,
.highlight--parent.highlight-hover {
  /* Slightly stronger shadow for parent highlights to emphasize containment */
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--hl-border, var(--ui-accent)) 85%, black 15%);
}

/* Global hover state for multi-segment highlights - creates continuous border around entire highlight */
.highlight-hover-global {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--hl-border, var(--ui-accent)) 72%, black 28%) !important;
  border-radius: 0.35em;
  z-index: 2;
}

/* Edit button visible state - shown when clicking on edit button or when global hover is active on last segment */
.highlight-edit-btn-visible {
  opacity: 1 !important;
  pointer-events: auto !important;
  transform: translateY(0) scale(1) !important;
}

.highlight[data-tag-colors] {
  background: var(--ui-hl-overlap);
}

.highlight .highlight-edit-btn {
  position: absolute;
  top: -0.95em;
  right: -0.65em;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-2px) scale(0.94);
  transition: opacity 120ms ease, transform 120ms ease, background-color 120ms ease;
  z-index: 3;
  white-space: nowrap;
  box-shadow: 0 0.2rem 0.45rem rgba(0, 0, 0, 0.16);
}

.highlight:hover .highlight-edit-btn,
.highlight.highlight-hover .highlight-edit-btn,
.highlight .highlight-edit-btn:focus-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.highlight .highlight-edit-btn:hover {
  background: var(--ui-surface);
}

.highlight-entry {
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--ui-border);
  border-radius: 0.75rem;
  background: var(--ui-surface);
}

.modal[data-bs-loaded="true"] {
  outline: 0;
}

.modal[data-bs-loaded="true"] .modal-content {
  transform: translateY(0);
}

[data-testid="app-nav"] .nav-link,
[data-testid="app-footer"] a {
  text-decoration-thickness: 0.08em;
}

/* --- Normalized Card & Component System (Wave P0.4) --- */
.tagma-card {
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-normal), box-shadow var(--transition-normal), border-color var(--transition-normal);
  overflow: hidden;
  margin-bottom: var(--space-4);
}

.tagma-card:hover {
  box-shadow: var(--shadow-md);
  border-color: color-mix(in oklch, var(--ui-border) 70%, var(--ui-accent));
}

.tagma-card__header {
  padding: var(--space-3) var(--space-4);
  background: color-mix(in oklch, var(--ui-surface) 95%, var(--ui-accent));
  border-bottom: 1px solid var(--ui-border);
  font-weight: var(--font-weight-semibold);
  color: var(--ui-accent-strong);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.tagma-card__body {
  padding: var(--space-4);
}

.tagma-card__footer {
  padding: var(--space-3) var(--space-4);
  background: var(--ui-surface);
  border-top: 1px solid var(--ui-border);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
}

/* Premium Button & Input Polish */
.btn {
  border-radius: var(--radius-md) !important;
  font-weight: var(--font-weight-medium) !important;
  transition: all var(--transition-normal) !important;
}

.btn-primary {
  background-color: var(--color-primary) !important;
  border-color: var(--color-primary) !important;
}

.btn-primary:hover, .btn-primary:focus {
  background-color: var(--color-primary-dark) !important;
  border-color: var(--color-primary-dark) !important;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 30%, transparent) !important;
}

.btn-outline-primary {
  color: var(--color-primary) !important;
  border-color: var(--color-primary) !important;
}

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

.form-control, .form-select {
  border-radius: var(--radius-md) !important;
  border: 1px solid var(--ui-border) !important;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast) !important;
  padding: 0.5rem 0.75rem !important;
}

.form-control:focus, .form-select:focus {
  border-color: var(--ui-accent) !important;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ui-accent) 25%, transparent) !important;
  outline: 0 !important;
}

/* Navigation breadcrumbs */
.tagma-breadcrumb {
  display: flex;
  flex-wrap: wrap;
  padding: 0;
  margin-bottom: var(--space-4);
  list-style: none;
  font-size: var(--font-size-sm);
  color: var(--ui-muted);
  gap: var(--space-2);
  align-items: center;
}

.tagma-breadcrumb-item + .tagma-breadcrumb-item::before {
  content: "/";
  padding-right: var(--space-2);
  color: var(--ui-border);
}

.tagma-breadcrumb-item a {
  color: var(--ui-accent-strong);
  text-decoration: none;
  font-weight: var(--font-weight-medium);
}

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

.tagma-breadcrumb-item.active {
  color: var(--ui-muted);
}

/* Custom Alert/Toast System Styles */
.custom-toast {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10000;
  min-width: 300px;
  max-width: 450px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--ui-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-2);
  transform: translateX(120%);
  transition: transform var(--transition-slow) cubic-bezier(0.68, -0.55, 0.265, 1.55), opacity var(--transition-slow) ease;
  opacity: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.custom-toast.show {
  transform: translateX(0);
  opacity: 1;
}

.custom-toast-content {
  flex-grow: 1;
  font-size: var(--font-size-sm);
  color: var(--ui-text);
  padding-right: var(--space-3);
  line-height: var(--line-height-normal);
}

.custom-toast-close {
  background: none;
  border: none;
  color: var(--ui-muted);
  font-size: var(--font-size-2xl);
  cursor: pointer;
  line-height: 1;
  padding: 0;
}

.custom-toast-close:hover {
  color: var(--ui-text);
}

/* Sidebar collapsibility (Wave P1.1) */
.project-workspace-row {
  display: flex !important;
  flex-wrap: nowrap !important;
  overflow-x: hidden !important;
  width: 100%;
  min-height: 60vh;
  transition: all var(--transition-normal);
}

.project-workspace-row .sidebar-col {
  transition: flex 0.2s ease, width 0.2s ease, max-width 0.2s ease, padding 0.2s ease, opacity 0.2s ease !important;
  width: 25%;
  flex: 0 0 25%;
  max-width: 25%;
  /* overflow-y:auto set in the final block (section 8) — do NOT set overflow:hidden here */
}

.project-workspace-row .content-col {
  transition: flex 0.2s ease, width 0.2s ease, max-width 0.2s ease !important;
  width: 75%;
  flex: 0 0 75%;
  max-width: 75%;
}

.project-workspace-row.sidebar-collapsed .sidebar-col {
  width: 0 !important;
  flex: 0 0 0 !important;
  max-width: 0 !important;
  overflow: hidden;
  padding-left: 0 !important;
  padding-right: 0 !important;
  border: none !important;
  opacity: 0;
  pointer-events: none;
}

.project-workspace-row.sidebar-collapsed .content-col {
  flex: 1 1 auto !important;
  width: auto !important;
  max-width: 100% !important;
}

#project-dashboard-container {
  width: 100%;
  max-width: 100%;
}

/* --- Document Reader Ergonomics & Focus (Wave P1.2) --- */
.document-panel {
  background: var(--ui-bg);
  border: 1px solid var(--ui-border) !important;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-6) !important;
  transition: all var(--transition-normal);
}

#document-contents,
.document-version-text {
  max-width: 72ch;
  margin-left: auto;
  margin-right: auto;
  padding: var(--space-4) 0;
  font-size: 1.05rem;
  line-height: var(--line-height-relaxed);
  color: var(--ui-text);
}

/* Document Empty State Upgrade */
.document-empty-state {
  display: flex !important;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-12) var(--space-6);
  text-align: center;
  color: var(--ui-muted);
  font-style: italic;
}

.document-empty-state::before {
  content: "\f15b"; /* FontAwesome file-alt icon */
  font-family: "Font Awesome 5 Free";
  font-weight: 900;
  font-size: 3rem;
  margin-bottom: var(--space-4);
  color: var(--ui-border);
  display: block;
}

/* --- Normalized Modal System (Wave P1.3) --- */
.modal-content {
  border: none !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow-xl) !important;
  background-color: var(--ui-bg) !important;
  overflow: hidden;
}

.modal-header {
  border-bottom: 1px solid var(--ui-border) !important;
  padding: var(--space-4) var(--space-5) !important;
  background: color-mix(in oklch, var(--ui-surface) 95%, var(--ui-accent));
}

.modal-title {
  font-weight: var(--font-weight-semibold) !important;
  color: var(--ui-accent-strong) !important;
  font-size: var(--font-size-lg) !important;
}

.modal-body {
  padding: var(--space-5) !important;
  color: var(--ui-text) !important;
  line-height: var(--line-height-normal) !important;
}

.modal-footer {
  border-top: 1px solid var(--ui-border) !important;
  padding: var(--space-4) var(--space-5) !important;
  background: var(--ui-surface) !important;
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3) !important;
}

/* Specific class for borderless confirm dialogs */
.modal-confirm .modal-content {
  border-radius: var(--radius-xl) !important;
}

.modal-confirm .modal-header {
  border-bottom: none !important;
  background: transparent !important;
  padding: var(--space-5) var(--space-5) var(--space-2) !important;
}

.modal-confirm .modal-body {
  padding: var(--space-2) var(--space-5) var(--space-4) !important;
}

.modal-confirm .modal-footer {
  border-top: none !important;
  background: transparent !important;
  padding: var(--space-2) var(--space-5) var(--space-5) !important;
}

/* Accessibility Focus Indicators (Wave P2.3) */
a:focus-visible,
button:focus-visible,
.btn:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible {
  outline: 3px solid var(--ui-accent) !important;
  outline-offset: 2px !important;
  box-shadow: none !important;
}

/* === Agent/Maestro Components === */
:root {
  --m-bg-primary: var(--ui-bg, #f8fafc);
  --m-bg-secondary: var(--ui-surface, #ffffff);
  --m-bg-surface: var(--ui-surface-hover, #f1f5f9);
  --m-bg-surface-hover: var(--ui-border, #e2e8f0);
  --m-accent-green: var(--ui-success, #10b981);
  --m-accent-red: var(--ui-error, #ef4444);
  --m-accent-orange: var(--ui-warning, #f59e0b);
  --m-accent-blue: var(--ui-accent, #125368);
  --m-accent-purple: #8b5cf6;
  --m-text-primary: var(--ui-text, #0f172a);
  --m-text-secondary: var(--ui-muted, #64748b);
  --m-text-dim: var(--ui-muted, #64748b);
  --m-border: var(--ui-border, #e2e8f0);
  --m-glow-green: 0 0 10px rgba(16,185,129,0.2);
  --m-glow-blue: 0 0 10px rgba(18,83,104,0.2);
  --m-glow-red: 0 0 10px rgba(239,68,68,0.2);
  --m-glow-orange: 0 0 10px rgba(245,158,11,0.2);
  --m-glow-purple: 0 0 10px rgba(139,92,246,0.2);
  --m-font-mono: var(--font-mono, monospace);
  --m-radius: var(--radius-lg, 10px);
  --m-radius-sm: var(--radius-md, 6px);
  --m-transition: var(--transition-normal, 0.2s ease);
  --m-sidebar-w: 300px;
  --m-console-border-color: var(--m-border);
}

[data-theme="dark"] {
  --m-bg-primary: var(--ui-bg, #0f1117);
  --m-bg-secondary: var(--ui-surface, #1a1d27);
  --m-bg-surface: var(--ui-surface-hover, #252836);
  --m-bg-surface-hover: var(--ui-border, #2e303f);
  --m-accent-green: var(--ui-success, #00e676);
  --m-accent-red: var(--ui-error, #ff5252);
  --m-accent-orange: var(--ui-warning, #ffab40);
  --m-accent-blue: var(--ui-accent, #4f98a3);
  --m-accent-purple: #b388ff;
  --m-text-primary: var(--ui-text, #f1f5f9);
  --m-text-secondary: var(--ui-muted, #94a3b8);
  --m-text-dim: var(--ui-muted, #94a3b8);
  --m-border: var(--ui-border, #2e303f);
  --m-glow-green: 0 0 14px rgba(0,230,118,0.3);
  --m-glow-blue: 0 0 14px rgba(68,138,255,0.3);
  --m-glow-red: 0 0 14px rgba(255,82,82,0.3);
  --m-glow-orange: 0 0 14px rgba(255,171,64,0.3);
  --m-glow-purple: 0 0 14px rgba(179,136,255,0.3);
}

html[data-theme="dark"] #document-version-panel-allmd {
  --m-bg-primary: var(--ui-bg, #0f1117);
  --m-bg-secondary: var(--ui-surface, #1a1d27);
  --m-bg-surface: var(--ui-surface-hover, #252836);
  --m-bg-surface-hover: var(--ui-border, #2e303f);
  --m-accent-green: var(--ui-success, #00e676);
  --m-accent-red: var(--ui-error, #ff5252);
  --m-accent-orange: var(--ui-warning, #ffab40);
  --m-accent-blue: var(--ui-accent, #4f98a3);
  --m-accent-purple: #b388ff;
  --m-text-primary: var(--ui-text, #f1f5f9);
  --m-text-secondary: var(--ui-muted, #94a3b8);
  --m-text-dim: var(--ui-muted, #94a3b8);
  --m-border: var(--ui-border, #2e303f);
  --m-glow-green: 0 0 14px rgba(0,230,118,0.3);
  --m-glow-blue: 0 0 14px rgba(68,138,255,0.3);
  --m-glow-red: 0 0 14px rgba(255,82,82,0.3);
  --m-glow-orange: 0 0 14px rgba(255,171,64,0.3);
  --m-glow-purple: 0 0 14px rgba(179,136,255,0.3);
}

#allmd-maestro-app {
  --m-sidebar-w: 280px;
}

/* ═══ LAYOUT ═══ */
#maestro-app, #allmd-maestro-app {
  display: grid;
  grid-template-columns: var(--m-sidebar-w) 1fr;
  min-height: calc(100vh - 170px);
  background: var(--m-bg-primary);
  border-radius: var(--m-radius);
  overflow: hidden;
  box-shadow: 0 4px 40px rgba(0,0,0,0.6);
  margin: -15px -15px 0 -15px;
}

#allmd-maestro-app {
  height: auto !important;
  min-height: 60vh;
  margin: 0;
  box-shadow: none;
  border-radius: 0;
  overflow: visible;
}

/* ═══ SIDEBAR ═══ */
#sidebar-overlay, #allmd-sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.65); z-index: 999;
  backdrop-filter: blur(3px);
}
#maestro-sidebar, #allmd-maestro-sidebar {
  background: var(--m-bg-secondary);
  border-right: 1px solid var(--m-border);
  display: flex; flex-direction: column;
  overflow: hidden; transition: transform 0.3s ease;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--m-border);
}
.sidebar-header h3 {
  margin: 0; font-family: var(--m-font-mono); font-size: 13px;
  font-weight: 600; color: var(--m-text-primary); letter-spacing: 0.5px;
}
.btn-icon {
  background: none; border: none; color: var(--m-text-secondary);
  cursor: pointer; padding: 4px 8px; border-radius: var(--m-radius-sm);
  transition: all var(--m-transition); font-size: 13px;
}
.btn-icon:hover { color: var(--m-accent-blue); background: var(--m-bg-surface); }

/* Sidebar tabs */
.sidebar-tabs {
  display: flex; border-bottom: 1px solid var(--m-border);
}
.sidebar-tab {
  flex: 1; padding: 10px 8px; text-align: center;
  font-family: var(--m-font-mono); font-size: 11px;
  color: var(--m-text-dim); cursor: pointer; border: none;
  background: none; transition: all var(--m-transition);
  text-transform: uppercase; letter-spacing: 0.5px;
  border-bottom: 2px solid transparent;
}
.sidebar-tab:hover { color: var(--m-text-secondary); }
.sidebar-tab.active {
  color: var(--m-accent-blue); border-bottom-color: var(--m-accent-blue);
  background: rgba(68,138,255,0.05);
}

/* Task list & deliverables */
.sidebar-panel { flex: 1; overflow-y: auto; padding: 6px; display: none; }
.sidebar-panel.active { display: block; }
.sidebar-panel::-webkit-scrollbar { width: 4px; }
.sidebar-panel::-webkit-scrollbar-thumb { background: var(--m-border); border-radius: 2px; }

.task-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--m-radius-sm);
  cursor: pointer; transition: all var(--m-transition);
  margin-bottom: 2px; border: 1px solid transparent;
}
.task-item:hover { background: var(--m-bg-surface); border-color: var(--m-border); }
.task-item.active {
  background: var(--m-bg-surface); border-color: var(--m-accent-blue);
  box-shadow: var(--m-glow-blue);
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  background: var(--m-text-dim);
}
.status-dot.completed { background: var(--m-accent-green); box-shadow: var(--m-glow-green); }
.status-dot.in_progress, .status-dot.streaming {
  background: var(--m-accent-blue); box-shadow: var(--m-glow-blue);
  animation: pulse-dot-m 1.5s ease-in-out infinite;
}
.status-dot.error, .status-dot.cancelled { background: var(--m-accent-red); }
.status-dot.awaiting {
  background: var(--m-accent-orange); box-shadow: var(--m-glow-orange);
  animation: pulse-dot-m 2s ease-in-out infinite;
}
.task-info { flex: 1; min-width: 0; }
.task-id {
  font-family: var(--m-font-mono); font-size: 11px;
  color: var(--m-text-primary); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.task-desc {
  font-size: 10px; color: var(--m-text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 2px;
}
.task-mode-tag {
  font-size: 9px; padding: 2px 6px; border-radius: 8px;
  background: var(--m-bg-surface); color: var(--m-accent-purple);
  border: 1px solid rgba(179,136,255,0.25); flex-shrink: 0;
}
.task-actions-row {
  display: flex; gap: 4px; margin-top: 4px;
}
.task-action-btn {
  font-size: 10px; padding: 2px 8px; border-radius: 4px; border: none;
  cursor: pointer; font-family: var(--m-font-mono);
  transition: all var(--m-transition);
}
.task-action-btn.resume-btn { background: var(--m-accent-orange); color: #fff; }
.task-action-btn.resume-btn:hover { filter: brightness(1.2); }
.task-action-btn.cancel-btn { background: var(--m-bg-surface); color: var(--m-accent-red); border: 1px solid var(--m-accent-red); }
.task-action-btn.cancel-btn:hover { background: rgba(255,82,82,0.1); }

/* Deliverable items */
.deliv-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: var(--m-radius-sm);
  border: 1px solid transparent; transition: all var(--m-transition);
  margin-bottom: 2px;
}
.deliv-item:hover { background: var(--m-bg-surface); border-color: var(--m-border); }
.deliv-icon { font-size: 14px; color: var(--m-accent-green); flex-shrink: 0; }
.deliv-info { flex: 1; min-width: 0; }
.deliv-name {
  font-family: var(--m-font-mono); font-size: 11px;
  color: var(--m-text-primary); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.deliv-meta {
  font-size: 10px; color: var(--m-text-dim); margin-top: 1px;
}

.sidebar-footer { padding: 10px; border-top: 1px solid var(--m-border); }
#btn-new-task, #allmd-btn-new-task {
  width: 100%; padding: 10px; border: none; border-radius: var(--m-radius-sm);
  font-family: var(--m-font-mono); font-size: 12px; font-weight: 600;
  cursor: pointer; transition: all var(--m-transition);
  background: linear-gradient(135deg, var(--m-accent-blue), #2962ff);
  color: #fff; letter-spacing: 0.3px;
}
#btn-new-task:hover, #allmd-btn-new-task:hover { transform: translateY(-1px); box-shadow: var(--m-glow-blue); filter: brightness(1.1); }
#btn-new-task:active, #allmd-btn-new-task:active { transform: translateY(0); }

/* ═══ HAMBURGER ═══ */
#hamburger-btn, #allmd-hamburger-btn {
  display: none; position: fixed; top: 70px; left: 12px; z-index: 1001;
  background: var(--m-bg-surface); border: 1px solid var(--m-border);
  color: var(--m-text-primary); width: 40px; height: 40px;
  border-radius: var(--m-radius-sm); font-size: 18px; cursor: pointer;
  transition: all var(--m-transition); box-shadow: 0 2px 10px rgba(0,0,0,0.4);
  align-items: center; justify-content: center;
}
#hamburger-btn:hover, #allmd-hamburger-btn:hover { background: var(--m-accent-blue); color: #fff; }

/* ═══ MAIN PANEL ═══ */
#maestro-main, #allmd-maestro-main {
  display: flex; flex-direction: column; background: var(--m-bg-primary); min-width: 0;
}
.main-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px; border-bottom: 1px solid var(--m-border);
  background: var(--m-bg-secondary); gap: 10px; flex-wrap: wrap;
}
.topbar-info { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.topbar-task-id {
  font-family: var(--m-font-mono); font-size: 12px; color: var(--m-text-primary);
  background: var(--m-bg-surface); padding: 4px 10px; border-radius: var(--m-radius-sm);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px;
}
.topbar-badge {
  font-size: 10px; padding: 3px 8px; border-radius: 10px;
  text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600;
}
.topbar-badge.mode { background: var(--m-bg-surface); color: var(--m-accent-purple); border: 1px solid rgba(179,136,255,0.3); }
.topbar-badge.status-completed { background: rgba(0,230,118,0.12); color: var(--m-accent-green); border: 1px solid rgba(0,230,118,0.3); }
.topbar-badge.status-in_progress { background: rgba(68,138,255,0.12); color: var(--m-accent-blue); border: 1px solid rgba(68,138,255,0.3); }
.topbar-badge.status-error, .topbar-badge.status-cancelled { background: rgba(255,82,82,0.12); color: var(--m-accent-red); border: 1px solid rgba(255,82,82,0.3); }
.topbar-badge.status-awaiting { background: rgba(255,171,64,0.12); color: var(--m-accent-orange); border: 1px solid rgba(255,171,64,0.3); }
.connection-indicator {
  display: flex; align-items: center; gap: 6px;
  font-size: 10px; color: var(--m-text-secondary); font-family: var(--m-font-mono);
}
.connection-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--m-text-dim); transition: all 0.3s;
}
.connection-dot.connected {
  background: var(--m-accent-green); box-shadow: var(--m-glow-green);
  animation: pulse-dot-m 1.5s ease-in-out infinite;
}

/* ═══ CONSOLE ═══ */
#maestro-console-wrap, #allmd-maestro-console-wrap { flex: 1; display: flex; flex-direction: column; position: relative; overflow: hidden; }
#session-history-manager {
  flex-direction: column;
  box-sizing: border-box;
}
#session-history-manager h2 { font-family: var(--m-font-mono); font-size: 20px; }
#session-history-manager article button {
  border: 1px solid var(--m-border); background: var(--m-bg-secondary);
  color: var(--m-text-secondary); border-radius: var(--m-radius-sm);
  padding: 6px 9px; cursor: pointer; font-size: 11px;
}
#session-history-manager article button:hover {
  color: var(--m-text-primary); border-color: var(--m-accent-blue);
}
#session-history-manager .history-delete:hover { border-color: var(--m-accent-red); color: var(--m-accent-red); }
#maestro-console, #allmd-maestro-console {
  flex: 1; overflow-y: auto; padding: 16px 20px;
  font-family: var(--m-font-mono); font-size: 13px; line-height: 1.65;
  border-top: 3px solid var(--m-console-border-color); transition: border-color 0.5s ease;
  scrollbar-width: thin; scrollbar-color: var(--m-border) transparent;
}
#maestro-console::-webkit-scrollbar, #allmd-maestro-console::-webkit-scrollbar { width: 5px; }
#maestro-console::-webkit-scrollbar-thumb, #allmd-maestro-console::-webkit-scrollbar-thumb { background: var(--m-border); border-radius: 3px; }

.console-empty {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; height: 100%; color: var(--m-text-dim);
  text-align: center; gap: 16px; padding: 40px 20px;
}
.console-empty i { font-size: 52px; opacity: 0.25; }
.console-empty p { font-size: 13px; line-height: 1.5; max-width: 360px; }
.console-empty .quick-modes {
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 8px;
}
.console-empty .quick-mode-btn {
  padding: 6px 14px; border-radius: 16px; font-size: 12px;
  border: 1px solid var(--m-border); background: var(--m-bg-surface);
  color: var(--m-text-secondary); cursor: pointer; font-family: var(--m-font-mono);
  transition: all var(--m-transition);
}
.console-empty .quick-mode-btn:hover {
  border-color: var(--m-accent-blue); color: var(--m-accent-blue);
  background: rgba(68,138,255,0.08);
}

/* Message bubbles */
.msg-bubble {
  max-width: 82%; padding: 12px 16px; border-radius: var(--m-radius);
  margin-bottom: 10px; position: relative; word-break: break-word;
  animation: fadeSlideIn-m 0.2s ease;
}
.msg-bubble .msg-time {
  font-size: 9px; color: var(--m-text-dim); margin-top: 5px; text-align: right;
}
.msg-bubble.msg-roocode {
  background: var(--m-bg-surface); border-left: 3px solid var(--m-accent-green);
  margin-right: auto; color: var(--m-text-primary);
}
.msg-bubble.msg-roocode.completion-result {
  border-left-color: var(--m-accent-purple);
  background: linear-gradient(135deg, var(--m-bg-surface), rgba(179,136,255,0.05));
}
.msg-bubble.msg-user {
  background: #1a2744; border-left: 3px solid var(--m-accent-blue);
  margin-left: auto; color: var(--m-text-primary);
}
.msg-bubble.msg-system {
  background: transparent; border: 1px dashed var(--m-border);
  margin: 6px auto; text-align: center; color: var(--m-text-secondary);
  font-style: italic; font-size: 11px; max-width: 55%;
}
.msg-bubble pre {
  background: var(--m-bg-secondary); padding: 10px; border-radius: var(--m-radius-sm);
  overflow-x: auto; margin: 6px 0 4px; font-size: 12px; border: 1px solid var(--m-border);
}
.msg-bubble code { font-family: var(--m-font-mono); font-size: 12px; }

/* Suggestions row */
.suggestions-row {
  display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px;
}
.suggestion-btn {
  padding: 6px 14px; border-radius: 16px; font-size: 11px;
  border: 1px solid var(--m-accent-blue); background: rgba(68,138,255,0.08);
  color: var(--m-accent-blue); cursor: pointer; font-family: var(--m-font-mono);
  transition: all var(--m-transition);
}
.suggestion-btn:hover {
  background: var(--m-accent-blue); color: #fff;
  box-shadow: var(--m-glow-blue);
}
.suggestion-btn.approve-sug { border-color: var(--m-accent-green); color: var(--m-accent-green); background: rgba(0,230,118,0.08); }
.suggestion-btn.approve-sug:hover { background: var(--m-accent-green); color: #fff; }
.suggestion-btn.reject-sug { border-color: var(--m-accent-red); color: var(--m-accent-red); background: rgba(255,82,82,0.08); }
.suggestion-btn.reject-sug:hover { background: var(--m-accent-red); color: #fff; }

/* Scroll badge */
#scroll-badge, #allmd-scroll-badge {
  display: none; position: absolute; bottom: 14px; left: 50%;
  transform: translateX(-50%); background: var(--m-accent-blue); color: #fff;
  padding: 5px 14px; border-radius: 16px; font-size: 11px;
  font-family: var(--m-font-mono); cursor: pointer; z-index: 10;
  box-shadow: 0 2px 14px rgba(68,138,255,0.45);
  transition: all var(--m-transition); animation: bounce-in-m 0.3s ease;
}
#scroll-badge:hover, #allmd-scroll-badge:hover { transform: translateX(-50%) scale(1.06); }

/* Loading dots */
#loading-indicator, #allmd-loading-indicator {
  display: none; padding: 6px 20px; text-align: center;
}
.loading-dots { display: inline-flex; gap: 5px; align-items: center; }
.loading-dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--m-accent-blue); animation: pulse-loading-m 1.4s ease-in-out infinite;
}
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

/* ═══ INPUT ═══ */
#maestro-input-area, #allmd-maestro-input-area {
  display: flex; gap: 8px; padding: 10px 20px;
  background: var(--m-bg-secondary); border-top: 1px solid var(--m-border);
  align-items: flex-end;
}
#maestro-input, #allmd-maestro-input {
  flex: 1; background: var(--m-bg-surface); border: 1px solid var(--m-border);
  color: var(--m-text-primary); font-family: var(--m-font-mono); font-size: 13px;
  padding: 10px 14px; border-radius: var(--m-radius-sm); resize: none;
  min-height: 40px; max-height: 120px; transition: border-color var(--m-transition); outline: none;
}
#maestro-input:focus, #allmd-maestro-input:focus { border-color: var(--m-accent-blue); box-shadow: 0 0 0 2px rgba(68,138,255,0.12); }
#maestro-input::placeholder, #allmd-maestro-input::placeholder { color: var(--m-text-dim); }
#btn-send, #allmd-btn-send {
  padding: 10px 16px; background: linear-gradient(135deg, var(--m-accent-blue), #2962ff);
  color: #fff; border: none; border-radius: var(--m-radius-sm);
  font-family: var(--m-font-mono); font-size: 13px; font-weight: 500;
  cursor: pointer; transition: all var(--m-transition);
}
#btn-send:hover, #allmd-btn-send:hover { filter: brightness(1.15); transform: translateY(-1px); box-shadow: var(--m-glow-blue); }
#btn-send:active, #allmd-btn-send:active { transform: translateY(0); }
#btn-send:disabled, #allmd-btn-send:disabled { opacity: 0.35; cursor: not-allowed; transform: none; filter: none; }

/* ═══ ACTION BAR ═══ */
#maestro-actions, #allmd-maestro-actions {
  display: flex; gap: 6px; padding: 10px 20px;
  background: var(--m-bg-secondary); border-top: 1px solid var(--m-border);
  justify-content: center; flex-wrap: wrap;
}
.action-btn {
  padding: 9px 18px; border: none; border-radius: var(--m-radius-sm);
  font-family: var(--m-font-mono); font-size: 12px; font-weight: 600;
  cursor: pointer; transition: all var(--m-transition);
  display: flex; align-items: center; gap: 5px;
}
.action-btn:hover { transform: translateY(-2px); filter: brightness(1.1); }
.action-btn:active { transform: translateY(0) scale(0.97); }
.action-btn:disabled { opacity: 0.3; cursor: not-allowed; transform: none !important; filter: none !important; }
.action-btn.approve { background: linear-gradient(135deg, #00c853, var(--m-accent-green)); color: #fff; }
.action-btn.approve:hover:not(:disabled) { box-shadow: var(--m-glow-green); }
.action-btn.reject { background: linear-gradient(135deg, #d50000, var(--m-accent-red)); color: #fff; }
.action-btn.reject:hover:not(:disabled) { box-shadow: var(--m-glow-red); }
.action-btn.cancel-task { background: var(--m-bg-surface); color: var(--m-text-secondary); border: 1px solid var(--m-border); }
.action-btn.cancel-task:hover:not(:disabled) { background: var(--m-bg-surface-hover); }
.action-btn.resume { background: linear-gradient(135deg, #ff6d00, var(--m-accent-orange)); color: #fff; }
.action-btn.resume:hover:not(:disabled) { box-shadow: var(--m-glow-orange); }
.action-btn.save-session {
  background: linear-gradient(135deg, #7c4dff, var(--m-accent-purple)); color: #fff;
}
.action-btn.save-session:hover:not(:disabled) { box-shadow: var(--m-glow-purple); }

/* ═══ MODAL ═══ */
#new-task-modal, #allmd-new-task-modal {
  display: none; position: fixed; inset: 0; z-index: 2000;
  background: rgba(0,0,0,0.7); backdrop-filter: blur(4px);
  align-items: center; justify-content: center;
}
#new-task-modal.open, #allmd-new-task-modal.open { display: flex; }
.modal-card {
  background: var(--m-bg-secondary); border: 1px solid var(--m-border);
  border-radius: var(--m-radius); width: 90%; max-width: 500px;
  box-shadow: 0 8px 50px rgba(0,0,0,0.65); animation: fadeSlideIn-m 0.25s ease;
}
.modal-card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--m-border);
}
.modal-card-header h4 {
  margin: 0; font-family: var(--m-font-mono); font-size: 14px; color: var(--m-text-primary);
}
.modal-card-header .close-modal {
  background: none; border: none; color: var(--m-text-secondary); font-size: 20px;
  cursor: pointer; padding: 4px 8px; border-radius: var(--m-radius-sm); transition: all var(--m-transition);
}
.modal-card-header .close-modal:hover { color: var(--m-accent-red); background: var(--m-bg-surface); }
.modal-card-body {
  padding: 20px; display: flex; flex-direction: column; gap: 14px;
}
.modal-card-body label {
  font-family: var(--m-font-mono); font-size: 11px; color: var(--m-text-secondary);
  text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; display: block;
}
.modal-card-body select,
.modal-card-body textarea {
  width: 100%; background: var(--m-bg-surface); border: 1px solid var(--m-border);
  color: var(--m-text-primary); font-family: var(--m-font-mono); font-size: 13px;
  padding: 10px 12px; border-radius: var(--m-radius-sm); outline: none;
  transition: border-color var(--m-transition); box-sizing: border-box;
}
.modal-card-body select:focus, .modal-card-body textarea:focus {
  border-color: var(--m-accent-blue); box-shadow: 0 0 0 2px rgba(68,138,255,0.12);
}
.modal-card-body select option { background: var(--m-bg-secondary); }
.modal-card-body textarea { resize: vertical; min-height: 100px; }
.modal-card-footer {
  padding: 14px 20px; border-top: 1px solid var(--m-border);
  display: flex; justify-content: flex-end; gap: 8px;
}
.modal-card-footer button {
  padding: 10px 20px; border-radius: var(--m-radius-sm);
  font-family: var(--m-font-mono); font-size: 12px; font-weight: 500;
  cursor: pointer; transition: all var(--m-transition); border: none;
}
.modal-card-footer .btn-cancel-modal {
  background: var(--m-bg-surface); color: var(--m-text-secondary); border: 1px solid var(--m-border);
}
.modal-card-footer .btn-cancel-modal:hover { background: var(--m-bg-surface-hover); }
.modal-card-footer .btn-create-task {
  background: linear-gradient(135deg, var(--m-accent-blue), #2962ff); color: #fff;
}
.modal-card-footer .btn-create-task:hover { filter: brightness(1.1); box-shadow: var(--m-glow-blue); }

/* Prompt suggestions in modal */
.prompt-suggestions {
  display: flex; flex-direction: column; gap: 4px; margin-top: 4px;
}
.prompt-sug-btn {
  padding: 8px 12px; border-radius: var(--m-radius-sm); font-size: 11px;
  border: 1px solid var(--m-border); background: var(--m-bg-surface);
  color: var(--m-text-secondary); cursor: pointer; text-align: left;
  font-family: var(--m-font-mono); transition: all var(--m-transition);
}
.prompt-sug-btn:hover { border-color: var(--m-accent-blue); color: var(--m-accent-blue); }

/* ═══ ANIMATIONS ═══ */
@keyframes pulse-dot-m { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@keyframes pulse-loading-m {
  0%, 100% { transform: scale(1); opacity: 0.4; }
  50% { transform: scale(1.5); opacity: 1; }
}
@keyframes fadeSlideIn-m { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes bounce-in-m {
  0% { transform: translateX(-50%) scale(0.8); opacity: 0; }
  60% { transform: translateX(-50%) scale(1.05); }
  100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

/* ═══ RESPONSIVE ═══ */
@media (max-width: 767px) {
  #maestro-app, #allmd-maestro-app { grid-template-columns: 1fr; margin: -15px; min-height: calc(100vh - 120px); border-radius: 0; }
  #maestro-sidebar, #allmd-maestro-sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: var(--m-sidebar-w); z-index: 1000; transform: translateX(-100%);
  }
  #maestro-sidebar.open, #allmd-maestro-sidebar.open { transform: translateX(0); }
  #sidebar-overlay.open, #allmd-sidebar-overlay.open { display: block; }
  #hamburger-btn, #allmd-hamburger-btn { display: flex; }
  #maestro-actions, #allmd-maestro-actions {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
    border-top: 1px solid var(--m-border); padding: 8px 10px;
  }
  .action-btn { flex: 1; justify-content: center; padding: 11px 6px; font-size: 11px; }
  #maestro-main, #allmd-maestro-main { padding-bottom: 64px; }
  .msg-bubble { max-width: 95%; }
  .msg-bubble.msg-system { max-width: 90%; }
}








/* === Consolidated from project.html === */
/* scoped CSS for ALLMD Maestro */
          #document-version-panel-allmd {
            --m-bg-primary: #f1f5f9;
            --m-bg-secondary: #ffffff;
            --m-bg-surface: #e2e8f0;
            --m-bg-surface-hover: #cbd5e1;
            --m-accent-green: #10b981;
            --m-accent-red: #ef4444;
            --m-accent-orange: #f59e0b;
            --m-accent-blue: #125368;
            --m-accent-purple: #8b5cf6;
            --m-text-primary: #0f172a;
            --m-text-secondary: #475569;
            --m-text-dim: #64748b;
            --m-border: #cbd5e1;
            --m-glow-green: 0 0 10px rgba(16,185,129,0.2);
            --m-glow-blue: 0 0 10px rgba(18,83,104,0.2);
            --m-glow-red: 0 0 10px rgba(239,68,68,0.2);
            --m-glow-orange: 0 0 10px rgba(245,158,11,0.2);
            --m-glow-purple: 0 0 10px rgba(139,92,246,0.2);
            --m-font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
            --m-radius: 10px;
            --m-radius-sm: 6px;
            --m-transition: 0.2s ease;
            --m-sidebar-w: 280px;
            --m-console-border-color: var(--m-border);
          }

          html[data-theme="dark"] #document-version-panel-allmd {
            --m-bg-primary: #1a1b2e;
            --m-bg-secondary: #111122;
            --m-bg-surface: #252640;
            --m-bg-surface-hover: #2e2e50;
            --m-accent-green: #00e676;
            --m-accent-red: #ff5252;
            --m-accent-orange: #ffab40;
            --m-accent-blue: #448aff;
            --m-accent-purple: #b388ff;
            --m-text-primary: #e0e0e0;
            --m-text-secondary: #9e9e9e;
            --m-text-dim: #5c5c7a;
            --m-border: #33335a;
            --m-glow-green: 0 0 14px rgba(0,230,118,0.3);
            --m-glow-blue: 0 0 14px rgba(68,138,255,0.3);
            --m-glow-red: 0 0 14px rgba(255,82,82,0.3);
            --m-glow-orange: 0 0 14px rgba(255,171,64,0.3);
            --m-glow-purple: 0 0 14px rgba(179,136,255,0.3);
          }

          #allmd-maestro-app {
            display: grid;
            grid-template-columns: var(--m-sidebar-w) 1fr;
            height: calc(100vh - 120px);
            background: var(--m-bg-primary);
            overflow: hidden;
          }

          #allmd-maestro-sidebar {
            background: var(--m-bg-secondary);
            border-right: 1px solid var(--m-border);
            display: flex;
            flex-direction: column;
            overflow: hidden;
          }

          .allmd-sidebar-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 10px 14px;
            border-bottom: 1px solid var(--m-border);
          }

          .allmd-sidebar-header h3 {
            margin: 0;
            font-family: var(--m-font-mono);
            font-size: 13px;
            font-weight: 600;
            color: var(--m-text-primary);
          }

          .allmd-sidebar-tabs {
            display: flex;
            border-bottom: 1px solid var(--m-border);
          }

          .allmd-sidebar-tab {
            flex: 1;
            padding: 10px 4px;
            text-align: center;
            font-family: var(--m-font-mono);
            font-size: 10px;
            color: var(--m-text-dim);
            cursor: pointer;
            border: none;
            background: none;
            transition: all var(--m-transition);
            border-bottom: 2px solid transparent;
            outline: none;
          }

          .allmd-sidebar-tab:hover {
            color: var(--m-text-secondary);
          }

          .allmd-sidebar-tab.active {
            color: var(--m-accent-blue);
            border-bottom-color: var(--m-accent-blue);
            background: rgba(68,138,255,0.05);
          }

          .allmd-sidebar-panel {
            flex: 1;
            overflow-y: auto;
            padding: 8px;
            display: none;
          }

          .allmd-sidebar-panel.active {
            display: block;
          }

          .allmd-sidebar-panel::-webkit-scrollbar {
            width: 4px;
          }

          .allmd-sidebar-panel::-webkit-scrollbar-thumb {
            background: var(--m-border);
            border-radius: 2px;
          }

          .allmd-task-item {
            display: flex;
            align-items: center;
            gap: 10px;
            padding: 8px 10px;
            border-radius: var(--m-radius-sm);
            cursor: pointer;
            transition: all var(--m-transition);
            margin-bottom: 2px;
            border: 1px solid transparent;
          }

          .allmd-task-item:hover {
            background: var(--m-bg-surface);
            border-color: var(--m-border);
          }

          .allmd-task-item.active {
            background: var(--m-bg-surface);
            border-color: var(--m-accent-blue);
            box-shadow: var(--m-glow-blue);
          }

          .allmd-status-dot {
            width: 8px;
            height: 8px;
            border-radius: 50%;
            flex-shrink: 0;
            background: var(--m-text-dim);
          }

          .allmd-status-dot.completed {
            background: var(--m-accent-green);
            box-shadow: var(--m-glow-green);
          }

          .allmd-status-dot.in_progress,
          .allmd-status-dot.streaming {
            background: var(--m-accent-blue);
            box-shadow: var(--m-glow-blue);
            animation: pulse-dot 1.5s ease-in-out infinite;
          }

          .allmd-status-dot.error,
          .allmd-status-dot.cancelled {
            background: var(--m-accent-red);
          }

.allmd-status-dot.awaiting {
            background: var(--m-accent-orange);
            box-shadow: var(--m-glow-orange);
            animation: pulse-dot 2s ease-in-out infinite;
          }

          .allmd-task-info {
            flex: 1;
            min-width: 0;
          }

          .allmd-task-id {
            font-family: var(--m-font-mono);
            font-size: 11px;
            color: var(--m-text-primary);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
          }

          .allmd-task-desc {
            font-size: 10px;
            color: var(--m-text-dim);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            margin-top: 2px;
          }

          .allmd-deliv-item {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 6px 10px;
            border-radius: var(--m-radius-sm);
            border: 1px solid transparent;
            transition: all var(--m-transition);
            margin-bottom: 2px;
            cursor: pointer;
          }

          .allmd-deliv-item:hover {
            background: var(--m-bg-surface);
            border-color: var(--m-border);
          }

          .allmd-deliv-icon {
            font-size: 13px;
            color: var(--m-accent-purple);
            flex-shrink: 0;
          }

          .allmd-deliv-info {
            flex: 1;
            min-width: 0;
          }

          .allmd-deliv-name {
            font-family: var(--m-font-mono);
            font-size: 11px;
            color: var(--m-text-primary);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
          }

          .allmd-deliv-meta {
            font-size: 9px;
            color: var(--m-text-dim);
            margin-top: 1px;
          }

          .allmd-sidebar-footer {
            padding: 8px;
            border-top: 1px solid var(--m-border);
          }

          #allmd-btn-new-task {
            width: 100%;
            padding: 8px;
            border: none;
            border-radius: var(--m-radius-sm);
            font-family: var(--m-font-mono);
            font-size: 11px;
            font-weight: 600;
            cursor: pointer;
            transition: all var(--m-transition);
            background: linear-gradient(135deg, var(--m-accent-blue), #2962ff);
            color: #fff;
          }

          #allmd-btn-new-task:hover {
            filter: brightness(1.1);
            box-shadow: var(--m-glow-blue);
          }

          #allmd-maestro-main {
            display: flex;
            flex-direction: column;
            background: var(--m-bg-primary);
            min-width: 0;
            height: 100%;
          }

          .allmd-main-topbar {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 8px 16px;
            border-bottom: 1px solid var(--m-border);
            background: var(--m-bg-secondary);
            gap: 10px;
          }

          .allmd-topbar-info {
            display: flex;
            align-items: center;
            gap: 10px;
            min-width: 0;
            flex: 1;
          }

          .allmd-topbar-task-id {
            font-family: var(--m-font-mono);
            font-size: 11px;
            color: var(--m-text-primary);
            background: var(--m-bg-surface);
            padding: 3px 8px;
            border-radius: var(--m-radius-sm);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            max-width: 180px;
          }

          .allmd-topbar-badge {
            font-size: 9px;
            padding: 2px 6px;
            border-radius: 10px;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            font-weight: 600;
          }

          .allmd-topbar-badge.mode {
            background: var(--m-bg-surface);
            color: var(--m-accent-purple);
            border: 1px solid rgba(179,136,255,0.3);
          }

          .allmd-topbar-badge.status-completed {
            background: rgba(0,230,118,0.12);
            color: var(--m-accent-green);
            border: 1px solid rgba(0,230,118,0.3);
          }

          .allmd-topbar-badge.status-in_progress {
            background: rgba(68,138,255,0.12);
            color: var(--m-accent-blue);
            border: 1px solid rgba(68,138,255,0.3);
          }

          .allmd-topbar-badge.status-error,
          .allmd-topbar-badge.status-cancelled {
            background: rgba(255,82,82,0.12);
            color: var(--m-accent-red);
            border: 1px solid rgba(255,82,82,0.3);
          }

          .allmd-topbar-badge.status-awaiting {
            background: rgba(255,171,64,0.12);
            color: var(--m-accent-orange);
            border: 1px solid rgba(255,171,64,0.3);
          }

          .allmd-connection-indicator {
            display: flex;
            align-items: center;
            gap: 6px;
            font-size: 9px;
            color: var(--m-text-secondary);
            font-family: var(--m-font-mono);
          }

          .allmd-connection-dot {
            width: 8px;
            height: 8px;
            border-radius: 50%;
            background: var(--m-text-dim);
            transition: all 0.3s;
          }

          .allmd-connection-dot.connected {
            background: var(--m-accent-green);
            box-shadow: var(--m-glow-green);
            animation: pulse-dot 1.5s ease-in-out infinite;
          }

          #allmd-maestro-console-wrap {
            flex: 1;
            display: flex;
            flex-direction: column;
            position: relative;
            overflow: hidden;
          }

          #allmd-agent-console {
            flex: 1;
            overflow-y: auto;
            padding: 12px 16px;
            font-family: var(--m-font-mono);
            font-size: 12px;
            line-height: 1.5;
            border-top: 3px solid var(--m-console-border-color);
            transition: border-color 0.5s ease;
          }

          #allmd-agent-console::-webkit-scrollbar {
            width: 5px;
          }

          #allmd-agent-console::-webkit-scrollbar-thumb {
            background: var(--m-border);
            border-radius: 3px;
          }

          .allmd-console-empty {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100%;
            color: var(--m-text-dim);
            text-align: center;
            gap: 12px;
            padding: 20px;
          }

          .allmd-console-empty i {
            font-size: 40px;
            opacity: 0.25;
          }

          .allmd-console-empty p {
            font-size: 12px;
            line-height: 1.4;
            max-width: 300px;
            margin: 0;
          }

          .allmd-quick-modes {
            display: flex;
            gap: 6px;
            flex-wrap: wrap;
            justify-content: center;
            margin-top: 8px;
          }

          .allmd-quick-mode-btn {
            padding: 4px 10px;
            border-radius: 12px;
            font-size: 11px;
            border: 1px solid var(--m-border);
            background: var(--m-bg-surface);
            color: var(--m-text-secondary);
            cursor: pointer;
            font-family: var(--m-font-mono);
            transition: all var(--m-transition);
          }

          .allmd-quick-mode-btn:hover {
            border-color: var(--m-accent-blue);
            color: var(--m-accent-blue);
            background: rgba(68,138,255,0.08);
          }

          .allmd-msg-bubble {
            max-width: 85%;
            padding: 10px 14px;
            border-radius: var(--m-radius);
            margin-bottom: 8px;
            position: relative;
            word-break: break-word;
            animation: fadeSlideIn 0.2s ease;
          }

          .allmd-msg-bubble.msg-roocode {
            background: var(--m-bg-surface);
            border-left: 3px solid var(--m-accent-green);
            margin-right: auto;
            color: var(--m-text-primary);
          }

          .allmd-msg-bubble.msg-roocode.completion-result {
            border-left-color: var(--m-accent-purple);
            background: linear-gradient(135deg, var(--m-bg-surface), rgba(179,136,255,0.05));
          }

          .allmd-msg-bubble.msg-user {
            background: #1a2744;
            border-left: 3px solid var(--m-accent-blue);
            margin-left: auto;
            color: var(--m-text-primary);
          }

          .allmd-msg-bubble.msg-system {
            background: transparent;
            border: 1px dashed var(--m-border);
            margin: 6px auto;
            text-align: center;
            color: var(--m-text-secondary);
            font-style: italic;
            font-size: 10px;
            max-width: 70%;
          }

          .allmd-msg-bubble pre {
            background: var(--m-bg-secondary);
            padding: 8px;
            border-radius: var(--m-radius-sm);
            overflow-x: auto;
            margin: 4px 0;
            font-size: 11px;
            border: 1px solid var(--m-border);
          }

          .allmd-msg-bubble code {
            font-family: var(--m-font-mono);
            font-size: 11px;
          }

          .allmd-msg-time {
            font-size: 8px;
            color: var(--m-text-dim);
            margin-top: 4px;
            text-align: right;
          }

          .allmd-suggestions-row {
            display: flex;
            gap: 6px;
            flex-wrap: wrap;
            margin-top: 6px;
          }

          .allmd-suggestion-btn {
            padding: 4px 10px;
            border-radius: 12px;
            font-size: 10px;
            border: 1px solid var(--m-accent-blue);
            background: rgba(68,138,255,0.08);
            color: var(--m-accent-blue);
            cursor: pointer;
            font-family: var(--m-font-mono);
            transition: all var(--m-transition);
          }

          .allmd-suggestion-btn:hover {
            background: var(--m-accent-blue);
            color: #fff;
            box-shadow: var(--m-glow-blue);
          }

          .allmd-suggestion-btn.approve-sug {
            border-color: var(--m-accent-green);
            color: var(--m-accent-green);
            background: rgba(0,230,118,0.08);
          }

          .allmd-suggestion-btn.approve-sug:hover {
            background: var(--m-accent-green);
            color: #fff;
          }

          .allmd-suggestion-btn.reject-sug {
            border-color: var(--m-accent-red);
            color: var(--m-accent-red);
            background: rgba(255,82,82,0.08);
          }

          .allmd-suggestion-btn.reject-sug:hover {
            background: var(--m-accent-red);
            color: #fff;
          }

          #allmd-scroll-badge {
            display: none;
            position: absolute;
            bottom: 10px;
            left: 50%;
            transform: translateX(-50%);
            background: var(--m-accent-blue);
            color: #fff;
            padding: 4px 10px;
            border-radius: 12px;
            font-size: 10px;
            font-family: var(--m-font-mono);
            cursor: pointer;
            z-index: 10;
            box-shadow: 0 2px 10px rgba(68,138,255,0.4);
          }

          #allmd-loading-indicator {
            display: none;
            padding: 4px 16px;
            text-align: center;
          }

          .allmd-loading-dots {
            display: inline-flex;
            gap: 4px;
            align-items: center;
          }

          .allmd-loading-dots span {
            width: 5px;
            height: 5px;
            border-radius: 50%;
            background: var(--m-accent-blue);
            animation: pulse-loading 1.4s ease-in-out infinite;
          }

          .allmd-loading-dots span:nth-child(2) {
            animation-delay: 0.2s;
          }

          .allmd-loading-dots span:nth-child(3) {
            animation-delay: 0.4s;
          }

          #allmd-maestro-input-area {
            display: flex;
            gap: 6px;
            padding: 8px 16px;
            background: var(--m-bg-secondary);
            border-top: 1px solid var(--m-border);
            align-items: flex-end;
          }

          #allmd-agent-input {
            flex: 1;
            background: var(--m-bg-surface);
            border: 1px solid var(--m-border);
            color: var(--m-text-primary);
            font-family: var(--m-font-mono);
            font-size: 12px;
            padding: 8px 10px;
            border-radius: var(--m-radius-sm);
            resize: none;
            min-height: 36px;
            max-height: 100px;
            outline: none;
          }

          #allmd-btn-send {
            padding: 8px 14px;
            background: linear-gradient(135deg, var(--m-accent-blue), #2962ff);
            color: #fff;
            border: none;
            border-radius: var(--m-radius-sm);
            font-family: var(--m-font-mono);
            font-size: 12px;
            font-weight: 500;
            cursor: pointer;
            transition: all var(--m-transition);
          }

          #allmd-btn-send:hover {
            filter: brightness(1.15);
          }

          #allmd-btn-send:disabled {
            opacity: 0.35;
            cursor: not-allowed;
          }

          #allmd-agent-actions {
            display: flex;
            gap: 6px;
            padding: 8px 16px;
            background: var(--m-bg-secondary);
            border-top: 1px solid var(--m-border);
            justify-content: center;
            flex-wrap: wrap;
          }

          .allmd-action-btn {
            padding: 6px 12px;
            border: none;
            border-radius: var(--m-radius-sm);
            font-family: var(--m-font-mono);
            font-size: 11px;
            font-weight: 600;
            cursor: pointer;
            transition: all var(--m-transition);
            display: flex;
            align-items: center;
            gap: 4px;
          }

          .allmd-action-btn:hover {
            filter: brightness(1.1);
          }

          .allmd-action-btn:disabled {
            opacity: 0.3;
            cursor: not-allowed;
          }

          .allmd-action-btn.approve {
            background: linear-gradient(135deg, #00c853, var(--m-accent-green));
            color: #fff;
          }

          .allmd-action-btn.reject {
            background: linear-gradient(135deg, #d50000, var(--m-accent-red));
            color: #fff;
          }

          .allmd-action-btn.cancel-task {
            background: var(--m-bg-surface);
            color: var(--m-text-secondary);
            border: 1px solid var(--m-border);
          }

          .allmd-action-btn.resume {
            background: linear-gradient(135deg, #ff6d00, var(--m-accent-orange));
            color: #fff;
          }

          .allmd-action-btn.save-session {
            background: linear-gradient(135deg, #7c4dff, var(--m-accent-purple));
            color: #fff;
          }

          /* Modals */
          .allmd-modal {
            display: none;
            position: fixed;
            inset: 0;
            z-index: 2000;
            background: rgba(0,0,0,0.7);
            backdrop-filter: blur(4px);
            align-items: center;
            justify-content: center;
          }

          .allmd-modal.open {
            display: flex;
          }

          .allmd-modal-card {
            background: var(--m-bg-secondary);
            border: 1px solid var(--m-border);
            border-radius: var(--m-radius);
            width: 90%;
            max-width: 450px;
            box-shadow: 0 8px 30px rgba(0,0,0,0.5);
            animation: fadeSlideIn 0.2s ease;
          }

          .allmd-modal-card-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 10px 16px;
            border-bottom: 1px solid var(--m-border);
          }

          .allmd-modal-card-header h4 {
            margin: 0;
            font-family: var(--m-font-mono);
            font-size: 13px;
            color: var(--m-text-primary);
          }

          .allmd-modal-card-header .close-modal {
            background: none;
            border: none;
            color: var(--m-text-secondary);
            font-size: 18px;
            cursor: pointer;
            outline: none;
          }

          .allmd-modal-card-body {
            padding: 16px;
            display: flex;
            flex-direction: column;
            gap: 12px;
          }

          .allmd-modal-card-body label {
            font-family: var(--m-font-mono);
            font-size: 10px;
            color: var(--m-text-secondary);
            text-transform: uppercase;
            margin-bottom: 4px;
            display: block;
          }

          .allmd-modal-card-body select,
          .allmd-modal-card-body textarea,
          .allmd-modal-card-body input {
            width: 100%;
            background: var(--m-bg-surface);
            border: 1px solid var(--m-border);
            color: var(--m-text-primary);
            font-family: var(--m-font-mono);
            font-size: 12px;
            padding: 8px;
            border-radius: var(--m-radius-sm);
            outline: none;
            box-sizing: border-box;
          }

          .allmd-modal-card-footer {
            padding: 10px 16px;
            border-top: 1px solid var(--m-border);
            display: flex;
            justify-content: flex-end;
            gap: 8px;
          }

          .allmd-modal-card-footer button {
            padding: 8px 16px;
            border-radius: var(--m-radius-sm);
            font-family: var(--m-font-mono);
            font-size: 11px;
            font-weight: 500;
            cursor: pointer;
            border: none;
          }

          .allmd-modal-card-footer .btn-cancel-modal {
            background: var(--m-bg-surface);
            color: var(--m-text-secondary);
            border: 1px solid var(--m-border);
          }

          .allmd-modal-card-footer .btn-create-task {
            background: linear-gradient(135deg, var(--m-accent-blue), #2962ff);
            color: #fff;
          }

          /* folder rendering */
          .allmd-folder-node {
            margin-top: 4px;
          }

          .allmd-folder-header {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 6px 8px;
            font-family: var(--m-font-mono);
            font-size: 11px;
            font-weight: 600;
            color: var(--m-accent-blue);
            background: rgba(68,138,255,0.06);
            border-radius: var(--m-radius-sm);
            cursor: pointer;
            transition: all var(--m-transition);
            user-select: none;
          }

          .allmd-folder-contents {
            display: block;
          }

          /* animations */
          @keyframes pulse-dot { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
          @keyframes pulse-loading {
            0%, 100% { transform: scale(1); opacity: 0.4; }
            50% { transform: scale(1.5); opacity: 1; }
          }
          @keyframes fadeSlideIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.nav-tabs {
    border-bottom: 2px solid #dee2e6;
    margin-bottom: 1.5rem;
  }

  .nav-tabs .nav-link {
    border: none;
    border-bottom: 3px solid transparent;
    color: #6c757d;
    font-weight: 500;
    transition: all 0.3s ease;
    cursor: pointer;
  }

  .nav-tabs .nav-link:hover {
    color: #0d6efd;
    border-bottom-color: #e9ecef;
  }

  .nav-tabs .nav-link.active {
    background-color: transparent;
    color: #0d6efd;
    border-bottom-color: #0d6efd;
  }

  .tab-content {
    animation: fadeIn 0.3s ease-in;
  }

  @keyframes fadeIn {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
  }

  .dashboard-card {
    border: 1px solid #e9ecef;
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
  }

  .dashboard-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
  }

/* === Consolidated from project_agent_settings.html === */
:root {
    --as-primary: #4f46e5;
    --as-primary-hover: #4338ca;
    --as-success: #10b981;
    --as-warning: #f59e0b;
    --as-danger: #ef4444;
    --as-surface: #ffffff;
    --as-surface-soft: #f8fafc;
    --as-border: #e2e8f0;
    --as-text: #1e293b;
    --as-text-muted: #64748b;
    --as-bg: #f1f5f9;
  }

  html[data-theme="dark"] {
    --as-primary: #6366f1;
    --as-primary-hover: #4f46e5;
    --as-success: #34d399;
    --as-warning: #fbbf24;
    --as-danger: #f87171;
    --as-surface: #1e293b;
    --as-surface-soft: #0f172a;
    --as-border: #334155;
    --as-text: #f8fafc;
    --as-text-muted: #94a3b8;
    --as-bg: #0b0f19;
  }

  .as-container {
    color: var(--as-text);
    font-family: 'Outfit', 'Inter', -apple-system, sans-serif;
  }

  .tagma-tabs {
    border-bottom: 2px solid var(--as-border);
    gap: 8px;
  }

  .tagma-tabs .nav-link {
    color: var(--as-text-muted);
    border: none;
    border-radius: 6px 6px 0 0;
    font-weight: 500;
    padding: 10px 16px;
    transition: all 0.2s ease;
  }

  .tagma-tabs .nav-link:hover {
    color: var(--as-primary);
    background: rgba(99, 102, 241, 0.05);
  }

  .tagma-tabs .nav-link.active {
    color: var(--as-primary) !important;
    background: var(--as-surface) !important;
    border-bottom: 2px solid var(--as-primary);
    font-weight: 600;
  }

  .as-card {
    background: var(--as-surface);
    border: 1px solid var(--as-border);
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05), 0 2px 4px -1px rgba(0,0,0,0.02);
    margin-bottom: 24px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
  }

  .as-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -2px rgba(0,0,0,0.04);
  }

  .as-card-header {
    border-bottom: 1px solid var(--as-border);
    padding: 16px 20px;
    font-weight: 600;
    font-size: 1.1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .as-card-body {
    padding: 20px;
  }

  .status-badge {
    padding: 4px 8px;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
  }

  .status-online {
    background: rgba(16, 185, 129, 0.15);
    color: var(--as-success);
    border: 1px solid rgba(16, 185, 129, 0.3);
  }

  .status-offline {
    background: rgba(239, 68, 68, 0.15);
    color: var(--as-danger);
    border: 1px solid rgba(239, 68, 68, 0.3);
  }

  .profile-item {
    border: 1px solid var(--as-border);
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--as-surface-soft);
    transition: all 0.2s ease;
  }

  .profile-item.active {
    border-color: var(--as-primary);
    background: rgba(99, 102, 241, 0.05);
  }

  .switch-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--as-border);
  }

  .switch-container:last-child {
    border-bottom: none;
  }

  .switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
  }

  .switch input {
    opacity: 0;
    width: 0;
    height: 0;
  }

  .slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #cbd5e1;
    transition: .3s;
    border-radius: 24px;
  }

  .slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
  }

  input:checked + .slider {
    background-color: var(--as-primary);
  }

  input:checked + .slider:before {
    transform: translateX(20px);
  }

  .as-btn {
    background: var(--as-primary);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 8px 16px;
    font-weight: 500;
    transition: background 0.2s;
  }

  .as-btn:hover {
    background: var(--as-primary-hover);
    color: white;
  }

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

  .as-btn-secondary:hover {
    background: var(--as-surface-soft);
    color: var(--as-text);
  }

  .toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1050;
  }

/* === Consolidated from project_documents.html === */
.rag-assistant-card {
    background: transparent;
    border-radius: 12px;
    border: none;
    box-shadow: none;
  }
  .settings-collapse {
    background: rgba(0, 0, 0, 0.03);
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.08);
  }
  .nav-tabs-custom {
    border-bottom: 2px solid rgba(99, 102, 241, 0.2);
    gap: 8px;
    margin-bottom: 20px;
  }
  .nav-tabs-custom .nav-link {
    border: none;
    border-radius: 8px 8px 0 0;
    color: #64748b;
    background: rgba(0, 0, 0, 0.02);
    border-bottom: 3px solid transparent;
    font-weight: 600;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 10px 20px;
  }
  .nav-tabs-custom .nav-link:hover {
    color: #6366f1;
    background: rgba(99, 102, 241, 0.05);
    border-bottom-color: rgba(99, 102, 241, 0.3);
    text-decoration: none;
  }
  .nav-tabs-custom .nav-link.active {
    color: #6366f1;
    background: linear-gradient(180deg, rgba(99, 102, 241, 0.05) 0%, rgba(99, 102, 241, 0.01) 100%);
    border-bottom-color: #6366f1;
    border-bottom-width: 3px;
  }
  .tab-pane {
    animation: tabFadeIn 0.4s ease-in-out;
  }
  @keyframes tabFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
  }

  /* Search page filters and search bar */
  .search-bar-shadow {
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
  }
  .filter-pill {
    background: rgba(0, 0, 0, 0.03);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 20px;
    transition: all 0.2s ease-in-out;
  }
  .filter-pill:hover {
    background: rgba(0, 0, 0, 0.06);
    border-color: rgba(0, 0, 0, 0.15);
  }
  
  /* AI Overview Featured Snippet */
  .ai-overview-card {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.05) 0%, rgba(99, 102, 241, 0.01) 100%);
    border: 1px solid rgba(129, 140, 248, 0.3);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
  }
  
  /* Google-Style Result Card */
  .result-card {
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.07);
    border-radius: 8px;
    padding: 18px;
    margin-bottom: 20px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.01);
    transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  }
  .result-card:hover {
    border-color: rgba(99, 102, 241, 0.25);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.05);
    transform: translateY(-2px);
  }
  .result-title {
    color: #4f46e5 !important;
    text-decoration: none;
    font-size: 1.15rem;
    font-weight: 600;
  }
  .result-title:hover {
    text-decoration: underline !important;
  }
  .result-meta {
    color: #059669 !important;
    font-size: 0.82rem;
    margin-bottom: 6px;
  }
  .result-snippet {
    color: #374151 !important;
    font-size: 0.9rem;
    line-height: 1.5;
    text-align: justify;
  }
  
  /* Search keywords highlighting */
  mark.search-highlight {
    background: rgba(245, 158, 11, 0.25);
    color: #b45309;
    padding: 0 3px;
    border-radius: 3px;
    font-weight: 600;
  }

  .btn-outline-indigo {
    color: #4f46e5 !important;
    border-color: rgba(99, 102, 241, 0.4) !important;
    background-color: transparent !important;
    transition: all 0.2s ease-in-out;
  }
  .btn-outline-indigo:hover:not(.disabled) {
    color: #fff !important;
    background-color: #6366f1 !important;
    border-color: #6366f1 !important;
    text-decoration: none !important;
  }
  .btn-outline-indigo.disabled, .btn-indigo:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
  }
  .btn-indigo {
    color: #fff !important;
    background-color: #6366f1 !important;
    border-color: #6366f1 !important;
  }

/* === Consolidated from project_query.html === */
/* Custom scrollbars */
  #rag-chat-messages::-webkit-scrollbar {
    width: 6px;
  }
  #rag-chat-messages::-webkit-scrollbar-thumb {
    background: #4f98a3;
    border-radius: 3px;
  }
  #rag-chat-messages::-webkit-scrollbar-track {
    background: #1a1d27;
  }

  /* Chat bubble styles */
  .chat-bubble {
    max-width: 75%;
    margin-bottom: 15px;
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.5;
    font-size: 0.95rem;
  }
  .chat-bubble-user {
    background-color: #4f46e5;
    color: #fff;
    align-self: flex-end;
    margin-left: auto;
    border-bottom-right-radius: 2px;
  }
  .chat-bubble-assistant {
    background-color: #2e303f;
    color: #f1f5f9;
    align-self: flex-start;
    margin-right: auto;
    border-bottom-left-radius: 2px;
  }
  .sources-list {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid #475569;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }
  .source-pill {
    background-color: #0f172a;
    border: 1px solid #4f98a3;
    color: #4f98a3;
    font-size: 0.8rem;
    font-weight: 500;
    padding: 4px 10px;
    border-radius: 20px;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
  }
  .source-pill:hover {
    background-color: #4f98a3;
    color: #0f172a;
    text-decoration: none;
  }

/* === Consolidated from project_dashboard.html === */
.nav-tabs {
    border-bottom: 2px solid #dee2e6;
    margin-bottom: 1.5rem;
  }

  .nav-tabs .nav-link {
    border: none;
    border-bottom: 3px solid transparent;
    color: #6c757d;
    font-weight: 500;
    transition: all 0.3s ease;
    cursor: pointer;
  }

  .nav-tabs .nav-link:hover {
    color: #0d6efd;
    border-bottom-color: #e9ecef;
  }

  .nav-tabs .nav-link.active {
    background-color: transparent;
    color: #0d6efd;
    border-bottom-color: #0d6efd;
  }

  .tab-content {
    animation: fadeIn 0.3s ease-in;
  }

  @keyframes fadeIn {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
  }

  .dashboard-card {
    border: 1px solid #e9ecef;
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
  }

  .dashboard-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
  }

/* === Consolidated from project_tags.html === */
.transition-all {
    transition: all 0.2s ease-in-out;
  }
  .tag-color-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
    border: 1px solid rgba(0, 0, 0, 0.1);
  }
  .hover-primary:hover {
    color: #007bff !important;
    text-decoration: none;
  }
  .action-buttons {
    opacity: 0.6;
    transition: opacity 0.2s ease-in-out;
  }
  tr:hover .action-buttons,
  .highlight-list-item:hover .action-buttons {
    opacity: 1;
  }
  .action-buttons button:hover {
    transform: scale(1.15);
    transition: transform 0.1s ease;
  }
  .snippet-preview {
    border-left-width: 4px !important;
  }
  .card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
  }
  .card:hover {
    transform: translateY(-2px);
    box-shadow: 0 .5rem 1.5rem rgba(0,0,0,.08)!important;
  }
  .modal-content {
    border-radius: 12px;
  }

/* === Consolidated from project_import_assistant.html === */
.report-header {
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    color: white;
    padding: 2rem;
    border-radius: 12px;
    margin-bottom: 2rem;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
  }
  .card-stat {
    border: none;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    transition: transform 0.2s, box-shadow 0.2s;
  }
  .card-stat:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 12px rgba(0,0,0,0.1);
  }
  .badge-custom {
    font-size: 0.85rem;
    padding: 0.4em 0.6em;
  }
  .table-responsive-custom {
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
  }
  .table-responsive-custom thead th {
    background-color: #343a40;
    color: white;
    border: none;
  }
  .search-box-custom {
    border-radius: 20px;
  }


/* =====================================================
   3. Tagma QDA Overrides & theme tweaks (formerly tagmaqda.css)
   ===================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.allmd-status-dot.planned,
.allmd-status-dot.archived,
.allmd-status-dot.orphan {
  background: var(--m-accent-orange);
}

.allmd-status-dot.orphan {
  background: var(--m-accent-red);
}

body {
  font-family: var(--font-sans) !important;
  background-color: var(--bg-color) !important;
  color: var(--text-color) !important;
}

code, pre, .cm-editor, .cm-content {
  font-family: var(--font-mono) !important;
}

/* Card theme-aware overrides */
.card, .tagma-card {
  background-color: var(--surface-color) !important;
  border-color: var(--ui-border) !important;
  color: var(--text-color) !important;
}

.card-header, .tagma-card__header {
  background-color: var(--ui-header-bg) !important;
  border-bottom: 1px solid var(--ui-border) !important;
  color: var(--text-color) !important;
}

/* Table overrides */
.table {
  color: var(--text-color) !important;
}

.table-striped tbody tr:nth-of-type(odd) {
  background-color: var(--ui-table-striped) !important;
}

.table-hover tbody tr:hover {
  background-color: var(--ui-table-hover) !important;
  color: var(--ui-input-focus-text) !important;
}

.thead-light th {
  background-color: var(--ui-header-bg) !important;
  border-color: var(--ui-border) !important;
  color: var(--text-muted) !important;
}

/* List group overrides */
.list-group-item {
  background-color: var(--surface-color) !important;
  border-color: var(--ui-border) !important;
  color: var(--text-color) !important;
}

.list-group-item-action:hover {
  background-color: var(--ui-surface-hover) !important;
  color: var(--primary-color) !important;
}

/* Navigation & Sidebar layout adjustments */
.app-shell__nav {
  background-color: var(--ui-nav-bg) !important;
  border-bottom: 1px solid var(--ui-border) !important;
}

.sidebar-col {
  background-color: var(--ui-sidebar-bg) !important;
  border-right: 1px solid var(--ui-border) !important;
}

/* Form controls overrides */
.form-control {
  background-color: var(--ui-input-bg) !important;
  border-color: var(--ui-border) !important;
  color: var(--text-color) !important;
}

.form-control:focus {
  background-color: var(--ui-input-focus-bg) !important;
  border-color: var(--primary-color) !important;
  color: var(--ui-input-focus-text) !important;
}

/* Shimmer Loader Effect */
@keyframes shimmer {
  0% {
    background-position: -450px 0;
  }
  100% {
    background-position: 450px 0;
  }
}

.skeleton-shimmer {
  background: linear-gradient(to right, #1e293b 8%, #334155 18%, #1e293b 33%);
  background-size: 800px 104px;
  animation: shimmer 1.5s infinite linear;
}

/* Toast container & alerts */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 10050;
}

.toast-msg {
  background: var(--surface-color);
  border-left: 5px solid var(--primary-color);
  color: var(--text-color);
  padding: 12px 20px;
  border-radius: 4px;
  margin-top: 10px;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* IDE Layout styling — scrollable, no fixed height trapping */
.project-workspace-row {
  display: flex;
  position: relative;
  overflow-y: visible;   /* allow page to scroll naturally vertically */
  overflow-x: hidden;    /* prevent horizontal scroll during sidebar toggle */
  min-height: calc(100vh - 160px);
  align-items: flex-start;
}

.sidebar-col {
  transition: transform 0.2s ease,
              margin-left 0.2s ease,
              width 0.2s ease,
              max-width 0.2s ease,
              flex 0.2s ease,
              opacity 0.2s ease;
  background-color: var(--ui-sidebar-bg) !important;
  border-right: 1px solid var(--ui-border) !important;
  /* Let height be determined by content; sidebar scrolls internally */
  height: auto;
  overflow-y: auto;
  position: relative;
  z-index: 101;
  /* sticky so sidebar follows scroll */
  position: sticky;
  top: 0;
  max-height: calc(100vh - 96px);
}

/* Collapsed state — driven by .sidebar-collapsed on the row (matches JS) */
.project-workspace-row.sidebar-collapsed .sidebar-col {
  width: 0 !important;
  max-width: 0 !important;
  flex: 0 0 0 !important;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  padding-left: 0 !important;
  padding-right: 0 !important;
}

/* Legacy: keep .sidebar-col.collapsed for backward compat */
.sidebar-col.collapsed {
  width: 0 !important;
  max-width: 0 !important;
  flex: 0 0 0 !important;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

.content-col {
  transition: max-width 0.2s ease, flex 0.2s ease, width 0.2s ease;
  /* No fixed height — let natural document flow control scroll */
  height: auto;
  min-height: calc(100vh - 160px);
  overflow: visible;
  background-color: var(--bg-color);
  padding: 20px;
}

.project-workspace-row.sidebar-collapsed .content-col,
.content-col.expanded {
  flex: 1 1 auto !important;
  width: auto !important;
  max-width: 100% !important;
}

/* Toggle buttons styling */
.sidebar-toggle-btn {
  background: var(--surface-color);
  color: var(--primary-color);
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

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

/* Custom toast container */
.custom-toast {
  background: var(--surface-color);
  border-left: 4px solid var(--primary-color);
  color: var(--text-color);
  padding: 12px 16px;
  border-radius: 6px;
  margin-top: 10px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 320px;
  opacity: 0;
  transform: translateX(100%);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.custom-toast.show {
  opacity: 1;
  transform: translateX(0);
}

.custom-toast--success {
  border-left-color: #10b981;
}

.custom-toast--error {
  border-left-color: #ef4444;
}

.custom-toast--info {
  border-left-color: #3b82f6;
}

.custom-toast-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.custom-toast-close:hover {
  color: #fff;
}

/* Skeleton and loading effects */
.skeleton-box {
  display: inline-block;
  height: 1em;
  position: relative;
  overflow: hidden;
  background-color: var(--ui-table-striped);
  border-radius: 4px;
  width: 100%;
}

.skeleton-box::after {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  transform: translateX(-100%);
  background-image: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0) 0,
    rgba(255, 255, 255, 0.05) 20%,
    rgba(255, 255, 255, 0.1) 60%,
    rgba(255, 255, 255, 0)
  );
  animation: shimmer-anim 2s infinite;
  content: '';
}

@keyframes shimmer-anim {
  100% {
    transform: translateX(100%);
  }
}

/* Responsive bottom sheet for screens < 768px */
@media (max-width: 767.98px) {
  .project-workspace-row {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }

  .sidebar-col {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100% !important;
    max-width: 100% !important;
    flex: 0 0 100% !important;
    height: 50vh !important;
    max-height: 50vh !important;
    background-color: var(--ui-sidebar-bg, var(--surface-color)) !important;
    border-top: 1px solid var(--ui-border) !important;
    border-right: none !important;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1040;
    margin-left: 0 !important;
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    box-shadow: 0 -8px 24px rgba(0,0,0,0.3);
    /* override sticky from desktop */
    position: fixed;
  }

  .sidebar-col.show-mobile {
    transform: translateY(0);
  }

  .project-workspace-row.sidebar-collapsed .sidebar-col,
  .sidebar-col.collapsed {
    transform: translateY(100%);
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    flex: 0 0 100% !important;
  }

  .content-col {
    height: auto;
    min-height: calc(100vh - 80px);
    overflow: visible;
    width: 100% !important;
    max-width: 100% !important;
    flex: 0 0 100% !important;
  }

  /* Bottom sheet toggle button */
  .mobile-sheet-toggle-btn {
    display: flex !important;
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1030;
    border-radius: 50%;
    width: 54px;
    height: 54px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
    background: var(--primary-color);
    color: #fff;
    border: none;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    cursor: pointer;
    transition: transform 0.2s ease;
  }

  .mobile-sheet-toggle-btn:active {
    transform: scale(0.9);
  }
}

/* Hide mobile controls on desktop */
.mobile-sheet-toggle-btn {
  display: none;
}

/* Performance rendering optimization for long lists */
.content-visibility-auto,
.highlight-list-item,
.tag-tree-node,
.document-list-item {
  content-visibility: auto;
  contain-intrinsic-size: 0 80px;
}

/* CodeMirror theme support */
.cm-editor {
  border: 1px solid var(--ui-border) !important;
  background-color: var(--ui-input-bg) !important;
  color: var(--ui-text) !important;
  border-radius: var(--radius-md) !important;
}
.cm-activeLine {
  background-color: var(--ui-surface-hover) !important;
}
.cm-gutters {
  background-color: var(--ui-surface-hover) !important;
  border-right: 1px solid var(--ui-border) !important;
  color: var(--ui-muted) !important;
}

/* Modals theme-aware support */
.modal-content {
  background-color: var(--surface-color) !important;
  border: 1px solid var(--ui-border) !important;
  color: var(--text-color) !important;
}
.modal-header {
  border-bottom: 1px solid var(--ui-border) !important;
  background-color: var(--ui-header-bg) !important;
}
.modal-footer {
  border-top: 1px solid var(--ui-border) !important;
  background-color: var(--ui-header-bg) !important;
}
.modal-header .close {
  color: var(--text-color) !important;
  opacity: 0.7;
  text-shadow: none;
}
.modal-header .close:hover {
  opacity: 1;
}

/* Dropdowns theme-aware support */
.dropdown-menu {
  background-color: var(--surface-color) !important;
  border: 1px solid var(--ui-border) !important;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15) !important;
}
.dropdown-item {
  color: var(--text-color) !important;
  transition: background-color var(--transition-fast) !important;
}
.dropdown-item:hover, .dropdown-item:focus {
  background-color: var(--ui-surface-hover) !important;
  color: var(--primary-color) !important;
}
.dropdown-divider {
  border-top: 1px solid var(--ui-border) !important;
}

/* Breadcrumbs theme-aware support */
.tagma-breadcrumb {
  background-color: var(--ui-surface-hover) !important;
  border: 1px solid var(--ui-border) !important;
  border-radius: var(--radius-md) !important;
}
.tagma-breadcrumb-item a {
  color: var(--primary-color) !important;
}
.tagma-breadcrumb-item.active {
  color: var(--text-muted) !important;
}

/* Badge count light overrides */
.badge-light {
  background-color: var(--ui-surface-hover) !important;
  color: var(--text-color) !important;
  border: 1px solid var(--ui-border) !important;
}

/* Form inputs & static label styles */
label, .form-text, .text-muted {
  color: var(--text-muted) !important;
}
.text-dark {
  color: var(--text-color) !important;
}
.text-secondary {
  color: var(--text-muted) !important;
}
legend {
  color: var(--text-color) !important;
}

/* Standard HTML hr line tag style */
hr {
  border-top: 1px solid var(--ui-border) !important;
}

/* Help guide and general anchors */
.navbar-dark .navbar-nav .nav-link {
  color: var(--ui-nav-text-muted, rgba(255,255,255,0.75)) !important;
}
.navbar-dark .navbar-nav .nav-link:hover,
.navbar-dark .navbar-nav .nav-link.active {
  color: var(--ui-nav-text, #fff) !important;
}

/* Core tag tree items & active elements theme-aware mixing */
.tag-tree__item:hover {
  background: color-mix(in oklch, var(--ui-accent) 7%, var(--surface-color)) !important;
}

.tag-current {
  background: color-mix(in oklch, var(--ui-accent) 10%, var(--surface-color)) !important;
}

.tag-color-swatch {
  box-shadow: inset 0 0 0 1px color-mix(in oklch, var(--ui-text) 18%, var(--surface-color)) !important;
}

/* Document link current active style */
li.document-link-current {
  background-color: var(--ui-surface-hover) !important;
  border-left: 3px solid var(--primary-color) !important;
}

li.document-link-current a.document-link-a {
  color: var(--primary-color) !important;
  font-weight: 600 !important;
}

/* Button & Badge text contrast in dark theme */
[data-theme="dark"] .btn-primary {
  color: #0f1117 !important;
  font-weight: 600 !important;
}

[data-theme="dark"] .btn-primary:hover,
[data-theme="dark"] .btn-primary:focus {
  color: #ffffff !important;
  background-color: var(--color-primary-light, #5db0bd) !important;
}

[data-theme="dark"] .badge-primary {
  color: #0f1117 !important;
}

/* General form control dark mode fallback styling assurance */
[data-theme="dark"] .form-control {
  background-color: var(--ui-input-bg) !important;
  color: var(--text-color) !important;
  border-color: var(--ui-border) !important;
}
[data-theme="dark"] .form-control:focus {
  background-color: var(--ui-input-focus-bg) !important;
  color: var(--ui-input-focus-text) !important;
  border-color: var(--primary-color) !important;
}

/* --- Global Theme-Aware Design Elements for Consistent light/dark modes --- */

.text-primary {
  color: var(--primary-color) !important;
}
a.text-primary:hover, a.text-primary:focus {
  color: var(--color-primary-light) !important;
}

.badge-primary {
  background-color: var(--primary-color) !important;
  color: #ffffff !important;
}
[data-theme="dark"] .badge-primary {
  color: #0f1117 !important;
  background-color: var(--primary-color) !important;
}

/* Nav tabs styling */
.nav-tabs {
  border-bottom: 2px solid var(--ui-border) !important;
  margin-bottom: 1.5rem;
}
.nav-tabs .nav-link {
  border: none !important;
  border-bottom: 3px solid transparent !important;
  color: var(--text-muted) !important;
  font-weight: 500 !important;
  background-color: transparent !important;
  transition: all 0.3s ease !important;
  cursor: pointer;
}
.nav-tabs .nav-link:hover {
  color: var(--primary-color) !important;
  border-bottom-color: var(--ui-border-hover) !important;
}
.nav-tabs .nav-link.active {
  background-color: transparent !important;
  color: var(--primary-color) !important;
  border-bottom-color: var(--primary-color) !important;
}
.nav-tabs .nav-link.disabled {
  color: var(--ui-border) !important;
  opacity: 0.5;
  cursor: not-allowed;
}

/* Theme-aware Alerts */
.alert {
  border-radius: var(--radius-md) !important;
  border: 1px solid var(--ui-border) !important;
  background-color: var(--ui-surface) !important;
  color: var(--text-color) !important;
}
.alert-primary {
  border-color: color-mix(in oklch, var(--primary-color) 40%, var(--ui-border)) !important;
  background-color: color-mix(in oklch, var(--primary-color) 8%, var(--ui-surface)) !important;
  color: var(--primary-color) !important;
}
.alert-success {
  border-color: rgba(16, 185, 129, 0.4) !important;
  background-color: rgba(16, 185, 129, 0.08) !important;
  color: #10b981 !important;
}
.alert-danger {
  border-color: rgba(239, 68, 68, 0.4) !important;
  background-color: rgba(239, 68, 68, 0.08) !important;
  color: #ef4444 !important;
}
.alert-warning {
  border-color: rgba(245, 158, 11, 0.4) !important;
  background-color: rgba(245, 158, 11, 0.08) !important;
  color: #f59e0b !important;
}
.alert-info {
  border-color: rgba(59, 130, 246, 0.4) !important;
  background-color: rgba(59, 130, 246, 0.08) !important;
  color: #3b82f6 !important;
}
.alert-secondary {
  border-color: var(--ui-border) !important;
  background-color: var(--ui-surface-hover) !important;
  color: var(--text-muted) !important;
}

/* Jumbotron */
.jumbotron {
  background-color: var(--ui-surface) !important;
  color: var(--text-color) !important;
  border: 1px solid var(--ui-border) !important;
}

/* Tables */
.table th, .table td {
  border-color: var(--ui-border) !important;
}
.table thead th {
  border-bottom: 2px solid var(--ui-border) !important;
  color: var(--text-color) !important;
}

/* Buttons */
.btn-secondary {
  background-color: var(--ui-surface-hover) !important;
  border-color: var(--ui-border) !important;
  color: var(--text-color) !important;
}
.btn-secondary:hover, .btn-secondary:focus {
  background-color: var(--ui-border) !important;
  border-color: var(--ui-border-hover) !important;
  color: var(--text-color) !important;
}
.btn-outline-secondary {
  color: var(--text-muted) !important;
  border-color: var(--ui-border) !important;
  background-color: transparent !important;
}
.btn-outline-secondary:hover, .btn-outline-secondary:focus {
  background-color: var(--ui-surface-hover) !important;
  color: var(--text-color) !important;
  border-color: var(--ui-border-hover) !important;
}

.dropdown-item.active {
  background-color: var(--ui-surface-hover) !important;
  color: var(--primary-color) !important;
}

/* Components from custom.css dark mode compatibility */
[data-theme="dark"] .document-source-banner {
  background-color: #1e2530 !important;
  color: #f1f5f9 !important;
}
[data-theme="dark"] .document-source-banner[data-source="md"] {
  background-color: #142e1b !important;
}
[data-theme="dark"] .document-source-banner[data-source="txt"] {
  background-color: #2e260e !important;
}
[data-theme="dark"] #document-view .highlight[data-comment]::after {
  background: var(--ui-surface-hover) !important;
  border-color: var(--ui-border) !important;
  color: var(--ui-text) !important;
}
[data-theme="dark"] #hlinfo {
  background-color: rgba(26, 29, 39, 0.98) !important;
  border-color: var(--ui-border) !important;
  color: var(--ui-text) !important;
}
[data-theme="dark"] #hlinfo-summary {
  color: var(--ui-muted) !important;
}




/* =====================================================
   4. Theme fixes & dark mode compat (formerly theme-fixes.css)
   ===================================================== */

/* =====================================================
   THEME FIXES — Taguette Dark/Light Mode Compatibility
   Correctifs pour Bootstrap + composants custom
   ===================================================== */

/* 1. Variables de base adaptatives basées sur tagma-ui.css */
:root {
  --tg-bg: var(--ui-bg, #f8fafc);
  --tg-bg-secondary: var(--ui-surface-hover, #f1f5f9);
  --tg-text: var(--ui-text, #0f172a);
  --tg-text-muted: var(--ui-muted, #64748b);
  --tg-border: var(--ui-border, #e2e8f0);
  --tg-card-bg: var(--ui-surface, #ffffff);
  --tg-input-bg: var(--ui-input-bg, #ffffff);
  --tg-input-text: var(--ui-text, #0f172a);
  --tg-sidebar-bg: var(--ui-sidebar-bg, #ffffff);
  --tg-sidebar-text: var(--ui-text, #0f172a);
  --tg-nav-bg: var(--ui-nav-bg, #125368);
  --tg-nav-text: #ffffff;
  --tg-modal-bg: var(--ui-surface, #ffffff);
  --tg-modal-text: var(--ui-text, #0f172a);
  --tg-table-bg: transparent;
  --tg-table-striped-bg: var(--ui-table-striped, #f8fafc);
  --tg-milkdown-bg: var(--ui-surface, #ffffff);
  --tg-milkdown-text: var(--ui-text, #0f172a);
  --tg-codemirror-bg: var(--ui-surface, #ffffff);
  --tg-codemirror-text: var(--ui-text, #0f172a);
  --tg-maestro-panel-bg: var(--ui-bg, #f8fafc);
  --tg-maestro-panel-text: var(--ui-text, #0f172a);
  --tg-tag-chip-bg: #e2e8f0;
  --tg-tag-chip-text: #0f172a;
}

[data-bs-theme="dark"], .dark-mode, [data-theme="dark"] {
  --tg-bg: var(--ui-bg, #0f1117);
  --tg-bg-secondary: var(--ui-surface-hover, #252836);
  --tg-text: var(--ui-text, #f1f5f9);
  --tg-text-muted: var(--ui-muted, #94a3b8);
  --tg-border: var(--ui-border, #2e303f);
  --tg-card-bg: var(--ui-surface, #1a1d27);
  --tg-input-bg: var(--ui-input-bg, #202330);
  --tg-input-text: var(--ui-text, #f1f5f9);
  --tg-sidebar-bg: var(--ui-sidebar-bg, #0c0d12);
  --tg-sidebar-text: var(--ui-text, #f1f5f9);
  --tg-nav-bg: var(--ui-nav-bg, #1a1d27);
  --tg-nav-text: var(--ui-text, #f1f5f9);
  --tg-modal-bg: var(--ui-surface, #1a1d27);
  --tg-modal-text: var(--ui-text, #f1f5f9);
  --tg-table-bg: transparent;
  --tg-table-striped-bg: var(--ui-table-striped, #202330);
  --tg-milkdown-bg: var(--ui-surface, #1a1d27);
  --tg-milkdown-text: var(--ui-text, #f1f5f9);
  --tg-codemirror-bg: var(--ui-surface, #1a1d27);
  --tg-codemirror-text: var(--ui-text, #f1f5f9);
  --tg-maestro-panel-bg: var(--ui-bg, #0f1117);
  --tg-maestro-panel-text: var(--ui-text, #f1f5f9);
  --tg-tag-chip-bg: #3e4156;
  --tg-tag-chip-text: #f1f5f9;
}

/* 2. Overrides Bootstrap composants en dark mode */
[data-bs-theme="dark"] .card,
.dark-mode .card,
[data-theme="dark"] .card,
[data-theme="dark"] .tagma-card {
  background-color: var(--tg-card-bg) !important;
  color: var(--tg-text) !important;
  border-color: var(--tg-border) !important;
}

[data-bs-theme="dark"] .modal-content,
[data-bs-theme="dark"] .modal-header,
[data-bs-theme="dark"] .modal-body,
[data-bs-theme="dark"] .modal-footer,
.dark-mode .modal-content,
.dark-mode .modal-header,
.dark-mode .modal-body,
.dark-mode .modal-footer,
[data-theme="dark"] .modal-content,
[data-theme="dark"] .modal-header,
[data-theme="dark"] .modal-body,
[data-theme="dark"] .modal-footer {
  background-color: var(--tg-modal-bg) !important;
  color: var(--tg-modal-text) !important;
  border-color: var(--tg-border) !important;
}

[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select,
[data-bs-theme="dark"] select.form-control,
.dark-mode .form-control,
.dark-mode .form-select,
.dark-mode select.form-control,
[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select,
[data-theme="dark"] select.form-control {
  background-color: var(--tg-input-bg) !important;
  color: var(--tg-input-text) !important;
  border-color: var(--tg-border) !important;
}

[data-bs-theme="dark"] .list-group-item,
.dark-mode .list-group-item,
[data-theme="dark"] .list-group-item {
  background-color: var(--tg-card-bg) !important;
  color: var(--tg-text) !important;
  border-color: var(--tg-border) !important;
}

[data-bs-theme="dark"] .dropdown-menu,
.dark-mode .dropdown-menu,
[data-theme="dark"] .dropdown-menu {
  background-color: var(--tg-card-bg) !important;
  color: var(--tg-text) !important;
  border-color: var(--tg-border) !important;
}

[data-bs-theme="dark"] .dropdown-item,
.dark-mode .dropdown-item,
[data-theme="dark"] .dropdown-item {
  color: var(--tg-text) !important;
}
[data-bs-theme="dark"] .dropdown-item:hover,
.dark-mode .dropdown-item:hover,
[data-theme="dark"] .dropdown-item:hover {
  background-color: var(--tg-bg-secondary) !important;
  color: var(--tg-text) !important;
}

[data-bs-theme="dark"] .nav-tabs .nav-link,
.dark-mode .nav-tabs .nav-link,
[data-theme="dark"] .nav-tabs .nav-link {
  color: var(--tg-text-muted) !important;
}
[data-bs-theme="dark"] .nav-tabs .nav-link.active,
.dark-mode .nav-tabs .nav-link.active,
[data-theme="dark"] .nav-tabs .nav-link.active {
  background-color: var(--tg-bg) !important;
  color: var(--tg-text) !important;
  border-color: var(--tg-border) var(--tg-border) var(--tg-bg) !important;
}

[data-bs-theme="dark"] .table,
.dark-mode .table,
[data-theme="dark"] .table {
  color: var(--tg-text) !important;
  background-color: var(--tg-table-bg) !important;
}

/* 3. Milkdown editor dark/light compliance + scrollbar overrides */
.milkdown {
  background-color: var(--tg-milkdown-bg) !important;
  color: var(--tg-milkdown-text) !important;
}
.milkdown .editor {
  background-color: var(--tg-milkdown-bg) !important;
  color: var(--tg-milkdown-text) !important;
  min-height: 200px !important;
  height: auto !important;
  outline: none !important;
}
.milkdown .editor * {
  color: inherit !important;
}
.milkdown-menu {
  background-color: var(--tg-card-bg) !important;
  border-bottom-color: var(--tg-border) !important;
}

[data-bs-theme="dark"] .milkdown ::selection,
.dark-mode .milkdown ::selection,
[data-theme="dark"] .milkdown ::selection {
  background: rgba(79, 152, 163, 0.3) !important;
}

/* 4. Milkdown containers — pas de scrollbar interne */
#allmd-milkdown-editor,
#maestro-milkdown-editor,
[id$="-milkdown-editor"] {
  height: auto !important;
  min-height: 200px;
  max-height: none !important;
  overflow: visible !important;
}

.milkdown,
.milkdown .editor {
  height: auto !important;
  min-height: 200px;
  max-height: none !important;
  overflow: visible !important;
}

/* 5. CodeMirror dark mode */
[data-bs-theme="dark"] .CodeMirror,
.dark-mode .CodeMirror,
[data-theme="dark"] .CodeMirror {
  background: var(--tg-codemirror-bg) !important;
  color: var(--tg-codemirror-text) !important;
}
[data-bs-theme="dark"] .CodeMirror-gutters,
.dark-mode .CodeMirror-gutters,
[data-theme="dark"] .CodeMirror-gutters {
  background: var(--tg-codemirror-bg) !important;
  border-right-color: var(--tg-border) !important;
}

/* 6. Sidebar et panels Maestro */
[data-bs-theme="dark"] .sidebar-col,
.dark-mode .sidebar-col,
[data-theme="dark"] .sidebar-col {
  background-color: var(--tg-sidebar-bg) !important;
  color: var(--tg-sidebar-text) !important;
}

[data-bs-theme="dark"] #allmd-maestro-sidebar,
[data-bs-theme="dark"] #allmd-maestro-main,
[data-bs-theme="dark"] #maestro-editor-pane,
[data-bs-theme="dark"] #allmd-maestro-editor-pane,
[data-bs-theme="dark"] #maestro-sidebar,
[data-bs-theme="dark"] #maestro-app,
.dark-mode #allmd-maestro-sidebar,
.dark-mode #allmd-maestro-main,
.dark-mode #maestro-editor-pane,
.dark-mode #allmd-maestro-editor-pane,
.dark-mode #maestro-sidebar,
.dark-mode #maestro-app,
[data-theme="dark"] #allmd-maestro-sidebar,
[data-theme="dark"] #allmd-maestro-main,
[data-theme="dark"] #maestro-editor-pane,
[data-theme="dark"] #allmd-maestro-editor-pane,
[data-theme="dark"] #maestro-sidebar,
[data-theme="dark"] #maestro-app {
  border-color: var(--tg-border) !important;
}

/* 7. Fix for hardcoded whitespaces or labels in table/alert */
[data-bs-theme="dark"] .alert-info,
[data-bs-theme="dark"] .alert-danger,
[data-bs-theme="dark"] .alert-warning,
.dark-mode .alert-info,
.dark-mode .alert-danger,
.dark-mode .alert-warning,
[data-theme="dark"] .alert-info,
[data-theme="dark"] .alert-danger,
[data-theme="dark"] .alert-warning {
  background-color: var(--tg-bg-secondary) !important;
  color: var(--tg-text) !important;
  border-color: var(--tg-border) !important;
}

/* 8. Project workspace layout — SINGLE SOURCE OF TRUTH (last wins)
   These rules override everything above to guarantee scrollability. */
.project-workspace-row {
  align-items: stretch !important;
  min-height: calc(100vh - 160px) !important;
  overflow-y: visible !important;  /* page scrolls naturally vertically */
  overflow-x: hidden !important;   /* prevent horizontal scroll */
}

/* Sidebar: sticky within viewport — scrolls independently */
.project-workspace-row .sidebar-col {
  height: auto !important;
  max-height: none !important;
  overflow-y: visible !important;
  overflow-x: visible !important;
  position: static !important;
  align-self: flex-start !important; /* don't stretch to content height */
}

/* Content area: auto height — page body scrolls */
.project-workspace-row .content-col {
  height: auto !important;
  min-height: calc(100vh - 160px) !important;
  overflow: visible !important;
}

.project-sidebar {
  position: sticky;
  top: 0;
  max-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  padding-bottom: 2rem;
}

.project-workspace-toolbar {
  min-height: 2rem;
}

/* ── Placeholder panels (history, etc.) ── */
.document-panel__content--placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 767.98px) {
  .project-workspace-row {
    overflow-y: visible !important;
    overflow-x: hidden !important;
  }
  .project-workspace-row .content-col {
    height: auto !important;
    min-height: calc(100vh - 120px) !important;
    overflow: visible !important;
  }

  .project-workspace-row .sidebar-col {
    max-height: 50vh !important;
    overflow-y: auto !important;
    position: fixed !important;  /* bottom sheet on mobile */
  }

  .project-sidebar {
    max-height: none;
  }
}

/* 9. Body styling */
body {
  background-color: var(--tg-bg);
  color: var(--tg-text);
}


/* --- NEW SCROLLBAR FIXES --- */
/* Force document panels to expand naturally */
#document-version-panel-html,
.document-panel__content:not(#document-version-panel-pdf) {
    height: auto !important;
    overflow: visible !important;
}

#document-version-panel-pdf {
    height: calc(100vh - 160px) !important;
    overflow: hidden !important;
}

/* Ensure editor containers do not clip content */
.document-editor-container {
    overflow: visible !important;
    height: auto !important;
}

/* Remove sidebar height restrictions */
.project-sidebar {
    max-height: none !important;
    overflow-y: visible !important;
}


/* ---------------------------------------------------------------------------
   Cases & attribute values
   --------------------------------------------------------------------------- */

.cases-tree .case-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.25rem;
}

.cases-tree .case-item.case-current {
  background-color: var(--ui-active-bg);
}

.case-swatch {
  flex: 0 0 auto;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 0.2rem;
  display: inline-block;
}

.cases-tree .case-name {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cases-tree .case-item.case-current .case-name {
  font-weight: bold;
}

/* Case coverage in the document: distinct vertical borders on the left */
#document-view .case-covered {
  padding-left: 0.35rem;
}

/* Spreadsheet grid */
.cases-matrix-wrapper {
  max-height: 55vh;
  overflow: auto;
}

.cases-matrix {
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}

.cases-matrix thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background-color: var(--ui-surface, #fff);
  white-space: nowrap;
  vertical-align: middle;
}

.cases-matrix tbody th,
.cases-matrix tbody td:first-child {
  white-space: nowrap;
}

.cases-matrix .attribute-cell {
  min-width: 7rem;
  cursor: cell;
}

.cases-matrix .attribute-cell:focus {
  outline: 2px solid var(--ui-accent-strong, #0d6efd);
  outline-offset: -2px;
}

.cases-matrix .attribute-cell-saving {
  opacity: 0.5;
}

.cases-matrix .attribute-cell-saved {
  background-color: rgba(25, 135, 84, 0.16);
  transition: background-color 1s ease-out;
}

.cases-matrix .attribute-cell input,
.cases-matrix .attribute-cell select {
  width: 100%;
  box-sizing: border-box;
  font-size: 0.85rem;
  padding: 0.1rem 0.25rem;
}

/* Cross-tabulation */
.crosstab-table {
  font-size: 0.85rem;
}

.crosstab-table th {
  white-space: nowrap;
}

.crosstab-table td {
  text-align: right;
}

.vega-chart {
  min-height: 2rem;
  overflow-x: auto;
}

[data-theme="dark"] .cases-matrix thead th {
  background-color: var(--ui-surface, #23272b);
}
