/* ==========================================================================
   IEC Customer Portal — Workspace Shell, Left Rail, Mobile Bar & Bottom Nav
   ========================================================================== */

/* --- Desktop Workspace Shell (>=1024px) ----------------------------------- */

.portal-workspace {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
}

.portal-workspace__body {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

/* --- Left Sidebar Rail ---------------------------------------------------- */

.portal-rail {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  background: #fff;
  border-right: 1px solid var(--line);
}

.portal-rail__brand {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.portal-rail__brand .portal-brand img {
  height: 40px;
  width: auto;
}

.portal-rail__brand .portal-brand__label {
  display: inline-flex;
  align-items: center;
  width: max-content;
  padding: 4px 9px;
  border-radius: var(--r-sm);
  background: var(--navy);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Active Company Card */

.portal-company-card {
  margin: 14px 14px 6px;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: #f6f9fb;
}

.portal-company-card__label {
  display: block;
  color: var(--muted2);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.portal-company-card__name {
  display: block;
  margin-top: 3px;
  color: var(--navy);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.portal-company-card__code {
  display: inline-block;
  margin-top: 5px;
  padding: 2px 6px;
  border-radius: 4px;
  background: #e5eef4;
  color: var(--navy);
  font-size: 11px;
  font-weight: 700;
}

.portal-company-card__switcher {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 6px 0 0;
}

.portal-company-card__switcher select {
  flex: 1 1 0;
  min-width: 0;
  min-height: 34px;
  padding: 5px 8px;
  border: 1px solid var(--input-bd);
  border-radius: var(--r-sm);
  background: #fff;
  color: var(--navy);
  font-size: 13px;
  font-weight: 700;
}

.portal-company-card__switch-btn {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 9px;
  border: 1px solid var(--input-bd);
  border-radius: var(--r-sm);
  background: #fff;
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
}

.portal-company-card__switch-btn:hover {
  border-color: var(--blue);
  background: #eef5fa;
}

/* Primary Navigation */

.portal-rail__nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 12px;
}

.portal-rail__nav a {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 42px;
  padding: 8px 12px;
  border-radius: var(--r-md);
  color: #2f424e;
  font-size: 14px;
  font-weight: 700;
  transition: background 0.14s ease, color 0.14s ease;
}

.portal-nav__icon {
  width: 19px;
  height: 19px;
  flex: 0 0 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.portal-rail__nav a:hover {
  background: #f0f5f8;
  color: var(--navy);
}

.portal-rail__nav a[aria-current="page"] {
  background: #e8f2f9;
  color: var(--blue-dark);
  font-weight: 800;
}

.portal-rail__nav a[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: 0;
  top: 7px;
  bottom: 7px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--red);
}

.portal-rail__divider {
  height: 1px;
  margin: 8px 8px;
  background: var(--line);
}

/* Bottom Utility Block */

.portal-rail__utility {
  margin-top: auto;
  padding: 14px 14px 16px;
  border-top: 1px solid var(--line);
  background: #fafcfd;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.portal-rail__branches {
  display: grid;
  gap: 4px;
}

.portal-rail__branches-title {
  color: var(--muted2);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 2px;
}

.portal-rail__branches a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 8px;
  border-radius: var(--r-sm);
  color: var(--muted);
  font-size: 12px;
}

.portal-rail__branches a strong {
  color: var(--navy);
  font-weight: 700;
}

.portal-rail__branches a:hover {
  background: #edf4f8;
  color: var(--blue);
}

.portal-rail__site-link {
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  padding: 2px 4px;
}

.portal-rail__site-link:hover {
  text-decoration: underline;
}

.portal-rail__user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.portal-rail__user-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.portal-account__name {
  overflow: hidden;
  color: var(--navy);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.portal-rail__user-meta small {
  overflow: hidden;
  color: var(--muted2);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.portal-signout-form {
  margin: 0;
  flex: 0 0 auto;
}

.portal-signout {
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid var(--input-bd);
  border-radius: var(--r-sm);
  background: #fff;
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

.portal-signout:hover {
  border-color: var(--blue);
  background: #f0f6fa;
}

.portal-signout--full {
  width: 100%;
  min-height: 40px;
}

/* --- Focused Top Header (Sign-in, Onboarding, Account Selection) ---------- */

.portal-header {
  position: relative;
  z-index: 20;
  flex: 0 0 auto;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.portal-header--mobile {
  display: none;
}

.portal-header__inner {
  display: flex;
  width: 100%;
  max-width: 1240px;
  height: 74px;
  align-items: center;
  gap: 20px;
  margin: 0 auto;
  padding: 0 24px;
}

.portal-brand {
  display: flex;
  flex: none;
  align-items: center;
}

.portal-brand img {
  width: auto;
  height: 48px;
  max-height: 48px;
}

.portal-header .portal-brand__label {
  margin-left: 16px;
  padding-left: 16px;
  border-left: 1px solid var(--line);
  color: var(--blue);
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

.portal-account {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
  white-space: nowrap;
}

.portal-account--solo {
  margin-left: auto;
}

.portal-site-link {
  margin-left: auto;
  color: var(--blue);
  font-size: 14px;
  font-weight: 700;
}

.portal-site-link:hover {
  text-decoration: underline;
}

/* --- Mobile Bottom Tab Bar & Single-Row Top Bar (<1024px) ----------------- */

.portal-bottom-nav {
  display: none;
}

@media (max-width: 1023px) {
  .portal-workspace {
    display: block;
    overflow: visible;
  }

  .portal-rail {
    display: none;
  }

  .portal-workspace__body {
    overflow: visible;
  }

  .portal-header--mobile {
    display: block;
    position: sticky;
    top: 0;
    z-index: 35;
    box-shadow: 0 2px 10px rgba(0, 44, 78, 0.05);
  }

  .portal-mobile-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    height: 56px;
    padding: 0 14px;
  }

  .portal-mobile-bar .portal-brand img {
    height: 32px;
    width: auto;
  }

  .portal-mobile-bar__company {
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-left: 12px;
    border-left: 1px solid var(--line);
    color: var(--navy);
    font-size: 14px;
    font-weight: 800;
  }

  .portal-mobile-menu {
    position: relative;
    flex: 0 0 auto;
  }

  .portal-mobile-menu__trigger {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    background: #fff;
    color: var(--navy);
    list-style: none;
    cursor: pointer;
  }

  .portal-mobile-menu__trigger::-webkit-details-marker {
    display: none;
  }

  .portal-mobile-menu__popover {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    z-index: 50;
    width: min(290px, calc(100vw - 24px));
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    background: #fff;
    box-shadow: 0 18px 46px rgba(0, 44, 78, 0.18);
    display: grid;
    gap: 14px;
  }

  .portal-mobile-menu__user {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
  }

  .portal-mobile-menu__user strong {
    color: var(--navy);
    font-size: 14px;
  }

  .portal-mobile-menu__user span {
    color: var(--muted);
    font-size: 12px;
  }

  .portal-mobile-menu__switcher {
    display: grid;
    gap: 8px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
  }

  .portal-mobile-menu__links {
    display: grid;
    gap: 6px;
  }

  .portal-mobile-menu__links a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 9px;
    border-radius: var(--r-sm);
    background: var(--soft);
    color: var(--navy);
    font-size: 13px;
    font-weight: 700;
  }

  .portal-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    background: #fff;
    border-top: 1px solid var(--line);
    box-shadow: 0 -4px 18px rgba(0, 44, 78, 0.08);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .portal-bottom-nav a {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 58px;
    padding: 6px 2px;
    color: var(--muted2);
    font-size: 11px;
    font-weight: 700;
    line-height: 1.1;
  }

  .portal-bottom-nav a .portal-nav__icon {
    width: 20px;
    height: 20px;
    flex: 0 0 20px;
  }

  .portal-bottom-nav a[aria-current="page"] {
    color: var(--blue);
    font-weight: 800;
  }

  .portal-bottom-nav a[aria-current="page"]::before {
    content: "";
    position: absolute;
    top: 0;
    left: 16%;
    right: 16%;
    height: 3px;
    border-radius: 0 0 3px 3px;
    background: var(--red);
  }

  body.portal-shell--workspace .portal-footer {
    padding-bottom: calc(66px + env(safe-area-inset-bottom, 0px));
  }
}

@media (max-width: 640px) {
  .portal-header--focused .portal-header__inner {
    height: 62px;
    padding: 0 16px;
  }

  .portal-header--focused .portal-brand img {
    height: 38px;
  }

  .portal-header--focused .portal-brand__label,
  .portal-header--focused .portal-account__name {
    display: none;
  }
}
