:root {
    --gt-navy: #1f3864;
    --gt-navy-dark: #152a4d;
    --gt-accent: #c8a24a;
    --sidebar-width: 250px;
}

body {
    background: #f4f6fa;
    font-size: 0.925rem;
}

/* ---------------------------------------------------------------- */
/* Shell                                                            */
/* ---------------------------------------------------------------- */
.layout {
    display: flex;
    min-height: 100vh;
    /*
     | Dynamic viewport height, where it is understood. On a phone 100vh is the
     | height with the browser chrome hidden, so a full-height column measured
     | that way runs further than the screen and the last thing in it sits
     | behind the address bar until you scroll.
     */
    min-height: 100dvh;
}

.sidebar {
    width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
    background: var(--gt-navy);
    color: #dfe6f5;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100dvh;
    z-index: 1045;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 1rem 1rem 0.9rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 9px;
    background: var(--gt-accent);
    color: #12203b;
    font-weight: 700;
    letter-spacing: -0.5px;
    flex: 0 0 38px;
}

.brand-text strong {
    display: block;
    color: #fff;
    line-height: 1.1;
}

.brand-text small {
    font-size: 0.72rem;
    opacity: 0.75;
}

.sidebar-nav {
    padding: 0.5rem 0.5rem 1rem;
    overflow-y: auto;
    flex: 1 1 auto;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0.7rem;
    border-radius: 7px;
    color: #c9d4ea;
    text-decoration: none;
    font-size: 0.875rem;
}

.sidebar-nav a:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.sidebar-nav a.active {
    background: rgba(200, 162, 74, 0.18);
    color: #fff;
    font-weight: 600;
    box-shadow: inset 3px 0 0 var(--gt-accent);
}

.sidebar-nav a i {
    width: 1.1rem;
    text-align: center;
}

.nav-heading {
    padding: 0.9rem 0.7rem 0.3rem;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    opacity: 0.55;
}

.sidebar-footer {
    padding: 0.75rem 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    font-size: 0.8rem;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1040;
}

.content {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: #fff;
    border-bottom: 1px solid #dde3ee;
    padding: 0.7rem 1rem;
    position: sticky;
    top: 0;
    z-index: 1030;
}

/* Let the title shrink and ellipsis rather than push the buttons off-screen. */
.topbar > .flex-grow-1 {
    min-width: 0;
}

.topbar .topbar-actions {
    flex: 0 0 auto;
}

body {
    overflow-x: hidden;
}

.main {
    padding: 1rem;
    flex: 1 1 auto;
}

.pagefooter {
    padding: 0.75rem 1rem 1.25rem;
    font-size: 0.75rem;
    color: #7b8699;
}

/* ---------------------------------------------------------------- */
/* Safe areas                                                       */
/* ---------------------------------------------------------------- */
/*
 | The page is sent `viewport-fit=cover`, which is what lets the navy theme
 | colour run right to the top edge instead of leaving a pale band under the
 | clock. The price is that the screen now includes the parts of the glass the
 | phone keeps for itself — the status bar and notch at the top, the home
 | indicator at the bottom, and the rounded corner on whichever side is down
 | in landscape. Installed to the home screen there is no browser chrome left
 | to hold anything clear of them, so each edge asks for the inset it needs.
 | In a desktop browser, and on any phone without a notch, every one of these
 | resolves to zero and nothing moves.
 */
.topbar {
    padding-top: calc(0.7rem + env(safe-area-inset-top));
    padding-left: calc(1rem + env(safe-area-inset-left));
    padding-right: calc(1rem + env(safe-area-inset-right));
}

.sidebar-brand {
    padding-top: calc(1rem + env(safe-area-inset-top));
}

.sidebar-nav,
.sidebar-footer {
    padding-left: calc(0.5rem + env(safe-area-inset-left));
}

.sidebar-footer {
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
}

.main {
    padding-left: calc(1rem + env(safe-area-inset-left));
    padding-right: calc(1rem + env(safe-area-inset-right));
}

/* The footer is the last thing on the page, so it carries the bottom inset
   and keeps the home indicator off the final line of text. */
.pagefooter {
    padding-left: calc(1rem + env(safe-area-inset-left));
    padding-right: calc(1rem + env(safe-area-inset-right));
    padding-bottom: calc(1.25rem + env(safe-area-inset-bottom));
}

/* ---------------------------------------------------------------- */
/* Touch                                                            */
/* ---------------------------------------------------------------- */
@media (max-width: 991.98px) {
    /*
     | Safari on iOS zooms the page in whenever it focuses a form control
     | whose text is smaller than 16px, and it does not zoom back out again
     | afterwards. The compact `-sm` controls the filter bars and the tenancy
     | form are built from are 14px, so tapping the outlet search left the
     | user pinching the page back down to a readable width before they could
     | read the result. Raising the text to the threshold is the whole fix;
     | the padding is left alone, so the controls stay as compact as they
     | look on a desktop.
     */
    .form-control,
    .form-select,
    .form-control-sm,
    .form-select-sm,
    /*
     | A compact control sitting in an input group is sized by a rule of its
     | own, `.input-group-sm > .form-control`, which names two classes where
     | the plain `.form-control-sm` above names one and therefore wins however
     | far down the file it is answered. The outlet search is built that way,
     | so without these it stayed at 14px and went on zooming — and of
     | everything on the screen it is the one thing most likely to be tapped
     | on a phone. The whole group goes up together so the box, its button and
     | any addon keep to one height.
     */
    .input-group-sm > .form-control,
    .input-group-sm > .form-select,
    .input-group-sm > .input-group-text,
    .input-group-sm > .btn {
        font-size: 16px;
    }
}

