/*
 * Base and business components (BRD 40.9 - 40.30). Every rule here reads tokens
 * from tokens.css; nothing below hard-codes a colour, spacing or radius value.
 */

/* ============================ Foundations ============================== */

body {
    font-family: var(--font-sans);
    font-size: var(--text-body);
    line-height: var(--leading-normal);
    color: var(--text-primary);
    background: var(--surface-page);
}

h1, .h1 { font-size: var(--text-h1); font-weight: var(--weight-semibold); line-height: var(--leading-tight); }
h2, .h2 { font-size: var(--text-h2); font-weight: var(--weight-semibold); line-height: var(--leading-tight); }
h3, .h3 { font-size: var(--text-h3); font-weight: var(--weight-semibold); line-height: var(--leading-tight); }

.text-body-lg { font-size: var(--text-body-lg); }
.text-small   { font-size: var(--text-small); }
.text-caption { font-size: var(--text-caption); color: var(--text-muted); }
.text-subtle  { color: var(--text-secondary); }

/* BRD 40.31 rule 14: financial values are always tabular and right-aligned. */
.value-money {
    font-variant-numeric: tabular-nums;
    font-weight: var(--weight-medium);
    text-align: right;
    white-space: nowrap;
}

a { color: var(--primary-600); text-decoration: none; }
a:hover { color: var(--primary-700); text-decoration: underline; }

:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: var(--radius-sm);
}

.visually-hidden-focusable:focus {
    position: fixed;
    top: var(--space-md);
    left: var(--space-md);
    z-index: 1080;
    padding: var(--space-sm) var(--space-lg);
    background: var(--white);
    border-radius: var(--radius-input);
    box-shadow: var(--elevation-3);
}

/* ============================ App shell (40.8) ========================== */

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: var(--header-height) 1fr auto;
    grid-template-areas:
        "sidebar header"
        "sidebar main"
        "sidebar footer";
}

.app-shell.is-collapsed { grid-template-columns: var(--sidebar-width-collapsed) 1fr; }

/* --- Sidebar: dark premium navigation --- */
.app-sidebar {
    grid-area: sidebar;
    background: var(--sidebar-bg);
    color: var(--text-on-dark);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: hidden;
}

.app-brand {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    height: var(--header-height);
    padding: 0 var(--space-md);
    flex: 0 0 auto;
    background: var(--sidebar-bg-deep);
    color: var(--white);
    font-weight: var(--weight-bold);
    font-size: var(--text-body-lg);
}

.app-brand:hover { color: var(--white); text-decoration: none; }
.app-brand__text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-brand .app-brand__mark { color: var(--gold-500); flex: 0 0 auto; }

.app-sidebar__search {
    flex: 0 0 auto;
    padding: var(--space-sm) var(--space-sm) var(--space-xs);
    position: relative;
}

.app-sidebar__search input {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.12);
    color: var(--text-on-dark);
    padding-right: var(--space-4xl);
}

.app-sidebar__search input::placeholder { color: var(--text-on-dark-muted); }

.app-sidebar__search button {
    position: absolute;
    right: var(--space-sm);
    top: var(--space-sm);
    height: var(--control-height);
    width: var(--control-height);
    display: grid;
    place-items: center;
    border: 0;
    background: none;
    color: var(--text-on-dark-muted);
    cursor: pointer;
}

/* The nav scrolls on its own so the user block stays pinned to the bottom. */
.app-nav {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: var(--space-xs) var(--space-sm) var(--space-md);
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}

.app-nav::-webkit-scrollbar { width: 6px; }
.app-nav::-webkit-scrollbar-track { background: transparent; }

.app-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.16);
    border-radius: var(--radius-pill);
}

.app-nav::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.28); }

.app-nav__section {
    padding: var(--space-md) var(--space-sm) var(--space-xs);
    font-size: var(--text-caption);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-on-dark-muted);
}

.app-nav__link {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    margin-bottom: 1px;
    border-radius: var(--radius-sm);
    color: var(--text-on-dark);
    font-size: var(--text-body);
    font-weight: var(--weight-medium);
    transition: background var(--motion-fast) var(--easing), color var(--motion-fast) var(--easing);
}

