/** Modern Larry phone/tablet layout. Desktop rules remain in modern.css.
 * CC BY-SA 3.0; see README.md. */
#ml-mobile-nav, #ml-drawer-backdrop { display: none; }

@media screen and (max-width: 800px), screen and (max-width: 1100px) and (pointer: coarse) {
  html { min-width: 0; }
  body, body.minwidth { min-width: 0 !important; font-size: 14px; }
  body:not(.iframe):not(.modern-login) { overflow: hidden; }
  *, *::before, *::after { -webkit-tap-highlight-color: transparent; }
  input[type="text"], input[type="email"], input[type="password"],
  input[type="search"], input[type="number"], input[type="url"], textarea, select {
    max-width: 100%;
    font-size: 16px;
  }
  input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; }
  button, input.button, a.button { touch-action: manipulation; }

  /* Account bar, task navigation, and the mobile pane controls. */
  #header { position: fixed; inset: 0 0 auto; z-index: 300; height: 84px; overflow: visible; }
  #header > br { display: none; }
  #topline, .minimal #topline, .minimal #topline:hover, .extwin #topline {
    height: 28px; padding: 3px 10px; font-size: 11px; line-height: 22px;
  }
  #topline .topleft { max-width: 30%; white-space: nowrap; overflow: hidden; }
  #topline .topright { display: flex; align-items: center; max-width: 70%; }
  #topline span.username, .minimal #topline span.username {
    display: inline-block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    padding-right: 4px; min-width: 0;
  }
  #topline a.button-logout { flex: 0 0 auto; }
  #topnav, .minimal #topnav { height: 56px; padding: 0 6px; }
  #toplogo { display: none; }
  #taskbar { float: none; width: 100%; height: 56px; padding: 0; gap: 4px; overflow-x: auto; }
  #taskbar a, .minimal #taskbar a {
    flex: 1 0 auto; justify-content: center; height: 44px; padding: 0 12px; border-radius: 6px;
  }
  #taskbar a span.button-inner, .minimal #taskbar a span.button-inner { gap: 6px; font-size: 12px; }
  #taskbar .minmodetoggle { display: none; }
  #ml-mobile-nav {
    position: fixed; top: 84px; left: 0; right: 0; z-index: 300;
    box-sizing: border-box; display: flex; align-items: center; gap: 4px;
    height: 48px; padding: 4px 8px; border-bottom: 1px solid var(--ml-border);
    background: var(--ml-surface);
  }
  #ml-mobile-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 6px; font-weight: 600; font-size: 13px; }
  #ml-mobile-nav .ml-mobile-button {
    display: inline-flex; align-items: center; gap: 6px; flex: 0 0 auto;
    min-height: 40px; margin: 0; padding: 7px 9px; border-color: transparent;
    background: transparent; color: var(--ml-accent); font-size: 12px;
  }
  #ml-mobile-nav [hidden] { display: none !important; }
  .ml-mobile-button::before {
    content: ""; display: inline-block; width: 18px; height: 18px; background: currentColor;
    -webkit-mask: var(--ml-icon) center / contain no-repeat; mask: var(--ml-icon) center / contain no-repeat;
  }
  .ml-mobile-menu { --ml-icon: url(images/modern/menu.svg); }
  .ml-mobile-back { --ml-icon: url(images/modern/back.svg); }
  .ml-mobile-select { --ml-icon: url(images/modern/select.svg); }
  #ml-mobile-nav .ml-mobile-button[aria-expanded="true"],
  #ml-mobile-nav .ml-mobile-button[aria-pressed="true"] { background: var(--ml-selection); }

  /* One workspace, one pane at a time. !important beats inline splitters. */
  #mainscreen, #mainscreen.offset,
  .minimal #mainscreen, .minimal #mainscreen.offset,
  .extwin #mainscreen, .extwin #mainscreen.offset {
    position: fixed; top: 140px; left: 8px; right: 8px; bottom: max(8px, env(safe-area-inset-bottom));
    min-width: 0;
  }
  #mainscreencontent { top: 0; }
  .ml-has-toolbar #mainscreencontent { top: 62px; }
  .ml-has-search #mainscreencontent { top: 112px; }
  .splitter, .iframe-splitter-fix { display: none !important; }
  #mailview-right, #addressview-right, #composeview-right,
  #settings-right, #pluginbody, #messagepartcontainer {
    left: 0 !important; right: 0 !important; width: auto !important; min-width: 0;
  }
  #mailview-right.offset { top: 62px; }
  #mailview-top, .widescreen #mailview-top {
    top: 0 !important; bottom: 0 !important; left: 0 !important; right: 0 !important;
    width: auto !important; height: auto !important;
  }
  .ml-mail-list #mailview-bottom { display: none !important; }

  /* Horizontal toolbar scrolling keeps every action available. Menus are
     moved to the document body by Roundcube, so they remain outside it. */
  #messagetoolbar, #addressbooktoolbar {
    position: absolute; top: 0; left: 0; right: 0; width: auto; height: 56px;
    overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  .toolbar a.button { min-width: 56px; max-width: 96px; height: 48px; margin: 0 2px; padding-left: 6px; padding-right: 6px; }
  .toolbar a.button.compose, .toolbar a.button.send { min-width: 76px; }
  .toolbar .spacer { width: 6px; }
  .toolbar .dropbutton { vertical-align: top; }
  #messagesearchtools { position: absolute; top: 62px; left: 0; right: 0; height: 42px; display: flex; gap: 8px; }
  #searchfilter { position: relative; top: 0; right: auto; flex: 0 1 32%; min-width: 0; }
  #searchfilter select { width: 100%; max-width: 100%; height: 40px; padding-left: 8px; font-size: 16px; }
  #messagesearchtools #quicksearchbar { position: relative; top: 0; left: auto; right: auto; flex: 1; width: auto; min-width: 0; }
  #mainscreen > #quicksearchbar { position: absolute; top: 62px; left: 0; right: 0; width: auto; }
  .searchbox input, #quicksearchbar input, #addressview-left #quicksearchbar input { width: 100%; height: 40px; font-size: 16px; }
  .searchbox .searchicon, .searchbox #searchmenulink, #quicksearchbar #searchmenulink { top: 11px; }
  .searchbox #searchreset, .searchbox .iconbutton.reset, #quicksearchbar #searchreset { top: 10px; }

  /* Off-canvas folders, address sources, compose contacts, and settings tabs. */
  #mailview-left.ml-mobile-drawer, #addressview-left.ml-mobile-drawer,
  #composeview-left.ml-mobile-drawer, #settings-sections.ml-mobile-drawer,
  #messagepartheader.ml-mobile-drawer {
    position: fixed; z-index: 320; top: 132px; bottom: 0; left: 0;
    box-sizing: border-box; width: min(320px, calc(100vw - 48px)) !important; height: auto;
    transform: translateX(-105%); visibility: hidden; border-radius: 0;
    border: 0; background: var(--ml-surface); box-shadow: 8px 0 28px rgb(16 34 47 / 18%);
  }
  .ml-drawer-open #mailview-left.ml-mobile-drawer,
  .ml-drawer-open #addressview-left.ml-mobile-drawer,
  .ml-drawer-open #composeview-left.ml-mobile-drawer,
  .ml-drawer-open #settings-sections.ml-mobile-drawer,
  .ml-drawer-open #messagepartheader.ml-mobile-drawer { transform: none; visibility: visible; }
  #ml-drawer-backdrop {
    position: fixed; z-index: 310; inset: 132px 0 0; width: 100%; height: auto;
    margin: 0; padding: 0; border: 0; border-radius: 0; background: rgb(16 34 47 / 35%);
  }
  .ml-drawer-open #ml-drawer-backdrop { display: block; }
  .ml-mobile-drawer .uibox { border-radius: 0; border: 0; box-shadow: none; }
  .ml-mobile-drawer .listing li > a, #subscription-table li > a { padding-top: 13px; padding-bottom: 13px; }
  .ml-mobile-drawer .folderlist li.mailbox .unreadcount { top: 12px; }
  #subscription-table li input { top: 13px; }
  #settings-sections.ml-mobile-drawer .boxtitle { padding: 11px 14px; }
  #settings-sections.ml-mobile-drawer .boxtitle + .scroller { top: 43px; }

  /* Message cards support the user's normal List layout and saved preview
     layouts, without changing the server's columns or sorting preferences. */
  #messagelistcontainer, .widescreen #messagelistcontainer { top: 0; bottom: 94px; overflow-x: hidden; }
  #messagelistheader, .widescreen #messagelistheader,
  #messagelist thead, table.messagelist.fixedcopy { display: none !important; }
  #messagelist { display: block; width: 100% !important; table-layout: auto; border: 0; }
  #messagelist tbody { display: block; width: 100%; }
  #messagelist tr.message {
    display: grid; grid-template-columns: 24px minmax(0, 1fr) minmax(60px, 100px) 24px;
    grid-template-rows: auto auto; position: relative; min-height: 64px;
    box-sizing: border-box; padding: 8px 6px; border-bottom: 1px solid #edf1f5;
  }
  #messagelist tr.message > td {
    display: block; box-sizing: border-box; width: auto; min-width: 0; height: auto;
    padding: 2px 4px !important; border: 0; background: transparent;
    overflow: hidden; text-overflow: ellipsis; line-height: 22px;
  }
  #messagelist tr.message > td.subject { grid-column: 2 / 4; grid-row: 2; font-size: 14px; }
  #messagelist tr.message > td.fromto,
  #messagelist tr.message > td.from,
  #messagelist tr.message > td.to { grid-column: 2; grid-row: 1; font-size: 13px; }
  #messagelist tr.message > td.date { grid-column: 3; grid-row: 1; text-align: right; color: var(--ml-muted); font-size: 11px; }
  #messagelist tr.message > td.flag { grid-column: 4; grid-row: 1; }
  #messagelist tr.message > td.attachment { grid-column: 4; grid-row: 2; }
  #messagelist tr.message > td.status { grid-column: 1; grid-row: 2; }
  #messagelist tr.message > td.threads { grid-column: 1; grid-row: 1; }
  #messagelist tr.message > td.selection { display: none; grid-column: 1; grid-row: 1 / 3; align-self: center; }
  .ml-selecting #messagelist tr.message > td.selection { display: block; }
  .ml-selecting #messagelist tr.message > td.status { display: none; }
  .ml-selecting #messagelist tr.message > td.threads { grid-column: 4; grid-row: 2; }
  #messagelist tr.message > td.size, #messagelist tr.message > td.priority,
  #messagelist tr.message > td.folder, #messagelist tr.message > td.cc,
  #messagelist tr.message > td.replyto, #messagelist tr.message > td.hidden { display: none; }
  #messagelist tr.message.selected { background: var(--ml-selection); box-shadow: inset 3px 0 var(--ml-accent); }
  #messagelist tr.message.selected td, #messagelist.focus tr.message.selected td { background: transparent !important; }
  #messagelist tr.message.unread > td.fromto, #messagelist tr.message.unread > td.from { color: #172b3a; }
  #messagelist tr.message > td.subject a { display: inline; }
  #messagelist td .branch { display: none; }
  /* The saved widescreen layout already nests sender/date in its subject. */
  .widescreen #messagelist tr.message > td.subject { grid-row: 1 / 3; }
  .widescreen #messagelist td.subject span.fromto { display: block; margin: 0 90px 0 0; padding: 0; color: inherit; font-size: 13px; }
  .widescreen #messagelist td.subject span.date { top: 2px; right: 4px; font-size: 11px; }
  .widescreen #messagelist td.subject span.subject { display: block; font-size: 14px; line-height: 22px; }
  .widescreen #messagelist tr.message > td.flags { grid-column: 4; grid-row: 1 / 3; }
  .widescreen #messagelist td.subject span.msgicon { display: none; }

  /* Two footer rows give selection and pagination real touch space. */
  #messagelistfooter { height: 94px; padding: 6px; white-space: normal; }
  #messagelistfooter #listcontrols, #messagelistfooter #listselectors { vertical-align: middle; margin: 0 12px 5px 0; }
  #messagelistfooter #countcontrols, .widescreen #messagelistfooter #countcontrols {
    display: flex; justify-content: space-between; align-items: center; width: 100%; white-space: nowrap;
  }
  #messagelistfooter .countdisplay { min-width: 0; padding: 0 4px; font-size: 11px; }
  #messagelistfooter .pagenavbuttons { position: static; display: inline-flex; align-items: center; gap: 2px; }
  #messagelistfooter .pagenav a.button { box-sizing: border-box; width: 30px; height: 36px; padding: 10px 6px; }
  #messagelistfooter .pagenav .pagejumper { width: 36px; height: 34px; padding: 3px 0; font-size: 16px; }
  #messagelistfooter a.iconbutton { height: 24px; vertical-align: middle; }
  a.menuselector .handle { height: 28px; line-height: 28px; }

  /* Contacts and settings: list first, detail iframe after selection. */
  #addresslist, #sectionslist, #folderslist, #identitieslist, #responseslist {
    left: 0 !important; right: 0 !important; width: auto !important; top: 0; bottom: 0;
  }
  #contacts-box, #preferences-box, #folder-details, #identity-details, #response-details {
    display: none; left: 0 !important; right: 0 !important; width: auto !important; top: 0; bottom: 0;
  }
  .ml-detail-open #contacts-box, .ml-detail-open #preferences-box,
  .ml-detail-open #folder-details, .ml-detail-open #identity-details,
  .ml-detail-open #response-details { display: block; }
  .ml-detail-open #addresslist, .ml-detail-open #sectionslist,
  .ml-detail-open #folderslist, .ml-detail-open #identitieslist,
  .ml-detail-open #responseslist { display: none; }
  #contacts-table td.selection { display: none; }
  .ml-selecting #contacts-table td.selection { display: table-cell; width: 34px; }
  #contacts-table td.name { width: auto; }
  .listing tbody td { padding-top: 13px; padding-bottom: 13px; }
  #contacts-table td.name::before, #sections-table td.section::before { vertical-align: -3px; }
  #folderslist .listsearchbox { box-sizing: border-box; }
  #pluginbody { overflow: auto; }

  /* Full reader: wrapping headers and attachments above the message. Wide
     HTML content can scroll inside the message instead of widening the app. */
  #mailview-right #messageheader { max-height: 40vh; overflow-y: auto; padding: 8px 10px 8px 24px; }
  #messageheader #contactphoto { display: none; }
  #messageheader #countcontrols, #messageheader #formatcontrols {
    position: static; width: auto; margin: 0 0 6px; text-align: right; white-space: normal;
  }
  #messageheader .pagenav .countdisplay { min-width: 0; padding: 0 5px; font-size: 11px; }
  /* Override Larry's more-specific -56px subject margin, which compensates
     for the desktop avatar and clips the opening letters on phones. */
  #messageheader h2.subject, #messageheader h3.subject,
  #mailview-right #messageheader h2.subject,
  #messageheader.previewheader h3.subject { clear: both; margin: 4px 0 8px; padding: 0; white-space: normal; overflow-wrap: anywhere; font-size: 17px; }
  #messageheader .message-headers { min-height: 0; }
  #messageheader .headers-table { width: 100%; table-layout: fixed; font-size: 12px; }
  #messageheader .headers-table td.header-title { width: 54px; padding-right: 5px; }
  #messageheader .headers-table td.header { white-space: normal; overflow-wrap: anywhere; }
  #messagecontent .rightcol, #messagepreview .rightcol {
    position: relative; top: auto; right: auto; width: auto; min-height: 0;
    margin: 0; padding: 8px; border-radius: 0; background: var(--ml-subtle);
  }
  #messagecontent .leftcol, #messagepreview .leftcol { margin-right: 0 !important; }
  #messagebody { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  #messagebody img { max-width: 100%; height: auto; }
  #messagepartheader.ml-mobile-drawer { padding: 12px; overflow: auto; }

  /* Compose is a scrolling form, followed by the editor and attachments. */
  #compose-content { position: absolute; inset: 0; overflow: auto !important; -webkit-overflow-scrolling: touch; }
  #composeheaders { padding: 10px 8px 8px 22px; }
  .compose-headers { width: 100%; table-layout: fixed; margin: 0; }
  .compose-headers td.title { width: 60px; min-width: 0; padding-left: 0; font-size: 12px; }
  .compose-headers td.editfield { width: auto; padding-right: 0; }
  #composeheaders .compose-headers textarea,
  #composeheaders .compose-headers input[type="text"],
  #composeheaders .compose-headers input[type="email"] { width: 100%; min-height: 42px; font-size: 16px; line-height: 24px; }
  #composeheaders .compose-headers select { width: 100%; min-height: 42px; font-size: 16px; }
  .compose-headers td.formlinks { white-space: normal; }
  #composeheaders .compose-headers a.iconlink { margin-left: 0; padding-top: 7px; padding-bottom: 7px; font-size: 12px; }
  #composeheaders .compose-headers a.iconlink::before { top: 9px; }
  #composebuttons { position: static; text-align: right; margin: 6px 0; }
  #composeoptions { padding: 8px 0 0; }
  #composeoptions .composeoption { display: block; padding: 5px 0; }
  #composeview-bottom { height: auto !important; min-height: 0; }
  #composebodycontainer { position: relative; inset: auto; width: 100%; min-height: 360px; border-radius: 0; }
  #composebody { box-sizing: border-box; width: 100% !important; height: 360px !important; min-height: 360px; padding: 12px; font-size: 16px; }
  #composebodycontainer > div { box-sizing: border-box; max-width: 100%; width: 100% !important; }
  #composebodycontainer .tox-tinymce { width: 100% !important; min-height: 360px; }
  #composebody_ifr { width: 100% !important; min-height: 260px; }
  #compose-attachments.rightcol { position: relative; inset: auto; box-sizing: border-box; width: 100%; min-height: 0; padding: 12px; border-top: 1px solid var(--ml-border); }
  #compose-attachments .upload-form { text-align: left !important; }
  #compose-attachments ul.attachmentslist { margin: 0; padding: 0; }

  /* Embedded settings/contact forms and plugin panels. */
  body.iframe { min-width: 0 !important; }
  body.iframe .boxcontent { box-sizing: border-box; max-width: 100%; overflow-x: auto; }
  body.iframe .boxtitle { box-sizing: border-box; width: 100%; overflow: hidden; text-overflow: ellipsis; }
  table.propform { table-layout: fixed; }
  table.propform > tbody > tr > td { display: block; box-sizing: border-box; width: 100%; padding: 8px 10px; }
  table.propform > tbody > tr > td.title { width: 100%; padding-bottom: 2px; white-space: normal; font-weight: 600; }
  .propform input[type="text"], .propform input[type="password"],
  .propform textarea, .propform select { max-width: 100%; }
  .skinselection span { max-width: 100%; white-space: normal; }
  .skinselection { overflow-wrap: anywhere; }
  #rcmfd_signature { min-width: 0; width: 100%; }
  #contact-details, #contacthead { min-width: 0; max-width: 100%; }
  #contact-details input, #contact-details select, #contact-details textarea { min-width: 0; max-width: 100%; }
  .contactfieldgroup .contactfieldlabel, .contactfieldgroup .contactfieldcontent { width: auto; float: none; }
  .tabsbar { display: flex; flex-wrap: wrap; height: auto; }
  .tabsbar .tablink { float: none; }
  .ui-dialog.ui-widget-content { box-sizing: border-box; max-width: calc(100vw - 16px); }
  .ui-dialog .ui-dialog-content { box-sizing: border-box; max-width: 100%; }
  .popupmenu { max-width: calc(100vw - 24px); box-sizing: border-box; }
  ul.toolbarmenu li a, ul.toolbarmenu li label { min-height: 24px; }
  ul.toolbarmenu li span.icon { min-height: 24px; height: auto; line-height: 24px; }
  ul.toolbarmenu li span.icon::before { top: 8px; }
  #messagestack { position: fixed; bottom: max(8px, env(safe-area-inset-bottom)); right: 8px; left: 8px; max-height: 45%; }
  #messagestack div { box-sizing: border-box; max-width: 100%; width: auto; }
  #login-form { margin-top: 40px; }
  #login-form input { font-size: 16px; }
}
