/* ==========================================================================
   FERMA FIIP — Application layout: shell, sidebar, topbar, footer, auth screens
   ========================================================================== */

/* ----- App shell ----- */
.ferma-shell {
    display: flex;
    min-height: 100vh;
    position: relative;
}

.ferma-main {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--ferma-surface-alt);
}

/* ----- Sidebar ----- */
.ferma-sidebar {
    flex: 0 0 var(--ferma-sidebar-width);
    width: var(--ferma-sidebar-width);
    background: linear-gradient(180deg, var(--ferma-road-asphalt) 0%, var(--ferma-road-asphalt-dark) 100%);
    color: #cdd3d8;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    transition: flex-basis var(--ferma-transition), width var(--ferma-transition);
    z-index: 1040;
}

.ferma-sidebar__brand {
    height: var(--ferma-topbar-height);
    display: flex;
    align-items: center;
    padding: 0 0.9rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex: 0 0 auto;
}

.ferma-sidebar__brand-link {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    color: #fff;
    text-decoration: none;
    overflow: hidden;
    white-space: nowrap;
}

.ferma-sidebar__brand-link:hover {
    color: #fff;
    text-decoration: none;
}

.ferma-sidebar__logo {
    display: block;
    height: 40px;
    width: auto;
}

/* Full lockup shows when expanded; compact mark shows when collapsed. */
.ferma-sidebar__logo--mark {
    display: none;
    height: 42px;
}

.ferma-sidebar__nav {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 0.75rem 0.6rem 1rem;
    /* Hide scrollbar chrome while keeping scroll behaviour (Firefox / IE). */
    scrollbar-width: none;
    -ms-overflow-style: none;
}

/* Hide scrollbar chrome on WebKit/Blink browsers. */
.ferma-sidebar__nav::-webkit-scrollbar {
    width: 0;
    height: 0;
    display: none;
}

.ferma-nav-group {
    margin-bottom: 0.65rem;
}

.ferma-nav-group__title {
    margin: 0.6rem 0 0.3rem;
    padding: 0 0.65rem;
    font-size: 0.66rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #79838b;
}

.ferma-nav-group__items {
    list-style: none;
    margin: 0;
    padding: 0;
}

.ferma-nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.55rem 0.65rem;
    margin: 0.1rem 0;
    border-radius: var(--ferma-radius-sm);
    color: #cdd3d8;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    transition: background var(--ferma-transition), color var(--ferma-transition);
    border-left: 3px solid transparent;
}

.ferma-nav-link:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
    text-decoration: none;
}

.ferma-nav-link.is-active {
    background: rgba(0, 107, 63, 0.22);
    color: #fff;
    border-left-color: var(--ferma-safety-yellow);
}

.ferma-nav-link__icon {
    flex: 0 0 auto;
    font-size: 1.05rem;
    width: 1.4rem;
    text-align: center;
}

.ferma-nav-link__label {
    flex: 1 1 auto;
    font-size: 0.86rem;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ferma-sidebar__footer {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.7rem 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 0.72rem;
    color: #9aa3aa;
}

.ferma-sidebar__footer-flag {
    flex: 0 0 auto;
    width: 26px;
    height: 16px;
    border-radius: 2px;
    background: linear-gradient(90deg, var(--ferma-green) 0 33%, #fff 33% 66%, var(--ferma-green) 66% 100%);
    box-shadow: var(--ferma-shadow-sm);
}

/* ----- Collapsed (desktop icon-only) ----- */
.ferma-shell--collapsed .ferma-sidebar {
    flex-basis: var(--ferma-sidebar-collapsed);
    width: var(--ferma-sidebar-collapsed);
}

.ferma-shell--collapsed .ferma-sidebar__logo--full,
.ferma-shell--collapsed .ferma-nav-group__title,
.ferma-shell--collapsed .ferma-nav-link__label,
.ferma-shell--collapsed .ferma-sidebar__footer-text {
    display: none;
}

.ferma-shell--collapsed .ferma-sidebar__logo--mark {
    display: block;
}

.ferma-shell--collapsed .ferma-nav-link {
    justify-content: center;
    gap: 0;
}

.ferma-shell--collapsed .ferma-sidebar__brand-link {
    justify-content: center;
}

.ferma-shell--collapsed .ferma-sidebar__footer {
    justify-content: center;
}

/* ----- Backdrop (mobile drawer) ----- */
.ferma-sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.5);
    z-index: 1035;
}

