/* =====================================================================
   AME shell: fixed dark sidebar, flat top bar, card canvas.
   Same structure as the GravityHR admin portal, in AME's navy and blue.
   Bootstrap 5.3 supplies the base; these tokens restyle it.
   ===================================================================== */

:root {
    --ame-font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
    --ame-font-size: .875rem;
    --ame-font-size-sm: .75rem;

    --ame-sidebar-w: 260px;
    --ame-sidebar-w-collapsed: 64px;
    --ame-topbar-h: 60px;
    --ame-transition: .25s cubic-bezier(.4, 0, .2, 1);

    --ame-accent: #2563eb;
    --ame-accent-rgb: 37, 99, 235;
    --ame-accent-hover: #1d4ed8;

    /* Sidebar: always dark. */
    --ame-sidebar-bg: #0f172a;
    --ame-sidebar-border: #1e293b;
    --ame-sidebar-text: #94a3b8;
    --ame-sidebar-text-hover: #f8fafc;
    --ame-sidebar-section: #64748b;
    --ame-sidebar-hover-bg: #1e293b;
    --ame-sidebar-active-bg: #172554;
    --ame-sidebar-active-text: #60a5fa;
    --ame-sidebar-profile-bg: #1e293b;

    /* Top bar, canvas and cards: light. */
    --ame-canvas: #f8fafc;
    --ame-surface: #ffffff;
    --ame-ink: #0f172a;
    --ame-muted: #64748b;
    --ame-faint: #94a3b8;
    --ame-border: #e2e8f0;
    --ame-head-bg: #f8fafc;
    --ame-row-hover: #eff6ff;
    --ame-input-bg: #ffffff;
    --ame-input-border: #cbd5e1;
    --ame-search-bg: #f1f5f9;
    --ame-danger: #dc2626;
    --ame-shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
    --ame-shadow-lg: 0 12px 40px rgba(15, 23, 42, .14);

    --bs-body-font-family: var(--ame-font);
    --bs-body-font-size: var(--ame-font-size);
    --bs-body-bg: var(--ame-canvas);
    --bs-body-color: var(--ame-ink);
    --bs-primary: var(--ame-accent);
    --bs-primary-rgb: var(--ame-accent-rgb);
    --bs-link-color: var(--ame-accent);
    --bs-link-color-rgb: var(--ame-accent-rgb);
    --bs-link-hover-color: var(--ame-accent-hover);
    --bs-border-radius: .5rem;
    --bs-border-color: var(--ame-border);
    --bs-secondary-color: var(--ame-muted);
    --bs-focus-ring-color: rgba(var(--ame-accent-rgb), .25);
}

[data-bs-theme=dark] {
    --ame-sidebar-bg: #0b1120;
    --ame-sidebar-border: #1e293b;

    --ame-canvas: #0f172a;
    --ame-surface: #1e293b;
    --ame-ink: #f1f5f9;
    --ame-muted: #94a3b8;
    --ame-faint: #64748b;
    --ame-border: #334155;
    --ame-head-bg: #172033;
    --ame-row-hover: rgba(var(--ame-accent-rgb), .14);
    --ame-input-bg: #0f172a;
    --ame-input-border: #475569;
    --ame-search-bg: #0f172a;
    --ame-danger: #f87171;
    --ame-shadow: 0 1px 3px rgba(0, 0, 0, .3);
    --ame-shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);

    --bs-body-bg: var(--ame-canvas);
    --bs-body-color: var(--ame-ink);
    --bs-secondary-color: var(--ame-muted);
    --bs-border-color: var(--ame-border);
    --bs-link-color: #60a5fa;
    --bs-link-color-rgb: 96, 165, 250;
    --bs-link-hover-color: #93c5fd;
}

*, *::before, *::after { box-sizing: border-box; }

/* Headings are not interactive: suppress the focus ring FocusOnNavigate leaves on route changes. */
h1, h2, h3, h4, h5, h6 { outline: none; }

