/* Phone-first: удобство на телефоне (до 767.98px) */

:root {
    --touch: 2.75rem;
    --phone-pad: 1rem;
    --phone-radius: 1rem;
}

@media (max-width: 767.98px) {
    html {
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }

    body.app-body {
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    main.container {
        width: 100%;
        max-width: none;
        padding-left: var(--phone-pad) !important;
        padding-right: var(--phone-pad) !important;
        padding-top: 0.85rem !important;
        padding-bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px)) !important;
    }

    /* —— Nav —— */
    .app-nav {
        padding: 0.55rem var(--phone-pad);
        padding-top: calc(0.55rem + env(safe-area-inset-top, 0px));
    }

    .app-logo {
        font-size: 1rem;
        max-width: 55vw;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .app-nav-btn {
        min-width: var(--touch);
        min-height: var(--touch);
        padding: 0.45rem 0.85rem;
        font-size: 0.9rem;
    }

    .app-nav-btn-text {
        display: none;
    }

    /* —— Buttons / forms —— */
    .btn {
        min-height: var(--touch);
        border-radius: 0.85rem;
        font-weight: 650;
    }

    .btn-sm {
        min-height: 2.35rem;
        padding-left: 0.85rem;
        padding-right: 0.85rem;
    }

    .form-control,
    .form-select {
        min-height: var(--touch);
        border-radius: 0.85rem;
        font-size: 1rem;
    }

    .form-control-sm,
    .form-select-sm {
        min-height: 2.35rem;
        font-size: 0.95rem;
    }

    .form-label {
        font-weight: 650;
        margin-bottom: 0.35rem;
    }

    /* —— Cards —— */
    .card {
        border-radius: var(--phone-radius) !important;
        border: 1px solid rgba(15, 42, 36, 0.08) !important;
    }

    .card-body {
        padding: 1rem !important;
    }

    .card-header {
        padding: 1rem 1rem 0.35rem !important;
    }

    h1.h3,
    .h3 {
        font-size: 1.35rem;
        letter-spacing: -0.02em;
    }

    /* —— Hub: крупные ряды под большой палец —— */
    .hub-screen {
        justify-content: flex-start;
        gap: 1rem;
        padding: calc(1rem + env(safe-area-inset-top, 0px)) var(--phone-pad) calc(1.5rem + env(safe-area-inset-bottom, 0px));
    }

    .hub-header {
        text-align: left;
        padding-top: 0.35rem;
    }

    .hub-kicker {
        font-size: 0.75rem;
    }

    .hub-title {
        font-size: 1.75rem;
    }

    .hub-greeting {
        font-size: 0.95rem;
    }

    .hub-tasks {
        border-radius: var(--phone-radius);
        padding: 0.85rem;
    }

    .hub-task-item {
        min-height: 3.35rem;
        padding: 0.8rem 0.85rem;
        border-radius: 0.9rem;
    }

    .hub-task-main {
        font-size: 1rem;
    }

    .hub-task-call {
        width: 3.1rem;
        min-height: 3.35rem;
        border-radius: 0.9rem;
        font-size: 1.15rem;
    }

    .hub-grid {
        grid-template-columns: 1fr !important;
        gap: 0.55rem;
    }

    .hub-tile {
        display: grid !important;
        grid-template-columns: auto minmax(0, 1fr) auto;
        grid-template-rows: auto auto;
        align-items: center;
        column-gap: 0.85rem;
        row-gap: 0.1rem;
        min-height: 4.1rem;
        padding: 0.85rem 1rem;
        border-radius: 1rem;
    }

    .hub-tile-icon {
        grid-row: 1 / span 2;
        grid-column: 1;
        width: 2.6rem;
        height: 2.6rem;
        font-size: 1.2rem;
        margin: 0;
    }

    .hub-tile-label {
        grid-column: 2;
        grid-row: 1;
        font-size: 1.05rem;
        line-height: 1.15;
        align-self: end;
    }

    .hub-tile-meta {
        grid-column: 2;
        grid-row: 2;
        font-size: 0.8rem;
        margin-top: 0;
        align-self: start;
    }

    .hub-tile::after {
        content: "";
        grid-row: 1 / span 2;
        grid-column: 3;
        width: 0.55rem;
        height: 0.55rem;
        border-right: 2px solid rgba(15, 42, 36, 0.28);
        border-bottom: 2px solid rgba(15, 42, 36, 0.28);
        transform: rotate(-45deg);
        align-self: center;
    }

    .hub-tile-muted::after {
        opacity: 0.45;
    }

    /* —— Project list —— */
    .project-list-item {
        border-radius: var(--phone-radius);
        padding: 1rem;
    }

    .project-list-link {
        font-size: 1.05rem;
    }

    .project-list-actions {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        width: 100%;
    }

    .project-list-actions .btn,
    .project-list-actions .create-kp-btn {
        width: 100%;
        justify-content: center;
        white-space: normal;
    }

    /* —— Workspace —— */
    .workspace-header {
        padding-top: env(safe-area-inset-top, 0px);
    }

    .workspace-header .btn-sm,
    .workspace-header .btn-icon {
        min-width: 2.5rem;
        min-height: 2.5rem;
        height: 2.5rem;
    }

    .project-name-input {
        height: 2.5rem;
        font-size: 0.95rem;
        max-width: none;
        flex: 1 1 auto;
    }

    .header-left {
        width: 100%;
    }

    .header-right {
        width: 100%;
        padding: 0.15rem 0 0.25rem;
        gap: 0.4rem;
    }

    .mobile-dock {
        height: calc(4.1rem + env(safe-area-inset-bottom, 0px));
        padding: 0.4rem 0.4rem calc(0.4rem + env(safe-area-inset-bottom, 0px));
        gap: 0.2rem;
        background: rgba(255, 255, 255, 0.96);
        backdrop-filter: blur(10px);
    }

    .dock-btn {
        min-height: 3.35rem;
        border-radius: 0.85rem;
        gap: 0.15rem;
        font-size: 0.68rem;
    }

    .dock-btn i {
        font-size: 1.35rem;
    }

    .dock-btn span {
        display: block;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .mobile-draw-bar {
        bottom: calc(4.1rem + env(safe-area-inset-bottom, 0px));
        padding: 0.55rem 0.75rem;
        gap: 0.55rem;
    }

    .mobile-draw-bar .btn {
        min-height: 2.75rem;
        flex: 1;
    }

    /* —— Modals: почти fullscreen —— */
    .modal-dialog {
        margin: 0.35rem;
        max-width: none;
    }

    .modal-dialog.modal-dialog-centered {
        min-height: calc(100% - 0.7rem);
    }

    .modal-dialog.modal-lg,
    .modal-dialog.modal-xl {
        margin: 0;
        max-width: none;
        height: 100%;
    }

    .modal-dialog.modal-lg .modal-content,
    .modal-dialog.modal-xl .modal-content {
        height: 100%;
        border-radius: 0;
        border: 0;
    }

    .modal-content {
        border-radius: 1.1rem;
    }

    .modal-header,
    .modal-footer {
        padding: 0.9rem 1rem;
    }

    .modal-body {
        padding: 1rem;
    }

    .modal-footer {
        gap: 0.5rem;
        flex-wrap: wrap;
    }

    .modal-footer .btn {
        min-height: var(--touch);
        flex: 1 1 calc(50% - 0.25rem);
    }

    .modal-footer .btn-primary {
        flex: 1 1 100%;
        order: -1;
    }

    /* —— Auth —— */
    .auth-card,
    .login-card {
        border-radius: var(--phone-radius);
    }

    .auth-card .btn,
    .login-card .btn,
    form[action*="login"] .btn-primary,
    form[action*="register"] .btn-primary {
        width: 100%;
        min-height: 2.95rem;
    }

    /* —— Settings tabs —— */
    .settings-tabs,
    .nav-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 0.25rem;
        padding-bottom: 0.25rem;
    }

    .settings-tabs .nav-link,
    .nav-tabs .nav-link {
        white-space: nowrap;
        min-height: 2.5rem;
        padding: 0.55rem 0.9rem;
        border-radius: 0.75rem;
    }

    /* —— Cookie —— */
    .cookie-banner {
        left: 0.65rem;
        right: 0.65rem;
        bottom: calc(0.65rem + env(safe-area-inset-bottom, 0px));
        border-radius: 1rem;
        padding: 1rem;
    }

    .cookie-banner-actions {
        display: grid;
        grid-template-columns: 1fr;
        gap: 0.45rem;
    }

    .cookie-banner-actions .btn {
        width: 100%;
    }
}

@media (max-width: 575.98px) {
    :root {
        --phone-pad: 0.85rem;
    }

    .hub-tile {
        min-height: 3.85rem;
        padding: 0.75rem 0.9rem;
    }

    .hub-tile-label {
        font-size: 1rem;
    }

    /* На очень узких — иконки дока крупнее, подписи короче */
    .dock-btn {
        font-size: 0.62rem;
    }

    .dock-btn i {
        font-size: 1.4rem;
    }

    /* Sticky page actions */
    .price-page > .d-flex,
    .crm-list-hero {
        position: sticky;
        top: 0;
        z-index: 20;
        background: rgba(247, 250, 248, 0.94);
        backdrop-filter: blur(10px);
        margin: -0.85rem calc(-1 * var(--phone-pad)) 0.85rem;
        padding: 0.75rem var(--phone-pad);
        border-bottom: 1px solid rgba(15, 42, 36, 0.07);
    }
}
