/*
 * App shell (sidebar + topbar + page) and the centred auth layout.
 * Geometry follows the Figma screens at 1440 px (Sidebar component 1:684,
 * Topbar 3:351); breakpoints keep it usable down to phones.
 */

/* ===================================================================== */
/* App grid                                                              */
/* ===================================================================== */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
  /* Paint the sidebar strip down the whole page (the sidebar itself is
     sticky and one viewport tall), so long pages and full-page captures
     keep the Figma column. */
  background: linear-gradient(
    to right,
    var(--bg-surface) 0 calc(var(--sidebar-width) - 1px),
    var(--border-subtle) calc(var(--sidebar-width) - 1px) var(--sidebar-width),
    transparent var(--sidebar-width)
  );
}

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

.page {
  flex: 1 0 auto;
  padding: var(--page-padding);
}

.page:focus {
  outline: none;
}

/* ===================================================================== */
/* Sidebar                                                               */
/* ===================================================================== */

.sidebar {
  position: sticky;
  top: 0;
  z-index: var(--z-sidebar);
  display: flex;
  flex-direction: column;
  width: var(--sidebar-width);
  height: 100vh;
  height: 100dvh;
  padding: 24px 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-right: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  scrollbar-gutter: auto;
}

/* Logo: 26 x 33 mark + "TelecomSoft" wordmark (Brand/Logo 1:260). */
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 33px;
  padding-left: 10px;
  border-radius: var(--radius-md);
  color: var(--text-primary);
}

.brand__mark {
  width: 26px;
  height: 33px;
  flex: none;
}

.brand__word {
  font: 600 22px/26px var(--font-display);
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.brand__word em {
  font-style: normal;
  color: var(--brand-red);
}

/* Workspace switcher card */
.ws-switch {
  position: relative;
  margin-top: 22px;
}

.ws-switch__button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 59px;
  padding: 0 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  background: var(--bg-elevated);
  text-align: left;
  transition: border-color var(--duration-fast) var(--ease-out), background-color var(--duration-fast) var(--ease-out);
}

.ws-switch__button:hover {
  border-color: var(--border-strong);
}

.ws-switch__tile {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: var(--radius-md);
  background: var(--brand-red);
  color: var(--base-white);
  font: 700 13px/16px var(--font-display);
}

.ws-switch__text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.ws-switch__name {
  font: var(--type-label-s-strong);
  letter-spacing: var(--track-label-s-strong);
  color: var(--text-primary);
}

.ws-switch__tagline {
  font: var(--type-body-xs);
  color: var(--text-tertiary);
}

.ws-switch__name,
.ws-switch__tagline {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.ws-switch__chevron {
  margin-left: auto;
  color: var(--text-tertiary);
  transition: transform var(--duration) var(--ease-out);
}

.ws-switch__button[aria-expanded="true"] .ws-switch__chevron {
  transform: rotate(180deg);
}

.ws-switch .menu {
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  min-width: 0;
}

/* Navigation */
.nav__label {
  margin: 22px 0 10px;
  padding-left: 12px;
  font: var(--type-eyebrow);
  letter-spacing: var(--track-eyebrow);
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.nav__list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.nav__item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 40px;
  padding: 0 12px;
  border-radius: var(--radius-lg);
  color: var(--text-secondary);
  font: var(--type-label-s);
  letter-spacing: var(--track-label-s);
  transition: background-color var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out);
}

.nav__item .i {
  --i-size: 18px;
  color: var(--text-tertiary);
  transition: color var(--duration-fast) var(--ease-out);
}

.nav__item:hover {
  background: var(--overlay-hover);
  color: var(--text-primary);
}

.nav__item:hover .i {
  color: var(--text-secondary);
}

.nav__item[aria-current="page"] {
  background: color-mix(in srgb, var(--brand-red) var(--alpha-soft), transparent);
  color: var(--text-primary);
  font: var(--type-label-s-strong);
  letter-spacing: var(--track-label-s-strong);
}

.nav__item[aria-current="page"] .i {
  color: var(--brand-red);
}

