/**
 * Page Header Workspace Switcher Styles
 * Workspace switcher positioned in top-right of main content area
 */

.page-header {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
  position: relative;
  padding-top: 2px;
}

.workspace-context-wrapper {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  z-index: var(--z-dropdown, 1000);
  pointer-events: auto;
}

.page-header-top-row {
  display: flex;
  /* Compact toolbar-style header row (like the reference image) */
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 0 12px;
  border-bottom: 1px solid rgba(var(--primary-rgb, 13, 148, 136), 0.12);
  margin-bottom: 0;
  width: 100%;
}

.page-header-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
  flex: 1;
  min-width: 260px;
}

/* NOTE: Old classes removed during cleanup:
   - .page-header-left, .page-header-right -> replaced by .page-header-content and .header-bar-card
   - .workspace-context -> replaced by .header-project-btn
   - .workspace-dropdown -> replaced by .header-dd
*/

/* -------------------------------------------------------------------------
   Header Bar Card (above page title/subtitle)
   ------------------------------------------------------------------------- */
.header-bar-card {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px;
  background: rgba(var(--primary-rgb, 13, 148, 136), 0.04);
  border: 1px solid rgba(var(--primary-rgb, 13, 148, 136), 0.10);
  border-radius: 14px;
  box-shadow: 0 6px 18px rgba(27, 28, 32, 0.06);
  width: fit-content;
  margin-left: auto; /* push to top-right */
  flex-shrink: 0;
  align-self: flex-start;
  /* Ensure proper spacing from right edge */
  margin-right: 0;
}

.header-bar-left,
.header-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-profile-btn,
.header-project-btn,
.header-settings-btn,
.header-create-btn {
  appearance: none;
  border: 1px solid rgba(var(--primary-rgb, 13, 148, 136), 0.14);
  background: rgba(255, 255, 255, 0.92);
  color: var(--text-primary, #1B1C20);
  border-radius: 12px;
  cursor: pointer;
  font-family: inherit;
  transition: box-shadow 0.2s, border-color 0.2s, transform 0.12s, background 0.2s;
}

.header-profile-btn:hover:not(:disabled),
.header-project-btn:hover:not(:disabled),
.header-settings-btn:hover:not(:disabled),
.header-create-btn:hover:not(:disabled) {
  border-color: rgba(var(--primary-rgb, 13, 148, 136), 0.28);
  box-shadow: 0 10px 22px rgba(27, 28, 32, 0.10);
  transform: translateY(-1px);
}

.header-profile-btn:active:not(:disabled),
.header-project-btn:active:not(:disabled),
.header-settings-btn:active:not(:disabled),
.header-create-btn:active:not(:disabled) {
  transform: translateY(0);
}

.header-profile-btn:focus-visible,
.header-project-btn:focus-visible,
.header-settings-btn:focus-visible,
.header-create-btn:focus-visible {
  outline: none;
  box-shadow:
    0 10px 22px rgba(27, 28, 32, 0.10),
    0 0 0 4px rgba(var(--primary-rgb, 13, 148, 136), 0.16);
}

.header-profile-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
}

.header-avatar {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--primary, #0D9488), var(--primary-light, #14B8A6));
  color: #FFFFFF;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.4px;
  flex-shrink: 0;
  box-shadow: 0 6px 18px rgba(var(--primary-rgb, 13, 148, 136), 0.25);
}

.header-project-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  min-width: 0;
  font-size: 13px;
  font-weight: 650;
}

