/* PWA Title Bar Customization */

/* Detect if window-controls-overlay is supported */
@supports (environment(titlebar-area-x)) {
  
  /* Title bar area styling */
  .title-bar {
    position: fixed;
    top: 0;
    left: env(titlebar-area-x);
    width: env(titlebar-area-width);
    height: env(titlebar-area-height);
    background-color: #196344;
    color: white;
    z-index: 10000;
    display: flex;
    align-items: center;
    padding: 0 16px;
    box-sizing: border-box;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  }
  
  /* App logo in title bar */
  .title-bar-logo {
    width: 24px;
    height: 24px;
    margin-right: 12px;
    flex-shrink: 0;
  }
  
  /* App title in title bar */
  .title-bar-title {
    font-size: 14px;
    font-weight: 600;
    color: white;
    flex-grow: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  
  /* Title bar buttons/actions */
  .title-bar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
  }
  
  /* Title bar button styling */
  .title-bar-btn {
    background: none;
    border: none;
    color: white;
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background-color 0.2s ease;
  }
  
  .title-bar-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
  }
  
  .title-bar-btn:active {
    background-color: rgba(255, 255, 255, 0.2);
  }
  
  /* Refresh button specific styling */
  .title-bar-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
  }
  
  .title-bar-btn .fa-spin {
    animation: fa-spin 1s infinite linear;
  }
  
  /* Custom refresh animation */
  @keyframes refresh-pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
  }
  
  .title-bar-btn:active .fa-refresh {
    animation: refresh-pulse 0.3s ease;
  }
  
  /* Adjust main content to account for title bar */
  body.has-titlebar {
    padding-top: env(titlebar-area-height);
  }
  
  /* Adjust main navigation/header */
  body.has-titlebar .nav-bar {
    top: env(titlebar-area-height);
  }
  
  /* Ensure content doesn't overlap with title bar */
  body.has-titlebar .hbox {
    margin-top: env(titlebar-area-height);
  }
  
  /* Title bar notification badge */
  .title-bar-badge {
    background-color: #ff4757;
    color: white;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: -2px;
    right: -2px;
  }
  
  /* Title bar dropdown menu */
  .title-bar-dropdown {
    position: relative;
  }
  
  .title-bar-dropdown-content {
    position: absolute;
    top: 100%;
    right: 0;
    background: white;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    padding: 8px 0;
    min-width: 150px;
    z-index: 1000;
    display: none;
  }
  
  .title-bar-dropdown:hover .title-bar-dropdown-content {
    display: block;
  }
  
  .title-bar-dropdown-item {
    padding: 8px 16px;
    color: #333;
    text-decoration: none;
    display: block;
    font-size: 12px;
  }
  
  .title-bar-dropdown-item:hover {
    background-color: #f8f9fa;
    color: #196344;
  }
}

/* Fallback for browsers that don't support window-controls-overlay */
@supports not (environment(titlebar-area-x)) {
  .title-bar {
    display: none;
  }
}

/* Mobile specific adjustments */
@media (max-width: 768px) {
  .title-bar {
    padding: 0 12px;
  }
  
  .title-bar-title {
    font-size: 13px;
  }
  
  .title-bar-actions {
    gap: 4px;
  }
  
  .title-bar-btn {
    padding: 4px 6px;
    font-size: 11px;
  }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .title-bar-logo {
    width: 20px;
    height: 20px;
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .title-bar {
    background-color: #0d4a2b;
    border-bottom-color: rgba(255, 255, 255, 0.2);
  }
  
  .title-bar-dropdown-content {
    background: #2d3748;
    color: white;
  }
  
  .title-bar-dropdown-item {
    color: #e2e8f0;
  }
  
  .title-bar-dropdown-item:hover {
    background-color: #4a5568;
    color: #9ae6b4;
  }
}

/* Focus styles for accessibility */
.title-bar-btn:focus {
  outline: 2px solid rgba(255, 255, 255, 0.5);
  outline-offset: 2px;
}

/* Animation for title bar appearance */
.title-bar {
  animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
  from {
    transform: translateY(-100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}