.app-nav__link:hover {
    background: rgba(255, 255, 255, 0.07);
    color: var(--white);
    text-decoration: none;
}

/* Active state carries a gold rail as well as a background, so it does not rely
   on colour alone (BRD 40.27). */
.app-nav__link.is-active {
    background: linear-gradient(90deg, var(--primary-700), var(--primary-600));
    color: var(--white);
    box-shadow: inset 3px 0 0 var(--gold-500);
}

/* Collapsible group, matching the chevron pattern in the reference design. */
.app-nav__chevron {
    margin-left: auto;
    transition: transform var(--motion-fast) var(--easing);
}

.app-nav__link[aria-expanded="true"] .app-nav__chevron { transform: rotate(180deg); }

.app-nav__sub { padding-left: var(--space-lg); }

.app-nav__sub .app-nav__link {
    font-weight: var(--weight-regular);
    font-size: var(--text-small);
    color: var(--text-on-dark-muted);
    padding-block: var(--space-xs);
}

.app-nav__sub .app-nav__link:hover,
.app-nav__sub .app-nav__link.is-active {
    color: var(--white);
    background: rgba(255, 255, 255, 0.06);
    box-shadow: none;
}

.app-nav__bullet {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    border: 1.5px solid currentColor;
    flex: 0 0 auto;
}

/* Signed-in user, pinned below the navigation. */
.app-sidebar__user {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: var(--sidebar-bg-deep);
    color: var(--text-on-dark);
}

.app-sidebar__avatar {
    width: 28px;
    height: 28px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.10);
    color: var(--white);
}

.app-sidebar__user-identity { min-width: 0; }

.app-sidebar__user-name,
.app-sidebar__user-role {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-sidebar__user-name { font-weight: var(--weight-semibold); line-height: 1.2; }
.app-sidebar__user-role { font-size: var(--text-caption); color: var(--text-on-dark-muted); }

.app-sidebar__logout {
    margin-left: auto;
    background: none;
    border: 0;
    padding: 0;
    color: var(--error-600);
    cursor: pointer;
}

.app-nav__link .icon { flex: 0 0 auto; }

.app-nav__badge {
    margin-left: auto;
    background: var(--gold-500);
    color: var(--primary-900);
    font-size: var(--text-caption);
    font-weight: var(--weight-semibold);
    border-radius: var(--radius-pill);
    padding: 0 var(--space-sm);
}

.is-collapsed .app-nav__link { justify-content: center; padding-inline: var(--space-sm); }
.is-collapsed .app-nav__label,
.is-collapsed .app-nav__section,
.is-collapsed .app-nav__sub,
.is-collapsed .app-nav__chevron,
.is-collapsed .app-sidebar__search,
.is-collapsed .app-sidebar__user > *:not(.app-sidebar__avatar),
.is-collapsed .app-brand__text { display: none; }

/* --- Top header --- */
.app-header {
    grid-area: header;
    background: linear-gradient(90deg, var(--header-from), var(--header-to));
    color: var(--white);
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: 0 var(--space-md);
    position: sticky;
    top: 0;
    z-index: 20;
}

.app-header__title {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: var(--text-h3);
    font-weight: var(--weight-semibold);
    margin: 0;
    color: var(--white);
}

/* Header controls sit on a dark ground, so they carry their own light styling. */
.app-header .btn-tertiary { color: rgba(255, 255, 255, 0.92); }

.app-header .btn-tertiary:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.14);
    color: var(--white);
}

.app-header__count {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: var(--radius-pill);
    background: var(--success-600);
    color: var(--white);
    font-size: 10px;
    font-weight: var(--weight-bold);
    line-height: 18px;
    text-align: center;
}

.app-header__count--alert { background: var(--warning-600); }

.app-header__avatar {
    width: 24px;
    height: 24px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    color: var(--white);
}

.app-header__search {
    flex: 1 1 auto;
    max-width: 420px;
    position: relative;
}

