/* ============================================================
   KASHAF — Modern Design System
   ============================================================ */

/* ---------- Design Tokens ---------- */
:root {
  /* Palette — dark mode first */
  --bg-primary: #0f1219;
  --bg-secondary: #161b26;
  --bg-elevated: #1c2333;
  --bg-glass: rgba(22, 27, 38, 0.72);
  --bg-glass-lighter: rgba(30, 38, 55, 0.65);

  --text-primary: #e8ecf4;
  --text-secondary: #9ba3b5;
  --text-muted: #5c6478;
  --text-accent: #64d8cb;

  --accent: #64d8cb;
  --accent-hover: #8ae8de;
  --accent-glow: rgba(100, 216, 203, 0.25);
  --accent-blue: #5b8ef5;
  --accent-blue-glow: rgba(91, 142, 245, 0.2);

  --border: rgba(255, 255, 255, 0.06);
  --border-focus: rgba(100, 216, 203, 0.5);

  --danger: #f06868;
  --warning: #f0b868;
  --success: #64d88a;

  /* Typography */
  --font-latin: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-arabic: 'Noto Sans Arabic', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;

  /* Sizing */
  --sidebar-w: 68px;
  --panel-w: 500px;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-pill: 100px;

  /* Effects */
  --blur: 18px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.18);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.28);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.38);
  --transition: 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Light mode overrides */
.light-mode {
  --bg-primary: #f4f6fa;
  --bg-secondary: #ffffff;
  --bg-elevated: #ffffff;
  --bg-glass: rgba(255, 255, 255, 0.78);
  --bg-glass-lighter: rgba(255, 255, 255, 0.60);

  --text-primary: #1a1e2c;
  --text-secondary: #555e72;
  --text-muted: #8c95a8;
  --text-accent: #0d8a7d;

  --accent: #0d8a7d;
  --accent-hover: #0fa48e;
  --accent-glow: rgba(13, 138, 125, 0.15);
  --accent-blue: #3b6fd8;
  --accent-blue-glow: rgba(59, 111, 216, 0.12);

  --border: rgba(0, 0, 0, 0.07);
  --border-focus: rgba(13, 138, 125, 0.5);

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.10);
}

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

html {
  height: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  height: 100%;
  font-family: var(--font-latin);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-primary);
  overflow-x: auto;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.25;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition);
}
a:hover {
  color: var(--accent-hover) !important;
}

/* ---------- @font-face ---------- */
/* Removed UthmanTN, using Noto Sans Arabic exclusively */

/* ---------- Sidebar (Icon Rail) ---------- */
#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 20px;
  z-index: 900;
  transition: var(--transition);
}

#sidebar .sidebar-brand {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 40px;
  letter-spacing: 1px;
}

#sidebar ul {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
}

#sidebar ul li {
  width: 100%;
}

#sidebar ul li a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 4px;
  color: var(--text-secondary);
  font-size: 10px;
  letter-spacing: 0.3px;
  text-align: center;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  cursor: pointer;
  text-decoration: none;
  position: relative;
}

#sidebar ul li a::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 0;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
  transition: height var(--transition);
}

#sidebar ul li a:hover {
  color: var(--text-primary) !important;
  background: var(--bg-glass-lighter);
}

#sidebar ul li a:hover::before {
  height: 24px;
}

#sidebar ul li a .nav-icon {
  font-size: 20px;
  transition: transform var(--transition);
}

#sidebar ul li a:hover .nav-icon {
  transform: scale(1.15);
}

#sidebar ul li a span.fa,
#sidebar ul li a span.fas {
  font-size: 18px;
  margin: 0;
  display: block;
}

/* Hide the hamburger icon on wider screens, keep on mobile */
#sidebar .icon {
  display: none;
}

/* ---------- Slide-out Panels (Search, Settings, Nav) ---------- */
.sidenav,
.sidesearch {
  position: fixed;
  top: 0;
  left: var(--sidebar-w);
  width: 0;
  height: 100vh;
  background: var(--bg-glass);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border-right: 1px solid var(--border);
  overflow-x: hidden;
  overflow-y: auto;
  z-index: 800;
  transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  padding: 0;
  color: var(--text-primary);
}

.sidenav.open,
.sidesearch.open {
  width: var(--panel-w);
}

.sidenav .panel-inner,
.sidesearch .panel-inner {
  padding: 28px 24px;
  opacity: 0;
  transform: translateX(-10px);
  transition: opacity 0.3s 0.1s, transform 0.3s 0.1s;
}

