/* SIMPLIFIED LAYOUT */
:root {
  --app-admin-bar-height: 0px;
}

body.admin-mode {
  --app-admin-bar-height: 8px;
}

.simplified-header {
  background-color: var(--app-header-bg);
  height: calc(var(--app-header-height) + var(--app-admin-bar-height));

  .container-xxl {
    /* Reuse existing .header styles, only override positioning/height */
    border-bottom: 1px solid var(--app-bg-sheet);
    box-sizing: border-box;
    height: calc(var(--app-header-height) + var(--app-admin-bar-height));
    position: fixed;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: nowrap;
    top: 0;
    left: 0;
    right: 0;
    z-index: 999;
    background-color: var(--app-header-bg);

    .simplified-header-desktop {
      width: 100%;
      justify-content: space-between;
      align-items: center;
      gap: 1rem;
      flex-wrap: nowrap;
      min-width: 0;
    }

    body.admin-mode & {
      border-top: var(--app-admin-bar-height) solid var(--hc-admin-blue);
    }

    .simplified-header-mobile {
      width: 100%;
      align-items: center;
      gap: 0.5rem;
      flex-wrap: nowrap;

      .logo-icon-only {
        border-radius: var(--app-radius-card);
        background: transparent;
        padding: 0.35rem;

        > img {
          width: 20px;
          height: auto;
        }

        /* Wordmark next to the mark when the header has room (tab bar). */
        .logo-letters {
          margin-left: 0.4rem;
        }
      }

      .mobile-primary-nav {
        display: flex;
        align-items: center;
        gap: 0.4rem;
        flex: 1;
        min-width: 0;
        margin-left: 0.25rem;

        /* With the bottom tab bar only the chat button is left here. */
        &.end {
          justify-content: flex-end;

          .pill-button {
            flex: 0 0 42px;
          }
        }

        .pill-button {
          margin-left: 0;
          padding: 0;
          border-radius: var(--app-radius-card);
          overflow: hidden;
          flex: 1;
          min-width: 0;

          a {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 100%;
            gap: 0.25rem;
            padding: 0.5rem 0.55rem;
            font-size: var(--app-text-md);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
          }

          &.icon-only a {
            padding: 0.5rem 0;

            .bi {
              font-size: 1.05rem;
              line-height: 1;
            }
          }
        }
      }

      .mobile-menu-button {
        border: 1px solid var(--app-chrome);
        background-color: var(--app-chrome);
        color: var(--app-accent-yellow);
        border-radius: var(--app-radius-card);
        width: 42px;
        height: 42px;
        padding: 0;

        .bi {
          font-size: 1.4rem;
          line-height: 1;
        }
      }
    }

    .logo {
      width: auto;
      flex-shrink: 0;

      .logo-letters img {
        height: 1.2rem;
      }
    }

    .left-section {
      min-width: 0;
      flex: 1;
      align-items: center;
    }

    .view-selector-wrapper {
      display: flex;
      flex-wrap: nowrap;
      align-items: center;
      min-width: 0;

      .pill-button {
        border-radius: var(--bs-border-radius-pill);
        padding: 0.5rem 1rem;
        font-size: var(--app-text-md);
        border: 1px solid var(--app-chrome);
        margin-left: 0.5rem;
        color: var(--app-fg-muted);

        a {
          text-decoration: none;

          &:hover,
          &:focus {
            color: inherit;
            text-decoration: none;
          }
        }

        &.active {
          background-color: var(--app-chrome);

          a,
          .dropdown-toggle {
            color: #fff !important;

            .bi {
              color: var(--app-accent-yellow);
            }
          }
        }
      }

      @media (hover: hover) and (pointer: fine) {
        .pill-button:not(.active):hover {
          background-color: var(--app-bg-wash);
        }
      }

      .overflow-item {
        display: none;
      }

      .nav-more {
        display: inline-flex;
        align-items: center;

        .dropdown-toggle {
          border: 0;
          background: transparent;
          color: inherit;
          padding: 0;

          &::after {
            display: none;
          }
        }

      }

      @media (min-width: 1400px) {
        .overflow-item {
          display: inline-flex;
        }

        .nav-more {
          display: none;
        }
      }
    }

    .account-controls {
      display: flex;
      align-items: center;
      gap: 0.75rem;
      flex-shrink: 0;

      .dropdown {
        .dropdown-toggle {
          border: 1px solid var(--app-surface-muted);
          background-color: var(--app-surface-muted);
          color: var(--app-fg);

          &::after {
            display: none;
          }

          &.user-control {
            width: 2.625rem;
            height: 2.625rem;
            padding: 0;
            border-radius: 50%;
            display: inline-flex;
            align-items: center;
            justify-content: center;

            .initials {
              font-weight: var(--app-text-semibold);
              font-size: var(--app-text-sm);
              letter-spacing: 0.02em;
            }
          }

          &.business-switcher {
            display: inline-flex;
            align-items: center;
            gap: 0.4rem;
            max-width: 12rem;
            height: 2.625rem;
            padding: 0.25rem 0.75rem;
            border-radius: var(--app-radius-xl);
            text-align: left;

            .bi {
              color: var(--hc-ink-500);
              flex-shrink: 0;
            }

            .name {
              min-width: 0;
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: nowrap;
              font-weight: var(--app-text-semibold);
              font-size: var(--app-text-sm);
            }
          }
        }

        .dropdown-menu {
          ul {
            list-style-type: none;
          }

          .dropdown-item-text.email {
            font-size: var(--app-text-sm);
            color: var(--app-fg-muted);
            max-width: 16rem;
            overflow: hidden;
            text-overflow: ellipsis;
          }
        }
      }
    }
  }
}