/* Red marker on the sidebar edge (x = 0) for the active item. */
.nav__item[aria-current="page"]::before {
  content: "";
  position: absolute;
  top: 11px;
  left: -16px;
  width: 3px;
  height: 18px;
  border-radius: 0 2px 2px 0;
  background: var(--brand-red);
}

.nav__text {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.nav__count {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 8px;
  border-radius: var(--radius-full);
  background: var(--bg-raised);
  color: var(--text-secondary);
  font: var(--type-label-xs-strong);
  letter-spacing: var(--track-label-xs-strong);
}

.nav__item[aria-current="page"] .nav__count--accent {
  background: var(--brand-red);
  color: var(--base-white);
}

/* Phase 4 Messages: unread messages need attention, so this count is red in
   every state (chat-fe lane, docs/messenger-design.md §15). */
.nav__count--unread,
.nav__item[aria-current="page"] .nav__count--unread {
  background: var(--brand-red);
  color: var(--base-white);
}

/* Bottom group: report storage + user card */
.sidebar__foot {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-top: auto;
  padding-top: 24px;
}

.storage-card {
  display: block;
  padding: 14px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  background: var(--bg-elevated);
  transition: border-color var(--duration-fast) var(--ease-out);
}

a.storage-card:hover {
  border-color: var(--border-strong);
}

.storage-card__head {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-primary);
  font: var(--type-label-s-strong);
  letter-spacing: var(--track-label-s-strong);
}

.storage-card__head .i {
  color: var(--text-secondary);
}

.storage-card__usage {
  margin-top: 10px;
  font: var(--type-body-xs);
  color: var(--text-tertiary);
}

.storage-card .progress {
  margin-top: 10px;
}

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 37px;
  padding: 0 4px;
}

.user-card__text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.user-card__name {
  overflow: hidden;
  color: var(--text-primary);
  font: var(--type-label-s-strong);
  letter-spacing: var(--track-label-s-strong);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.user-card__role {
  overflow: hidden;
  color: var(--text-tertiary);
  font: var(--type-body-xs);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.user-card__signout {
  display: flex;
  margin-left: auto;
}

/* 18 px glyph box like Figma; the ::before keeps a 28 px hit area. */
.user-card__signout .icon-btn--xs {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  overflow: visible;
}

.user-card__signout .icon-btn--xs::before {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: var(--radius-md);
}

.user-card__signout .icon-btn--xs:hover {
  background: transparent;
}

.user-card__signout .icon-btn--xs:hover::before {
  background: var(--overlay-hover);
}

/* ===================================================================== */
/* Topbar                                                                */
/* ===================================================================== */

.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--topbar-height);
  padding: 0 var(--page-padding);
  border-bottom: 1px solid var(--border-subtle);
  background: color-mix(in srgb, var(--bg-canvas) 88%, transparent);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  backdrop-filter: blur(14px) saturate(140%);
}

.topbar__menu {
  display: none;
}

.topbar__heading {
  flex: 1 1 auto;
  min-width: 0;
  margin-right: auto;
}

.topbar__title {
  overflow: hidden;
  color: var(--text-primary);
  font: var(--type-h4);
  letter-spacing: var(--track-h4);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.topbar__subtitle {
  margin-top: 2px;
  overflow: hidden;
  color: var(--text-tertiary);
  font: var(--type-body-xs);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.topbar__actions {
  display: flex;
  flex: none; /* the heading truncates first; actions never get squeezed */
  align-items: center;
  gap: 12px;
  min-width: 0;
}

/* Search box that opens the command palette (Ctrl/Cmd K). */
.topbar-search {
  position: relative;
  display: flex;
  flex: 0 1 300px;
  align-items: center;
  gap: 8px;
  width: 300px;
  min-width: 200px;
  height: var(--control-height);
  padding: 0 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  color: var(--text-tertiary);
  cursor: text;
  transition: border-color var(--duration-fast) var(--ease-out);
}

.topbar-search:hover {
  border-color: var(--border-strong);
}

.topbar-search:focus-within {
  border-color: var(--border-strong);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-red) 22%, transparent);
}

.topbar-search__submit {
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  flex: none;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
}

.topbar-search__input {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-primary);
  font: var(--type-body-s);
  letter-spacing: var(--track-body-s);
}

