:root {
    /* Высоты */
    --topbar-h: 52px;

    /* Акцентные */
    --c-accent: #22B14C;
    --c-accent-hover: #1C9A41;
    --c-accent-dark: #15803D;
    --c-accent-light: #E8F7EE;
    --c-accent-border: #BFEAD0;

    /* Текст */
    --c-text: #1C2030;
    --c-text-2: #454A58;
    --c-text-3: #636878;
    --c-text-4: #8C91A0;
    --c-text-ph: #B8BCC7;
    --c-muted: #454A58;

    /* Фоны */
    --c-bg: #E8E9EC;
    --c-surface: #FFFFFF;
    --c-bg-2: #F5F6F8;
    --c-bg-3: #FAFAFA;
    --c-bg-sel: #F0FDF4;

    /* Границы */
    --c-border: #D8DBE2;
    --c-border-div: #EBEDF1;

    /* Деструктивные */
    --c-danger: #E24B4A;

    /* Статусы */
    --c-status-ok-bg: #E8F7EE;
    --c-status-ok-text: #15803D;
    --c-status-warn-bg: #FEF9C3;
    --c-status-warn-text: #854D0E;
    --c-status-err-bg: #FEE2E2;
    --c-status-err-text: #991B1B;
    --c-status-neutral-bg: #EBEDF1;
    --c-status-neutral-text: #454A58;
    --c-status-tariff-bg: #E6F1FB;
    --c-status-tariff-text: #185FA5;
}

* { box-sizing: border-box; }

html {
    min-height: 100%;
    font-size: 13px;
}

body {
    min-height: 100vh;
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    color: var(--c-text);
    background: var(--c-bg);
    display: flex;
    flex-direction: column;
}

a { color: inherit; }

/* --- Шапка ---------------------------------------------------------------- */
.topbar {
    display: flex;
    min-height: var(--topbar-h);
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 10px;
    border-bottom: 0.5px solid var(--c-border);
    background: var(--c-surface);
    color: var(--c-text-2);
    font-size: 13px;
}

.topbar__left,
.topbar__nav,
.topbar__account {
    display: flex;
    align-items: center;
}

.topbar__left {
    min-width: 0;
    gap: 18px;
}

.topbar__brand {
    flex: 0 0 auto;
    color: var(--c-text);
    font-weight: 700;
    font-size: 15px;
    text-decoration: none;
    letter-spacing: 0;
}

.topbar__brand:hover,
.topbar__brand:focus {
    color: var(--c-text);
}

/* --- Навигация ------------------------------------------------------------- */
.topbar__nav {
    min-width: 0;
    gap: 4px;
    overflow: hidden;
    white-space: nowrap;
}

.topbar__nav-item {
    display: inline-flex;
    min-height: 30px;
    align-items: center;
    padding: 0 12px;
    text-decoration: none;
    font-weight: 500;
    color: var(--c-text-4);
    border-bottom: 2px solid transparent;
    transition: color 120ms ease, border-color 120ms ease;
}

.topbar__nav-item:hover {
    color: var(--c-text-2);
}

.topbar__nav .topbar__nav-item--active,
.topbar__nav .topbar__nav-item--active:link,
.topbar__nav .topbar__nav-item--active:visited {
    color: var(--c-accent);
    border-bottom-color: var(--c-accent);
    font-weight: 500;
}

/* Вход в шапке */
.topbar__login {
    display: inline-flex;
    min-height: 30px;
    align-items: center;
    padding: 0 12px;
    border-radius: 4px;
    text-decoration: none;
    color: var(--c-accent);
    font-weight: 500;
    white-space: nowrap;
    transition: background-color 120ms ease;
}

.topbar__login:hover { background: var(--c-bg-2); }

/* --- Аккаунт -------------------------------------------------------------- */
.topbar__account {
    flex: 0 0 auto;
    gap: 7px;
    position: relative;
}

.topbar__account-badge {
    display: inline-flex;
    width: 26px;
    height: 26px;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--c-accent);
    color: #fff;
    font-weight: 700;
    flex-shrink: 0;
}

.topbar__account-text {
    display: flex;
    align-items: flex-start;
    flex-direction: column;
    line-height: 1.1;
}

.topbar__account-name {
    color: #5a626d;
    font-weight: 600;
}

/* Кнопка-гамбургер */
.topbar__account-toggle {
    width: 30px;
    height: 30px;
    border: 0.5px solid var(--c-border);
    border-radius: 4px;
    background: var(--c-surface);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 4px;
}

.topbar__account-toggle:hover { background: var(--c-bg-2); }

/* Три полоски гамбургера */
.topbar__account-bars,
.topbar__account-bars::before,
.topbar__account-bars::after {
    display: block;
    width: 14px;
    height: 2px;
    background: var(--c-text);
    border-radius: 1px;
}