.header-project-name {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-settings-btn {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.header-settings-btn.header-settings-disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: rgba(255, 255, 255, 0.5);
}

.header-settings-btn.header-settings-disabled:hover {
  transform: none;
  box-shadow: none;
}

.header-settings-icon {
  width: 18px;
  height: 18px;
  color: var(--text-primary, #383A47);
  flex-shrink: 0;
}

.header-caret {
  opacity: 0.6;
  flex-shrink: 0;
  transition: transform 0.2s, opacity 0.2s;
}

.header-profile-btn[aria-expanded="true"],
.header-project-btn[aria-expanded="true"] {
  background: rgba(var(--primary-rgb, 13, 148, 136), 0.08);
  border-color: rgba(var(--primary-rgb, 13, 148, 136), 0.32);
  box-shadow: 0 10px 22px rgba(27, 28, 32, 0.10);
}

.header-project-btn[aria-expanded="true"] .header-caret {
  transform: rotate(180deg);
  opacity: 0.9;
}

.header-create-btn {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: #FFFFFF; /* White background */
  border: 1px solid rgba(var(--primary-rgb, 13, 148, 136), 0.14);
  transition: all 0.2s ease;
}

.header-create-btn:hover:not(:disabled) {
  background: #F0FDF4; /* Light green tint on hover */
  border-color: rgba(var(--primary-rgb, 13, 148, 136), 0.28);
}

.header-create-icon {
  color: #10B981; /* Green icon color */
  stroke-width: 2.5;
}

/* Dropdown base (used for both profile and project dropdowns) */
.header-dd {
  position: fixed;
  max-width: 360px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg, 16px);
  box-shadow: 0 16px 50px rgba(27, 28, 32, 0.16);
  z-index: var(--z-dropdown, 1000);
  overflow-y: auto;
  overflow-x: hidden;
  opacity: 1;
  /* Ensure no content extends beyond bounds */
  box-sizing: border-box;
  contain: layout;
}

/* Profile dropdown anchors to right */
#header-profile-dd {
  right: 0;
}

/* Project dropdown anchors to project button */
#header-project-dd {
  left: 0;
}

.header-dd-section-label,
.header-dd-subsection-label {
  padding: var(--space-3, 12px) var(--space-4, 16px) var(--space-2, 6px);
  font-size: var(--text-xs, 12px);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
}

.header-dd-subsection-label {
  padding-top: 6px;
  padding-left: calc(var(--space-4, 16px) + 20px); /* Indent to align with project items */
}

.header-dd-current {
  padding: 10px 16px 4px;
}

.header-dd-current-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-secondary, #70727F);
  margin-bottom: 6px;
}

.header-dd-current-value {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid rgba(var(--primary-rgb, 13, 148, 136), 0.12);
  border-radius: 12px;
  background: rgba(var(--primary-rgb, 13, 148, 136), 0.04);
}

.header-dd-current-icon {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(var(--primary-rgb, 13, 148, 136), 0.10);
}

.header-dd-current-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary, #1B1C20);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
}

