/* Refinements apply only after login; original authentication styling is preserved. */
@scope (body:has(.shell)) {
  /* Shared usability fixes, scoped away from the original sign-in screen. */
  .recent-document-actions {
    min-width: 118px;
  }
  .recent-document-actions .row-action-group {
    grid-template-columns: 1fr;
  }
  .catalog-search {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    justify-content: space-between;
    gap: 16px;
    padding: 20px;
    margin-bottom: 24px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: white;
  }
  .catalog-search label {
    flex: 1 1 260px;
    max-width: 520px;
  }
  .catalog-search input {
    margin-bottom: 0;
  }
  .catalog-search [role="status"] {
    color: var(--muted);
    font-size: 13px;
    padding-bottom: 10px;
  }
  .phase-disabled {
    opacity: 1;
    color: #526879;
  }
  .business-stack,
  .business-stack > *,
  .accounting-tools > * {
    min-width: 0;
  }
  .accounting-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .accounting-stats button {
    min-width: 0;
    white-space: normal;
  }
  #business-root:has(.accounting-stats) table {
    min-width: 760px;
  }
  .analysis-project-expand {
    width: 100%;
    margin-top: 18px;
  }
  .settings-toolbar {
    position: sticky;
    top: 0;
    z-index: 6;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 16px;
    padding: 10px;
    margin-bottom: 24px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #f5f8fb;
    box-shadow: 0 3px 12px #173d5608;
  }
  .settings-toolbar .settings-nav {
    position: static;
    flex: 1 1 520px;
    flex-wrap: wrap;
    padding: 0;
    margin: 0;
    background: none;
    border: 0;
    border-radius: 0;
    backdrop-filter: none;
    overflow: visible;
    gap: 4px;
  }
  .settings-toolbar .settings-nav a {
    padding: 9px 10px;
  }
  .settings-save {
    display: flex;
    flex: 1 1 auto;
    align-items: center;
    justify-content: flex-end;
    gap: 14px;
  }
  #settings-save-status {
    color: #526879;
    font-size: 12px;
  }
  #settings-save-status.is-unsaved {
    color: #895614;
  }
  .settings-section {
    scroll-margin-top: 150px;
  }
  @media (max-width: 760px) {
    #business-root:has(.accounting-stats) table {
      min-width: 0;
    }
    [data-account-rows] thead {
      display: none;
    }
    [data-account-rows] tbody {
      display: block;
    }
    [data-account-rows] tr {
      display: grid;
      gap: 14px;
      padding: 20px 0;
      border-top: 1px solid var(--line);
    }
    [data-account-rows] td {
      display: grid;
      grid-template-columns: 100px minmax(0, 1fr);
      gap: 8px;
      min-width: 0;
      padding: 0;
      border: 0;
    }
    [data-account-rows] td::before {
      content: attr(data-label);
      color: var(--muted);
      font-size: 12px;
    }
    [data-account-rows] td:first-child,
    [data-account-rows] .accounting-row-action {
      display: block;
    }
    [data-account-rows] td:first-child::before,
    [data-account-rows] .accounting-row-action::before {
      display: none;
    }
    [data-account-rows] .accounting-row-action button {
      width: 100%;
    }
    #project-results table {
      min-width: 0;
    }
    #project-results thead {
      display: none;
    }
    #project-results tbody {
      display: block;
    }
    #project-results tr {
      display: grid;
      padding: 20px;
      gap: 14px;
      border-bottom: 1px solid var(--line);
    }
    #project-results td {
      display: grid;
      grid-template-columns: 115px minmax(0, 1fr);
      gap: 4px 12px;
      padding: 0;
      border: 0;
      min-width: 0;
      text-align: left;
    }
    #project-results td::before {
      content: attr(data-label);
      color: var(--muted);
      font-size: 12px;
    }
    #project-results td:first-child {
      display: block;
      font-size: 15px;
    }
    #project-results td:first-child::before {
      display: none;
    }
    #project-results td > small,
    #project-results .project-progress {
      grid-column: 2;
    }
    #project-results .project-open-cell {
      display: block;
    }
    #project-results .project-open-cell::before {
      display: none;
    }
    #project-results .project-open-cell button {
      width: 100%;
    }
    .accounting-stats {
      grid-template-columns: 1fr;
    }
    .accounting-stats button {
      display: grid;
      grid-template-columns: minmax(0, 1fr) auto;
      padding: 16px;
    }
    .accounting-stats button strong {
      grid-column: 2;
      grid-row: 1 / 3;
    }
    .accounting-stats button span {
      grid-column: 1;
    }
    .accounting-tools {
      display: grid;
      grid-template-columns: 1fr;
    }
    .accounting-tools label {
      min-width: 0;
      max-width: none;
    }
    .accounting-tools .actions {
      display: flex;
      flex-wrap: wrap;
    }
    .accounting-tools .actions button {
      flex: 1 1 auto;
    }
    .project-tabs {
      display: grid;
      grid-template-columns: repeat(3, minmax(0, 1fr));
      overflow: visible;
      gap: 4px;
    }
    .project-tabs button {
      padding: 10px 6px;
      font-size: 12px;
    }
    .project-tabs .project-link {
      grid-column: 1 / -1;
      margin: 4px 0 0;
      border: 1px solid var(--line);
      border-radius: 8px;
    }
    .analysis-more > div {
      left: 0;
      right: auto;
      max-width: calc(100vw - 60px);
    }
    .settings-toolbar .settings-nav {
      flex-basis: 100%;
    }
    .settings-save {
      justify-content: space-between;
    }
    .settings-section {
      scroll-margin-top: 200px;
    }
  }
  :scope {
    --surface: #fff;
    --button-shadow: 0 1px 2px #18364b0a;
    --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  }
  button,
  .button {
    border-radius: 8px;
    font-weight: 500;
    box-shadow: var(--button-shadow);
    transition:
      background-color 160ms ease,
      border-color 160ms ease,
      color 160ms ease,
      box-shadow 160ms ease;
  }
  button:not(:disabled):active,
  .button:active {
    box-shadow: none;
  }
  button:focus-visible,
  .button:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 3px;
  }
  button:disabled {
    transform: none;
    box-shadow: none;
  }
  button.primary,
  .button.primary {
    background: #086eaf;
    color: #fff;
    border-color: #086eaf;
    box-shadow: 0 2px 4px #086eaf22;
  }
  @media (hover: hover) {
    button:not(:disabled):hover,
    .button:hover {
      border-color: #9db5c9;
      box-shadow: 0 3px 9px #10283f0d;
    }
    button.primary:not(:disabled):hover,
    .button.primary:hover {
      background: #085e95;
      border-color: #085e95;
    }
    .nav button:not(:disabled):hover {
      background: #e6f1f8;
      color: #17354d;
      border-color: transparent;
      box-shadow: none;
    }
  }
  .shell {
    grid-template-columns: 234px minmax(0, 1fr);
  }
  .sidebar {
    width: 234px;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: #688398 #10283d;
    clip-path: none;
    inset: 0 auto 0 0;
    border-radius: 0;
    background: #10283d;
    padding: 22px 12px 18px;
    box-shadow: none;
    z-index: 20;
  }
  .brand {
    padding: 0 20px 18px;
  }
  .brand img {
    border-radius: 14px;
  }
  .nav {
    gap: 4px;
  }
  .nav .nav-group-title {
    letter-spacing: 0.09em;
    text-transform: uppercase;
    font-size: 10px;
    margin: 20px 14px 8px;
    color: #9ab0c2;
  }
  .nav button {
    border-radius: 12px;
    min-height: 44px;
    font-weight: 500;
    color: #c2d1df;
    padding: 10px 14px;
    box-shadow: none;
  }
  .nav button.active {
    background: #294960;
    color: #fff;
    box-shadow: inset 0 0 0 1px #49667d;
  }
  .nav button.active:before {
    display: none;
  }
  .nav button.active svg {
    color: #7bd0ff;
  }
  .sidebar-bottom {
    font-size: 11px;
    padding: 22px 14px 0;
  }
  .topbar {
    margin: 0;
    padding: 12px 28px;
    height: auto;
    min-height: 64px;
    border: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    background: var(--surface);
    box-shadow: none;
    gap: 16px;
    flex-wrap: wrap;
  }
  .workspace-brand {
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
  }
  .workspace-date {
    display: none;
  }
  .top-right {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-wrap: wrap;
  }
  .top-right button {
    border-radius: 8px;
    min-height: 38px;
    padding: 8px 12px;
    font-size: 12px;
    box-shadow: none;
  }
  main {
    padding-top: 28px;
  }
  .page-head h1 {
    font-size: 30px;
    letter-spacing: -0.8px;
  }
  .panel {
    border-radius: 16px;
    overflow: clip;
  }
  .panel-head {
    background: var(--surface);
    border-bottom: 1px solid var(--line);
  }

  .nav-toggle {
    display: none;
  }
  .nav-toggle svg {
    width: 18px;
    height: 18px;
  }
  .sidebar::-webkit-scrollbar {
    width: 6px;
  }
  .sidebar::-webkit-scrollbar-track {
    background: #10283d;
  }
  .sidebar::-webkit-scrollbar-thumb {
    background: #688398;
    border: 1px solid #10283d;
    border-radius: 8px;
  }
  @media (max-width: 1250px) {
    .workspace-brand {
      display: none;
    }
    .topbar {
      margin: 0;
      padding: 9px 12px;
    }
    .top-right {
      width: 100%;
      justify-content: flex-end;
    }
  }
  @media (max-width: 760px) {
    .shell {
      display: block;
    }
    .workspace {
      width: 100%;
    }
    .sidebar {
      visibility: hidden;
      transform: translateX(-110%);
      transition:
        transform 220ms var(--ease-out),
        visibility 220ms;
      inset: 78px auto 12px 12px;
      width: 250px;
    }
    .navigation-open .sidebar {
      visibility: visible;
      transform: translateX(0);
      box-shadow: 12px 12px 80px #0008;
    }
    .nav-toggle {
      display: inline-flex;
      padding: 10px;
      min-width: 44px;
    }
    .topbar {
      margin: 0;
      gap: 8px;
      flex-wrap: nowrap;
      border-radius: 0;
    }
    .top-right {
      justify-content: flex-end;
      width: auto;
      flex: 1;
    }
    .top-right > button {
      font-size: 11px;
      padding: 7px 9px;
    }
    .top-right > button[data-action="password"],
    .top-right > button[data-action="analysis-assistant"] {
      display: none;
    }
    .theme-switcher {
      margin-right: 0;
    }
    .theme-switcher .theme-indicator {
      width: 36px;
      height: 36px;
    }
    .topbar .workspace-brand {
      display: none;
    }
    main {
      padding: 24px 16px;
    }
    .page-head h1 {
      font-size: 26px;
    }
    .sidebar .nav {
      display: flex;
      flex-direction: column;
    }
    .sidebar .brand {
      display: none;
    }
    .sidebar .nav-group-title {
      display: block;
    }
    .sidebar-bottom {
      display: block;
    }
  }

  @media (max-width: 760px) {
    .sidebar {
      position: fixed;
      max-height: calc(100dvh - 90px);
    }
  }
  .notification-dismiss {
    width: 36px;
    height: 36px;
    padding: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .notification-dismiss svg {
    width: 18px;
    height: 18px;
  }
  .profile-card {
    max-width: 880px;
    background: white;
    border: 1px solid var(--line);
    border-radius: 20px;
    overflow: hidden;
  }
  .profile-banner {
    height: 80px;
    background: #10283d;
  }
  .profile-content {
    padding: 0 32px 30px;
  }
  .profile-identity {
    display: flex;
    align-items: flex-end;
    gap: 20px;
    margin-top: -32px;
    margin-bottom: 26px;
    flex-wrap: wrap;
  }
  .profile-avatar {
    width: 88px;
    height: 88px;
    display: grid;
    place-items: center;
    border: 5px solid white;
    border-radius: 24px;
    background: #e4f2fb;
    color: #086eaf;
    font-size: 28px;
    font-weight: 700;
    flex-shrink: 0;
  }
  .profile-identity h2 {
    margin: 0 0 6px;
    font-size: 24px;
  }
  .profile-identity > div {
    padding-top: 42px;
  }
  .profile-identity p {
    margin: 0;
    color: var(--muted);
  }
  .profile-identity .account-role {
    margin-left: auto;
    margin-bottom: 4px;
  }
  .profile-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 30px;
    margin: 0;
  }
  .profile-details div {
    padding: 16px 0;
    border-top: 1px solid var(--line);
    min-width: 0;
  }
  .profile-details dt {
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 7px;
  }
  .profile-details dd {
    margin: 0;
    overflow-wrap: anywhere;
    font-weight: 600;
  }
  .profile-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    border-top: 1px solid var(--line);
    padding-top: 22px;
    margin-top: 10px;
  }
  @media (max-width: 600px) {
    .profile-content {
      padding: 0 20px 24px;
    }
    .profile-details {
      grid-template-columns: 1fr;
    }
    .profile-identity {
      gap: 12px;
    }
  }
  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      transition-duration: 0.01ms !important;
      animation-duration: 0.01ms !important;
    }
    button:active {
      transform: none;
    }
  }

  .workspace main :is(.actions, .client-actions) > :is(button, .button) {
    min-height: 40px;
    padding: 9px 14px;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.35;
    border-radius: 8px;
    margin-top: 0;
  }
  .workspace main :is(.actions, .client-actions) > .primary {
    font-weight: 600;
  }
  .workspace main button.quiet {
    box-shadow: none;
  }
  .workspace main button.danger:hover {
    background: #fff1f2;
    color: #a51d37;
    border-color: #efb9c3;
  }
  .document-table:has(.quote-status) th {
    width: auto;
  }
  .document-table:has(.quote-status) th:first-child {
    width: 22%;
  }
  .document-table:has(.quote-status) th:nth-child(4) {
    width: 23%;
  }
  .document-table:has(.quote-status) th:last-child {
    width: 218px;
  }
  .row-action-group {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    align-items: center;
  }
  .document-row-actions .row-action-group button {
    width: 100%;
    min-height: 38px;
    height: 38px;
    padding: 8px 10px;
    margin: 0;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.35;
    border-radius: 8px;
    white-space: nowrap;
    box-shadow: none;
    border: 1px solid var(--line);
    background: white;
  }
  .document-row-actions .row-action-group button:hover {
    background: #f0f5fa;
    border-color: #afc3d6;
  }
  .document-row-actions .row-action-group button.danger:hover {
    background: #fff1f2;
    border-color: #efb9c3;
  }
  .notification-trigger {
    gap: 8px;
  }
  .notification-trigger .notification-count {
    display: grid;
    place-items: center;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    background: #e5f1fb;
    color: #075e99;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
  }
  .notification-center {
    background: white;
    border: 1px solid var(--line);
    border-radius: 14px;
    overflow: hidden;
  }
  .notification-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 22px;
    border-bottom: 1px solid var(--line);
  }
  .notification-tabs {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
  }
  .notification-tabs button {
    border: 1px solid transparent;
    background: transparent;
    box-shadow: none;
    color: var(--muted);
    min-height: 40px;
    padding: 8px 12px;
    gap: 8px;
  }
  .notification-tabs button[aria-pressed="true"] {
    background: #eaf3fb;
    border-color: #cfdfed;
    color: #075e99;
    font-weight: 600;
  }
  .notification-tabs button span {
    min-width: 20px;
    text-align: center;
    font-size: 11px;
    border-radius: 5px;
    padding: 2px 5px;
    background: #f0f3f6;
    color: #465f74;
  }
  .notification-total {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
  }
  .notification-feed {
    list-style: none;
    padding: 0;
    margin: 0;
  }
  .notification-item {
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 22px 26px;
    border-bottom: 1px solid #e8eef4;
    transition: background-color 160ms;
  }
  .notification-item:hover {
    background: #f9fbfd;
  }
  .notification-item:last-child {
    border-bottom: 0;
  }
  .notification-symbol {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    border-radius: 12px;
    background: #edf4fb;
    color: #176aab;
  }
  .notification-symbol svg {
    width: 21px;
    height: 21px;
  }
  .notification-item.approval .notification-symbol {
    background: #fff3dc;
    color: #976114;
  }
  .notification-content {
    flex: 1;
    min-width: 0;
    overflow-wrap: anywhere;
  }
  .notification-heading {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
  }
  .notification-heading strong {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.4;
  }
  .notification-category {
    font-size: 11px;
    color: #52677b;
    background: #f0f4f8;
    border-radius: 5px;
    padding: 3px 7px;
  }
  .notification-content p {
    margin: 7px 0 3px;
    font-size: 13px;
    font-weight: 500;
  }
  .notification-content p span {
    margin: 0 3px;
    color: var(--muted);
  }
  .notification-project {
    display: block;
    font-size: 13px;
    color: var(--muted);
    line-height: 1.6;
  }
  .notification-content small {
    display: block;
    margin-top: 8px;
    color: var(--muted);
    font-size: 12px;
  }
  .notification-actions {
    display: grid;
    grid-template-columns: 82px 38px;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
  }
  .notification-actions button {
    height: 38px;
    min-height: 38px;
    box-shadow: none;
    font-size: 12px;
  }
  .notification-trigger .notification-count[hidden] {
    display: none;
  }
  .document-table .document-date small {
    white-space: normal;
  }
  .notification-actions .notification-dismiss {
    width: 38px;
    height: 38px;
    padding: 9px;
    background: transparent;
    color: var(--muted);
    border-color: transparent;
  }
  .notification-actions .notification-dismiss:hover {
    background: #edf3f8;
    border-color: var(--line);
    color: var(--ink);
  }
  .notification-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--line);
    background: #fafcfe;
  }
  .notification-footer summary {
    font-size: 12px;
    color: var(--muted);
    cursor: pointer;
  }
  .notification-footer p {
    font-size: 13px;
    line-height: 1.6;
    color: var(--muted);
    max-width: 680px;
    margin-bottom: 0;
  }
  .notification-empty {
    text-align: center;
    padding: 64px 24px;
  }
  .notification-empty > span {
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    margin: 0 auto 18px;
    background: #edf7f2;
    color: #267551;
    border-radius: 16px;
  }
  .notification-empty svg {
    width: 27px;
    height: 27px;
  }
  .notification-empty h2 {
    font-size: 18px;
    margin: 0 0 10px;
  }
  .notification-empty p {
    color: var(--muted);
    font-size: 14px;
    margin: 0 auto;
    max-width: 420px;
    line-height: 1.6;
  }
  @media (min-width: 901px) and (max-width: 1250px) {
    .document-table:has(.quote-status) th:last-child {
      width: 190px;
    }
    .row-action-group {
      grid-template-columns: 1fr;
      gap: 6px;
    }
  }
  @media (max-width: 1250px) {
    .document-table .document-row-actions {
      display: block;
    }
    .row-action-group {
      max-width: 320px;
      margin-left: auto;
    }
    .document-row-actions .row-action-group button {
      height: 44px;
      min-height: 44px;
      font-size: 13px;
    }
  }
  @media (max-width: 760px) {
    .sidebar {
      border-radius: 0 16px 16px 0;
      clip-path: inset(0 round 0 16px 16px 0);
      inset: 70px auto 0 0;
      max-height: calc(100dvh - 70px);
    }
    .navigation-open .sidebar {
      inset: 70px auto 0 0;
    }
    .notification-toolbar {
      align-items: flex-start;
      padding: 12px;
      flex-direction: column;
      gap: 8px;
    }
    .notification-tabs {
      gap: 3px;
    }
    .notification-tabs button {
      padding: 8px 9px;
      font-size: 12px;
      gap: 5px;
    }
    .notification-total {
      padding: 0 8px;
    }
    .notification-item {
      display: grid;
      grid-template-columns: 36px minmax(0, 1fr);
      align-items: start;
      padding: 20px 16px;
      gap: 12px;
    }
    .notification-symbol {
      width: 36px;
      height: 36px;
      border-radius: 10px;
    }
    .notification-actions {
      grid-column: 2;
      grid-template-columns: 90px 44px;
      justify-content: flex-end;
    }
    .notification-actions button {
      min-height: 44px;
      height: 44px;
    }
    .notification-actions .notification-dismiss {
      width: 44px;
    }
    .notification-heading {
      gap: 6px;
    }
    .notification-category {
      display: none;
    }
  }
}
