/**
 * XFactorAI Layout
 * Page structure, grid, main sections
 */

/* ========================================
   APP SHELL
   ======================================== */

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
  max-width: 100vw;
  overflow: hidden;
}

/* ========================================
   HEADER - Clean Modern Design
   ======================================== */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 16px;
  background: #ffffff;
  border-bottom: 1px solid #e8e8e8;
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
}

/* Left section - Brand (width tracks sidebar so tabs align with divider)
   Subtract header padding (16px) so right edge sits on the sidebar border */
.header__left {
  display: flex;
  align-items: center;
  width: calc(var(--sidebar-width, 260px) - 16px);
  min-width: 140px;
  gap: 16px;
  flex-shrink: 0;
  transition: width 0.05s ease;
}

.header__brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header__help {
  display: flex;
  align-items: center;
}

.header__logo {
  font-size: 20px;
}

.header__title {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-primary, #2563EB);
  letter-spacing: -0.01em;
}

/* Center section - Tabs aligned to sidebar divider.
   padding-left matches icon-bar's 8px so pills align with Compose button */
.header__center {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex: 1;
  min-width: 0;
  overflow: visible;
  padding-left: 8px;
}

/* Mode Toggle - now in icon-bar */
.header__mode-toggle {
  display: flex;
  align-items: center;
  background: var(--color-background-alt);
  border-radius: 6px;
  padding: 2px;
  position: relative;
  margin-right: 8px;
}

.header__mode-btn {
  position: relative;
  padding: 4px 12px;
  border: none;
  background: transparent;
  font-size: 12px;
  font-weight: 500;
  color: var(--email-text-secondary, #666);
  border-radius: 4px;
  cursor: pointer;
  transition: color 0.2s ease;
  z-index: 1;
}

.header__mode-btn:hover {
  color: var(--email-text, #333);
}

.header__mode-btn--active {
  color: #fff;
}

.header__mode-indicator {
  position: absolute;
  top: 2px;
  left: 2px;
  height: calc(100% - 4px);
  width: calc(50% - 2px);
  background: linear-gradient(135deg, #2563EB 0%, #3B82F6 100%);
  border-radius: 4px;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 4px rgba(37, 99, 235, 0.3);
}

.header__mode-toggle:has(.header__mode-btn[data-mode="auto"].header__mode-btn--active) .header__mode-indicator {
  transform: translateX(100%);
}

/* Right section - Actions */
.header__right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  min-width: 200px;
}

/* My Context Button */
.header__context-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.header__context-btn:hover {
  background: #f5f5f5;
}

.header__context-icon {
  font-size: 14px;
}

.header__context-label {
  font-size: 13px;
  font-weight: 500;
  color: #444;
}

/* EODR Button */
.header__eodr-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.header__eodr-btn:hover {
  background: rgb(248, 248, 248);
}

.header__eodr-icon {
  font-size: 14px;
}

.header__eodr-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--email-text);
}

.header__eodr-caret {
  font-size: 10px;
  color: #666;
  transition: transform 0.2s ease;
}

/* Daily Report Dropdown */
.header__daily-report-dropdown {
  position: relative;
}

.header__daily-report-dropdown.is-open .header__eodr-caret {
  transform: rotate(180deg);
}

.header__daily-report-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 200px;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  padding: 4px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-8px);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
  z-index: 1000;
}

.header__daily-report-dropdown.is-open .header__daily-report-menu {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
}

.header__daily-report-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease;
}

.header__daily-report-item:hover {
  background: #f3f4f6;
}

.header__daily-report-item-icon {
  font-size: 16px;
}

.header__daily-report-item-label {
  font-size: 13px;
  font-weight: 500;
  color: #374151;
}

/* Header icon button (settings, etc.) */
.header__icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
  transition: background 0.15s ease;
}

.header__icon-btn:hover {
  background: #f5f5f5;
}

/* Header actions container */
.header__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* User Menu */
.user-menu {
  position: relative;
}

.user-menu__trigger {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 50%;
}

.user-menu__trigger:hover .user-menu__avatar {
  box-shadow: 0 0 0 2px #e8e8e8;
}

.user-menu__avatar {
  width: 32px;
  height: 32px;
  min-width: 32px;
  min-height: 32px;
  background: linear-gradient(135deg, #2563EB 0%, #3B82F6 100%);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  transition: box-shadow 0.15s ease;
  overflow: hidden;
  text-overflow: clip;
  white-space: nowrap;
}

.user-menu__avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.user-menu__name {
  display: none;
}

/* User Menu Dropdown */
.user-menu__dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 280px;
  background: #fff;
  border: 1px solid #e8e8e8;
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: all 0.15s ease;
  z-index: 1000;
  overflow: hidden;
}

.user-menu__dropdown--visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* Connection status dot */
.user-menu__connection-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 10px;
  height: 10px;
  background: #22c55e;
  border: 2px solid #fff;
  border-radius: 50%;
}

/* Sections */
.user-menu__section {
  padding: 12px;
  border-bottom: 1px solid #f0f0f0;
}

.user-menu__section:last-of-type {
  border-bottom: none;
}

.user-menu__section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: #888;
  margin-bottom: 10px;
  letter-spacing: 0.5px;
}

/* Account info */
.user-menu__account-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-menu__account-avatar {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #2563EB 0%, #3B82F6 100%);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  flex-shrink: 0;
}

.user-menu__account-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.user-menu__account-details {
  flex: 1;
  min-width: 0;
}

