.login-gate {
    position: fixed;
    inset: 0;
    width: 100vw;
    z-index: 20000;
    min-height: 100vh;
    color: #123236;
    background:
        linear-gradient(90deg, rgba(246, 252, 248, 0.88) 0%, rgba(246, 252, 248, 0.58) 42%, rgba(246, 252, 248, 0.18) 100%),
        url("../assets/login-bg.png") center/cover no-repeat;
    background-color: #f7fbf8;
    display: grid;
    grid-template-columns: minmax(360px, 0.92fr) minmax(360px, 480px);
    align-items: center;
    gap: 56px;
    padding: clamp(28px, 5vw, 72px);
    overflow-x: hidden;
    transition: opacity 0.35s ease, visibility 0.35s ease;
}

.login-gate.login-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.login-brand {
    max-width: 760px;
    min-width: 0;
}

.login-brand-mark {
    width: 58px;
    height: 58px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    color: #0b5f59;
    font-weight: 800;
    font-size: 18px;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid rgba(255, 255, 255, 0.86);
    box-shadow: 0 16px 38px rgba(20, 92, 96, 0.12);
}

.login-kicker {
    margin-top: 26px;
    color: #14746b;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0;
}

.login-title {
    display: block;
    margin-top: 14px;
    max-width: 780px;
    font-size: clamp(34px, 4.1vw, 56px);
    line-height: 1.05;
    letter-spacing: 0;
    color: #102f33;
    font-weight: 800;
    white-space: normal;
    overflow-wrap: anywhere;
}

.login-mobile-break {
    display: none;
}

.login-subtitle {
    margin-top: 18px;
    max-width: 620px;
    color: #3d6869;
    font-size: 17px;
    line-height: 1.8;
}

.login-signal-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 34px;
}

.login-signal {
    height: 34px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0 13px;
    border-radius: 8px;
    color: #164b4f;
    background: rgba(255, 255, 255, 0.64);
    border: 1px solid rgba(255, 255, 255, 0.78);
    box-shadow: 0 10px 24px rgba(19, 99, 102, 0.08);
    font-size: 13px;
    font-weight: 650;
}

.login-signal::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #2aa889;
    box-shadow: 0 0 0 4px rgba(42, 168, 137, 0.14);
}

.login-panel {
    width: min(100%, 440px);
    min-width: 0;
    justify-self: end;
    padding: 28px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid rgba(255, 255, 255, 0.88);
    box-shadow: 0 26px 76px rgba(15, 70, 78, 0.18);
    backdrop-filter: blur(22px);
    -webkit-backdrop-filter: blur(22px);
}

.login-panel h2 {
    margin: 0;
    color: #123236;
    font-size: 22px;
    letter-spacing: 0;
}

.login-panel-caption {
    margin-top: 8px;
    color: #5d7979;
    font-size: 13px;
}

.login-form {
    margin-top: 26px;
    display: grid;
    gap: 16px;
}

.login-field {
    display: grid;
    gap: 8px;
}

.login-field label {
    color: #284f52;
    font-size: 13px;
    font-weight: 700;
}

.login-input-wrap {
    position: relative;
}

.login-input-wrap input {
    width: 100%;
    height: 46px;
    border: 1px solid rgba(35, 99, 105, 0.18);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.86);
    color: #102f33;
    outline: none;
    padding: 0 14px;
    font-size: 15px;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.login-input-wrap input:focus {
    border-color: #24a284;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 0 0 4px rgba(36, 162, 132, 0.14);
}

.login-password-toggle {
    position: absolute;
    top: 7px;
    right: 7px;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 8px;
    color: #42686a;
    background: transparent;
    cursor: pointer;
    font-size: 16px;
}

.login-password-toggle:hover {
    background: rgba(36, 162, 132, 0.1);
}

.login-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 24px;
}

.login-check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #4f7071;
    font-size: 13px;
}

.login-check input {
    width: 15px;
    height: 15px;
    accent-color: #24a284;
}

.login-error {
    min-height: 18px;
    color: #d33d36;
    font-size: 13px;
    text-align: right;
}

