/* The top bar and its narrow-screen menu (issue #267). Split out of style.css (issue #159). */

.project-header-actions { display: flex; align-items: center; gap: 0.6rem; }

/* ---- Top bar (issue #267) ---------------------------------------------------
   The keskuskuvaskanneri's bar: dark in both themes, the white logo with the
   tool's name and version on the left, the view buttons, the user and the
   theme switch on the right. Below 760 px the right-hand part folds behind
   #nav-toggle: the media block after this one, and nav.js. */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  color: var(--bar-text);
  background: var(--bar);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.header-row {
  position: relative;
  max-width: 1680px;
  min-height: var(--header-height);
  margin: 0 auto;
  padding: 0 2rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.brand {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 0.85rem;
  color: var(--bar-text);
  text-decoration: none;
}

.brand-logo {
  display: block;
  width: auto;
  height: 2.2rem;
}

.brand-name {
  font-size: 1.05rem;
  font-weight: 600;
  white-space: nowrap;
}

.app-version {
  color: var(--bar-muted);
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}

.header-actions {
  min-width: 0;
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.mode-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

/* The view buttons and the logout: white words on the bar, no box. */
.mode-nav button,
.user-chip-logout {
  min-height: 2.4rem;
  padding: 0 0.8rem;
  color: var(--bar-text);
  background: transparent;
  border: 0;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
}

/* The bar's own hover. `.topbar` outranks the orange hover that every
   other button gets further down. */
.topbar button:hover:not(:disabled) { background: var(--bar-hover); }

/* The view you are on: an orange line under it. */
.mode-nav button.active {
  border-radius: 0;
  box-shadow: inset 0 -3px 0 var(--accent);
}

/* Who is logged in (issue #72). Hidden until the UI has asked /api/me, and
   for good under AUTH_MODE=none. The name gives way first when the bar is
   short of room. */
.user-chip {
  min-width: 0;
  margin: 0 0 0 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.user-chip-name {
  min-width: 0;
  max-width: 14rem;
  overflow: hidden;
  color: var(--bar-muted);
  font-size: 0.85rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.theme-toggle {
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  padding: 0;
  color: var(--bar-text);
  background: transparent;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
}

.theme-icon {
  width: 1.25rem;
  height: 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* The icon shows where the button takes you: a sun in the dark theme, a
   moon in the light one. The label is only for the narrow-screen menu,
   where the button is a row of its own. */
.theme-icon-moon { display: none; }

html[data-theme="light"] .theme-icon-sun { display: none; }

html[data-theme="light"] .theme-icon-moon { display: block; }

.theme-toggle-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.nav-toggle { display: none; }

/* Between 900 px and the fold this bar has more in it than the kanneri's:
   the buttons close up and the user's name goes (the phone menu shows it
   again). Logging out stays. */

@media (max-width: 900px) {
  .header-row { padding: 0 1rem; gap: 0.75rem; }
  .mode-nav button,
  .user-chip-logout { padding: 0 0.5rem; }
  .user-chip { margin-left: 0; }
  .user-chip-name { display: none; }
}

/* ---- Narrow screens ------------------------------------------------------
   Below 760 px the view buttons, the user and the theme switch fold into a
   menu behind one button. nav.js only flips the button's aria-expanded;
   showing and hiding the menu is all here, and the 760 must match nav.js. */

@media (max-width: 760px) {
  .header-row {
    min-height: 3.5rem;
    padding: 0 0.75rem;
    gap: 0.6rem;
  }
  .brand { gap: 0.6rem; }
  .brand-logo { height: 1.8rem; }
  .brand-name { font-size: 0.95rem; }
  .nav-toggle {
    display: inline-grid;
    place-items: center;
    width: 2.6rem;
    height: 2.6rem;
    margin-left: auto;
    padding: 0;
    color: var(--bar-text);
    background: transparent;
    border: 0;
  }
  .nav-toggle[aria-expanded="true"] { background: var(--bar-hover); }
  .nav-toggle svg {
    width: 1.4rem;
    height: 1.4rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
  }
  .nav-icon-close { display: none; }
  .nav-toggle[aria-expanded="true"] .nav-icon-open { display: none; }
  .nav-toggle[aria-expanded="true"] .nav-icon-close { display: block; }
  .header-actions { display: none; }
  /* The open menu: a panel under the bar's right end, a row per item. */
  .nav-toggle[aria-expanded="true"] + .header-actions {
    position: absolute;
    top: 100%;
    right: 0.75rem;
    z-index: 60;
    min-width: 13rem;
    padding: 0.35rem 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-float);
  }
  .nav-toggle[aria-expanded="true"] + .header-actions .mode-nav,
  .nav-toggle[aria-expanded="true"] + .header-actions .user-chip {
    margin: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
  }
  .nav-toggle[aria-expanded="true"] + .header-actions .user-chip { border-top: 1px solid var(--border); }
  .nav-toggle[aria-expanded="true"] + .header-actions .user-chip-name {
    display: block;
    max-width: none;
    padding: 0.5rem 1rem 0;
    color: var(--muted);
  }
  .nav-toggle[aria-expanded="true"] + .header-actions .mode-nav button,
  .nav-toggle[aria-expanded="true"] + .header-actions .user-chip-logout,
  .nav-toggle[aria-expanded="true"] + .header-actions .theme-toggle {
    width: 100%;
    height: auto;
    min-height: 2.75rem;
    padding: 0 1rem;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.6rem;
    color: var(--text);
    border-radius: 0;
    box-shadow: none;
    font-size: 0.95rem;
  }
  .nav-toggle[aria-expanded="true"] + .header-actions button:hover:not(:disabled) { background: var(--control-hover); }
  /* The view you are on: an orange line at the row's start. */
  .nav-toggle[aria-expanded="true"] + .header-actions .mode-nav button.active { box-shadow: inset 3px 0 0 var(--accent); }
  .nav-toggle[aria-expanded="true"] + .header-actions .theme-toggle {
    border-top: 1px solid var(--border);
    font-weight: 600;
  }
  .nav-toggle[aria-expanded="true"] + .header-actions .theme-toggle-label {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
  }
}

@media (max-width: 480px) {
  .app-version { display: none; }
}

@media (max-width: 700px) {
  .project-header-actions { align-items: stretch; flex-direction: column; width: 100%; }
  .project-header-actions > * { width: 100%; text-align: center; }
}