body {
    font-family: var(--ame-font);
    font-size: var(--ame-font-size);
    background: var(--ame-canvas);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.muted { color: var(--ame-muted); }

/* Theme and sidebar switches (state lives on <html>). */
[data-bs-theme=dark] .ame-when-light,
:root:not([data-bs-theme=dark]) .ame-when-dark,
[data-ame-sidebar=collapsed] .ame-when-expanded,
:root:not([data-ame-sidebar=collapsed]) .ame-when-collapsed { display: none !important; }

.ame-skip {
    position: fixed; left: 1rem; top: -60px; z-index: 2000;
    padding: .5rem 1rem; border-radius: .5rem; background: var(--ame-surface); box-shadow: var(--ame-shadow-lg);
}
.ame-skip:focus { top: 1rem; }

/* ---- Brand mark ---- */
.ame-logo {
    flex: 0 0 auto;
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; border-radius: 8px;
    color: #fff; background: var(--ame-accent);
}
.ame-logo svg { width: 20px; height: 20px; }

/* =====================================================================
   Sidebar
   ===================================================================== */
.ame-sidebar {
    position: fixed; z-index: 1040; top: 0; bottom: 0; left: 0;
    width: var(--ame-sidebar-w);
    display: flex; flex-direction: column;
    background: var(--ame-sidebar-bg);
    border-right: 1px solid var(--ame-sidebar-border);
    overflow: hidden;
    transition: width var(--ame-transition), left var(--ame-transition);
}

.ame-sidebar-brand {
    display: flex; align-items: center; gap: .75rem; flex-shrink: 0;
    height: var(--ame-topbar-h); padding: 0 1rem;
    border-bottom: 1px solid var(--ame-sidebar-border);
    text-decoration: none; overflow: hidden;
}
.ame-sidebar-brand-text {
    display: flex; flex-direction: column; min-width: 0; line-height: 1.25; white-space: nowrap;
    color: var(--ame-sidebar-text-hover);
    transition: opacity var(--ame-transition);
}
.ame-sidebar-brand-text strong { font-size: .9375rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; }
.ame-sidebar-brand-text span { font-size: .8125rem; color: var(--ame-sidebar-section); overflow: hidden; text-overflow: ellipsis; }

.ame-sidebar-nav {
    flex: 1; overflow-y: auto; overflow-x: hidden; padding: .5rem 0;
    scrollbar-width: thin; scrollbar-color: var(--ame-sidebar-border) transparent;
}
.ame-sidebar-nav::-webkit-scrollbar { width: 4px; }
.ame-sidebar-nav::-webkit-scrollbar-thumb { background-color: var(--ame-sidebar-border); border-radius: 4px; }

.ame-sidebar-section { margin-bottom: .125rem; }
.ame-sidebar-section-label {
    margin: 0; padding: .875rem 1rem .3rem;
    font-size: .6875rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
    color: var(--ame-sidebar-section); white-space: nowrap; overflow: hidden;
    transition: opacity var(--ame-transition), height var(--ame-transition), padding var(--ame-transition);
}

.ame-sidebar-item,
.ame-sidebar-item:visited,
.ame-sidebar-item:hover,
.ame-sidebar-item:focus,
.ame-sidebar-item:active { color: var(--ame-sidebar-text); text-decoration: none; }

.ame-sidebar-item {
    position: relative;
    display: flex; align-items: center; gap: .75rem;
    padding: .5625rem .875rem;
    border-left: 3px solid transparent;
    white-space: nowrap; overflow: hidden;
    transition: background-color var(--ame-transition), color var(--ame-transition), border-left-color var(--ame-transition);
}
.ame-sidebar-item:hover { background-color: var(--ame-sidebar-hover-bg); color: var(--ame-sidebar-text-hover); }
.ame-sidebar-item:focus-visible { outline: 2px solid var(--ame-sidebar-active-text); outline-offset: -2px; }
.ame-sidebar-item.active {
    background-color: var(--ame-sidebar-active-bg);
    border-left-color: var(--ame-sidebar-active-text);
    color: var(--ame-sidebar-active-text);
    font-weight: 500;
}
.ame-sidebar-item-icon { display: flex; align-items: center; justify-content: center; flex-shrink: 0; width: 20px; font-size: 1.0625rem; line-height: 1; }
.ame-sidebar-item-label { flex: 1; overflow: hidden; text-overflow: ellipsis; transition: opacity var(--ame-transition); }

.ame-sidebar-profile {
    display: flex; align-items: center; gap: .75rem; flex-shrink: 0;
    padding: .875rem 1rem;
    background: var(--ame-sidebar-profile-bg);
    border-top: 1px solid var(--ame-sidebar-border);
    overflow: hidden;
}
.ame-sidebar-profile-info { min-width: 0; transition: opacity var(--ame-transition); }
.ame-sidebar-profile-name { color: var(--ame-sidebar-text-hover); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ame-sidebar-profile-email { color: var(--ame-sidebar-section); font-size: var(--ame-font-size-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ame-avatar {
    display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--ame-accent); color: #fff;
    font-size: .75rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
}

/* Collapsed to an icon rail (wide screens only; the title attribute names each icon). */
@media (min-width: 992px) {
    [data-ame-sidebar=collapsed] .ame-sidebar { width: var(--ame-sidebar-w-collapsed); }
    [data-ame-sidebar=collapsed] .ame-sidebar-brand,
    [data-ame-sidebar=collapsed] .ame-sidebar-profile { gap: 0; justify-content: center; padding-left: 0; padding-right: 0; }
    [data-ame-sidebar=collapsed] .ame-sidebar-brand-text,
    [data-ame-sidebar=collapsed] .ame-sidebar-profile-info { opacity: 0; width: 0; }
    [data-ame-sidebar=collapsed] .ame-sidebar-section-label { opacity: 0; height: 0; padding-top: 0; padding-bottom: 0; }
    [data-ame-sidebar=collapsed] .ame-sidebar-section + .ame-sidebar-section { border-top: 1px solid var(--ame-sidebar-border); margin-top: .25rem; padding-top: .25rem; }
    [data-ame-sidebar=collapsed] .ame-sidebar-item { justify-content: center; gap: 0; padding-left: 0; padding-right: 0; border-left-width: 0; }
    [data-ame-sidebar=collapsed] .ame-sidebar-item-label { flex: 0 0 0; width: 0; opacity: 0; }
}

/* =====================================================================
   Main column and top bar
   ===================================================================== */
.ame-main {
    min-height: 100vh;
    display: flex; flex-direction: column;
    padding-left: var(--ame-sidebar-w);
    transition: padding-left var(--ame-transition);
}
@media (min-width: 992px) {
    [data-ame-sidebar=collapsed] .ame-main { padding-left: var(--ame-sidebar-w-collapsed); }
}

.ame-topbar {
    position: sticky; top: 0; z-index: 1030;
    display: flex; align-items: center; gap: .5rem; flex-shrink: 0;
    height: var(--ame-topbar-h); padding: 0 1.25rem;
    background: var(--ame-surface);
    border-bottom: 1px solid var(--ame-border);
}

.ame-topbar-btn {
    position: relative;
    display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
    width: 36px; height: 36px; padding: 0;
    border: 0; border-radius: 6px; background: none;
    color: var(--ame-muted); font-size: 1.0625rem; text-decoration: none;
    transition: color var(--ame-transition), background-color var(--ame-transition);
}
.ame-topbar-btn:hover { background: var(--ame-search-bg); color: var(--ame-ink); }
.ame-topbar-btn[data-ame-sidebar-toggle] { font-size: 1.25rem; }

.ame-topbar-actions { display: flex; align-items: center; gap: .125rem; flex-shrink: 0; margin-left: auto; }
.ame-topbar-divider { width: 1px; height: 22px; margin: 0 .25rem; background: var(--ame-border); flex-shrink: 0; }

.ame-topbar-avatar {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; margin-left: .375rem; padding: 0;
    border: 0; border-radius: 50%; background: var(--ame-accent); color: #fff;
    font-size: .75rem; font-weight: 700; letter-spacing: .05em;
    transition: box-shadow var(--ame-transition);
}
.ame-topbar-avatar:hover, .ame-topbar-avatar[aria-expanded=true] { box-shadow: 0 0 0 3px rgba(var(--ame-accent-rgb), .3); }

/* ---- Page search ---- */
.ame-search {
    position: relative;
    display: flex; align-items: center; gap: .5rem; flex: 1;
    max-width: 480px; margin: 0 auto; padding: .4rem .875rem;
    background: var(--ame-search-bg);
    border: 1px solid var(--ame-border); border-radius: 8px;
    transition: border-color var(--ame-transition), box-shadow var(--ame-transition), background-color var(--ame-transition);
}
.ame-search:focus-within { border-color: var(--ame-accent); box-shadow: 0 0 0 3px rgba(var(--ame-accent-rgb), .15); background: var(--ame-surface); }
.ame-search-icon { color: var(--ame-faint); font-size: .8125rem; flex-shrink: 0; }
.ame-search-input {
    flex: 1; min-width: 0; padding: 0;
    border: 0; outline: none; background: none;
    font: inherit; color: var(--ame-ink);
}
.ame-search-input::placeholder { color: var(--ame-faint); }
.ame-search-input::-webkit-search-cancel-button { display: none; }
.ame-search-kbd { display: flex; gap: .2rem; flex-shrink: 0; }
.ame-search-kbd kbd {
    padding: .05rem .35rem; border: 1px solid var(--ame-border); border-radius: 4px;
    background: var(--ame-surface); color: var(--ame-muted);
    font: 600 .6875rem var(--ame-font); box-shadow: none;
}
.ame-search.open .ame-search-kbd { display: none; }

.ame-search-results {
    position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 1050;
    max-height: min(420px, 70vh); overflow-y: auto; padding: .375rem 0;
    background: var(--ame-surface);
    border: 1px solid var(--ame-border); border-radius: .75rem;
    box-shadow: var(--ame-shadow-lg);
}
.ame-search-section {
    padding: .5rem 1rem .25rem;
    font-size: .6875rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ame-faint);
}
.ame-search-item {
    display: flex; align-items: center; gap: .625rem;
    padding: .45rem 1rem; color: var(--ame-ink); text-decoration: none;
}
.ame-search-item:hover, .ame-search-item.active { background: var(--ame-row-hover); color: var(--ame-ink); }
.ame-search-item-icon {
    display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
    width: 28px; height: 28px; border-radius: 6px;
    background: rgba(var(--ame-accent-rgb), .1); color: var(--ame-accent); font-size: .875rem;
}
.ame-search-empty { padding: 1.25rem 1rem; text-align: center; color: var(--ame-muted); }

/* ---- User menu ---- */
.ame-menu {
    --bs-dropdown-bg: var(--ame-surface);
    --bs-dropdown-border-color: var(--ame-border);
    --bs-dropdown-color: var(--ame-ink);
    --bs-dropdown-link-color: var(--ame-ink);
    --bs-dropdown-link-hover-bg: var(--ame-head-bg);
    --bs-dropdown-link-active-bg: var(--ame-head-bg);
    --bs-dropdown-link-active-color: var(--ame-ink);
    --bs-dropdown-divider-bg: var(--ame-border);
    min-width: 240px; padding: .375rem 0; margin-top: 8px !important;
    border-radius: .75rem; box-shadow: var(--ame-shadow-lg);
}
.ame-menu-head { display: flex; align-items: center; gap: .625rem; padding: .75rem 1rem; min-width: 0; }
.ame-menu-head > div { min-width: 0; }
.ame-menu-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ame-menu-email { font-size: var(--ame-font-size-sm); color: var(--ame-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ame-menu form { margin: 0; }
.ame-menu .dropdown-divider { margin: .25rem 0; }
.ame-menu .dropdown-item { display: flex; align-items: center; gap: .625rem; padding: .5rem 1rem; font-size: var(--ame-font-size); }
.ame-menu .dropdown-item .bi { width: 1.1rem; font-size: 1rem; opacity: .7; }
.ame-menu .ame-menu-danger, .ame-menu .ame-menu-danger:hover { color: var(--ame-danger); }
.ame-menu .ame-menu-danger .bi { opacity: 1; }

/* ---- Breadcrumb ---- */
.ame-crumbs { margin-bottom: .75rem; }
.ame-crumbs ol { display: flex; flex-wrap: wrap; align-items: center; margin: 0; padding: 0; list-style: none; font-size: var(--ame-font-size-sm); }
.ame-crumbs li { display: flex; align-items: center; gap: .3rem; color: var(--ame-muted); white-space: nowrap; }
.ame-crumbs li + li::before { content: "\F285"; font-family: bootstrap-icons; font-size: .6rem; margin: 0 .5rem; opacity: .6; }
.ame-crumbs a { color: var(--ame-muted); text-decoration: none; }
.ame-crumbs a:hover { color: var(--ame-accent); }
.ame-crumbs [aria-current=page] { color: var(--ame-ink); font-weight: 500; }

/* =====================================================================
   Page canvas
   ===================================================================== */
.ame-page {
    flex: 1; width: 100%; max-width: 1400px;
    padding: 1.25rem 2rem 1.5rem;
}

.ame-page h1 { font-size: 1.25rem; font-weight: 700; line-height: 1.3; margin: 0 0 .2rem; }
.ame-page h1 + .muted { margin-bottom: 1.5rem; max-width: 80ch; font-size: .8125rem; }
.ame-page h1:not(:has(+ .muted)) { margin-bottom: 1.25rem; }

/* Any <section> on a page becomes a card; its first heading becomes the card header. */
.ame-page section,
.ame-card {
    margin-top: 1.25rem; padding: 1.25rem;
    background: var(--ame-surface);
    border: 1px solid var(--ame-border); border-radius: .75rem;
    box-shadow: var(--ame-shadow);
}
.ame-page section > h2:first-child {
    display: flex; align-items: center; gap: .625rem;
    margin: -1.25rem -1.25rem 1.25rem; padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--ame-border); border-radius: .75rem .75rem 0 0;
    font-size: .9375rem; font-weight: 600;
}
.ame-page section > h2:first-child::before {
    content: ""; flex-shrink: 0; width: 4px; height: 16px; border-radius: 2px; background: var(--ame-accent);
}
.ame-page section h2:not(:first-child), .ame-page h3 { font-size: .9375rem; font-weight: 600; margin: 1.25rem 0 .75rem; }

/* Plain tables (pages that don't add Bootstrap's .table). */
.ame-page table:not(.table) { width: 100%; border-collapse: collapse; margin-bottom: 1rem; }
.ame-page table:not(.table) th {
    padding: .75rem 1rem; text-align: left; white-space: nowrap;
    font-size: var(--ame-font-size-sm); font-weight: 600; letter-spacing: .03em; text-transform: uppercase;
    color: var(--ame-muted); background: var(--ame-head-bg);
    border-bottom: 1px solid var(--ame-border);
}
.ame-page table:not(.table) td { padding: .75rem 1rem; vertical-align: middle; border-bottom: 1px solid var(--ame-border); }
.ame-page table:not(.table) tbody tr:last-child td { border-bottom: 0; }
.ame-page table:not(.table) tbody tr { transition: background-color .15s; }
.ame-page table:not(.table) tbody tr:hover { background: var(--ame-row-hover); }
.ame-page table:not(.table) td code { font-size: .75rem; word-break: break-all; color: var(--ame-muted); }
/* Inside a card the table runs to the card's edges. */
.ame-page section > table:not(.table) { width: calc(100% + 2.5rem); margin-left: -1.25rem; margin-right: -1.25rem; }
.ame-page section > table:not(.table):last-child { margin-bottom: -1.25rem; }
/* A table placed straight on the page gets its own card. */
.ame-page > table:not(.table) {
    border-collapse: separate; border-spacing: 0; overflow: hidden;
    background: var(--ame-surface);
    border: 1px solid var(--ame-border); border-radius: .75rem;
    box-shadow: var(--ame-shadow);
}

/* Bootstrap tables pick up the same look. */
.table { --bs-table-bg: transparent; --bs-table-hover-bg: var(--ame-row-hover); --bs-table-border-color: var(--ame-border); }
.table > thead th { font-size: var(--ame-font-size-sm); font-weight: 600; letter-spacing: .03em; text-transform: uppercase; color: var(--ame-muted); background: var(--ame-head-bg); }

/* Plain form controls. */
.ame-page form.inline {
    display: flex; flex-wrap: wrap; align-items: center; gap: .625rem;
    margin-top: 1rem; padding-top: 1rem; border-top: 1px dashed var(--ame-border);
}
.ame-page :where(input:not([type=checkbox], [type=radio], [type=hidden], [type=file], .form-control), select:not(.form-select)) {
    height: 38px; padding: 0 .875rem;
    font: inherit; color: var(--ame-ink);
    border: 1.5px solid var(--ame-input-border); border-radius: .5rem; background-color: var(--ame-input-bg);
    transition: border-color var(--ame-transition), box-shadow var(--ame-transition);
}
.ame-page :where(select:not(.form-select)) {
    appearance: none; -webkit-appearance: none; padding-right: 2.25rem; cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 16 16'%3E%3Cpath fill='%2364748b' d='M7.247 11.14L2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: calc(100% - .75rem) center;
}
.ame-page :where(input, select, textarea):focus { outline: none; border-color: var(--ame-accent); box-shadow: 0 0 0 3px rgba(var(--ame-accent-rgb), .15); }
.ame-page :where(input, textarea)::placeholder { color: var(--ame-faint); }
.ame-page input.code { width: 6.5rem; text-transform: uppercase; }
.form-control, .form-select { border-width: 1.5px; border-color: var(--ame-input-border); background-color: var(--ame-input-bg); }
.form-control:focus, .form-select:focus { border-color: var(--ame-accent); box-shadow: 0 0 0 3px rgba(var(--ame-accent-rgb), .15); }

/* Buttons: a solid accent by default, like GravityHR's primary button. */
.btn { font-weight: 600; border-width: 1.5px; }
.btn-primary {
    --bs-btn-color: #fff;
    --bs-btn-bg: var(--ame-accent);
    --bs-btn-border-color: var(--ame-accent);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--ame-accent-hover);
    --bs-btn-hover-border-color: var(--ame-accent-hover);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--ame-accent-hover);
    --bs-btn-active-border-color: var(--ame-accent-hover);
    --bs-btn-disabled-color: #fff;
    --bs-btn-disabled-bg: var(--ame-accent);
    --bs-btn-disabled-border-color: var(--ame-accent);
    --bs-btn-focus-shadow-rgb: var(--ame-accent-rgb);
}
.btn-outline-secondary {
    --bs-btn-color: var(--ame-ink);
    --bs-btn-border-color: var(--ame-border);
    --bs-btn-hover-color: var(--ame-ink);
    --bs-btn-hover-bg: var(--ame-head-bg);
    --bs-btn-hover-border-color: var(--ame-input-border);
    --bs-btn-active-color: var(--ame-ink);
    --bs-btn-active-bg: var(--ame-head-bg);
    --bs-btn-active-border-color: var(--ame-input-border);
}
.ame-page .btn:not(.btn-lg, .btn-sm) { display: inline-flex; align-items: center; gap: .4rem; height: 38px; padding: 0 1.1rem; font-size: var(--ame-font-size); }
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(var(--ame-accent-rgb), .3); }

