/* =========================================================
   BASE
   The site shell: side menu, top bar and page area.

   Signed-in pages (body.has-nav) get a permanent side menu on
   wide screens; below 1100px it becomes a slide-in drawer opened
   from the top bar. The login page and kiosk have no menu.
   ========================================================= */

:root {
    --nav-width: 232px;
    --topbar-height: 56px;
    --shell: #1a1d23;
    --shell-border: #2b3037;
}

/* clip, not hidden: hidden on both made body a scroll box of its
   own, so the sticky top bar and farm tabs scrolled away */
html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    overflow-x: clip;
    background: var(--bg);
}

body {
    margin: 0;
    color: var(--text);
}

.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

body.has-nav .app {
    margin-left: var(--nav-width);
}

/* Room for the scrollbar on every page, so short and long pages line up */
html {
    scrollbar-gutter: stable;
}

main {
    width: 100%;
    max-width: 1920px;
    margin: 0 auto;
    padding: 20px 24px 40px;
    box-sizing: border-box;
}


/* =========================================================
   BRAND
   ========================================================= */

.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    text-decoration: none;
    line-height: 1;
}

.site-logo {
    width: 34px;
    height: 34px;
    object-fit: contain;
}

.brand-text {
    display: flex;
    flex-direction: column;
}

.brand-main {
    font-size: 16px;
    font-weight: 800;
    letter-spacing: 1.2px;
    color: #ffffff;
}

.brand-sub {
    margin-top: 4px;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 3px;
    color: var(--green);
}


/* =========================================================
   SIDE MENU
   ========================================================= */

#side-menu {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--nav-width);
    height: 100vh;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    padding: 0 10px 12px;
    background: var(--shell);
    border-right: 1px solid var(--shell-border);
    overflow-y: auto;
    z-index: 1100;
}

#side-menu .brand {
    flex-shrink: 0;
    height: var(--topbar-height);
    padding: 0 8px;
    margin-bottom: 6px;
}

.nav-group {
    padding: 16px 10px 6px;
    color: #6f7a82;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 1.4px;
    text-transform: uppercase;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 10px;
    margin-bottom: 2px;
    border-radius: 7px;
    color: #b9c1c7;
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 600;
    transition: background 0.12s ease, color 0.12s ease;
}

.nav-link .material-symbols-outlined {
    font-size: 20px;
    color: #7c8890;
}

.nav-link:hover {
    background: #23272e;
    color: #ffffff;
}

/* The page you are on */
.nav-link.active {
    background: var(--green-bg);
    color: #ffffff;
}

.nav-link.active .material-symbols-outlined,
.nav-link:hover .material-symbols-outlined {
    color: var(--green-light);
}

/* Number of active events, next to the Events link */
.nav-count {
    margin-left: auto;
    min-width: 20px;
    padding: 2px 6px;
    box-sizing: border-box;
    border-radius: 999px;
    background: var(--sev-colour, var(--bad));
    color: #14171b;
    font-size: 11px;
    font-weight: 800;
    text-align: center;
}

.nav-foot {
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid var(--shell-border);
}

.nav-farm {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px 10px;
    color: #d5dbdf;
    font-size: 13px;
    font-weight: 600;
}

.nav-farm .material-symbols-outlined {
    font-size: 19px;
    color: var(--green-light);
}


/* =========================================================
   TOP BAR
   ========================================================= */

.topbar {
    position: sticky;
    top: 0;
    z-index: 1000;
    flex-shrink: 0;
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 24px;
    box-sizing: border-box;
    background: var(--shell);
    border-bottom: 1px solid var(--shell-border);
}

.header-left,
.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.page-name {
    overflow: hidden;
    color: #ffffff;
    font-size: 16px;
    font-weight: 700;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* Only needed when the side menu is a drawer (narrow screens) */
.menu-toggle {
    display: none;
    width: 40px;
    height: 40px;
    margin-left: -8px;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #ffffff;
    cursor: pointer;
}

.menu-toggle:hover {
    background: #2a2d34;
    color: var(--green-light);
}

.menu-toggle .material-symbols-outlined {
    font-size: 26px;
}


/* =========================================================
   ALARM CHIP
   Live count of active events, in the top bar of every page.
   data-state: loading | clear | info | warning | fault | critical
   ========================================================= */

.alarm-chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 34px;
    padding: 0 13px 0 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--panel2);
    color: #aeb7bd;
    font-size: 12.5px;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.12s ease, border-color 0.12s ease;
}

a.alarm-chip:hover {
    border-color: currentColor;
}

.alarm-chip .material-symbols-outlined {
    font-size: 19px;
}

.alarm-chip[data-state="clear"] {
    color: var(--good);
}

.alarm-chip[data-state="info"] {
    color: var(--sev-info);
}

.alarm-chip[data-state="warning"] {
    color: var(--sev-warning);
    border-color: rgba(241, 196, 15, 0.45);
    background: rgba(241, 196, 15, 0.08);
}

.alarm-chip[data-state="fault"] {
    color: var(--sev-fault);
    border-color: rgba(230, 126, 34, 0.5);
    background: rgba(230, 126, 34, 0.1);
}

.alarm-chip[data-state="critical"] {
    color: #ff8578;
    border-color: rgba(231, 76, 60, 0.6);
    background: rgba(231, 76, 60, 0.14);
}


/* =========================================================
   MENU OVERLAY (drawer mode)
   ========================================================= */

#menu-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1050;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

#menu-overlay.open {
    opacity: 1;
    visibility: visible;
}


