/*
 * RowTech mobile workspace
 *
 * Layout-only overrides for Roundcube Elastic. Brand colours intentionally
 * come from the existing RowTech variables in styles.css.
 */

@media screen and (max-width: 480px),
       screen and (max-height: 640px) and (max-width: 768px) {
  html.layout-phone {
    --rt-mobile-nav-height: 76px;
    --rt-mobile-nav-gap: 6px;
    --rt-mobile-panel-bottom: calc(var(--rt-mobile-nav-height) + var(--rt-mobile-nav-gap) * 2 + env(safe-area-inset-bottom));
  }

  html.layout-phone,
  html.layout-phone body {
    min-width: 280px;
    width: 100%;
    height: 100%;
    min-height: 100%;
  }

  html.layout-phone body:not(.task-login) {
    padding: 0 !important;
    overscroll-behavior: none;
  }

  html.layout-phone body:not(.task-login) #layout {
    box-sizing: border-box;
    height: 100vh;
    height: 100dvh;
    min-height: 100svh;
    padding: 0 !important;
  }

  /* The old theme moved each panel up after already reserving bottom space. */
  html.layout-phone body:not(.task-login) #layout-sidebar,
  html.layout-phone body:not(.task-login) #layout-list,
  html.layout-phone body:not(.task-login) #layout-content {
    inset: auto !important;
    bottom: auto !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    height: 100% !important;
    min-height: 0 !important;
    flex: 1 1 100% !important;
    border: 0 !important;
    box-shadow: none !important;
  }

  html.layout-phone #layout > div > .header {
    min-height: 64px !important;
    height: 64px !important;
    line-height: 64px !important;
    padding: env(safe-area-inset-top) 8px 0 !important;
    overflow: visible;
    background: var(--rt-panel, #fff) !important;
    border-bottom: 1px solid var(--rt-line) !important;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  html.layout-phone #layout > div > .header .header-title {
    min-width: 0;
    margin: 0 !important;
    padding: 0 6px;
    text-align: left;
    font-size: 1.28rem;
    line-height: 64px;
    font-weight: 800 !important;
  }

  html.layout-phone #layout > div > .header a.button,
  html.layout-phone #layout > div > .header .toolbar > a,
  html.layout-phone #layout > div > .header .toolbar-button {
    box-sizing: border-box;
    min-width: 44px;
    min-height: 44px;
    margin: 10px 1px !important;
    padding: 0 !important;
    border-radius: 50% !important;
  }

  html.layout-phone #layout > div > .header a.button::before,
  html.layout-phone #layout > div > .header .toolbar > a::before,
  html.layout-phone #layout > div > .header .toolbar-button::before {
    width: 44px;
    height: 44px !important;
    line-height: 44px !important;
    font-size: 1.35rem !important;
  }

  html.layout-phone #layout-list .toolbar.menu {
    align-items: center;
  }

  html.layout-phone #layout-list .searchbar {
    min-height: 54px;
    padding: 7px 12px !important;
    background: var(--rt-panel, #fff) !important;
    border-bottom: 1px solid var(--rt-line) !important;
  }

  html.layout-phone #layout-list .searchbar form {
    height: 40px;
    border-radius: 14px !important;
    background: var(--rt-soft, #f8f8f8);
  }

  html.layout-phone #layout-list .searchbar input {
    min-height: 40px;
    height: 40px !important;
    font-size: 16px;
  }

  html.layout-phone #messagelist-content {
    background: var(--rt-panel, #fff);
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
  }

  /* Outlook-like hierarchy: avatar, sender/date line, subject line. */
  html.layout-phone .messagelist tbody tr {
    position: relative;
    display: flex !important;
    min-height: 82px;
    contain: layout paint;
    background: var(--rt-panel, #fff);
    border-bottom: 1px solid var(--rt-line) !important;
  }

  html.layout-phone .messagelist tbody tr td {
    border: 0 !important;
    background-color: transparent !important;
  }

  html.layout-phone .messagelist tbody tr td.subject {
    position: relative;
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "sender date"
      "subject subject";
    align-content: center;
    column-gap: 8px;
    width: 100% !important;
    min-width: 0;
    min-height: 82px;
    padding: 11px 42px 11px 66px !important;
  }

  html.layout-phone .messagelist td.subject span.fromto {
    grid-area: sender;
    display: block !important;
    min-width: 0;
    padding: 0 !important;
    overflow: hidden;
    color: var(--rt-ink, #191a22) !important;
    font-size: 15px !important;
    line-height: 22px !important;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  html.layout-phone .messagelist td.subject span.date {
    grid-area: date;
    display: block !important;
    align-self: center;
    color: var(--rt-muted, #707680) !important;
    font-size: 11.5px !important;
    line-height: 20px !important;
    white-space: nowrap;
  }

  html.layout-phone .messagelist td.subject span.subject {
    grid-area: subject;
    display: block !important;
    width: auto !important;
    min-width: 0;
    padding: 0 !important;
    overflow: hidden;
    color: var(--rt-ink-soft, #4c4e58) !important;
    font-size: 13.5px !important;
    line-height: 20px !important;
    font-weight: 500;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  html.layout-phone .messagelist td.subject span.subject a {
    display: inline;
    color: inherit !important;
    line-height: inherit;
  }

  html.layout-phone .messagelist tr.unread td.subject span.fromto,
  html.layout-phone .messagelist tr.unread td.subject span.subject,
  html.layout-phone .messagelist tr.unread td.subject span.subject a {
    color: var(--rt-ink, #191a22) !important;
    font-weight: 800 !important;
  }

  html.layout-phone .messagelist tr.unread:not(.selected) td {
    background-color: var(--rt-accent-soft, rgba(98, 85, 255, .12)) !important;
    background-image: none !important;
  }

  html.layout-phone .messagelist tr.unread:not(.selected) td:first-child {
    box-shadow: inset 4px 0 0 var(--rt-accent, #6255ff) !important;
  }

  html.layout-phone .messagelist tr.selected td {
    background: var(--rt-accent-soft, rgba(98, 85, 255, .12)) !important;
  }

  html.layout-phone .messagelist .rt-mobile-avatar {
    position: absolute;
    z-index: 2;
    top: 50%;
    left: 13px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    margin-top: -21px;
    border-radius: 50%;
    background: var(--rt-accent-soft, rgba(98, 85, 255, .12));
    color: var(--rt-accent, #6255ff);
    font-size: 12px;
    line-height: 1;
    font-weight: 800;
    letter-spacing: .02em;
    pointer-events: none;
  }

  html.layout-phone .messagelist tr.unread .rt-mobile-avatar {
    background: var(--rt-accent, #6255ff);
    color: #fff;
  }

  html.layout-phone .messagelist td.flags {
    top: auto !important;
    right: 8px !important;
    bottom: 8px !important;
    width: 30px !important;
    height: 30px;
    line-height: 30px;
  }

  html.layout-phone .messagelist td.flags > span {
    height: 30px;
    line-height: 30px;
  }

  html.layout-phone .messagelist.withselection td.subject {
    padding-left: 98px !important;
  }

  html.layout-phone .messagelist.withselection .rt-mobile-avatar {
    left: 50px;
  }

  html.layout-phone .messagelist td.selection,
  html.layout-phone .messagelist td.threads {
    align-self: center;
    line-height: 82px !important;
  }

  /* Folders remain a full, comfortable touch list. */
  html.layout-phone #folderlist-content {
    padding: 6px 4px 12px;
    -webkit-overflow-scrolling: touch;
  }

  html.layout-phone .folderlist li.mailbox > a {
    min-height: 50px;
    margin: 2px 6px !important;
    padding-top: 12px !important;
    padding-bottom: 12px !important;
    border-radius: 14px !important;
    font-size: 15px;
  }

  html.layout-phone #layout-sidebar .footer.small,
  html.layout-phone #layout-list .footer.small {
    min-height: 42px;
    height: 42px;
    line-height: 42px;
  }

  html.layout-phone #quotadisplay.quota-widget {
    min-height: 42px;
  }

  /* Reading and composing stay one-column and keyboard-safe. */
  html.layout-phone #layout-content .iframe-wrapper,
  html.layout-phone #messagecontframe {
    min-width: 0;
    background: var(--rt-panel, #fff) !important;
  }

  html.layout-phone .task-mail.action-compose #layout-content > .formcontent,
  html.layout-phone body.action-compose #layout-content > .formcontent {
    padding: 10px 12px 18px;
    -webkit-overflow-scrolling: touch;
  }

  html.layout-phone body.action-compose input,
  html.layout-phone body.action-compose textarea,
  html.layout-phone body.action-compose select {
    font-size: 16px !important;
  }

  html.layout-phone body.action-compose .form-control,
  html.layout-phone body.action-compose .custom-select {
    min-height: 44px;
  }

  /* Bottom app navigation; same RowTech colours, corrected geometry. */
  html.layout-phone body:not(.task-login) #layout-menu {
    position: fixed !important;
    z-index: 5000 !important;
    inset: auto max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left)) !important;
    box-sizing: border-box;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    height: var(--rt-mobile-nav-height) !important;
    max-height: none !important;
    overflow: visible !important;
    border: 1px solid rgba(255, 255, 255, .10) !important;
    border-radius: 22px !important;
    background: var(--rt-menu, #171820) !important;
    box-shadow: 0 16px 38px rgba(17, 18, 24, .28) !important;
  }

  html.layout-phone #layout-menu .popover-header {
    display: none !important;
  }

  html.layout-phone #taskmenu {
    display: flex !important;
    align-items: stretch !important;
    justify-content: space-around !important;
    gap: 2px !important;
    width: 100%;
    height: 100% !important;
    padding: 5px !important;
    overflow: visible;
  }

  html.layout-phone #layout-menu .action-buttons {
    display: none !important;
  }

  html.layout-phone #taskmenu > a,
  html.layout-phone #taskmenu > .action-buttons > a,
  html.layout-phone #taskmenu > button.rt-mobile-more {
    flex: 1 1 0 !important;
    min-width: 0 !important;
    min-height: 64px !important;
    height: 64px !important;
    margin: 0 2px !important;
    padding: 6px 4px 5px !important;
    border: 0;
    border-radius: 17px !important;
    background: transparent;
    color: rgba(255, 255, 255, .78) !important;
    box-shadow: none !important;
    font-family: inherit;
    text-align: center;
  }

  html.layout-phone #taskmenu > button.rt-mobile-more {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    cursor: pointer;
  }

  html.layout-phone #taskmenu > a::before {
    height: 25px !important;
    margin: 0 !important;
    font-size: 23px !important;
    line-height: 25px !important;
  }

  html.layout-phone #taskmenu > a .inner {
    font-size: 11px !important;
    line-height: 1.1 !important;
  }

  html.layout-phone #taskmenu > a.mail .inner::after,
  html.layout-phone #taskmenu > a.contacts .inner::after,
  html.layout-phone #taskmenu > a.settings .inner::after {
    font-size: 11px !important;
  }

  html.layout-phone #taskmenu > button.rt-mobile-more::before {
    content: "";
    display: block;
    width: 27px;
    height: 25px;
    background: radial-gradient(circle, currentColor 2.2px, transparent 2.6px) center / 9px 9px repeat-x;
  }

  html.layout-phone #taskmenu > button.rt-mobile-more .inner {
    max-width: 100%;
    overflow: hidden;
    font-size: 11px;
    line-height: 1.1;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  html.layout-phone #taskmenu > button.rt-mobile-more[aria-expanded="true"] {
    background: var(--rt-accent, #6255ff) !important;
    color: #fff !important;
  }

  html.layout-phone #layout-menu .special-buttons {
    position: fixed;
    right: max(10px, env(safe-area-inset-right));
    bottom: calc(var(--rt-mobile-panel-bottom) + 2px);
    display: none !important;
    width: min(250px, calc(100vw - 20px));
    padding: 7px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, .10);
    border-radius: 18px;
    background: var(--rt-menu, #171820) !important;
    box-shadow: 0 18px 44px rgba(17, 18, 24, .30);
  }

  html.layout-phone #layout-menu.rt-mobile-more-open .special-buttons {
    display: flex !important;
    flex-direction: column;
  }

  html.layout-phone #layout-menu .special-buttons a {
    display: flex !important;
    flex: 0 0 auto !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 8px !important;
    width: auto !important;
    height: auto !important;
    min-height: 46px !important;
    margin: 1px !important;
    padding: 8px 10px !important;
    border-radius: 12px !important;
    color: rgba(255, 255, 255, .86) !important;
    text-align: left !important;
  }

  html.layout-phone #layout-menu .special-buttons a::before {
    flex: 0 0 30px;
    width: 30px !important;
    height: 30px !important;
    margin: 0 !important;
    line-height: 30px !important;
    text-align: center;
  }

  html.layout-phone #layout-menu .special-buttons a .inner {
    display: inline !important;
    width: auto !important;
    max-width: none !important;
    height: auto !important;
    overflow: visible !important;
    font-size: 13px !important;
    line-height: 20px !important;
    text-overflow: clip !important;
  }

  html.layout-phone .floating-action-buttons {
    right: 2px;
    bottom: 2px;
  }

  html.layout-phone .footer:not(:empty) + .floating-action-buttons {
    bottom: 42px;
  }

  html.layout-phone .floating-action-buttons a.button {
    width: 54px;
    height: 54px;
    margin: 0 10px 10px 0;
    border-radius: 16px;
    background: var(--rt-accent, #6255ff) !important;
    box-shadow: 0 14px 28px rgba(98, 85, 255, .28) !important;
  }

  html.layout-phone .floating-action-buttons a.button::before {
    width: 54px;
    height: 54px;
    line-height: 54px;
  }

  /* When the software keyboard opens, recover the whole lower viewport. */
  html.layout-phone body.rt-mobile-keyboard #layout-menu {
    display: none !important;
  }

  html.layout-phone body.rt-mobile-keyboard #layout {
    padding-bottom: 0 !important;
  }

  html.layout-phone body.rt-mobile-keyboard #layout-sidebar,
  html.layout-phone body.rt-mobile-keyboard #layout-list,
  html.layout-phone body.rt-mobile-keyboard #layout-content {
    height: 100% !important;
  }

  html.dark-mode.layout-phone .messagelist tbody tr,
  html.dark-mode.layout-phone #messagelist-content,
  html.dark-mode.layout-phone #layout-list .searchbar,
  html.dark-mode.layout-phone #layout > div > .header {
    background: var(--rt-panel, #171820) !important;
  }

  html.dark-mode.layout-phone .messagelist td.subject span.fromto,
  html.dark-mode.layout-phone .messagelist td.subject span.subject,
  html.dark-mode.layout-phone .messagelist td.subject span.subject a {
    color: var(--rt-ink, #f5f5f7) !important;
  }

  html.dark-mode.layout-phone .messagelist td.subject span.date {
    color: var(--rt-muted, #a8adba) !important;
  }

  html.dark-mode.layout-phone .messagelist tr.unread:not(.selected) td {
    background: var(--rt-accent-soft, rgba(98, 85, 255, .24)) !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  html.layout-phone #messagelist-content {
    scroll-behavior: auto;
  }
}

/* Desktop rail: give two-line labels enough room without widening the bar. */
@media screen and (min-width: 1025px) {
  #layout-menu #taskmenu > a,
  #layout-menu #taskmenu > .action-buttons > a {
    height: auto !important;
    min-height: 64px !important;
    margin-top: 7px !important;
    margin-bottom: 7px !important;
  }

  #layout-menu #taskmenu > .action-buttons > a.compose {
    min-height: 72px !important;
    margin-bottom: 9px !important;
  }

  #layout-menu #taskmenu > a .inner,
  #layout-menu #taskmenu > .action-buttons > a .inner {
    line-height: 1.2 !important;
  }
}

