/*
 * The app shell: sidebar, top bar, content frame, phone drawer and bottom tab bar.
 *
 * Desktop (>= 1200px): full sidebar with labels, as in the design.
 * Tablet (900px to 1199px): the sidebar becomes a 76px icon rail; labels show as tooltips.
 * Phone (< 900px): the sidebar is a drawer opened from the top bar; a bottom tab bar carries
 * the five main destinations.
 */

.app {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
}

.frame {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ---- Sidebar -------------------------------------------------------------------------- */

.sidebar {
  position: sticky;
  top: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--sidebar-gradient);
  color: var(--on-dark);
  padding: 14px 10px 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.brand {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 10px 6px 20px;
  color: var(--on-dark);
}

.brand-logo {
  display: block;
  width: 100%;
  max-width: 206px;
  height: auto;
}

.brand-emblem {
  display: none;
  width: 40px;
  height: auto;
}

.nav {
  display: grid;
  gap: 4px;
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 48px;
  padding: 0 16px;
  border-radius: var(--r-md);
  color: var(--on-dark);
  font-size: var(--fs-16);
  font-weight: 500;
  transition: background var(--dur) var(--ease);
}

.nav-item:hover {
  background: var(--sidebar-hover);
}

.nav-item[aria-current="page"] {
  background: var(--sidebar-active);
  font-weight: 700;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.nav-item .icon {
  width: 22px;
  height: 22px;
}

.nav-badge {
  display: grid;
  place-items: center;
  margin-left: auto;
  min-width: 24px;
  height: 24px;
  padding: 0 7px;
  border-radius: 12px;
  background: #19a04a;
  color: #fff;
  font-size: var(--fs-13);
  font-weight: 800;
  line-height: 1;
}

.nav-item .nav-dot {
  margin-left: auto;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--leaf);
  box-shadow: 0 0 0 3px rgba(77, 190, 42, 0.22);
}

.nav-item .nav-chevron {
  margin-left: auto;
  width: 18px;
  height: 18px;
  color: var(--on-dark-2);
}

.nav-divider {
  height: 1px;
  margin: 14px 8px;
  background: var(--sidebar-line);
}

/* Footer: which app this is. */
.sidebar-foot {
  margin-top: auto;
  padding-top: 18px;
}

.app-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.app-pill-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: var(--leaf);
}

.app-pill-icon .icon {
  width: 20px;
  height: 20px;
}

.app-pill-text {
  display: grid;
  min-width: 0;
  line-height: 1.25;
}

.app-pill-text strong {
  font-size: var(--fs-13);
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-pill-text span {
  font-size: var(--fs-12);
  color: var(--on-dark-2);
}

/* Top right: the account button opens Settings and Log out. */
.account {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 0 8px 0 4px;
  border-radius: var(--r-pill);
  color: var(--ink);
  font-size: var(--fs-16);
  font-weight: 600;
  text-align: left;
  transition: background var(--dur) var(--ease);
}

.account:hover,
.account[aria-expanded="true"] {
  background: var(--surface-2);
}

.account-avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #eef1f3;
  color: var(--ink-2);
}

.account-avatar .icon {
  width: 22px;
  height: 22px;
}

.account-label {
  max-width: 180px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-chev {
  width: 18px;
  height: 18px;
  color: var(--ink-3);
}

/* The date, outlined, beside the bell. */
.date-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font-size: var(--fs-15);
  font-weight: 600;
  white-space: nowrap;
}

.date-pill .icon {
  width: 20px;
  height: 20px;
  color: var(--ink-2);
}

.date-pill .short {
  display: none;
}

.sidebar-close {
  display: none;
}

