/*
 * 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 language flags: as wide as the screen instead of the page frame */
    #divbody > table:first-child {
        width: auto;
    }

    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: only the title image and the menu remain. */
    #left-logo,
    #right-logo {
        display: none !important;
    }

    #middle-logo {
        text-align: center;
    }

    #middle-logo img {
        position: static !important;
        width: 100% !important;
        height: auto !important;
    }

    /* The golden frame of the banner: the same width on all four sides and between the
       title and the menu. On a wide screen the fixed height of the banner produces it; here
       the two nested tables would leave gold on the left and right only. */
    #banner-cell {
        padding: 5px;
        /* 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;
    }

    #menubar {
        margin-top: 4px;
    }

    #middle-logo img {
        display: block;
    }

    /* 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 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;
    }

    #footer-cell {
        text-align: center;
    }

    /* Larger type: the sizes in saltanat.css were chosen for a large screen. */
    div#menu {
        font-size: 15px;
    }

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

    span.homepage-latest-video-title {
        display: block;
        position: static;
        padding: 6px 10px 2px 10px;
        font-size: 17px;
        white-space: normal;
    }

    span.homepage-latest-video-infotext {
        font-size: 14px;
    }

    /* The description of a video: readable size, cut off after four lines. */
    span.homepage-latest-video-text {
        width: auto;
        height: auto;
        /* no padding at the bottom: the next line would show through below the cut */
        padding-bottom: 0;
        margin-bottom: 10px;
        font-size: 15px;
        line-height: 1.35;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 4;
    }

    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;
    }

    #copyright,
    #social-links {
        font-size: 14px;
    }

    /* 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 input[type=text] {
        width: 100%;
        box-sizing: border-box;
        font-size: 16px;
    }

    /* 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;
    }

    span.video-doclet-description-text {
        font-size: 15px;
        line-height: 19px;
        height: 57px;
    }

    /* the general rule for pictures above would shrink the thumbnail inside its table cell */
    img.video-doclet-thumb {
        width: 110px;
        max-width: none;
    }

    /* 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 page of one post (postpage.php) */
    table.post-list,
    table.post-list table {
        width: 100% !important;
        box-sizing: border-box;
    }

    table.post-list {
        font-size: 16px;
    }

    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;
    }

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

    a.video-list-item {
        height: 78px;
        padding-top: 9px;
        padding-inline-start: 114px;
        border-bottom: 1px solid #c8c8c8;
    }

    a.video-list-item img {
        width: 104px;
        height: 78px;
    }

    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;
    }
}