@media (max-width: 991.98px) {
    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-backdrop.show {
        display: block;
    }

    .main {
        padding: 0.75rem;
        /* Restated, because the shorthand above would otherwise drop the
           landscape insets the rule further up puts on. */
        padding-left: calc(0.75rem + env(safe-area-inset-left));
        padding-right: calc(0.75rem + env(safe-area-inset-right));
    }

    /* Keep the heading on one line so the action buttons stay beside it. */
    .topbar h1 {
        font-size: 1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .topbar .small {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

@media (max-width: 575.98px) {
    /* Not enough width for a title and four buttons, so the buttons take
       their own row underneath rather than squeezing the title to nothing. */
    .topbar {
        padding: 0.6rem 0.75rem;
        gap: 0.4rem;
        flex-wrap: wrap;
        /* As above: keep the status-bar and landscape insets the shorthand
           would have discarded. */
        padding-top: calc(0.6rem + env(safe-area-inset-top));
        padding-left: calc(0.75rem + env(safe-area-inset-left));
        padding-right: calc(0.75rem + env(safe-area-inset-right));
    }

    .topbar h1 {
        font-size: 0.95rem;
    }

    .topbar .topbar-actions {
        flex: 1 0 100%;
        justify-content: flex-end;
    }

    /* Two ageing cards per row on a phone. */
    .ageing-btn {
        flex: 1 1 calc(50% - 0.25rem);
        min-width: 0;
        padding: 0.5rem 0.6rem;
    }

    .ageing-btn .count {
        font-size: 1.3rem;
    }
}

/* ---------------------------------------------------------------- */
/* Ageing buttons                                                   */
/* ---------------------------------------------------------------- */
.ageing-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.ageing-btn {
    flex: 1 1 140px;
    min-width: 128px;
    text-align: left;
    text-decoration: none;
    border-radius: 10px;
    padding: 0.6rem 0.75rem;
    border: 1px solid #dde3ee;
    background: #fff;
    color: #243;
    display: block;
    transition: transform 0.08s ease, box-shadow 0.12s ease;
}

.ageing-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(31, 56, 100, 0.12);
}

.ageing-btn .count {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.1;
}

.ageing-btn .label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.8;
}

.ageing-btn.is-active {
    box-shadow: 0 0 0 2px currentColor inset;
    font-weight: 600;
}

.ageing-btn.tone-danger { border-left: 5px solid var(--bs-danger); color: var(--bs-danger); }
.ageing-btn.tone-warning { border-left: 5px solid var(--bs-warning); color: #8a6100; }
.ageing-btn.tone-info { border-left: 5px solid var(--bs-info); color: #0b6c80; }
.ageing-btn.tone-primary { border-left: 5px solid var(--bs-primary); color: var(--bs-primary); }
.ageing-btn.tone-success { border-left: 5px solid var(--bs-success); color: #126b3f; }
.ageing-btn.tone-secondary { border-left: 5px solid var(--bs-secondary); color: var(--bs-secondary); }
.ageing-btn.tone-dark { border-left: 5px solid #343a40; color: #343a40; }

/*
 | The same ageing colours inside a dropdown, so a list of tenancies to
 | renew says at a glance which have lapsed. A browser paints an option in
 | the colour it is given but keeps the closed select in the page colour,
 | so the note under the select repeats it for the chosen one.
 */
option.tone-danger { color: var(--bs-danger); }
option.tone-warning { color: #8a6100; }
option.tone-info { color: #0b6c80; }
option.tone-primary { color: var(--bs-primary); }
option.tone-success { color: #126b3f; }
option.tone-secondary { color: var(--bs-secondary); }
option.tone-dark { color: #343a40; }

/* ---------------------------------------------------------------- */
/* Tables                                                           */
/* ---------------------------------------------------------------- */
.table-sticky thead th {
    position: sticky;
    top: 0;
    background: #eef2f9;
    z-index: 2;
    white-space: nowrap;
}

.table td,
.table th {
    vertical-align: middle;
}

.cell-narrow {
    max-width: 240px;
}

.text-small {
    font-size: 0.8rem;
}

.card {
    border-color: #e2e7f0;
}

.card-header {
    background: #f7f9fd;
    font-weight: 600;
}

.stat {
    border-radius: 10px;
    background: #fff;
    border: 1px solid #e2e7f0;
    padding: 0.85rem 1rem;
}

.stat .value {
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1.1;
}

.stat .label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6b7688;
}

.bar-track {
    height: 8px;
    border-radius: 4px;
    background: #eceff5;
    overflow: hidden;
    display: flex;
}

/* ---------------------------------------------------------------- */
/* Print                                                            */
/* ---------------------------------------------------------------- */
@media print {
    .sidebar,
    .topbar,
    .pagefooter,
    .no-print {
        display: none !important;
    }

    body {
        background: #fff;
    }

    .main {
        padding: 0;
    }

    .table {
        font-size: 9pt;
    }

    a[href]:after {
        content: '';
    }
}
