/* =============================================================================
   APP SHELL — sidebar, topbar, content area
   Depends on tokens.css. Contains no literal colours.
   ========================================================================== */

.app {
  display: flex;
  min-height: 100vh;
}

/* =========================================================================
   SIDEBAR
   ========================================================================= */

.app-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: var(--z-sidebar);
  display: flex;
  flex-direction: column;
  width: var(--sidebar-width);
  background-color: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  transition: width var(--duration-normal) var(--ease),
              transform var(--duration-slow) var(--ease-out);
}

/* --- Brand --- */

.app-sidebar__brand-row { display: flex; align-items: center; }

/* Drawer-only: on desktop the sidebar is always there and has nothing to close. */
.app-sidebar__close { display: none; margin-right: var(--space-4); }

.app-sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: var(--topbar-height);
  padding: 0 var(--space-5);
  flex-shrink: 0;
  color: var(--text);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.015em;
}

.app-sidebar__brand:hover { color: var(--text); }

.app-sidebar__logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-active) 100%);
  color: var(--accent-fg);
}

.app-sidebar__logo svg { width: 16px; height: 16px; }

.app-sidebar__brand-name { white-space: nowrap; overflow: hidden; }

/* --- Primary action --- */

.app-sidebar__cta { padding: var(--space-4) var(--space-4) var(--space-3); }
.app-sidebar__cta .btn { width: 100%; }

/* --- Navigation --- */

.app-sidebar__nav {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: var(--space-2) var(--space-4) var(--space-5);
}

.nav-group + .nav-group { margin-top: var(--space-6); }

.nav-group__label {
  padding: 0 var(--space-3);
  margin-bottom: var(--space-2);
  color: var(--text-subtle);
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  overflow: hidden;
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: 34px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-md);
  color: var(--sidebar-item);
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  transition: background-color var(--duration-fast) var(--ease),
              color var(--duration-fast) var(--ease);
}

.nav-item:hover { background-color: var(--sidebar-item-hover-bg); color: var(--text); }

.nav-item.is-active {
  background-color: var(--sidebar-item-active-bg);
  color: var(--sidebar-item-active);
}

.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }

.nav-item__label { overflow: hidden; text-overflow: ellipsis; }

/* The status shortcuts are indented one step so the group reads as "All Parcels, and
   these ways of narrowing it" rather than six unrelated destinations. */
.nav-item--sub { padding-left: var(--space-7); }

/* The tally. margin-left:auto pins it to the trailing edge, which is also what keeps a
   long translated label from pushing it out of the sidebar - the label ellipsises first. */
.nav-item__count {
  margin-left: auto;
  flex-shrink: 0;
  min-width: 20px;
  padding: 0 6px;
  border-radius: var(--radius-pill);
  background-color: var(--surface-sunken);
  color: var(--text-subtle);
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
  line-height: 18px;
  text-align: center;
}

.nav-item.is-active .nav-item__count { color: var(--sidebar-item-active); }

/* --- Footer --- */

.app-sidebar__footer {
  flex-shrink: 0;
  padding: var(--space-4);
  border-top: 1px solid var(--sidebar-border);
}

.plan-card {
  display: block;
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background-color: var(--surface-sunken);
}

.plan-card__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}

/* On the PRO card the row is the whole card, so it has nothing to space itself
   from. */
.plan-card__row:last-child { margin-bottom: 0; }

.plan-card__action { margin-top: var(--space-4); }

