/**
 * Адаптивная панель: телефон (<640px), планшет (640–1023px), десктоп (≥1024px).
 */
:root {
    --panel-bp-tablet: 640px;
    --panel-bp-desktop: 1024px;
    --panel-space: 1rem;
}

/* ——— База: телефон ——— */
body {
    padding: 0.5rem;
}

main.container-fluid {
    width: 100%;
    max-width: 100%;
    padding-inline: 0;
}

.app-topnav {
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--pico-muted-border-color, #e0e0e0);
}

.app-topnav-inner {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.app-topnav-bar {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    flex: 1 1 100%;
    gap: 0.5rem;
    margin: 0;
}

.app-topnav-bar > li:first-child {
    flex: 1;
    min-width: 0;
}

.app-topnav-bar > li:first-child strong {
    font-size: clamp(0.95rem, 4vw, 1.1rem);
    word-break: break-word;
}

.app-topnav-burger-wrap {
    list-style: none;
    margin: 0;
    flex-shrink: 0;
}

.app-topnav-burger {
    margin: 0;
    padding: 0.35rem 0.65rem;
    font-size: 0.9rem;
    line-height: 1.2;
}

.app-topnav-menu {
    display: none;
    flex-direction: column;
    flex: 1 1 100%;
    width: 100%;
    gap: 0.25rem;
    margin: 0.25rem 0 0 0;
    padding: 0.5rem 0 0 0;
    border-top: 1px solid var(--pico-muted-border-color, #e8e8e8);
}

.app-topnav-menu.is-open {
    display: flex;
}

.app-topnav-menu li {
    width: 100%;
}

.app-topnav-menu a {
    display: block;
    padding: 0.45rem 0;
}

.app-topnav-menu form {
    width: 100%;
}

.app-topnav-menu form button {
    width: 100%;
    margin: 0.25rem 0 0 0;
}

.nav-profile {
    padding: 0.5rem 0;
}

/* Сетка KPI: 1 → 2 → 4 */
.kpi-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

.kpi-grid--triple {
    grid-template-columns: 1fr;
}

/* Формы фильтров: колонка на телефоне */
.panel-filter-row,
.panel-form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
}

.panel-filter-row > label,
.panel-form-row > label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    flex: 1 1 100%;
}

.panel-filter-row > label input,
.panel-filter-row > label select,
.panel-form-row > label input,
.panel-form-row > label select,
.panel-form-row > label textarea {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.panel-filter-row > div,
.panel-form-row > div {
    flex: 1 1 100%;
}

.panel-filter-row .filter-category-block {
    flex: 1 1 100%;
    width: 100%;
    max-width: 100%;
}

.panel-dialog-head {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: space-between;
    align-items: center;
}

.panel-actions-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.panel-actions-row button {
    flex: 1 1 auto;
    min-width: min(100%, 8rem);
}

.panel-form-row > button {
    width: 100%;
    align-self: stretch;
}

@media (min-width: 640px) {
    .panel-form-row > button {
        width: auto;
        align-self: flex-end;
    }
}

.toolbar {
    flex-direction: column;
    align-items: stretch;
}

.toolbar label,
.toolbar > label {
    width: 100%;
}

.toolbar label input,
.toolbar label select {
    width: 100%;
    max-width: 100%;
}

.toolbar button {
    width: 100%;
}

.table-wrap {
    margin: 0 -0.25rem;
    padding: 0 0.25rem;
    -webkit-overflow-scrolling: touch;
}

.table-wrap table {
    font-size: 0.82rem;
}

.table-wrap th,
.table-wrap td {
    padding: 0.35rem 0.5rem;
    vertical-align: top;
}

.pay-card {
    margin: 1rem auto;
    padding: 1rem;
    max-width: 100%;
    border: 1px solid #ddd;
    border-radius: 10px;
    box-sizing: border-box;
}

/* Диалоги */
dialog {
    width: min(96vw, 100% - 1rem);
    max-width: 100%;
    margin: auto;
    padding: 0.75rem;
}

dialog article {
    padding: 0.5rem;
}

#detail_dialog,
#detail_dialog > article {
    width: min(100%, 96vw) !important;
    max-width: 100% !important;
    box-sizing: border-box;
}

.cash-copy-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: stretch;
}

.cash-copy-row input {
    flex: 1 1 12rem;
    min-width: 0;
}

.cash-copy-row button {
    flex: 0 0 auto;
}

