:root {
    --ink: #233635;
    --muted: #71807e;
    --accent: #17665d;
    --line: #e3e9e7;
    --background: #f5f7f6;
    font: 14px Inter, "Segoe UI", Arial, sans-serif;
    color: var(--ink);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--background);
}

a {
    color: inherit;
    text-decoration: none;
}

button, input, select {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
}

h1, h2, h3, p {
    margin: 0;
}

h1 {
    font-size: 30px;
    font-weight: 650;
    letter-spacing: -1px;
}

h2 {
    font-size: 15px;
    font-weight: 650;
}

h3 {
    font-size: 12px;
    font-weight: 550;
}

small {
    display: block;
    color: var(--muted);
    font-size: 10px;
}

:focus-visible {
    outline: 3px solid #338d80;
    outline-offset: 3px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.skip-link {
    position: fixed;
    top: -60px;
    left: 20px;
    padding: 12px;
    background: var(--accent);
    color: white;
    z-index: 10;
}

.skip-link:focus {
    top: 12px;
}

.button {
    display: inline-block;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 9px 13px;
    background: white;
    font-size: 12px;
}

.button:hover {
    background: var(--background);
}

.badge {
    display: inline-block;
    padding: 4px 7px;
    border-radius: 5px;
    background: #f0f3f1;
    color: var(--muted);
    font-size: 10px;
    white-space: nowrap;
}

.badge[data-kind=amber] {
    background: #fcf3e1;
    color: #9b691e;
}

.badge[data-kind=blue] {
    background: #eef4fa;
    color: #557c9b;
}

.badge[data-kind=purple] {
    background: #f3f0f9;
    color: #7b6c9b;
}

.avatar {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border-radius: 50%;
    background: #eef0ec;
    color: #687e6f;
    font-size: 11px;
}

.empty {
    padding: 20px 12px;
    color: var(--muted);
    font-size: 12px;
}

/* Application frame */
#topbar {
    height: 76px;
    padding: 0 30px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    background: white;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 5;
}

.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    font-size: 19px;
    font-weight: 750;
    letter-spacing: 1px;
}

.brand > span {
    display: inline-grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 9px;
    background: var(--accent);
    color: white;
    font-size: 31px;
}

.brand small {
    padding-left: 16px;
    margin-left: 8px;
    border-left: 1px solid var(--line);
    font-size: 12px;
    font-weight: 400;
    letter-spacing: 0;
}

.account {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 12px;
}

.account small {
    margin-top: 4px;
}

.account > .badge {
    margin-right: 14px;
    background: #f8f4e9;
    color: #7a6b48;
}

.account .avatar {
    background: #eff1f7;
    color: #626886;
}

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

main {
    padding: 28px 38px 0;
    min-width: 0;
    max-width: 1600px;
    width: 100%;
    margin: 0 auto;
}

main > section > footer {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 24px 0;
    color: #7c8981;
    font-size: 10px;
}

.breadcrumb {
    display: flex;
    gap: 12px;
    margin-bottom: 26px;
    font-size: 11px;
    color: var(--muted);
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 24px;
}

.page-header small {
    margin-bottom: 9px;
    color: var(--accent);
    font-size: 10px;
    letter-spacing: 0.17em;
}

.page-header p {
    margin-top: 10px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.6;
}

/* Resident navigation */
.sidebar {
    position: sticky;
    top: 76px;
    height: calc(100vh - 76px);
    display: flex;
    flex-direction: column;
    padding: 30px 16px 20px;
    border-right: 1px solid var(--line);
    background: #fcfdfc;
}

.sidebar > small {
    padding: 0 12px;
    margin-bottom: 12px;
    font-size: 10px;
    letter-spacing: 0.14em;
}

.sidebar > a {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 11px 12px;
    border-radius: 6px;
    font-size: 13px;
}

.sidebar > a .badge {
    margin-left: auto;
}

.sidebar > a:hover, .sidebar [aria-current=page] {
    background: #eaf3ee;
}

.sidebar hr {
    width: 100%;
    border: 0;
    border-top: 1px solid var(--line);
    margin: 23px 0;
}

.sidebar > header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
}

.sidebar h2 {
    font-size: 13px;
}

.sidebar > p {
    padding: 0 12px;
    margin-top: 7px;
    font-size: 11px;
    color: var(--muted);
}

.search {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 18px 8px 13px;
    padding: 8px 9px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: white;
}

.search input[type=search] {
    min-width: 0;
    width: 100%;
    border: 0;
    background: transparent;
    font-size: 11px;
}

.search button {
    border: 0;
    padding: 0;
    background: transparent;
    color: var(--muted);
    font-size: 21px;
    line-height: 1;
}

.residents {
    overflow: auto;
    min-height: 0;
}