.app-header__search .icon {
    position: absolute;
    left: var(--space-md);
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.app-header__search input { padding-left: var(--space-4xl); }
.app-header__actions { margin-left: auto; display: flex; align-items: center; gap: var(--space-sm); }

.app-main {
    grid-area: main;
    padding: var(--space-lg);
    min-width: 0;
}

.app-footer {
    grid-area: footer;
    padding: var(--space-sm) var(--space-lg);
    border-top: 1px solid var(--border-subtle);
    background: var(--surface-raised);
    color: var(--text-muted);
    font-size: var(--text-small);
}

/* Uppercase group label above a band of cards, as used on the dashboard. */
.section-label {
    display: flex;
    align-items: baseline;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
    font-size: var(--text-caption);
    font-weight: var(--weight-bold);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.section-label__hint {
    text-transform: none;
    letter-spacing: 0;
    font-weight: var(--weight-regular);
    color: var(--text-muted);
}

.page-header {
    display: flex;
    align-items: flex-start;
    gap: var(--space-md);
    flex-wrap: wrap;
    margin-bottom: var(--space-lg);
}

.page-header p { margin-bottom: 0; }

.page-header__actions { margin-left: auto; display: flex; gap: var(--space-sm); }

/* Breadcrumbs for detail navigation (BRD 40.25). */
.breadcrumb-trail {
    font-size: var(--text-small);
    color: var(--text-muted);
    margin-bottom: var(--space-sm);
}
.breadcrumb-trail a { color: var(--text-secondary); }
.breadcrumb-trail span + span::before { content: "/"; margin: 0 var(--space-sm); color: var(--border-strong); }

/* ============================ Buttons (40.9) =========================== */

.btn {
    --btn-height: var(--control-height);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    min-height: var(--btn-height);
    padding: 0 var(--space-md);
    border-radius: var(--radius-input);
    border: 1px solid transparent;
    font-size: var(--text-body);
    font-weight: var(--weight-medium);
    line-height: 1;
    cursor: pointer;
    transition: background var(--motion-fast) var(--easing),
                border-color var(--motion-fast) var(--easing),
                color var(--motion-fast) var(--easing);
}

.btn-sm { --btn-height: var(--control-height-sm); padding-inline: var(--space-sm); font-size: var(--text-small); }
.btn-lg { --btn-height: var(--control-height-lg); padding-inline: var(--space-xl); font-size: var(--text-body-lg); }

.btn-primary {
    background: var(--primary-700);
    border-color: var(--primary-700);
    color: var(--white);
}
.btn-primary:hover:not(:disabled) { background: var(--primary-600); border-color: var(--primary-600); color: var(--white); }
.btn-primary:active:not(:disabled) { background: var(--primary-800); border-color: var(--primary-800); }

.btn-secondary {
    background: var(--surface-raised);
    border-color: var(--border-strong);
    color: var(--text-primary);
}
.btn-secondary:hover:not(:disabled) { background: var(--grey-100); border-color: var(--grey-400); color: var(--text-primary); }

.btn-tertiary {
    background: transparent;
    border-color: transparent;
    color: var(--primary-600);
}
.btn-tertiary:hover:not(:disabled) { background: var(--primary-50); color: var(--primary-700); }

.btn-danger {
    background: var(--error-600);
    border-color: var(--error-600);
    color: var(--white);
}
.btn-danger:hover:not(:disabled) { background: var(--error-700); border-color: var(--error-700); color: var(--white); }

.btn-icon { width: var(--btn-height); padding: 0; }

.btn:disabled, .btn.disabled { opacity: 0.55; cursor: not-allowed; }

/* Loading state: the spinner replaces the label, width stays stable. */
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    border: 2px solid var(--white);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 600ms linear infinite;
}
.btn-secondary.is-loading::after,
.btn-tertiary.is-loading::after { border-color: var(--primary-700); border-top-color: transparent; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ============================ Forms (40.10) ============================ */

.form-field { margin-bottom: var(--space-md); }

.form-label {
    display: block;
    margin-bottom: var(--space-xs);
    font-size: var(--text-small);
    font-weight: var(--weight-medium);
    color: var(--text-primary);
}

.form-label .required { color: var(--error-600); margin-left: 2px; }

.form-control, .form-select {
    width: 100%;
    min-height: var(--control-height);
    padding: var(--space-xs) var(--space-sm);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-input);
    background: var(--surface-raised);
    font-size: var(--text-body);
    color: var(--text-primary);
    transition: border-color var(--motion-fast) var(--easing), box-shadow var(--motion-fast) var(--easing);
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary-600);
    box-shadow: var(--focus-ring);
    outline: none;
}

