/* Side menu ("Royal card"): brand, search, page groups, language button, profile menu (sign out),
   collapsed icon rail, hover labels, phone drawer and top bar. */


.nav-toggle { position: absolute; opacity: 0; pointer-events: none; }

.nav-scrim, .sidebar-close { display: none; }

body:has(.app-sidebar) { padding-inline-start: calc(var(--sidebar-width) + var(--sidebar-gap) * 2); transition: padding 0.3s cubic-bezier(.2, .8, .2, 1); }

body:has(.app-sidebar) header.app-topbar { display: none; }

/* The card */
.app-sidebar {
    position: fixed;
    top: var(--sidebar-gap);
    bottom: var(--sidebar-gap);
    inset-inline-start: var(--sidebar-gap);
    z-index: 40;
    width: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    border-radius: 22px;
    background: var(--ep-primary-strong);
    color: var(--white);
    box-shadow: 0 24px 50px -24px rgb(15 35 90 / 55%), 0 2px 6px rgb(15 35 90 / 15%);
    overflow: hidden;
    transition: width 0.3s cubic-bezier(.2, .8, .2, 1), transform 0.35s cubic-bezier(.2, .8, .2, 1), visibility 0.35s;
}

/* Brand */
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 16px 16px 12px; }

.brand-mark { width: 34px; height: 34px; flex: none; display: grid; place-items: center; border-radius: 10px; background: var(--ep-accent); color: var(--ep-primary-strong); font: 700 17px/1 var(--ep-font); }

.brand-text { min-width: 0; flex: 1; }

.brand-text strong { display: block; font-size: 17px; font-weight: 800; letter-spacing: 0.2px; }

