/* ===== Masthead Layout ===== */
/* Masthead menu: flex layout so greedy-nav + utility buttons sit side by side */
.masthead__menu {
  display: flex;
  align-items: center;
}

.masthead__menu .greedy-nav {
  flex: 1;
  min-width: 0; /* allow shrinking */
}

/* Center navigation links */
.greedy-nav .visible-links {
  text-align: center;
}

/* ===== Masthead Utility Buttons (dark mode + language) ===== */
.masthead-utils {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  margin-left: 8px;
  position: relative;
  z-index: 15;
}

.masthead-util-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 18px;
  padding: 4px 6px;
  border-radius: 4px;
  color: #555;
  line-height: 1;
  transition: background 0.2s ease, color 0.2s ease;
}

.masthead-util-btn:hover {
  background: #f0f0f0;
  color: #333;
}

/* Sun/Moon toggle icons */
.dm-icon { font-size: 18px; line-height: 1; }
.dm-moon { display: none; }
body.dark-mode .dm-sun { display: none; }
body.dark-mode .dm-moon { display: inline; }

body.dark-mode .masthead-util-btn {
  color: #ccc;
}
body.dark-mode .masthead-util-btn:hover {
  background: #2a2a44;
  color: #fff;
}

/* ===== Language Dropdown ===== */
.lang-dropdown {
  position: relative;
}

.lang-dropdown-btn {
  gap: 2px;
}

.lang-dropdown-btn .fa-globe {
  font-size: 15px;
}

.lang-dropdown-arrow {
  font-size: 10px;
  margin-left: 1px;
}

.lang-dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  padding-top: 6px;
  background: transparent;
  z-index: 100;
}

.lang-dropdown-menu-inner {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  min-width: 140px;
  padding: 4px 0;
  max-height: 360px;
  overflow-y: auto;
}

.lang-dropdown:hover .lang-dropdown-menu,
.lang-dropdown.open .lang-dropdown-menu {
  display: block;
}

.lang-dropdown-item {
  display: block;
  padding: 6px 16px;
  font-size: 13px;
  color: #555;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s ease;
}

a.lang-dropdown-item:hover {
  background: #f5f5f5;
  color: #333;
}

.lang-dropdown-current {
  font-weight: 600;
  color: #0f4d92;
  cursor: default;
}

body.dark-mode .lang-dropdown-menu-inner {
  background: #20203a;
  border-color: #3a3a54;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

body.dark-mode .lang-dropdown-item {
  color: #b0b0c0;
}

body.dark-mode a.lang-dropdown-item:hover {
  background: #2a2a44;
  color: #e8e8f0;
}

body.dark-mode .lang-dropdown-current {
  color: #6eaadc;
}

/* On mobile, keep utils compact */
@media screen and (max-width: 924px) {
  .masthead-utils {
    margin-left: 4px;
  }
}

/* ===== Dark Mode Overrides ===== */
body.dark-mode {
  background-color: #1a1a2e;
  color: #d4d4dc;
}

body.dark-mode #main {
  color: #d4d4dc;
}

body.dark-mode h1,
body.dark-mode h2,
body.dark-mode h3,
body.dark-mode h4,
body.dark-mode h5,
body.dark-mode h6 {
  color: #e8e8f0;
}

body.dark-mode a {
  color: #6eaadc;
}
body.dark-mode a:hover {
  color: #8ec4f0;
}

/* Masthead / top navigation */
body.dark-mode .masthead {
  background-color: #16162a;
  border-bottom-color: #2a2a44;
}
body.dark-mode .greedy-nav {
  background: #16162a;
}
body.dark-mode .greedy-nav .hidden-links {
  background: #20203a;
  border-color: #2a2a44;
}
body.dark-mode .greedy-nav .hidden-links a:hover {
  background: #25254a;
}
body.dark-mode .masthead a,
body.dark-mode .greedy-nav a {
  color: #d4d4dc;
}
body.dark-mode .greedy-nav .visible-links a:before {
  background: #6eaadc;
}

/* Sidebar */
body.dark-mode .sidebar {
  color: #d4d4dc;
}
body.dark-mode .sidebar .author__name a {
  color: #e8e8f0;
}
body.dark-mode .author__bio {
  color: #b0b0c0;
}
body.dark-mode .author__urls a {
  color: #b0b0c0;
}
body.dark-mode .author__urls a:hover {
  color: #6eaadc;
}
body.dark-mode .author__avatar img {
  border-color: #3a3a54;
}