.sidenav.open .panel-inner,
.sidesearch.open .panel-inner {
  opacity: 1;
  transform: translateX(0);
}

/* Panel header */
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}

.panel-header h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 10px;
}

.panel-header h3 .fa,
.panel-header h3 .fas {
  color: var(--accent);
  font-size: 16px;
}

/* Close button */
.closebtn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 20px;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  line-height: 1;
}
.closebtn:hover {
  background: var(--danger);
  color: white !important;
  border-color: transparent;
}

/* ---------- Form Controls ---------- */
.form-group {
  margin-bottom: 20px;
}

.form-group label,
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  word-wrap: break-word;
  white-space: normal;
}

.form-control {
  width: 100%;
  padding: 10px 14px;
  font-size: 14px;
  font-family: var(--font-arabic);
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: var(--transition);
}

.form-control:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-control::placeholder {
  color: var(--text-muted);
}

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239ba3b5' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

select.form-control option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* Multi-select (bootstrap-select override) */
.bootstrap-select {
  width: 100% !important;
}

.bootstrap-select .dropdown-toggle {
  background: var(--bg-elevated) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-sm) !important;
  box-shadow: none !important;
  transition: var(--transition);
  padding: 10px 14px !important;
  font-size: 14px;
  display: block !important;
  text-align: left;
}

.bootstrap-select .dropdown-toggle .filter-option {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.bootstrap-select .dropdown-toggle:focus {
  border-color: var(--border-focus) !important;
  box-shadow: 0 0 0 3px var(--accent-glow) !important;
}

.bootstrap-select .dropdown-menu {
  background: var(--bg-elevated) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-sm) !important;
}

.bootstrap-select .dropdown-menu li a {
  color: var(--text-primary) !important;
}

.bootstrap-select .dropdown-menu li a:hover,
.bootstrap-select .dropdown-menu li.active a {
  background: var(--accent-glow) !important;
  color: var(--accent) !important;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 22px;
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font-latin);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  line-height: 1.4;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-blue));
  color: #0f1219;
  font-weight: 600;
  box-shadow: 0 2px 12px var(--accent-glow);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

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

.btn-secondary:hover {
  border-color: var(--text-muted);
  background: var(--bg-glass-lighter);
}

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

.btn-outline:hover {
  background: var(--accent-glow);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 12px;
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
}

/* ---------- Toggle Switch ---------- */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

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

.switchSlider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--bg-elevated);
  border: 1px solid var(--border);
  transition: var(--transition);
}

.switchSlider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 2px;
  bottom: 2px;
  background-color: var(--text-muted);
  transition: var(--transition);
}

input:checked + .switchSlider {
  background-color: var(--accent);
  border-color: var(--accent);
}

input:checked + .switchSlider:before {
  background: white;
  transform: translateX(20px);
}

input:focus + .switchSlider {
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.switchSlider.round {
  border-radius: 24px;
}

.switchSlider.round:before {
  border-radius: 50%;
}

/* Toggle row */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.toggle-row:last-child {
  border-bottom: none;
}

.toggle-label {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.toggle-label small {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-arabic);
  margin-top: 2px;
}

.main-content {
  position: relative;
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  padding: 32px 40px;
  transition: var(--transition);
}

/* ---------- Header ---------- */
#header {
  text-align: center;
  margin-bottom: 24px;
  animation: fadeInDown 0.6s ease-out;
}

@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-18px); }
  to { opacity: 1; transform: translateY(0); }
}

#header h1 {
  font-size: 28px;
  font-weight: 700;
  color: #ffffff;
  margin-bottom: 8px;
}

#header h2 {
  font-size: 14px;
  font-weight: 400;
  color: var(--text-secondary);
  font-family: var(--font-arabic);
}

/* ---------- Legend ---------- */
.my-legend {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-glass);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  margin-bottom: 20px;
  animation: fadeIn 0.5s ease-out 0.2s both;
}

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

.my-legend .legend-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.my-legend .legend-scale ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  width: 100%;
}

.my-legend .legend-scale ul:first-child {
  margin-bottom: 8px;
}

.my-legend .legend-scale ul:first-child li {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  flex: 0 0 auto;
}

.my-legend .legend-scale ul li {
  display: inline-flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 11px;
  color: var(--text-secondary);
  white-space: normal;
  line-height: 1.4;
  margin-top: 2px;
}