.topbar-search__input::placeholder {
  color: var(--text-tertiary);
  opacity: 1;
}

.topbar-search__input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

.topbar-search__input:focus-visible {
  outline: none;
}

.topbar-search .kbd {
  flex: none;
}

.bell {
  position: relative;
}

.bell .dot {
  position: absolute;
  /* Figma ellipse 3:366 sits at (23, 9) in the 40 px bell frame; absolute
     offsets start inside the 1 px border, hence 8 px (integration fix). */
  top: 8px;
  right: 8px;
}

/* ===================================================================== */
/* Mobile drawer                                                         */
/* ===================================================================== */

.sidebar-scrim {
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-sidebar) - 1);
  background: var(--scrim);
  opacity: 0;
  transition: opacity var(--duration) var(--ease-out);
}

.sidebar-scrim.is-visible {
  opacity: 1;
}

.sidebar__close {
  display: none;
}

/* ===================================================================== */
/* Responsive                                                            */
/* ===================================================================== */

/* 1280-1439: same layout; long subtitles truncate, the search narrows. */
@media (max-width: 1279px) {
  :root {
    --page-padding: 28px;
  }

  .topbar-search {
    width: 240px;
    flex-basis: 240px;
  }
}

/* Below 1200 the search collapses to an icon button that opens the palette. */
@media (max-width: 1199px) {
  .topbar-search {
    flex: none;
    justify-content: center;
    width: var(--control-height);
    min-width: 0;
    padding: 0;
    cursor: pointer;
  }

  .topbar-search__input,
  .topbar-search .kbd {
    display: none;
  }

  .topbar-search__submit {
    width: 100%;
    height: 100%;
  }
}

/* Below 1024 the sidebar becomes an off-canvas drawer. */
@media (max-width: 1023px) {
  :root {
    --page-padding: 24px;
  }

  .app {
    grid-template-columns: minmax(0, 1fr);
    background: none;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    max-width: calc(100vw - 48px);
    transform: translateX(-104%);
    visibility: hidden;
    transition: transform var(--duration-slow) var(--ease-out), visibility 0s linear var(--duration-slow);
  }

  .sidebar.is-open {
    transform: none;
    visibility: visible;
    box-shadow: var(--elevation-float);
    transition: transform var(--duration-slow) var(--ease-out), visibility 0s;
  }

  .sidebar__close {
    display: inline-grid;
    position: absolute;
    top: 22px;
    right: 14px;
  }

  .topbar__menu {
    display: inline-grid;
    margin-left: -6px;
  }

  body.has-drawer {
    overflow: hidden;
  }
}

/* Phones: the topbar wraps, actions move to their own row. */
@media (max-width: 767px) {
  :root {
    --page-padding: 16px;
  }

  .topbar {
    flex-wrap: wrap;
    row-gap: 10px;
    height: auto;
    min-height: 64px;
    padding-top: 12px;
    padding-bottom: 12px;
  }

  .topbar__heading {
    flex-basis: calc(100% - 64px);
  }

  .topbar__actions {
    flex: 1 1 100%;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
  }

  .topbar__actions > .btn {
    flex: 1 1 auto;
  }
}

/* ===================================================================== */
/* Auth layout (sign-in, password pages, errors)                         */
/* ===================================================================== */

.auth {
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 56px 20px 40px;
  overflow: hidden;
}

/* Subtle grid that fades out from the centre. */
.auth::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -2;
  background-image:
    linear-gradient(to right, rgb(255 255 255 / 0.035) 1px, transparent 1px),
    linear-gradient(to bottom, rgb(255 255 255 / 0.035) 1px, transparent 1px);
  background-size: 56px 56px;
  background-position: center center;
  -webkit-mask-image: radial-gradient(ellipse 70% 60% at 50% 42%, #000 20%, transparent 78%);
  mask-image: radial-gradient(ellipse 70% 60% at 50% 42%, #000 20%, transparent 78%);
}

/* Red glow behind the card. */
.auth::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: -1;
  width: min(900px, 140vw);
  height: 620px;
  border-radius: 50%;
  background:
    radial-gradient(closest-side, color-mix(in srgb, var(--brand-red) 30%, transparent), transparent 72%),
    radial-gradient(closest-side at 70% 30%, color-mix(in srgb, var(--brand-red-deep) 50%, transparent), transparent 70%);
  filter: blur(36px);
  opacity: 0.85;
  transform: translate(-50%, -62%);
  pointer-events: none;
}

