/* ==========================================================================
   PulseOS Shell Layout
   6-tab top-bar navigation shell replacing the 3-hub sidebar layout.
   Uses design tokens from tokens.css.
   ========================================================================== */

/* ── WCAG AA: Skip Link ────────────────────────────────────────────────── */

.skip-link {
    position: absolute;
    left: -9999px;
    top: auto;
    width: 1px;
    height: 1px;
    overflow: hidden;
    z-index: 9999;
    padding: var(--sp-2, 0.5rem) var(--sp-4, 1rem);
    background: var(--brand-primary, #0072BC);
    color: #fff;
    font-weight: 700;
    font-size: var(--text-sm, 0.8125rem);
    text-decoration: none;
    border-radius: var(--radius-sm, 6px);
}
.skip-link:focus {
    position: fixed;
    left: var(--sp-4, 1rem);
    top: var(--sp-4, 1rem);
    width: auto;
    height: auto;
    overflow: visible;
}

/* ── WCAG AA: Focus Visible ────────────────────────────────────────────── */

/* The ring is two tokens (`--focus-ring`, `--focus-offset`) read by FOUR shared rules: this one, the control list below, and the two in
   `site.css` (`.btn:focus-visible ...` and the bare `:focus-visible`). It sets no `border-radius`: a ring never squares a rounded control. */
*:focus-visible {
    outline: var(--focus-ring);
    outline-offset: var(--focus-offset);
}

/* Remove default focus ring for mouse users (keep for keyboard) */
*:focus:not(:focus-visible) {
    outline: none;
}

/* Ensure interactive elements have visible focus */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[role="tab"]:focus-visible,
[role="button"]:focus-visible {
    outline: var(--focus-ring);
    outline-offset: var(--focus-offset);
}

/* ── Top Bar ────────────────────────────────────────────────────────────── */

/* ── Shell header height ────────────────────────────────────────────────
   One source of truth for how tall the fixed top bar is.

   tokens.css sets --header-height: 48px for the LEGACY site-header, which is
   genuinely 48px tall. The shell's top bar is 90px, but the sidebar offsets
   and the toast container were reading the 48px token — so on every shell
   page the sidebar was positioned 42px too high and slid under the header,
   and toasts opened tucked behind it.

   Redefining the token here rather than in tokens.css keeps the change to
   pages that load this file: base_shell.html loads shell.css and never
   sidebar.css, while base_legacy.html and base_sidebar_compat.html load
   sidebar.css and never this. The legacy header stays 48px.
   ──────────────────────────────────────────────────────────────────────── */
:root {
    --header-height: 90px;
}

.shell-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    /* Explicit, not inherited from frontend/css/site.css's global reset: the
       2px bottom border must be INSIDE --header-height, or the bar renders
       92px tall while everything positioned below it offsets by 90 and the
       routine drawer clips the header again. Not worth depending on another
       app's stylesheet for. */
    box-sizing: border-box;
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 var(--sp-5, 1.25rem);
    gap: var(--sp-4, 1rem);
    background: linear-gradient(90deg, #f8fafc, #eef4ff, #f0f9ff);
    border-bottom: 2px solid #dbeafe;
    /* Above the drawers. The bar creates a stacking context, so this also
       governs everything anchored to it -- the notifications dropdown is
       z-index:100 INSIDE this context, which is why it lost to the routine
       drawer's 10100 no matter what number it carried itself. */
    z-index: var(--z-header, 10200);
}

/* ── Logo ───────────────────────────────────────────────────────────────── */

.shell-logo {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    text-decoration: none;
    flex-shrink: 0;
}

.shell-logo__img {
    height: 81px;
    width: auto;
    object-fit: contain;
}

/* ── Tabs ───────────────────────────────────────────────────────────────── */

/* The row never scrolls and is never cut: menu.css keeps its words as long as they fit and folds them in a fixed order. */
.shell-tabs {
    display: flex;
    gap: 2px;
}

.shell-tab {
    display: flex;
    align-items: center;
    gap: 5px;
    /* Trimmed from 8px 16px when wave 3 took the bar from nine tabs to
       eleven. */
    padding: 8px 11px;
    white-space: nowrap;
    border-radius: 20px;
    text-decoration: none;
    color: #475569;
    font-size: 0.82rem;
    font-weight: 500;
    transition: background 200ms ease, color 200ms ease, box-shadow 200ms ease;
    white-space: nowrap;
    position: relative;
}

.shell-tab:hover {
    background: rgba(0, 114, 188, 0.06);
    color: #334155;
}

.shell-tab--active {
    color: #0072BC;
    background: #fff;
    font-weight: 600;
    box-shadow: var(--tab-lit-shadow);
    border: var(--tab-lit-border);
}

.shell-tab__icon {
    font-size: 1rem;
    line-height: 1;
    color: inherit;
}

.shell-tab__label {
    font-size: inherit;
    line-height: 1.2;
}

.shell-tab__badge {
    min-width: 18px;
    height: 18px;
    border-radius: var(--radius-full, 9999px);
    background: var(--danger, #c4321c);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    position: absolute;
    top: 0;
    inset-inline-end: 0;
}

/* ── Actions (right side) ───────────────────────────────────────────────── */

.shell-actions {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    margin-inline-start: auto;
    flex-shrink: 0;
}

/* ── The timer pill (spec D1) ──────────────────────────────────────── */
/* One compact pill at every width and in every state: the dot, the clock (a link to the task) and the buttons. The longer
   text of each state (.timer-pill__full) comes back from 1800px; below that it is still in aria-label and title. */
.timer-pill { display: inline-flex; align-items: center; gap: 8px; padding: 3px 8px 3px 10px; border-radius: 999px; white-space: nowrap; flex-shrink: 0; font-size: .78rem; background: var(--success-bg, #ecfdf3); border: 1px solid #6dd4a0; color: #0a5c37; }
.timer-pill[hidden] { display: none; }
.timer-pill__dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; animation: timer-pill-pulse 1.6s ease-in-out infinite; }
@keyframes timer-pill-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
.timer-pill__clock { display: inline-flex; align-items: center; min-height: 24px; font-family: var(--font-mono, Menlo, monospace); font-weight: 600; font-variant-numeric: tabular-nums; color: inherit; text-decoration: none; }
a.timer-pill__clock:hover, a.timer-pill__clock:focus-visible { text-decoration: underline; }
.timer-pill__full { display: none; }
.timer-pill__code { font-family: var(--font-mono, Menlo, monospace); font-size: .7rem; color: var(--brand-primary, #0072BC); max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.timer-pill__btn { display: inline-flex; align-items: center; justify-content: center; min-width: 24px; height: 24px; border: 0; cursor: pointer; font: inherit; }
.timer-pill__btn--pause, .timer-pill__btn--stop { border-radius: 50%; color: #fff; font-size: 8px; }
.timer-pill__btn--pause { background: #D97706; }
.timer-pill__btn--stop { background: #DC2626; }
.timer-pill__btn--yes { padding: 0 9px; border-radius: 6px; background: var(--brand-primary, #0072BC); color: #fff; font-size: .76rem; font-weight: 600; text-decoration: none; }
.timer-pill--paused { background: var(--warning-bg, #fffbeb); border-color: var(--warning-border, #f0d060); color: #8a5a0b; }
.timer-pill--paused .timer-pill__dot { animation: none; }
.timer-pill__badge { display: inline-flex; align-items: center; min-height: 24px; padding: 0 8px; border-radius: 999px; background: var(--warning-bg, #fffbeb); border: 1px solid var(--warning-border, #f0d060); color: #8a5a0b; font-size: .72rem; font-weight: 600; text-decoration: none; }
.timer-pill--asked, .timer-pill--paused_by_system { background: var(--warning-bg, #fffbeb); border-color: var(--warning-border, #f0d060); color: #8a5a0b; }
.timer-pill--asked .timer-pill__dot { animation-duration: .8s; }
/* The clock and the name are one button that opens the picker; the idle control is a button of its own. */
.timer-pill__who, .timer-pill__open { display: inline-flex; align-items: center; gap: 8px; padding: 0; border: 0; background: none; color: inherit; font: inherit; cursor: pointer; white-space: nowrap; }
.timer-pill__who:hover .timer-pill__clock, .timer-pill__who:focus-visible .timer-pill__clock { text-decoration: underline; }
.timer-pill--idle { background: var(--timer-idle-bg); border-color: var(--timer-idle-border); color: var(--timer-idle-text); padding-block: 3px; padding-inline: 4px 10px; }
.timer-pill__play { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 50%; background: var(--brand-primary, #0072BC); color: #fff; font-size: 9px; padding-inline-start: 1px; }
.timer-pill__today { display: none; font-variant-numeric: tabular-nums; font-weight: 600; }
.timer-pill__words { display: none; line-height: 1.15; text-align: start; }
.timer-pill__words b { font-size: .8rem; font-weight: 700; }
.timer-pill__words small { font-size: .75rem; }
/* The status line: fixed under the header, at the inline end, never in the way of a click. */
.timer-pill-say { position: fixed; inset-block-start: calc(var(--header-height, 90px) + 6px); inset-inline-end: var(--sp-2, 8px); z-index: 60; max-width: calc(100% - 2 * var(--sp-2, 8px)); padding: 8px 12px; border-radius: 10px; border: 1px solid var(--timer-say-border); background: var(--timer-say-bg); color: var(--timer-say-text); font-size: .8rem; font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; pointer-events: none; box-shadow: 0 6px 18px rgba(0, 59, 122, .12); }
.timer-pill-say[hidden] { display: none; }
.timer-pill-say--error { border-color: var(--timer-say-error-border); background: var(--timer-say-error-bg); color: var(--timer-say-error-text); }
/* Resume: the word, or from 1024 to 1799px a play icon (the control is no wider than the running pill there). */
.timer-pill__btn--yes .timer-pill__icon { display: none; }
@media (min-width: 1024px) and (max-width: 1799px) {
    button.timer-pill__btn--yes { padding: 0; width: 24px; border-radius: 50%; }
    .timer-pill__btn--yes .timer-pill__word { display: none; }
    .timer-pill__btn--yes .timer-pill__icon { display: inline; font-size: 9px; padding-inline-start: 1px; }
}
/* Room for the control (Ruling 20): the keyboard hint is a hint, so it goes first. (The Website word left this rule in stage 5: a member
   finds "Public website" in the account menu, and the bar's own link is the signed-out visitor's.) */
@media (max-width: 1799px) {
    .shell-search-hint { display: none; }
}
@media (max-width: 1599px) {
    .shell-tab { padding-inline: 9px; }
}
@media (min-width: 768px) { .timer-pill__today { display: inline; } }
@media (min-width: 1800px) {
    .timer-pill__today { display: none; }
    .timer-pill__words { display: grid; }
}
/* From 1800px only: at 1500px the full form (289 to 347px) still cost a member three to five tabs, so a laptop keeps the compact pill. */
@media (min-width: 1800px) { .timer-pill__full { display: inline; } }
/* Below 1024px the pill has a row of its own inside the header. In the row it pushed My Day off the tab strip (768px, 901px)
   and, on a phone, the account menu off the screen; hung under the bar it covered drawer headers. The header grows by the row:
   --header-height is what drawers, sidebars, toasts and the tracker anchors below start under. */
@media (max-width: 1023px) {
    html.has-timer-pill { --header-height: 126px; }
    html.has-timer-pill .shell-topbar { padding-bottom: 36px; }
    html.has-timer-pill .timer-pill { position: absolute; bottom: 2px; inset-inline-end: var(--sp-2, 8px); }
    /* Idle (no has-timer-pill) sits in the top row, between the tabs and the actions; its play button alone is a 44px target. */
    .timer-pill--idle { padding: 0; border: 0; background: none; }
    .timer-pill--idle .timer-pill__open { min-width: 44px; min-height: 44px; justify-content: center; }
    html.has-timer-pill .timer-pill { gap: 20px; }
    /* Every button in the control, old and new, keeps its 24px look and gets a 44 by 44px hit area. */
    .timer-pill__btn { position: relative; }
    .timer-pill__btn::after { content: ""; position: absolute; inset: -10px; min-width: 44px; min-height: 44px; }
    .timer-pill__who { position: relative; }
    .timer-pill__who::after { content: ""; position: absolute; inset: -10px -4px; min-width: 44px; min-height: 44px; }
    .timer-pill__badge { position: relative; }
    .timer-pill__badge::after { content: ""; position: absolute; inset: -10px -4px; min-width: 44px; min-height: 44px; }
}
/* At 360px the 44px idle button leaves the account menu off the screen: the action buttons sit closer together. */
@media (max-width: 400px) { .shell-actions { gap: var(--sp-1, 4px); } }
@media (max-width: 380px) { .shell-actions { gap: 2px; } }
/* The pill's "Confirm hours" link lands on #task-<id> in the Time Tracker: keep that wrapper clear of the fixed bar. */
.tt-now[id^="task-"], .tt-task[id^="task-"] { scroll-margin-top: 4px; }

.shell-search-trigger {
    display: flex;
    align-items: center;
    gap: var(--sp-1);
    background: #fff;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 0.8rem;
    color: #64748b;
    cursor: pointer;
    transition: background 200ms ease, border-color 200ms ease;
}

.shell-search-trigger:hover {
    background: #f0f9ff;
    border-color: #93c5fd;
}

.shell-search-hint {
    font-size: 0.65rem;
    color: #94a3b8;
    opacity: 1;
    padding: 1px 5px;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
}

.shell-action-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--ink-soft);
    padding: var(--sp-2);
    border-radius: var(--radius-sm, 6px);
    transition: background var(--duration) var(--ease), color var(--duration) var(--ease);
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.shell-action-btn:hover {
    background: var(--bg-1);
    color: var(--ink);
}

.shell-website-label {
    font-size: 0.8rem;
    font-weight: 500;
    margin-left: var(--sp-1);
}

/* ── User Menu ──────────────────────────────────────────────────────────── */

.shell-user-menu {
    position: relative;
}

.shell-user-chip {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    background: none;
    border: none;
    cursor: pointer;
    padding: var(--sp-1);
    border-radius: var(--radius-sm, 6px);
    transition: background var(--duration) var(--ease);
}

.shell-user-chip:hover {
    background: rgba(0, 114, 188, 0.06);
}

.shell-avatar {
    width: 30px;
    height: 30px;
    border-radius: 9999px;
    background: #0072BC;
    color: #fff;
    font-weight: 600;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* The account menu's first line: the person's name, not a link. The block keeps the page's direction; the name itself
   sits in a <bdi> in the template, so a Latin name in an Arabic menu is isolated without being pushed to the other edge. */
.shell-dropdown__who {
    padding: var(--sp-2) var(--sp-3);
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--ink);
    border-bottom: 1px solid var(--line);
    margin-bottom: var(--sp-1);
    overflow-wrap: anywhere;
    text-align: start;
}

.shell-dropdown {
    position: absolute;
    right: 0;
    top: 100%;
    min-width: 180px;
    /* Grows to its longest entry (an entry never wraps) and never leaves the window. */
    max-width: calc(100vw - 16px);
    background: var(--panel-drop-bg);
    border: 1px solid var(--line);
    border-radius: var(--radius-md, 10px);
    box-shadow: var(--glass-shadow-md);
    z-index: 100;
    padding: var(--sp-1);
    margin-top: var(--sp-1);
}

.shell-dropdown__item {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-3);
    text-decoration: none;
    color: var(--ink);
    font-size: var(--text-sm);
    border-radius: var(--radius-sm, 6px);
    border: none;
    background: none;
    cursor: pointer;
    width: 100%;
    text-align: left;
    white-space: nowrap;
    transition: background var(--duration) var(--ease);
}

.shell-dropdown__item:hover {
    background: var(--bg-1);
}

/* ── Shell Layout ───────────────────────────────────────────────────────── */

.shell-layout {
    display: flex;
    margin-top: var(--header-height);
    min-height: calc(100vh - var(--header-height));
}

.shell-main {
    flex: 1;
    padding: var(--sp-6);
    min-height: calc(100vh - 60px);
    max-width: 100%;
    overflow-x: hidden;
}

.shell-footer {
    text-align: center;
    padding: var(--sp-4);
    font-size: var(--text-xs, 0.75rem);
    color: var(--ink-soft);
    margin-top: var(--sp-8);
}

/* ── Contextual Sidebar ─────────────────────────────────────────────────── */

.shell-sidebar {
    --sidebar-width: 220px;
    --sidebar-collapsed-width: 48px;
    width: var(--sidebar-width);
    min-height: calc(100vh - var(--header-height, 90px));
    background: linear-gradient(180deg, #EAF6F8, #F5F8FA);
    border-right: 1px solid #D5E8EC;
    overflow-y: auto;
    overflow-x: hidden;
    flex-shrink: 0;
    transition: width 200ms ease-out;
}

.shell-sidebar--collapsed {
    width: var(--sidebar-collapsed-width);
}

.shell-sidebar__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--bg-2);
    gap: var(--sp-2);
}

.shell-sidebar--collapsed .shell-sidebar__header {
    justify-content: center;
    padding: var(--sp-3) var(--sp-2);
}

.shell-sidebar__back {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    color: #0072BC;
    font-size: 0.8rem;
    text-decoration: none;
    transition: color var(--duration, 200ms) var(--ease);
    white-space: nowrap;
    overflow: hidden;
}

.shell-sidebar__back:hover {
    color: var(--ink);
}

.shell-sidebar__toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--ink-soft);
    cursor: pointer;
    border-radius: var(--radius-sm, 6px);
    flex-shrink: 0;
    transition: background var(--duration, 200ms) var(--ease),
                color var(--duration, 200ms) var(--ease);
}

.shell-sidebar__toggle:hover {
    background: var(--bg-2);
    color: var(--ink);
}

.shell-sidebar__nav {
    padding: var(--sp-2) 0;
}

.shell-sidebar__link {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-4);
    color: #475569;
    text-decoration: none;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    transition: background var(--duration, 200ms) var(--ease),
                color var(--duration, 200ms) var(--ease);
}

.shell-sidebar--collapsed .shell-sidebar__link {
    justify-content: center;
    padding: var(--sp-2) var(--sp-2);
}

.shell-sidebar__link:hover {
    background: #fff;
    color: var(--ink);
}

.shell-sidebar__link--active {
    background: #fff;
    border-left: 2px solid #27A9B8;
    box-shadow: 0 1px 3px rgba(0, 59, 122, 0.06);
    color: #003B7A;
    font-weight: 600;
}

.shell-sidebar__link-icon {
    font-size: 1rem;
    flex-shrink: 0;
    width: 1.1em;
    text-align: center;
}

.shell-sidebar__link-label {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* A MODULE's name (Arabic since stage 5) wraps onto a second line instead of being cut; the link carries the full name
   as its title. Scoped to the module links: the class is also the label of the sub-items, Favourites and Recent, whose
   titles are a person's own words and stay on one line. */
.shell-sidebar__nav > .shell-sidebar__group > a.shell-sidebar__link > .shell-sidebar__link-label {
    min-width: 0;
    white-space: normal;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

/* Read-only marker. Muted rather than alarming: a locked module is a normal
   state for the role, not a fault the member should try to fix. */
.shell-sidebar__lock {
    margin-left: auto;
    font-size: var(--type-caption, 12px);
    opacity: 0.55;
    flex-shrink: 0;
}

.shell-sidebar__badge {
    margin-left: auto;
    min-width: 18px;
    min-height: 18px;
    border-radius: var(--radius-full, 9999px);
    background: var(--danger, #c4321c);
    color: #fff;
    font-size: var(--type-caption, 12px);
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    flex-shrink: 0;
}

.shell-sidebar__fav-icon {
    color: var(--warning, #f59e0b);
}

.shell-sidebar__link--compact {
    font-size: 0.75rem;
    padding: var(--sp-1) var(--sp-4) var(--sp-1) var(--sp-6);
}

.shell-sidebar--collapsed .shell-sidebar__link--compact {
    padding: var(--sp-1) var(--sp-2);
}

.shell-sidebar__section {
    border-top: 1px solid var(--bg-2);
    padding: var(--sp-2) 0;
}

.shell-sidebar__section-title {
    font-size: var(--type-caption, 12px);
    font-weight: 600;
    color: #0072BC;
    padding: var(--sp-2) var(--sp-4);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0;
}

/* ── Dark Mode Overrides ────────────────────────────────────────────────── */

/* ── Responsive: Tablet (768-1023px) ───────────────────────────────────── */

@media (max-width: 1023px) and (min-width: 768px) {
    .shell-tab__icon {
        font-size: 1.25rem;
    }

    .shell-search-trigger {
        max-width: 160px;
    }

    .shell-search-hint {
        display: none;
    }

    .shell-sidebar {
        position: fixed;
        left: 0;
        top: var(--header-height, 90px);
        bottom: 0;
        z-index: 40;
        transform: translateX(-100%);
        transition: transform var(--duration) var(--ease);
        box-shadow: var(--glass-shadow-lg);
    }

    .shell-sidebar--open {
        transform: translateX(0);
    }

    /* the closed side menu leaves to the right on an Arabic page (it stands at the right edge there) */
    html[dir="rtl"] .shell-sidebar {
        transform: translateX(100%);
    }

    /* the open side menu on an Arabic page is back at 0 */
    html[dir="rtl"] .shell-sidebar--open {
        transform: translateX(0);
    }

    .shell-main {
        padding: var(--sp-4) var(--sp-5);
    }
}

/* ── Responsive: Mobile (<768px) ──────────────────────────────────────── */

@media (max-width: 767px) {
    .shell-topbar {
        padding: 0 var(--sp-2);
        gap: var(--sp-2);
        flex-wrap: nowrap;
    }

    /* Hide desktop tabs — replaced by bottom bar */
    .shell-tabs {
        display: none;
    }

    .shell-search-trigger {
        padding: var(--sp-2);
    }

    .shell-search-trigger .shell-search-hint,
    .shell-search-trigger span:not(.shell-search-hint) {
        display: none;
    }

    .shell-search-hint {
        display: none;
    }

    .shell-website-label {
        display: none;
    }

    .shell-sidebar {
        position: fixed;
        left: 0;
        top: var(--header-height, 90px);
        bottom: var(--bar-height, 56px); /* above bottom tab bar */
        z-index: 40;
        transform: translateX(-100%);
        transition: transform var(--duration) var(--ease);
        box-shadow: var(--glass-shadow-lg);
    }

    .shell-sidebar--open {
        transform: translateX(0);
    }

    /* the closed side menu leaves to the right on an Arabic page (it stands at the right edge there) */
    html[dir="rtl"] .shell-sidebar {
        transform: translateX(100%);
    }

    /* the open side menu on an Arabic page is back at 0 */
    html[dir="rtl"] .shell-sidebar--open {
        transform: translateX(0);
    }

    .shell-main {
        padding: var(--sp-3);
        padding-bottom: 72px; /* space for bottom tab bar */
    }

    .shell-footer {
        padding-bottom: 72px;
    }

    /* ── Mobile Bottom Tab Bar ── */
    .shell-bottom-tabs {
        display: flex;
        position: fixed;
        bottom: 0;
        inset-inline: 0;
        height: 56px;
        background: var(--bar-bg);
        border-top: 1px solid var(--bg-2, #e4edf5);
        z-index: 50;
        justify-content: space-around;
        align-items: center;
        padding: 0 var(--sp-1);
    }

    .shell-bottom-tabs .shell-tab {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: var(--sp-1) 0;
        min-width: 0;
        border-radius: 0;
    }
}

/* The bar's label and icon, and the bar's sheets, are phone.css's (UX stage 6, Task 3): the label and icon rules moved there
   (the label to 12px), the More popup's rules left with the popup. */

/* Hide bottom tabs on desktop/tablet */
@media (min-width: 768px) {
    .shell-bottom-tabs {
        display: none;
    }
}

/* ── Dark mode: bottom tab bar ─────────────────────────────────────────── */

/* ── Messenger widget: mobile collapse to FAB ──────────────────────────── */

@media (max-width: 767px) {
    .messenger-panel {
        bottom: 72px; /* above bottom tab bar */
        max-height: calc(100vh - 128px); /* header + bottom bar */
    }

    .messenger-fab {
        bottom: 68px; /* above bottom tab bar */
    }

    .cp-dialog {
        top: 5%;
        width: 95%;
        max-height: 80vh;
    }

    .cp-results {
        max-height: 280px;
    }
}

/* ── Command Palette ────────────────────────────────────────────────────── */

.cp-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.cp-dialog {
    position: fixed;
    top: 15%;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 640px;
    background: var(--card, #fff);
    border-radius: var(--radius-lg, 14px);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    overflow: hidden;
}

.cp-search {
    display: flex;
    align-items: center;
    padding: var(--sp-4);
    border-bottom: 1px solid var(--bg-2);
    gap: var(--sp-3);
}

.cp-search-icon {
    color: var(--ink-soft);
    font-size: 1.2rem;
    flex-shrink: 0;
}

.cp-search-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 1rem;
    background: transparent;
    color: var(--ink);
    font-family: var(--font-body);
}

/* The palette's box has no border of its own to change: the ring is the focus (Task 12), inside the row's 16 px padding. */
.cp-search-input:focus-visible {
    outline: var(--focus-ring);
    outline-offset: var(--focus-offset);
}

.cp-search-input::placeholder {
    color: var(--ink-soft);
}

.cp-kbd {
    font-size: var(--type-caption, 12px);
    padding: 2px 6px;
    background: var(--bg-1);
    border: 1px solid var(--bg-2);
    border-radius: 4px;
    color: var(--ink-soft);
    font-family: var(--font-mono);
    line-height: 1.4;
}

/* The plus key of the empty state's sentence (it was an inline `font-size:10px` in command_palette.html; the size leaves the
   attribute so that phone.css can raise it to 12px under 768px: unchanged from 768px up). */
.cp-kbd-plus {
    font-size: var(--type-caption, 12px);
}

/* The live toast's "Click to dismiss" (it was an inline size in notifications.js: unchanged from 768px up; 12px under it, phone.css). */
.ws-toast__hint {
    font-size: var(--type-caption, 12px);
}

.cp-tabs {
    display: flex;
    gap: var(--sp-1);
    padding: var(--sp-2) var(--sp-4);
    border-bottom: 1px solid var(--bg-2);
}

.cp-tab {
    background: none;
    border: none;
    padding: var(--sp-1) var(--sp-3);
    border-radius: var(--radius-sm, 6px);
    font-size: 0.8rem;
    color: var(--ink-soft);
    cursor: pointer;
    transition: background var(--duration) var(--ease), color var(--duration) var(--ease);
    font-family: var(--font-body);
}

.cp-tab:hover {
    background: var(--bg-1);
    color: var(--ink);
}

.cp-tab--active {
    background: var(--info-bg);
    color: var(--brand-primary);
    font-weight: 600;
}

.cp-results {
    max-height: 400px;
    overflow-y: auto;
    padding: var(--sp-2) 0;
}

.cp-section-title {
    font-size: var(--type-caption, 12px);
    font-weight: 600;
    color: var(--ink-soft);
    padding: var(--sp-2) var(--sp-4);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.cp-result {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-2) var(--sp-4);
    text-decoration: none;
    color: var(--ink);
    font-size: 0.85rem;
    cursor: pointer;
    transition: background var(--duration) var(--ease);
}

.cp-result:hover,
.cp-result--active {
    background: var(--bg-1);
}

.cp-result__type {
    font-size: var(--type-caption, 12px);
    padding: 2px 6px;
    background: var(--bg-1);
    border-radius: 4px;
    color: var(--ink-soft);
    flex-shrink: 0;
}

.cp-result__label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cp-empty {
    text-align: center;
    padding: var(--sp-6);
    color: var(--ink-soft);
    font-size: 0.9rem;
}

.cp-footer {
    display: flex;
    gap: var(--sp-4);
    padding: var(--sp-3) var(--sp-4);
    border-top: 1px solid var(--bg-2);
    font-size: 0.75rem;
    color: var(--ink-soft);
}

/* Dark mode overrides for command palette */

/* ── Print ──────────────────────────────────────────────────────────────── */

@media print {
    .shell-topbar,
    .shell-sidebar,
    .shell-footer {
        display: none;
    }

    .shell-layout {
        margin-top: 0;
    }

    .shell-main {
        padding: 0;
    }
}

/* ==========================================================================
   RTL Support — Arabic (dir="rtl")
   Flips directional properties for the shell layout.
   ========================================================================== */

html[dir="rtl"] .shell-topbar {
    direction: rtl;
}
html[dir="rtl"] .shell-search-hint {
    margin-left: 0;
    margin-right: var(--sp-1, 0.25rem);
}

/* Sidebar RTL */
html[dir="rtl"] .shell-sidebar {
    left: auto;
    right: 0;
    border-left: 1px solid var(--line, rgba(0,59,122,0.1));
    border-right: none;
}
html[dir="rtl"] .shell-sidebar__link {
    border-left: none;
    border-right: 2px solid transparent;
    text-align: right;
}
html[dir="rtl"] .shell-sidebar__link--active {
    border-right-color: var(--brand-teal, #27A9B8);
    border-left-color: transparent;
}

/* Dropdown RTL */
html[dir="rtl"] .shell-dropdown {
    left: 0;
    right: auto;
}

/* The two bells' panels and badges are placed by LOGICAL properties (they were inline `right`, which beat the old
   right-to-left rule and sent the panel off the window's left edge in Arabic). Opaque, and never wider than the window.
   Their position, size and the badges' place and size were inline in the two bell templates and moved here at the same values
   (UX stage 6, Task 8: an inline declaration cannot be beaten without `!important`, so a phone's rules could not place them);
   from 768px up nothing moves. phone.css hangs the panels from the window under 768px. */
.notification-dropdown,
.admin-notification-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    inset-inline-end: 0;
    max-width: calc(100vw - 16px);
    background: var(--panel-drop-bg);
}
.notification-dropdown {
    width: 320px;
    max-height: 400px;
}
.admin-notification-dropdown {
    width: 360px;
    max-height: 440px;
}
/* The two badges: the WHOLE look the two templates' inline styles held (they printed it on the first paint, while the 30-second poll
   swaps in a bare `<span class="notification-badge">` from platform/views.py, so the badge a person saw after the first poll was never
   the one the template drew). One look now, whichever draws it. `.shell-actions .x` (0,2,0) beats site.css's `.notification-badge`
   (0,1,0: its 0.7rem size, its display, its margin-left) on the polled badge as the inline style did on the first paint. site.css's own
   Arabic rule `html[dir="rtl"] .notification-badge { right: auto; left: -6px }` (0,2,1) is older, is not changed here, and still beats
   `inset-inline-end` on an Arabic page: the badge stands 6 px past the button's corner there, as it did before this move. */
.shell-actions .notification-badge,
.shell-actions .admin-notification-badge {
    position: absolute;
    top: -4px;
    inset-inline-end: -4px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: var(--radius-full, 100px);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
}
.shell-actions .notification-badge {
    background: var(--danger, #c62828);
}
.shell-actions .admin-notification-badge {
    background: var(--brand-primary, #0072BC);
}

/* The toast container (it was inline in toast_container.html; the physical `right` is kept on purpose: its Arabic place does not
   move from 768px up, and phone.css gives a phone both edges). */
#ws-toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: var(--z-toast, 10400);
    width: 380px;
}

/* Content area RTL */
html[dir="rtl"] .shell-main {
    direction: rtl;
    text-align: right;
}

/* Bottom tabs RTL */
html[dir="rtl"] .shell-bottom-tabs {
    direction: rtl;
}

/* Empty state RTL */
html[dir="rtl"] .ed-empty-state {
    direction: rtl;
    text-align: center;
}
html[dir="rtl"] .ed-empty-state__clause {
    direction: rtl;
}

/* KPI card RTL */
html[dir="rtl"] .kpi-card {
    direction: rtl;
}

/* Font override for Arabic */
html[dir="rtl"] body,
html[dir="rtl"] .shell-tab__label,
html[dir="rtl"] .shell-sidebar__label,
html[dir="rtl"] .shell-dropdown__item {
    font-family: var(--font-ar, 'IBM Plex Sans Arabic', 'DM Sans', sans-serif);
}

/* ── Mobile sidebar opener ────────────────────────────────────────────────
   The panel is translated off-screen below 1024px and .shell-sidebar--open
   brings it back. Nothing ever applied that class, so every drill-down
   module was unreachable on a phone or a narrow tablet. This is the control
   that applies it; it lives outside the panel, because a button inside
   something translated off-screen cannot be pressed.
   ---------------------------------------------------------------------- */
.shell-sidebar__mobile-toggle {
    display: none;
    position: fixed;
    left: var(--sp-3, 12px);
    bottom: var(--sp-3, 12px);
    z-index: 45;                 /* above the panel (40), below any modal */
    width: 44px;                 /* a real touch target */
    height: 44px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border, #e3e8f0);
    border-radius: 50%;
    background: #ffffff;
    color: var(--brand-navy, #0f2b5b);
    font-size: 1.15rem;
    box-shadow: 0 3px 12px rgba(15, 43, 91, .18);
    cursor: pointer;
}

.shell-sidebar__mobile-toggle:focus-visible {
    outline: 2px solid var(--brand-primary, #0072BC);
    outline-offset: 2px;
}

.shell-sidebar__backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 39;                 /* directly under the panel */
    background: rgba(15, 43, 91, .32);
}

@media (max-width: 1023px) {
    .shell-sidebar__mobile-toggle {
        display: flex;
    }

    /* the round button stands at the right on an Arabic page, on the side of its panel (the messenger's button takes the
       other corner there: see widget.css) */
    html[dir="rtl"] .shell-sidebar__mobile-toggle {
        left: auto;
        right: var(--sp-3, 12px);
    }

    .shell-sidebar__backdrop {
        display: block;
    }
}

@media (max-width: 767px) {
    /* Clear of the bottom tab bar. */
    .shell-sidebar__mobile-toggle {
        bottom: 68px;
    }
}

/* ── Language switcher ────────────────────────────────────────────────────
   Arabic is a first-class locale here and was reachable only from the public
   site and the retired legacy shell, so nobody signed in could get to it.
   ---------------------------------------------------------------------- */
.shell-lang { display: inline-flex; margin: 0 4px; }

.shell-lang__btn {
    min-width: 34px;
    height: 34px;
    padding: 0 8px;
    border: 1px solid var(--border, #e3e8f0);
    border-radius: 8px;
    background: #ffffff;
    color: var(--brand-navy, #0f2b5b);
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    line-height: 1;
}

.shell-lang__btn:hover { background: #f4f7fb; }

.shell-lang__btn:focus-visible {
    outline: 2px solid var(--brand-primary, #0072BC);
    outline-offset: 2px;
}

/* ── Active workspace, and the way out of it ──────────────────────────────
   A role can carry several streams and a stream narrows what you can reach,
   so someone with two of them was locked into half their permissions for the
   session with nothing on screen saying so. This existed in the legacy
   sidebar and was never carried into this shell.
   ---------------------------------------------------------------------- */
.shell-stream {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    margin-right: 4px;
    border: 1px solid var(--border, #e3e8f0);
    border-radius: 999px;
    background: #f4f7fb;
    max-width: 220px;
}

.shell-stream .stream-indicator__dot {
    width: 7px; height: 7px; flex-shrink: 0;
    border-radius: 50%;
    background: var(--brand-primary, #0072BC);
}

.shell-stream .stream-indicator__text {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
    min-width: 0;
}

.shell-stream .stream-indicator__role {
    font-size: 0.6875rem;
    color: var(--ink-soft, #5a6270);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.shell-stream .stream-indicator__stream {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--brand-navy, #0f2b5b);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Superusers only. Quieter than the role above it: it is a footnote to the
   workspace, not another thing to read every time. */
.shell-stream .stream-indicator__note {
    font-size: 0.625rem;
    color: var(--ink-muted, #94a3b8);
    font-style: italic;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.shell-clear-workspace { display: inline-flex; margin-right: 4px; }

/* The indicator is the first thing to go when the bar gets tight; the button
   that escapes the workspace is the last. */
@media (max-width: 900px) {
    .shell-stream { display: none; }
}

/* ── Report an issue: the top bar's button from 768px up ──────────────────
   On a phone the header's button is hidden and nothing floats: Report an issue is a tile of the centre
   button's sheet (base_shell.html, the block report_fab; phone.css). */
.shell-report-btn { gap: var(--sp-1); font-weight: 600; color: var(--brand-primary); }
.shell-report-btn .shell-report-label { font-size: 0.8rem; }

@media (max-width: 767px) {
    .shell-report-btn { display: none; }
}

/* Below 1500px the labelled button squeezes the tab strip (Operations / People /
   Tools clip at 1280px); the icon alone keeps the title and aria-label. */
@media (max-width: 1499px) {
    .shell-report-btn .shell-report-label { display: none; }
}

@media print { .shell-report-btn { display: none; } }

/* A finger (stage 5, D7): the bell, the picture, the bell's panel and the account menu are at least 44 by 44. These controls show
   below 768px too, so this block stands in this sheet: menu.css holds only rules from 768px up. */
@media (pointer: coarse) {
    .notification-bell-btn,
    .admin-notification-bell-btn,
    .shell-user-chip {
        min-height: 44px;
        min-width: 44px;
        justify-content: center;
    }

    .notification-dropdown__inbox,
    .notification-dropdown__action,
    .notification-dropdown .notification-item,
    .shell-dropdown__item {
        min-height: 44px;
        min-width: 44px;
    }

    .notification-dropdown__action {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* A display rule beats the hidden attribute (there is no global [hidden] rule): "Enable desktop alerts" stays hidden
       until notifications.js shows it. */
    .notification-dropdown__action[hidden] {
        display: none;
    }
}
