/* MZUNI Mail — responsive navigation and icon alignment repair.
   Loaded AFTER outlook.css so the v22 Inbox/Compose styles remain intact.
   Uses Roundcube's own .hidden pane navigation; no DOM polling. */

:root {
  --mzuni-mobile-menu-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M4 6h16M4 12h16M4 18h16'/%3E%3C/svg%3E");
  --mzuni-mobile-back-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m15 18-6-6 6-6M9 12h12'/%3E%3C/svg%3E");
  --mzuni-mobile-folders-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 7a2 2 0 0 1 2-2h5l2 2h7a2 2 0 0 1 2 2v10H3z'/%3E%3C/svg%3E");
  --mzuni-mobile-search-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='10.5' cy='10.5' r='6.5'/%3E%3Cpath d='m16 16 5 5'/%3E%3C/svg%3E");
  --mzuni-mobile-close-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M5 5l14 14M19 5 5 19'/%3E%3C/svg%3E");
}

/* Help and Theme are in the suitebar and profile menu; Sign out is in the
   profile card footer. Do not duplicate these at the bottom of the left rail. */
body:not(.task-login) #taskmenu .special-buttons { display: none !important; }
body:not(.task-login) #taskmenu a,
body:not(.task-login) #taskmenu .button { flex-shrink: 0 !important; }
body:not(.task-login) #taskmenu a.compose::before { --fluent-icon: var(--fluent-compose) !important; }
body:not(.task-login) #taskmenu a.mail::before { --fluent-icon: var(--fluent-mail) !important; }
body:not(.task-login) #taskmenu a.contacts::before { --fluent-icon: var(--fluent-contacts) !important; }
body:not(.task-login) #taskmenu a.settings::before { --fluent-icon: var(--fluent-settings) !important; }
body:not(.task-login) #taskmenu a.compose::before,
body:not(.task-login) #taskmenu a.mail::before,
body:not(.task-login) #taskmenu a.contacts::before,
body:not(.task-login) #taskmenu a.settings::before {
  content: "" !important;
  display: block !important;
  width: 21px !important;
  height: 21px !important;
  flex: 0 0 21px !important;
  font-size: 0 !important;
  background: currentColor !important;
  -webkit-mask: var(--fluent-icon) center / contain no-repeat !important;
  mask: var(--fluent-icon) center / contain no-repeat !important;
}
body:not(.task-login) .outlook-profile-logout::before {
  --fluent-icon: var(--fluent-logout) !important;
  content: "" !important;
  background: currentColor !important;
  -webkit-mask: var(--fluent-icon) center / contain no-repeat !important;
  mask: var(--fluent-icon) center / contain no-repeat !important;
}
body:not(.task-login) #outlook-suitebar .outlook-profile-menu { margin-left: 0 !important; }
body:not(.task-login) #outlook-suitebar .outlook-profile-card { z-index: 1400 !important; }
body:not(.task-login) #outlook-suitebar .outlook-top-action,
body:not(.task-login) #outlook-suitebar .outlook-profile-trigger { flex-shrink: 0 !important; }
body:not(.task-login) #outlook-suitebar .outlook-top-action:focus-visible,
body:not(.task-login) #outlook-suitebar .outlook-profile-trigger:focus-visible {
  outline: 2px solid #fff !important;
  outline-offset: 2px !important;
}

/* Hidden in desktop; used only for narrow viewport navigation. */
#outlook-mobile-menu, #outlook-mobile-back,
#outlook-mobile-folders, #outlook-mobile-search { display: none !important; }

@media screen and (max-width: 1100px) and (min-width: 769px) {
  #outlook-suitebar { gap: 8px !important; }
  #outlook-suitebar .outlook-search-slot { min-width: 150px !important; }
  #outlook-suitebar .outlook-suite-actions { gap: 4px !important; min-width: 0 !important; }
  #outlook-suitebar .outlook-top-action { padding: 0 8px !important; gap: 6px !important; }
}