.auth__brand {
  display: inline-flex;
}

.auth__brand .brand {
  padding-left: 0;
}

.auth-card {
  position: relative;
  width: min(440px, 100%);
  padding: 36px 36px 32px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-2xl);
  background: color-mix(in srgb, var(--bg-surface) 92%, transparent);
  box-shadow: var(--elevation-float);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}

/* Thin red highlight along the top edge of the card. */
.auth-card::before {
  content: "";
  position: absolute;
  top: -1px;
  left: 36px;
  right: 36px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--brand-red), transparent);
  opacity: 0.8;
}

.auth-card--wide {
  width: min(520px, 100%);
}

.auth-card__eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--brand-red);
  font: var(--type-eyebrow);
  letter-spacing: var(--track-eyebrow);
  text-transform: uppercase;
}

.auth-card__eyebrow::before {
  content: "";
  width: 16px;
  height: 1px;
  background: currentColor;
}

.auth-card__title {
  margin-top: 12px;
  color: var(--text-primary);
  font: var(--type-h3);
  letter-spacing: var(--track-h3);
}

.auth-card__lead {
  margin-top: 8px;
  color: var(--text-secondary);
  font: var(--type-body-s);
  letter-spacing: var(--track-body-s);
}

.auth-card__body {
  margin-top: 28px;
}

.auth-card__footer {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border-subtle);
  color: var(--text-tertiary);
  font: var(--type-body-xs);
  text-align: center;
}

.auth-card__footer a {
  color: var(--text-secondary);
  font-weight: 600;
}

.auth-card__footer a:hover {
  color: var(--text-primary);
}

.auth__legal {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-tertiary);
  font: var(--type-body-xs);
  text-align: center;
}

.auth__legal .i {
  color: var(--status-success);
}

/* Error pages: big status code above the card text. */
.error-code {
  color: var(--text-primary);
  font: var(--type-display-l);
  letter-spacing: var(--track-display-l);
}

.error-code em {
  font-style: normal;
  color: var(--brand-red);
}

@media (max-width: 480px) {
  .auth {
    justify-content: flex-start;
    padding-top: 36px;
  }

  .auth-card {
    padding: 28px 22px 24px;
  }

  .auth-card__title {
    font: var(--type-h4);
    letter-spacing: var(--track-h4);
  }
}

/* Three-line menu glyph for the drawer button (drawn in CSS). */
.hamburger,
.hamburger::before,
.hamburger::after {
  display: block;
  width: 18px;
  height: 1.75px;
  border-radius: 2px;
  background: currentColor;
}

.hamburger {
  position: relative;
}

.hamburger::before,
.hamburger::after {
  content: "";
  position: absolute;
  left: 0;
}

.hamburger::before {
  top: -6px;
}

.hamburger::after {
  top: 6px;
}

/* Auth details */
.auth-submit {
  margin-top: 6px;
}

.auth-link {
  color: var(--brand-red);
  transition: color var(--duration-fast) var(--ease-out);
}

.auth-link:hover {
  color: var(--brand-red-bright);
}

.auth-card--status {
  text-align: center;
}

.auth-card--status .empty__icon {
  margin: 4px auto 0;
}

.auth-card--status .auth-card__title {
  margin-top: 22px;
}

.auth-card__note {
  margin-top: 14px;
  color: var(--text-tertiary);
  font: var(--type-body-xs);
}

.empty__icon--success {
  background: color-mix(in srgb, var(--status-success) var(--alpha-chip), transparent);
  color: var(--status-success);
  box-shadow: 0 0 0 8px color-mix(in srgb, var(--status-success) 5%, transparent);
}

/* Print: content only. */
@media print {
  .sidebar,
  .sidebar-scrim,
  .topbar__actions,
  .topbar__menu,
  .toasts,
  .skip-link {
    display: none !important;
  }

  .app {
    display: block;
    background: none;
  }

  .topbar {
    position: static;
    backdrop-filter: none;
  }
}