.residents a {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 2px 0;
    padding: 13px 11px;
    border: 1px solid transparent;
    border-radius: 7px;
}

.residents a:hover {
    background: #f0f4f1;
}

.residents a[aria-current] {
    border-color: #dce9e1;
}

.residents a[aria-current] .avatar {
    background: #d6e6dc;
    color: #2b6650;
}

.residents strong {
    display: block;
    font-weight: 550;
    font-size: 12px;
}

.residents small {
    margin-top: 5px;
}

.residents .badge {
    margin-left: auto;
    background: #fbf1df;
    color: #a66a22;
}

.sidebar > footer {
    margin-top: auto;
    padding: 35px 10px 0;
    color: #60736a;
    font-size: 10px;
}

.sidebar > footer small {
    margin-top: 6px;
    font-size: 9px;
    line-height: 1.6;
}

/* Resident details and metrics */
.panel {
    background: white;
    border: 1px solid var(--line);
    border-radius: 10px;
}

.panel > header, .metrics-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.panel > header p, .metrics-heading p {
    margin-top: 6px;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.5;
}

.profile {
    padding: 20px 22px;
}

.profile h2 {
    font-size: 13px;
}

.profile dl {
    display: grid;
    grid-template-columns: 1.2fr .8fr 1fr 1.3fr 1fr;
    gap: 16px;
    margin: 21px 0 0;
}

.profile dt {
    margin-bottom: 7px;
    font-size: 10px;
    color: var(--muted);
}

.profile dd {
    margin: 0;
    font-size: 12px;
}

.profile small {
    margin-top: 5px;
}

.metrics-heading {
    margin: 28px 0 15px;
}

.segmented {
    display: flex;
    flex-shrink: 0;
    gap: 3px;
    padding: 3px;
    border-radius: 6px;
    background: #ecefed;
}

.segmented a {
    padding: 7px 13px;
    border-radius: 4px;
    color: var(--muted);
    font-size: 10px;
}

.segmented [aria-current] {
    background: white;
    color: var(--accent);
    box-shadow: 0 1px 3px #20382b10;
}

