/* ══════════════════════════════════════════════════════════════════
   HEADER
   ══════════════════════════════════════════════════════════════════ */

header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  background: #ece9e9;
  border-bottom: 1px solid var(--line);
  padding: var(--sp-3) var(--sp-6);
  display: flex;
  align-items: center;
  gap: var(--sp-4);
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: 700;
  font-size: var(--fs-lg);
  letter-spacing: -0.01em;
  color: var(--ink);
  white-space: nowrap;
}
/* The mark is one file: assets/logo.svg. Replace that file and both the
   header and the login screen update — no CSS or HTML edit needed. */
.logo-mark {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  display: block;
  border-radius: var(--r-sm);
  object-fit: contain;
}
.logo-sub {
  color: var(--muted);
  font-weight: 600;
}

/* Term selector — a fully custom dropdown (not a native <select>), so the
   open list gets the same rounded corners and shadow as everything else.
   Built from a trigger button + a popover listbox (see js/modal.js). */
.term-pick {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-full);
  padding: 4px 5px 4px 14px;
  box-shadow: var(--sh-1);
  transition:
    border-color var(--dur-1) var(--ease-out),
    box-shadow var(--dur-1) var(--ease-out);
}
.term-pick:hover {
  border-color: var(--muted);
  box-shadow: var(--sh-2);
}
.term-pick:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 23, 42, 0.09);
}
.term-label {
  font-size: var(--fs-xs);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}
.term-trigger {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font: inherit;
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--ink);
  background: var(--surface-2);
  border: none;
  border-radius: var(--r-full);
  padding: var(--sp-2) var(--sp-3);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color var(--dur-1) var(--ease-out);
}
.term-trigger:hover {
  background: var(--surface-3);
}
.term-chevron {
  width: 12px;
  height: 12px;
  color: var(--muted);
  transition: transform var(--dur-2) var(--ease-out);
}
.term-trigger[aria-expanded="true"] .term-chevron {
  transform: rotate(180deg);
}

/* The open list. `popover` puts it in the browser's top layer, so it is
   never clipped by the header and needs no z-index juggling. JS sets its
   left/top from the trigger's position. */
.term-menu {
  position: fixed;
  margin: 0;
  inset: auto;
  padding: var(--sp-1);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-3);
  max-height: 60vh;
  overflow-y: auto;
  min-width: 240px;
}
.term-menu:popover-open {
  animation: term-menu-in var(--dur-2) var(--ease-out);
}
@keyframes term-menu-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
}
.term-option {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: var(--fs-md);
  color: var(--ink-2);
  background: none;
  border: none;
  border-radius: var(--r-md);
  padding: var(--sp-2);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color var(--dur-1) var(--ease-out);
}
.term-option:hover,
.term-option:focus-visible {
  background: var(--surface-2);
}
.term-option:focus-visible {
  outline-offset: -2px;
}
.term-option-num {
  flex-shrink: 0;
  min-width: 26px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 var(--sp-2);
  border-radius: var(--r-sm);
  background: var(--surface-3);
  color: var(--muted);
  font-size: var(--fs-sm);
  font-weight: 700;
}
.term-option-dates {
  flex: 1;
}
.term-check {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  color: var(--accent);
  opacity: 0;
}
/* The currently selected term: tinted row, dark number badge, visible tick. */
.term-option[aria-selected="true"] {
  background: var(--surface-3);
  font-weight: 600;
  color: var(--ink);
}
.term-option[aria-selected="true"] .term-option-num {
  background: var(--accent);
  color: var(--accent-ink);
}
.term-option[aria-selected="true"] .term-check {
  opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
  .term-menu:popover-open {
    animation: none;
  }
}

.spacer {
  flex: 1;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-size: var(--fs-base);
}
.avatar {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: var(--r-full);
  /* Neutral on purpose: an amber avatar would imply "Thai team". */
  background: var(--ink);
  color: var(--accent-ink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--fs-md);
}
.user-chip b {
  color: var(--ink);
}
.user-chip .role {
  color: var(--muted);
  font-size: var(--fs-sm);
}

.badge {
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 2px var(--sp-2);
  border-radius: var(--r-full);
  vertical-align: 1px;
}
.badge.head {
  background: var(--surface-3);
  color: var(--muted);
  border: 1px solid var(--line);
}

.signout-btn {
  font-size: var(--fs-sm);
  padding: var(--sp-2) var(--sp-3);
  color: var(--muted);
}