.simplified-mobile-menu {
  --bs-offcanvas-width: min(92vw, 360px);
  background-color: var(--app-bg-sheet);
  border-left: 1px solid color-mix(in srgb, var(--app-fg-muted) 18%, transparent);

  .offcanvas-header {
    border-bottom: 0;
    padding: 0.875rem 1.25rem 0.5rem;

    .brand-wrap img:first-child {
      width: 16px;
      height: auto;
    }

    .brand-wrap img:last-child {
      height: 14px;
      width: auto;
    }
  }

  .offcanvas-body {
    padding: 0.5rem 1rem 1.25rem;
  }

  .mobile-nav-link {
    display: inline-flex;
    align-items: center;
    gap: 0.65rem;
    width: 100%;
    border-radius: 12px;
    padding: 0.7rem 0.85rem;
    color: var(--app-fg-muted);
    font-size: var(--app-text-sm);
    text-decoration: none;
    background: transparent;
    border: 0;
    text-align: left;

    &:focus-visible {
      background-color: color-mix(in srgb, var(--app-chrome) 14%, transparent);
      text-decoration: none;
      color: var(--app-fg);
    }

    @media (hover: hover) and (pointer: fine) {
      &:hover {
        background-color: color-mix(in srgb, var(--app-chrome) 14%, transparent);
        text-decoration: none;
        color: var(--app-fg);
      }
    }

    &.active {
      background-color: var(--app-chrome);
      color: #fff;

      .bi {
        color: var(--app-accent-yellow);
      }
    }
  }

  .nav-divider {
    padding: 0.25rem 0;

    hr {
      margin: 0;
      border-color: color-mix(in srgb, var(--app-fg-muted) 18%, transparent);
    }
  }

  .mobile-account-card {
    .mobile-account-profile {
      border-radius: var(--app-radius-xl);
      border: 1px solid var(--app-surface-muted);
      background-color: var(--app-surface-muted);
      padding: 0.625rem 1rem;
      text-align: left;

      .icon {
        color: var(--hc-ink-500);

        .initials {
          display: inline-flex;
          align-items: center;
          justify-content: center;
          width: 2rem;
          height: 2rem;
          border-radius: 50%;
          background: var(--app-fg);
          color: var(--app-fg-on-inverse);
          font-weight: var(--app-text-semibold);
          font-size: var(--app-text-xs);
        }
      }

      .title {
        color: var(--app-fg);
        font-weight: var(--app-text-semibold);
        font-size: var(--app-text-sm);
      }

      .subtitle {
        color: var(--app-fg-muted);
        font-size: var(--app-text-xs);
        font-weight: var(--app-text-normal);
      }
    }
  }

  .mobile-legal-links {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    font-size: var(--app-text-xs);
    padding-bottom: 0.25rem;

    .legal-link {
      color: var(--app-fg-muted);
      text-decoration: none;

      &:focus-visible {
        color: var(--app-fg);
        text-decoration: none;
      }

      @media (hover: hover) and (pointer: fine) {
        &:hover {
          color: var(--app-fg);
          text-decoration: none;
        }
      }
    }

    .sep {
      color: var(--app-fg-muted);
      opacity: 0.5;
    }
  }

  .mobile-bottom-section {
    .feedback-trigger {
      display: inline-flex;
      align-items: center;
      gap: 0.3rem;
      border: 1px solid var(--app-chrome);
      border-radius: var(--bs-border-radius-pill);
      background-color: var(--app-chrome);
      color: #fff;
      padding: 0.2rem 0.55rem;
      font-size: var(--app-text-xs);
      line-height: 1.2;
      cursor: pointer;

      .bi {
        font-size: 0.85em;
        color: var(--app-accent-yellow);
      }
    }
  }
}

