/*
 * Mobile view.
 *
 * The site is built from nested layout tables with fixed widths (css/saltanat.css and width
 * attributes in the templates). On a narrow screen this file turns those tables into plain
 * blocks that stack, so that the page can be read without zooming. On a wide screen it
 * changes nothing.
 *
 * It is only loaded on pages that have been adapted: the home page and every page that sets
 * $pageMobileView before including includes/header.php (videopage.php, postpage.php, …).
 */
@media (max-width: 800px) {

    html, body {
        margin: 0;
        padding: 0;
        -webkit-text-size-adjust: 100%;
    }

    #divbody {
        padding: 0 8px;
    }

    /* the languages: as wide as the screen instead of the page frame, larger, with room
       around them for a finger */
    #language-bar {
        width: auto;
        height: auto;
        margin: 4px 0 6px 0;
        font-size: 16px;
        line-height: 24px;
    }

    #language-bar a {
        display: inline-block;
        margin-inline-start: 6px;
        padding: 6px 6px;
    }

    img {
        max-width: 100%;
        height: auto;
    }

    /* The layout tables and their cells become blocks. */
    #maintable,
    #maintable > tbody,
    #maintable > tbody > tr,
    #maintable > tbody > tr > td,
    #banner-table,
    #banner-table > tbody,
    #banner-table > tbody > tr,
    #banner-table > tbody > tr > td,
    #inner-banner-table,
    #inner-banner-table > tbody,
    #inner-banner-table > tbody > tr,
    #inner-banner-table > tbody > tr > td,
    #content-column-panel,
    #content-column-panel > tbody,
    #content-column-panel > tbody > tr,
    #content-column-panel > tbody > tr > td,
    #homepage-container,
    #homepage-container > tbody,
    #homepage-container > tbody > tr,
    #homepage-container > tbody > tr > td {
        display: block;
        width: auto !important;
        height: auto !important;
        box-sizing: border-box;
    }

    /* Header: the two pictures stand small beside the title, the subtitle and the menu
       below them over the full width. On a wide screen the pictures flank title and menu
       together; here the menu wraps onto two lines, which would make them tall strips. In
       the markup title, subtitle and menu are rows of a table nested in the middle cell;
       that table and its rows are dissolved (display: contents), so that the cells become
       items of the grid of the outer row. In Arabic the grid follows dir="rtl", as the table
       does. */
    #banner-table > tbody > tr {
        display: grid;
        grid-template-columns: min(16vw, 90px) minmax(0, 1fr) min(16vw, 90px);
        grid-template-areas:
            "left  title right"
            "sub   sub   sub"
            "menu  menu  menu";
        gap: 3px;
    }

    #banner-table > tbody > tr > td:nth-child(2),
    #inner-banner-table,
    #inner-banner-table > tbody,
    #inner-banner-table > tbody > tr {
        display: contents;
    }

    #inner-banner-table > tbody > tr:last-child > td {
        grid-area: menu;
    }

    /* the pictures are as high as the title image and cut to fit */
    #left-logo,
    #right-logo {
        /* saltanat.css centres the left one with auto margins, which in a grid shrink it to
           nothing */
        margin: 0 !important;
        background-size: cover !important;
        background-position: center !important;
    }

    #left-logo {
        grid-area: left;
    }

    #right-logo {
        grid-area: right;
    }

    #middle-logo {
        grid-area: title;
        text-align: center;
        /* the blue gradient over the height of the cell, which is lower than the picture
           of the gradient */
        background-size: 100% 100% !important;
    }

    /* The title image without its two lines of subtitle, which would be too small to read
       here (they follow as text), and without the empty space at the sides, so that the
       word "Saltanat" fills the cell. The link is the window onto the image: as wide as the
       cell, as high as the title, and the image is enlarged and moved behind it. Measured in
       the files: English and Turkish (1180 x 196) title in x 359-809 and y 10-103, Arabic
       (605 x 110) in x 227-373 and y 6-54. Window 508 x 112 from x 330, Arabic 268 x 59 from
       x 166 - both in the same proportion. */
    #middle-logo a {
        display: block;
        overflow: hidden;
        aspect-ratio: 508 / 112;
        /* the margin below moves the image to the left in both writing directions */
        direction: ltr;
    }

    #middle-logo img {
        display: block;
        position: static !important;
        max-width: none;
        width: 232.28% !important;      /* 1180 / 508 */
        height: auto !important;
        margin-left: -64.96%;           /* 330 / 508 */
        border-radius: 0;
    }

    /* the drawings of the title (images/saltanat-title.svg, saltanat-title-ar.svg) need no
       cutting: they fill the window as they are */
    #middle-logo img[src*="saltanat-title"] {
        width: 100% !important;
        height: 100% !important;
        margin-left: 0;
        object-fit: contain;
    }

    #header-subtitle {
        grid-area: sub;
        display: block;
        padding: 4px 6px 5px 6px;
        background: linear-gradient(#1e1e96, #1e1e5f);
        color: #DAC23D;
        font-family: Georgia, serif;
        /* two lines down to about 360px; below that a line wraps, then evenly */
        font-size: clamp(10.5px, 3.2vw, 12px);
        line-height: 1.35;
        text-align: center;
        text-wrap: balance;
    }

    #header-subtitle span {
        display: block;
    }

    /* The golden frame of the banner: the same width on all four sides and between the
       parts. On a wide screen the fixed height of the banner produces it; here the nested
       tables would leave gold on the left and right only. 3px instead of the 5px of the
       wide screen, which look heavy around a header this small. */
    #banner-cell {
        padding: 3px;
        /* the colour of golden-lineF.png, which is too low for a menu of several lines */
        background: #CBAF42 !important;
    }

    #banner-table,
    #inner-banner-table {
        padding: 0 !important;
    }

    /* The home page: the box of the latest broadcast is left out (decided by the owner,
       2026-11-30); the list of the latest videos follows directly. (The heading "Home" is
       left out on every screen since 2026-12, index.php.) */
    #homepage-news-left-column > table > tbody > tr.homepage-ro:first-child {
        display: none;
    }

    #homepage-container {
        margin-top: 12px;
    }

    /* The spacer cell between the two columns of the home page */
    #homepage-container > tbody > tr > td[width] {
        display: none;
    }

    #homepage-news-left-column,
    #homepage-news-right-column {
        margin: 0 0 12px 0;
    }

    /* Tables inside the columns fill the width. */
    #homepage-container table {
        width: 100% !important;
        box-sizing: border-box;
    }

    /* The menu wraps onto as many lines as it needs. */
    #menubar,
    #menu,
    #menu ul.menu {
        height: auto !important;
    }

    #menu ul.menu {
        overflow: hidden;
    }

    /* On a phone the seven entries stand in two lines, 4 + 3, each line centred, instead
       of filling the first line and leaving one or two alone on the second. The break is
       an empty pseudo element of full width placed between the fourth and the fifth entry
       (order). */
    @media (max-width: 560px) {
        div#menu ul.menu {
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
        }

        div#menu ul.menu > li {
            display: block;
            white-space: nowrap;
        }

        div#menu ul.menu::after {
            content: "";
            flex-basis: 100%;
            order: 1;
        }

        div#menu ul.menu > li:nth-child(n+5) {
            order: 2;
        }
    }

    /* Below 380px four entries no longer fit on a line in English and Turkish: 3 + 3 + 1. */
    @media (max-width: 380px) {
        div#menu ul.menu::before {
            content: "";
            flex-basis: 100%;
            order: 1;
        }

        div#menu ul.menu > li:nth-child(n+4) {
            order: 2;
        }

        div#menu ul.menu::after {
            order: 3;
        }

        div#menu ul.menu > li:nth-child(n+7) {
            order: 4;
        }
    }

    /* On a wide screen the menu is positioned absolutely inside the banner. */
    #menu {
        position: static !important;
        width: auto !important;
        margin: 0;
        /* the background strip is one menu line high; repeat it for the further lines */
        background-repeat: repeat !important;
    }

    /* The two boxes at the bottom: text first, the picture centred underneath. */
    table.homepage-declaration,
    table.homepage-declaration > tbody,
    table.homepage-declaration > tbody > tr,
    table.homepage-declaration > tbody > tr > td,
    table.homepage-sign,
    table.homepage-sign > tbody,
    table.homepage-sign > tbody > tr,
    table.homepage-sign > tbody > tr > td {
        display: block;
        width: auto !important;
        box-sizing: border-box;
    }

    img#homepage-foto-mawlana,
    img#homepage-foto-sign {
        display: block;
        margin: 0 auto 20px auto;
        max-width: 80%;
        height: auto;
    }

    /* The footer: every group on a line of its own, centred. */
    div#footer {
        padding: 2px 12px;
        font-size: 15px;
        text-align: center;
    }

    div#footer div.footer-row {
        display: block;
        padding: 6px 0;
    }

    div#footer div.footer-row > div {
        padding: 2px 0;
    }

    /* 4px above and below: with the line height still a finger's width */
    div#footer a {
        margin: 0 9px !important;
        padding: 4px 0;
    }

    /* The main menu: smaller than on a wide screen (14px). It wraps onto two lines on any
       phone, and at the size of the wide screen those two lines were higher than the title
       and the pictures together. */
    div#menu {
        font-size: 13px;
    }

    div#menu ul.menu > li,
    div#menu ul.menu > li > a {
        height: 26px !important;
        line-height: 26px !important;
    }

    div#menu ul.menu > li > a span {
        padding: 0 6px;
    }

    /* Larger type: the sizes in saltanat.css were chosen for a large screen. */

    div.homepage-broadcast-content {
        font-size: 16px;
        line-height: 1.4;
    }

    /* The latest videos on the home page: every entry is one dark card that holds the
       thumbnail and the text. In the markup an entry is a table row whose inner text cell
       alone is dark, with the thumbnail beside it; that only looks like one unit as long as
       both have the same height. Here the nested table levels are dissolved and the row
       becomes a grid. */
    table[id^="homepage-latest-video"],
    table[id^="homepage-latest-video"] > tbody {
        display: block;
    }

    tr.homepage-video-block {
        display: grid;
        grid-template-columns: 200px minmax(0, 1fr);
        grid-template-rows: auto auto 1fr;
        grid-template-areas:
            "thumb title"
            "thumb info"
            "thumb text";
        column-gap: 12px;
        margin: 0 0 8px 0;
        padding: 8px;
        background-color: #003200;
        border-radius: 6px;
        color: whitesmoke;
        cursor: pointer;
    }

    tr.homepage-video-block > td:first-child {
        display: block;
        grid-area: thumb;
    }

    tr.homepage-video-block > td + td,
    tr.homepage-video-block > td + td > table,
    tr.homepage-video-block > td + td > table > tbody,
    tr.homepage-video-block > td + td > table > tbody > tr,
    tr.homepage-video-block td.latest-video-body {
        display: contents;
    }

    tr.homepage-video-block br {
        display: none;
    }

    img.video-doclet-latest-thumb {
        display: block;
        width: 100%;
        margin: 0;
    }

    span.homepage-latest-video-title {
        grid-area: title;
        position: static;
        padding: 0;
        font-size: 17px;
        line-height: 1.25;
        white-space: normal;
    }

    span.homepage-latest-video-infotext {
        grid-area: info;
        padding: 2px 0 4px 0;
        font-size: 14px;
        opacity: 0.8;
    }

    /* The description of a video: readable size, cut off after three lines. */
    span.homepage-latest-video-text {
        grid-area: text;
        align-self: start;
        width: auto;
        height: auto;
        padding: 0;
        font-size: 15px;
        line-height: 1.35;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 3;
    }

    /* On a phone the thumbnail is smaller, and the description uses the full width below. */
    @media (max-width: 520px) {
        tr.homepage-video-block {
            grid-template-columns: 124px minmax(0, 1fr);
            grid-template-rows: auto 1fr auto;
            grid-template-areas:
                "thumb title"
                "thumb info"
                "text  text";
            column-gap: 10px;
        }

        span.homepage-latest-video-text {
            margin-top: 8px;
        }
    }

    div.homepage-list,
    div.homepage-list-summary {
        font-size: 16px;
    }

    div.homepage-list-content {
        font-size: 15px;
        line-height: 1.4;
    }

    div.homepage-declaration,
    div.homepage-sign {
        font-size: 16px;
        line-height: 1.45;
    }

    div.homepage-declaration span.title {
        font-size: 19px;
    }

    /* Lists of videos (videos.php, oldsohbats.php). The right-hand column with search,
       calendar and filters is taken apart: the search form moves above the list, the
       calendar and the filters follow below it. */
    #content-column-panel > tbody > tr {
        display: flex;
        flex-direction: column;
    }

    #right-column {
        display: contents !important;
    }

    #right-column > * {
        order: 1;
        margin-left: auto;
        margin-right: auto;
    }

    #right-column > .media-search-form {
        order: -1;
        margin-bottom: 10px;
    }

    .media-search-form table {
        width: 100%;
    }

    .media-search-form td:first-child {
        width: 100%;
    }

    .media-search-form input[type=text] {
        width: 100%;
        box-sizing: border-box;
        font-size: 16px;
    }

    /* On a very narrow screen (below 360px) the calendar (286px) needs a little less side
       margin. (The title of a video and its line with date, language and length stand one
       under the other since 2026-12, so they need no rule here any more.) */
    @media (max-width: 359px) {
        #divbody {
            padding: 0 6px;
        }

    }

    /* A message of the site ("Post not found" and the like) floats over the page, 400px
       wide from a quarter of the window: here it spans the window. */
    #sessionMessages {
        left: 8px !important;
        right: 8px;
        width: auto !important;
        box-sizing: border-box;
    }

    /* one video per line instead of two */
    #media-result,
    table.media-result-table,
    table.media-result-table > tbody,
    table.media-result-table > tbody > tr,
    table.media-result-table > tbody > tr > td {
        display: block;
        width: auto !important;
    }

    table.video-doclet {
        width: 100% !important;
        margin-bottom: 8px;
    }

    /* The box of a video in the lists (includes/video_box.php) as the latest videos on the
       home page above: picture, title, line with date, language and length, description of
       three lines; on a phone a smaller picture and the description below in full width. */
    div.video-box {
        display: grid;
        grid-template-columns: 200px minmax(0, 1fr);
        grid-template-rows: auto auto 1fr;
        grid-template-areas:
            "thumb title"
            "thumb info"
            "thumb text";
        column-gap: 12px;
        padding: 8px;
    }
    div.video-box-body {
        display: contents;
    }
    div.video-box img.video-doclet-thumb {
        grid-area: thumb;
        width: 100%;
        max-width: none;
    }
    div.video-box span.video-doclet-title {
        grid-area: title;
        font-size: 17px;
        line-height: 1.25;
        white-space: normal;
    }
    div.video-box span.video-doclet-title[style] {
        font-size: 17px !important;
    }
    div.video-box span.video-doclet-text {
        grid-area: info;
        padding: 2px 0 4px 0;
        font-size: 14px;
        opacity: 0.8;
    }
    div.video-box span.video-doclet-description-text {
        grid-area: text;
        height: auto;
        font-size: 15px;
        line-height: 1.35;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 3;
    }
    @media (max-width: 520px) {
        div.video-box {
            grid-template-columns: 124px minmax(0, 1fr);
            /* the date line right under the title (2026-12): no gap between the rows (the
               10 px of the wide layout stood between title and date line), and an empty row
               beside the picture takes what the picture is higher than the two */
            grid-template-rows: auto auto 1fr auto;
            row-gap: 0;
            grid-template-areas:
                "thumb title"
                "thumb info"
                "thumb ."
                "text  text";
            column-gap: 10px;
        }
        div.video-box span.video-doclet-description-text {
            margin-top: 10px;
        }
    }

    /* the page numbers below the list wrap, with room for a finger between them */
    a.ui-panel-button,
    a.datapage-button-disabled {
        display: inline-block;
        margin: 3px 2px;
        padding: 6px 11px;
        font-size: 16px;
    }

    /* The magazines (magazines.php): they use the layout of the video lists above. */
    table.magazine-doclet {
        width: 100% !important;
        margin-bottom: 8px;
    }

    table.magazine-doclet span.magazine-doclet-title {
        font-size: 16px;
    }

    table.magazine-doclet span.magazine-doclet-text {
        font-size: 14px;
        line-height: 18px;
        height: 72px;
    }

    div#volume-menu,
    table.search-selector {
        width: auto;
        margin-left: auto !important;
        margin-right: auto !important;
    }

    /* the calendar and the boxes of filters as wide as the list above them */
    #right-column > .media-search-form,
    #right-column > div#calendar-widget,
    #right-column > div.filter-box {
        align-self: stretch;
        margin-left: 0;
        margin-right: 0;
    }
    div.filter-box,
    div#calendar-widget table#calendar-table.calendar {
        box-sizing: border-box;
        width: 100% !important;
        margin: 10px 0 !important;
    }

    /* The list of posts (articles.php) */
    table.homepage-list,
    table.articles-list {
        width: 100% !important;
        box-sizing: border-box;
    }

    div.articles-list-date {
        white-space: nowrap;
    }

    div.articles-list-content {
        font-size: 16px;
    }

    /* The contact form (contact.php): one field per line, less space around the card.
       16px keeps a phone from zooming in when a field is tapped. */
    div.contact-card {
        padding: 18px 16px 20px 16px;
    }

    div.contact-row {
        display: block;
    }

    div.contact-actions .contact-button {
        width: 100%;
    }

    /* The page of one post (postpage.php) */
    div.post-card {
        padding: 16px 16px 20px 16px;
        font-size: 16px;
    }

    h1.post-card-title {
        font-size: 20px;
    }

    div#post-page object {
        height: 70vh;
    }

    /* The video page (videopage.php): the player fits the screen, and the list of videos
       stands below it in full width and length instead of beside it. */
    div#video-page {
        display: block;
    }

    div#video-main {
        width: auto;
    }

    video.saltanat-video,
    div#video-page video {
        width: 100%;
        max-width: 100%;
        height: auto;
    }

    #video-title {
        font-size: 18px;
    }

    h2#video-title {
        font-size: 20px;
    }

    div#video-list {
        width: auto;
        height: auto;
        overflow-y: visible;
        margin-top: 28px;
    }

    /* The dialogs of the lists (information about a video, transcriptions, tell a friend).
       jQuery UI gives them a fixed position and width, chosen for a large screen: 380 px
       from the left edge and up to 600 px wide. Here they span the window. */
    .ui-dialog {
        left: 8px !important;
        width: calc(100% - 16px) !important;
        box-sizing: border-box;
    }

    .ui-dialog .ui-dialog-content {
        height: auto !important;
        max-height: 65vh;
        overflow: auto !important;
        box-sizing: border-box;
        font-size: 15px;
    }

    .ui-dialog .ui-dialog-content table {
        max-width: 100%;
    }

    .ui-dialog .ui-dialog-content input[type="text"],
    .ui-dialog .ui-dialog-content textarea {
        box-sizing: border-box;
        width: 100%;
        font-size: 16px;
    }

    /* The information about a video stacks three languages as absolutely positioned layers
       in a box of fixed height and shows one of them (ajax_videoinfo.php). Here the layers
       follow the flow of the text, and the hidden ones take no room. */
    #videoInfoDialog [id^="media-title-"],
    #videoInfoDialog [id^="media-info-"],
    #videoInfoDialog div.media-info {
        position: static !important;
    }

    #videoInfoDialog [id^="media-title-"][style*="hidden"],
    #videoInfoDialog [id^="media-info-"][style*="hidden"] {
        display: none;
    }

    .ui-dialog .ui-dialog-buttonpane button {
        font-size: 15px;
    }

    /* "Saltanat TV": the playlist has several hundred entries. It scrolls in a box of its
       own instead of making the page that long. */
    div#video-list.video-list-playlist {
        max-height: 70vh;
        overflow-y: auto;
    }

    /* as high as its text needs, at least as the picture: date, language and length may
       break into a second line instead of being cut ("Turkish · 12…") */
    a.video-list-item {
        height: auto;
        min-height: 78px;
        padding-top: 9px;
        padding-bottom: 9px;
        padding-inline-start: 138px;
    }

    a.video-list-item img {
        top: 4px;
        inset-inline-start: 4px;
        width: 124px;
        height: 70px;
    }

    a.video-list-item span.video-list-title {
        font-size: 16px;
        line-height: 20px;
    }

    a.video-list-item span.video-list-date {
        font-size: 14px;
        line-height: 17px;
        white-space: normal;
    }
}