@media screen and (max-width: 768px) {
  :root { --outlook-suitebar-height: 56px; }
  html, body { max-width: 100%; overflow-x: hidden !important; }
  body:not(.task-login) #layout {
    width: 100% !important;
    height: 100vh !important;
    height: 100dvh !important;
    padding-top: var(--outlook-suitebar-height) !important;
    padding-bottom: 0 !important;
    min-width: 0 !important;
    display: flex !important;
    overflow: hidden !important;
  }
  body:not(.task-login) #outlook-suitebar {
    height: var(--outlook-suitebar-height) !important;
    min-height: var(--outlook-suitebar-height) !important;
    padding: 0 8px !important;
    gap: 5px !important;
    justify-content: flex-start !important;
    overflow: visible !important;
    z-index: 1100 !important;
  }
  body:not(.task-login) #outlook-suitebar .outlook-brand {
    min-width: 0 !important;
    width: auto !important;
    flex: 0 0 auto !important;
    gap: 6px !important;
  }
  body:not(.task-login) #outlook-suitebar .outlook-brand-mark {
    width: 36px !important;
    height: 36px !important;
    flex: 0 0 36px !important;
    background-size: 33px 33px !important;
  }
  body:not(.task-login) #outlook-suitebar .outlook-brand-title {
    display: inline !important;
    font-size: 15px !important;
  }
  body:not(.task-login) #outlook-suitebar .outlook-suite-actions {
    display: flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 4px !important;
    flex: 1 1 auto !important;
    min-width: 0 !important;
    max-width: none !important;
    margin-left: auto !important;
    overflow: visible !important;
  }
  /* Secondary actions live in the profile menu on phones/tablets. */
  body:not(.task-login) #outlook-suitebar .outlook-top-action.contacts,
  body:not(.task-login) #outlook-suitebar .outlook-top-action.settings,
  body:not(.task-login) #outlook-suitebar .outlook-top-action.help,
  body:not(.task-login) #outlook-suitebar .outlook-top-action.theme {
    display: none !important;
  }
  body:not(.task-login) #outlook-suitebar .outlook-top-action.compose {
    display: inline-flex !important;
    width: 40px !important;
    min-width: 40px !important;
    height: 40px !important;
    min-height: 40px !important;
    padding: 0 !important;
    border-radius: 9px !important;
  }
  body:not(.task-login) #outlook-suitebar .outlook-top-action.compose::after { display: none !important; content: none !important; }
  body:not(.task-login) #outlook-suitebar .outlook-profile-trigger {
    width: 40px !important;
    min-width: 40px !important;
    height: 40px !important;
    padding: 0 !important;
  }
  body:not(.task-login) #outlook-suitebar .outlook-profile-avatar { width: 32px !important; height: 32px !important; }
  body:not(.task-login) #outlook-suitebar .outlook-profile-avatar.large { width: 54px !important; height: 54px !important; }

  body:not(.task-login) #outlook-mobile-menu,
  body:not(.task-login) #outlook-mobile-folders,
  body:not(.task-login) #outlook-mobile-search,
  body:not(.task-login) #outlook-mobile-back {
    flex: 0 0 38px !important;
    width: 38px !important;
    height: 40px !important;
    min-width: 38px !important;
    min-height: 40px !important;
    border: 0 !important;
    border-radius: 9px !important;
    padding: 0 !important;
    margin: 0 !important;
    background: transparent !important;
    color: #fff !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
    position: relative !important;
  }
  body:not(.task-login) #outlook-mobile-menu,
  body.task-mail #outlook-mobile-folders,
  body.task-mail #outlook-mobile-search { display: inline-flex !important; }
  body:not(.task-login) #outlook-mobile-back { display: none !important; }
  body.outlook-inline-compose-active #outlook-mobile-menu { display: none !important; }
  body.outlook-inline-compose-active #outlook-mobile-back { display: inline-flex !important; }
  body.outlook-inline-compose-active #outlook-mobile-folders,
  body.outlook-inline-compose-active #outlook-mobile-search,
  body.outlook-inline-compose-active #outlook-suitebar .outlook-top-action.compose { display: none !important; }
  body:not(.task-login) .outlook-mobile-control:hover,
  body:not(.task-login) .outlook-mobile-control:focus-visible,
  body:not(.task-login) .outlook-mobile-control[aria-expanded="true"] {
    background: rgba(255,255,255,.20) !important;
    outline-offset: 2px !important;
  }
  body:not(.task-login) .outlook-mobile-control::before {
    content: "" !important;
    display: block !important;
    width: 21px !important;
    height: 21px !important;
    background: currentColor !important;
    -webkit-mask: var(--mzuni-mobile-control-icon) center / contain no-repeat !important;
    mask: var(--mzuni-mobile-control-icon) center / contain no-repeat !important;
  }
  #outlook-mobile-menu { --mzuni-mobile-control-icon: var(--mzuni-mobile-menu-icon); }
  #outlook-mobile-back { --mzuni-mobile-control-icon: var(--mzuni-mobile-back-icon); }
  #outlook-mobile-folders { --mzuni-mobile-control-icon: var(--mzuni-mobile-folders-icon); }
  #outlook-mobile-search { --mzuni-mobile-control-icon: var(--mzuni-mobile-search-icon); }

  /* Mobile search expands into a second header row only when requested. */
  body:not(.task-login) #outlook-suitebar #outlook-search-slot {
    display: none !important;
    position: absolute !important;
    top: var(--outlook-suitebar-height) !important;
    left: 0 !important;
    right: 0 !important;
    height: 52px !important;
    min-width: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 7px 12px !important;
    background: #fff !important;
    border-radius: 0 !important;
    border-bottom: 1px solid #dce5dc !important;
    box-shadow: 0 3px 8px rgba(0,0,0,.08) !important;
    z-index: 1150 !important;
  }
  body.outlook-search-open #outlook-suitebar #outlook-search-slot { display: flex !important; }
  body.outlook-search-open:not(.task-login) #layout { padding-top: calc(var(--outlook-suitebar-height) + 52px) !important; }
  body.outlook-search-open #outlook-search-slot .searchbar,
  body.outlook-search-open #outlook-search-slot input { width: 100% !important; min-width: 0 !important; }

  /* Native Roundcube menu becomes an accessible side drawer, not a bottom rail. */
  body:not(.task-login) #layout-menu {
    display: none !important;
    position: fixed !important;
    top: var(--outlook-suitebar-height) !important;
    bottom: 0 !important;
    left: 0 !important;
    right: auto !important;
    height: calc(100dvh - var(--outlook-suitebar-height)) !important;
    width: min(292px, calc(100vw - 48px)) !important;
    max-width: min(292px, calc(100vw - 48px)) !important;
    min-width: 0 !important;
    flex: none !important;
    z-index: 1250 !important;
    border: 0 !important;
    border-radius: 0 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    box-shadow: 8px 0 30px rgba(0,0,0,.28) !important;
  }
  body:not(.task-login) #layout-menu.outlook-mobile-open { display: block !important; }
  body:not(.task-login) #layout-menu.outlook-mobile-open .popover-header {
    display: flex !important;
    height: 64px !important;
    min-height: 64px !important;
    padding: 8px 14px !important;
    align-items: center !important;
    justify-content: space-between !important;
    background: #08492b !important;
    color: #fff !important;
  }
  body:not(.task-login) #layout-menu .popover-header #logo {
    width: 52px !important;
    max-width: 52px !important;
    max-height: 48px !important;
    object-fit: contain !important;
  }
  body:not(.task-login) #layout-menu .popover-header a.cancel {
    display: inline-flex !important;
    width: 40px !important;
    height: 40px !important;
    justify-content: center !important;
    align-items: center !important;
    flex: 0 0 40px !important;
    color: #fff !important;
  }
  body:not(.task-login) #layout-menu .popover-header a.cancel::before {
    content: "" !important;
    display: block !important;
    width: 20px !important;
    height: 20px !important;
    background: currentColor !important;
    -webkit-mask: var(--mzuni-mobile-close-icon) center / contain no-repeat !important;
    mask: var(--mzuni-mobile-close-icon) center / contain no-repeat !important;
  }
  body:not(.task-login) #layout-menu .popover-header a.cancel .inner { display: none !important; }
  body:not(.task-login) #taskmenu {
    width: 100% !important;
    height: auto !important;
    min-height: calc(100% - 64px) !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    justify-content: flex-start !important;
    gap: 4px !important;
    padding: 14px 10px !important;
    background: #064f2b !important;
  }
  body:not(.task-login) #taskmenu .action-buttons {
    display: block !important;
    width: 100% !important;
    margin: 0 0 12px !important;
  }
  body:not(.task-login) #taskmenu a,
  body:not(.task-login) #taskmenu .button,
  body:not(.task-login) #taskmenu span.action-buttons a {
    display: flex !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    height: 48px !important;
    min-height: 48px !important;
    padding: 0 16px !important;
    margin: 0 !important;
    justify-content: flex-start !important;
    gap: 14px !important;
    border-radius: 9px !important;
  }
  body:not(.task-login) #taskmenu a .inner,
  body:not(.task-login) #taskmenu .button .inner {
    display: inline !important;
    position: static !important;
    width: auto !important;
    height: auto !important;
    min-width: 0 !important;
    padding: 0 !important;
    transform: none !important;
    opacity: 1 !important;
    clip: auto !important;
    clip-path: none !important;
    overflow: visible !important;
    pointer-events: auto !important;
    background: transparent !important;
    color: #fff !important;
    font-size: 15px !important;
    font-weight: 600 !important;
    line-height: 1.3 !important;
  }
  #outlook-mobile-backdrop {
    position: fixed !important;
    inset: var(--outlook-suitebar-height) 0 0 0 !important;
    background: rgba(15,30,19,.48) !important;
    z-index: 1200 !important;
  }

  /* Let Roundcube switch between folders, message list and reading pane using
     its own .hidden class. Remove v10 desktop widths that blocked this. */
  body:not(.task-login) #layout > #layout-sidebar,
  body:not(.task-login) #layout > #layout-list,
  body:not(.task-login) #layout > #layout-content {
    position: relative !important;
    flex: 1 1 auto !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    height: 100% !important;
    overflow: hidden !important;
    border-left: 0 !important;
    border-right: 0 !important;
  }
  body:not(.task-login) #layout > .hidden { display: none !important; }
  body:not(.task-login) #layout > .listbox:not(.hidden),
  body:not(.task-login) #layout > #layout-content:not(.hidden) { min-width: 0 !important; }
  body:not(.task-login) #layout > div > .header {
    min-height: 48px !important;
    height: 48px !important;
    width: 100% !important;
    padding: 0 10px !important;
    align-items: center !important;
    overflow: hidden !important;
  }
  body:not(.task-login) #layout > div > .header .header-title { min-width: 0 !important; overflow: hidden !important; text-overflow: ellipsis !important; }
  /* The top-left menu and folder controls replace these native duplicates. */
  body:not(.task-login) #layout > div > .header a.task-menu-button,
  body.task-mail #layout-list > .header a.back-sidebar-button { display: none !important; }
  body.task-mail #layout-list > .header .header-title { flex: 1 1 auto !important; font-weight: 700 !important; }

  body:not(.task-login) #layout > div > .scroller,
  body:not(.task-login) #layout > div > .iframe-wrapper { min-width: 0 !important; }
  body:not(.task-login) #layout-list .toolbar.menu,
  body:not(.task-login) #mailtoolbar.toolbar.menu,
  body:not(.task-login) #messagetoolbar.toolbar.menu {
    min-width: 0 !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    scrollbar-width: thin !important;
  }
  body:not(.task-login) #layout-list .toolbar.menu.popupmenu { display: none !important; }
  body:not(.task-login) #layout-content > .header > .button.back-list-button { min-width: 40px !important; padding: 0 6px !important; }
  body:not(.task-login) #mailtoolbar.toolbar.menu a,
  body:not(.task-login) #messagetoolbar.toolbar.menu a { flex: 0 0 auto !important; }
  body:not(.task-login) #layout-list .outlook-list-summary { display: none !important; }

  /* Profile opens under the avatar, within the viewport; logout remains the
     final action at the bottom of the card, never in the mobile header. */
  body:not(.task-login) #outlook-suitebar .outlook-profile-card {
    position: fixed !important;
    top: calc(var(--outlook-suitebar-height) + 7px) !important;
    left: 10px !important;
    right: 10px !important;
    width: auto !important;
    max-width: none !important;
    max-height: calc(100dvh - var(--outlook-suitebar-height) - 16px) !important;
    overflow-y: auto !important;
    border-radius: 14px !important;
  }
  body:not(.task-login) .outlook-profile-card-brand { padding: 14px 16px !important; }
  body:not(.task-login) .outlook-profile-link,
  body:not(.task-login) .outlook-profile-logout { min-height: 46px !important; }

  /* Preserve v22's inline Compose iframe; show it as the sole pane on mobile. */
  body.outlook-inline-compose-active #layout > #layout-sidebar,
  body.outlook-inline-compose-active #layout > #layout-list { display: none !important; }
  body.outlook-inline-compose-active #layout > #layout-content {
    display: flex !important;
    width: 100% !important;
    flex: 1 1 auto !important;
    min-width: 0 !important;
  }
  body.outlook-inline-compose-active #layout-content > .header { display: none !important; }
  body.outlook-inline-compose-active #layout-content #outlook-inline-compose {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    border: 0 !important;
    display: flex !important;
  }
  body.outlook-inline-compose-active #layout-content #outlook-inline-compose iframe {
    width: 100% !important;
    height: 100% !important;
    min-width: 0 !important;
  }
  html.iframe body.action-compose #compose-content,
  html.outlook-framed-compose-clean body.action-compose #compose-content {
    padding: 12px 10px !important;
    min-width: 0 !important;
  }
  body.task-addressbook #layout-list,
  body.task-settings #layout-list { min-width: 0 !important; }
}