.simplified-main {
  flex: 1 1 auto;
  min-height: 0;
  padding-top: calc(var(--app-header-height) + var(--app-admin-bar-height) + 1rem);
  padding-bottom: 2rem;

  /* The client bar sits flush against the header. */
  &:has(> .client-nav) {
    padding-top: calc(var(--app-header-height) + var(--app-admin-bar-height));
  }

  .breadcrumb {
    font-size: var(--app-text-sm);
  }

  .table-row-actions-dropdown {
    /* Sits over tables, so it keeps a white surface with a border. */
    .dropdown-menu {
      --bs-dropdown-bg: var(--app-surface);
      --bs-dropdown-border-width: 1px;
      --bs-dropdown-border-color: var(--app-border-subtle);
      --bs-dropdown-min-width: 12rem;
    }
  }
}

/* Page-level wide container for data-dense BWA yearly tables */
.bwa-income-statement-wide {
  --bs-gutter-x: clamp(1rem, 2vw, 2rem);

  /* Tighten the header block above the table so the data-dense table gets more
     of the viewport height (the table sizes itself to the space left below it). */
  .sheet {
    padding-top: 1rem;

    .row.title {
      margin-bottom: 0.75rem;
    }

    hr {
      margin-top: 0.5rem;
      margin-bottom: 0.5rem;
    }
  }
}

@media (max-width: 991.98px) {
  :root {
    --app-header-height: 64px;
  }

  .simplified-header {
    padding-top: env(safe-area-inset-top, 0px);

    .container-xxl {
      height: calc(var(--app-header-height) + var(--app-admin-bar-height));
      padding-left: 0.85rem;
      padding-right: 0.85rem;
    }

    .simplified-header-mobile {
      .pill-button a {
        padding: 0.35rem 0.6rem;
        font-size: var(--app-text-sm);
      }

      .mobile-menu-button {
        width: 38px;
        height: 38px;

        .bi {
          font-size: 1.25rem;
        }
      }
    }
  }

  .simplified-main,
  .simplified-main:has(> .client-nav) {
    padding-top: calc(var(--app-header-height) + var(--app-admin-bar-height) + env(safe-area-inset-top, 0px));
  }

  /* Section tabs at the bottom of the screen for business users. */
  body.with-tab-bar {
    --app-tab-bar-height: 3.75rem;
    /* Navigation moved to the tab bar, so the header only needs room for its 38px buttons. */
    --app-header-height: 52px;

    .simplified-main {
      padding-bottom: calc(var(--app-tab-bar-height) + env(safe-area-inset-bottom, 0px) + 1.5rem);
    }

    /* Margin, because the container's bottom/padding utilities are !important. */
    .toast-container {
      margin-bottom: calc(var(--app-tab-bar-height) + env(safe-area-inset-bottom, 0px));
    }

    .mobile-tab-bar {
      position: fixed;
      left: 0;
      right: 0;
      bottom: 0;
      z-index: 1000;
      display: flex;
      height: calc(var(--app-tab-bar-height) + env(safe-area-inset-bottom, 0px));
      padding: 0.4rem 0.35rem env(safe-area-inset-bottom, 0px);
      background-color: var(--app-header-bg);
      border-top: 1px solid var(--app-separator);
      box-shadow: 0 -0.25rem 0.75rem rgba(0, 0, 0, 0.08);

      .tab {
        flex: 1 1 0;
        min-width: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 0.2rem;
        color: var(--app-fg-muted);
        font-size: var(--app-text-xs);
        text-decoration: none;

        .bi {
          font-size: 1.2rem;
          line-height: 1;
          padding: 0.3rem 1rem;
          border-radius: var(--bs-border-radius-pill);
        }

        .label {
          max-width: 100%;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }

        &.active {
          color: var(--app-fg);
          font-weight: var(--app-text-semibold);

          .bi {
            background-color: var(--app-chrome);
            color: var(--app-accent-yellow);
          }
        }
      }
    }
  }

  /* Desktop-only breadcrumbs still render a wrapper with mb-2; hide it on mobile. */
  .simplified-breadcrumbs:has(.d-none.d-lg-block) {
    display: none;
  }
}