.form-control::placeholder { color: var(--text-muted); }
.form-control:disabled, .form-select:disabled { background: var(--grey-100); color: var(--text-muted); }

.form-help { margin-top: var(--space-xs); font-size: var(--text-caption); color: var(--text-secondary); }

.form-control.is-invalid, .form-select.is-invalid { border-color: var(--error-600); }

.field-validation-error, .invalid-feedback {
    display: block;
    margin-top: var(--space-xs);
    font-size: var(--text-caption);
    color: var(--error-700);
}

/* Long forms are split into sections rather than one long column (BRD 40.10). */
.form-section {
    border-top: 1px solid var(--border-subtle);
    padding-top: var(--space-lg);
    margin-top: var(--space-lg);
}
.form-section:first-of-type { border-top: 0; padding-top: 0; margin-top: 0; }
.form-section__title { font-size: var(--text-h3); margin-bottom: var(--space-md); }

/* ============================ Cards (40.12) ============================ */

.card {
    background: var(--surface-raised);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-card);
    box-shadow: var(--elevation-1);
}

.card__header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--border-subtle);
}

.card__title { font-size: var(--text-h3); font-weight: var(--weight-semibold); margin: 0; }
.card__actions { margin-left: auto; display: flex; gap: var(--space-sm); }
.card__body { padding: var(--space-lg); }
.card__body--flush { padding: 0; }

/* --- KPI card (40.16) --- */
.kpi-card { padding: var(--space-md) var(--space-lg); }

.kpi-card__head {
    display: flex;
    align-items: flex-start;
    gap: var(--space-md);
    margin-bottom: var(--space-sm);
}

.kpi-card__label {
    font-size: var(--text-caption);
    color: var(--text-secondary);
    font-weight: var(--weight-bold);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.kpi-card__icon {
    width: 30px;
    height: 30px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    border-radius: var(--radius-sm);
    background: var(--primary-50);
    color: var(--primary-700);
}

.kpi-card__icon--accent  { background: var(--gold-50);    color: var(--gold-700); }
.kpi-card__icon--success { background: var(--success-100); color: var(--success-700); }
.kpi-card__icon--warning { background: var(--warning-100); color: var(--warning-700); }
.kpi-card__icon--error   { background: var(--error-100);   color: var(--error-700); }
.kpi-card__icon--info    { background: var(--info-100);    color: var(--info-700); }

.kpi-card__value {
    font-size: var(--text-display);
    font-weight: var(--weight-bold);
    line-height: var(--leading-tight);
    font-variant-numeric: tabular-nums;
}

.kpi-card__trend { display: flex; align-items: center; gap: var(--space-xs); margin-top: var(--space-sm); font-size: var(--text-small); }
.kpi-card__trend--up   { color: var(--success-700); }
.kpi-card__trend--down { color: var(--error-700); }
.kpi-card__trend--flat { color: var(--text-muted); }
.kpi-card__period { color: var(--text-muted); }

/* Responsive KPI grid (BRD 40.7). */
/* More tiles per row now that each one is shorter (BRD 40.7). */
.kpi-grid {
    display: grid;
    gap: var(--space-md);
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}

/* ============================ Tables (40.11) =========================== */

.data-table-wrap {
    background: var(--surface-raised);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-card);
    box-shadow: var(--elevation-1);
    overflow: hidden;
}

.data-table-scroll { overflow-x: auto; max-height: 74vh; }

.data-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--text-body); }

.data-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--grey-50);
    border-bottom: 1px solid var(--border-strong);
    padding: var(--space-sm) var(--space-md);
    text-align: left;
    font-size: var(--text-small);
    font-weight: var(--weight-semibold);
    color: var(--text-secondary);
    white-space: nowrap;
}

.data-table tbody td {
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--border-subtle);
    vertical-align: middle;
}

.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: var(--grey-50); }

.data-table th.is-numeric, .data-table td.is-numeric { text-align: right; }