.login-submit {
    height: 46px;
    border: 0;
    border-radius: 8px;
    color: #fff;
    background: linear-gradient(135deg, #159a86 0%, #2877c9 100%);
    box-shadow: 0 16px 34px rgba(35, 125, 158, 0.24);
    cursor: pointer;
    font-size: 15px;
    font-weight: 800;
    letter-spacing: 0;
    transition: transform 0.16s ease, box-shadow 0.16s ease, filter 0.16s ease;
}

.login-submit:hover {
    transform: translateY(-1px);
    box-shadow: 0 18px 38px rgba(35, 125, 158, 0.28);
}

.login-submit:disabled {
    cursor: wait;
    filter: saturate(0.72);
    transform: none;
}

.login-footnote {
    margin-top: 18px;
    color: #799091;
    font-size: 12px;
    line-height: 1.7;
}

.login-logout-btn {
    position: fixed;
    right: 18px;
    bottom: 104px;
    z-index: 650;
    height: 30px;
    padding: 0 11px;
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.82);
    color: #52616b;
    font-size: 12px;
    cursor: pointer;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

@media (max-width: 900px) {
    .login-logout-btn {
        right: 14px;
        bottom: 94px;
    }
}

.login-logout-btn:hover {
    color: #159a86;
    border-color: rgba(21, 154, 134, 0.28);
}

body.login-active .login-logout-btn {
    display: none;
}

body.login-active .loading-overlay {
    display: none !important;
}

body.login-active #bottomDock,
body.login-active #mobileDashboard,
body.login-active #mobileStoreList,
body.login-active #mapContainer,
body.login-active .top-bar,
body.login-active #dataFreshnessBadge,
body.login-active #icp-footer {
    display: none !important;
}

@media (max-width: 900px) {
    .login-gate {
        grid-template-columns: 1fr;
        align-content: center;
        gap: 28px;
        padding: 24px;
        overflow-y: auto;
    }

    .login-brand {
        max-width: 100%;
        width: calc(100vw - 48px);
    }

    .login-title {
        width: calc(100vw - 48px);
        max-width: 100%;
        font-size: clamp(30px, 9vw, 38px);
        line-height: 1.12;
        word-break: break-all;
    }

    .login-mobile-break {
        display: block;
    }

    .login-subtitle {
        font-size: 15px;
    }

    .login-panel {
        justify-self: stretch;
        width: calc(100vw - 48px);
        max-width: calc(100vw - 48px);
        padding: 22px;
    }
}