/* Book widget in sidebar */
body.dark-mode .widget {
  background-color: #20203a;
  border-color: #2a2a44;
  box-shadow: 0 0 10px rgba(0,0,0,0.2);
}

/* Page content */
body.dark-mode .page__content {
  color: #d4d4dc;
}

/* Footer */
body.dark-mode .page__footer {
  background-color: #12122a;
  border-top-color: #2a2a44;
  color: #888;
}
body.dark-mode .page__footer a {
  color: #6eaadc;
}

/* Tables */
body.dark-mode table {
  color: #d4d4dc;
}
body.dark-mode table th {
  background-color: #20203a;
  color: #e8e8f0;
}
body.dark-mode table td {
  border-color: #2a2a44;
}
body.dark-mode table tr:nth-child(even) {
  background-color: #1e1e36;
}
body.dark-mode table tr:hover {
  background-color: #25254a;
}

/* Accordion styles (publications & about) */
body.dark-mode .pub-accordion details,
body.dark-mode .article-accordion details {
  background: #20203a;
  border-color: #2a2a44;
}
body.dark-mode .pub-accordion details[open],
body.dark-mode .article-accordion details[open] {
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
body.dark-mode .pub-accordion summary:hover,
body.dark-mode .article-accordion summary:hover {
  background: #25254a;
}
body.dark-mode .pub-citation,
body.dark-mode .article-citation {
  color: #d4d4dc;
}
body.dark-mode .pub-citation a,
body.dark-mode .article-citation a {
  color: #6eaadc;
}
body.dark-mode .pub-body,
body.dark-mode .article-body {
  border-top-color: #2a2a44;
}
body.dark-mode .pub-abstract,
body.dark-mode .abstract-text {
  color: #b0b0c0;
}
body.dark-mode .pub-resources a {
  background: #2a2a44;
  border-color: #3a3a54;
  color: #b0b0c0;
}
body.dark-mode .pub-resources a:hover {
  border-color: #6eaadc;
  color: #6eaadc;
  background: #1e2a3e;
}
body.dark-mode .pub-mentions {
  border-top-color: #2a2a44;
}
body.dark-mode .pub-mentions a {
  color: #6eaadc;
}
body.dark-mode .pub-mentions span {
  color: #888;
}

/* Newsletter cards */
body.dark-mode .newsletter-card {
  background: #20203a;
  border-color: #2a2a44;
}
body.dark-mode .newsletter-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
body.dark-mode .newsletter-card-title {
  color: #e8e8f0;
}
body.dark-mode .newsletter-card a:hover .newsletter-card-title {
  color: #6eaadc;
}
body.dark-mode .newsletter-card-subtitle {
  color: #b0b0c0;
}
body.dark-mode .newsletter-card-date {
  color: #999;
}
body.dark-mode .newsletter-card-img {
  border-bottom-color: #2a2a44;
}

/* Blockquotes (editorial reviews on book page) */
body.dark-mode blockquote,
body.dark-mode .book-review {
  border-left-color: #3a5a8a;
  background-color: #1e1e36;
  color: #b0b0c0;
}

/* Code blocks */
body.dark-mode code {
  background-color: #2a2a44;
  color: #d4d4dc;
}
body.dark-mode pre {
  background-color: #1e1e36;
}

body.dark-mode hr {
  border-color: #2a2a44;
}

body.dark-mode ::selection {
  background: #3a5a8a;
  color: #fff;
}

/* Follow button dark mode */
body.dark-mode .btn--inverse {
  background-color: #2a2a44;
  color: #ccc !important;
  border-color: #3a3a54 !important;
}
body.dark-mode .btn--inverse:hover {
  background-color: #3a3a54;
  color: #fff !important;
  border-color: #555 !important;
}

/* Author URLs dropdown dark mode (mobile) */
body.dark-mode .author__urls {
  background: #20203a;
  border-color: #2a2a44;
  box-shadow: 0 0 10px rgba(0,0,0,0.4);
}

/* Hide book widget on mobile (below 925px / $large) */
@media screen and (max-width: 924px) {
  .widget {
    display: none;
  }
}

/* Book events table mobile fix */
@media screen and (max-width: 700px) {
  .event-list {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .event-list table {
    min-width: 500px;
  }
}

/* Make #main the positioning context for the events sidebar */
#main {
  position: relative;
}

/* Reserve space for events sidebar on desktop */
@media screen and (min-width: 925px) {
  .archive,
  .page {
    padding-right: 220px !important;
  }
}

/* ===== Events Sidebar ===== */
.events-sidebar {
  position: absolute;
  top: 0;
  right: 0;
  width: 190px;
  padding: 14px 16px;
  background: #f9f9fa;
  border: 1px solid #e8e8e8;
  border-radius: 6px;
  font-size: 9.5pt;
}

.events-sidebar-title {
  font-weight: 700;
  font-size: 8.5pt;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #555;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid #0f4d92;
}

.event-item {
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid #eee;
  line-height: 1.4;
}

.event-item:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.event-date {
  display: block;
  font-weight: 600;
  color: #0f4d92;
  font-size: 9pt;
}

.event-name {
  display: block;
  color: #333;
  font-weight: 500;
}

.event-location {
  display: block;
  color: #888;
  font-size: 8.5pt;
}

body.dark-mode .events-sidebar {
  background: #20203a;
  border-color: #2a2a44;
}

body.dark-mode .events-sidebar-title {
  color: #aaa;
  border-bottom-color: #6eaadc;
}

body.dark-mode .event-date {
  color: #6eaadc;
}

body.dark-mode .event-name {
  color: #d4d4dc;
}

body.dark-mode .event-location {
  color: #888;
}

body.dark-mode .event-item {
  border-bottom-color: #2a2a44;
}

@media screen and (max-width: 924px) {
  .events-sidebar {
    position: static;
    width: 100%;
    margin: 0 0 20px 0;
  }

  .events-sidebar-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .event-item {
    flex: 1 1 45%;
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
    padding: 8px;
    background: #fff;
    border: 1px solid #eee;
    border-radius: 4px;
  }

  body.dark-mode .event-item {
    background: #1e1e36;
    border-color: #2a2a44;
  }
}

/* ===== Arabic RTL Support ===== */

/* Flip sidebar to the right side for RTL */
@media (min-width: 64em) {
  html[dir="rtl"] .sidebar {
    float: right;
    margin-left: 0;
    margin-right: 0;
  }
  html[dir="rtl"] .archive,
  html[dir="rtl"] .page {
    float: left;
    margin-left: 0;
    margin-right: 0;
  }
  html[dir="rtl"] #main {
    direction: rtl;
  }
}