.metrics {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.metrics > a {
    overflow: hidden;
    padding: 15px 14px 12px;
    background: white;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.metrics > a:hover, .metrics [aria-current] {
    border-color: #8bb4a1;
}

.metrics header {
    font-size: 10px;
    color: var(--muted);
    white-space: nowrap;
}

.metrics header span {
    color: #7b9d8e;
    font-size: 14px;
    margin-right: 6px;
}

.metrics strong {
    display: block;
    margin: 10px 0;
    font-size: 26px;
    font-weight: 600;
    letter-spacing: -.7px;
}

.metrics strong small {
    display: inline;
    font-weight: 400;
    letter-spacing: 0;
}

.metrics > a > small {
    margin-top: 8px;
    font-size: 9px;
    white-space: nowrap;
}

.summarylinegraph {
    display: block;
    width: 100%;
    height: 28px;
}

.summarylinegraph polyline {
    fill: none;
    stroke: #84ab99;
    stroke-width: 1.3;
    vector-effect: non-scaling-stroke;
}

.readings {
    padding: 21px 22px 14px;
    scroll-margin-top: 96px;
}

.chart-legend {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin: 25px 0 8px;
    color: var(--muted);
    font-size: 10px;
}

.chart-legend span::before {
    content: "";
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-right: 6px;
    background: #488b73;
    border-radius: 50%;
}

.chart-legend span:last-child::before {
    background: #fbf1dc;
    border: 1px solid #dab577;
    border-radius: 0;
}

.chart {
    display: block;
    width: 100%;
    height: auto;
}

.chart line {
    stroke: #edf1ee;
}

.chart text {
    fill: var(--muted);
    font-size: 10px;
    font-family: inherit;
}

.chart rect {
    fill: #fcf4e4;
}

.chart rect[data-selected=true] {
    fill: #f8e7bf;
}

.chart path {
    fill: #eaf3ee;
    fill-opacity: .6;
}

.chart polyline {
    fill: none;
    stroke: #488b73;
    stroke-width: 1.8;
    stroke-linejoin: round;
}

.chart-note {
    padding-top: 12px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 10px;
    line-height: 1.6;
}

.chart-note.selected {
    color: #906321;
}

.table-scroll {
    overflow: auto;
    max-height: 255px;
}

table {
    border-collapse: collapse;
    width: 100%;
    font-size: 11px;
    text-align: left;
}

th, td {
    padding: 10px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

th {
    background: #f8faf9;
    color: var(--muted);
    font-size: 10px;
    font-weight: 500;
}

tr.selected {
    background: #fff6e4;
}

/* Inference log */
.events {
    overflow: hidden;
    margin-top: 22px;
}

.events > header {
    padding: 21px 22px;
}

.events form {
    display: flex;
    gap: 6px;
}

.events select {
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: white;
    font-size: 10px;
}

.events article {
    display: grid;
    grid-template-columns: 46px 1fr auto;
    gap: 14px;
    padding: 18px 22px;
    border-top: 1px solid var(--line);
}

.events article.selected {
    background: #fffaf1;
    box-shadow: inset 3px 0 #cfab72;
}

.events time {
    padding-top: 2px;
    font-size: 11px;
    color: var(--muted);
}

.events time small {
    margin-top: 4px;
    font-size: 9px;
}

.events article header {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 7px;
}

.events article p {
    color: var(--muted);
    font-size: 11px;
    line-height: 1.6;
}

.events article div > small {
    margin-top: 7px;
    font-size: 9px;
}

.events article > a {
    color: var(--accent);
    font-size: 10px;
    white-space: nowrap;
    padding-top: 5px;
}

.events article > a:hover {
    text-decoration: underline;
}

.events footer {
    padding: 13px 22px;
    border-top: 1px solid var(--line);
    background: #fafcfb;
    font-size: 10px;
    color: var(--muted);
    line-height: 1.6;
}

/* Secondary views */
.cards {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 20px;
}

.cards article {
    padding: 26px;
}

.cards article > span:first-child {
    display: block;
    margin-bottom: 18px;
    color: var(--accent);
    font-size: 25px;
}

.cards p {
    margin: 12px 0 22px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.8;
}

.signed-out {
    display: grid;
    place-items: center;
    min-height: calc(100vh - 76px);
    padding: 24px;
}

.signed-out .panel {
    max-width: 460px;
    padding: 45px;
    text-align: center;
}

.signed-out h1 {
    margin-top: 22px;
    font-size: 26px;
}

.signed-out p {
    margin: 15px 0 25px;
    color: var(--muted);
    line-height: 1.7;
}

@media (max-width: 1200px) {
    .brand small {
        display: none;
    }

    .shell {
        grid-template-columns: 228px minmax(0, 1fr);
    }

    main {
        padding: 26px 24px 0;
    }

    .metrics {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .profile dl {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        row-gap: 20px;
    }

    .cards {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 760px) {
    #topbar {
        height: 64px;
        padding: 0 16px;
    }

    .brand {
        font-size: 16px;
    }

    .account {
        gap: 8px;
    }

    .account > .avatar, .account > span:not(.badge) {
        display: none;
    }

    .account > .badge {
        margin: 0;
        padding: 5px;
        font-size: 9px;
    }

    .shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
        padding: 16px;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .sidebar > small, .sidebar > p, .sidebar hr, .sidebar footer {
        display: none;
    }

    .sidebar > a {
        align-self: flex-end;
        padding: 6px 0;
        margin-bottom: 12px;
        font-size: 11px;
    }

    .sidebar > a .badge {
        display: none;
    }

    .sidebar > header {
        padding: 0;
    }

    .search {
        margin: 12px 0;
    }

    .residents {
        display: flex;
        flex-shrink: 0;
        gap: 8px;
        padding-bottom: 4px;
    }

    .residents a {
        min-width: 168px;
        padding: 9px;
        gap: 8px;
    }

    .residents strong {
        font-size: 11px;
    }

    .residents .badge {
        display: none;
    }

    main {
        padding: 22px 16px 0;
    }

    h1 {
        font-size: 26px;
    }

    .page-header {
        align-items: start;
    }

    .page-header p {
        font-size: 10px;
    }

    .page-header > .badge {
        white-space: normal;
        text-align: right;
    }

    .profile {
        padding: 17px;
    }

    .profile dl {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .metrics-heading {
        align-items: start;
    }

    .metrics-heading p {
        font-size: 10px;
    }

    .metrics {
        gap: 8px;
    }

    .metrics > a {
        padding: 12px;
    }

    .metrics header {
        font-size: 9px;
    }

    .metrics strong {
        font-size: 23px;
    }

    .metrics > a > small {
        white-space: normal;
    }

    .segmented a {
        padding: 7px 9px;
        font-size: 9px;
    }

    .readings {
        padding: 17px 14px 12px;
    }

    .events > header {
        padding: 17px 14px;
        flex-wrap: wrap;
    }

    .events article {
        grid-template-columns: 46px minmax(0, 1fr);
        gap: 10px;
        padding: 16px 14px;
    }

    .events article > a {
        grid-column: 2;
    }

    .events footer {
        padding: 12px 14px;
        font-size: 9px;
    }

    main > section > footer > span:last-child {
        display: none;
    }
}

#live-status { color: var(--muted); font-size: 11px; margin: -10px 0 18px; }

.history-time { color: var(--muted); font-size: 11px; margin: 8px 0; }