/* Sortable headers keep an arrow, so sort direction is never colour-only. */
.data-table th.is-sortable a { color: inherit; display: inline-flex; align-items: center; gap: var(--space-xs); }
.data-table th.is-sortable a:hover { color: var(--primary-700); text-decoration: none; }

.table-toolbar {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex-wrap: wrap;
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--border-subtle);
}

.table-footer {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex-wrap: wrap;
    padding: var(--space-xs) var(--space-md);
    border-top: 1px solid var(--border-subtle);
    font-size: var(--text-small);
    color: var(--text-secondary);
}

.table-footer__pages { margin-left: auto; display: flex; gap: var(--space-xs); }

.row-actions { display: flex; gap: var(--space-xs); justify-content: flex-end; }

/* ============================ Badges (40.13) =========================== */

.badge-status {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: 2px var(--space-md);
    border-radius: var(--radius-pill);
    font-size: var(--text-caption);
    font-weight: var(--weight-medium);
    line-height: 1.6;
    white-space: nowrap;
}

.badge-status .icon { width: 14px; height: 14px; }

.badge-status--success { background: var(--success-100); color: var(--success-700); }
.badge-status--warning { background: var(--warning-100); color: var(--warning-700); }
.badge-status--error   { background: var(--error-100);   color: var(--error-700); }
.badge-status--info    { background: var(--info-100);    color: var(--info-700); }
.badge-status--neutral { background: var(--neutral-100); color: var(--neutral-700); }
.badge-status--accent  { background: var(--gold-100);    color: var(--gold-700); }

/* ============================ Filters (40.18) ========================== */

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    align-items: flex-end;
    padding: var(--space-md);
    background: var(--surface-raised);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-card);
    margin-bottom: var(--space-lg);
}

.filter-bar__field { flex: 1 1 148px; min-width: 132px; margin: 0; }
.filter-bar__actions { margin-left: auto; display: flex; gap: var(--space-sm); }

.filter-count {
    background: var(--primary-700);
    color: var(--white);
    border-radius: var(--radius-pill);
    padding: 0 var(--space-sm);
    font-size: var(--text-caption);
    font-weight: var(--weight-semibold);
}

/* ============================ States (40.20 - 40.22) =================== */

.empty-state { padding: var(--space-4xl) var(--space-xl); text-align: center; }

.empty-state__icon {
    width: 44px;
    height: 44px;
    margin: 0 auto var(--space-lg);
    display: grid;
    place-items: center;
    border-radius: var(--radius-lg);
    background: var(--primary-50);
    color: var(--primary-600);
}

.empty-state__title { font-size: var(--text-h3); font-weight: var(--weight-semibold); margin-bottom: var(--space-sm); }
.empty-state__text { color: var(--text-secondary); max-width: 40ch; margin: 0 auto var(--space-xl); }

.error-state { padding: var(--space-5xl) var(--space-2xl); text-align: center; }
.error-state__icon { color: var(--error-600); margin-bottom: var(--space-lg); }

/* Skeletons mirror the shape of the content they replace (BRD 40.21). */
.skeleton {
    background: linear-gradient(90deg, var(--grey-200) 25%, var(--grey-100) 37%, var(--grey-200) 63%);
    background-size: 400% 100%;
    border-radius: var(--radius-sm);
    animation: skeleton-shimmer 1.4s ease infinite;
}

.skeleton--text  { height: 12px; margin-bottom: var(--space-sm); }
.skeleton--title { height: 20px; width: 40%; margin-bottom: var(--space-md); }
.skeleton--kpi   { height: 28px; width: 60%; }
.skeleton--row   { height: 16px; }

@keyframes skeleton-shimmer {
    0%   { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}

/* ============================ Toasts (40.24) =========================== */

.toast-stack {
    position: fixed;
    right: var(--space-2xl);
    bottom: var(--space-2xl);
    z-index: 1070;
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    width: min(360px, calc(100vw - var(--space-4xl)));
}

.toast-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-md);
    padding: var(--space-lg);
    background: var(--surface-raised);
    border: 1px solid var(--border-subtle);
    border-left: 4px solid var(--info-600);
    border-radius: var(--radius-input);
    box-shadow: var(--elevation-3);
    animation: toast-in var(--motion-slow) var(--easing);
}