.ame-page :where(button:not(.btn, .ame-topbar-btn, .ame-topbar-avatar, .dropdown-item)) {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    height: 38px; padding: 0 1.1rem;
    border: 1.5px solid var(--ame-accent); border-radius: .5rem;
    background: var(--ame-accent); color: #fff;
    font: inherit; font-weight: 600; white-space: nowrap; cursor: pointer;
    transition: all var(--ame-transition);
}
.ame-page :where(button:not(.btn, .ame-topbar-btn, .ame-topbar-avatar, .dropdown-item)):hover:not(:disabled) {
    background: var(--ame-accent-hover); border-color: var(--ame-accent-hover);
    transform: translateY(-1px); box-shadow: 0 4px 12px rgba(var(--ame-accent-rgb), .3);
}
.ame-page :where(button:not(.btn, .ame-topbar-btn, .ame-topbar-avatar, .dropdown-item)):disabled { opacity: .65; cursor: not-allowed; }

/* Secondary, danger and small buttons alongside the default. */
.ame-page :where(button.ame-secondary) { background: transparent; color: var(--ame-ink); border-color: var(--ame-border); }
.ame-page :where(button.ame-secondary):hover:not(:disabled) { background: var(--ame-head-bg); border-color: var(--ame-input-border); box-shadow: none; }
.ame-page :where(button.ame-danger) { background: var(--ame-danger); border-color: var(--ame-danger); }
.ame-page :where(button.ame-danger):hover:not(:disabled) { background: #b91c1c; border-color: #b91c1c; box-shadow: 0 4px 12px rgba(220, 38, 38, .3); }
.ame-page :where(button.ame-small) { height: 30px; padding: 0 .7rem; font-size: var(--ame-font-size-sm); border-radius: .375rem; }

/* Alerts. A bare class="alert" reads as an error. */
.alert { border-radius: .5rem; display: flex; gap: .5rem; align-items: flex-start; padding: .75rem 1rem; font-size: var(--ame-font-size); }
.alert:not([class*="alert-"]), .alert-danger {
    color: #b91c1c; background: #fef2f2; border: 1px solid #fecaca;
}
[data-bs-theme=dark] .alert:not([class*="alert-"]),
[data-bs-theme=dark] .alert-danger { color: #fca5a5; background: rgba(220, 38, 38, .12); border-color: rgba(220, 38, 38, .35); }
.alert-danger::before,
.alert:not([class*="alert-"])::before { content: "\F33A"; font-family: bootstrap-icons; }
.alert-success::before { content: "\F26B"; font-family: bootstrap-icons; }
.alert-warning::before { content: "\F33B"; font-family: bootstrap-icons; }

/* Status badges as soft pills. */
.badge { padding: .25rem .6rem; border-radius: 9999px; font-size: .6875rem; font-weight: 600; letter-spacing: .02em; }
.badge.text-bg-success { background: #dcfce7 !important; color: #166534 !important; }
.badge.text-bg-warning { background: #fef3c7 !important; color: #92400e !important; }
.badge.text-bg-danger { background: #fee2e2 !important; color: #991b1b !important; }
.badge.text-bg-secondary { background: #e2e8f0 !important; color: #334155 !important; }
.badge.text-bg-dark { background: #1e293b !important; color: #e2e8f0 !important; }
.badge.text-bg-light { background: #dbeafe !important; color: #1e40af !important; }
[data-bs-theme=dark] .badge.text-bg-success { background: #14532d !important; color: #86efac !important; }
[data-bs-theme=dark] .badge.text-bg-warning { background: #451a03 !important; color: #fcd34d !important; }
[data-bs-theme=dark] .badge.text-bg-danger { background: #450a0a !important; color: #fca5a5 !important; }
[data-bs-theme=dark] .badge.text-bg-secondary { background: #334155 !important; color: #cbd5e1 !important; }
[data-bs-theme=dark] .badge.text-bg-dark { background: #020617 !important; color: #cbd5e1 !important; }
[data-bs-theme=dark] .badge.text-bg-light { background: #1e3a8a !important; color: #bfdbfe !important; }

/* Page toolbars: the entity picker and filters above a page's content. */
.ame-toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .625rem 1rem; margin-bottom: 1.25rem; }
.ame-toolbar label, .ame-field { display: flex; flex-direction: column; gap: .35rem; }
.ame-toolbar-label, .ame-field > span { font-size: .8125rem; font-weight: 600; color: var(--ame-muted); }
.ame-toolbar .ame-check, .ame-check { flex-direction: row; align-items: center; gap: .45rem; height: 38px; }
.ame-check input { accent-color: var(--ame-accent); }

/* User permissions: one card per area, a "grant all" action in the card header, a grid of ticks. */
.ame-page section > h2 .ame-h2-note { font-weight: 400; font-size: var(--ame-font-size-sm); color: var(--ame-muted); }
.ame-page section > h2 .ame-h2-action { margin-left: auto; }
.ame-permission-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: .25rem 1.5rem; }
.ame-permission-grid .ame-check { height: auto; min-height: 38px; align-items: flex-start; padding: .45rem 0; }
.ame-permission-grid .ame-check input { margin-top: .2rem; }
.ame-permission-via { display: block; font-size: var(--ame-font-size-sm); color: var(--ame-muted); }

/* Forms laid out as a grid of labelled fields. */
.ame-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem 1.25rem; align-items: end; }
.ame-form .ame-wide { grid-column: 1 / -1; }
.ame-form textarea, .ame-page textarea {
    width: 100%; padding: .55rem .875rem; font: inherit; color: var(--ame-ink);
    border: 1.5px solid var(--ame-input-border); border-radius: .5rem; background-color: var(--ame-input-bg);
}
.ame-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: 1.25rem; }

/* Line items as numbered cards: account, debit, credit on top; currency, dimensions and memo wrap beneath.
   Sized by the list's own width, so it works whether or not the sidebar is open. */
.ame-lines { container-type: inline-size; }
.ame-lines ol { list-style: none; margin: 0; padding: 0; counter-reset: ame-line; display: grid; gap: .75rem; }
.ame-line {
    display: grid; gap: .75rem 1rem; align-items: end;
    grid-template-columns: 1.75rem minmax(0, 1fr) 10rem 10rem 38px;
    grid-template-areas: "no account debit credit remove" ". details details details details";
    padding: 1rem; border: 1px solid var(--ame-border); border-radius: .5rem;
}
.ame-lines li.ame-line::before {
    counter-increment: ame-line; content: counter(ame-line); grid-area: no;
    height: 38px; line-height: 38px; font-weight: 600; color: var(--ame-faint); font-variant-numeric: tabular-nums;
}
.ame-line :is(input, select) { width: 100%; min-width: 0; }
.ame-line-account { grid-area: account; }
.ame-line-debit { grid-area: debit; }
.ame-line-credit { grid-area: credit; }
.ame-line :is(.ame-line-debit, .ame-line-credit) input { text-align: right; font-variant-numeric: tabular-nums; }
.ame-line .ame-line-remove { grid-area: remove; width: 38px; padding: 0; }
.ame-line-details {
    grid-area: details; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem 1rem;
    padding-top: .75rem; border-top: 1px dashed var(--ame-border);
}
.ame-line-details .ame-field > span { font-size: var(--ame-font-size-sm); font-weight: 500; }
.ame-line-memo { grid-column: 1 / -1; width: 50%; }
.ame-line-total { margin-top: .75rem; align-items: center; font-weight: 700; background: var(--ame-head-bg); }
.ame-line-total .num { text-align: right; font-variant-numeric: tabular-nums; padding-right: calc(.875rem + 1.5px); }
.ame-line-status { grid-area: details; font-weight: 500; }
.ame-lines-note { margin: .75rem 0 0; }
@container (max-width: 640px) {
    .ame-line {
        padding: .75rem;
        grid-template-columns: 1.25rem minmax(0, 1fr) minmax(0, 1fr) 38px;
        grid-template-areas: "no account account remove" ". debit credit credit" ". details details details";
    }
    .ame-line-memo { width: auto; }
}

/* Figures line up on the decimal point; credits and totals stand out. */
.ame-page table :is(th, td).num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ame-page tr.ame-total td { font-weight: 700; border-top: 2px solid var(--ame-border); background: var(--ame-head-bg); }
.ame-page tr.ame-header-row td { font-weight: 600; }
.ame-page td.ame-indent-1 { padding-left: 2rem; }
.ame-page td.ame-indent-2 { padding-left: 3.1rem; }
.ame-page td.ame-indent-3 { padding-left: 4.2rem; }
.ame-page td.ame-indent-4 { padding-left: 5.3rem; }
.ame-page tr.ame-selected { background: rgba(var(--ame-accent-rgb), .08); }
.ame-page table input:not([type=checkbox]), .ame-page table select { height: 34px; width: 100%; min-width: 6rem; }

/* Definition lists for a record's details. */
.ame-facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem 1.5rem; margin: 0; }
.ame-facts dt { font-size: var(--ame-font-size-sm); font-weight: 500; color: var(--ame-faint); }
.ame-facts dd { margin: .2rem 0 0; font-weight: 500; }

/* Empty and status states. */
.ame-empty { display: flex; flex-direction: column; align-items: center; max-width: 460px; margin: 8vh auto 0; padding: 2rem; text-align: center; color: var(--ame-muted); }
.ame-empty h1 { color: var(--ame-ink); }
.ame-empty-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 64px; height: 64px; margin-bottom: 1.25rem;
    border-radius: 50%; font-size: 1.75rem;
    color: var(--ame-accent); background: rgba(var(--ame-accent-rgb), .1);
}
.ame-empty .btn { margin-top: .75rem; }

.ame-footer { padding: .75rem 2rem 1.25rem; font-size: var(--ame-font-size-sm); color: var(--ame-faint); }

/* Two lists side by side (the reconciliation workspace); stacked on narrow screens. */
.ame-split { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 0 1.25rem; }
.ame-page tr.ame-pickable { cursor: pointer; }
.ame-page tr.ame-picked { background: rgba(var(--ame-accent-rgb), .12); }
.ame-page tr.ame-picked:hover { background: rgba(var(--ame-accent-rgb), .16); }

/* Printable documents (a WHT certificate): only the document goes on paper. */
.ame-document { max-width: 760px; }
.ame-document > h2:first-child::before { display: none; }
@media print {
    .ame-sidebar, .ame-topbar, .ame-crumbs, .ame-footer, .ame-skip, .ame-sidebar-overlay, .ame-no-print { display: none !important; }
    body { background: #fff; }
    .ame-main { padding: 0 !important; }
    .ame-page { padding: 0; max-width: none; }
    .ame-page section, .ame-card { box-shadow: none; border-color: #ccc; }
}

/* =====================================================================
   Phones and tablets: the sidebar slides in over the page
   ===================================================================== */
.ame-sidebar-overlay { display: none; }

@media (max-width: 991.98px) {
    .ame-sidebar { left: calc(-1 * var(--ame-sidebar-w) - 1px); box-shadow: none; }
    [data-ame-nav-open] .ame-sidebar { left: 0; box-shadow: 4px 0 24px rgba(0, 0, 0, .4); }
    [data-ame-nav-open] .ame-sidebar-overlay {
        display: block; position: fixed; inset: 0; z-index: 1035; background: rgba(0, 0, 0, .5);
    }
    /* The toggle shows the "open" glyph while the sidebar is hidden. */
    .ame-topbar-btn[data-ame-sidebar-toggle] .ame-when-expanded { display: none !important; }
    .ame-topbar-btn[data-ame-sidebar-toggle] .ame-when-collapsed { display: inline-block !important; }

    .ame-main { padding-left: 0; }
    .ame-topbar { padding: 0 .75rem; }
    .ame-search { max-width: none; }
    .ame-search-kbd { display: none; }
    .ame-page { padding: 1rem; }
    .ame-footer { padding: .5rem 1rem 1rem; }
    .ame-page section, .ame-card { padding: 1rem; }
    .ame-page section > h2:first-child { margin: -1rem -1rem 1rem; padding: .875rem 1rem; }
    .ame-page section > table:not(.table) { display: block; overflow-x: auto; width: calc(100% + 2rem); margin-left: -1rem; margin-right: -1rem; }
    .ame-page section > table:not(.table):last-child { margin-bottom: -1rem; }
    .ame-page > table:not(.table) { display: block; overflow-x: auto; }
    .ame-page table:not(.table) td { white-space: nowrap; }
}

@media (max-width: 575.98px) {
    .ame-topbar-actions > a.ame-topbar-btn { display: none; }
}

/* =====================================================================
   Sign-in: form on the left, brand panel on the right
   ===================================================================== */
.ame-auth { min-height: 100vh; display: grid; grid-template-columns: 40% 60%; }

.ame-auth-panel {
    display: flex; align-items: center; justify-content: center;
    padding: 2.5rem 2rem; background: var(--ame-surface); overflow-y: auto;
}
.ame-auth-card { width: 100%; max-width: 400px; }
.ame-auth-brand {
    display: flex; align-items: center; gap: .6rem; margin-bottom: 2rem;
    font-size: 1.125rem; font-weight: 700; letter-spacing: -.01em; color: var(--ame-ink);
}
.ame-auth-card h1 { font-size: 1.5rem; font-weight: 700; line-height: 1.25; margin: 0 0 .35rem; }
.ame-auth-card h1 + .muted { font-size: .9rem; margin-bottom: 1.75rem; }
.ame-auth-card form { display: flex; flex-direction: column; gap: .35rem; }
.ame-auth-card .form-label { margin: .65rem 0 0; font-size: .8125rem; font-weight: 600; }
.ame-auth-card .form-control { padding: .65rem .875rem; font-size: .9rem; border-radius: .5rem; }
.ame-auth-card .validation-message { font-size: .78rem; }
.ame-auth-card .btn { margin-top: 1.25rem; padding: .7rem 1.5rem; font-size: .9rem; border-radius: .5rem; }

.ame-auth-hero {
    position: relative; overflow: hidden;
    display: flex; align-items: flex-end;
    padding: 3rem;
    color: #fff;
    background:
        radial-gradient(ellipse at 70% 30%, rgba(96, 165, 250, .35) 0%, transparent 60%),
        linear-gradient(135deg, #0f172a 0%, #1e3a8a 55%, #2563eb 100%);
}
/* Faint ledger rules behind the pitch. */
.ame-auth-hero::before {
    content: ""; position: absolute; inset: 0; pointer-events: none;
    background-image: repeating-linear-gradient(to bottom, rgba(255, 255, 255, .06) 0 1px, transparent 1px 44px);
}
.ame-auth-pitch { position: relative; max-width: 30rem; }
.ame-auth-pitch h2 { font-size: clamp(1.5rem, 1.1rem + 1.5vw, 2.25rem); font-weight: 700; line-height: 1.2; margin-bottom: 1.5rem; }
.ame-auth-pitch ul { list-style: none; padding: 0; margin: 0; display: grid; gap: .75rem; }
.ame-auth-pitch li { display: flex; align-items: center; gap: .75rem; color: rgba(255, 255, 255, .85); font-size: .95rem; }
.ame-auth-pitch li .bi {
    display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 8px;
    background: rgba(255, 255, 255, .12); color: #fff;
}

@media (max-width: 1024px) {
    .ame-auth { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
    .ame-auth-hero { order: -1; min-height: 200px; align-items: center; padding: 2rem; }
    .ame-auth-pitch h2 { font-size: 1.25rem; margin-bottom: 1rem; }
}

@media (max-width: 640px) {
    .ame-auth { grid-template-rows: 1fr; }
    .ame-auth-hero { display: none; }
    .ame-auth-panel { align-items: flex-start; padding: 1.5rem 1rem; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