/* Short vertical rails: compact utilities and reveal their labels on demand. */
@media screen and (min-width: 769px) and (max-height: 820px),
       screen and (min-width: 481px) and (max-width: 768px) and (min-height: 641px) and (max-height: 820px) {
  #layout-menu .popover-header {
    height: 66px !important;
  }

  #layout-menu .popover-header img,
  #layout-menu #logo {
    width: 48px !important;
    height: 48px !important;
    max-width: 48px !important;
    max-height: 48px !important;
    margin-top: 9px !important;
  }

  #layout-menu #taskmenu > a,
  #layout-menu #taskmenu > .action-buttons > a {
    height: auto !important;
    min-height: 54px !important;
    margin: 3px 8px !important;
    padding: 4px 3px !important;
    gap: 2px !important;
  }

  #layout-menu #taskmenu > .action-buttons > a.compose {
    min-height: 62px !important;
    margin-bottom: 5px !important;
  }

  #layout-menu #taskmenu > a::before,
  #layout-menu #taskmenu > .action-buttons > a::before {
    font-size: 19px !important;
  }

  #layout-menu #taskmenu > a .inner,
  #layout-menu #taskmenu > .action-buttons > a .inner {
    font-size: 10.5px !important;
    line-height: 1.1 !important;
  }

  #layout-menu .special-buttons a {
    position: relative !important;
    height: 42px !important;
    min-height: 42px !important;
    margin: 2px 8px !important;
    padding: 3px !important;
    overflow: visible !important;
  }

  #layout-menu .special-buttons a::before {
    font-size: 19px !important;
  }

  #layout-menu .special-buttons a .inner {
    position: absolute !important;
    z-index: 6000;
    top: 50%;
    left: calc(100% + 8px);
    display: block !important;
    width: max-content !important;
    max-width: 180px !important;
    padding: 6px 9px !important;
    overflow: visible !important;
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 9px;
    background: var(--rt-menu, #171820);
    color: #fff !important;
    font-size: 11px !important;
    line-height: 1.15 !important;
    white-space: nowrap !important;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-50%) translateX(-4px);
    transition: opacity .14s ease, transform .14s ease, visibility .14s ease;
  }

  #layout-menu .special-buttons a:hover .inner,
  #layout-menu .special-buttons a:focus .inner,
  #layout-menu .special-buttons a:focus-visible .inner {
    opacity: 1;
    visibility: visible;
    transform: translateY(-50%) translateX(0);
  }
}

