/**
 * Page Header Component
 * Container-aware responsive header with theme toggle
 */

.page-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background-color: var(--bg-secondary);
  box-shadow: 0 2px 10px rgb(0 0 0 / 10%);
  z-index: 100;
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
  container-type: inline-size;
}

.header-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 56px;
  max-height: 56px;
}

/* Site Logo (always on left) */
.site-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.site-logo > a {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--text-primary);
  text-decoration: none;
  transition: color 0.2s ease;
}

.site-logo > a:hover {
  color: var(--accent-color);
}

.site-logo img {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

/* Breadcrumb Navigation */
.breadcrumb-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--text-secondary);
}

.breadcrumb-nav a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: all 0.2s ease;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
}

.breadcrumb-nav a:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary, rgba(0, 0, 0, 0.05));
}

.breadcrumb-nav a:focus-visible {
  outline: 2px solid var(--color-primary, #2563eb);
  outline-offset: 2px;
}

.breadcrumb-separator {
  color: var(--text-muted);
  font-size: 12px;
}

/* Current page (non-linked) */
.breadcrumb-nav .breadcrumb-current {
  color: var(--text-primary);
  font-weight: 500;
  padding: 4px 8px;
}

/* Header Title (center - optional) */
.header-title {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  color: var(--text-primary);
  text-align: center;
  white-space: nowrap;
  flex-shrink: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Header Actions (for app pages with action buttons) */
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.header-actions .icon-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.header-actions .icon-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--accent-color);
}

.header-actions .icon-btn svg {
  flex-shrink: 0;
}

.header-actions .btn-label {
  display: inline;
}

/* Menu container for dropdown */
.menu-container {
  position: relative;
}

.menu-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgb(0 0 0 / 15%);
  padding: 8px 0;
  min-width: 200px;
  z-index: 1000;
  display: none;
}

.menu-dropdown.open {
  display: block;
}

.menu-dropdown .menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 16px;
  background: none;
  border: none;
  text-align: left;
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.menu-dropdown .menu-item:hover {
  background: var(--bg-tertiary);
}

.menu-dropdown .menu-item svg {
  flex-shrink: 0;
}

/* Help Link Button */
.help-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-tertiary, rgba(0, 0, 0, 0.05));
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid var(--border-color);
  transition: background-color 0.2s, color 0.2s, border-color 0.2s;
  flex-shrink: 0;
}

.help-link:hover {
  background: var(--accent-color, #4a90e2);
  color: white;
  border-color: var(--accent-color, #4a90e2);
}

.help-link:focus-visible {
  outline: 2px solid var(--accent-color, #4a90e2);
  outline-offset: 2px;
}

/* Header Theme Toggle (always on right) */
.header-theme-toggle {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.header-theme-toggle button {
  background-color: rgb(0 0 0 / 10%);
  border: 1px solid rgb(0 0 0 / 20%);
  border-radius: 20px;
  padding: 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  width: 56px;
  height: 28px;
  position: relative;
  transition: all 0.3s ease;
  overflow: hidden;
}

.header-theme-toggle button:hover {
  background-color: rgb(0 0 0 / 15%);
}

.header-theme-toggle button .toggle-icon {
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Android Emoji", "EmojiOne Color", "Twemoji Mozilla", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  position: absolute;
  transition: all 0.3s ease;
  z-index: 2;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-theme-toggle button .ghibli-icon {
  left: 3px;
  opacity: 1;
  transform: scale(1.1);
}

.header-theme-toggle button .real-icon {
  right: 3px;
  opacity: 0.5;
}

.header-theme-toggle button .toggle-slider {
  width: 22px;
  height: 22px;
  background-color: #fff;
  border-radius: 50%;
  position: absolute;
  left: 3px;
  top: 3px;
  box-shadow: 0 1px 3px rgb(0 0 0 / 20%);
  transition: transform 0.3s cubic-bezier(0.68, -0.55, 0.27, 1.55);
  z-index: 1;
}

body.real-mode .header-theme-toggle button .toggle-slider {
  transform: translateX(28px);
}

body.real-mode .header-theme-toggle button .ghibli-icon {
  opacity: 0.5;
  transform: scale(1);
}

body.real-mode .header-theme-toggle button .real-icon {
  opacity: 1;
  transform: scale(1.1) translateX(-1.5px);
}

/* Main content spacing */
main {
  margin-top: 60px;
  padding-top: 0;
}

body.has-fixed-header main {
  margin-top: 60px;
}

body.has-fixed-header .container {
  padding-top: 10px;
}

/* Container query - hide elements on small screens */
@container (max-width: 768px) {
  .site-logo {
    flex-wrap: wrap;
    gap: 8px;
  }

  .site-logo > a span {
    display: none;
  }

  .breadcrumb-nav {
    font-size: 12px;
    flex-basis: 100%;
    margin-left: 40px; /* Align with logo */
  }

  .breadcrumb-separator {
    font-size: 10px;
  }

  .header-title {
    font-size: 16px;
  }

  .header-actions .btn-label {
    display: none;
  }

  .header-actions .icon-btn {
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
    justify-content: center;
  }

  /* Keep theme toggle at desktop size */
  .header-theme-toggle button {
    margin-top: 0;
    margin-bottom: 0;
  }

  main,
  body.has-fixed-header main {
    margin-top: 60px;
  }
}

/* Container query - very small screens */
@container (max-width: 420px) {
  .header-container {
    padding: 10px 12px;
    gap: 8px;
    min-height: 52px;
    max-height: 52px;
  }

  .site-logo {
    gap: 4px;
  }

  .breadcrumb-nav {
    font-size: 11px;
    margin-left: 36px; /* Align with smaller logo */
  }

  .breadcrumb-separator {
    font-size: 9px;
  }

  .breadcrumb-nav a {
    padding: 2px 4px;
  }

  .header-title {
    font-size: 14px;
  }

  .header-actions {
    gap: 4px;
  }

  .header-actions .icon-btn {
    padding: 6px;
    min-width: 44px;
    min-height: 44px;
  }

  /* Keep theme toggle at desktop size */
  .header-theme-toggle button {
    margin-top: 0;
    margin-bottom: 0;
  }
}

/* Touch-friendly targets on mobile */
@container (max-width: 768px) {
  .site-logo a {
    min-height: 44px;
    padding: 10px 6px;
    margin-top: -10px;
    margin-bottom: -10px;
  }
}

/* Hide input file for import */
#import-file {
  display: none;
}