/* ---- Top bar -------------------------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: var(--topbar-h);
  padding: 0 var(--gutter);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar-menu {
  display: none;
}

.topbar-text {
  flex: 0 1 auto;
  min-width: 0;
}

.topbar-title {
  font-size: var(--fs-28);
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-sub {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-2);
  font-size: var(--fs-15);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-sub .sep {
  color: var(--ink-3);
}

/* Search, on screens that offer it: centred between the title and the actions. */
.topbar-search {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 320px;
  max-width: 440px;
  min-width: 0;
  margin-inline: auto;
  min-height: 44px;
  padding: 0 8px 0 16px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  border: 1px solid transparent;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.topbar-search:focus-within {
  background: var(--surface);
  border-color: var(--green);
  box-shadow: var(--focus);
}

.topbar-search-icon {
  width: 20px;
  height: 20px;
  color: var(--ink-2);
}

.topbar-search-input {
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0;
  border: 0;
  background: transparent;
  font-size: var(--fs-15);
  color: var(--ink);
  outline: none;
  box-shadow: none;
}

.topbar-search-input::placeholder {
  color: var(--ink-3);
}

.topbar-search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

.topbar-kbd {
  font: 600 var(--fs-12) / 1 var(--font);
  color: var(--ink-2);
  background: #e3e8ec;
  border-radius: 6px;
  padding: 6px 8px;
  white-space: nowrap;
}

.topbar-search-close,
.topbar-search-toggle {
  display: none;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}

.pill--status .icon {
  width: 20px;
  height: 20px;
}

.pill--status .short {
  display: none;
}

/* Unread count on the bell. */
.icon-btn .count {
  position: absolute;
  top: 3px;
  right: 3px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: #ee3a30;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  border: 2px solid var(--surface);
}

/* ---- Main ----------------------------------------------------------------------------- */

.main {
  flex: 1;
  width: 100%;
  padding: var(--gutter) var(--gutter) calc(var(--gutter) + 8px);
  outline: none;
}

/* ---- Scrim (drawer backdrop) ---------------------------------------------------------- */

.scrim {
  position: fixed;
  inset: 0;
  z-index: 44;
  background: rgba(3, 20, 12, 0.5);
}

/* ---- Bottom tab bar (phones) ---------------------------------------------------------- */

.tabbar {
  display: none;
}

/* ---- Tablet: icon rail ---------------------------------------------------------------- */

@media (max-width: 1199.98px) {
  :root {
    --gutter: 20px;
  }

  .app {
    grid-template-columns: var(--rail-w) minmax(0, 1fr);
  }

  .sidebar {
    padding: 12px 8px 14px;
    align-items: stretch;
  }

  .brand {
    padding: 6px 0 16px;
  }

  .brand-logo,
  .nav-item .nav-label,
  .nav-item .nav-chevron {
    display: none;
  }

  .brand-emblem {
    display: block;
  }

  .nav-badge {
    position: absolute;
    top: 5px;
    right: 6px;
    margin: 0;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    font-size: 11px;
  }

  .nav-item {
    justify-content: center;
    padding: 0;
    min-height: 50px;
  }

  .nav-item .nav-dot {
    position: absolute;
    top: 9px;
    right: 11px;
    margin: 0;
  }

  /* Label as a tooltip on hover or focus. */
  .nav-item::after {
    content: attr(data-label);
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
    padding: 6px 10px;
    border-radius: var(--r-sm);
    background: var(--ink);
    color: var(--on-dark);
    font-size: var(--fs-13);
    font-weight: 600;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dur) var(--ease);
    z-index: 50;
  }

  .nav-item:hover::after,
  .nav-item:focus-visible::after {
    opacity: 1;
  }

  .app-pill {
    justify-content: center;
    padding: 8px 0;
  }

  .app-pill-text {
    display: none;
  }

  .account {
    padding: 0 2px;
  }

  .account-label,
  .account-chev {
    display: none;
  }

  .date-pill .long {
    display: none;
  }

  .date-pill .short {
    display: inline;
  }

  .topbar-title {
    font-size: var(--fs-24);
  }

  .topbar-search {
    flex-basis: 220px;
    max-width: 340px;
  }

  .topbar-kbd {
    display: none;
  }
}

/* ---- Phone: drawer and tab bar -------------------------------------------------------- */

