/* ===========================================================================
   Ayan Design System — the Calm Ledger shell (W19, the approved prototype ayan-redesign.html)
   ---------------------------------------------------------------------------
   The frame around every page: a light navigation rail (icons, and labels from
   1280px), a quiet top bar (company · branch, "search or go to", notifications,
   the user's initials), the workspace's pages as tabs, and on a phone a bottom
   bar with a create button. Built on the Calm tokens (calm.css), which follow
   the company theme and dark appearance.
   =========================================================================== */

.calm-shell {
    --calm-rail-w: 72px;
    --calm-accent-soft: color-mix(in srgb, var(--ayan-color-action) 12%, var(--ayan-color-surface));
    display: flex;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--calm-canvas);
    color: var(--calm-ink);
    font-size: var(--calm-fs);
}
@media (min-width: 1280px) { .calm-shell { --calm-rail-w: 232px; } }

/* ——— Rail ——— */
.calm-rail {
    position: sticky; top: 0; height: 100vh; height: 100dvh; flex: 0 0 var(--calm-rail-w); width: var(--calm-rail-w);
    display: flex; flex-direction: column;
    background: var(--calm-surface); border-inline-end: 1px solid var(--calm-line);
    z-index: 40;
}
.calm-rail__brand {
    display: flex; align-items: center; gap: 12px; height: 60px; padding-inline: 16px; flex-shrink: 0;
    color: var(--calm-ink); text-decoration: none; font-weight: 700; font-size: calc(var(--calm-fs) * 1.07);
}
.calm-rail__brand:hover { color: var(--calm-ink); }
.calm-mark {
    width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0; display: inline-grid; place-items: center;
    background: var(--ayan-color-action); color: var(--ayan-color-on-action); font-weight: 700; font-size: 15px; line-height: 1;
}
.calm-rail__close { position: absolute; top: 11px; inset-inline-end: 10px; }
.calm-rail__items { display: flex; flex-direction: column; gap: 4px; padding: 8px 12px; flex: 1; overflow-y: auto; scrollbar-width: thin; }
.calm-rail__foot { padding: 8px 12px 16px; border-top: 1px solid var(--calm-line); }
.calm-nav-item {
    display: flex; align-items: center; gap: 12px; height: 40px; padding-inline: 12px; border-radius: var(--calm-r-m);
    color: var(--calm-ink-2); font-weight: 500; white-space: nowrap; text-decoration: none;
    transition: background-color 120ms ease, color 120ms ease;
}
.calm-nav-item:hover { background: var(--calm-sunken); color: var(--calm-ink); }
.calm-nav-item[aria-current="page"] { background: var(--calm-accent-soft); color: var(--ayan-color-action); font-weight: 600; }
.calm-nav-item:focus-visible, .calm-tab:focus-visible, .calm-icon-btn:focus-visible, .calm-menu-item:focus-visible {
    outline: 2px solid var(--ayan-color-action); outline-offset: 2px;
}
.calm-nav-item svg { flex-shrink: 0; }
.calm-rail__label { display: none; }
@media (min-width: 1280px) { .calm-rail__label { display: inline; overflow: hidden; text-overflow: ellipsis; } }
@media (max-width: 1279px) { .calm-rail__brand, .calm-nav-item { justify-content: center; padding-inline: 0; } }

/* The full menu: on a phone the rail opens as a drawer listing every page of every workspace. */
.calm-rail__pages { display: none; }
.calm-shell__backdrop { display: none; }

/* ——— Main column and top bar ——— */
.calm-shell__main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.calm-topbar {
    position: sticky; top: 0; z-index: 30; height: 60px; display: flex; align-items: center; gap: 8px;
    padding-inline: 24px; border-bottom: 1px solid var(--calm-line);
    background: color-mix(in srgb, var(--calm-canvas) 88%, transparent); backdrop-filter: blur(10px);
}
.calm-topbar__spacer { flex: 1; }
.calm-topbar__mark { display: none; }
.calm-topbar__actions { display: flex; align-items: center; gap: 6px; }