.user-menu__account-name {
  font-size: 14px;
  font-weight: 600;
  color: #333;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-menu__account-email {
  font-size: 12px;
  color: #666;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Email integration section */
.user-menu__email-empty {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  color: #888;
  font-size: 13px;
}

.user-menu__email-empty-icon {
  font-size: 10px;
}

/* Email provider card */
.user-menu__email-provider {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px;
  border-radius: 8px;
  margin-bottom: 6px;
  background: #f8f9fa;
  transition: background 0.1s;
}

.user-menu__email-provider:last-of-type {
  margin-bottom: 0;
}

.user-menu__email-provider--active {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
}

.user-menu__email-provider-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.user-menu__email-provider-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.user-menu__email-provider-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-menu__email-provider-avatar--icon {
  font-size: 14px;
  color: #fff;
}

.user-menu__email-provider-details {
  flex: 1;
  min-width: 0;
}

.user-menu__email-provider-name {
  font-size: 13px;
  font-weight: 500;
  color: #333;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-menu__email-provider-email {
  font-size: 11px;
  color: #666;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-menu__email-provider-actions {
  display: flex;
  gap: 4px;
}

.user-menu__provider-btn {
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.6;
  transition: all 0.1s;
}

.user-menu__provider-btn:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.05);
}

.user-menu__provider-btn--disconnect:hover {
  background: #fef2f2;
  color: #dc2626;
}

/* Dropdown divider */
.user-menu__dropdown-divider {
  height: 1px;
  background: #f0f0f0;
  margin: 0;
}

/* Dropdown items */
.user-menu__dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  background: transparent;
  font-size: 13px;
  color: #333;
  cursor: pointer;
  transition: background 0.1s ease;
  text-align: left;
}

.user-menu__dropdown-item:hover {
  background: #f5f5f5;
}

.user-menu__dropdown-item--primary {
  color: #2563EB;
  font-weight: 500;
}

.user-menu__dropdown-item--primary:hover {
  background: #fff7ed;
}

.user-menu__dropdown-item--secondary {
  color: #666;
  font-size: 12px;
}

.user-menu__dropdown-item--danger {
  color: #dc2626;
}

.user-menu__dropdown-item--danger:hover {
  background: #fef2f2;
}

/* Legacy support for old nav button class */
.header__nav-btn[aria-pressed="true"],
.header__nav-btn.is-active {
  background: var(--gradient-primary);
  color: white;
}

/* ========================================
   MAIN LAYOUT
   ======================================== */

.main {
  display: flex;
  flex: 1;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: var(--space-6);
  gap: var(--space-8);
}

/* ========================================
   SIDEBAR - Floating Card Style
   ======================================== */

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  padding: var(--space-4);
  box-shadow: var(--shadow-card);
  border: 1px solid rgba(255, 255, 255, 0.8);
  height: fit-content;
  position: sticky;
  top: calc(var(--header-height) + var(--space-6));
}

.sidebar__footer {
  margin-top: auto;
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
}

/* ========================================
   CONTENT AREA
   ======================================== */

.content {
  flex: 1;
  min-width: 0; /* Prevent flex overflow */
  max-width: var(--max-content-width);
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

/* ========================================
   SECTIONS - Premium Cards
   ======================================== */

.input-section,
.output-section,
.trust-layer,
.original-section-container {
  background: var(--gradient-surface);
  border-radius: var(--radius-2xl);
  border: 1px solid rgba(255, 255, 255, 0.8);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  transition: box-shadow var(--transition-base);
}

.input-section:hover,
.output-section:hover,
.original-section-container:hover {
  box-shadow: var(--shadow-card-hover);
}

/* Input Section */
.input-section {
  padding: var(--space-6);
}

/* Original Section Container */
.original-section-container {
  padding: var(--space-6);
}

/* Output Section */
.output-section {
  display: flex;
  flex-direction: column;
}

.output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface-secondary);
}

.output-header__title {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
}

.output-header__actions {
  display: flex;
  gap: var(--space-2);
}

.output-content {
  padding: var(--space-6);
  flex: 1;
}

/* ========================================
   STATUS BAR
   ======================================== */

.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--status-bar-height);
  padding: 0 var(--space-6);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

.status-bar__text {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.status-bar__version {
  font-size: var(--font-size-xs);
  font-family: var(--font-family-mono);
}

/* ========================================
   TOAST CONTAINER
   ======================================== */

.toasts {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  pointer-events: none;
}

.toasts > * {
  pointer-events: auto;
}

/* ========================================
   RESPONSIVE
   ======================================== */

@media (max-width: 1024px) {
  /* Only apply column layout to non-email main containers */
  .main:not(.main--email) {
    flex-direction: column;
  }
  
  .sidebar {
    width: 100%;
  }
  
  .content {
    max-width: 100%;
  }
  
  .header__context-label,
  .header__eodr-label,
  .header__eodr-caret {
    display: none;
  }
}

@media (max-width: 768px) {
  .header {
    padding: 0 12px;
  }
  
  .header__left {
    gap: 8px;
    min-width: auto;
  }
  
  .header__right {
    min-width: auto;
    gap: 8px;
  }
  
  .header__mode-btn {
    padding: 6px 10px;
    font-size: 12px;
  }
}

@media (max-width: 640px) {
  .main {
    padding: var(--space-4);
    gap: var(--space-4);
  }
  
  .header {
    padding: 0 8px;
  }
  
  .header__title {
    display: none;
  }
  
  .header__left,
  .header__right {
    min-width: auto;
    gap: 4px;
  }
  
  .header__mode-btn {
    padding: 4px 8px;
    font-size: 11px;
  }
  
  .header__icon-btn {
    width: 28px;
    height: 28px;
    font-size: 14px;
  }
  
  .header__help-btn,
  .tour-help-btn {
    width: 24px;
    height: 24px;
    font-size: 12px;
  }
  
  .input-section,
  .output-content,
  .trust-layer__plan {
    padding: var(--space-4);
  }
}