@media screen and (max-width: 370px) {
  body:not(.task-login) #outlook-suitebar .outlook-brand-title { display: none !important; }
  body:not(.task-login) #outlook-suitebar .outlook-suite-actions { gap: 1px !important; }
  body:not(.task-login) #outlook-suitebar .outlook-brand { gap: 0 !important; }
  body:not(.task-login) #outlook-mobile-menu,
  body:not(.task-login) #outlook-mobile-folders,
  body:not(.task-login) #outlook-mobile-search { width: 36px !important; min-width: 36px !important; flex-basis: 36px !important; }
}

/* Dark mode: keep text and icons legible in the drawer and profile card. */
html.dark-mode #outlook-mobile-backdrop { background: rgba(0,0,0,.62) !important; }
html.dark-mode #outlook-suitebar .outlook-profile-card { background: #171d17 !important; color: #f3f7f1 !important; }
html.dark-mode #outlook-suitebar .outlook-profile-link { color: #f3f7f1 !important; }
html.dark-mode #outlook-suitebar .outlook-profile-logout { color: #ffb1a6 !important; }

/* Profile links use explicit standard icons, including Mail and Sign out. */
body:not(.task-login) .outlook-profile-link.mail::before {
  --fluent-icon: var(--fluent-mail) !important;
  content: "" !important;
  width: 19px !important;
  height: 19px !important;
  display: inline-block !important;
  flex: 0 0 19px !important;
  background: currentColor !important;
  -webkit-mask: var(--fluent-mail) center / contain no-repeat !important;
  mask: var(--fluent-mail) center / contain no-repeat !important;
}

