/**
 * QuickSuite Layout CSS (Enterprise Precision Sizing & Zero Glitch Fit)
 * Exact flexbox calculations, zero double-scrollbars, responsive viewport.
 */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100vh;
  width: 100vw;
  font-family: var(--p-font-family);
  font-size: var(--p-font-size-md);
  color: var(--p-color-text);
  background-color: var(--p-color-bg-app);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Custom Sleek Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.16);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.28);
}

/* ==========================================================================
   TOP HORIZONTAL BAR (Shopify Admin Header Style)
   ========================================================================== */
.qs-topbar {
  height: var(--p-topbar-height);
  min-height: var(--p-topbar-height);
  background-color: var(--p-color-bg-topbar);
  color: var(--p-color-text-inverse);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--p-space-4);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  position: relative;
  z-index: 1000;
  user-select: none;
  flex-shrink: 0;
}

.qs-topbar-left {
  display: flex;
  align-items: center;
  gap: var(--p-space-3);
  min-width: 280px;
}

.qs-brand-link {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: #fff;
  padding: 4px 6px;
  border-radius: var(--p-border-radius-sm);
  transition: background var(--p-transition-fast);
}
.qs-brand-link:hover {
  background-color: var(--p-color-bg-topbar-surface);
}

.qs-brand-logo-icon {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: linear-gradient(135deg, #008060 0%, #004c3f 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  color: #ffffff;
}

.qs-brand-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: #ffffff;
  display: flex;
  align-items: center;
  gap: 6px;
}
.qs-brand-subtitle {
  font-size: 10px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.15);
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #d2f0db;
}

.qs-workspace-separator {
  width: 1px;
  height: 20px;
  background-color: rgba(255, 255, 255, 0.12);
}

/* Tenant / Workspace Selector */
.qs-workspace-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--p-color-bg-topbar-surface);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #e3e5e8;
  padding: 5px 10px;
  border-radius: var(--p-border-radius-md);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--p-transition-fast);
}
.qs-workspace-picker:hover {
  background: var(--p-color-bg-topbar-hover);
  border-color: rgba(255, 255, 255, 0.2);
  color: #ffffff;
}
.qs-workspace-avatar {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  background: #008060;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Global Center Search */
.qs-topbar-center {
  flex: 1;
  max-width: 500px;
  padding: 0 var(--p-space-4);
}

.qs-search-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--p-color-bg-topbar-surface);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #8c9196;
  height: 34px;
  padding: 0 12px;
  border-radius: var(--p-border-radius-md);
  font-size: 13px;
  cursor: pointer;
  transition: all var(--p-transition-fast);
}
.qs-search-trigger:hover {
  background: var(--p-color-bg-topbar-hover);
  border-color: rgba(255, 255, 255, 0.22);
  color: #e3e5e8;
}
.qs-search-left {
  display: flex;
  align-items: center;
  gap: 8px;
}
.qs-kbd-shortcut {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 11px;
  font-family: var(--p-font-family-mono);
  color: #a6acb2;
}

/* Topbar Right Tools */
.qs-topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.qs-topbar-btn {
  background: transparent;
  border: none;
  color: #c9cccf;
  width: 34px;
  height: 34px;
  border-radius: var(--p-border-radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: all var(--p-transition-fast);
}
.qs-topbar-btn:hover {
  background: var(--p-color-bg-topbar-surface);
  color: #ffffff;
}

.qs-badge-dot {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 7px;
  height: 7px;
  background-color: #ef4444;
  border-radius: 50%;
  border: 1.5px solid var(--p-color-bg-topbar);
}

.qs-user-profile-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--p-color-bg-topbar-surface);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 3px 8px 3px 4px;
  border-radius: var(--p-border-radius-full);
  color: #ffffff;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all var(--p-transition-fast);
}
.qs-user-profile-btn:hover {
  background: var(--p-color-bg-topbar-hover);
  border-color: rgba(255, 255, 255, 0.25);
}
.qs-user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #303030;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 11px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