/* Change Log — a header action button, not a tab. Icon + label. */
.log-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  padding: var(--sp-2) var(--sp-3);
  cursor: pointer;
  white-space: nowrap;
  transition:
    background-color var(--dur-1) var(--ease-out),
    border-color var(--dur-1) var(--ease-out),
    color var(--dur-1) var(--ease-out);
}
.log-btn svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}
.log-btn:hover {
  background: var(--surface-2);
  border-color: var(--muted);
  color: var(--ink);
}
.log-btn:active {
  background: var(--surface-3);
}
/* When the Change Log view is open, the button reads as "on". */
.log-btn[aria-current="page"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

/* ══════════════════════════════════════════════════════════════════
   SIDEBAR NAV — collapsed to an icon rail; hover flies it open, the pin
   button keeps it open. The rail reserves --rail-w in the layout; the
   panel is absolutely positioned so the fly-out overlays content instead
   of shoving it sideways.
   ══════════════════════════════════════════════════════════════════ */

.app-body {
  display: flex;
  align-items: flex-start;
}

.sidebar {
  position: sticky;
  top: var(--header-h, 60px);
  align-self: flex-start;
  flex-shrink: 0;
  /* Above the sticky room/name columns (z-sticky) so the fly-out covers
     them instead of letting their text bleed through. */
  z-index: var(--z-sidebar);
  width: var(--rail-w);
  height: calc(100vh - var(--header-h, 60px));
  transition: width var(--dur-2) var(--ease-out);
}
.sidebar.pinned {
  width: var(--panel-w);
}
.sidebar-panel {
  position: absolute;
  inset: 0;
  width: var(--rail-w);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  padding: var(--sp-2);
  background: var(--surface);
  border-right: 1px solid var(--line);
  transition:
    width var(--dur-2) var(--ease-out),
    box-shadow var(--dur-2) var(--ease-out);
}
.sidebar.pinned .sidebar-panel {
  width: var(--panel-w);
}
/* Fly-out on hover OR keyboard focus (so tabbing through the rail reveals
   the labels), only when NOT pinned — floats over the content. */
.sidebar:not(.pinned):hover .sidebar-panel,
.sidebar:not(.pinned):focus-within .sidebar-panel {
  width: var(--panel-w);
  box-shadow: var(--sh-3);
  border-right-color: var(--line-strong);
}

.nav-item,
.sidebar-pin {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  min-height: 40px;
  padding: var(--sp-2);
  border: none;
  background: none;
  border-radius: var(--r-md);
  font: inherit;
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  text-align: left;
  transition:
    background-color var(--dur-1) var(--ease-out),
    color var(--dur-1) var(--ease-out);
}
.nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  /* keeps the icon centred in the collapsed rail (40px − 2×8px padding) */
  margin-left: 2px;
}
/* Labels fade in as the panel opens; they never wrap or push the icon. */
.nav-label {
  flex: 1;
  overflow: hidden;
  opacity: 0;
  transition: opacity var(--dur-1) var(--ease-out);
}
.sidebar.pinned .nav-label,
.sidebar:hover .nav-label,
.sidebar:focus-within .nav-label {
  opacity: 1;
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--ink);
}
.nav-item:focus-visible {
  outline-offset: -2px;
}
/* Active page: tinted fill + an accent bar on the left as the current-page
   marker (a meaningful state indicator, the standard sidebar affordance). */
.nav-item.active {
  position: relative;
  background: var(--surface-3);
  color: var(--ink);
  font-weight: 700;
}
.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}

/* Pin toggle sits apart from the nav items, above them. */
.sidebar-pin {
  color: var(--muted);
  margin-bottom: var(--sp-1);
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding-bottom: var(--sp-3);
}
.sidebar-pin:hover {
  color: var(--ink);
}
.sidebar-pin[aria-pressed="true"] {
  color: var(--accent);
}
.sidebar-pin[aria-pressed="true"] .nav-icon {
  fill: color-mix(in srgb, var(--accent) 15%, transparent);
}

/* ══════════════════════════════════════════════════════════════════
   LAYOUT
   ══════════════════════════════════════════════════════════════════ */

main {
  /* flex child next to the sidebar. min-width:0 lets wide tables scroll
     inside their own container instead of stretching the whole page. */
  flex: 1;
  min-width: 0;
  padding: var(--sp-6) var(--sp-6) var(--sp-10);
}
.view {
  display: none;
}
/* A quick fade+rise when a view becomes active. The resting state is fully
   visible, so if the animation never runs the content still shows. */
.view.active {
  display: block;
  animation: view-in var(--dur-3) var(--ease-out);
}
@keyframes view-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}

.toolbar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
  flex-wrap: wrap;
}
.hint {
  font-size: var(--fs-sm);
  color: var(--muted);
  margin-left: auto;
  max-width: 60ch;
  text-align: right;
}

/* Small label before a chip group ("Language", "Rooms"). */
.filter-label {
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-right: var(--sp-1);
}

/* ── Filter chips ── */
.chip {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  border-radius: var(--r-full);
  padding: var(--sp-1) var(--sp-3);
  font: inherit;
  font-size: var(--fs-base);
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
  transition:
    background-color var(--dur-1) var(--ease-out),
    border-color var(--dur-1) var(--ease-out),
    color var(--dur-1) var(--ease-out);
}
.chip:hover {
  color: var(--ink);
  border-color: var(--muted);
}
/* A default ink background so an "on" chip is NEVER invisible, even if it
   carries no language colour class (the status chips on Reservation don't).
   The .c-* rules below override this for the language filter chips. */
.chip.on {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}
.chip.on:hover {
  filter: brightness(1.1);
}
/* Filled chips use the darker solids — white text needs 4.5:1. */
.chip.on.c-thai {
  background: var(--thai-solid);
}
.chip.on.c-eng {
  background: var(--eng-solid);
}
.chip.on.c-chi {
  background: var(--chi-solid);
}
.chip.on.c-all {
  background: var(--accent);
}