/* ----- Topbar ----- */
.ferma-topbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    height: var(--ferma-topbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0 1.1rem;
    background: var(--ferma-surface);
    border-bottom: 1px solid var(--ferma-border);
    box-shadow: var(--ferma-shadow-sm);
}

.ferma-topbar__left,
.ferma-topbar__right {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    min-width: 0;
}

.ferma-topbar__titles {
    min-width: 0;
}

.ferma-topbar__eyebrow {
    display: block;
    font-size: 0.66rem;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--ferma-muted);
}

.ferma-topbar__title {
    margin: 0;
    font-size: 1.02rem;
    font-weight: 700;
    color: var(--ferma-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 52vw;
}

.ferma-iconbtn {
    display: inline-grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border: 1px solid transparent;
    border-radius: var(--ferma-radius-sm);
    background: transparent;
    color: var(--ferma-road-asphalt);
    font-size: 1.15rem;
    cursor: pointer;
    position: relative;
}

.ferma-iconbtn:hover {
    background: var(--ferma-cloud);
    border-color: var(--ferma-border);
}

.ferma-topbar__notify-dot {
    position: absolute;
    top: 8px;
    right: 9px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ferma-danger);
    border: 2px solid var(--ferma-surface);
}

/* User button */
.ferma-userbtn {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    background: transparent;
    border: 1px solid var(--ferma-border);
    border-radius: 999px;
    padding: 0.25rem 0.7rem 0.25rem 0.3rem;
    cursor: pointer;
}

.ferma-userbtn:hover {
    background: var(--ferma-cloud);
}

.ferma-userbtn__avatar {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--ferma-green);
    color: #fff;
    font-weight: 700;
    font-size: 0.8rem;
}

.ferma-userbtn__meta {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
    text-align: left;
}

.ferma-userbtn__name {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--ferma-text);
}

.ferma-userbtn__role {
    font-size: 0.7rem;
    color: var(--ferma-muted);
}

.ferma-usermenu {
    min-width: 260px;
    padding: 0;
    border: 1px solid var(--ferma-border);
    box-shadow: var(--ferma-shadow-lg);
}

.ferma-usermenu__header {
    padding: 0.8rem 1rem 0.4rem;
}

.ferma-usermenu__name {
    margin: 0;
    font-weight: 700;
}

.ferma-usermenu__email {
    margin: 0;
    font-size: 0.78rem;
    color: var(--ferma-muted);
}

.ferma-usermenu__detail {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.25rem 1rem;
    font-size: 0.8rem;
}

.ferma-usermenu__detail span {
    color: var(--ferma-muted);
}

/* ----- Content + footer ----- */
.ferma-content {
    flex: 1 1 auto;
    padding: 1.2rem 1.3rem 2rem;
    max-width: 1500px;
    width: 100%;
    margin: 0 auto;
}

.ferma-page-subtitle {
    color: var(--ferma-muted);
    margin: 0.2rem 0 1rem;
    max-width: 70ch;
}

.ferma-footer {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    padding: 0.85rem 1.3rem;
    background: var(--ferma-surface);
    border-top: 1px solid var(--ferma-border);
    font-size: 0.78rem;
    color: var(--ferma-muted);
}

.ferma-footer__identity strong {
    color: var(--ferma-text);
    display: block;
}

