.titlebar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 40px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: transparent;
  color: #111827;
  --titlebar-nav-hover-bg: rgba(0, 0, 0, 0.08);
  --titlebar-pill-bg: rgba(0, 0, 0, 0.08);
  z-index: 9999;
  user-select: none;
  /* border-bottom: 1px solid rgba(0, 0, 0, 0.1); */
}

.dark .titlebar {
  background-color: #2c0b0b00;
  color: #ffffff;
  --titlebar-nav-hover-bg: rgba(255, 255, 255, 0.1);
  --titlebar-pill-bg: rgba(255, 255, 255, 0.34);
  /* border-bottom: 1px solid rgba(255, 255, 255, 0.1); */
}

.dark .titlebar.titlebar-chat {
  background-color: #16161600;
}

.dark .titlebar.titlebar-chat .titlebar-control-button {
  background-color: transparent;
}

.titlebar-drag-region {
  -webkit-app-region: drag;
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: 12px;
}

/* macOS keeps the native traffic lights; reserve their hit area. */
.titlebar-mac .titlebar-drag-region {
  padding-left: 82px;
}

.titlebar-mac .titlebar-controls {
  padding-right: 12px;
}

/* Linux uses Electron's native window-controls overlay; reserve the right edge. */
.titlebar-linux .titlebar-controls {
  padding-right: 132px;
}

.titlebar-title {
  font-size: 13px;
  font-weight: 500;
  opacity: 1;
  color: currentColor;
}

.titlebar-controls {
  -webkit-app-region: no-drag;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 100%;
  flex: 0 0 auto;
  min-width: 0;
  padding-right: 8px;
}

.titlebar-nav-controls {
  -webkit-app-region: no-drag;
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 6px;
}

.titlebar-project-name {
  min-width: 0;
  max-width: 240px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  opacity: 0.82;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.titlebar-nav-icon-shell {
  width: 24px;
  height: 24px;
}

.titlebar-pill {
  margin-top: 4px;
  margin-bottom: 4px;
  border-radius: 9999px;
  border: none;
  padding: 1px 14px;
  min-height: 24px;
  min-width: 65px;
  font-size: 12px;
  line-height: 1;
  color: inherit;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  /* display: flex; */
  align-items: center;
  user-select: none;
  cursor: pointer;
}

.titlebar-pill-label {
  font-weight: 500;
}

.titlebar-remote-pill {
  margin-right: 6px;
  padding-left: 10px;
  padding-right: 10px;
}

.cwd-pill {
  position: relative;
  flex: 1 1 256px;
  min-width: 0;
  max-width: 256px;
  margin-right: 2px;
}

.cwd-pill:disabled {
  cursor: default;
  opacity: 0.8;
}

.cwd-pill-text {
  display: inline-block;
  min-width: max-content;
  transform: translateX(0);
  will-change: transform;
}

.titlebar-pill-mono {
  font-family: monospace;
}

.titlebar-pill-empty {
  font-style: italic;
  opacity: 1;
}

.cwd-pill:hover .cwd-pill-text-scroll {
  animation: cwd-hover-scroll 2.2s ease-in-out infinite alternate;
}

.titlebar-control-button {
  border: none;
  background: transparent;
  color: currentColor;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  margin: 0;
  border-radius: 9999px;
}

.titlebar-control-icon-shell {
  display: flex;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  border-radius: 9999px;
  /* border: 1px solid rgba(229, 229, 229, 0.8); */
  background: rgb(250, 250, 250);
  color: rgb(64, 64, 64);
  transition:
    transform 0.1s ease,
    background-color 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease,
    box-shadow 0.15s ease;
}

.dark .titlebar-control-icon-shell {
  border-color: rgba(64, 64, 64, 0.7);
  background: rgb(23, 23, 23);
  color: rgb(212, 212, 212);
}

.titlebar-control-button:hover .titlebar-control-icon-shell {
  transform: scale(1.08);
}

.titlebar-control-button:active .titlebar-control-icon-shell {
  transform: scale(0.95);
}

.titlebar-control-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.titlebar-control-button:disabled .titlebar-control-icon-shell {
  transform: none;
}

.titlebar-compact:hover .titlebar-control-icon-shell {
  background-color: rgb(37, 99, 235);
  border-color: rgb(37, 99, 235);
  color: #fff;
}

.dark .titlebar-compact:hover .titlebar-control-icon-shell {
  background-color: rgb(59, 130, 246);
  border-color: rgb(59, 130, 246);
  color: #fff;
}

.titlebar-compact.titlebar-compact-active .titlebar-control-icon-shell,
.titlebar-compact.titlebar-compact-active:hover .titlebar-control-icon-shell {
  background-color: rgb(37, 99, 235);
  border-color: rgb(37, 99, 235);
  color: #fff;
}

.dark .titlebar-compact.titlebar-compact-active .titlebar-control-icon-shell,
.dark .titlebar-compact.titlebar-compact-active:hover .titlebar-control-icon-shell {
  background-color: rgb(59, 130, 246);
  border-color: rgb(59, 130, 246);
  color: #fff;
}

.titlebar-close:hover .titlebar-control-icon-shell {
  background-color: #e81123;
  border-color: #e81123;
  color: white;
}

.titlebar-control-button svg {
  width: 14px;
  height: 14px;
}

/* Tailwind-like breakpoints for CWD pill sizing */
@media (min-width: 640px) {
  .cwd-pill {
    flex-basis: 236px;
    max-width: 236px;
  }
}

@media (min-width: 768px) {
  .cwd-pill {
    flex-basis: 300px;
    max-width: 300px;
  }
}

@media (max-width: 980px) {
  .titlebar-project-name {
    max-width: 160px;
  }
}

@media (max-width: 820px) {
  .titlebar-project-name {
    display: none;
  }
}

@media (max-width: 640px) {
  .titlebar-mac .titlebar-drag-region {
    padding-left: 78px;
  }

  .titlebar-mac .titlebar-remote-pill,
  .titlebar-linux .titlebar-remote-pill {
    display: none;
  }

  .titlebar-linux .titlebar-controls {
    padding-right: 120px;
  }
}

/* Collapse sooner on very small windows so window controls stay visible */
@media (max-width: 520px) {
  .cwd-pill {
    flex-basis: 208px;
    max-width: 208px;
    padding-left: 8px !important;
    padding-right: 8px !important;
  }
}

@media (max-width: 430px) {
  .cwd-pill {
    flex-basis: 64px;
    max-width: 64px;
    margin-right: 0 !important;
    padding-left: 7px !important;
    padding-right: 7px !important;
  }
}

/* Base app-content styling - always applied */
.app-content {
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  overflow: hidden;
}

.app-main {
  flex: 1 1 auto;
  min-width: 0;
}

/* Add padding to app content to account for title bar */
body.has-titlebar {
  --titlebar-height: 40px;
}

body.has-titlebar .app-content {
  padding-top: var(--titlebar-height);
  box-sizing: border-box;
}

/* Spin animation for loading state */
@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@keyframes cwd-hover-scroll {
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(-28px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .cwd-pill:hover .cwd-pill-text-scroll {
    animation: none;
  }
}

.animate-spin {
  animation: spin 1s linear infinite;
}

.dark .titlebar-close:hover .titlebar-control-icon-shell,
.dark .titlebar-close:hover .titlebar-control-icon-shell.acrylic-subtle {
  background-color: #e81123;
  border-color: #e81123;
  color: white;
}