.calm-icon-btn {
    position: relative; width: 38px; height: 38px; display: inline-grid; place-items: center; border: 0; border-radius: var(--calm-r-m);
    background: transparent; color: var(--calm-ink-2); cursor: pointer; list-style: none; text-decoration: none;
}
.calm-icon-btn:hover { background: var(--calm-sunken); color: var(--calm-ink); }
.calm-icon-btn::-webkit-details-marker, .calm-popover-host > summary::-webkit-details-marker { display: none; }
.calm-dot { position: absolute; top: 8px; inset-inline-end: 8px; width: 8px; height: 8px; border-radius: 99px; background: var(--ayan-tone-danger); }

/* Popovers are <details>: they open on a click without a script and close on a second one. */
.calm-popover-host { position: relative; }
.calm-popover-host > summary { list-style: none; cursor: pointer; }
.calm-popover {
    position: absolute; top: calc(100% + 6px); inset-inline-end: 0; z-index: 60; min-width: 240px; padding: 8px;
    background: var(--calm-surface); border-radius: var(--calm-r-l); box-shadow: var(--calm-shadow-2); color: var(--calm-ink);
    animation: calm-rise 160ms ease-out;
}
.calm-popover--start { inset-inline-end: auto; inset-inline-start: 0; }
.calm-popover__eyebrow { font-size: var(--calm-fs-xs); font-weight: 600; color: var(--calm-muted); padding: 4px 8px 8px; }
.calm-popover__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 8px 6px; font-weight: 600; }
.calm-popover__sep { height: 1px; margin: 4px 0; background: var(--calm-line); border: 0; }
.calm-menu-item {
    display: flex; align-items: center; gap: 10px; width: 100%; min-height: 36px; padding: 6px 10px; border: 0; border-radius: 8px;
    background: transparent; color: var(--calm-ink); font: inherit; font-size: var(--calm-fs-m); text-align: start; text-decoration: none; cursor: pointer;
}
.calm-menu-item:hover, .calm-menu-item.is-active { background: var(--calm-sunken); color: var(--calm-ink); }
.calm-menu-item__meta { color: var(--calm-faint); font-size: var(--calm-fs-xs); }
.calm-menu-item--current { font-weight: 600; }