.ferma-footer__support {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.ferma-corrid {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.ferma-corrid code {
    background: var(--ferma-cloud);
    border: 1px solid var(--ferma-border);
    border-radius: 4px;
    padding: 0.05rem 0.4rem;
    color: var(--ferma-road-asphalt);
}

.ferma-corrid--block {
    display: flex;
    width: 100%;
    flex-wrap: wrap;
}

/* ----- Responsive: mobile drawer ----- */
@media (max-width: 991.98px) {
    .ferma-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        transform: translateX(-100%);
        transition: transform var(--ferma-transition);
        box-shadow: var(--ferma-shadow-lg);
    }

    .ferma-shell--mobile-open .ferma-sidebar {
        transform: translateX(0);
    }

    .ferma-shell--mobile-open .ferma-sidebar-backdrop {
        display: block;
    }

    .ferma-topbar__title {
        max-width: 40vw;
    }

    /* On mobile the collapsed (icon-only) desktop mode does not apply. */
    .ferma-shell--collapsed .ferma-sidebar {
        width: var(--ferma-sidebar-width);
        flex-basis: var(--ferma-sidebar-width);
    }

    .ferma-shell--collapsed .ferma-nav-link__label,
    .ferma-shell--collapsed .ferma-nav-group__title,
    .ferma-shell--collapsed .ferma-sidebar__logo--full,
    .ferma-shell--collapsed .ferma-sidebar__footer-text {
        display: revert;
    }

    .ferma-shell--collapsed .ferma-sidebar__logo--mark {
        display: none;
    }
}

/* ==========================================================================
   Auth layout (login / errors)
   ========================================================================== */
.ferma-auth {
    min-height: 100vh;
    background: var(--ferma-surface-alt);
}

.ferma-auth__shell {
    display: grid;
    grid-template-columns: 1.05fr 1fr;
    min-height: 100vh;
}

.ferma-auth__brandpane {
    position: relative;
    background:
        linear-gradient(180deg, rgba(0, 63, 42, 0.92), rgba(31, 36, 39, 0.95)),
        repeating-linear-gradient(90deg, transparent 0 48px, rgba(246, 195, 67, 0.10) 48px 56px);
    color: #fff;
    display: flex;
    align-items: center;
    padding: 3rem;
    overflow: hidden;
}

.ferma-auth__brandpane::after {
    /* Stylised road centre-line motif */
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 12%;
    height: 10px;
    background: repeating-linear-gradient(90deg, var(--ferma-safety-yellow) 0 38px, transparent 38px 76px);
    opacity: 0.45;
}

.ferma-auth__brandpane-content {
    position: relative;
    z-index: 1;
    max-width: 420px;
}

.ferma-auth__mark {
    display: block;
    width: auto;
    height: 72px;
    margin-bottom: 1.4rem;
}

.ferma-auth__agency {
    font-size: 1.45rem;
    font-weight: 800;
    margin: 0 0 0.3rem;
}

.ferma-auth__platform {
    font-size: 1rem;
    color: #d7dde1;
    margin: 0 0 0.2rem;
}

.ferma-auth__nation {
    font-size: 0.85rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--ferma-safety-yellow);
    margin: 0 0 1.8rem;
}

.ferma-auth__points {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 0.7rem;
}

.ferma-auth__points li {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    color: #e5e9ec;
    font-size: 0.9rem;
}

.ferma-auth__points i {
    color: var(--ferma-safety-yellow);
}

.ferma-auth__formpane {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2.5rem 1.5rem;
}

.ferma-auth__formcard {
    width: 100%;
    max-width: 440px;
    background: var(--ferma-surface);
    border: 1px solid var(--ferma-border);
    border-radius: var(--ferma-radius-lg);
    box-shadow: var(--ferma-shadow-md);
    padding: 2rem 2rem 1.6rem;
}

.ferma-auth__footer {
    margin-top: 1.5rem;
    text-align: center;
    color: var(--ferma-muted);
    font-size: 0.78rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

@media (max-width: 860px) {
    .ferma-auth__shell {
        grid-template-columns: 1fr;
    }

    .ferma-auth__brandpane {
        display: none;
    }
}

/* ==========================================================================
   Phase-2 topbar additions: global search, demo badge, notifications
   ========================================================================== */

.ferma-topbar__search {
    position: relative;
    flex: 1 1 420px;
    max-width: 520px;
    display: flex;
    align-items: center;
}

.ferma-search__icon {
    position: absolute;
    left: 0.75rem;
    color: var(--ferma-muted);
    pointer-events: none;
}

.ferma-search__input {
    width: 100%;
    height: 40px;
    padding: 0 0.9rem 0 2.2rem;
    border: 1px solid var(--ferma-border);
    border-radius: 999px;
    background: var(--ferma-cloud);
    font-size: 0.86rem;
}

.ferma-search__input:focus {
    outline: none;
    border-color: var(--ferma-green);
    background: var(--ferma-surface);
    box-shadow: 0 0 0 0.2rem rgba(0, 107, 63, 0.12);
}

.ferma-search__results {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: var(--ferma-surface);
    border: 1px solid var(--ferma-border);
    border-radius: var(--ferma-radius);
    box-shadow: var(--ferma-shadow-lg);
    max-height: 60vh;
    overflow-y: auto;
    z-index: 1200;
    padding: 0.35rem;
}

.ferma-search__result {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0.6rem;
    border-radius: var(--ferma-radius-sm);
    color: var(--ferma-text);
    text-decoration: none;
}

.ferma-search__result:hover,
.ferma-search__result:focus {
    background: var(--ferma-cloud);
    text-decoration: none;
}

.ferma-search__result > i {
    color: var(--ferma-green);
    font-size: 1.05rem;
}

.ferma-search__result-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1 1 auto;
}