/* ===== iPhone / mobile app shell ===== */
@media (max-width: 768px) {
    :root {
        --mobile-dock-height: 68px;
        --mobile-safe-bottom: env(safe-area-inset-bottom, 0px);
        --mobile-safe-top: env(safe-area-inset-top, 0px);
    }

    html,
    body {
        width: 100%;
        min-height: 100%;
        overflow: hidden;
        background: #eef6f5;
    }

    .login-gate {
        min-height: 100dvh;
        grid-template-columns: 1fr;
        grid-template-rows: auto auto;
        align-content: center;
        justify-items: stretch;
        gap: 20px;
        padding:
            max(22px, calc(env(safe-area-inset-top, 0px) + 14px))
            18px
            max(24px, calc(env(safe-area-inset-bottom, 0px) + 18px));
        background:
            linear-gradient(180deg, rgba(245, 252, 249, 0.98) 0%, rgba(235, 249, 246, 0.96) 52%, rgba(227, 242, 250, 0.98) 100%),
            url("../assets/login-bg.png") center/cover no-repeat;
        background-color: #eef8f6;
    }

    .login-brand {
        width: 100%;
        max-width: none;
    }

    .login-brand-mark {
        width: 48px;
        height: 48px;
        font-size: 15px;
        box-shadow: 0 12px 28px rgba(20, 92, 96, 0.14);
    }

    .login-kicker {
        margin-top: 18px;
        font-size: 12px;
    }

    .login-title {
        width: 100%;
        font-size: 34px;
        line-height: 1.08;
        word-break: keep-all;
        overflow-wrap: normal;
    }

    .login-subtitle {
        margin-top: 10px;
        font-size: 15px;
        line-height: 1.5;
    }

    .login-signal-row {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px;
        margin-top: 18px;
    }

    .login-signal {
        height: 32px;
        justify-content: center;
        padding: 0 8px;
        font-size: 12px;
        white-space: nowrap;
    }

    .login-signal::before {
        display: none;
    }

    .login-panel {
        width: 100%;
        max-width: none;
        padding: 20px;
        border-radius: 12px;
        background: rgba(255, 255, 255, 0.84);
        box-shadow: 0 18px 54px rgba(15, 70, 78, 0.18);
    }

    .login-panel h2 {
        font-size: 20px;
    }

    .login-form {
        margin-top: 20px;
        gap: 14px;
    }

    .login-input-wrap input,
    .login-submit {
        height: 48px;
        font-size: 16px;
    }

    .login-row {
        align-items: flex-start;
    }

    .login-check {
        max-width: 52%;
        line-height: 1.35;
    }

    .login-error {
        flex: 1;
        min-width: 0;
    }

    .login-footnote {
        margin-top: 14px;
    }

    body.login-active #icp-footer {
        display: none !important;
    }

    #mobileDashboard,
    #mobileStoreList {
        top: 0 !important;
        bottom: calc(var(--mobile-dock-height) + var(--mobile-safe-bottom)) !important;
        background:
            linear-gradient(180deg, #eef8f6 0%, #f6f8fb 42%, #f4f7fb 100%) !important;
        z-index: 700 !important;
        isolation: isolate;
    }

    .md-header {
        padding:
            max(14px, calc(var(--mobile-safe-top) + 10px))
            16px
            12px !important;
        background: rgba(255, 255, 255, 0.88) !important;
        border-bottom: 1px solid rgba(15, 84, 92, 0.08) !important;
        box-shadow: 0 8px 24px rgba(31, 86, 97, 0.08) !important;
        backdrop-filter: blur(18px);
        -webkit-backdrop-filter: blur(18px);
    }

    .md-header-top {
        min-height: 36px;
    }

    .md-logo {
        width: 30px;
        height: 30px;
        display: inline-grid;
        place-items: center;
        border-radius: 8px;
        background: #e8f6f0;
        font-size: 16px !important;
    }

    .md-title {
        min-width: 0;
        font-size: 17px !important;
        color: #102f33 !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .md-month-select,
    .md-sort-select {
        height: 34px;
        max-width: 116px;
        border-radius: 10px !important;
        border-color: rgba(16, 87, 93, 0.14) !important;
        background-color: rgba(255, 255, 255, 0.92) !important;
        font-size: 13px !important;
    }

    .md-body {
        padding: 12px 12px max(18px, env(safe-area-inset-bottom, 0px)) !important;
    }

    .md-kpi-row {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 10px !important;
    }

    .md-kpi,
    .md-section {
        border-radius: 12px !important;
        border: 1px solid rgba(15, 84, 92, 0.06);
        box-shadow: 0 6px 20px rgba(31, 86, 97, 0.06) !important;
    }

    .md-kpi {
        padding: 12px 10px !important;
        text-align: left !important;
    }

    .md-kpi-label {
        font-size: 12px !important;
        color: #60757a !important;
    }

    .md-kpi-value {
        font-size: 21px !important;
        color: #102f33 !important;
    }

    .md-flow-row {
        display: grid !important;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px !important;
    }

    .md-flow-row .md-kpi {
        padding: 10px 8px !important;
        text-align: center !important;
    }

    .md-flow-row .md-kpi-value {
        font-size: 16px !important;
    }

    .md-section {
        padding: 14px !important;
        margin-bottom: 12px !important;
    }

    .md-store-card {
        min-height: 54px;
        padding: 12px !important;
        border-radius: 10px !important;
    }

    .md-empty-note {
        padding: 12px;
        border-radius: 10px;
        background: rgba(20, 184, 166, 0.08);
        color: #4d6f72;
        font-size: 13px;
        line-height: 1.55;
    }

    .md-store-name {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    #mapContainer {
        width: 100vw !important;
        height: 100dvh !important;
        min-height: 100dvh;
    }

    body.mobile-overview-active #mapContainer,
    body.mobile-stores-active #mapContainer {
        pointer-events: none;
        visibility: hidden;
        opacity: 0;
    }

    body.mobile-map-active #mapContainer {
        visibility: visible;
        opacity: 1;
    }

    body:not(.mobile-map-active) .node-search-box {
        display: none !important;
    }

    body.mobile-map-active .node-search-box {
        display: flex !important;
        position: fixed !important;
        top: max(10px, calc(var(--mobile-safe-top) + 8px)) !important;
        left: 12px !important;
        right: 12px !important;
        z-index: 760 !important;
        min-height: 40px;
        border-radius: 12px !important;
        background: rgba(255, 255, 255, 0.92) !important;
        box-shadow: 0 10px 28px rgba(15, 23, 42, 0.12) !important;
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
    }

    .bottom-dock {
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: calc(var(--mobile-dock-height) + var(--mobile-safe-bottom)) !important;
        max-width: none !important;
        transform: none !important;
        padding: 6px 8px max(6px, var(--mobile-safe-bottom)) !important;
        gap: 2px !important;
        border-radius: 18px 18px 0 0 !important;
        background: rgba(255, 255, 255, 0.94) !important;
        border: 1px solid rgba(15, 23, 42, 0.08) !important;
        border-bottom: 0 !important;
        box-shadow: 0 -12px 34px rgba(31, 86, 97, 0.16) !important;
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        z-index: 900 !important;
    }

    .dock-btn {
        flex: 1 1 0 !important;
        min-width: 0 !important;
        height: 54px;
        padding: 5px 2px !important;
        border-radius: 12px !important;
        color: #6a7680 !important;
        font-size: 18px !important;
        line-height: 1;
    }

    .dock-btn svg {
        width: 20px !important;
        height: 20px !important;
    }

    .dock-btn span {
        margin-top: 4px;
        font-size: 10px !important;
        white-space: nowrap;
    }

    .dock-btn.active {
        background: #e5f3ff !important;
        color: #2364d8 !important;
    }

    .drawer-panel,
    .flow-drawer,
    .feasibility-panel {
        left: 8px !important;
        right: 8px !important;
        bottom: calc(var(--mobile-dock-height) + var(--mobile-safe-bottom)) !important;
        border-radius: 18px 18px 0 0 !important;
        max-height: min(62dvh, 560px) !important;
    }

    .drawer-panel {
        top: auto !important;
    }

    .drawer-body,
    .flow-drawer-body {
        max-height: calc(62dvh - 58px) !important;
        padding-bottom: 16px !important;
        -webkit-overflow-scrolling: touch;
    }

    .flow-info-card {
        left: 10px !important;
        right: 10px !important;
        bottom: calc(var(--mobile-dock-height) + var(--mobile-safe-bottom) + 10px) !important;
        max-height: 42dvh !important;
    }

    .compare-bar {
        bottom: calc(var(--mobile-dock-height) + var(--mobile-safe-bottom)) !important;
        border-radius: 16px 16px 0 0 !important;
    }

    .mobile-more-overlay {
        z-index: 950 !important;
    }

    .mobile-more-panel {
        max-height: min(78dvh, 620px) !important;
        padding-bottom: var(--mobile-safe-bottom) !important;
        background: rgba(18, 31, 38, 0.96) !important;
        z-index: 960 !important;
    }

    .mobile-more-header {
        padding-top: 18px !important;
    }

    .mobile-menu-item {
        min-height: 42px;
        border-radius: 12px !important;
    }

    .login-logout-btn {
        right: 12px !important;
        top: auto !important;
        bottom: calc(var(--mobile-dock-height) + var(--mobile-safe-bottom) + 12px) !important;
        height: 34px;
        border-radius: 999px;
        z-index: 930;
        box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
    }

    #dataFreshnessBadge.data-freshness-badge {
        right: 12px !important;
        bottom: calc(var(--mobile-dock-height) + var(--mobile-safe-bottom) + 54px) !important;
        min-height: 28px;
        border-radius: 999px !important;
        z-index: 920 !important;
    }

    body.mobile-overview-active #dataFreshnessBadge.data-freshness-badge,
    body.mobile-stores-active #dataFreshnessBadge.data-freshness-badge,
    body.mobile-overview-active .login-logout-btn,
    body.mobile-stores-active .login-logout-btn {
        display: none !important;
    }

    #icp-footer {
        left: 12px !important;
        right: auto !important;
        bottom: calc(var(--mobile-dock-height) + var(--mobile-safe-bottom) + 4px) !important;
        z-index: 110 !important;
        opacity: 0.55;
    }
}

@media (max-width: 380px) {
    .login-title {
        font-size: 30px;
    }

    .login-signal-row {
        grid-template-columns: 1fr;
    }

    .md-flow-row {
        grid-template-columns: 1fr !important;
    }

    .dock-btn span {
        font-size: 9px !important;
    }
}
