* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { background: var(--bg); }
body {
    background: var(--bg);
    color: var(--text);
    font-family: Inter, "Segoe UI", Arial, sans-serif;
    font-size: 15px;
    font-weight: 400;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; font-weight: 400; }
button { color: inherit; }
h1, h2, h3, h4, strong, b { font-weight: 500; }
a { color: inherit; text-decoration: none; }
.sr-only { position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0; }

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 228px minmax(0, 1fr);
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 18px 14px 16px;
    display: flex;
    flex-direction: column;
    z-index: 50;
}

.sidebar-brand {
    height: 48px;
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 0 10px 12px;
    font-size: 20px;
    font-weight: 500;
    letter-spacing: -.2px;
}

.brand-logo {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    color: var(--primary);
}

.sidebar-nav {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 6px 0 10px;
    display: grid;
    gap: 3px;
    align-content: start;
}

.nav-group { min-width: 0; }

.nav-item {
    width: 100%;
    min-height: 40px;
    display: grid;
    grid-template-columns: 24px minmax(0,1fr) 18px;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    text-align: left;
    cursor: pointer;
}

.nav-item:hover { background: var(--surface-3); }

.nav-item.active {
    background: var(--primary-soft);
    color: var(--primary);
}

.nav-icon {
    width: 24px;
    height: 24px;
    display: grid;
    place-items: center;
    color: currentColor;
    flex: 0 0 auto;
}

.nav-chevron {
    justify-self: end;
    color: var(--muted);
    display: grid;
    place-items: center;
}
.nav-chevron .ui-svg {
    width: 14px;
    height: 14px;
}

.nav-children {
    max-height: 0;
    opacity: 0;
    visibility: hidden;
    overflow: hidden;
    padding: 0 0 0 42px;
    transition:
        max-height .22s ease,
        opacity .16s ease,
        padding .18s ease,
        visibility 0s linear .22s;
}

.nav-children-inner {
    display: grid;
    gap: 1px;
}

.nav-group.is-open > .nav-children {
    max-height: 340px;
    opacity: 1;
    visibility: visible;
    padding: 4px 0 6px 42px;
    transition:
        max-height .22s ease,
        opacity .16s ease,
        padding .18s ease,
        visibility 0s;
}

.nav-children a {
    color: var(--muted);
    padding: 6px 8px;
    border-radius: 7px;
    font-size: 14px;
    line-height: 1.35;
    transition: color .14s ease, background .14s ease;
}

.nav-children a:hover {
    color: var(--primary);
    background: var(--primary-soft);
}

.nav-children a.active {
    color: var(--primary);
    background: var(--primary-soft);
}

.nav-group.is-open > .nav-parent .nav-chevron {
    transform: rotate(180deg);
    color: var(--primary);
}

.nav-chevron {
    transition: transform .18s ease, color .18s ease;
}

.nav-parent.active {
    background: var(--primary-soft);
    color: var(--primary);
}

.nav-item-spacer {
    width: 18px;
    height: 18px;
}

.sidebar-logout {
    margin-top: auto;
    min-height: 40px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 8px;
}

.sidebar-logout:hover { background: var(--surface-3); }

.workspace {
    min-width: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.workspace > .page-content {
    flex: 1 0 auto;
}

.topbar {
    height: 64px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 0 24px 0 18px;
    position: sticky;
    top: 0;
    z-index: 40;
}

.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar h1 { margin: 0; font-size: 19px; font-weight: 500; }

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 13px;
}

.theme-segment {
    min-height: 36px;
    display: flex;
    align-items: center;
    border: 1px solid var(--border);
    background: var(--surface-3);
    border-radius: 11px;
    padding: 3px;
}

.theme-segment button {
    border: 0;
    background: transparent;
    padding: 6px 10px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--muted);
}

html[data-theme="light"] .theme-segment button[data-theme-set="light"],
html[data-theme="dark"] .theme-segment button[data-theme-set="dark"] {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}

.theme-moon { color: var(--muted); padding: 0 1px; }

.icon-btn {
    position: relative;
    border: 0;
    background: transparent;
    min-width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border-radius: 9px;
    cursor: pointer;
}

.icon-btn:hover { background: var(--surface-3); }

.icon-btn .ui-svg {
    width: 18px;
    height: 18px;
}

.notification-badge {
    position: absolute;
    top: 1px;
    right: 1px;
    width: 17px;
    height: 17px;
    background: var(--red);
    color: white;
    border: 2px solid var(--surface);
    border-radius: 99px;
    display: grid;
    place-items: center;
    font-size: 11px;
}