html[dir="rtl"] .masthead__menu {
  direction: rtl;
}
html[dir="rtl"] .greedy-nav .visible-links {
  direction: rtl;
}
html[dir="rtl"] .masthead-utils {
  margin-left: 0;
  margin-right: 8px;
}
html[dir="rtl"] .author__avatar,
html[dir="rtl"] .author__content,
html[dir="rtl"] .author__urls-wrapper {
  text-align: right;
}
html[dir="rtl"] .author__urls li {
  text-align: right;
}
html[dir="rtl"] .author__urls a {
  padding-right: 0;
  padding-left: 5px;
}
html[dir="rtl"] .sidebar .book-widget {
  text-align: right;
}
html[dir="rtl"] .page__content {
  direction: rtl;
  text-align: right;
}
html[dir="rtl"] .lang-dropdown-menu {
  right: auto;
  left: 0;
}
html[dir="rtl"] blockquote {
  border-left: none;
  border-right: 4px solid #e8e8e8;
  padding-left: 0;
  padding-right: 1em;
}
html[dir="rtl"] .events-sidebar {
  direction: rtl;
  text-align: right;
  right: auto;
  left: 0;
}
/* RTL about page: use flexbox for proper 3-column layout when events
   sidebar is present (events left, content center, profile right) */
@media (min-width: 64em) {
  html[dir="rtl"] #main:has(.events-sidebar) {
    display: flex;
    align-items: flex-start;
  }
  html[dir="rtl"] #main:has(.events-sidebar) > .sidebar {
    flex-shrink: 0;
    float: none;
  }
  html[dir="rtl"] #main:has(.events-sidebar) > .page {
    flex: 1;
    float: none;
    width: auto;
    min-width: 0;
    margin: 0 0 0 10px;
  }
  html[dir="rtl"] #main:has(.events-sidebar) > .events-sidebar {
    position: relative;
    flex-shrink: 0;
    order: 1;
  }
}