/* The original folder title is the username. Replace visually with one
   "Folders" label rather than appending "Folders" to the email address. */
body.task-mail #layout-sidebar > .header .header-title.username {
  font-size: 0 !important;
}
body.task-mail #layout-sidebar > .header .header-title.username::before {
  content: "Folders" !important;
  font-size: 15px !important;
  font-weight: 700 !important;
  line-height: 48px !important;
}

/* Do not render inherited placeholder glyphs as separate rows beside the
   built-in Archive/Junk folders (their link already supplies the icon). */
#mailboxlist li.mailbox.archive::before,
#mailboxlist li.mailbox.junk::before { content: none !important; display: none !important; }

/* v25.1: Inbox/mail icon stability hotfix.
   Use a self-contained standard envelope glyph rather than relying on an
   optional --fluent-mail variable, which may be undefined on navigation.
   Scope to the task rail only; leave the working href and Roundcube handlers. */
body:not(.task-login) #taskmenu a.mail::before,
body:not(.task-login) #taskmenu a.mail.selected::before,
body:not(.task-login) #taskmenu a.mail.active::before,
body:not(.task-login) #taskmenu a.mail:hover::before,
body:not(.task-login) #taskmenu a.mail:focus-visible::before {
  --fluent-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='5' width='18' height='14' rx='2'/%3E%3Cpath d='m3 7 9 6 9-6'/%3E%3C/svg%3E") !important;
  content: '' !important;
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  width: 21px !important;
  min-width: 21px !important;
  height: 21px !important;
  min-height: 21px !important;
  flex: 0 0 21px !important;
  background: currentColor !important;
  -webkit-mask: var(--fluent-icon) center / contain no-repeat !important;
  mask: var(--fluent-icon) center / contain no-repeat !important;
  transform: none !important;
}
/* Ensure selected navigation never becomes white-on-white or transparent. */
body:not(.task-login) #taskmenu a.mail.selected,
body:not(.task-login) #taskmenu a.mail.active,
body:not(.task-login) #taskmenu a.mail[aria-current='page'] {
  color: #ffffff !important;
}
/* Preserve folder-row Inbox glyph after folder selection and redraw. */
body.task-mail #mailboxlist li.mailbox.inbox > a,
body.task-mail #mailboxlist li.mailbox.inbox.selected > a,
body.task-mail #mailboxlist li.mailbox.inbox.active > a {
  position: relative;
}
body.task-mail #mailboxlist li.mailbox.inbox > a::before,
body.task-mail #mailboxlist li.mailbox.inbox.selected > a::before,
body.task-mail #mailboxlist li.mailbox.inbox.active > a::before {
  visibility: visible !important;
  opacity: 1 !important;
}