.my-legend ul.legend-labels li span.color-circle {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: var(--radius-pill);
  flex-shrink: 0;
  margin-top: 1px;
}

#gradeTooltip {
  visibility: hidden;
  width: 100%;
  background: var(--bg-glass) !important;
  backdrop-filter: blur(var(--blur));
  color: var(--text-primary) !important;
  border-radius: var(--radius-sm) !important;
  border: 1px solid var(--border);
  text-align: center;
  padding: 8px 12px;
  direction: rtl;
  font-family: var(--font-arabic);
  font-size: 13px;
  margin-top: 8px;
  z-index: 10;
  transition: visibility 0.2s;
}

/* ---------- Result Table ---------- */
#resultTable {
  max-height: 300px;
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin: 12px 0;
  font-size: 14px;
  animation: fadeIn 0.4s ease-out;
}

#resultTable table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

#resultTable thead {
  position: sticky;
  top: 0;
  z-index: 2;
}

#resultTable th {
  padding: 12px 16px;
  text-align: right;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

#resultTable td {
  padding: 12px 16px;
  text-align: right;
  color: var(--text-primary);
  font-family: var(--font-arabic);
  font-size: 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}

#resultTable tr:hover td {
  background: var(--accent-glow);
}

#resultTable h6 {
  font-family: var(--font-arabic);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 4px;
}

/* Scrollbar styling for result table */
#resultTable::-webkit-scrollbar {
  width: 6px;
}

#resultTable::-webkit-scrollbar-track {
  background: transparent;
}

#resultTable::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 3px;
}

/* ---------- Tree / Diagram Container ---------- */
#tree-container {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  min-height: 300px;
  margin: 20px 0;
  overflow: auto;
  position: relative;
  animation: fadeIn 0.5s ease-out 0.3s both;
}

#tree-container .mermaid {
  display: flex;
  justify-content: center;
}

/* Mermaid SVG theming */
#tree-container svg {
  max-width: 100%;
}

/* ---------- Mermaid Code Export Panel ---------- */
.code-export-panel {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  animation: fadeIn 0.4s ease-out 0.4s both;
}

.code-export-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
}

.code-export-header:hover {
  background: var(--bg-glass-lighter);
}

.code-export-header h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.code-export-header .chevron {
  transition: transform var(--transition);
  color: var(--text-muted);
  font-size: 12px;
}

.code-export-panel.open .code-export-header .chevron {
  transform: rotate(180deg);
}

.code-export-body {
  display: none;
  padding: 16px;
  background: var(--bg-secondary);
}

.code-export-panel.open .code-export-body {
  display: block;
}

.code-export-body textarea {
  width: 100%;
  min-height: 200px;
  padding: 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  resize: vertical;
  outline: none;
  transition: var(--transition);
  direction: ltr;
  text-align: left;
}

.code-export-body textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.code-export-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.copy-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--accent);
  color: var(--bg-primary);
  padding: 10px 20px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s ease;
  z-index: 9999;
  pointer-events: none;
}

.copy-toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* ---------- Tooltip (Hadith detail card) ---------- */
.google-visualization-tooltip,
.hadith-tooltip {
  visibility: visible !important;
  width: 560px !important;
  max-height: 320px !important;
  overflow-y: auto;
  background: var(--bg-elevated) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-lg) !important;
  font-size: 14px !important;
  padding: 16px !important;
  z-index: 100;
  color: var(--text-primary) !important;
}

.google-visualization-tooltip th {
  font-size: 0.8em;
}

/* ---------- Bottom Card (MMA panel) ---------- */
#card {
  position: fixed;
  bottom: 24px;
  right: 5%;
  width: 90%;
  height: 200px;
  resize: vertical;
  overflow: scroll;
  z-index: 30;
  background: var(--bg-glass);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  transform: rotateZ(180deg);
  padding: 0 8px 8px 0;
}

#rsz {
  transform: rotateZ(180deg);
  width: 100%;
  height: 100%;
  overflow: auto;
}

#rsz th, #rsz td {
  padding: 5px;
  color: inherit;
  background: inherit;
}

#rsz th {
  position: sticky;
  top: 0;
  border-radius: 0px !important;
}

#card tr:hover {
  background-color: var(--accent-glow) !important;
}

#card tr {
  background-color: transparent !important;
}

