/* The program on a phone or a tablet (saeed, 2026-10-29: «در موبایل هم بشه به سبک موبایل دید»), opened over the
   office Wi-Fi («دسترسی از موبایل» in تنظیمات). Only narrow screens change; the Mac's big window stays as it is. */

/* ---------- Tablet and phone: the side menu slides in from the side with the ☰ button ---------- */
@media (max-width: 1024px) {
    .ns-menu-toggle { display: grid !important; flex: none; }
    html.ns-menu-open .ns-sidebar {
        display: flex !important; width: min(300px, 84vw) !important; margin: 0 !important; height: 100% !important;
        border-radius: 0 !important; z-index: 1200; background: var(--g-panel-strong, #fff) !important;
        box-shadow: 0 0 40px rgba(16, 24, 40, .25);
    }
    html.ns-menu-open.ns-collapsed .ns-nav a span, html.ns-menu-open.ns-collapsed .ns-brand span,
    html.ns-menu-open.ns-collapsed .ns-sidebar-foot { display: revert; }
    html.ns-menu-open.ns-collapsed .ns-nav a { justify-content: flex-start; padding: 10px 14px; }
    .ns-menu-shade { display: none; }
    html.ns-menu-open .ns-menu-shade { display: block; position: fixed; inset: 0; z-index: 1150; background: rgba(15, 23, 42, .35); }
    html.ns-menu-open, html.ns-menu-open body { overflow: hidden; }
}

/* ---------- Phone ---------- */
@media (max-width: 760px) {
    body { font-size: 15px; -webkit-text-size-adjust: 100%; }
    body.with-sidebar #container { overflow-x: clip; }
    body.with-sidebar #container { padding-inline-start: 0 !important; min-width: 0; }

    /* the top bar: ☰, search, راهنما and the user; the rest is in the menu or not needed on a phone */
    .ns-topbar { gap: 8px; padding: 8px 10px !important; flex-wrap: wrap; }
    body.ns-glass .ns-topbar { margin: 8px 8px 0 !important; top: 8px; border-radius: 14px; }
    .ns-search { flex: 1 1 0; min-width: 0; margin: 0; order: 1; }
    .ns-search input[type=search] { font-size: 16px; height: 38px; }  /* 16px: iPhone does not zoom into the box */
    .ns-menu-toggle { order: 0; }
    .ns-help-link { order: 2; padding-inline: 9px !important; }
    .ns-user { order: 3; }
    .ns-top-menu, .ns-lang, .ns-date, .ns-user-name, .ns-theme { display: none !important; }
    .ns-help-link { font-size: 0 !important; gap: 0 !important; }
    .ns-help-link .icon { width: 20px; height: 20px; }
    .ns-user-menu { inset-inline-end: 0; z-index: 40; }
    .acc-home-btn span { display: none; }

    /* the page */
    div.breadcrumbs { padding: 10px 12px 0 !important; }
    #content { padding: 8px 10px 16px !important; }
    h1 { font-size: 18px; }
    .ns-footer { flex-direction: column; gap: 4px; padding: 12px; text-align: center; }

    /* forms: one column, boxes as wide as the screen, big enough for a finger */
    .aligned .form-row, fieldset.module .form-row { padding: 8px 10px !important; }
    .form-row > div, .form-row .flex-container { flex-wrap: wrap; }
    .aligned label, .aligned .flex-container > label { float: none !important; width: auto !important; display: block; padding: 0 0 4px !important; }
    .aligned .help, .aligned p.help, form .aligned div.help { margin-inline-start: 0 !important; padding-inline-start: 0 !important; }
    form .aligned ul { margin-inline-start: 0 !important; padding-inline-start: 0 !important; }
    input[type=text], input[type=number], input[type=email], input[type=password], input[type=search], input[type=url],
    input[type=tel], input[type=date], textarea, select, .vTextField, .vLargeTextField {
        max-width: 100%; font-size: 16px !important; box-sizing: border-box;
    }
    .aligned .form-row input[type=text], .aligned .form-row input[type=number], .aligned .form-row textarea,
    .aligned .form-row select, .aligned .vTextField { width: 100% !important; }
    .select2-container { max-width: 100% !important; }
    .submit-row { flex-wrap: wrap; gap: 8px; padding: 10px !important; }
    .submit-row input, .submit-row a, .submit-row button { margin: 0 !important; }
    fieldset.module, .module, .inline-group { min-width: 0; max-width: 100%; }

    /* wide tables slide sideways inside their own box, the page itself does not */
    #content table { display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    #content table table { display: table; }
    #changelist { flex-direction: column; }
    #changelist .changelist-form-container { width: 100%; }
    html #changelist-filter { flex: none; width: auto; margin: 10px 0 0 !important; order: 2; }
    #changelist #toolbar form input[type=text] { width: 100%; }
    .object-tools { float: none; margin: 0 0 8px; flex-wrap: wrap; display: flex; gap: 6px; }

    /* the dashboard and the big-button pages: one card in a row */
    .ns-cards { grid-template-columns: minmax(0, 1fr) !important; gap: 10px; }
    .dashboard #content-related { max-width: none; }
}

/* An iPhone with the program on its home screen: no gap under the notch */
@supports (padding: env(safe-area-inset-top)) {
    @media (max-width: 760px) {
        body.ns-glass .ns-topbar { margin-top: max(8px, env(safe-area-inset-top)) !important; }
    }
}

@media (max-width: 760px) {
    #changelist #toolbar form, #changelist-search { display: flex; flex-wrap: wrap; gap: 6px; }
    #changelist #toolbar form > div { width: 100%; min-width: 0; box-sizing: border-box; }
    #changelist #toolbar form #searchbar { width: auto !important; flex: 1 1 0; min-width: 0; }
    #changelist #toolbar form input[type=submit] { flex: none; }
}

/* the save buttons stay at the end of the form on a phone: kept on the screen they would hide half of it */
@media (max-width: 760px) {
    #content .submit-row { position: static !important; }
}

/* the list pages of حسابداری (فاکتورهای فروش، خرید…) */
@media (max-width: 760px) {
    .hb-wrap { grid-template-columns: minmax(0, 1fr); }
    .hb-head-tools { flex-wrap: wrap; }
    .hb-head-tools > * { white-space: nowrap; }
    .hb-cards { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 10px; }
    .hb-panel { min-width: 0; }
}