/* ==========================================================================
   WORKSPACE HORIZONTAL TABS BAR
   ========================================================================== */
.qs-tabs-bar {
  height: var(--p-tabsbar-height);
  min-height: var(--p-tabsbar-height);
  background-color: #ffffff;
  border-bottom: 1px solid var(--p-border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--p-space-4);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  position: relative;
  z-index: 900;
  flex-shrink: 0;
}

.qs-tabs-list {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  height: 100%;
}
.qs-tabs-list::-webkit-scrollbar {
  display: none;
}

.qs-tab {
  height: 32px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--p-color-text-subdued);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--p-border-radius-md);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  user-select: none;
}
.qs-tab:hover {
  background: var(--p-color-bg-surface-hover);
  color: var(--p-color-text);
}
.qs-tab.active {
  background: #ebebeb;
  color: #111827;
  font-weight: 600;
  border-color: var(--p-border-subtle);
}

.qs-tab-home.active {
  background: #f1f2f4;
  color: #1a1a1a;
}

.qs-tab-icon {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qs-tab-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  font-size: 14px;
  color: var(--p-color-text-subdued);
  transition: all var(--p-transition-fast);
  margin-left: 4px;
}
.qs-tab-close:hover {
  background: rgba(0, 0, 0, 0.08);
  color: var(--p-color-danger-solid);
}

.qs-tabs-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ==========================================================================
   VIEWPORT & MAIN MODES
   ========================================================================== */
.qs-viewport {
  flex: 1;
  height: calc(100vh - var(--p-topbar-height) - var(--p-tabsbar-height));
  width: 100%;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* Mode 1: Hub / Launchpad */
.qs-hub-mode {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  background-color: var(--p-color-bg-app);
}

/* Mode 2: In-App Workspace */
.qs-app-workspace {
  width: 100%;
  height: 100%;
  display: flex;
  overflow: hidden;
}

/* Left Sidebar (In-App) */
.qs-app-sidebar {
  width: var(--p-sidebar-width);
  min-width: var(--p-sidebar-width);
  height: 100%;
  background-color: #ffffff;
  border-right: 1px solid var(--p-border-subtle);
  display: flex;
  flex-direction: column;
  user-select: none;
  overflow: hidden;
  flex-shrink: 0;
  z-index: 800;
}

.qs-sidebar-header {
  height: 56px;
  padding: 0 var(--p-space-4);
  border-bottom: 1px solid var(--p-border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.qs-sidebar-app-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.qs-sidebar-app-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--p-border-radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}

.qs-sidebar-app-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--p-color-text);
  line-height: 1.2;
}

.qs-sidebar-app-version {
  font-size: 11px;
  color: var(--p-color-text-subdued);
  font-weight: 400;
}

.qs-sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--p-space-3) var(--p-space-2);
}

.qs-nav-group-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--p-color-text-subdued);
  padding: var(--p-space-3) var(--p-space-3) var(--p-space-1);
}

.qs-nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  margin: 2px 0;
  border-radius: var(--p-border-radius-md);
  font-size: 13px;
  font-weight: 500;
  color: var(--p-color-text);
  text-decoration: none;
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}
.qs-nav-item:hover {
  background-color: var(--p-color-bg-surface-hover);
  transform: translateX(2px);
}
.qs-nav-item.active {
  background-color: #ebebeb;
  color: #111827;
  font-weight: 600;
}

.qs-nav-item-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.qs-nav-icon {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--p-color-text-subdued);
  transition: color 0.15s ease;
}
.qs-nav-item.active .qs-nav-icon {
  color: var(--p-color-interactive-primary);
}