/* ---------- Footer ---------- */
footer {
  text-align: center;
  padding: 20px 16px;
  margin-left: var(--sidebar-w);
  font-size: 12px;
  color: var(--text-muted);
}

footer a {
  color: var(--accent);
}

/* ---------- Spinner ---------- */
.spinner-border-sm {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}

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

/* ---------- Status / Message Labels ---------- */
#btnMessage {
  font-size: 13px;
  color: var(--text-secondary);
}

#pattern-error,
#data-error {
  font-size: 13px;
  color: var(--warning);
}

/* ---------- SVG text (for any remaining SVGs) ---------- */
text {
  font-size: 0.85rem;
  fill: var(--text-primary);
  z-index: 100;
}

/* ---------- Button Group in Panels ---------- */
.panel-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

/* ---------- Autocomplete ---------- */
.autocomplete {
  position: relative;
}

.autocomplete-items {
  position: absolute;
  border: 1px solid var(--border);
  z-index: 99;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 200px;
  overflow-y: auto;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

.autocomplete-items div {
  padding: 10px 14px;
  cursor: pointer;
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
  font-family: var(--font-arabic);
  font-size: 14px;
  transition: background var(--transition);
}

.autocomplete-items div:hover {
  background: var(--accent-glow);
}

.autocomplete-active {
  background: var(--accent) !important;
  color: var(--bg-primary) !important;
}

/* ---------- Responsive ---------- */
@media screen and (max-width: 768px) {
  #sidebar {
    width: 0;
    overflow: hidden;
  }

  #sidebar.mobile-open {
    width: var(--sidebar-w);
  }

  .main-content {
    margin-left: 0;
    padding: 20px 16px;
  }

  footer {
    margin-left: 0;
  }

  .sidenav,
  .sidesearch {
    left: 0;
  }

  .my-legend .legend-scale ul li {
    font-size: 10px;
  }

  #header h1 {
    font-size: 22px;
  }

  .mobile-menu-btn {
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 950;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-glass);
    backdrop-filter: blur(var(--blur));
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    font-size: 18px;
    cursor: pointer;
  }
}

@media screen and (min-width: 769px) {
  .mobile-menu-btn {
    display: none;
  }
}

/* ---------- Mermaid Diagram Enhancements ---------- */
.mermaid .node rect,
.mermaid .node circle,
.mermaid .node ellipse,
.mermaid .node polygon {
  stroke: var(--border) !important;
}

.mermaid .edgePath .path {
  stroke: var(--text-muted) !important;
  stroke-width: 1.5px;
}

.mermaid .edgeLabel {
  background: var(--bg-secondary) !important;
  color: var(--text-secondary) !important;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
}

/* ---------- Empty State ---------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  color: var(--text-muted);
  font-size: 14px;
  gap: 12px;
}

.empty-state .empty-icon {
  font-size: 48px;
  opacity: 0.3;
}

/* ---------- Link special styles ---------- */
.btn-primary-outline {
  background-color: transparent;
  border-color: transparent;
  color: var(--text-secondary);
  padding: 8px 14px;
  font-size: 13px;
}

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

/* ---------- Utility ---------- */
.text-center { text-align: center; }
.justify-content-center { display: flex; justify-content: center; }
.mb-5 { margin-bottom: 3rem !important; }
.mx-3 { margin-left: 1rem; margin-right: 1rem; }
.px-2 { padding-left: 0.5rem; padding-right: 0.5rem; }
.pt-2 { padding-top: 0.5rem; }
.row { display: flex; flex-wrap: wrap; width: 100%; }

/* Dropdown toggle general fix */
.dropdown-toggle {
  background-color: var(--bg-elevated) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border) !important;
}

/* Language Toggle Visibility */
body.lang-ar .lang-texten {
  display: none !important;
}
body.lang-ar .lang-textar {
  display: inline !important;
}
body:not(.lang-ar) .lang-textar {
  display: none !important;
}
body:not(.lang-ar) .lang-texten {
  display: inline !important;
}

/* ---------- 2026 Monochrome Refresh ---------- */
:root,
.light-mode {
  --bg-primary: #000000;
  --bg-secondary: #000000;
  --bg-elevated: #000000;
  --bg-glass: #000000;
  --bg-glass-lighter: #050505;
  --text-primary: #ffffff;
  --text-secondary: #d5d5d5;
  --text-muted: #9a9a9a;
  --text-accent: #ffffff;
  --accent: #ffffff;
  --accent-hover: #ffffff;
  --accent-glow: rgba(255, 255, 255, 0.1);
  --border: rgba(255, 255, 255, 0.45);
  --border-focus: rgba(255, 255, 255, 0.8);
  --radius-sm: 0;
  --radius-md: 0;
  --radius-lg: 0;
  --radius-pill: 0;
}