section.timesheet-toolbar {
    display: flex;
    flex-direction: column;
    align-items: stretch;
}

section.timesheet-toolbar > label,
section.timesheet-toolbar > div {
    width: 100%;
}

section.timesheet-toolbar > div {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

section.timesheet-toolbar > div button,
section.timesheet-toolbar > div a.secondary {
    flex: 1 1 auto;
    min-width: min(100%, 9rem);
    justify-content: center;
}

/* ——— Планшет ——— */
@media (min-width: 640px) {
    body {
        padding: 0.75rem;
    }

    section.timesheet-toolbar {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: flex-end;
    }

    section.timesheet-toolbar > label,
    section.timesheet-toolbar > div {
        width: auto;
    }

    section.timesheet-toolbar > div button,
    section.timesheet-toolbar > div a.secondary {
        flex: 0 0 auto;
        min-width: auto;
    }

    .cash-copy-row {
        flex-wrap: nowrap;
        align-items: center;
    }

    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .kpi-grid--triple {
        grid-template-columns: repeat(3, 1fr);
    }

    .panel-filter-row > label,
    .panel-form-row > label {
        flex: 1 1 calc(50% - 8px);
        max-width: calc(50% - 8px);
    }

    .panel-filter-row > div:not(.full-width),
    .panel-form-row > div:not(.full-width) {
        flex: 1 1 auto;
    }

    .toolbar {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: flex-end;
    }

    .toolbar label {
        width: auto;
        flex: 0 1 auto;
    }

    .toolbar label input,
    .toolbar label select {
        width: auto;
        min-width: 8rem;
    }

    .toolbar button {
        width: auto;
    }

    .table-wrap table {
        font-size: 0.88rem;
    }

    .table-wrap th,
    .table-wrap td {
        padding: 0.45rem 0.6rem;
    }

    .pay-card {
        padding: 1.25rem 1.5rem;
    }
}

/* ——— Десктоп ——— */
@media (min-width: 1024px) {
    body {
        padding: 1rem;
    }

    .app-topnav-burger-wrap {
        display: none;
    }

    .app-topnav {
        border-bottom: none;
        margin-bottom: 1.25rem;
        padding-bottom: 0;
    }

    /* Название слева, навигация справа */
    .app-topnav-inner {
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: center;
        justify-content: space-between;
        gap: 1rem;
    }

    .app-topnav-bar {
        flex: 0 0 auto;
        width: auto;
    }

    .app-topnav-bar > li:first-child {
        flex: 0 0 auto;
    }

    .app-topnav-bar > li:first-child strong {
        white-space: nowrap;
    }

    .app-topnav-menu {
        display: flex !important;
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: center;
        justify-content: flex-end;
        gap: 0.35rem 1rem;
        flex: 1 1 auto;
        min-width: 0;
        width: auto;
        margin: 0;
        padding: 0;
        border-top: none;
    }

    .app-topnav-menu li {
        width: auto;
        flex-shrink: 0;
        white-space: nowrap;
    }

    .app-topnav-menu a {
        display: inline;
        padding: 0;
    }

    .app-topnav-menu form {
        width: auto;
    }

    .app-topnav-menu form button {
        width: auto;
        margin: 0;
    }

    .kpi-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 12px;
    }

    .panel-filter-row > label,
    .panel-form-row > label {
        flex: 0 1 auto;
        max-width: none;
    }

    .panel-filter-row .filter-category-block {
        flex: 0 1 auto;
        width: auto;
        max-width: none;
    }

    .panel-form-row > label.field-grow {
        flex: 1 1 200px;
    }

    .panel-actions-row button {
        flex: 0 0 auto;
        min-width: auto;
    }

    .table-wrap {
        margin: 0;
        padding: 0;
    }

    .table-wrap table {
        font-size: 1rem;
    }

    .table-wrap th,
    .table-wrap td {
        padding: 0.5rem 0.75rem;
    }

    .pay-card {
        max-width: 520px;
        margin: 2.5rem auto;
        padding: 1.75rem;
    }

    #detail_dialog,
    #detail_dialog > article {
        width: min(1200px, 96vw) !important;
        max-width: min(1200px, 96vw) !important;
    }
}

/* Страница входа (отдельный layout) */
.auth-login-body {
    padding: 0.75rem;
}

.auth-login-main {
    margin-top: clamp(2rem, 12vw, 5rem);
    max-width: 480px;
}

@media (min-width: 640px) {
    .auth-login-body {
        padding: 1rem;
    }
}