/* RTL fixes for publications */
html[dir="rtl"] .pub-accordion summary {
  text-align: left;
  padding-right: 16px;
  padding-left: 36px;
}
html[dir="rtl"] .pub-accordion .ar-title {
  text-align: right;
}
html[dir="rtl"] .pub-citation {
  direction: ltr;
  unicode-bidi: isolate;
  text-align: left;
}
html[dir="rtl"] .pub-accordion summary::after {
  right: auto;
  left: 16px;
}
html[dir="rtl"] .pub-abstract,
html[dir="rtl"] .abstract-label {
  direction: rtl;
  text-align: right;
}
html[dir="rtl"] .pub-resources {
  direction: ltr;
  text-align: left;
}
html[dir="rtl"] .pub-mentions {
  direction: ltr;
  text-align: left;
}
html[dir="rtl"] .pub-filter-controls {
  text-align: right;
}
html[dir="rtl"] .pub-count {
  text-align: right;
}

/* RTL fixes for media cards */
html[dir="rtl"] .media-card {
  direction: rtl;
}
html[dir="rtl"] .card-title {
  direction: rtl;
  text-align: right;
  font-size: 0;
  -webkit-line-clamp: unset;
  overflow: visible;
  display: block;
}
html[dir="rtl"] .card-title a {
  font-size: 11pt;
  line-height: 1.4;
  display: block;
}
html[dir="rtl"] .card-title a + a {
  font-size: 9pt;
  color: #888;
  direction: ltr;
  unicode-bidi: isolate;
  margin-top: 2px;
}
body.dark-mode html[dir="rtl"] .card-title a + a {
  color: #777;
}
html[dir="rtl"] .card-meta {
  direction: ltr;
  unicode-bidi: isolate;
  text-align: right;
}
html[dir="rtl"] .card-format-tag {
  left: 8px;
  right: auto;
}
html[dir="rtl"] .filter-controls {
  text-align: right;
}

/* RTL fixes for article-accordion on about page */
html[dir="rtl"] .article-accordion .article-citation {
  direction: ltr;
  unicode-bidi: isolate;
}
html[dir="rtl"] .article-accordion summary {
  padding-right: 36px;
  padding-left: 16px;
}
html[dir="rtl"] .article-accordion summary::after {
  right: auto;
  left: 16px;
}
html[dir="rtl"] .article-accordion .article-abstract {
  direction: rtl;
  text-align: right;
}
html[dir="rtl"] .article-accordion .abstract-label {
  direction: rtl;
  text-align: right;
}

/* RTL fixes for book page */
html[dir="rtl"] .book-wrapper {
  float: left;
  margin: 8px 25px 20px 0;
}
html[dir="rtl"] .book-description {
  text-align: right;
}
html[dir="rtl"] .book-links-section {
  text-align: right;
}
html[dir="rtl"] .review-text {
  text-align: right;
  border-left: none;
  padding-left: 0;
  border-right: 3px solid #0f4d92;
  padding-right: 16px;
}
body.dark-mode html[dir="rtl"] .review-text {
  border-right-color: #6eaadc;
}
html[dir="rtl"] .event-list thead th {
  text-align: right;
}
html[dir="rtl"] .event-list thead th:nth-child(2) {
  text-align: center;
}
html[dir="rtl"] .event-list thead th:nth-child(3) {
  text-align: left;
}
html[dir="rtl"] .event-list td:first-child {
  text-align: right;
}
html[dir="rtl"] .event-list td:last-child {
  text-align: left;
}
html[dir="rtl"] .talk-note,
html[dir="rtl"] .excerpt-note,
html[dir="rtl"] .recording-note {
  text-align: right;
}

/* ===== Smooth Transitions ===== */
body, #main, .masthead, .page__footer, .sidebar,
.widget, .pub-accordion details, .article-accordion details,
.newsletter-card, blockquote, code, pre, table, table th, table td,
.btn--inverse, .author__urls, .events-sidebar {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}