/* =========================================================
   NARROW SCREENS: side menu becomes a drawer
   ========================================================= */

@media (max-width: 1100px) {

    body.has-nav .app {
        margin-left: 0;
    }

    #side-menu {
        left: calc(-1 * var(--nav-width) - 20px);
        box-shadow: 5px 0 20px rgba(0, 0, 0, 0.3);
        transition: left 0.22s ease;
    }

    #side-menu.open {
        left: 0;
    }

    .menu-toggle {
        display: flex;
    }
}

@media (max-width: 600px) {

    main {
        padding: 12px 12px 32px;
    }

    .topbar {
        padding: 0 12px;
    }
}


/* =========================================================
   DEMO BANNER
   ========================================================= */

.demo-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    padding: 9px 20px;
    background: #2a3a2f;
    border-bottom: 1px solid #36533f;
    color: #cfe9d9;
    font-size: 13px;
    text-align: center;
}

.demo-banner .material-symbols-outlined {
    font-size: 18px;
    color: var(--green-light);
}

.demo-toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    z-index: 2000;
    transform: translateX(-50%);
    padding: 11px 18px;
    border: 1px solid #36533f;
    border-radius: 8px;
    background: #2a3a2f;
    color: #e2f3e8;
    font-size: 13px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

/* Active events, but only on robots that are not milking */
.alarm-chip[data-state="idle"] {
    color: #c2c9ce;
}

.nav-count.nav-count-idle {
    background: #4a525a;
    color: #e4e8eb;
}


/* =========================================================
   FARM CHIP
   The farm every page shows, in the top bar. The farm pages
   follow it; the menu links carry it.
   ========================================================= */

.farm-chip {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 34px;
    min-width: 0;
    max-width: 280px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--panel2);
    color: #d5dbdf;
    font-size: 12.5px;
    font-weight: 700;
    white-space: nowrap;
    box-sizing: border-box;
}

.farm-chip .material-symbols-outlined {
    flex-shrink: 0;
    font-size: 18px;
    color: var(--green-light);
}

.farm-chip-chosen {
    border-color: rgba(63, 168, 120, 0.55);
    background: var(--green-bg);
    color: #ffffff;
}

.farm-chip:not(.farm-chip-fixed) {
    cursor: pointer;
}

.farm-chip:not(.farm-chip-fixed):hover,
.farm-chip:focus-within {
    border-color: var(--green);
}

.farm-chip select {
    min-width: 0;
    max-width: 100%;
    padding: 0 18px 0 0;
    margin-right: -18px;
    border: none;
    background: transparent;
    color: inherit;
    font: inherit;
    text-overflow: ellipsis;
    cursor: pointer;
    /* As wide as the chosen farm, not the longest one in the list */
    field-sizing: content;
    appearance: none;
    -webkit-appearance: none;
    outline: none;
}

.farm-chip select option {
    background: var(--panel);
    color: #e8ecef;
}

.farm-chip .farm-chip-caret {
    font-size: 18px;
    color: #aeb7bd;
    pointer-events: none;
}

.farm-chip-name {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* The chosen farm's own page, at the top of the menu */
.nav-link-farm span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}


/* =========================================================
   CHOOSE A FARM (a one-farm page opened with all farms)
   ========================================================= */

.choose-farm {
    max-width: 720px;
}

.choose-farm-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 10px;
}

.choose-farm-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel);
    color: #e8ecef;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
}

.choose-farm-item:hover {
    border-color: var(--green);
    background: var(--green-bg);
}

.choose-farm-item .material-symbols-outlined {
    color: var(--green-light);
}

.choose-farm-name {
    flex: 1;
}

.choose-farm-go {
    color: #89949c !important;
}

.choose-farm-none {
    color: var(--muted);
}


/* Narrow screens: the farm matters more than the page name, which
   the menu and the page heading already show */
@media (max-width: 600px) {

    .topbar .page-name {
        display: none;
    }

    .header-right {
        flex: 1;
        justify-content: flex-end;
        gap: 8px;
    }

    .farm-chip {
        flex: 0 1 auto;
        max-width: none;
    }
}


/* =========================================================
   FARM TABS
   Under the top bar on every page about the chosen farm. They
   stay in view while scrolling, and scroll sideways on phones.
   ========================================================= */

.farm-tabs {
    position: sticky;
    top: var(--topbar-height);
    z-index: 990;
    flex-shrink: 0;
    background: var(--shell);
    border-bottom: 1px solid var(--shell-border);
}

.farm-tabs-inner {
    display: flex;
    gap: 2px;
    max-width: 1920px;
    margin: 0 auto;
    padding: 0 16px;
    box-sizing: border-box;
    overflow-x: auto;
    scrollbar-width: none;
}

.farm-tabs-inner::-webkit-scrollbar {
    display: none;
}

.farm-tab {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    gap: 7px;
    padding: 11px 12px 10px;
    border-bottom: 2px solid transparent;
    color: var(--muted);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}

.farm-tab .material-symbols-outlined {
    font-size: 19px;
}

.farm-tab:hover {
    color: var(--text);
}

.farm-tab.active {
    color: #ffffff;
    border-bottom-color: var(--green);
}

.farm-tab.active .material-symbols-outlined {
    color: var(--green-light);
}

@media (max-width: 600px) {

    .farm-tabs-inner {
        padding: 0 6px;
    }

    .farm-tab {
        padding: 10px 10px 9px;
        font-size: 13px;
    }

    .farm-tab .material-symbols-outlined {
        font-size: 17px;
    }
}
