/* Mobile responsive overrides.
 * Layered on top of legacy site.css. Targets two reported pain points:
 *   (1) layout breaks on narrow viewports — fix containers + nav,
 *   (2) text input "doesn't work" on mobile — almost always iOS Safari
 *       auto-zoom when input font-size < 16px; the zoom shifts the layout
 *       so users perceive the input as un-tappable. font-size: 16px stops it.
 */

/* ───── Feedback widget panel: respect [hidden] ─────
 * #fb-widget-panel sets display:flex inline — its selector (0,1,0,0) beats
 * the UA [hidden] (0,0,1,0), so on mobile the closed panel still sat as a
 * fullscreen overlay with pointer-events:auto, swallowing every tap on
 * inputs below. Forcing display:none when [hidden] is present restores
 * normal click-through.
 */
#fb-widget-panel[hidden] { display: none !important; }

/* ───── SignIn / Register two-column → one-column on narrow ───── */
.signin-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
}
@media (max-width: 768px) {
    .signin-grid {
        grid-template-columns: 1fr;
        gap: 24px;
        padding: 20px !important;
    }
}

/* ── Register form rows ── */
.reg-row              { display: grid; gap: 16px; }
.reg-row-3            { grid-template-columns: 1fr 1fr 1fr; }
.reg-row-2            { grid-template-columns: 1fr 1fr; }
.reg-row-edrpou       { grid-template-columns: 200px 1fr; }
@media (max-width: 768px) {
    .reg-row-3,
    .reg-row-2,
    .reg-row-edrpou   { grid-template-columns: 1fr; gap: 12px; }
}

/* ── Register preview modal ── */
.preview-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.preview-modal__box {
    background: #fff;
    border-radius: 8px;
    padding: 32px 40px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}
@media (max-width: 640px) {
    .preview-modal__box {
        padding: 20px 16px;
        width: 94%;
        max-height: 92vh;
    }
}

/* ───── Form fields: prevent iOS auto-zoom + improve touch target ─────
 * Apple iOS Safari zooms in whenever an editable field with computed
 * font-size < 16px receives focus — the page shifts, the input feels
 * un-tappable. Override site.css's .form-input/.form-textarea/.form-select
 * (which set 14px). Class selector specificity (0,1,0,0) needed — bare tag
 * selectors lose to the legacy classes. */
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"],
input[type="number"],
input[type="url"],
input[type="search"],
input[type="date"],
input[type="datetime-local"],
input:not([type]),
textarea,
select,
.form-input,
.form-textarea,
.form-select {
    font-size: 16px;
}

/* On very small screens, give inputs more breathing room. */
@media (max-width: 640px) {
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="password"],
    input[type="number"],
    input[type="url"],
    input[type="search"],
    textarea,
    select {
        width: 100%;
        max-width: 100%;
        min-height: 44px;
        padding: 10px 12px;
        box-sizing: border-box;
    }

    textarea { min-height: 96px; }

    button,
    .btn,
    input[type="submit"],
    input[type="button"],
    a.btn {
        min-height: 44px;        /* Apple HIG / WCAG touch target */
        padding: 10px 16px;
        font-size: 16px;
        box-sizing: border-box;
    }

    /* Make button rows wrap nicely instead of overflowing. */
    .btn-group, .form-actions, .actions {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }
    .btn-group .btn, .form-actions .btn { flex: 1 1 auto; }

    /* Page-container — drop the desktop max-width, eat full viewport. */
    .page-container,
    .container,
    .content-wrap {
        max-width: 100% !important;
        padding-left: 12px !important;
        padding-right: 12px !important;
        box-sizing: border-box;
    }

    /* Header hero / banner — keep title readable. */
    .hero,
    .hero--compact {
        padding: 16px 12px !important;
    }
    .hero__title { font-size: 22px !important; line-height: 1.3; }
    .hero__inner { display: block !important; }
    .hero__aside { margin-top: 8px !important; font-size: 14px; }

    /* Navigation: stack vertically. */
    .navbar,
    .site-header,
    header.site-header {
        flex-wrap: wrap;
    }
    .nav, .nav-items { flex-wrap: wrap; gap: 4px; }

    /* Tables — overflow horizontally instead of breaking layout. */
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }

    /* User dropdown — keep site.css's relative-positioned trigger so the
     * dropdown anchors under it. The old override here (position:fixed on
     * .user-menu) broke the dropdown's stacking context and pushed it off
     * the trigger button. */

    /* Cards on petition list / dashboard. */
    .card, .panel, .mud-paper {
        margin-left: 0;
        margin-right: 0;
        border-radius: 8px;
    }

    /* Petition title on detail page. */
    h1, .petition-title {
        font-size: 22px !important;
        line-height: 1.3 !important;
        word-wrap: break-word;
    }

    /* Sign button + progress block — readable size. */
    .sign-button {
        width: 100%;
        font-size: 16px;
    }
}

/* ───── Site header toolbar overlap (auth flow) ─────
 * On 375px the top toolbar packs: ← E-DEM • Про проект • "Вітаємо, ПІБ" •
 * 📍Оберіть громаду. With long PIB ("Радченко Олександра Олексіївна") the
 * user-menu text and the city-pill collided and overlapped. Allow the row
 * to wrap, and ellipsis-trim the welcome text so a wide name doesn't push
 * the city pill off-screen. */
@media (max-width: 640px) {
    .site-toolbar {
        flex-wrap: wrap;
        row-gap: 4px;
        column-gap: 6px;
        justify-content: flex-end;
    }
    .site-header__top .inner {
        flex-wrap: wrap;
        row-gap: 6px;
    }
    .user-menu { min-width: 0; max-width: 100%; }
    .user-menu__trigger {
        max-width: 70vw;
    }
    .user-menu__trigger span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 50vw;
        display: inline-block;
        vertical-align: middle;
    }
    /* Drop the "Вітаємо, " prefix on tight screens — name alone is plenty.
     * Must beat .user-menu__trigger span above (specificity 0,1,1,0). */
    .user-menu__trigger .user-menu__greeting { display: none; }
    /* City pill: don't shrink to 0, drop to new line if needed. */
    .site-city, .site-city--empty { white-space: nowrap; }
}
@media (max-width: 400px) {
    .hero__title { font-size: 20px !important; }
    h1 { font-size: 20px !important; }
    body { font-size: 14px; }
}

/* ───── Tablet-ish ───── */
@media (max-width: 900px) and (min-width: 641px) {
    .page-container, .container, .content-wrap {
        max-width: 100% !important;
        padding-left: 16px !important;
        padding-right: 16px !important;
    }
}
