/* HDR overrides.
   theme_scripts.blade.php re-appends <link id="themeColor"> (style_dark.css) to
   <head> AFTER this file, so link order alone does not win the cascade -
   verified live: index 12 is this file, index 13 is style_dark.css. Hence the
   !important on the declarations that must survive that re-injection. */

/* ---------------------------------------------------------------------------
   1. Sidebar logo was cropped.

   .sidebar-header is height:60px with 14px vertical padding, leaving 32px of
   content box. The brand image was sized `width: 80%` with no height limit, so
   a wide wordmark (398x210) resolved to a height far taller than 32px and was
   clipped by the header. Constrain by HEIGHT and let width follow, with
   object-fit:contain so it is never stretched.
--------------------------------------------------------------------------- */
.sidebar .sidebar-header {
    padding-top: 8px !important;
    padding-bottom: 8px !important;
}

.sidebar .sidebar-header .sidebar-brand {
    display: flex;
    align-items: center !important;
    height: 100% !important;
    min-width: 0 !important;          /* allow the flex item to shrink instead of overflow */
    overflow: hidden !important;
}

.sidebar .sidebar-header .sidebar-brand img {
    width: auto !important;
    height: auto !important;
    max-width: 100% !important;
    max-height: 44px !important;      /* 60px header - 2x8px padding, with a little breathing room */
    object-fit: contain !important;   /* fill the box without distorting the wordmark */
    display: block !important;
}

/* When the sidebar is folded to icons, the wordmark has no room; shrink it
   rather than letting it overflow the narrow rail. */
.sidebar-folded .sidebar .sidebar-header .sidebar-brand img {
    max-height: 34px !important;
}

/* Company logos are supplied as dark artwork on a transparent background,
   which disappears against the dark sidebar. Knock the wordmark out to solid
   white in dark mode - a predictable result whatever colours the source uses,
   where a plain invert() would just shift a coloured logo to its complement. */
:root[data-theme="dark"] .sidebar .sidebar-header .sidebar-brand img {
    filter: brightness(0) invert(1);
}

/* ---------------------------------------------------------------------------
   2. Two scrollbars on the sidebar, and page-wide lag when moving the cursor
      between the content area and the sidebar.

   .sidebar-body carried `overflow-y: scroll` (a permanent native scrollbar)
   AND template.js attached a PerfectScrollbar to the same element, so the
   element had a native scrollbar plus a JS-driven one. PerfectScrollbar binds
   mousemove/scroll/resize handlers and recalculates geometry, which is what
   made crossing into the sidebar janky.

   Native scrolling is compositor-driven and costs nothing on hover, so keep it
   and drop the JS scrollbar (see template.js). `auto` also means the bar only
   appears when the menu actually overflows, and overscroll-behavior stops
   scroll chaining from bubbling out to the page.
--------------------------------------------------------------------------- */
/* The menu is genuinely taller than the space it has (measured: 942px of items
   in an 850px box on a 900px viewport), so it must stay scrollable. What it
   must NOT do is render its own visible bar right beside the page's, which is
   what read as "two sliders" - the sidebar's overlay bar appearing on hover,
   next to the document scrollbar.

   Keep the scrolling, drop the bar. A fade at the bottom edge (below) keeps the
   affordance that there is more menu to reach. */
.sidebar .sidebar-body {
    overflow-y: auto !important;
    overscroll-behavior: contain !important;
    scrollbar-width: none !important;          /* Firefox */
    -ms-overflow-style: none !important;       /* legacy Edge */
}

.sidebar .sidebar-body::-webkit-scrollbar {
    width: 0 !important;
    height: 0 !important;
    display: none !important;
}

/* style.css caps the menu at calc(100% - 50px) while .sidebar-header is 60px
   tall, so the menu box overhung its container by 10px. Match the real header
   height and reclaim the difference. */
.sidebar .sidebar-body {
    max-height: calc(100% - 60px) !important;
}

/* Soft fade at the bottom edge so a cut-off menu still looks scrollable
   without a scrollbar. Non-interactive so it never eats a click. */
.sidebar .sidebar-body {
    -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 28px), transparent 100%);
    mask-image: linear-gradient(to bottom, #000 calc(100% - 28px), transparent 100%);
}

/* Sidebar icons sat on top of their own labels in Arabic, on 6 of 19 items.

   style.css gives .link-icon `position: absolute` with NO left/right offset, so
   it falls back to its static position - where it would have sat in the flex
   row. That resolves differently depending on whether the item has a
   .link-arrow chevron: measured live, items WITH a chevron computed
   right: 25px (correct for RTL) while items WITHOUT computed left: 25px, i.e.
   the LTR corner, directly under the label. rtl_style.css flips the title's
   margin for every item but never repositions the icon, so the plain items had
   nothing pushing them across.

   Pin the offset explicitly to the value the working items already resolve to,
   rather than leaving it to static position. Arabic only - LTR is unaffected. */