.toast-item--success { border-left-color: var(--success-600); }
.toast-item--warning { border-left-color: var(--warning-600); }
.toast-item--error   { border-left-color: var(--error-600); }

.toast-item__icon--success { color: var(--success-600); }
.toast-item__icon--warning { color: var(--warning-600); }
.toast-item__icon--error   { color: var(--error-600); }
.toast-item__icon--info    { color: var(--info-600); }

.toast-item__body { flex: 1 1 auto; font-size: var(--text-body); }
.toast-item__close { background: none; border: 0; color: var(--text-muted); cursor: pointer; padding: 0; }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: none; }
}

/* ============================ Notifications (40.19) ==================== */

.notification-item {
    display: flex;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--border-subtle);
}

.notification-item.is-unread { background: var(--primary-50); }
.notification-item__icon { flex: 0 0 auto; color: var(--primary-600); margin-top: 2px; }
.notification-item__title { font-weight: var(--weight-semibold); font-size: var(--text-body); }
.notification-item__text { color: var(--text-secondary); font-size: var(--text-small); }
.notification-item__time { color: var(--text-muted); font-size: var(--text-caption); margin-top: var(--space-xs); }

.notification-dot {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--error-600);
    border: 2px solid var(--surface-raised);
}

/* ============================ Modals (40.23) =========================== */

.modal-content {
    border: 0;
    border-radius: var(--radius-lg);
    box-shadow: var(--elevation-3);
}

.modal-header { padding: var(--space-lg); border-bottom: 1px solid var(--border-subtle); }
.modal-title { font-size: var(--text-h3); font-weight: var(--weight-semibold); }
.modal-body { padding: var(--space-lg); }
.modal-footer { padding: var(--space-md) var(--space-lg); border-top: 1px solid var(--border-subtle); gap: var(--space-sm); }

/* ============================ Tabs (40.25) ============================= */

.tab-nav { display: flex; gap: var(--space-md); border-bottom: 1px solid var(--border-subtle); margin-bottom: var(--space-md); }

.tab-nav__item {
    padding: var(--space-sm) var(--space-xs);
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-weight: var(--weight-medium);
}

.tab-nav__item:hover { color: var(--primary-700); text-decoration: none; }
.tab-nav__item.is-active { color: var(--primary-800); border-bottom-color: var(--primary-700); }

/* ============================ Property media (40.15) =================== */

.property-card__media { position: relative; aspect-ratio: 16 / 9; background: var(--surface-sunken); overflow: hidden; }
.property-card__media img { width: 100%; height: 100%; object-fit: cover; }

.property-card__count {
    position: absolute;
    right: var(--space-sm);
    bottom: var(--space-sm);
    background: rgba(13, 27, 42, 0.75);
    color: var(--white);
    border-radius: var(--radius-sm);
    padding: 2px var(--space-sm);
    font-size: var(--text-caption);
}

.property-thumb { aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--radius-sm); width: 100%; }

/* ============================ Charts (40.17) =========================== */

.chart-card__meta { font-size: var(--text-small); color: var(--text-muted); }
.chart-canvas { width: 100%; min-height: 260px; }

/* Sparkline and mini bars: shape only, always beside a number that carries the
   actual value, never the sole source of the figure (BRD 40.17, 40.27). */
.spark {
    display: block;
    width: 100%;
    height: 40px;
    margin-top: var(--space-md);
    overflow: visible;
}

.spark__line { fill: none; stroke: var(--primary-600); stroke-width: 2; }
.spark__area { fill: var(--primary-100); opacity: 0.55; stroke: none; }

.mini-bars {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 44px;
    margin-top: var(--space-md);
}

.mini-bars__bar {
    flex: 1 1 0;
    min-height: 3px;
    border-radius: 3px;
    background: var(--primary-500);
}

.mini-bars--success .mini-bars__bar { background: var(--success-600); }
.mini-bars--warning .mini-bars__bar { background: var(--warning-600); }
.mini-bars--error   .mini-bars__bar { background: var(--error-600); }

/* Labelled progress meter, as used for wallet and loyalty breakdowns. */
.meter {
    height: 6px;
    border-radius: var(--radius-pill);
    background: var(--surface-sunken);
    overflow: hidden;
    margin-top: var(--space-sm);
}