@media (max-width: 899.98px) {
  :root {
    --gutter: 16px;
    --topbar-h: 64px;
  }

  .app {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 45;
    width: min(300px, 84vw);
    padding: 14px 12px 16px;
    transform: translateX(-100%);
    transition: transform calc(var(--dur) * 1.5) var(--ease);
    box-shadow: none;
  }

  .sidebar.is-open {
    transform: none;
    box-shadow: var(--shadow-float);
  }

  /* Restore the full labels inside the drawer. */
  .brand {
    padding: 8px 6px 18px;
  }

  .brand-logo,
  .nav-item .nav-label,
  .nav-item .nav-chevron {
    display: block;
  }

  .brand-emblem {
    display: none;
  }

  .nav-badge {
    position: static;
    margin-left: auto;
    min-width: 24px;
    height: 24px;
    padding: 0 7px;
    font-size: var(--fs-13);
  }

  .nav-item {
    justify-content: flex-start;
    padding: 0 16px;
  }

  .nav-item .nav-dot {
    position: static;
    margin-left: auto;
  }

  .nav-item::after {
    display: none;
  }

  .app-pill {
    justify-content: flex-start;
    padding: 10px 12px;
  }

  .app-pill-text {
    display: grid;
  }

  .date-pill {
    min-height: 40px;
    padding: 0 10px;
    font-size: var(--fs-14);
  }

  .sidebar-close {
    display: grid;
    position: absolute;
    top: 12px;
    right: 10px;
    color: var(--on-dark);
  }

  .sidebar-close:hover {
    background: var(--sidebar-hover);
  }

  .topbar {
    gap: 10px;
    padding: 0 12px 0 8px;
  }

  .topbar-menu {
    display: grid;
  }

  .topbar-title {
    font-size: var(--fs-20);
  }

  .topbar-sub {
    font-size: var(--fs-13);
  }

  .topbar-sub .who {
    display: none;
  }

  /* Search folds into an icon; tapping it opens the box across the whole bar. */
  .topbar-search {
    display: none;
  }

  .topbar-search-toggle {
    display: grid;
  }

  .topbar.is-searching .topbar-search {
    display: flex;
    flex: 1;
    max-width: none;
    margin: 0;
    padding-right: 4px;
  }

  .topbar.is-searching .topbar-search-close {
    display: grid;
    width: 36px;
    height: 36px;
  }

  .topbar.is-searching .topbar-text,
  .topbar.is-searching .topbar-actions,
  .topbar.is-searching .topbar-kbd {
    display: none;
  }

  .pill--status {
    min-height: 36px;
    padding: 0 12px;
  }

  .pill--status .long {
    display: none;
  }

  .pill--status .short {
    display: inline;
  }

  .main {
    padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
  }

  .tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    min-height: var(--tabbar-h);
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface);
    border-top: 1px solid var(--line);
  }

  .tab {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: var(--tabbar-h);
    color: var(--ink-2);
    font-size: var(--fs-12);
    font-weight: 600;
  }

  .tab .icon {
    width: 24px;
    height: 24px;
  }

  .tab[aria-current="page"] {
    color: var(--green-ink);
  }

  .tab[aria-current="page"]::before {
    content: "";
    position: absolute;
    top: 0;
    width: 36px;
    height: 3px;
    border-radius: 0 0 3px 3px;
    background: var(--green);
  }

  .tab-badge {
    position: absolute;
    top: 7px;
    right: calc(50% - 24px);
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: #19a04a;
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    line-height: 18px;
    text-align: center;
  }

  .tab .nav-dot {
    position: absolute;
    top: 10px;
    right: calc(50% - 18px);
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--green);
  }
}

@media (max-width: 599.98px) {
  .date-pill {
    display: none;
  }
}

@media (max-width: 479.98px) {
  .pill--status .short {
    display: none;
  }

  .pill--status {
    width: 36px;
    padding: 0;
    justify-content: center;
  }

  .topbar-actions {
    gap: 4px;
  }
}

/* ---- One-screen fit: the top bar scales with the viewport height too --------------------- */

@media (min-width: 900px) and (min-height: 560px) {
  .frame:has(.main.is-fit) .topbar {
    min-height: clamp(56px, 7.5vh, 72px);
  }

  .frame:has(.main.is-fit) .topbar-title {
    font-size: clamp(1.25rem, 2.9vh, 1.75rem);
  }

  .frame:has(.main.is-fit) .topbar-sub {
    font-size: clamp(0.75rem, 1.7vh, 0.9375rem);
  }

  .frame:has(.main.is-fit) .topbar-search {
    min-height: clamp(36px, 5vh, 44px);
  }

  .frame:has(.main.is-fit) .topbar-search-input {
    height: clamp(32px, 4.6vh, 40px);
  }
}
