/* Global reset + app shell layout.
   Header / sidebar are fleshed out in Phase 3. This is the base skeleton. */

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  font-family: var(--font-sans);
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--color-bg);
  color: var(--color-fg);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: var(--font-bold); line-height: var(--leading-tight); }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
img, svg { display: block; max-width: 100%; }
button { font: inherit; cursor: pointer; }

/* Visible focus ring for keyboard users (never removed). */
:focus-visible {
  outline: 2px solid var(--color-ring);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

/* SVG icon sprite is hidden but its symbols are referenced via <use>. */
.svg-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; }

/* App shell scaffold — Phase 3 builds the real header + sidebar here. */
#app { min-height: 100dvh; }

/* Full-screen boot loader shown before JS mounts. */
.app-boot {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: var(--color-bg);
  z-index: var(--z-modal);
}
.app-boot__spinner {
  width: 40px; height: 40px; border-radius: var(--radius-full);
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  animation: app-spin 0.8s linear infinite;
}
@keyframes app-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ── App shell: sidebar + header + main ─────────────────────────────────── */
.app-shell { display: grid; grid-template-columns: var(--sidebar-width) 1fr; min-height: 100dvh;
  transition: grid-template-columns var(--dur-base) var(--ease-in-out); }

.app-sidebar {
  position: sticky; top: 0; align-self: start; height: 100dvh;
  display: flex; flex-direction: column; gap: var(--space-2);
  padding: var(--space-4) var(--space-3);
  background: var(--color-surface); border-right: 1px solid var(--color-border);
  /* No overflow-x:hidden here — it would clip the hover flyout submenus, which
     intentionally render past the sidebar's right edge (position:absolute,
     left:100%). Each label already self-clips via .sidebar__link-label's own
     overflow:hidden, so this ancestor-level clip was redundant anyway. */
  /* position:sticky establishes its own stacking context, so a submenu's
     z-index inside only ranks against other sidebar content — it needs the
     SIDEBAR ITSELF elevated above .app-main's content (cards, sticky header)
     or the flyout paints underneath them despite its own high z-index. */
  z-index: var(--z-drawer);
}
.sidebar__brand { padding: var(--space-2) var(--space-3) var(--space-4); font-weight: var(--font-bold); }
.sidebar__brand-row { display: flex; align-items: center; gap: var(--space-3); }
/* Default HRlume mark: full wordmark when expanded, icon-only once collapsed
   (toggled purely via [data-sidebar-collapsed] below — see .sidebar__brand-icon
   for the customer-logo case, which has no such toggle since it's one image). */
