/* Unified app shell — CSS Grid (single source of truth) */
:root {
    --shell-sidebar-width: 240px;
    --shell-canvas: #F0F2F5;
    --shell-header-height: 64px;
    --shell-content-max: 1120px;
}

/* Overlays — outside grid flow */
.hamilku-app-shell__overlays {
    position: fixed;
    inset: 0;
    z-index: 2100;
    pointer-events: none;
}

.hamilku-app-shell__overlays > * {
    pointer-events: auto;
}

/* Shell grid — mobile default */
.page.hamilku-app-shell {
    display: grid;
    width: 100% !important;
    min-height: 100dvh;
    height: 100dvh;
    max-height: 100dvh;
    background: var(--shell-canvas, #F0F2F5);
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
    grid-template-areas:
        "main"
        "bottomnav";
}

.hamilku-app-shell__sidebar {
    display: none !important;
}

.hamilku-app-shell__main {
    grid-area: main;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    width: 100% !important;
    background: var(--shell-canvas, #F0F2F5);
}

.hamilku-app-shell__scroll {
    flex: 1;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    width: 100% !important;
}

.hamilku-app-shell__scroll > .hamilku-app-shell__page {
    width: 100% !important;
    max-width: none;
    margin-inline: 0;
    box-sizing: border-box;
}

.hamilku-app-shell__page {
    width: 100%;
    min-height: 100%;
    position: relative;
}

.hamilku-app-shell__content {
    position: relative;
    width: 100%;
    max-width: var(--shell-content-max, 1120px);
    margin-inline: auto;
    box-sizing: border-box;
    padding-inline: var(--space-4, 16px);
}

@media (min-width: 1024px) {
    .hamilku-app-shell__content {
        padding-inline: var(--space-6, 24px);
    }
}

/* Fixed FABs — never stretch with page/shell width rules */
.hamilku-sos-fab,
.kia-selfcare-fab,
.kia-fab-root {
    width: auto !important;
    max-width: none !important;
    margin-inline: 0 !important;
}

.kia-selfcare-fab {
    width: 56px !important;
    min-width: 56px !important;
    max-width: 56px !important;
    height: 56px !important;
    min-height: 56px !important;
    max-height: 56px !important;
    flex: 0 0 auto;
    box-sizing: border-box;
    aspect-ratio: 1;
}

.hamilku-app-shell__bottom-nav {
    grid-area: bottomnav;
    position: static;
    width: 100% !important;
}

/* Desktop — LinkedIn-style white header + full-width main; hide bottom nav */
@media (min-width: 1024px) {
    .page.hamilku-app-shell.hamilku-app-shell--with-header,
    .page.hamilku-app-shell.hamilku-app-shell--with-sidebar {
        grid-template-columns: 1fr;
        grid-template-rows: var(--shell-header-height) 1fr;
        grid-template-areas:
            "header"
            "main";
        width: 100% !important;
        background: var(--shell-canvas, #F0F2F5);
    }

    .hamilku-app-shell__sidebar {
        display: none !important;
    }

    .hamilku-app-shell__bottom-nav {
        display: none !important;
    }

    .hamilku-app-shell__scroll {
        padding-bottom: 0;
        width: 100% !important;
    }
}

/* Nav link reset (Bootstrap + NavLink isolation) */
.hamilku-sidebar a,
.hamilku-sidebar a:visited {
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
}

.hamilku-sidebar a:hover,
.hamilku-sidebar a:focus-visible {
    color: #fff;
}

.hamilku-sidebar a.active {
    color: #fff;
    font-weight: 600;
}

/* Bottom nav — global (NavLink <a> is outside component CSS isolation) */
.hamilku-bottom-nav a.hamilku-bottom-nav__link,
.hamilku-bottom-nav a.hamilku-bottom-nav__link:visited {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    width: 100%;
    height: 100%;
    min-height: calc(var(--touch-target-min, 44px) + 1.85rem);
    padding: var(--space-2, 8px) var(--space-1, 4px);
    box-sizing: border-box;
    text-align: center;
    text-decoration: none;
    color: var(--color-muted, #888);
    font: var(--type-body-sm, 400 0.875rem/1.25 system-ui);
}

.hamilku-bottom-nav a.hamilku-bottom-nav__link.active,
.hamilku-bottom-nav a.hamilku-bottom-nav__link:hover,
.hamilku-bottom-nav a.hamilku-bottom-nav__link:focus-visible {
    color: var(--color-primary, var(--primer, #169873));
}

.hamilku-bottom-nav a.hamilku-bottom-nav__link .hamilku-bottom-nav__sprite {
    display: block;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    margin-inline: auto;
    position: relative;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

.hamilku-bottom-nav a.hamilku-bottom-nav__link .hamilku-bottom-nav__sprite::before,
.hamilku-bottom-nav a.hamilku-bottom-nav__link .hamilku-bottom-nav__sprite::after {
    content: '';
    position: absolute;
    inset: 0;
    background-repeat: no-repeat;
    background-size: contain;
    background-position: center;
}

.hamilku-bottom-nav a.hamilku-bottom-nav__link .hamilku-bottom-nav__sprite::after {
    opacity: 0;
    z-index: 1;
}

.hamilku-bottom-nav a.hamilku-bottom-nav__link:nth-child(1) .hamilku-bottom-nav__sprite::before {
    background-image: url(/menu1.png);
}

.hamilku-bottom-nav a.hamilku-bottom-nav__link:nth-child(2) .hamilku-bottom-nav__sprite::before {
    background-image: url(/menu2.png);
}

.hamilku-bottom-nav a.hamilku-bottom-nav__link:nth-child(3) .hamilku-bottom-nav__sprite::before {
    background-image: url(/menu3.png);
}

.hamilku-bottom-nav a.hamilku-bottom-nav__link:nth-child(4) .hamilku-bottom-nav__sprite::before {
    background-image: url(/menu4.png);
}

.hamilku-bottom-nav a.hamilku-bottom-nav__link:nth-child(5) .hamilku-bottom-nav__sprite::before {
    background-image: url(/menu5.png);
}

.hamilku-bottom-nav a.hamilku-bottom-nav__link.active:nth-child(1) .hamilku-bottom-nav__sprite::after {
    background-image: url(/menu1On.png);
    opacity: 1;
}

.hamilku-bottom-nav a.hamilku-bottom-nav__link.active:nth-child(2) .hamilku-bottom-nav__sprite::after {
    background-image: url(/menu2On.png);
    opacity: 1;
}

.hamilku-bottom-nav a.hamilku-bottom-nav__link.active:nth-child(3) .hamilku-bottom-nav__sprite::after {
    background-image: url(/menu3On.png);
    opacity: 1;
}

.hamilku-bottom-nav a.hamilku-bottom-nav__link.active:nth-child(4) .hamilku-bottom-nav__sprite::after {
    background-image: url(/menu4On.png);
    opacity: 1;
}

.hamilku-bottom-nav a.hamilku-bottom-nav__link.active:nth-child(5) .hamilku-bottom-nav__sprite::after {
    background-image: url(/menu5On.png);
    opacity: 1;
}

.hamilku-bottom-nav a.hamilku-bottom-nav__link .hamilku-bottom-nav__label {
    display: block;
    width: 100%;
    margin: 0;
    font-size: 0.7rem;
    line-height: 1.1;
    font-weight: 400;
    text-align: center;
}

.hamilku-bottom-nav a.hamilku-bottom-nav__link .hamilku-bottom-nav__indicator {
    position: absolute;
    top: 0;
    left: 20%;
    right: 20%;
    height: 3px;
    background: var(--color-primary, var(--primer, #169873));
    border-radius: 0 0 var(--shape-xs, 4px) var(--shape-xs, 4px);
    pointer-events: none;
}

.hamilku-bottom-nav a.hamilku-bottom-nav__link:not(.active) .hamilku-bottom-nav__indicator {
    display: none;
}

/* Sidebar (desktop) — deferred green chrome; sidebar hidden in Phase 6 PC shell */
@media (min-width: 1024px) {
    .hamilku-sidebar {
        display: none !important;
    }
}

/* Dashboard page — single column (Buku KIA lives in Diary) */
.dashboard-page {
    display: block;
    width: 100%;
    min-height: 100%;
}

.dashboard-main {
    min-width: 0;
}

@media (min-width: 1024px) {
    .dashboard-page {
        padding: 0;
    }
}

/* Mobile services balanced grid */
@media (max-width: 767px) {
    #indexDashboard .menu .boxBtn {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: var(--space-3, 12px) var(--space-3, 12px);
        grid-template-rows: auto auto;
    }

    #indexDashboard .menu .boxBtn .menu-item:nth-child(n+5) {
        grid-column: span 1;
    }

    #indexDashboard .menu .boxBtn .menu-item:nth-child(5) {
        grid-column: 1;
    }

    #indexDashboard .menu .boxBtn .menu-item:nth-child(6) {
        grid-column: 2;
    }

    #indexDashboard .menu .boxBtn .menu-item:nth-child(7) {
        grid-column: 3;
    }
}

@media (min-width: 1024px) {
    #indexDashboard .menu .boxBtn {
        display: grid;
        grid-template-columns: repeat(7, minmax(88px, 1fr));
        gap: var(--space-4, 16px);
        overflow-x: visible;
        padding-bottom: 0;
    }

    #indexDashboard .menu .boxBtn .menu-item {
        min-width: 0;
        width: 100%;
    }
}

/* Desktop top header (LinkedIn-inspired) — global for NavLink isolation */
.hamilku-top-header {
    display: none;
    width: 100% !important;
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    box-sizing: border-box;
}

.hamilku-top-header__inner {
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    gap: 16px;
    width: 100% !important;
    max-width: var(--shell-content-max, 1120px);
    margin-inline: auto;
    min-height: 64px;
    padding: 0 16px;
    box-sizing: border-box;
}

.hamilku-top-header__brand {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--brand-primary, #169873);
    font-weight: 700;
    flex-shrink: 0;
}

.hamilku-top-header__brand:hover,
.hamilku-top-header__brand:focus-visible {
    color: var(--brand-primary-hover, #148D6C);
}

.hamilku-top-header__logo {
    display: block;
    width: 34px;
    height: 34px;
    object-fit: contain;
}

.hamilku-top-header__search {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 180px;
    max-width: 480px;
}

.hamilku-top-header__nav {
    display: flex;
    align-items: stretch;
    margin-left: 0;
    gap: 2px;
}

.hamilku-top-header a.hamilku-top-header__link,
.hamilku-top-header a.hamilku-top-header__link:visited {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 72px;
    min-height: 64px;
    padding: 8px 10px 10px;
    text-decoration: none;
    color: #666;
    font-size: 0.7rem;
    line-height: 1.1;
    box-sizing: border-box;
}

.hamilku-top-header a.hamilku-top-header__link:hover,
.hamilku-top-header a.hamilku-top-header__link:focus-visible {
    color: var(--brand-primary, #16AB51);
}

.hamilku-top-header a.hamilku-top-header__link.active {
    color: var(--brand-primary, #16AB51);
    font-weight: 600;
}

.hamilku-top-header__underline {
    display: none;
    position: absolute;
    left: 6%;
    right: 6%;
    bottom: 0;
    height: 3px;
    background: var(--brand-primary, #16AB51);
    border-radius: 2px 2px 0 0;
}

.hamilku-top-header a.hamilku-top-header__link.active .hamilku-top-header__underline {
    display: block;
}

.hamilku-top-header__sprite {
    width: 28px;
    height: 28px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    filter: grayscale(1) opacity(0.7);
}

.hamilku-top-header a.hamilku-top-header__link.active .hamilku-top-header__sprite {
    filter: none;
}

.hamilku-top-header__sprite--0 { background-image: url(/menu1.png); }
.hamilku-top-header a.hamilku-top-header__link.active .hamilku-top-header__sprite--0 { background-image: url(/menu1On.png); }
.hamilku-top-header__sprite--1 { background-image: url(/menu2.png); }
.hamilku-top-header a.hamilku-top-header__link.active .hamilku-top-header__sprite--1 { background-image: url(/menu2On.png); }
.hamilku-top-header__sprite--2 { background-image: url(/menu3.png); }
.hamilku-top-header a.hamilku-top-header__link.active .hamilku-top-header__sprite--2 { background-image: url(/menu3On.png); }
.hamilku-top-header__sprite--3 { background-image: url(/menu4.png); }
.hamilku-top-header a.hamilku-top-header__link.active .hamilku-top-header__sprite--3 { background-image: url(/menu4On.png); }
.hamilku-top-header__sprite--4 { background-image: url(/menu5.png); }
.hamilku-top-header a.hamilku-top-header__link.active .hamilku-top-header__sprite--4 { background-image: url(/menu5On.png); }

@media (min-width: 1024px) {
    .hamilku-top-header {
        display: block;
        grid-area: header;
    }
}
