/* =========================================================
   Desktop Floating Action Rail — AlMajd Operational Plan
   Fixed icon rail for desktop; original top actions remain the fallback
   below the desktop breakpoint and for narrow/laptop/mobile layouts.
   ========================================================= */
:root {
  --rail-w: 52px;
  --rail-gap: 6px;
  --rail-left: 14px;
  --rail-z: 760;
}

.almajd-floating-rail,
.almajd-rail-more {
  display: none;
}

@media screen and (min-width: 1280px) {
  body:not([data-exec-presentation="true"]) .almajd-floating-rail {
    position: fixed;
    left: var(--rail-left);
    top: 50%;
    transform: translateY(-50%);
    z-index: var(--rail-z);
    width: var(--rail-w);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--rail-gap);
    padding: 8px 5px;
    border: 1px solid rgba(18, 60, 105, .15);
    border-radius: 18px;
    background: rgba(255,255,255,.92);
    box-shadow: 0 16px 42px rgba(11,37,69,.18);
    backdrop-filter: blur(16px) saturate(1.1);
    -webkit-backdrop-filter: blur(16px) saturate(1.1);
    direction: ltr;
  }

  /* Keep only the page title/meta in the sticky top bar on desktop. */
  .topbar .top-actions { display: none !important; }
  .topbar {
    min-height: 58px;
    justify-content: flex-start;
  }
  .topbar .current-title { margin-inline-start: 6px; }

  .almajd-rail-btn {
    position: relative;
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 12px;
    background: transparent;
    color: #17365f;
    cursor: pointer;
    font: inherit;
    transition: background .16s ease, color .16s ease, border-color .16s ease, transform .16s ease, box-shadow .16s ease;
  }
  .almajd-rail-btn:hover,
  .almajd-rail-btn:focus-visible {
    background: rgba(18,60,105,.08);
    border-color: rgba(18,60,105,.13);
    color: #0b2545;
    transform: translateX(1px);
    outline: none;
  }
  .almajd-rail-btn:focus-visible {
    box-shadow: 0 0 0 3px rgba(212,175,55,.28);
  }
  .almajd-rail-btn svg {
    width: 20px;
    height: 20px;
    display: block;
    pointer-events: none;
  }
  .almajd-rail-btn[aria-pressed="true"],
  .almajd-rail-btn.is-active {
    color: #fff;
    background: linear-gradient(145deg, #0b2545, #174f82);
    border-color: #0b2545;
    box-shadow: 0 8px 18px rgba(11,37,69,.22), inset 0 0 0 1px rgba(255,255,255,.12);
  }
  .almajd-rail-btn[data-action="table"][aria-pressed="true"] {
    background: linear-gradient(145deg, #0f766e, #14b8a6);
    border-color: #0f766e;
  }
  .almajd-rail-btn[data-action="edit"][aria-pressed="true"] {
    background: linear-gradient(145deg, #9a6c06, #d4af37);
    border-color: #9a6c06;
  }
  .almajd-rail-btn.is-unavailable:not([aria-pressed="true"]) {
    opacity: .46;
  }
  .almajd-rail-btn.is-unavailable:not([aria-pressed="true"]):hover { opacity: .72; }

  /* Tooltips open toward the document, not outside the viewport. */
  .almajd-rail-btn::after {
    content: attr(data-label);
    position: absolute;
    left: calc(100% + 11px);
    top: 50%;
    transform: translate(-4px,-50%);
    width: max-content;
    max-width: 210px;
    padding: 7px 10px;
    border-radius: 9px;
    background: #0b2545;
    color: #fff;
    font-size: 11px;
    font-weight: 850;
    line-height: 1.25;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    box-shadow: 0 8px 20px rgba(2,18,38,.18);
    transition: opacity .13s ease, transform .13s ease, visibility .13s ease;
    direction: rtl;
  }
  .almajd-rail-btn:hover::after,
  .almajd-rail-btn:focus-visible::after {
    opacity: 1;
    visibility: visible;
    transform: translate(0,-50%);
  }

  .almajd-rail-sep {
    width: 27px;
    height: 1px;
    flex: 0 0 1px;
    background: rgba(18,60,105,.12);
    margin: 1px 0;
  }

  .almajd-rail-counter {
    width: 40px;
    min-height: 31px;
    display: grid;
    place-items: center;
    padding: 4px 2px;
    border-radius: 11px;
    background: rgba(212,175,55,.12);
    border: 1px solid rgba(212,175,55,.25);
    color: #17365f;
    font-size: 10px;
    font-weight: 950;
    line-height: 1.05;
    direction: ltr;
    user-select: none;
  }
  .almajd-rail-counter b { font-size: 12px; color: #0b2545; }
  .almajd-rail-counter span { color: #7a8797; font-size: 8px; }

  .almajd-rail-more {
    position: fixed;
    left: calc(var(--rail-left) + var(--rail-w) + 10px);
    top: 50%;
    transform: translate(-8px,-50%);
    z-index: calc(var(--rail-z) + 1);
    width: 270px;
    max-height: min(620px, calc(100vh - 36px));
    overflow: auto;
    padding: 11px;
    border-radius: 18px;
    border: 1px solid rgba(18,60,105,.14);
    background: rgba(255,255,255,.97);
    box-shadow: 0 22px 58px rgba(11,37,69,.22);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    direction: rtl;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .16s ease, transform .16s ease, visibility .16s ease;
  }
  .almajd-rail-more.is-open {
    display: block;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translate(0,-50%);
  }
  .almajd-rail-more-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 4px 5px 9px;
    border-bottom: 1px solid rgba(18,60,105,.09);
    margin-bottom: 8px;
  }
  .almajd-rail-more-head b { color: #0b2545; font-size: 13px; }
  .almajd-rail-more-head span { color: #8a98aa; font-size: 9px; font-weight: 850; letter-spacing: .05em; }
  .almajd-rail-more-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }
  .almajd-rail-menu-btn {
    min-height: 43px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 9px;
    border: 1px solid rgba(18,60,105,.10);
    border-radius: 11px;
    background: #f7f9fc;
    color: #17365f;
    cursor: pointer;
    font: inherit;
    font-size: 10px;
    font-weight: 850;
    text-align: right;
    transition: background .14s ease, border-color .14s ease, transform .14s ease;
  }
  .almajd-rail-menu-btn:hover,
  .almajd-rail-menu-btn:focus-visible {
    background: #eef4fb;
    border-color: rgba(18,60,105,.20);
    transform: translateY(-1px);
    outline: none;
  }
  .almajd-rail-menu-btn svg { width: 17px; height: 17px; flex: 0 0 auto; }
  .almajd-rail-menu-btn[aria-pressed="true"] {
    background: #e8f3ff;
    border-color: rgba(18,60,105,.26);
    color: #0b2545;
  }
  .almajd-rail-menu-btn[hidden] { display: none !important; }

  /* The legacy bottom status line must not compete with the fixed rail. */
  .status-line { left: calc(var(--rail-left) + var(--rail-w) + 14px); }
}

/* The floating rail is a screen-only affordance. */
@media print {
  .almajd-floating-rail,
  .almajd-rail-more { display: none !important; }
}

/* Dark theme compatibility. */
@media screen and (min-width: 1280px) {
  :is(html.dark-active, html:not(.light-active)) .almajd-floating-rail,
  :is(html.dark-active, html:not(.light-active)) .almajd-rail-more {
    background: rgba(8,24,46,.94);
    border-color: rgba(255,255,255,.10);
  }
  :is(html.dark-active, html:not(.light-active)) .almajd-rail-btn,
  :is(html.dark-active, html:not(.light-active)) .almajd-rail-counter,
  :is(html.dark-active, html:not(.light-active)) .almajd-rail-more-head b,
  :is(html.dark-active, html:not(.light-active)) .almajd-rail-menu-btn { color: #e6eef8; }
  :is(html.dark-active, html:not(.light-active)) .almajd-rail-btn:hover,
  :is(html.dark-active, html:not(.light-active)) .almajd-rail-btn:focus-visible { background: rgba(255,255,255,.08); }
  :is(html.dark-active, html:not(.light-active)) .almajd-rail-counter { background: rgba(212,175,55,.12); }
  :is(html.dark-active, html:not(.light-active)) .almajd-rail-counter b { color: #fff; }
  :is(html.dark-active, html:not(.light-active)) .almajd-rail-menu-btn {
    background: rgba(255,255,255,.05);
    border-color: rgba(255,255,255,.10);
  }
  :is(html.dark-active, html:not(.light-active)) .almajd-rail-menu-btn:hover { background: rgba(255,255,255,.09); }
}