/* Company and branch: one chip. */
.calm-context > summary {
    display: inline-flex; align-items: center; gap: 8px; height: 38px; padding-inline: 10px; border-radius: var(--calm-r-m);
    color: var(--calm-ink); min-width: 0; max-width: min(460px, 52vw);
}
.calm-context > summary:hover { background: var(--calm-sunken); }
.calm-context__company { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.calm-context__branch { color: var(--calm-ink-2); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.calm-context__sep { color: var(--calm-faint); }
.calm-context .calm-popover { width: 280px; }

/* "Search or go to": looks like a field, opens the palette. */
.calm-search-trigger {
    display: flex; align-items: center; gap: 8px; width: min(360px, 34vw); height: 38px; padding-inline: 12px; border: 0;
    border-radius: var(--calm-r-m); background: var(--calm-surface); box-shadow: inset 0 0 0 1px var(--calm-line-strong);
    color: var(--calm-faint); font: inherit; cursor: pointer; text-align: start;
}
.calm-search-trigger:hover { box-shadow: inset 0 0 0 1px var(--ayan-color-action); }
.calm-search-trigger__text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.calm-kbd { font-family: ui-monospace, Consolas, monospace; font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--calm-sunken); color: var(--calm-muted); direction: ltr; }

.calm-avatar {
    width: 36px; height: 36px; border-radius: 99px; display: grid; place-items: center; flex-shrink: 0;
    background: var(--calm-sunken); color: var(--calm-ink-2); font-weight: 600; font-size: 13px;
}
.calm-user .calm-popover { width: 260px; }
.calm-user__name { font-weight: 600; padding: 4px 10px 0; }
.calm-user__mail { color: var(--calm-faint); font-size: var(--calm-fs-xs); padding: 0 10px 6px; direction: ltr; text-align: start; unicode-bidi: plaintext; overflow-wrap: anywhere; }

/* Notifications */
.calm-bell .calm-popover { width: min(340px, calc(100vw - 24px)); max-height: 70vh; overflow-y: auto; }
.calm-notice-item { align-items: flex-start; }
.calm-notice-item__dot { margin-top: 7px; width: 8px; height: 8px; border-radius: 99px; flex-shrink: 0; background: var(--calm-line-strong); }
.calm-notice-item.is-unread .calm-notice-item__dot { background: var(--ayan-color-action); }
.calm-notice-item__text { display: flex; flex-direction: column; min-width: 0; }
.calm-link-btn { border: 0; background: none; padding: 0; color: var(--ayan-color-action); font: inherit; font-size: var(--calm-fs-s); cursor: pointer; }

/* ——— Content and workspace tabs ——— */
.calm-shell__content { flex: 1; width: 100%; max-width: 1344px; margin-inline: auto; padding: 32px 32px 48px; min-width: 0; }
.calm-tabs {
    display: flex; align-items: center; gap: 4px; border-bottom: 1px solid var(--calm-line); margin-bottom: 24px;
    overflow-x: auto; scrollbar-width: none;
}
.calm-tabs::-webkit-scrollbar { display: none; }
.calm-tab {
    position: relative; display: inline-flex; align-items: center; height: 42px; padding-inline: 12px; white-space: nowrap;
    color: var(--calm-muted); font-weight: 500; text-decoration: none;
}
.calm-tab:hover { color: var(--calm-ink); }
.calm-tab[aria-current="page"] { color: var(--calm-ink); font-weight: 600; }
.calm-tab[aria-current="page"]::after {
    content: ""; position: absolute; inset-inline: 10px; bottom: -1px; height: 2px; border-radius: 2px; background: var(--ayan-color-action);
}
.calm-tabs__more { margin-inline-start: auto; }
.calm-tabs__more > summary { display: inline-flex; align-items: center; gap: 4px; height: 42px; padding-inline: 10px; color: var(--calm-muted); font-weight: 500; }
.calm-tabs__more > summary:hover { color: var(--calm-ink); }
.calm-tabs__more .calm-popover { position: fixed; top: auto; margin-top: 6px; inset-inline-end: 32px; max-height: 60vh; overflow-y: auto; }

/* A Calm register draws its workspace's tabs under its own title, a document page shows none: the shell's strip steps aside. */
.calm-shell__content:has(.ayan-calm) > .calm-tabs--shell { display: none; }
.ayan-calm > .calm-tabs { margin-bottom: 0; }

/* ——— Command palette ——— */
.calm-scrim-shell { position: fixed; inset: 0; z-index: 70; background: rgba(18, 24, 32, 0.32); }
[data-appearance="dark"] .calm-scrim-shell { background: rgba(0, 0, 0, 0.55); }
.calm-palette {
    position: fixed; z-index: 71; top: 12vh; left: 50%; transform: translateX(-50%); width: min(620px, calc(100vw - 32px));
    background: var(--calm-surface); border-radius: var(--calm-r-l); box-shadow: var(--calm-shadow-2); overflow: hidden; color: var(--calm-ink);
    font-size: var(--calm-fs); animation: calm-rise 160ms ease-out;
}
.calm-palette__input-row { display: flex; align-items: center; gap: 12px; height: 56px; padding-inline: 16px; border-bottom: 1px solid var(--calm-line); color: var(--calm-muted); }
.calm-palette__input:focus, .calm-palette__input:focus-visible { outline: none; box-shadow: none; }
.calm-palette__input { flex: 1; border: 0; outline: none; background: transparent; color: var(--calm-ink); font: inherit; font-size: calc(var(--calm-fs) * 1.07); }
.calm-palette__list { max-height: 52vh; overflow-y: auto; padding: 8px; scrollbar-width: thin; }
.calm-palette__group { font-size: var(--calm-fs-xs); font-weight: 600; color: var(--calm-muted); padding: 8px 10px 4px; }
.calm-palette__empty { padding: 24px; text-align: center; color: var(--calm-muted); }
.calm-palette__foot { display: flex; align-items: center; gap: 16px; height: 38px; padding-inline: 16px; border-top: 1px solid var(--calm-line); color: var(--calm-faint); font-size: var(--calm-fs-xs); }
.calm-palette__foot .calm-link-btn { margin-inline-start: auto; }

/* ——— Phone ——— */
.calm-bottombar { display: none; }
@media (max-width: 767.98px) {
    .calm-rail {
        position: fixed; inset-block: 0; inset-inline-start: 0; width: min(300px, 86vw); height: 100vh; height: 100dvh;
        transform: translateX(-105%); transition: transform 200ms ease; box-shadow: var(--calm-shadow-2); z-index: 80;
    }
    [dir="rtl"] .calm-rail { transform: translateX(105%); }
    #ayan-nav-toggle:checked ~ .calm-shell .calm-rail { transform: none; }
    #ayan-nav-toggle:checked ~ .calm-shell .calm-shell__backdrop { display: block; position: fixed; inset: 0; z-index: 79; background: rgba(18, 24, 32, 0.32); }
    .calm-rail__brand, .calm-nav-item { justify-content: flex-start; padding-inline: 12px; }
    .calm-rail__label { display: inline; }
    .calm-rail__items > .calm-nav-item { display: none; }
    .calm-rail__pages { display: flex; flex-direction: column; gap: 2px; }
    .calm-rail__group { font-size: var(--calm-fs-xs); font-weight: 600; color: var(--calm-muted); padding: 12px 12px 4px; }
    .calm-rail__page { display: flex; align-items: center; min-height: 40px; padding-inline: 12px; border-radius: var(--calm-r-m); color: var(--calm-ink-2); text-decoration: none; }
    .calm-rail__page[aria-current="page"] { background: var(--calm-accent-soft); color: var(--ayan-color-action); font-weight: 600; }

    .calm-topbar { padding-inline: 12px; }
    .calm-topbar__mark { display: inline-grid; }
    .calm-context__branch, .calm-context__sep { display: none; }
    .calm-search-trigger { display: none; }
    .calm-shell__content { padding: 24px 16px 150px; }

    .calm-bottombar {
        display: flex; align-items: center; position: fixed; bottom: 0; inset-inline: 0; z-index: 45;
        background: var(--calm-surface); border-top: 1px solid var(--calm-line); padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    .calm-bottombar__item {
        flex: 1; height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; border: 0;
        background: none; color: var(--calm-muted); font: inherit; font-size: 11.5px; font-weight: 500; text-decoration: none; cursor: pointer;
    }
    .calm-bottombar__item[aria-current="page"] { color: var(--ayan-color-action); }
    .calm-bottombar__create { flex: 1; display: flex; justify-content: center; }
    .calm-bottombar__create button {
        width: 46px; height: 46px; border: 0; border-radius: 99px; display: grid; place-items: center; cursor: pointer;
        background: var(--ayan-color-action); color: var(--ayan-color-on-action);
    }
    .calm-tabs__more .calm-popover { inset-inline-end: 16px; }
}
@media (min-width: 768px) { .calm-show-phone { display: none !important; } }
@media (max-width: 767.98px) { .calm-hide-phone { display: none !important; } }

@keyframes calm-rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.calm-palette { animation-name: calm-palette-rise; }
@keyframes calm-palette-rise { from { opacity: 0; transform: translate(-50%, 6px); } to { opacity: 1; transform: translate(-50%, 0); } }
@media (prefers-reduced-motion: reduce) { .calm-popover, .calm-palette, .calm-rail { animation: none; transition: none; } }
@media print { .calm-rail, .calm-topbar, .calm-bottombar, .calm-tabs { display: none !important; } .calm-shell__content { padding: 0; } }

/* Z6: a field the browser scrolls to (focus, Tab, a validation message, "Edit" on a row) stops below the sticky top bar, and on a
   phone above the fixed bottom bar and the page's action bar instead of under them. */
html { scroll-padding-top: 76px; }
@media (max-width: 767.98px) {
    html { scroll-padding-bottom: calc(56px + 4.5rem + env(safe-area-inset-bottom, 0px)); }
}