.header-dd-current-badge {
  margin-left: auto;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(var(--primary-rgb, 13, 148, 136), 0.12);
  color: var(--primary, #0D9488);
}

.header-dd-divider {
  height: 1px;
  background: rgba(var(--primary-rgb, 13, 148, 136), 0.10);
  margin: 10px 0;
}

.header-dd-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  color: var(--text-primary, #1B1C20);
  transition: background 0.15s, transform 0.12s;
  text-decoration: none;
}

.header-dd-item:hover {
  background: rgba(var(--primary-rgb, 13, 148, 136), 0.06);
}

.header-dd-item.active {
  background: rgba(var(--primary-rgb, 13, 148, 136), 0.10);
  box-shadow: inset 3px 0 0 var(--primary, #0D9488);
}

.header-dd-item-icon {
  width: 18px;
  height: 18px;
  color: var(--text-secondary, #70727F);
  flex-shrink: 0;
  display: inline-block;
}

.header-dd-item-content {
  flex: 1;
  min-width: 0;
  /* Ensure flex item can shrink below content size */
  overflow: hidden;
}

.header-dd-item-name {
  font-size: 13px;
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  /* Use 100% of parent width for proper truncation */
  width: 100%;
}

.header-dd-item-desc {
  font-size: 12px;
  color: var(--text-secondary, #70727F);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  /* Use 100% of parent width for proper truncation */
  width: 100%;
}

.header-dd-item-check {
  flex-shrink: 0;
  stroke: var(--primary, #0D9488);
}

/* Indent project items to show hierarchy under General */
.header-dd-project-item {
  padding-left: calc(var(--space-4, 16px) + 20px);
}

.header-dd-account-meta {
  padding: 2px 16px 10px;
}

.header-dd-account-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary, #1B1C20);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-dd-account-role {
  font-size: 12px;
  color: var(--text-secondary, #70727F);
  margin-top: 2px;
}

/* Platform Admin Viewing Context */
.header-dd-viewing-context {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  margin: 4px 8px 8px;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.25);
  border-radius: 6px;
  font-size: 12px;
  color: #b45309;
}

.header-dd-viewing-context svg {
  flex-shrink: 0;
  stroke: #d97706;
}

.header-dd-viewing-context strong {
  color: #92400e;
}

.header-dd-exit-view {
  margin-left: auto;
  padding: 3px 8px;
  font-size: 11px;
  background: rgba(245, 158, 11, 0.2);
  color: #b45309;
  border: 1px solid rgba(245, 158, 11, 0.4);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.header-dd-exit-view:hover {
  background: rgba(245, 158, 11, 0.3);
  border-color: rgba(245, 158, 11, 0.6);
}

/* Dark theme adjustments */
[data-theme="dark"] .header-dd-viewing-context {
  background: rgba(245, 158, 11, 0.15);
  border-color: rgba(245, 158, 11, 0.3);
  color: #fbbf24;
}

[data-theme="dark"] .header-dd-viewing-context strong {
  color: #fcd34d;
}

[data-theme="dark"] .header-dd-exit-view {
  background: rgba(245, 158, 11, 0.25);
  color: #fbbf24;
  border-color: rgba(245, 158, 11, 0.5);
}

.header-dd-empty {
  padding: 18px 16px 22px;
  text-align: center;
  color: var(--text-secondary, #70727F);
}

.header-dd-empty-icon {
  width: 48px;
  height: 48px;
  color: var(--text-tertiary, #CDCED8);
  opacity: 0.6;
  margin-bottom: 8px;
  display: block;
  margin-left: auto;
  margin-right: auto;
}

.header-dd-empty-text {
  font-size: 13px;
  font-weight: 600;
}

.header-dd-empty-subtext {
  font-size: 12px;
  margin-top: 4px;
}

/* Dark theme tweaks */
[data-theme="dark"] .header-bar-card,
html[data-theme="dark"] .header-bar-card,
[data-theme="dark"] .header-profile-btn,
html[data-theme="dark"] .header-profile-btn,
[data-theme="dark"] .header-project-btn,
html[data-theme="dark"] .header-project-btn,
[data-theme="dark"] .header-settings-btn,
html[data-theme="dark"] .header-settings-btn,
[data-theme="dark"] .header-dd,
html[data-theme="dark"] .header-dd {
  background: rgba(51, 65, 85, 0.92);
  border-color: rgba(255, 255, 255, 0.12);
}

[data-theme="dark"] .header-profile-btn,
html[data-theme="dark"] .header-profile-btn,
[data-theme="dark"] .header-project-btn,
html[data-theme="dark"] .header-project-btn,
[data-theme="dark"] .header-settings-btn,
html[data-theme="dark"] .header-settings-btn {
  background: rgba(15, 23, 42, 0.25);
}

[data-theme="dark"] .page-header-top-row,
html[data-theme="dark"] .page-header-top-row {
  border-bottom-color: rgba(255, 255, 255, 0.14);
}

[data-theme="dark"] .header-dd-divider,
html[data-theme="dark"] .header-dd-divider {
  background: rgba(255, 255, 255, 0.10);
}

/* NOTE: .workspace-context-* and .btn-project-settings removed - replaced by .header-settings-btn */

/* Responsive */
@media (max-width: 1024px) {
  .page-header-top-row {
    flex-wrap: wrap;
    gap: 12px;
  }

  .page-header-content {
    min-width: 0;
    flex: 1 1 auto;
  }

  .header-bar-card {
    flex-wrap: wrap;
    gap: 8px;
  }

  .header-project-name {
    max-width: 180px;
  }
}

@media (max-width: 768px) {
  .page-header-top-row {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .header-bar-card {
    width: 100%;
    justify-content: space-between;
  }

  .header-bar-left,
  .header-bar-right {
    flex: 1;
    justify-content: flex-start;
  }

  .page-header-content h1 {
    font-size: 24px;
  }

  .page-header-content p {
    font-size: 13px;
  }

  .header-dd {
    width: calc(100vw - 32px);
    max-width: 100%;
  }

  #header-project-dd {
    left: auto;
    right: 0;
  }
}

@media (max-width: 640px) {
  .page-header-content h1 {
    font-size: 22px;
  }

  .header-bar-left {
    gap: 6px;
  }

  .header-project-btn {
    font-size: 12px;
    padding: 6px 10px;
  }

  .header-project-name {
    max-width: 140px;
  }

  .header-settings-btn,
  .header-create-btn,
  .header-profile-btn {
    width: 34px;
    height: 34px;
  }

  .header-dd {
    width: min(420px, calc(100vw - 24px));
  }
}

/* =========================================================================
   Header Credits Indicator Button
   ========================================================================= */

.header-credits-wrapper {
  display: flex;
  align-items: center;
}

.header-credits-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  appearance: none;
  border: 1px solid rgba(var(--primary-rgb, 13, 148, 136), 0.14);
  background: rgba(255, 255, 255, 0.92);
  color: var(--text-primary, #1B1C20);
  border-radius: 12px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.2s;
  position: relative;
}

.header-credits-btn:hover {
  background: rgba(255, 255, 255, 1);
  border-color: rgba(var(--primary-rgb, 13, 148, 136), 0.25);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.header-credits-btn svg {
  color: var(--primary, #0D9488);
  flex-shrink: 0;
}

.header-credits-value {
  font-variant-numeric: tabular-nums;
}

.header-credits-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 10px;
  height: 10px;
  background: var(--warning, #f59e0b);
  border: 2px solid var(--white, #fff);
  border-radius: 50%;
}

/* Warning state (low balance) */
.header-credits-btn.credits-warning {
  border-color: rgba(245, 158, 11, 0.4);
  background: rgba(245, 158, 11, 0.08);
}

.header-credits-btn.credits-warning:hover {
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.5);
}

.header-credits-btn.credits-warning .header-credits-badge {
  background: var(--warning, #f59e0b);
}

/* Danger state (no credits) */
.header-credits-btn.credits-danger {
  border-color: rgba(239, 68, 68, 0.4);
  background: rgba(239, 68, 68, 0.08);
  animation: credits-pulse 2s infinite;
}

.header-credits-btn.credits-danger:hover {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.5);
}

.header-credits-btn.credits-danger .header-credits-badge {
  background: var(--danger, #ef4444);
}

.header-credits-btn.credits-danger svg {
  color: var(--danger, #ef4444);
}

@keyframes credits-pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.3);
  }
  50% {
    box-shadow: 0 0 0 4px rgba(239, 68, 68, 0);
  }
}

/* Dark theme support */
[data-theme="dark"] .header-credits-btn,
html[data-theme="dark"] .header-credits-btn {
  background: rgba(15, 23, 42, 0.25);
  border-color: rgba(255, 255, 255, 0.12);
  color: var(--text, #e2e8f0);
}

[data-theme="dark"] .header-credits-btn:hover,
html[data-theme="dark"] .header-credits-btn:hover {
  background: rgba(15, 23, 42, 0.4);
  border-color: rgba(255, 255, 255, 0.2);
}

[data-theme="dark"] .header-credits-btn.credits-warning,
html[data-theme="dark"] .header-credits-btn.credits-warning {
  background: rgba(245, 158, 11, 0.15);
  border-color: rgba(245, 158, 11, 0.4);
}

[data-theme="dark"] .header-credits-btn.credits-danger,
html[data-theme="dark"] .header-credits-btn.credits-danger {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
}

/* Responsive adjustments */
@media (max-width: 640px) {
  .header-credits-btn {
    padding: 6px 10px;
    font-size: 12px;
  }

  .header-credits-btn svg {
    width: 14px;
    height: 14px;
  }
}