.plan-card__label {
  color: var(--text-subtle);
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.plan-card__text { color: var(--text-muted); font-size: var(--text-xs); margin: 0; }

.sidebar-collapse-btn {
  margin-top: var(--space-3);
  width: 100%;
  justify-content: flex-start;
}

/* --- Collapsed (icon rail) ---

   Everything here is scoped to .app-sidebar. The brand mark and wordmark are
   reused by the signed-out header and footer, which live outside the app shell
   and have no sidebar to collapse - an unscoped rule silently hid the wordmark
   on the public site for anyone who had ever collapsed the sidebar in the app. */

:root.sidebar-collapsed .app-sidebar { width: var(--sidebar-width-collapsed); }

:root.sidebar-collapsed .app-sidebar .app-sidebar__brand-name,
:root.sidebar-collapsed .app-sidebar .nav-group__label,
:root.sidebar-collapsed .app-sidebar .nav-item__label,
:root.sidebar-collapsed .app-sidebar .nav-item__count,
:root.sidebar-collapsed .app-sidebar .plan-card,
:root.sidebar-collapsed .app-sidebar .sidebar-collapse-btn .btn-label { display: none; }

:root.sidebar-collapsed .app-sidebar .app-sidebar__brand,
:root.sidebar-collapsed .app-sidebar .app-sidebar__cta,
:root.sidebar-collapsed .app-sidebar .app-sidebar__nav { padding-left: var(--space-4); padding-right: var(--space-4); }

:root.sidebar-collapsed .app-sidebar .nav-item { justify-content: center; padding: 0; }
:root.sidebar-collapsed .app-sidebar .app-sidebar__cta .btn { padding: 0; }
:root.sidebar-collapsed .app-sidebar .sidebar-collapse-btn { justify-content: center; }
:root.sidebar-collapsed .app-main { margin-left: var(--sidebar-width-collapsed); }

/* =========================================================================
   MAIN COLUMN
   ========================================================================= */

.app-main {
  flex: 1 1 auto;
  min-width: 0;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  transition: margin-left var(--duration-normal) var(--ease);
}

/* --- Topbar --- */

.app-topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  height: var(--topbar-height);
  padding: 0 var(--space-6);
  border-bottom: 1px solid var(--topbar-border);
  background-color: var(--topbar-bg);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
}

/* Hidden while the sidebar is on screen - the sidebar's active item already
   names the page, and the page's own <h1> sits directly below this bar. It
   comes back at the sidebar breakpoint, where it is the only page label. */
.app-topbar__title {
  display: none;
  margin: 0;
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-topbar__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
}

.app-topbar__nav-toggle { display: none; }

/* --- Account menu --- */

.account-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  height: 32px;
  padding: 0 var(--space-2) 0 var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text);
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
  cursor: pointer;
}

.account-btn:hover { background-color: var(--surface-hover); }
.account-btn:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 1px; }
.account-btn::after { display: none; }
.account-btn svg { width: 14px; height: 14px; color: var(--text-subtle); }

.avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  border-radius: 50%;
  background-color: var(--accent-soft);
  color: var(--accent-soft-fg);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
}

.account-menu__head {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-2);
}

.account-menu__name { color: var(--text); font-weight: var(--weight-medium); }
.account-menu__email { color: var(--text-subtle); font-size: var(--text-xs); overflow-wrap: anywhere; }

/* --- Content --- */

/* Left-aligned rather than centred, and --content-max only caps how wide a
   table row may get on a very large monitor. Centring would start the content
   at a different x depending on which cap applied, so a page's <h1> would slide
   sideways as you moved between Parcels (wide) and Profile (narrow). */
.app-content {
  flex: 1 1 auto;
  width: 100%;
  max-width: var(--content-max);
  padding: var(--content-pad-y) var(--content-pad) var(--content-pad-b);
  margin: 0;
}

/* Pages that are read or filled in rather than scanned run in a narrower
   column. The wizard sits between the two: wide enough that a row of fields
   does not feel like a dialog on a laptop, narrow enough to stay a form. */
.app-content--narrow { max-width: var(--content-max-narrow); }
.app-content--wizard { max-width: var(--content-max-wizard); }

/* --- Footer --- */

.app-footer {
  padding: var(--space-6);
  border-top: 1px solid var(--border);
  color: var(--text-subtle);
  font-size: var(--text-xs);
  text-align: center;
}

.app-footer a { color: var(--text-muted); }
.app-footer a:hover { color: var(--text); }

/* =========================================================================
   MOBILE — sidebar becomes an off-canvas drawer
   ========================================================================= */

.app-sidebar__scrim {
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-sidebar) - 1);
  background-color: var(--overlay);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--duration-normal) var(--ease),
              visibility var(--duration-normal) var(--ease);
}