/* The boxes of the right column of the home page on a phone (2026-12): a compact row each,
   the picture small at the start and the title beside it, instead of a picture as wide as
   the screen under every title - eight boxes made a very long way down. The summaries are
   written differently from box to box (the link directly, or inside a span with a stray
   </p>), so the span gives its children to the row (display: contents). */
@media (max-width: 800px) {
    div.homepage-list {
        padding-bottom: 12px;
    }
    div.homepage-list-summary {
        display: flex;
        align-items: center;
        gap: 12px;
        padding-bottom: 0;
    }
    div.homepage-list-summary > span {
        display: contents;
    }
    div.homepage-list-summary a:has(> img) {
        flex: none;
        order: -1;
        width: 132px;
    }
    div.homepage-list-summary a > img {
        width: 132px;
        margin-top: 0 !important;
    }
    div.homepage-list-content {
        padding-bottom: 0;
    }
    /* the strip of the Hijri date lower than the width of the screen would make it */
    div.homepage-list-content img[src^="images/hijri-date.jpg"] {
        height: 64px;
        object-fit: cover;
    }
}

/* The post list on a phone (2026-12): less room inside the card; the layout itself is that
   of every width (css/saltanat.css, the card of the post page). */
@media (max-width: 800px) {
    table.articles-list {
        padding: 16px 16px 18px 16px;
    }
    div.articles-list-title {
        font-size: 20px;
    }
}

/* The latest videos of the home page on a phone (2026-12): the first six; the link under them
   leads to the video library. Fifteen made about 3,300 px before the first box. */
@media (max-width: 800px) {
    tr.homepage-video-block:nth-of-type(n+7) {
        display: none;
    }
}

/* A long filter box on a phone (the topics, 2026-12): the first eight chips and a button for
   the rest; includes/filter_box.php collapses it by script, so without one all stay. */
@media (max-width: 800px) {
    div.filter-box.is-collapsed a.filter-chip-extra {
        display: none;
    }
    div.filter-box.is-collapsed button.filter-box-more {
        display: inline-block;
        margin-top: 8px;
        padding: 5px 14px;
        border: 1px solid #0b4d0b;
        border-radius: 999px;
        background: transparent;
        color: #0b4d0b;
        font: bold 14px/1.4 "Trebuchet MS", sans-serif;
        cursor: pointer;
    }
}