.profile-menu {
    display: flex;
    align-items: center;
    gap: 9px;
    padding-left: 3px;
}

.avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--surface-3);
    color: var(--muted);
    display: grid;
    place-items: center;
}

.profile-copy { display: grid; line-height: 1.15; min-width: 65px; }
.profile-copy strong { font-size: 14px; }
.profile-copy span { color: var(--muted); font-size: 13px; margin-top: 3px; }
.profile-arrow {
    color: var(--muted);
    display: grid;
    place-items: center;
}
.profile-arrow .ui-svg {
    width: 14px;
    height: 14px;
}

.page-content { padding: 20px; }

.panel,
.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.primary-btn,
.secondary-btn {
    min-height: 38px;
    border-radius: 8px;
    padding: 8px 13px;
    border: 1px solid var(--border);
    cursor: pointer;
    white-space: nowrap;
}

.primary-btn {
    background: #172137;
    border-color: #172137;
    color: #fff;
}

html[data-theme="dark"] .primary-btn {
    background: var(--primary-2);
    border-color: var(--primary-2);
}

.secondary-btn {
    background: var(--surface);
    color: var(--text);
}

.secondary-btn:hover { background: var(--surface-3); }

.mobile-menu { display: none; }
.mobile-backdrop { display: none; }

/* Stage 2 shared footer + authentication */
.app-footer {
    min-height: 54px;
    border-top: 1px solid var(--border);
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    color: var(--muted);
    font-size: 12px;
    background: var(--surface);
}

.auth-page {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 24px;
}

.auth-shell { width: min(430px, 100%); }

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 34px;
}

.auth-card h1 { margin: 12px 0 4px; font-size: 26px; }
.auth-card > p { margin: 0 0 24px; }
.auth-card form { display: grid; gap: 9px; }
.auth-card label { color: var(--muted); font-size: 13px; margin-top: 4px; }
.auth-card input {
    width: 100%;
    height: 42px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0 12px;
    outline: none;
}
.auth-card input:focus { border-color: var(--primary); }
.auth-logo { width: 46px; height: 46px; }
.auth-submit { margin-top: 8px; }
.theme-link {
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    padding: 16px 0 0;
}

.alert, .notice {
    border-radius: 9px;
    padding: 10px 12px;
    font-size: 13px;
}
.alert, .notice.error {
    border: 1px solid rgba(226,85,85,.28);
    background: var(--red-soft);
    color: var(--red);
}
.notice.success {
    border: 1px solid rgba(56,165,107,.28);
    background: var(--green-soft);
    color: var(--green);
}
.notice { margin-bottom: 14px; }

.ui-svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    flex: 0 0 auto;
    display: block;
}

@media (max-width: 980px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed;
        left: 0;
        transform: translateX(-100%);
        transition: transform .2s ease;
        width: 228px;
    }
    body.sidebar-open .sidebar { transform: translateX(0); }
    .mobile-menu { display: grid; }
    .mobile-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,.35);
        z-index: 45;
    }
    body.sidebar-open .mobile-backdrop { display: block; }
}

@media (max-width: 620px) {
    .topbar { padding: 0 12px; }
    .page-content { padding: 12px; }
    .profile-copy, .profile-arrow { display:none; }
    .theme-segment button { padding-inline: 7px; }
    .app-footer { align-items: flex-start; flex-direction: column; }
}


/* ------------------------------------------------------------------
   Stage 7A — shared sidebar scrollbar + notification dropdown
   These components live in the shared layout, so their styling must
   live in app.css and not only on notification-specific pages.
   ------------------------------------------------------------------ */

/* Premium sidebar scrollbar: subtle in both light and dark mode. */
.sidebar-nav {
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
    scrollbar-gutter: stable;
}

.sidebar-nav::-webkit-scrollbar {
    width: 8px;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    min-height: 48px;
    background: var(--border-strong);
    border: 2px solid transparent;
    background-clip: padding-box;
    border-radius: 999px;
}

.sidebar-nav::-webkit-scrollbar-thumb:hover {
    background: var(--muted-2);
    border: 2px solid transparent;
    background-clip: padding-box;
}

.sidebar-nav::-webkit-scrollbar-button {
    display: none;
    width: 0;
    height: 0;
}

/* Notification dropdown belongs to the global topbar. */
.notification-menu {
    position: relative;
    display: flex;
    align-items: center;
}

