/* fm-core/header.css: Unified App Shell Header for FM Suite */
@import url('./sync-panel.css');

:root {
  --fm-h-bg: #181816;
  --fm-h-text: #f0f0ee;
  --fm-h-text-muted: #9c9c96;
  --fm-h-border: rgba(255, 255, 255, 0.09);
  --fm-h-active-bg: rgba(255, 255, 255, 0.12);
  --fm-h-hover-bg: rgba(255, 255, 255, 0.07);
  --fm-h-accent-peach: #e09f67;
  --fm-h-accent-green: #4ade80;
  --fm-h-accent-blue: #60a5fa;
  --fm-h-font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

fm-header {
  display: block;
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  width: 100%;
}

.fm-header {
  font-family: var(--fm-h-font);
  background: var(--fm-h-bg);
  color: var(--fm-h-text);
  border-bottom: 1px solid var(--fm-h-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 16px;
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  min-height: 50px;
  box-sizing: border-box;
}

/* Left: Menu & App Switcher */
.fm-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.fm-menu-btn {
  display: none;
}

@media (max-width: 1024px) {
  .fm-menu-btn {
    display: inline-flex;
  }
}

.fm-app-switcher {
  display: flex;
  align-items: center;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--fm-h-border);
  border-radius: 9999px;
  padding: 2px 3px;
  gap: 2px;
}

.fm-app-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 9999px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--fm-h-text-muted);
  text-decoration: none;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.fm-app-link:hover {
  color: #ffffff;
  background: var(--fm-h-hover-bg);
}

.fm-app-link.active {
  color: #ffffff;
  background: var(--fm-h-active-bg);
}

.fm-app-link[data-app="pro"].active {
  color: var(--fm-h-accent-peach);
}

.fm-app-link[data-app="rent"].active {
  color: var(--fm-h-accent-blue);
}

.fm-app-link[data-app="expense"].active {
  color: var(--fm-h-accent-green);
}

.fm-app-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.8;
}

/* Center: Client Picker or Household Badge */
.fm-header-center {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1 1 auto;
  justify-content: center;
  min-width: 0;
}

.fm-client-picker {
  display: inline-flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--fm-h-border);
  border-radius: 9999px;
  padding: 2px 4px 2px 10px;
  max-width: 320px;
}

.fm-client-picker select {
  background: transparent;
  color: #ffffff;
  border: none;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  outline: none;
  cursor: pointer;
  padding: 4px 6px;
  text-overflow: ellipsis;
  max-width: 220px;
}

.fm-client-picker select option {
  background: #242422;
  color: #ffffff;
}

.fm-household-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--fm-h-text);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--fm-h-border);
  border-radius: 9999px;
  padding: 4px 12px;
  white-space: nowrap;
}

.fm-nw-indicator {
  font-size: 13px;
  font-weight: 700;
  color: var(--fm-h-text);
  white-space: nowrap;
}

/* Right: Tools & Indicators */
.fm-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

/* Sync Chip */
.fm-sync-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--fm-h-border);
  border-radius: 9999px;
  color: #ffffff;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.fm-sync-chip:hover {
  background: rgba(255, 255, 255, 0.13);
  border-color: rgba(255, 255, 255, 0.2);
}

.fm-sync-chip.syncing {
  border-color: var(--fm-h-accent-blue);
  color: var(--fm-h-accent-blue);
}

.fm-sync-chip.offline {
  border-color: #f59e0b;
  color: #f59e0b;
}

.fm-sync-chip.paused {
  border-color: #ef4444;
  color: #ef4444;
}

/* Icon Buttons */
.fm-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: transparent;
  border: none;
  color: var(--fm-h-text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
  padding: 0;
}

.fm-icon-btn:hover {
  background: var(--fm-h-hover-bg);
  color: #ffffff;
}

.fm-icon-btn:active {
  background: var(--fm-h-active-bg);
}

.fm-icon-btn[aria-pressed="true"] {
  color: var(--fm-h-accent-peach);
  background: rgba(224, 159, 103, 0.15);
}

.fm-account-btn {
  width: auto;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 9999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--fm-h-border);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--fm-h-text);
}

.fm-account-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.fm-ico {
  width: 17px;
  height: 17px;
  flex: none;
}

.fm-ico-sm {
  width: 14px;
  height: 14px;
  flex: none;
}

/* Responsive Rules */
@media (max-width: 860px) {
  .fm-app-link span.fm-app-title-full {
    display: none;
  }
  .fm-app-link span.fm-app-title-short {
    display: inline;
  }
  .fm-nw-indicator {
    display: none;
  }
}

@media (min-width: 861px) {
  .fm-app-link span.fm-app-title-full {
    display: inline;
  }
  .fm-app-link span.fm-app-title-short {
    display: none;
  }
}

/* Tablet & Phone Optimization: Screens <= 600px */
@media (max-width: 600px) {
  .fm-header {
    padding: 6px 10px;
    padding-top: calc(6px + env(safe-area-inset-top, 0px));
    gap: 6px;
    min-height: 46px;
  }
  /* Hide the household badge on smaller viewports to prevent cramped overlap */
  .fm-household-badge {
    display: none !important;
  }
  .fm-app-link {
    padding: 4px 7px;
    font-size: 11px;
    gap: 4px;
  }
  .fm-sync-chip {
    padding: 5px 8px;
    font-size: 11px;
  }
  .fm-sync-label,
  .fm-account-label {
    display: none !important;
  }
  .fm-account-btn {
    padding: 5px 8px;
  }
}

/* iPhone & Compact Mobile Viewports: Screens <= 480px */
@media (max-width: 480px) {
  .fm-header {
    padding: 4px 8px;
    padding-top: calc(4px + env(safe-area-inset-top, 0px));
    gap: 4px;
    min-height: 44px;
  }
  .fm-header-left {
    gap: 4px;
  }
  .fm-header-center {
    gap: 4px;
  }
  .fm-header-right {
    gap: 4px;
  }
  .fm-icon-btn {
    width: 32px;
    height: 32px;
  }
  /* Hide secondary non-essential top-bar action buttons on narrow phone screens */
  /* (Lock is accessible via App Settings; Theme is accessible via Settings/Data menu) */
  #btn-lock-app,
  #thbtn {
    display: none !important;
  }
  .fm-app-switcher {
    padding: 2px;
    gap: 1px;
  }
  .fm-app-link {
    padding: 3px 6px;
    font-size: 11px;
  }
  .fm-app-dot {
    display: none !important;
  }
  .fm-client-picker {
    padding: 1px 3px 1px 5px;
    gap: 2px;
  }
  .fm-client-picker select {
    max-width: 80px;
    font-size: 11px;
    padding: 2px 3px;
  }
  .fm-client-picker .fm-icon-btn {
    width: 24px;
    height: 24px;
  }
  .fm-sync-chip {
    padding: 5px 6px;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    justify-content: center;
  }
  .fm-account-btn {
    padding: 4px 6px;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