.topbar__account-bars { position: relative; }

.topbar__account-bars::before,
.topbar__account-bars::after {
    content: "";
    position: absolute;
    left: 0;
}

.topbar__account-bars::before { top: -4px; }
.topbar__account-bars::after { top: 4px; }

/* Выпадающее меню аккаунта */
.topbar__account-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 260px;
    background: var(--c-surface);
    border: 0.5px solid var(--c-border);
    border-radius: 10px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .09);
    padding: 6px;
    z-index: 10;
}

.topbar__account-menu[hidden] { display: none; }

.topbar__account-menu-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px 13px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--c-text);
    font: inherit;
    text-decoration: none;
    cursor: pointer;
}

.topbar__account-menu-item:hover { background: var(--c-bg-2); }

.topbar__account-menu-item--button { color: var(--c-danger); }

/* --- Рабочая область ------------------------------------------------------ */
.app-shell {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
}

/* Контейнер Flutter-приложения (монтируется сюда, без iframe) */
.portal-app {
    flex: 1 1 auto;
    min-height: 0;
    position: relative;
    background: var(--c-surface);
}

/* Апстрим приложения недоступен — сообщение вместо молчаливого пустого контейнера */
.portal-app--unavailable {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    color: var(--c-muted);
    font-size: 16px;
}

/* --- Обычные страницы ----------------------------------------------------- */
.page { padding: 28px 32px; }
.page__title { margin: 0 0 16px; font-size: 20px; font-weight: 500; }
.page__subtitle { margin: 24px 0 10px; font-size: 17px; font-weight: 500; }
.page__muted { color: var(--c-text-4); }

.page__lead {
    margin: 0 0 20px;
    max-width: 60ch;
    font-size: 16px;
    line-height: 1.5;
    color: var(--c-text-4);
}

.page__action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 34px;
    padding: 0 18px;
    border: 0;
    border-radius: 8px;
    background: var(--c-accent);
    color: #fff;
    font: inherit;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 120ms ease;
}

.page__action:hover { background: var(--c-accent-hover); }

.profile {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 8px 20px;
    margin: 0;
}

.profile dt { color: var(--c-muted); }
.profile dd { margin: 0; }

.permissions {
    margin: 0;
    padding-left: 18px;
    color: var(--c-text);
}

/* --- Вход ----------------------------------------------------------------- */
.login-page {
    align-items: center;
    justify-content: center;
    background: var(--c-bg);
}

.login-card {
    width: 100%;
    max-width: 360px;
    padding: 28px;
    background: var(--c-surface);
    border: 0.5px solid var(--c-border);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .08);
    display: flex;
    flex-direction: column;
}

.login-card__title {
    margin: 0 0 20px;
    font-size: 20px;
    font-weight: 500;
    text-align: center;
}

.login-card__error {
    margin: 0 0 14px;
    padding: 9px 12px;
    border-radius: 8px;
    background: var(--c-status-err-bg);
    color: var(--c-danger);
    font-size: 13px;
}

.login-card__label {
    font-size: 12px;
    font-weight: 500;
    color: var(--c-text-3);
    margin-bottom: 4px;
}

.login-card__input {
    height: 38px;
    padding: 0 12px;
    margin-bottom: 16px;
    border: 0.5px solid var(--c-border);
    border-radius: 8px;
    font: inherit;
    color: var(--c-text);
    background: var(--c-surface);
}

.login-card__input::placeholder {
    color: var(--c-text-ph);
}

.login-card__input:focus {
    border-color: var(--c-accent);
    box-shadow: 0 0 0 3px rgba(34, 177, 76, .10);
    outline: none;
}

.login-card__submit {
    height: 34px;
    padding: 0 14px;
    border: 0;
    border-radius: 8px;
    background: var(--c-accent);
    color: #fff;
    font: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 120ms ease;
}

.login-card__submit:hover { background: var(--c-accent-hover); }

/* --- Ошибка --------------------------------------------------------------- */
.error-page { padding: 32px; }
.error-page__title { color: var(--c-danger); font-weight: 500; }

/* --- Мобильная версия ----------------------------------------------------- */
@media (max-width: 640px) {
    .topbar {
        align-items: stretch;
        flex-direction: column;
        gap: 8px;
        padding: 8px 10px;
    }

    .topbar__left {
        width: 100%;
        flex-wrap: wrap;
    }

    .topbar__nav {
        width: 100%;
        overflow-x: auto;
    }

    .topbar__account {
        align-self: flex-end;
    }

    .app-shell {
        min-height: calc(100vh - 102px);
    }

    .page {
        padding: 16px;
    }
}