@media (max-width: 991.98px) {
  .app-sidebar {
    transform: translateX(-100%);
    box-shadow: var(--shadow-xl);
  }

  :root.nav-open .app-sidebar { transform: translateX(0); }
  :root.nav-open .app-sidebar__scrim { opacity: 1; visibility: visible; }

  .app-main,
  :root.sidebar-collapsed .app-main { margin-left: 0; }

  .app-topbar__nav-toggle { display: inline-flex; }
  .app-sidebar__close { display: inline-flex; }
  .app-sidebar__brand-row .app-sidebar__brand { flex: 1 1 auto; min-width: 0; }

  /* The collapse control is desktop-only */
  .app-sidebar__footer .sidebar-collapse-btn {
  margin-top: var(--space-3); display: none; }

  .app-topbar__title { display: block; }
  .app-content { padding: var(--space-5) var(--content-pad) var(--space-9); }
  .app-topbar { padding: 0 var(--content-pad); }
}

@media (max-width: 575.98px) {
  .app-topbar__title { font-size: var(--text-md); }
  .account-btn__name { display: none; }
}

/* =========================================================================
   AUTH SHELL — login / register / password / timezone
   ========================================================================= */

.auth {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-color: var(--canvas);
}

.auth__topbar {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  height: var(--topbar-height);
  padding: 0 var(--space-6);
}

.auth__topbar-actions { display: flex; align-items: center; gap: var(--space-2); margin-left: auto; }

.auth__main {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-8) var(--space-5) var(--space-10);
}

.auth__card {
  width: 100%;
  max-width: 400px;
}

.auth__head { text-align: center; margin-bottom: var(--space-7); }

.auth__title {
  margin: 0 0 var(--space-2);
  font-size: var(--text-2xl);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.02em;
}

.auth__subtitle { margin: 0; color: var(--text-muted); }

.auth__form { display: flex; flex-direction: column; gap: var(--space-5); }

.auth__divider {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin: var(--space-6) 0;
  color: var(--text-subtle);
  font-size: var(--text-xs);
}

.auth__divider::before,
.auth__divider::after {
  content: "";
  flex: 1 1 auto;
  height: 1px;
  background-color: var(--border);
}

.auth__links {
  display: flex;
  justify-content: center;
  gap: var(--space-4);
  margin-top: var(--space-6);
  font-size: var(--text-sm);
}

.auth__trust {
  display: flex;
  justify-content: center;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-top: var(--space-7);
  color: var(--text-subtle);
  font-size: var(--text-xs);
}

.auth__trust-item { display: inline-flex; align-items: center; gap: var(--space-2); }
.auth__trust-item svg { width: 13px; height: 13px; }

.auth__footer {
  padding: var(--space-6);
  color: var(--text-subtle);
  font-size: var(--text-xs);
  text-align: center;
}

.auth__tagline { margin: 0 0 var(--space-2); }

/* Error page card - a little wider than the auth form it borrows the shell from. */
.error-card { width: 100%; max-width: 520px; }
.auth__footer > .auth__tagline:only-child { margin-bottom: 0; }

/* Google sign-in */

.btn-google {
  --_btn-bg: var(--surface);
  --_btn-fg: var(--text);
  --_btn-border: var(--border-strong);
  width: 100%;
}

.btn-google:hover { --_btn-bg: var(--surface-hover); }
.btn-google svg { width: 17px; height: 17px; }

/* =========================================================================
   THEME + LANGUAGE CONTROLS
   ========================================================================= */


/* Only one of the two glyphs is shown, depending on the resolved theme */
.theme-toggle__sun,
.theme-toggle__moon { display: inline-flex; }

.theme-toggle__moon { display: none; }

:root[data-theme="dark"] .theme-toggle__sun { display: none; }
:root[data-theme="dark"] .theme-toggle__moon { display: block; }

.lang-btn { width: auto; padding: 0 var(--space-3); gap: var(--space-2); font-size: var(--text-sm); font-weight: var(--weight-medium); }
.lang-btn__code { text-transform: uppercase; }

.lang-menu .dropdown-item.is-active { color: var(--accent-text); font-weight: var(--weight-medium); }