.brand-text small { display: block; color: rgb(255 255 255 / 65%); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-collapse {
    flex: none; width: 32px; height: 32px; display: grid; place-items: center; padding: 0; cursor: pointer;
    border: 1px solid rgb(255 255 255 / 20%); border-radius: 10px; background: rgb(255 255 255 / 8%); color: var(--white);
    transition: background 0.2s ease, transform 0.3s ease;
}

.sidebar-collapse:hover { background: rgb(255 255 255 / 18%); }

.sidebar-collapse svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

html[dir=rtl] .sidebar-collapse svg { transform: scaleX(-1); }

html.nav-collapsed .sidebar-collapse { transform: rotate(180deg); }

/* Avatar and name, used by the profile button at the bottom */
.sidebar-avatar { width: 34px; height: 34px; flex: none; display: grid; place-items: center; border-radius: 50%; background: rgb(255 255 255 / 16%); color: var(--white); }
.sidebar-avatar svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.sidebar-user-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.35; text-align: start; }
.sidebar-user-text strong { font-size: 14.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-text small { color: rgb(255 255 255 / 66%); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-text small:empty { display: none; }

/* Page groups */
.app-nav { flex: 1; display: flex; flex-direction: column; gap: 2px; padding: 6px 12px 12px; overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; }

.nav-home { padding: 2px 0; display: flex; flex-direction: column; gap: 2px; }

.nav-group-title {
    width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 14px;
    padding: 4px 12px; border: 0; background: none; cursor: pointer; text-align: start; border-radius: 8px;
    color: rgb(255 255 255 / 68%); font: 800 12.5px/1.3 var(--ep-font); letter-spacing: 0.04em;
}

.nav-group-title:hover { color: var(--white); }
.nav-group-title:hover .nav-chevron, .nav-group-closed .nav-chevron, .nav-group-title:focus-visible .nav-chevron { opacity: 1; }

.nav-group-title:focus-visible { outline: 2px solid var(--ep-accent); outline-offset: 1px; }

.nav-chevron { opacity: 0; width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform 0.25s ease; }

.nav-group-closed .nav-chevron { transform: rotate(-90deg); }

html[dir=rtl] .nav-group-closed .nav-chevron { transform: rotate(90deg); }

.nav-group-links { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; max-height: 420px; overflow: hidden; transition: max-height 0.35s ease, opacity 0.25s ease; }

.nav-group-closed .nav-group-links { max-height: 0; opacity: 0; }

.app-nav a {
    position: relative; display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 9px 12px; border-radius: 12px;
    color: rgb(255 255 255 / 90%); font-size: 15.5px; font-weight: 700; letter-spacing: 0.1px; text-decoration: none; white-space: nowrap;
    transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.app-nav a:hover, .app-nav a:focus-visible { background: rgb(255 255 255 / 12%); color: var(--white); transform: translateX(var(--nudge)); outline: none; }

.app-nav a.active-nav { background: var(--white); color: var(--ep-primary-strong); box-shadow: 0 10px 22px -10px rgb(10 25 70 / 60%); transform: none; }

.app-nav a.active-nav .nav-icon { color: var(--ep-primary); }

.nav-label { overflow: hidden; text-overflow: ellipsis; }

.nav-icon { width: 21px; height: 21px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* Profile menu at the bottom: one button that opens sign out. */
.sidebar-profile { position: relative; padding: 10px 12px 12px; border-top: 1px solid rgb(255 255 255 / 10%); }
.profile-menu > summary { list-style: none; }
.profile-menu > summary::-webkit-details-marker { display: none; }
.profile-button {
    display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 12px; cursor: pointer;
    color: var(--white); transition: background 0.2s ease;
}
.profile-button:hover, .profile-menu[open] > .profile-button { background: rgb(255 255 255 / 10%); }
.profile-button:focus-visible { outline: 2px solid var(--ep-accent); outline-offset: 1px; }
.profile-chevron { width: 16px; height: 16px; flex: none; fill: none; stroke: rgb(255 255 255 / 60%); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.profile-popover {
    position: absolute; inset-inline: 12px; bottom: calc(100% - 4px); z-index: 5;
    display: flex; flex-direction: column; gap: 4px; padding: 8px;
    background: var(--ep-surface); color: var(--text); border: 1px solid var(--ep-border);
    border-radius: 14px; box-shadow: var(--shadow-xl);
    animation: ep-popover-in 0.18s var(--ease-out) both;
}
@keyframes ep-popover-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.profile-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 10px; border-radius: 10px; }
.profile-row + .profile-row { border-top: 1px solid var(--ep-border); border-radius: 0; }
.profile-label { font-size: 13px; font-weight: 600; color: var(--ep-muted); }
body:has(.app-sidebar) .app-sidebar .profile-popover .language-switch-link {
    color: var(--ep-primary); border: 1px solid var(--ep-primary-border); background: var(--ep-primary-soft); padding: 4px 12px; font-size: 13px;
}
body:has(.app-sidebar) .app-sidebar .profile-popover .language-switch-link:hover { background: var(--ep-primary); color: var(--white); border-color: var(--ep-primary); }
.profile-popover .sidebar-logout {
    display: flex; align-items: center; gap: 10px; margin-top: 4px; padding: 10px; border-radius: 10px;
    color: var(--status-danger); font-size: 14px; font-weight: 600; text-decoration: none; border-top: 1px solid var(--ep-border);
}
.profile-popover .sidebar-logout:hover, .profile-popover .sidebar-logout:focus-visible { background: var(--status-danger-soft); outline: none; }
.profile-popover .sidebar-logout .nav-icon { width: 18px; height: 18px; }
html[dir=rtl] .sidebar-logout .nav-icon, html[dir=rtl] .topbar-logout .nav-icon { transform: scaleX(-1); }










/* Entrance animation, once per browser session (html.nav-intro is set by the menu script). */
@keyframes ep-nav-in { from { opacity: 0; transform: translateX(calc(var(--nudge) * -4)); } to { opacity: 1; transform: none; } }

@keyframes ep-card-in { from { opacity: 0; transform: translateX(calc(var(--nudge) * -6)) scale(0.98); } to { opacity: 1; transform: none; } }

html.nav-intro .app-sidebar { animation: ep-card-in 0.5s cubic-bezier(.2, .8, .2, 1) both; }

html.nav-intro .nav-group,
html.nav-intro .sidebar-profile { animation: ep-nav-in 0.45s cubic-bezier(.2, .8, .2, 1) both; }


html.nav-intro .nav-group:nth-child(1) { animation-delay: 0.18s; }

html.nav-intro .nav-group:nth-child(2) { animation-delay: 0.24s; }

html.nav-intro .nav-group:nth-child(3) { animation-delay: 0.30s; }

html.nav-intro .sidebar-profile { animation-delay: 0.36s; }


@media (min-width: 1025px) {
    html.nav-collapsed .brand-text,
    html.nav-collapsed .sidebar-user-text,
    html.nav-collapsed .sidebar-logout-label,
    html.nav-collapsed .nav-label,
    html.nav-collapsed .nav-group-title { display: none; }
    html.nav-collapsed .sidebar-brand { flex-direction: column; gap: 10px; padding-inline: 0; }
    html.nav-collapsed .sidebar-collapse { width: var(--rail-tile); height: var(--rail-tile); min-width: 0; padding: 0; border-radius: 15px; display: grid; place-items: center; }
    html.nav-collapsed .sidebar-avatar { background: rgb(255 255 255 / 12%); color: var(--white); border: 1px solid rgb(255 255 255 / 22%); box-shadow: none; }
    html.nav-collapsed .sidebar-avatar svg,
    html.nav-collapsed .sidebar-collapse svg { width: 22px; height: 22px; }
    html.nav-collapsed .app-nav { padding-inline: 0; align-items: center; gap: 4px; }
    html.nav-collapsed .nav-home,
    html.nav-collapsed .nav-group,
    html.nav-collapsed .nav-group-links { align-items: center; width: 100%; }
    html.nav-collapsed .nav-group-links { gap: 4px; }
    html.nav-collapsed .nav-group-closed .nav-group-links { max-height: 420px; opacity: 1; }
    html.nav-collapsed .nav-group { margin-top: 6px; padding-top: 10px; border-top: 1px solid rgb(255 255 255 / 14%); width: 56px; }
    html.nav-collapsed .app-nav a { width: var(--rail-tile); height: var(--rail-tile); min-height: 0; padding: 0; justify-content: center; border-radius: 15px; }
    html.nav-collapsed .app-nav a .nav-icon { width: var(--rail-icon); height: var(--rail-icon); stroke-width: 1.8; }
    html.nav-collapsed .app-nav a:hover,
    html.nav-collapsed .app-nav a:focus-visible { transform: scale(1.06); background: rgb(255 255 255 / 16%); }
    html.nav-collapsed .app-nav a.active-nav { transform: none; }
    html.nav-collapsed .app-nav a.active-nav::before {
        content: ""; position: absolute; inset-inline-start: -12px; top: 12px; bottom: 12px; width: 4px; border-radius: 4px; background: var(--ep-accent);
    }
    /* Collapsed rail: the profile button is just the avatar; its menu opens beside the rail. */
    html.nav-collapsed .profile-chevron { display: none; }
    html.nav-collapsed .sidebar-profile { padding: 10px 0 12px; display: flex; justify-content: center; }
    html.nav-collapsed .profile-button { padding: 6px; }
    html.nav-collapsed .app-sidebar:has(.profile-menu[open]) { overflow: visible; }
    html.nav-collapsed .profile-popover { inset-inline: auto; inset-inline-start: calc(100% + 14px); bottom: 8px; width: 260px; }
}

.app-sidebar { --globe: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='8.5'/%3E%3Cpath d='M3.5 12h17M12 3.5c2.4 2.3 3.6 5.1 3.6 8.5s-1.2 6.2-3.6 8.5c-2.4-2.3-3.6-5.1-3.6-8.5s1.2-6.2 3.6-8.5z'/%3E%3C/svg%3E"); }

/* Hover label bubble (created by the menu script, positioned next to the hovered icon). */
.nav-tooltip {
    position: fixed; z-index: 1000; transform: translate(-6px, -50%); opacity: 0; pointer-events: none;
    padding: 8px 12px; border-radius: 10px; background: #14204a; color: #fff; font-size: 13.5px; font-weight: 700; white-space: nowrap;
    box-shadow: 0 12px 26px -12px rgb(10 20 60 / 70%); transition: opacity .15s ease, transform .15s ease;
}

.nav-tooltip::before {
    content: ""; position: absolute; top: 50%; inset-inline-start: -5px; width: 10px; height: 10px; background: inherit;
    transform: translateY(-50%) rotate(45deg); border-radius: 2px;
}

.nav-tooltip.is-rtl { transform: translate(6px, -50%); }

.nav-tooltip.is-visible { opacity: 1; transform: translate(0, -50%); }


@media (prefers-reduced-motion: reduce) {
 .nav-tooltip { transition: none; }
}

/* The page header (title of each page) as a clean strip next to the card. */
body:has(.app-sidebar) header:not(.app-topbar) {
    background: var(--ep-surface);
    color: var(--ep-heading);
    border: 1px solid var(--ep-border);
    border-radius: 18px;
    margin: var(--sidebar-gap) var(--sidebar-gap) 0 0;
    margin-inline: 0 var(--sidebar-gap);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    padding-block: 16px;
}

body:has(.app-sidebar) header:not(.app-topbar) h1 { color: var(--ep-heading); }

body:has(.app-sidebar) header:not(.app-topbar) p { color: var(--ep-muted); }

body:has(.app-sidebar) header:not(.app-topbar) .header-brand strong { display: none; }

body:has(.app-sidebar) header:not(.app-topbar) a { color: var(--ep-primary); }

body:has(.app-sidebar) header:not(.app-topbar) input[type=submit] { background: var(--ep-surface); color: var(--ep-heading); border: 1px solid var(--ep-border); }

body:has(.app-sidebar) .page-step-badge { background: var(--ep-primary-soft); color: var(--ep-primary); border-color: var(--ep-primary-border); }



@media (prefers-reduced-motion: reduce) {
    html.nav-intro .app-sidebar, html.nav-intro .nav-group, html.nav-intro .sidebar-profile { animation: none; }
    .app-sidebar, .app-nav a, .nav-group-links, body:has(.app-sidebar) { transition: none; }
}

.language-switch-link {
    color: var(--white);
    border: 1px solid rgba(255, 255, 255, 0.55);
    border-radius: 999px;
    padding: 4px 14px;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}

.language-switch-link:hover { background: rgba(255, 255, 255, 0.14); }

.language-switch-link:focus-visible { outline: 3px solid var(--adalo-gold); outline-offset: 2px; }



/* ---------- Responsive layout: drawer menu below 1024px, single column and scrollable tables on phones ---------- */
@media (max-width: 1024px) {
    body:has(.app-sidebar) { padding-inline-start: 0; padding-top: 60px; }
    body:has(.app-sidebar) header.app-topbar {
        position: fixed; inset-inline: 0; top: 0; z-index: 38; height: 60px; margin: 0; padding: 0 12px;
        display: flex; align-items: center; justify-content: flex-start; flex-wrap: nowrap; gap: 10px;
        background: var(--ep-primary-strong); color: var(--white); border: 0; border-radius: 0; box-shadow: 0 2px 12px rgb(15 23 42 / 20%);
    }
    .app-topbar .nav-burger { display: grid; place-items: center; width: 42px; height: 42px; flex: none; border-radius: 11px; background: rgb(255 255 255 / 12%); cursor: pointer; }
    .nav-burger-lines, .nav-burger-lines::before, .nav-burger-lines::after { display: block; width: 20px; height: 2px; border-radius: 2px; background: var(--white); content: ''; position: relative; }
    .nav-burger-lines::before { position: absolute; top: -6px; }
    .nav-burger-lines::after { position: absolute; top: 6px; }
    .topbar-brand { display: flex; align-items: center; gap: 8px; }
    .app-topbar .topbar-brand strong { margin: 0; color: var(--white); font: 700 17px/1.2 var(--ep-font); }
    .app-topbar .brand-mark { width: 34px; height: 34px; font-size: 16px; }
    .topbar-spacer { flex: 1; }
    body:has(.app-sidebar) .app-topbar .topbar-logout { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 11px; border: 1px solid rgb(255 255 255 / 40%); color: var(--white); }
    body:has(.app-sidebar) .app-topbar .topbar-logout:hover { background: #dc2626; border-color: #dc2626; }
    .topbar-logout .nav-icon { width: 19px; height: 19px; }
    .app-sidebar { top: 10px; bottom: 10px; inset-inline-start: 10px; z-index: 50; width: min(84vw, 300px); transform: translateX(var(--drawer-hidden)); visibility: hidden; }
    .nav-toggle:checked ~ .app-sidebar { transform: none; visibility: visible; }
    .nav-toggle:checked ~ .nav-scrim { display: block; position: fixed; inset: 0; z-index: 45; background: rgb(15 23 42 / 45%); backdrop-filter: blur(2px); }
    .sidebar-collapse { display: none; }
    .sidebar-close { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; font-size: 22px; line-height: 1; color: var(--white); background: rgb(255 255 255 / 12%); cursor: pointer; }
    body:has(.app-sidebar) header:not(.app-topbar) { margin: 12px; }
}


/* Language button: always visible above the profile menu (and in the phone top bar). */
.sidebar-language {
    display: flex; align-items: center; gap: 10px; margin: 0 0 8px; padding: 6px 8px; border-radius: 12px;
    background: rgb(255 255 255 / 8%); border: 1px solid rgb(255 255 255 / 14%); color: var(--white);
}
.sidebar-language > .nav-icon { width: 20px; height: 20px; flex: none; opacity: 0.85; }
.sidebar-language .language-switch { flex: 1; display: flex; }
body:has(.app-sidebar) .sidebar-language .language-switch-link {
    flex: 1; text-align: center; padding: 7px 14px; font-size: 14.5px; font-weight: 700; color: var(--white);
    border: 1px solid rgb(255 255 255 / 40%); background: transparent; border-radius: 999px; transition: background 0.2s ease, color 0.2s ease;
}
body:has(.app-sidebar) .sidebar-language .language-switch-link:hover { background: var(--white); color: var(--ep-primary-strong); }
.topbar-language { display: none; }
@media (min-width: 1025px) {
    html.nav-collapsed .sidebar-language { flex-direction: column; justify-content: center; padding: 6px 4px; margin-inline: auto; width: var(--rail-tile); background: none; border: 0; }
    html.nav-collapsed .sidebar-language > .nav-icon { display: none; }
    html.nav-collapsed .sidebar-language .language-switch-link { padding: 8px 0; font-size: 12.5px; width: var(--rail-tile); overflow: hidden; text-overflow: clip; }
}
@media (max-width: 1024px) {
    .topbar-language { display: inline-flex; }
    body:has(.app-sidebar) .app-topbar .language-switch-link { padding: 7px 12px; font-size: 13.5px; font-weight: 700; color: var(--white); border-color: rgb(255 255 255 / 50%); }
}
/* Small phones: the logo mark is enough; leaves room for language, search and sign out. */
@media (max-width: 420px) {
    .app-topbar .topbar-brand strong { display: none; }
    body:has(.app-sidebar) header.app-topbar { gap: 8px; padding: 0 10px; }
}