.sidebar__brand-full { height: 24px; width: auto; object-fit: contain; background: #fff; border-radius: var(--radius-sm); padding: var(--space-1) var(--space-2); }
.sidebar__brand-compact { display: none; width: 32px; height: 32px; object-fit: contain; border-radius: var(--radius-md); }
.sidebar__brand-icon { width: 32px; height: 32px; object-fit: contain; border-radius: var(--radius-md); flex-shrink: 0; }
.sidebar__powered { display: flex; align-items: center; gap: var(--space-2); margin-top: var(--space-2); padding-left: var(--space-3); opacity: 0.55; font-size: var(--text-xs); font-weight: var(--font-medium); }
.sidebar__powered img { width: 14px; height: 14px; object-fit: contain; border-radius: 3px; }

/* Identity card at the top of the drawer — link to the signed-in user's own
   profile. Mirrors the header's avatar+name, but this is the only place that
   also shows the role/position on mobile (the header hides __name below
   900px), so it gives the drawer real "who am I" context on its own. */
.sidebar__profile {
  display: flex; align-items: center; gap: var(--space-3);
  margin: var(--space-2) 0 var(--space-4); padding: var(--space-3);
  border-radius: var(--radius-md); border: 1px solid var(--color-border);
  color: inherit; transition: background var(--dur-fast) var(--ease-in-out);
}
.sidebar__profile:hover { background: var(--color-surface-hover); }
.sidebar__profile-info { min-width: 0; display: flex; flex-direction: column; }
.sidebar__profile-name { font-size: var(--text-sm); font-weight: var(--font-semibold); color: var(--color-fg);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar__profile-role { font-size: var(--text-xs); color: var(--color-fg-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar__profile-avatar { position: relative; display: inline-flex; flex-shrink: 0; }
.sidebar__profile-avatar > i {
  position: absolute; right: -1px; bottom: -1px; width: 10px; height: 10px;
  border: 2px solid var(--color-surface); border-radius: var(--radius-full);
  background: var(--color-success);
}
.sidebar__profile-arrow { width: 14px; height: 14px; margin-left: auto; flex-shrink: 0; color: var(--color-fg-subtle); }
.sidebar__section-label {
  padding: 0 var(--space-3); color: var(--color-fg-subtle);
  font-size: 10px; font-weight: var(--font-bold); letter-spacing: .09em; text-transform: uppercase;
}
.sidebar__mobile-close {
  display: none; position: absolute; top: var(--space-4); right: var(--space-4);
  width: 38px; height: 38px; place-items: center; border: 1px solid var(--color-border);
  border-radius: var(--radius-md); background: var(--color-surface); color: var(--color-fg-muted);
}
.sidebar__mobile-close .icon { width: 18px; height: 18px; }

.sidebar__nav { display: flex; flex-direction: column; gap: var(--space-1); }
.sidebar__link {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3); border-radius: var(--radius-md);
  color: var(--color-fg-muted); font-size: var(--text-sm); font-weight: var(--font-medium);
  transition: background var(--dur-fast) var(--ease-in-out), color var(--dur-fast) var(--ease-in-out);
  white-space: nowrap;
}
.sidebar__link:hover { background: var(--color-surface-hover); color: var(--color-fg); }
/* 2026-07-13: active state got a left accent bar (same device as the
   pinned-announcement card) instead of relying on the tinted background
   alone to read as "current page" — makes it identifiable at a glance
   rather than just a slightly different fill. */
.sidebar__link.is-active { background: var(--color-primary-soft); color: var(--color-primary); box-shadow: inset 3px 0 0 var(--color-primary); }
.sidebar__link .icon { width: 20px; height: 20px; flex-shrink: 0; }
.sidebar__link-label { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.sidebar__link .sidebar__link-arrow { width: 14px; height: 14px; flex-shrink: 0; margin-left: auto; opacity: 0.6; }

/* Hover flyout submenu (desktop only — see media query below): hovering a nav
   item with sub-destinations (People/Leaves/Recruiting/Documents) reveals a
   panel of direct links, so users can jump straight to a sub-tab instead of
   landing on the hub's default tab first. Pure CSS :hover, no JS state. */
.sidebar__item { position: relative; }
.sidebar__submenu {
  display: none;
  position: absolute; left: calc(100% + var(--space-2)); top: 0; z-index: var(--z-drawer);
  min-width: 200px; padding: var(--space-1);
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
}
.sidebar__submenu-link {
  display: block; padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm);
  color: var(--color-fg); font-size: var(--text-sm); font-weight: var(--font-medium); white-space: nowrap;
}
.sidebar__submenu-link:hover { background: var(--color-surface-hover); }
.sidebar__submenu-link.is-active { background: var(--color-primary-soft); color: var(--color-primary); }

/* Flyout only triggers on real hover (desktop) — on touch, tapping the parent
   link just navigates straight to the hub, whose own in-page tab bar already
   exposes every sub-destination the flyout would have offered. */
@media (min-width: 901px) {
  .sidebar__item:hover .sidebar__submenu,
  .sidebar__submenu:hover { display: block; }
}

/* Bottom-pinned group (Налаштування + collapse toggle) — visually separated from the
   main nav list by a divider and pushed to the foot of the sidebar via margin-top:auto. */
.sidebar__bottom { margin-top: auto; padding-top: var(--space-3); border-top: 1px solid var(--color-border); }
.sidebar__collapse {
  display: flex; align-items: center; gap: var(--space-3); width: 100%; margin-top: var(--space-1);
  padding: var(--space-3); border: 0; border-radius: var(--radius-md); background: transparent;
  color: var(--color-fg-subtle); font-size: var(--text-sm); font-weight: var(--font-medium);
  transition: background var(--dur-fast) var(--ease-in-out), color var(--dur-fast) var(--ease-in-out);
}
.sidebar__collapse:hover { background: var(--color-surface-hover); color: var(--color-fg); }
.sidebar__collapse .icon { width: 20px; height: 20px; flex-shrink: 0; }

/* Mobile-only theme/language pair — moved out of the header (which only shows
   burger/search/bell/avatar there) into the drawer, as one segmented pill
   (same visual device as the auth page's language+theme control). Hidden on
   desktop below, where the header keeps its own copies. */
.sidebar__quick-controls {
  display: flex; align-items: stretch; height: 44px; margin-top: var(--space-1);
  border: 1px solid var(--color-border); border-radius: var(--radius-full);
  overflow: hidden;
}
.sidebar__quick-btn {
  flex: 1; display: inline-flex; align-items: center; justify-content: center;
  border: 0; background: transparent; color: var(--color-fg-muted);
  font-size: var(--text-xs); font-weight: var(--font-bold); letter-spacing: 0.02em;
  transition: background var(--dur-fast) var(--ease-in-out), color var(--dur-fast) var(--ease-in-out);
}
.sidebar__quick-btn + .sidebar__quick-btn { border-left: 1px solid var(--color-border); }
.sidebar__quick-btn:hover { background: var(--color-surface-hover); color: var(--color-fg); }
.sidebar__quick-btn .icon { width: 18px; height: 18px; }
@media (min-width: 901px) { .sidebar__quick-controls { display: none; } }

/* Collapsed state — icon rail only, desktop-only (the mobile drawer already fully
   hides/shows the sidebar via its own .is-open transform, so this is scoped above
   the drawer breakpoint to avoid the two mechanisms fighting each other). */
@media (min-width: 901px) {
  :root[data-sidebar-collapsed] .app-shell { grid-template-columns: var(--sidebar-width-collapsed) 1fr; }
  :root[data-sidebar-collapsed] .sidebar__brand { padding-left: 0; padding-right: 0; }
  :root[data-sidebar-collapsed] .sidebar__brand-row { justify-content: center; }
  :root[data-sidebar-collapsed] .sidebar__brand-full { display: none; }
  :root[data-sidebar-collapsed] .sidebar__brand-compact { display: block; }
  :root[data-sidebar-collapsed] .sidebar__brandname,
  :root[data-sidebar-collapsed] .sidebar__powered,
  :root[data-sidebar-collapsed] .sidebar__section-label,
  :root[data-sidebar-collapsed] .sidebar__link-label,
  :root[data-sidebar-collapsed] .sidebar__link-arrow { display: none; }
  :root[data-sidebar-collapsed] .sidebar__link,
  :root[data-sidebar-collapsed] .sidebar__collapse { justify-content: center; gap: 0; }
  :root[data-sidebar-collapsed] .nav-badge { position: absolute; top: 6px; right: 6px; }
  :root[data-sidebar-collapsed] .sidebar__link { position: relative; }
  :root[data-sidebar-collapsed] .sidebar__profile { justify-content: center; padding: var(--space-2); border-color: transparent; }
  :root[data-sidebar-collapsed] .sidebar__profile-info { display: none; }
  :root[data-sidebar-collapsed] .sidebar__profile-arrow,
  :root[data-sidebar-collapsed] .sidebar__profile-avatar > i { display: none; }
}

.app-main { min-width: 0; display: flex; flex-direction: column; }

.app-header {
  position: sticky; top: 0; z-index: var(--z-header);
  display: flex; align-items: center; gap: var(--space-4);
  height: var(--header-height); padding: 0 var(--space-6);
  background: var(--color-surface); border-bottom: 1px solid var(--color-border);
}
.hdr-icon {
  display: grid; place-items: center; width: 40px; height: 40px; flex-shrink: 0;
  border: 0; border-radius: var(--radius-md); background: transparent; color: var(--color-fg-muted);
}
.hdr-icon:hover { background: var(--color-surface-hover); color: var(--color-fg); }
.hdr-lang { width: auto; padding: 0 var(--space-3); font-size: var(--text-sm); font-weight: var(--font-semibold); }
.hdr-burger { display: none; }

/* 2026-07-13: widened 420px→560px per polish feedback ("ширший пошук") —
   the top bar had a lot of unused space beside it on desktop. */
.hdr-search { position: relative; flex: 1; max-width: 560px; display: flex; align-items: center; }
.hdr-search .icon { position: absolute; left: var(--space-3); width: 18px; height: 18px; color: var(--color-fg-subtle); pointer-events: none; }
.hdr-search input {
  width: 100%; height: 40px; padding: 0 var(--space-3) 0 var(--space-10);
  font: inherit; font-size: var(--text-sm); color: var(--color-fg);
  background: var(--color-surface-2); border: 1px solid transparent; border-radius: var(--radius-md);
}
.hdr-search input:focus { outline: none; border-color: var(--color-ring); background: var(--color-surface); }

.hdr-actions { display: flex; align-items: center; gap: var(--space-2); margin-left: auto; }
.hdr-dropdown { position: relative; }
.hdr-user { display: flex; align-items: center; gap: var(--space-2); height: 40px; padding: 0 var(--space-2); border: 0; border-radius: var(--radius-md); background: transparent; color: var(--color-fg); }
.hdr-user:hover { background: var(--color-surface-hover); }
.hdr-user__name { font-size: var(--text-sm); font-weight: var(--font-medium); }
.icon--sm { width: 16px; height: 16px; }

.dropdown-menu {
  position: absolute; top: calc(100% + var(--space-2)); right: 0; min-width: 200px;
  padding: var(--space-1); background: var(--color-surface);
  border: 1px solid var(--color-border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  z-index: var(--z-drawer);
}
.dropdown-menu--right { right: 0; }
.dropdown-item {
  display: flex; align-items: center; width: 100%; min-height: 38px;
  box-sizing: border-box; gap: var(--space-2); padding: 9px var(--space-3);
  border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--color-fg);
  font: inherit; font-size: var(--text-sm); line-height: 1.25;
  text-align: left; text-decoration: none;
}
.dropdown-item:hover { background: var(--color-surface-hover); }
.dropdown-item--danger { color: var(--color-danger); }
.dropdown-divider { border-top: 1px solid var(--color-border); margin: var(--space-1) 0; }
.dropdown-empty { padding: var(--space-6) var(--space-4); text-align: center; color: var(--color-fg-muted); font-size: var(--text-sm); }

/* Notification bell */
.hdr-icon { position: relative; }
.hdr-badge { position: absolute; top: 3px; right: 3px; min-width: 16px; height: 16px; padding: 0 4px; font-size: 10px; line-height: 16px; }
.notif-menu { width: 340px; max-width: 90vw; padding: 0; overflow: hidden; }
.notif-head { display: flex; align-items: center; justify-content: space-between; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-border); font-weight: var(--font-semibold); font-size: var(--text-sm); }
.notif-readall { border: 0; background: transparent; color: var(--color-primary); font-size: var(--text-xs); font-weight: var(--font-semibold); cursor: pointer; }
#notif-list { max-height: 380px; overflow-y: auto; }
.notif-item { display: block; width: 100%; text-align: left; padding: var(--space-3) var(--space-4); border: 0; border-bottom: 1px solid var(--color-border); background: transparent; cursor: pointer; }
.notif-item:hover { background: var(--color-surface-hover); }
.notif-item.is-unread { background: var(--color-primary-soft); }
.notif-item__title { font-size: var(--text-sm); font-weight: var(--font-semibold); color: var(--color-fg); }
.notif-item__body { font-size: var(--text-xs); color: var(--color-fg-muted); margin-top: 2px; }
.notif-item__time { font-size: var(--text-xs); color: var(--color-fg-subtle); margin-top: 2px; }
.notif-viewall { display: block; text-align: center; padding: var(--space-3) var(--space-4); font-size: var(--text-sm); font-weight: var(--font-semibold); color: var(--color-primary); text-decoration: none; border-top: 1px solid var(--color-border); }
.notif-viewall:hover { background: var(--color-surface-hover); }

/* Notifications inbox page (backlog Priority 13) */
.notif-card { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); cursor: pointer; }
.notif-card.is-unread { border-left: 3px solid var(--color-primary); }
.notif-card__main { min-width: 0; flex: 1; }
.notif-card__action { flex-shrink: 0; }

.app-view { flex: 1; width: 100%; max-width: var(--content-max); margin: 0 auto; padding: var(--space-8) var(--space-6); }
.sidebar-scrim { display: none; }

/* License status banner (Phase 47) — persistent, not a dismissible toast. */
.license-banner { padding: var(--space-3) var(--space-6); font-size: var(--text-sm); font-weight: var(--font-medium); text-align: center; }
.license-banner--danger { background: var(--color-danger-soft); color: var(--color-danger); }
.license-banner--warn { background: var(--color-warning-soft); color: var(--color-warning); }
/* Phase 48 — read-only (expired, not revoked): deliberately orange, distinct
   from the red (revoked) and amber (stale) banners above. */
.license-banner--readonly { background: var(--color-orange-soft); color: var(--color-orange); }
/* Phase 49 — trial countdown: blue, distinct from every other banner state
   above (none of them mean "everything's fine, just a heads-up"). */
.license-banner--trial { background: var(--color-primary-soft); color: var(--color-primary); }

/* 2026-07-19 — "no license at all" (a freshly provisioned/registered
   instance). Solid primary fill + inline CTA, not another soft/tinted bar
   like the others — this is the one banner state with a single obvious
   next action (paste a key), so it reads as a prompt to act, not a status
   readout. */
.license-banner--none {
  display: flex; align-items: center; justify-content: center; gap: var(--space-3);
  background: var(--color-primary); color: var(--color-on-primary);
}
.license-banner--none .icon { width: 18px; height: 18px; flex-shrink: 0; }
.license-banner__cta {
  display: inline-flex; align-items: center; padding: 3px var(--space-3);
  background: rgba(255, 255, 255, 0.18); color: #fff; border-radius: var(--radius-full);
  font-weight: var(--font-semibold); font-size: var(--text-xs); text-decoration: none;
  transition: background var(--dur-fast) var(--ease-in-out);
}
.license-banner__cta:hover { background: rgba(255, 255, 255, 0.3); }
@media (max-width: 560px) {
  .license-banner--none { flex-wrap: wrap; }
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .app-sidebar {
    position: fixed; left: 0; top: 0; z-index: var(--z-modal);
    /* Was a flat var(--sidebar-width) (264px) — on a 375-430px phone that's
       only ~60-70% of the screen and read as cramped. min(86vw,340px) hits
       the requested ~82-86% on phones while staying a sane drawer width
       (not a second full page) once this breakpoint's upper end (900px)
       is a small tablet. */
    width: min(86vw, 340px);
    transform: translateX(-100%); transition: transform var(--dur-base) var(--ease-out);
    /* The base rule leaves both axes at their default `visible` on purpose —
       desktop's hover flyout submenus (position:absolute, rendered past the
       sidebar's right edge) rely on that. Scoping overflow-y:auto to mobile
       only avoids the CSS "if one axis is auto the other computes to auto
       too" coupling from ever reaching the desktop rule and re-clipping
       those flyouts; the drawer has no flyout to protect, so it's safe here.
       Without this the drawer's content (profile card + growing nav list)
       could exceed 100dvh with no way to reach what's cut off. */
    overflow-y: auto; -webkit-overflow-scrolling: touch;
  }
  .app-sidebar.is-open { transform: none; box-shadow: var(--shadow-xl); }
  .sidebar__mobile-close { display: grid; }
  .hdr-burger { display: grid; }
  .sidebar-scrim.is-open { display: block; position: fixed; inset: 0; z-index: var(--z-drawer); background: var(--color-overlay); }
  .hdr-user__name { display: none; }
  .sidebar__collapse { display: none; } /* icon-rail collapse is a desktop-only affordance — the drawer already fully hides the sidebar on mobile */
  /* Top bar simplification: theme/language move into the drawer's own
     .sidebar__quick-controls pill (see above) — the header keeps only
     burger · search · bell · avatar. */
  .hdr-theme, .hdr-lang { display: none; }
  /* Header search is a stub (Enter just jumps to People, see app.js) that
     crowded the mobile top bar for little payoff; dashboard.js now renders
     a full-width, more discoverable version of the same input right under
     the greeting instead (.dash-search, dashboard.css). */
  .hdr-search { display: none; }
  /* Safety net against stray horizontal page-scroll on phones. `clip` (not
     hidden) creates no scroll container and doesn't touch position:sticky; the
     desktop hover flyouts live above 901px, so nothing here is being clipped.
     The real per-component fixes (minmax grids → min(N,100%)) are the primary
     defense; this just guarantees the page can never scroll sideways. */
  .app-view { overflow-x: clip; }
}
@media (max-width: 560px) {
  .app-view { padding: var(--space-5) var(--space-4); }
}