.qs-sidebar-footer {
  height: 48px;
  padding: 0 var(--p-space-4);
  border-top: 1px solid var(--p-border-subtle);
  background: var(--p-color-bg-subdued);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

/* App Main Viewport */
.qs-app-main {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-color: var(--p-color-bg-app);
  min-width: 0;
}

.qs-app-topbar {
  height: 48px;
  min-height: 48px;
  background: #ffffff;
  border-bottom: 1px solid var(--p-border-subtle);
  padding: 0 var(--p-space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.qs-app-breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--p-color-text-subdued);
}
.qs-app-breadcrumb a {
  color: var(--p-color-text-subdued);
  text-decoration: none;
}
.qs-app-breadcrumb a:hover {
  text-decoration: underline;
  color: var(--p-color-text);
}
.qs-app-breadcrumb-current {
  font-weight: 600;
  color: var(--p-color-text);
}

.qs-app-content-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--p-space-6);
  position: relative;
}

.qs-view-wrapper {
  max-width: 1280px;
  margin: 0 auto;
  width: 100%;
}

/* In-App Live Inbox Exact Fitting */
.qs-inbox-container {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.qs-inbox-shell {
  flex: 1;
  min-height: 560px;
  height: 100%;
  display: flex;
  background: #ffffff;
  border: 1px solid var(--p-border-subtle);
  border-radius: var(--p-border-radius-xl);
  overflow: hidden;
  box-shadow: var(--p-shadow-100);
}

.qs-inbox-threads {
  width: 320px;
  min-width: 300px;
  border-right: 1px solid var(--p-border-subtle);
  display: flex;
  flex-direction: column;
  height: 100%;
}

.qs-inbox-threads-header {
  height: 52px;
  padding: 0 16px;
  border-bottom: 1px solid var(--p-border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.qs-threads-list {
  flex: 1;
  overflow-y: auto;
}

.qs-thread-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--p-border-subtle);
  cursor: pointer;
  transition: background 0.15s ease;
}
.qs-thread-item:hover {
  background: var(--p-color-bg-surface-hover);
}
.qs-thread-item.active {
  background: #f1f2f4;
  border-left: 3px solid #008060;
}

.qs-thread-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #e1e3e5;
  color: #202223;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  position: relative;
  flex-shrink: 0;
}

.qs-thread-channel-badge {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  color: #ffffff;
}

.qs-thread-info {
  flex: 1;
  min-width: 0;
}
.qs-thread-top {
  display: flex;
  justify-content: space-between;
  margin-bottom: 2px;
}
.qs-thread-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--p-color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.qs-thread-time {
  font-size: 11px;
  color: var(--p-color-text-subdued);
}
.qs-thread-preview {
  font-size: 12px;
  color: var(--p-color-text-subdued);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.qs-inbox-conversation {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
}

.qs-convo-header {
  height: 56px;
  padding: 0 20px;
  border-bottom: 1px solid var(--p-border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #ffffff;
  flex-shrink: 0;
}

.qs-convo-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.qs-msg-bubble {
  max-width: 65%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.45;
  position: relative;
}
.qs-msg-bubble.inbound {
  align-self: flex-start;
  background: #ffffff;
  border: 1px solid var(--p-border-subtle);
  color: var(--p-color-text);
  border-bottom-left-radius: 2px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.qs-msg-bubble.outbound {
  align-self: flex-end;
  background: #008060;
  color: #ffffff;
  border-bottom-right-radius: 2px;
  box-shadow: 0 1px 3px rgba(0,128,96,0.25);
}
.qs-msg-time {
  font-size: 10px;
  opacity: 0.75;
  margin-top: 4px;
  text-align: right;
}

.qs-convo-input-box {
  height: 60px;
  padding: 0 20px;
  border-top: 1px solid var(--p-border-subtle);
  background: #ffffff;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.qs-convo-input {
  flex: 1;
  height: 38px;
  border: 1px solid var(--p-border-default);
  border-radius: var(--p-border-radius-md);
  padding: 0 14px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s ease;
}
.qs-convo-input:focus {
  border-color: #008060;
}

.qs-inbox-sidebar {
  width: 280px;
  min-width: 260px;
  border-left: 1px solid var(--p-border-subtle);
  padding: 20px;
  background: #fafbfb;
  overflow-y: auto;
  height: 100%;
}

/* Polaris Table Wrapper for responsive overflow */
.Polaris-Table-Wrapper {
  width: 100%;
  overflow-x: auto;
}