:is(html[lang="ar"], html[lang="fa"], html[lang="he"], html[lang="ur"])
.sidebar .sidebar-body .nav .nav-item .nav-link .link-icon {
    right: 25px !important;
    left: auto !important;
}

/* Neutralise any PerfectScrollbar rails left in the DOM from a cached script. */
.sidebar .sidebar-body > .ps__rail-x,
.sidebar .sidebar-body > .ps__rail-y {
    display: none !important;
}

/* PerfectScrollbar sets `overflow: hidden` on elements it manages; make sure a
   stale instance cannot leave the menu unscrollable. */
.sidebar .sidebar-body.ps {
    overflow-y: auto !important;
}

/* ---------------------------------------------------------------------------
   3. Dropdown menu rows only responded to clicks on the text itself.

   The markup is <li class="dropdown-item py-2"><a>…</a></li>. The padding and
   the hover highlight belong to the <li>, but the <a> was `display: inline`,
   so it was 70x15 inside a 240x35 row - about 12% of the area people were
   aiming at. document.elementFromPoint at the centre of the row returned the
   LI, not the link, which is why "App QR" took a dozen attempts to open.

   Move the padding onto the interactive element and let it fill the row, so
   the whole highlighted strip is the hit target. This covers every item in the
   profile menu (Profile, Request Leave, App QR, Log out), not just the one
   that was reported.
--------------------------------------------------------------------------- */
.dropdown-menu li.dropdown-item {
    padding: 0 !important;
    overflow: hidden;              /* keep the child inside the rounded corners */
}

.dropdown-menu li.dropdown-item > a,
.dropdown-menu li.dropdown-item > button {
    display: flex !important;
    align-items: center;
    inline-size: 100%;
    padding: .55rem 1rem !important;
    margin: 0 !important;
    text-decoration: none;
}

/* The icons are sized by .me-2/.icon-md; stop them shrinking when a label
   wraps, so the text never collides with the glyph. */
.dropdown-menu li.dropdown-item > a > svg,
.dropdown-menu li.dropdown-item > a > i {
    flex: none;
}

/* The hover state now belongs to the link that fills the row. */
.dropdown-menu li.dropdown-item > a:hover,
.dropdown-menu li.dropdown-item > a:focus-visible {
    background: rgba(37, 99, 235, .08);
}