body,
#screen,
.main-content,
#header,
#tree-container,
.code-export-panel,
.code-export-body,
.sidesearch,
#sidebar,
footer {
  background: #000 !important;
  color: #fff;
}

#sidebar ul li a:hover,
.code-export-header:hover,
#resultTable tr:hover td,
.autocomplete-items div:hover {
  background: #0d0d0d !important;
}

.btn,
.form-control,
.dropdown-toggle,
.closebtn,
#tree-container,
.code-export-panel,
.code-export-body textarea,
.switchSlider,
#resultTable,
.my-legend,
#matn-analysis-panel,
.collector-analysis,
.matn-variant,
.pec-chip,
.matn-pill,
.autocomplete-items,
.autocomplete-items div {
  border-radius: 0 !important;
}

.btn {
  background: #000 !important;
  color: #fff !important;
  border: 1px solid rgba(255, 255, 255, 0.65) !important;
}

.btn:hover {
  background: #111 !important;
}

#tree-container {
  border: 1px solid rgba(255, 255, 255, 0.65) !important;
}

#tree-container svg {
  user-select: none;
}

.analysis-panel {
  margin-top: 14px;
  border: 1px solid rgba(255, 255, 255, 0.65);
  background: #000;
}

.analysis-panel-header {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.35);
}

.analysis-panel-header h3 {
  font-size: 15px;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.analysis-panel-body {
  padding: 14px 16px;
  max-height: 360px;
  overflow: auto;
}

.analysis-empty {
  margin: 0;
  color: #bbb;
}

.collector-analysis {
  border: 1px solid rgba(255, 255, 255, 0.25);
  padding: 10px;
  margin-bottom: 10px;
}

.collector-analysis h4 {
  margin: 0 0 8px 0;
  font-size: 13px;
  color: #fff;
}

.matn-variant {
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 8px;
  margin-bottom: 8px;
}

.matn-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.matn-pill,
.pec-chip {
  display: inline-block;
  border: 1px solid;
  padding: 2px 6px;
  font-size: 11px;
}

.matn-meta-count {
  font-size: 11px;
  color: #bbb;
}

.peculiarities {
  margin-bottom: 6px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.matn-text {
  margin: 0;
  line-height: 1.9;
  color: #eee;
}

.matn-token {
  border: 1px solid;
  padding: 1px 3px;
}

/* ---------- RIWAYA Layout Refinements ---------- */
:root {
  --font-display: 'EB Garamond', serif;
}

#header .brand-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 44px;
  letter-spacing: 0.3px;
  margin: 0 0 6px 0;
}

#header .brand-subtitle {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 20px;
  color: #d0d0d0;
  margin: 0 0 8px 0;
}

#tree-container {
  height: 560px;
  min-height: 320px;
  resize: vertical;
  overflow: auto;
}

.analysis-panel {
  height: 320px;
  min-height: 220px;
  resize: vertical;
  overflow: auto;
}

.analysis-panel-body {
  max-height: none;
}

#gradeTooltip {
  margin-bottom: 8px;
}

.floating-legend {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 320px;
  max-width: calc(100% - 24px);
  z-index: 15;
  border: 1px solid rgba(255, 255, 255, 0.65);
  background: rgba(0, 0, 0, 0.92);
}

.floating-legend-toggle {
  width: 100%;
  background: #000;
  color: #fff;
  border: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.3);
  text-align: left;
  padding: 8px 10px;
  font-size: 13px;
  cursor: pointer;
}

.floating-legend-body {
  max-height: 280px;
  overflow: auto;
  padding: 8px 10px;
}

.floating-legend.collapsed .floating-legend-body {
  display: none;
}

.floating-legend .legend-labels {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.floating-legend .legend-labels li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: #d8d8d8;
}

.floating-legend .color-circle {
  width: 12px;
  height: 12px;
  display: inline-block;
  border-radius: 0;
  flex-shrink: 0;
}

@media screen and (max-width: 768px) {
  #header .brand-title {
    font-size: 34px;
  }

  #header .brand-subtitle {
    font-size: 18px;
  }

  .floating-legend {
    width: calc(100% - 24px);
  }
}