.meter__fill {
    height: 100%;
    border-radius: var(--radius-pill);
    background: var(--primary-600);
}

.meter__fill--success { background: var(--success-600); }
.meter__fill--warning { background: var(--warning-600); }
.meter__fill--accent  { background: var(--gold-600); }

.stat-row {
    display: grid;
    gap: var(--space-xl);
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.stat-row__label {
    font-size: var(--text-caption);
    font-weight: var(--weight-bold);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.stat-row__value {
    font-size: var(--text-h2);
    font-weight: var(--weight-bold);
    font-variant-numeric: tabular-nums;
    line-height: var(--leading-tight);
}

/* ============================ Icons (40.14) ============================ */

.icon {
    width: 17px;
    height: 17px;
    flex: 0 0 auto;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.icon--sm { width: 14px; height: 14px; }
.icon--lg { width: 22px; height: 22px; }

/* ============================ Responsive (40.28) ======================= */

@media (max-width: 1024px) {
    .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

    .app-shell { grid-template-columns: var(--sidebar-width-collapsed) 1fr; }
    .app-shell .app-nav__label,
    .app-shell .app-nav__section,
    .app-shell .app-brand__text { display: none; }
    .app-shell .app-nav__link { justify-content: center; padding-inline: var(--space-sm); }

    /* The expanded sidebar becomes an overlay drawer on smaller screens. */
    .app-shell.is-drawer-open { grid-template-columns: var(--sidebar-width) 1fr; }
    .app-shell.is-drawer-open .app-nav__label,
    .app-shell.is-drawer-open .app-nav__section,
    .app-shell.is-drawer-open .app-brand__text { display: block; }
    .app-shell.is-drawer-open .app-nav__link { justify-content: flex-start; padding-inline: var(--space-lg); }
}

@media (max-width: 640px) {
    .kpi-grid { grid-template-columns: minmax(0, 1fr); }

    .app-shell { grid-template-columns: 1fr; grid-template-areas: "header" "main" "footer"; }

    .app-sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: var(--sidebar-width);
        z-index: 1050;
        transform: translateX(-100%);
        transition: transform var(--motion-base) var(--easing);
    }

    .app-shell.is-drawer-open .app-sidebar { transform: none; box-shadow: var(--elevation-3); }

    .app-main { padding: var(--space-lg); }
    .app-header { padding-inline: var(--space-lg); }
    .app-header__search { display: none; }
    .toast-stack { right: var(--space-lg); left: var(--space-lg); bottom: var(--space-lg); width: auto; }
}

.sidebar-scrim { display: none; }

.app-shell.is-drawer-open .sidebar-scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(13, 27, 42, 0.45);
    z-index: 1040;
}

@media (min-width: 641px) { .app-shell.is-drawer-open .sidebar-scrim { display: none; } }

/* ======================= Analytics charts (40.17, 40.26) ================ */

.chart-grid {
    display: grid;
    gap: var(--space-md);
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
}

.chart-card__head {
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
}

.chart-card__title { font-size: var(--text-h3); font-weight: var(--weight-semibold); margin: 0; }
.chart-card__hint { font-size: var(--text-caption); color: var(--text-muted); }

.chart-card__total {
    margin-left: auto;
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: var(--weight-semibold);
    white-space: nowrap;
}

/* --- Column chart: months across, value up --- */
.chart-columns {
    display: flex;
    align-items: flex-end;
    gap: var(--space-xs);
    height: 150px;
    padding-top: var(--space-lg);
    border-bottom: 1px solid var(--border-strong);
}

.chart-columns__item {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    height: 100%;
    gap: 2px;
}

.chart-columns__bar {
    width: 100%;
    min-height: 2px;
    border-radius: 3px 3px 0 0;
    background: linear-gradient(180deg, var(--primary-500), var(--primary-700));
}

.chart-columns__bar--muted { background: var(--grey-200); }

.chart-columns__value {
    font-size: 10px;
    font-variant-numeric: tabular-nums;
    color: var(--text-secondary);
    white-space: nowrap;
}

.chart-axis {
    display: flex;
    gap: var(--space-xs);
    margin-top: var(--space-xs);
}

.chart-axis__item {
    flex: 1 1 0;
    min-width: 0;
    text-align: center;
    font-size: 10px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* --- Bar chart: label, track, value on one row --- */
.chart-bars { display: grid; gap: var(--space-sm); }

.chart-bars__row {
    display: grid;
    grid-template-columns: minmax(84px, 30%) 1fr auto;
    gap: var(--space-sm);
    align-items: center;
}

.chart-bars__label {
    font-size: var(--text-small);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chart-bars__track {
    height: 16px;
    border-radius: 3px;
    background: var(--surface-sunken);
    overflow: hidden;
}

.chart-bars__fill {
    height: 100%;
    border-radius: 3px;
    background: var(--primary-600);
    min-width: 2px;
}

.chart-bars__fill--accent  { background: var(--gold-600); }
.chart-bars__fill--success { background: var(--success-600); }
.chart-bars__fill--info    { background: var(--info-600); }

.chart-bars__value {
    font-size: var(--text-small);
    font-variant-numeric: tabular-nums;
    font-weight: var(--weight-medium);
    text-align: right;
    white-space: nowrap;
}

.chart-bars__caption { font-size: var(--text-caption); color: var(--text-muted); }

/* --- Donut: proportion ring with a legend that carries the numbers --- */
.chart-donut { display: flex; align-items: center; gap: var(--space-xl); flex-wrap: wrap; }
.chart-donut__figure { flex: 0 0 auto; position: relative; width: 132px; height: 132px; }
.chart-donut__svg { width: 132px; height: 132px; transform: rotate(-90deg); }
.chart-donut__track { fill: none; stroke: var(--surface-sunken); }
.chart-donut__segment { fill: none; stroke-linecap: butt; }

.chart-donut__centre {
    position: absolute;
    inset: 0;
    display: grid;
    place-content: center;
    text-align: center;
}

.chart-donut__centre strong { font-size: var(--text-h2); font-variant-numeric: tabular-nums; line-height: 1; }
.chart-donut__centre span { font-size: var(--text-caption); color: var(--text-muted); }

.chart-legend { flex: 1 1 180px; display: grid; gap: 5px; min-width: 0; }

.chart-legend__row {
    display: grid;
    grid-template-columns: 10px 1fr auto auto;
    gap: var(--space-sm);
    align-items: center;
    font-size: var(--text-small);
}

.chart-legend__swatch { width: 10px; height: 10px; border-radius: 2px; }
.chart-legend__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-legend__value { font-variant-numeric: tabular-nums; font-weight: var(--weight-medium); }
.chart-legend__percent { font-variant-numeric: tabular-nums; color: var(--text-muted); font-size: var(--text-caption); }

.chart-empty {
    display: grid;
    place-items: center;
    min-height: 130px;
    color: var(--text-muted);
    font-size: var(--text-small);
    text-align: center;
    background: var(--surface-sunken);
    border-radius: var(--radius-sm);
}

/* ---------------------------------------------------------- contact actions
   Call and WhatsApp sit next to a number wherever one is shown. They are
   secondary to the number itself, so they read as quiet links rather than
   buttons until hovered. */
.contact-actions {
    display: inline-flex;
    gap: var(--space-xs);
    margin-left: var(--space-xs);
    vertical-align: middle;
}

.contact-actions__link {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 1px var(--space-xs);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    font-size: var(--text-caption);
    line-height: 1.6;
    color: var(--text-muted);
    text-decoration: none;
    white-space: nowrap;
}

.contact-actions__link:hover,
.contact-actions__link:focus-visible {
    color: var(--primary-700);
    border-color: var(--primary-700);
    background: var(--primary-50);
}

.contact-actions__link--whatsapp:hover,
.contact-actions__link--whatsapp:focus-visible {
    color: var(--success-700);
    border-color: var(--success-700);
    background: var(--success-100);
}

/* The spoken-magnitude echo under a money input. Empty until something is
   typed, so it must not reserve space or the form jumps as it fills in. */
.money-hint:empty { display: none; }
.money-hint { color: var(--primary-700); font-variant-numeric: tabular-nums; }