/* ---------------------------------------------------------------------------
   4. QR list: a 480px code in a table cell.

   QrAttendance::getQrCodeAttribute() emits <img width="480" height="480">.
   That size is deliberate - the printed code has to stay scannable - but it
   made every row of the QR list 480px tall, one code per screen.

   Present it as a thumbnail that links to the printable version. The white
   plate is not decoration: the PNG has a white quiet zone baked in, and
   without a light backing the code sits on the dark card in dark mode looking
   broken.
--------------------------------------------------------------------------- */
.qr_code .qr-thumb {
    display: inline-flex;
    padding: 6px;
    border-radius: 10px;
    background: #fff;
    border: 1px solid var(--hdr-card-border, #e8ecf3);
    line-height: 0;
    transition: transform .15s ease, box-shadow .15s ease;
}

.qr_code .qr-thumb:hover {
    transform: scale(1.04);
    box-shadow: 0 6px 18px rgba(16, 24, 40, .18);
}

.qr_code .qr-thumb .qr {
    line-height: 0;
}

/* Override the inline width/height attributes on the generated <img>. */
.qr_code .qr-thumb img {
    inline-size: 88px !important;
    block-size: 88px !important;
    display: block;
}

/* Keep the cell from stretching the row while the image loads. */
.qr_code {
    inline-size: 1%;
    white-space: nowrap;
    vertical-align: middle;
}

@media (prefers-reduced-motion: reduce) {
    .qr_code .qr-thumb {
        transition: none !important;
    }
    .qr_code .qr-thumb:hover {
        transform: none;
    }
}

/* ---------------------------------------------------------------------------
   5. Numbers, dates and phone numbers were rendered backwards in Arabic.

   With an RTL base direction the bidi algorithm reorders any left-to-right run
   it does not consider strongly LTR. The DOM text was always correct - verified
   live: the cell really did contain "+966 11 470 0000" and "16 Sep 2026" - but
   it PAINTED as "0000 470 11 966+" and "Sep 2026 16", and "40 %" as "% 40",
   because digits and "+"/"%" are bidi-neutral and got laid out right-to-left.

   `unicode-bidi: plaintext` resolves each element's direction from its own
   first strong character instead of inheriting the page's. A cell of Arabic
   still lays out RTL; a cell that is only digits and punctuation has no strong
   character and falls back to LTR, which is what a phone number or a date
   needs. One rule handles both, so no column has to be classified by hand.

   Scoped to :is(html[lang="ar"], html[lang="fa"], html[lang="he"], html[lang="ur"]) so the LTR locales are untouched.
--------------------------------------------------------------------------- */
:is(html[lang="ar"], html[lang="fa"], html[lang="he"], html[lang="ur"]) table td,
:is(html[lang="ar"], html[lang="fa"], html[lang="he"], html[lang="ur"]) table th,
:is(html[lang="ar"], html[lang="fa"], html[lang="he"], html[lang="ur"]) .progress-bar > span,
:is(html[lang="ar"], html[lang="fa"], html[lang="he"], html[lang="ur"]) .hdr-kpi h3,
:is(html[lang="ar"], html[lang="fa"], html[lang="he"], html[lang="ur"]) .card-title,
:is(html[lang="ar"], html[lang="fa"], html[lang="he"], html[lang="ur"]) .breadcrumb-item,
:is(html[lang="ar"], html[lang="fa"], html[lang="he"], html[lang="ur"]) .badge,
:is(html[lang="ar"], html[lang="fa"], html[lang="he"], html[lang="ur"]) .form-control,
:is(html[lang="ar"], html[lang="fa"], html[lang="he"], html[lang="ur"]) input,
:is(html[lang="ar"], html[lang="fa"], html[lang="he"], html[lang="ur"]) textarea {
    unicode-bidi: plaintext;
}

/* Machine-readable strings read left-to-right in every language.

   Selected by CONTENT, never by href. An earlier version of this rule included
   a[href^="http"], reasoning that such links are URLs - but APP_URL is
   https://hr.hdragency.com, so Laravel's route() helper emits an absolute URL
   for EVERY link in the panel. Measured: 70 of 92 links on the dashboard were
   forced to direction: ltr, including the sidebar navigation, which left
   "لوحة التحكم" resolving LTR while "إدارة الشركة" stayed RTL. The href is not
   the content; only the visible text matters here.

   Use the .ltr-text class for a URL that is actually displayed as text. */
:is(html[lang="ar"], html[lang="fa"], html[lang="he"], html[lang="ur"]) :is(
    a[href^="mailto:"],
    a[href^="tel:"],
    .text-monospace,
    .ltr-text,
    code,
    kbd
) {
    direction: ltr;
    unicode-bidi: isolate;
}

/* ---------------------------------------------------------------------------
   6. Date-range picker was unreadable in dark mode.

   export.blade.php pulls daterangepicker's stylesheet straight from a CDN. That
   sheet is light-themed and knows nothing about the app's dark mode, while the
   text colour is inherited from the page - so the container painted a WHITE
   background under near-white text (measured: bg rgb(255,255,255),
   color rgb(238,244,255)), and .drp-selected - the "08/20/2026 - 08/30/2026"
   label above the buttons - was white on white, i.e. invisible.

   At the same time style_dark.css's generic table rules bled into the inner
   .calendar-table, so the day grid rendered dark inside that white shell. Two
   themes in one widget.

   Give the whole picker one coherent dark treatment, using the same tokens as
   the rest of the panel. Light mode is untouched - the library's own styling is
   correct there.
--------------------------------------------------------------------------- */
:root[data-theme="dark"] .daterangepicker {
    background-color: #131a2b !important;
    border: 1px solid #26334d !important;
    border-radius: 12px !important;
    box-shadow: 0 18px 40px rgba(0, 0, 0, .45) !important;
    color: #e8eefc !important;
}

/* The little callout arrow is drawn with borders, so it needs the same colours
   or it floats as a white notch above the panel. */
:root[data-theme="dark"] .daterangepicker::before {
    border-bottom-color: #26334d !important;
}

:root[data-theme="dark"] .daterangepicker::after {
    border-bottom-color: #131a2b !important;
}

:root[data-theme="dark"] .daterangepicker .drp-calendar,
:root[data-theme="dark"] .daterangepicker .calendar-table {
    background-color: transparent !important;
    border: 0 !important;
    color: #e8eefc !important;
}

/* Weekday initials and the month caption. */
:root[data-theme="dark"] .daterangepicker .calendar-table th,
:root[data-theme="dark"] .daterangepicker .month {
    color: #9fb0cc !important;
    background: transparent !important;
    border: 0 !important;
    font-weight: 600;
}

:root[data-theme="dark"] .daterangepicker td {
    background: transparent !important;
    border: 0 !important;
    color: #dbe4f5 !important;
    border-radius: 8px !important;
}

/* Days outside the shown month, and disabled days: present but recessive. */
:root[data-theme="dark"] .daterangepicker td.off,
:root[data-theme="dark"] .daterangepicker td.off.in-range,
:root[data-theme="dark"] .daterangepicker td.off.start-date,
:root[data-theme="dark"] .daterangepicker td.off.end-date {
    background: transparent !important;
    color: #7386a6 !important;   /* still recessive, but >=3:1 and clickable */
}

:root[data-theme="dark"] .daterangepicker td.disabled,
:root[data-theme="dark"] .daterangepicker option.disabled {
    color: #3c4863 !important;
    text-decoration: line-through;
}

:root[data-theme="dark"] .daterangepicker td.available:hover,
:root[data-theme="dark"] .daterangepicker th.available:hover {
    background: rgba(96, 165, 250, .16) !important;
    color: #ffffff !important;
}

/* The span between the two chosen dates. */
:root[data-theme="dark"] .daterangepicker td.in-range {
    background: rgba(96, 165, 250, .14) !important;
    color: #eaf2ff !important;
    border-radius: 0 !important;
}

/* The two endpoints. */
:root[data-theme="dark"] .daterangepicker td.active,
:root[data-theme="dark"] .daterangepicker td.active:hover,
:root[data-theme="dark"] .daterangepicker td.start-date,
:root[data-theme="dark"] .daterangepicker td.end-date {
    background: #2f6fd0 !important;
    color: #ffffff !important;
    font-weight: 600;
}

:root[data-theme="dark"] .daterangepicker td.start-date {
    border-radius: 8px 0 0 8px !important;
}

:root[data-theme="dark"] .daterangepicker td.end-date {
    border-radius: 0 8px 8px 0 !important;
}

:root[data-theme="dark"] .daterangepicker td.start-date.end-date {
    border-radius: 8px !important;
}

/* Month / year dropdowns. */
:root[data-theme="dark"] .daterangepicker select.monthselect,
:root[data-theme="dark"] .daterangepicker select.yearselect,
:root[data-theme="dark"] .daterangepicker select.hourselect,
:root[data-theme="dark"] .daterangepicker select.minuteselect,
:root[data-theme="dark"] .daterangepicker select.secondselect,
:root[data-theme="dark"] .daterangepicker select.ampmselect {
    background: #1b2438 !important;
    color: #e8eefc !important;
    border: 1px solid #2c3a56 !important;
    border-radius: 6px !important;
}

/* Prev / next chevrons are CSS-drawn borders. */
:root[data-theme="dark"] .daterangepicker .prev span,
:root[data-theme="dark"] .daterangepicker .next span {
    border-color: #9fb0cc !important;
}

:root[data-theme="dark"] .daterangepicker .prev:hover span,
:root[data-theme="dark"] .daterangepicker .next:hover span {
    border-color: #ffffff !important;
}

/* Footer: this is where the invisible white-on-white label lived. */
:root[data-theme="dark"] .daterangepicker .drp-buttons {
    background: transparent !important;
    border-top: 1px solid #26334d !important;
}

:root[data-theme="dark"] .daterangepicker .drp-selected {
    color: #b9c7de !important;
    font-size: 12px;
}

:root[data-theme="dark"] .daterangepicker .cancelBtn {
    background: transparent !important;
    color: #cdd8ea !important;
    border: 1px solid #35425e !important;
    border-radius: 8px !important;
}

:root[data-theme="dark"] .daterangepicker .cancelBtn:hover {
    background: rgba(255, 255, 255, .06) !important;
    color: #ffffff !important;
}

:root[data-theme="dark"] .daterangepicker .applyBtn {
    border-radius: 8px !important;
    border: 0 !important;
}

/* Preset-range list down the side, when one is configured. */
:root[data-theme="dark"] .daterangepicker .ranges li {
    color: #cdd8ea !important;
}

:root[data-theme="dark"] .daterangepicker .ranges li:hover {
    background: rgba(96, 165, 250, .14) !important;
}

:root[data-theme="dark"] .daterangepicker .ranges li.active {
    background: #2f6fd0 !important;
    color: #ffffff !important;
}

/* plaintext resolves DIRECTION, not alignment. A digits-only cell resolves LTR
   and its inherited `text-align: start` then used-values to LEFT, while the
   Arabic <th> above it stays right - so numeric columns detached from their own
   headers. Only .text-center was guarded, leaving the ~1088 cells that carry no
   alignment class to drift.

   Pin the physical edge so direction resolution and alignment are decoupled.
   Specificity (0,1,3) beats style_dark.css's `th { text-align: -webkit-match-parent }`
   without !important, even though that sheet is re-appended last. Bootstrap's
   .text-center / .text-end still win, as they are !important. */
:is(html[lang="ar"], html[lang="fa"]) table td,
:is(html[lang="ar"], html[lang="fa"]) table th {
    text-align: right;
}