/* Very short desktop windows: icons stay available, labels become tooltips. */
@media screen and (min-width: 769px) and (max-height: 620px) {
  #layout-menu .popover-header {
    height: 54px !important;
  }

  #layout-menu .popover-header img,
  #layout-menu #logo {
    width: 42px !important;
    height: 42px !important;
    max-width: 42px !important;
    max-height: 42px !important;
    margin-top: 6px !important;
  }

  #layout-menu #taskmenu > a,
  #layout-menu #taskmenu > .action-buttons > a {
    position: relative !important;
    height: 44px !important;
    min-height: 44px !important;
    margin: 2px 8px !important;
    padding: 3px !important;
    overflow: visible !important;
  }

  #layout-menu #taskmenu > .action-buttons > a.compose {
    min-height: 48px !important;
    margin-bottom: 3px !important;
  }

  #layout-menu #taskmenu > a .inner,
  #layout-menu #taskmenu > .action-buttons > a .inner {
    position: absolute !important;
    z-index: 6000;
    top: 50%;
    left: calc(100% + 8px);
    display: block !important;
    width: max-content !important;
    max-width: 180px !important;
    padding: 6px 9px !important;
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 9px;
    background: var(--rt-menu, #171820);
    color: #fff !important;
    font-size: 11px !important;
    line-height: 1.15 !important;
    white-space: nowrap !important;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-50%) translateX(-4px);
  }

  #layout-menu #taskmenu > a:hover .inner,
  #layout-menu #taskmenu > a:focus .inner,
  #layout-menu #taskmenu > a:focus-visible .inner,
  #layout-menu #taskmenu > .action-buttons > a:hover .inner,
  #layout-menu #taskmenu > .action-buttons > a:focus .inner,
  #layout-menu #taskmenu > .action-buttons > a:focus-visible .inner {
    opacity: 1;
    visibility: visible;
    transform: translateY(-50%) translateX(0);
  }
}