.ferma-search__result-title {
    font-weight: 600;
    font-size: 0.85rem;
}

.ferma-search__result-sub {
    font-size: 0.76rem;
    color: var(--ferma-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ferma-search__result-cat {
    flex: 0 0 auto;
    font-size: 0.66rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ferma-muted);
    background: var(--ferma-cloud);
    border: 1px solid var(--ferma-border);
    border-radius: 999px;
    padding: 0.1rem 0.45rem;
}

.ferma-search__empty {
    padding: 0.8rem;
    text-align: center;
    color: var(--ferma-muted);
    font-size: 0.84rem;
}

/* Demo mode badge */
.ferma-demobadge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: rgba(246, 195, 67, 0.18);
    color: #8a5a00;
    border: 1px solid rgba(246, 195, 67, 0.6);
    border-radius: 999px;
    padding: 0.25rem 0.6rem;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

/* Notifications */
.ferma-topbar__badge {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--ferma-danger);
    color: #fff;
    font-size: 0.62rem;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
    border: 2px solid var(--ferma-surface);
}

.ferma-notify-menu {
    width: 360px;
    max-width: 92vw;
    padding: 0;
    border: 1px solid var(--ferma-border);
    box-shadow: var(--ferma-shadow-lg);
    overflow: hidden;
}

.ferma-notify-menu__head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.7rem 0.9rem;
    font-weight: 700;
    border-bottom: 1px solid var(--ferma-border);
}

.ferma-notify-menu__count {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--ferma-danger);
}

.ferma-notify-menu__markall {
    background: none;
    border: 0;
    color: var(--ferma-green);
    font-size: 0.74rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0;
}
.ferma-notify-menu__markall:hover { text-decoration: underline; }

.ferma-notify-menu__list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 60vh;
    overflow-y: auto;
}

.ferma-note {
    display: flex;
    gap: 0.6rem;
    padding: 0.7rem 0.9rem;
    border-bottom: 1px solid var(--ferma-border);
    color: var(--ferma-text);
    text-decoration: none;
    position: relative;
}

.ferma-note:hover {
    background: var(--ferma-cloud);
    text-decoration: none;
}

.ferma-note.is-unread {
    background: rgba(13, 110, 253, 0.04);
}

.ferma-note__icon {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    font-size: 1rem;
}

.ferma-note--info .ferma-note__icon { background: #e7f0ff; color: var(--ferma-info); }
.ferma-note--success .ferma-note__icon { background: #e7f3ec; color: var(--ferma-success); }
.ferma-note--warning .ferma-note__icon { background: #fdf3e2; color: var(--ferma-warning-amber); }
.ferma-note--danger .ferma-note__icon { background: #fbe9eb; color: var(--ferma-danger); }
.ferma-note--critical .ferma-note__icon { background: #fbe5e3; color: var(--ferma-critical); }

.ferma-note__body { display: flex; flex-direction: column; min-width: 0; }
.ferma-note__title { font-weight: 600; font-size: 0.83rem; }
.ferma-note__msg { font-size: 0.78rem; color: var(--ferma-muted); }
.ferma-note__time { font-size: 0.7rem; color: var(--ferma-muted); margin-top: 0.1rem; }

.ferma-note__dot {
    position: absolute;
    top: 0.9rem;
    right: 0.8rem;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ferma-info);
}

.ferma-notify-menu__foot {
    padding: 0.55rem 0.9rem;
    text-align: center;
    border-top: 1px solid var(--ferma-border);
    background: var(--ferma-cloud);
}

@media (max-width: 1100px) {
    .ferma-topbar__search { flex-basis: 240px; }
}

@media (max-width: 860px) {
    .ferma-topbar__search { display: none; }
    .ferma-demobadge__text { display: none; }
}