.notification-dropdown {
    position: absolute;
    right: -8px;
    top: calc(100% + 10px);
    width: 390px;
    max-width: calc(100vw - 28px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 18px 52px rgba(20, 30, 50, .16);
    overflow: hidden;
    display: none;
    z-index: 120;
}

html[data-theme="dark"] .notification-dropdown {
    box-shadow: 0 22px 58px rgba(0, 0, 0, .38);
}

.notification-dropdown.is-open {
    display: block;
}

.notification-dropdown::before {
    content: "";
    position: absolute;
    right: 19px;
    top: -6px;
    width: 11px;
    height: 11px;
    background: var(--surface);
    border-left: 1px solid var(--border);
    border-top: 1px solid var(--border);
    transform: rotate(45deg);
}

.notification-dropdown-head {
    position: relative;
    z-index: 1;
    min-height: 62px;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.notification-dropdown-head > div {
    display: grid;
    gap: 2px;
}

.notification-dropdown-head strong {
    font-size: 14px;
    font-weight: 500;
}

.notification-dropdown-head span {
    color: var(--muted);
    font-size: 12px;
}

.notification-dropdown-head a {
    min-height: 30px;
    padding: 6px 9px;
    border-radius: 7px;
    color: var(--primary);
    background: var(--primary-soft);
    font-size: 12px;
    display: inline-flex;
    align-items: center;
}

.notification-mini-list {
    display: grid;
    max-height: 360px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

.notification-mini-list > a {
    min-height: 72px;
    padding: 11px 13px;
    border-bottom: 1px solid var(--border);
    display: grid;
    grid-template-columns: 9px minmax(0, 1fr);
    gap: 10px;
    color: var(--text);
    background: var(--surface);
}

.notification-mini-list > a:hover {
    background: var(--surface-2);
}

.notification-mini-list > a.unread {
    background: var(--primary-soft);
}

.notification-mini-list > a:last-child {
    border-bottom: 0;
}

.notification-mini-list > a > div {
    min-width: 0;
    display: grid;
    gap: 3px;
}

.notification-mini-list strong {
    display: block;
    font-size: 12px;
    line-height: 1.35;
    font-weight: 500;
}

.notification-mini-list span {
    display: block;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.notification-mini-list small {
    display: block;
    color: var(--muted-2);
    font-size: 10px;
}

.notification-mini-empty {
    min-height: 118px;
    padding: 20px;
    display: grid;
    place-items: center;
    text-align: center;
    color: var(--muted);
    font-size: 12px;
}

.notification-severity {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-top: 4px;
}

.notification-severity.info { background: var(--primary); }
.notification-severity.success { background: var(--green); }
.notification-severity.warning { background: var(--amber); }
.notification-severity.critical { background: var(--red); }

.notification-settings-link {
    min-height: 40px;
    padding: 10px 14px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--primary);
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.notification-settings-link:hover {
    background: var(--primary-soft);
}

@media (max-width: 620px) {
    .notification-dropdown {
        position: fixed;
        top: 68px;
        left: 12px;
        right: 12px;
        width: auto;
        max-width: none;
    }

    .notification-dropdown::before {
        display: none;
    }
}


/* ------------------------------------------------------------------
   Stage 8A2 — Global typography standard
   Keep the approved light-weight visual language, but eliminate micro
   text so all modules remain comfortably readable at desktop scale.
   ------------------------------------------------------------------ */
body {
    font-size: 15px;
    line-height: 1.5;
}

button,
input,
select,
textarea {
    font-size: 13px;
    line-height: 1.4;
}

.sidebar-brand { font-size: 20px; }
.nav-item { font-size: 14px; }
.nav-children a { font-size: 13px; }
.topbar h1 { font-size: 19px; }

.page-intro h1,
.page-intro h2 { font-size: 21px; }
.page-intro p { font-size: 13px; }

.section-heading-pro h3,
.mini-heading h3 { font-size: 15px; }
.section-heading-pro p { font-size: 12px; }

.directory-table th {
    font-size: 12px;
    line-height: 1.35;
}
.directory-table td {
    font-size: 13px;
    line-height: 1.4;
}
.cell-stack strong { font-size: 13px; }
.cell-stack small { font-size: 11px; }
.record-count { font-size: 12px; }
.status-pill { font-size: 11px; }

.toolbar-search input,
.panel-toolbar input,
.panel-toolbar select,
.form-grid input,
.form-grid select,
.form-grid textarea {
    font-size: 13px;
}

.primary-btn,
.secondary-btn {
    font-size: 13px;
}

/* Shared compact secondary control. Previously some pages rendered
   text-link-button as an unstyled native gray browser button. */
.text-link-button {
    min-height: 32px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--surface);
    color: var(--primary);
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background .14s ease, border-color .14s ease, color .14s ease;
}
.text-link-button:hover {
    background: var(--primary-soft);
    border-color: var(--primary);
}

.app-footer {
    font-size: 12px;
}


/* ------------------------------------------------------------------
   Stage 8A4 — Global in-app toast system
   success = green, error = red, warning = amber, info = primary blue.
   ------------------------------------------------------------------ */
.rpm-toast-seed {
    display: none !important;
}

.rpm-toast-stack {
    position: fixed;
    top: 76px;
    right: 18px;
    z-index: 250;
    width: min(390px, calc(100vw - 28px));
    display: grid;
    gap: 10px;
    pointer-events: none;
}

.rpm-toast {
    position: relative;
    min-height: 68px;
    padding: 12px 42px 13px 12px;
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: 0 18px 50px rgba(18, 28, 48, .16);
    opacity: 0;
    transform: translateY(-8px) translateX(10px);
    transition: opacity .18s ease, transform .18s ease;
    pointer-events: auto;
}

html[data-theme="dark"] .rpm-toast {
    box-shadow: 0 22px 58px rgba(0, 0, 0, .38);
}

.rpm-toast.is-visible {
    opacity: 1;
    transform: translateY(0) translateX(0);
}

.rpm-toast.is-leaving {
    opacity: 0;
    transform: translateX(18px);
}

.rpm-toast-icon {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    display: grid;
    place-items: center;
    font-size: 14px;
    font-weight: 600;
}

.rpm-toast-copy {
    min-width: 0;
    display: grid;
    gap: 2px;
}

.rpm-toast-copy strong {
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
}

.rpm-toast-copy span {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.4;
}

.rpm-toast-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 18px;
}

.rpm-toast-close:hover {
    background: var(--surface-3);
    color: var(--text);
}

.rpm-toast-progress {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 3px;
    transform-origin: left center;
    animation: rpm-toast-countdown linear forwards;
}

.rpm-toast-success {
    border-color: color-mix(in srgb, var(--green) 28%, var(--border));
}
.rpm-toast-success .rpm-toast-icon {
    background: var(--green-soft);
    color: var(--green);
}
.rpm-toast-success .rpm-toast-progress {
    background: var(--green);
}

.rpm-toast-error {
    border-color: color-mix(in srgb, var(--red) 30%, var(--border));
}
.rpm-toast-error .rpm-toast-icon {
    background: var(--red-soft);
    color: var(--red);
}
.rpm-toast-error .rpm-toast-progress {
    background: var(--red);
}

.rpm-toast-warning {
    border-color: color-mix(in srgb, var(--amber) 30%, var(--border));
}
.rpm-toast-warning .rpm-toast-icon {
    background: var(--amber-soft);
    color: var(--amber);
}
.rpm-toast-warning .rpm-toast-progress {
    background: var(--amber);
}

.rpm-toast-info {
    border-color: color-mix(in srgb, var(--primary) 28%, var(--border));
}
.rpm-toast-info .rpm-toast-icon {
    background: var(--primary-soft);
    color: var(--primary);
}
.rpm-toast-info .rpm-toast-progress {
    background: var(--primary);
}

@keyframes rpm-toast-countdown {
    from { transform: scaleX(1); }
    to { transform: scaleX(0); }
}

.field-manage-modal {
    width: min(680px, 100%);
}

.field-governance-strip {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 12px;
}

.field-governance-strip > div {
    min-height: 62px;
    padding: 9px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    display: grid;
    align-content: center;
    gap: 3px;
}

.field-governance-strip span {
    color: var(--muted);
    font-size: 11px;
}

.field-governance-strip strong {
    color: var(--text);
    font-size: 12px;
    font-weight: 500;
    overflow-wrap: anywhere;
}

.field-governance-note {
    margin-bottom: 13px;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 11px;
    line-height: 1.45;
}

.field-manage-modal .form-grid small {
    color: var(--muted);
    font-size: 11px;
    line-height: 1.4;
}

@media (max-width: 680px) {
    .rpm-toast-stack {
        top: 68px;
        right: 12px;
        left: 12px;
        width: auto;
    }

    .field-governance-strip {
        grid-template-columns: 1fr 1fr;
    }
}
