/* ═══════════════════════════════════════════════════════════════
   PortalDialog – Persistent tabbed modal dialog for Portal UI
   
   Built on Bootstrap 3 modal. Matches existing portal styling
   from Screen.css with full-height layout and tab support.
   ═══════════════════════════════════════════════════════════════ */

/* ── Faster transition (100ms) ── */

.portal-dialog.modal.fade .portal-dialog-container {
  transition: transform 0.1s ease-out;
}

.portal-dialog.modal.fade {
  transition: opacity 0.1s linear;
}

/* ── Dialog container: full-height by default ── */

.portal-dialog .portal-dialog-container {
  height: calc(100vh - 10px);
  display: flex;
  flex-direction: column;
}

  .portal-dialog .portal-dialog-container.portal-dialog-fullscreen {
    width: 99%;
    margin: 5px auto;
  }

@media (max-width: 768px) {
  .portal-dialog .portal-dialog-container.portal-dialog-fullscreen {
    width: 100%;
    margin: 0;
    height: 100vh;
  }

  .portal-dialog .portal-dialog-container {
    margin: 4px auto;
  }
}

/* ── Modal content: flex column ── */

.portal-dialog .modal-content {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* ── GetWindowDialog compat marker ── */
/* v9: Must be jQuery :visible (offsetWidth > 0) when the modal is shown,
   so GetWindowDialog(parentWindow) detects it and pages get .standalonepage.
   1×1px absolutely positioned, invisible to users but has positive dimensions.
   When the modal is hidden (Bootstrap sets display:none on .modal),
   offsetWidth naturally becomes 0 → :visible returns false → correct. */
.portal-dialog-compat-marker {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  opacity: 0;
  pointer-events: none;
}

/* ── Header with tabs ── */

.portal-dialog-header.modal-header {
  display: flex;
  align-items: stretch;
  padding: 0;
  min-height: 40px;
  flex-shrink: 0;
  border-bottom: 1px solid #ddd;
  position: relative;
  z-index: 10; /* v11: above body so tab dropdown floats over iframe */
}

  /* v14: Kill Bootstrap 3 clearfix pseudo-elements (display:table) –
     they become invisible flex items and shift the layout by a few pixels. */
  .portal-dialog-header.modal-header::before,
  .portal-dialog-header.modal-header::after {
    display: none;
  }

/* Tab scroll wrapper (MobileNav pattern) */
.portal-dialog-scroll-wrapper {
  flex: 1 1 auto;
  position: relative;
  min-width: 0;
  overflow: hidden;
}

/* Scroll container (nav element) – flow child that determines wrapper height */
.portal-dialog-tabs-nav {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  /* Hide scrollbar */
  -ms-overflow-style: none;
  scrollbar-width: none;
}

  .portal-dialog-tabs-nav::-webkit-scrollbar {
    display: none;
  }

/* Tab list inside scroll container */
.portal-dialog-tabs {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: nowrap;
}

/* Scroll arrow buttons – overlay on top of nav */
.portal-dialog-scroll-btn {
  display: none; /* JS sets display:block when needed */
  position: absolute;
  top: 0;
  bottom: 0;
  width: 36px;
  border: none;
  color: #555;
  font-size: 20px;
  cursor: pointer;
  z-index: 10;
  padding: 0;
}

  .portal-dialog-scroll-btn.left {
    left: 0;
    background: linear-gradient(to right, #fff 30%, rgba(255, 255, 255, 0.9) 60%, rgba(255, 255, 255, 0));
  }

  .portal-dialog-scroll-btn.right {
    right: 0;
    background: linear-gradient(to left, #fff 30%, rgba(255, 255, 255, 0.9) 60%, rgba(255, 255, 255, 0));
  }

  .portal-dialog-scroll-btn:hover {
    color: #111;
  }

  .portal-dialog-scroll-btn:disabled {
    opacity: 0.25;
    cursor: default;
  }

.portal-dialog-tab {
  flex-shrink: 0;
}

  .portal-dialog-tab > a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    white-space: nowrap;
    text-decoration: none;
    color: #666;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
  }

    .portal-dialog-tab > a:hover,
    .portal-dialog-tab > a:focus {
      color: #333;
      border-bottom-color: #ccc;
      background-color: rgba(0, 0, 0, 0.02);
      text-decoration: none;
    }

  .portal-dialog-tab.active > a,
  .portal-dialog-tab.active > a:hover,
  .portal-dialog-tab.active > a:focus {
    color: #333;
    font-weight: 600;
    border-bottom-color: #337ab7;
    background-color: transparent;
  }

/* Tab title (with ellipsis for overflow as safety net) */
.portal-dialog-tab-title {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Tab close button (×) – hidden on pinned tabs (handled by JS) */
.portal-dialog-tab-close {
  font-size: 15px;
  line-height: 1;
  color: #666;
  opacity: 0.5;
  cursor: pointer;
  padding: 0 2px;
  font-weight: normal;
}

  .portal-dialog-tab-close:hover {
    opacity: 1;
    color: #c00;
  }

/* Header action buttons – unified size/color with tab icons */
.portal-dialog-actions {
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 10px;
  flex-shrink: 0;
  border-left: 1px solid #eee;
}

  .portal-dialog-actions .close {
    float: none;
    margin: 0;
    font-size: 15px;
    color: #666;
    opacity: 0.5;
    text-shadow: none;
  }

    .portal-dialog-actions .close:hover {
      opacity: 1;
      color: #333;
    }

/* ── Body: fills remaining vertical space ── */

.portal-dialog-body.modal-body {
  flex: 1 1 auto;
  padding: 0;
  overflow: hidden;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1; /* v11: below header so tab dropdown is not covered by iframe */
  /* Override Screen.css .modal-body */
  overflow-y: hidden;
  -webkit-overflow-scrolling: auto;
  overflow-scrolling: auto;
}

/* Tab panes */
.portal-dialog-pane {
  display: none;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

  .portal-dialog-pane.active {
    display: flex;
  }

/* Iframe fills pane */
.portal-dialog-iframe {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  border: none;
  margin: 0;
  padding: 0;
  outline: 0;
}

/* HTML content in pane */
.portal-dialog-pane > :not(iframe):not(.portal-dialog-iframe):not(.portal-dialog-loading) {
  overflow-y: auto;
  flex: 1 1 auto;
}

/* ── Loading overlay ── */

.portal-dialog-loading {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.85);
  color: #999;
}

/* ── Footer ── */

.portal-dialog-footer.modal-footer {
  flex-shrink: 0;
  padding: 6px 15px;
}

/* ── v11: Minimize button ── */

.portal-dialog-actions > .portal-dialog-btn-minimize {
  font-size: 12px;
}

.portal-dialog-btn-minimize {
  /* size inherited from .portal-dialog-actions .close (15px) */
}

/* ── v11: Floating badge (minimized indicator) ── */

.portal-dialog-badge {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 1040; /* below modal (1050) but above everything else */
  background: #337ab7;
  color: #fff;
  border: none;
  border-radius: 24px;
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background-color 0.15s, transform 0.15s;
  user-select: none;
}

  .portal-dialog-badge:hover {
    background: #286090;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  }

  .portal-dialog-badge i {
    font-size: 16px;
  }

.portal-dialog-badge-count {
  font-weight: 600;
  min-width: 12px;
  text-align: center;
}

/* ── v11: Tab actions (× close + ▾ dropdown) ── */

.portal-dialog-tab-actions {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-left: 4px;
}

/* Dropdown wrapper – relative for menu positioning */
.portal-dialog-tab-dropdown {
  position: relative;
  display: inline-block;
}

.portal-dialog-tab-dropdown-toggle {
  font-size: 12px;
  color: #666;
  opacity: 0.5;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
}

  .portal-dialog-tab-dropdown-toggle:hover {
    opacity: 1;
    color: #333;
  }

/* Dropdown menu – fixed position to escape scroll container overflow */
.portal-dialog-tab-menu.dropdown-menu {
  display: none;
  position: fixed;
  min-width: 180px;
  z-index: 1060;
  margin: 0;
  font-size: 13px;
}

.portal-dialog-tab-dropdown.open .portal-dialog-tab-menu.dropdown-menu {
  display: block;
}

.portal-dialog-tab-menu > li.disabled > a {
  color: #aaa;
  cursor: default;
}

  .portal-dialog-tab-menu > li.disabled > a:hover {
    background: transparent;
    color: #aaa;
  }
